Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::Utilities::InputPly Class Reference

Converter for Ply files. More...

#include <InputPly.h>

Inheritance diagram for Nektar::Utilities::InputPly:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::InputPly:
Collaboration graph
[legend]

Public Member Functions

 InputPly (MeshSharedPtr m)
 
virtual ~InputPly ()
 
virtual void Process ()
 Populate and validate required data structures. More...
 
void ReadPly (std::ifstream &mshFile, NekDouble scale=1.0)
 
- Public Member Functions inherited from Nektar::Utilities::InputModule
 InputModule (FieldSharedPtr p_m)
 
void AddFile (string fileType, string fileName)
 
 InputModule (MeshSharedPtr p_m)
 
void OpenStream ()
 Open a file for input. More...
 
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
 
virtual void Process (po::variables_map &vm)=0
 
void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
void PrintConfig ()
 Print out all configuration options for a module. More...
 
void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
bool GetRequireEquiSpaced (void)
 
void SetRequireEquiSpaced (bool pVal)
 
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 
 Module (MeshSharedPtr p_m)
 
void RegisterConfig (string key, string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 

Static Public Member Functions

static ModuleSharedPtr create (MeshSharedPtr m)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::InputModule
void PrintSummary ()
 Print summary of elements. More...
 
void PrintSummary ()
 Print summary of elements. More...
 
- Protected Member Functions inherited from Nektar::Utilities::Module
 Module ()
 
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual void ProcessElements ()
 Generate element IDs. More...
 
virtual void ProcessComposites ()
 Generate composites. More...
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, set< int > &prismsDone, vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::Utilities::InputModule
set< string > m_allowedFiles
 
std::ifstream m_mshFile
 Input stream. More...
 
- Protected Attributes inherited from Nektar::Utilities::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 
MeshSharedPtr m_mesh
 Mesh object. More...
 

Detailed Description

Converter for Ply files.

Definition at line 46 of file InputPly.h.

Constructor & Destructor Documentation

Nektar::Utilities::InputPly::InputPly ( MeshSharedPtr  m)

Definition at line 52 of file InputPly.cpp.

52  : InputModule(m)
53  {
54 
55  }
Nektar::Utilities::InputPly::~InputPly ( )
virtual

Definition at line 57 of file InputPly.cpp.

58  {
59 
60  }

Member Function Documentation

static ModuleSharedPtr Nektar::Utilities::InputPly::create ( MeshSharedPtr  m)
inlinestatic

Creates an instance of this class.

Definition at line 50 of file InputPly.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

50  {
52  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::Utilities::InputPly::Process ( )
virtual

Populate and validate required data structures.

Parameters
pFilenameFilename of Gmsh file to read.

Implements Nektar::Utilities::Module.

Definition at line 67 of file InputPly.cpp.

References Nektar::Utilities::InputModule::m_mshFile, Nektar::Utilities::InputModule::OpenStream(), Nektar::Utilities::Module::ProcessComposites(), Nektar::Utilities::Module::ProcessEdges(), Nektar::Utilities::Module::ProcessElements(), Nektar::Utilities::Module::ProcessFaces(), Nektar::Utilities::Module::ProcessVertices(), and ReadPly().

68  {
69 
70  // Open the file stream.
71  OpenStream();
72 
74 
75  m_mshFile.close();
76 
78  ProcessEdges();
79  ProcessFaces();
82  }
std::ifstream m_mshFile
Input stream.
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
virtual void ProcessVertices()
Extract element vertices.
virtual void ProcessElements()
Generate element IDs.
virtual void ProcessComposites()
Generate composites.
void ReadPly(std::ifstream &mshFile, NekDouble scale=1.0)
Definition: InputPly.cpp:84
virtual void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
void OpenStream()
Open a file for input.
void Nektar::Utilities::InputPly::ReadPly ( std::ifstream &  mshFile,
NekDouble  scale = 1.0 
)

Definition at line 84 of file InputPly.cpp.

References ASSERTL0, Nektar::LibUtilities::eTriangle, Nektar::Utilities::GetElementFactory(), and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

85  {
86  m_mesh->m_expDim = 0;
87  string line;
88  int nVertices = 0;
89  int nEntities = 0;
90  int nProperties = 0;
92  map<string, int> propMap;
93 
94  if (m_mesh->m_verbose)
95  {
96  cout << "InputPly: Start reading file..." << endl;
97  }
98 
99  while (!mshFile.eof())
100  {
101  getline(mshFile, line);
102  stringstream s(line);
103  string word;
104  s >> word;
105  if(word == "format")
106  {
107  s >> word;
108  if(word != "ascii")
109  {
110  ASSERTL0(false,"InputPly file currently only set up to read ascii formatted ply files");
111  }
112  }
113  else if (word == "element")
114  {
115  s >> word;
116  if (word == "vertex")
117  {
118  s >> nVertices;
119  }
120  else if (word == "face")
121  {
122  s >> nEntities;
123  }
124  continue;
125  }
126  else if (word == "property")
127  {
128  s >> word >> word;
129  propMap[word] = nProperties++;
130  }
131  else if (word == "end_header")
132  {
133  // Read nodes
134  vector<double> data(nProperties);
135  for (int i = 0; i < nVertices; ++i)
136  {
137  getline(mshFile, line);
138  stringstream st(line);
139 
140  for (int j = 0; j < nProperties; ++j)
141  {
142  st >> data[j];
143  }
144 
145  double x = data[propMap["x"]];
146  double y = data[propMap["y"]];
147  double z = data[propMap["z"]];
148 
149  if ((y * y) > 0.000001 && m_mesh->m_spaceDim != 3)
150  {
151  m_mesh->m_spaceDim = 2;
152  }
153  if ((z * z) > 0.000001)
154  {
155  m_mesh->m_spaceDim = 3;
156  }
157 
158  x *= scale;
159  y *= scale;
160  z *= scale;
161 
162 
163  m_mesh->m_node.push_back(
164  boost::shared_ptr<Node>(new Node(i, x, y, z)));
165 
166  // Read vertex normals.
167  if (propMap.count("nx") > 0)
168  {
169  double nx = data[propMap["nx"]];
170  double ny = data[propMap["ny"]];
171  double nz = data[propMap["nz"]];
172  m_mesh->m_vertexNormals[i] = Node(0, nx, ny, nz);
173  }
174  }
175 
176  // Read elements
177  for (int i = 0; i < nEntities; ++i)
178  {
179  getline(mshFile, line);
180  stringstream st(line);
181  int id = 0;
182 
183  // Create element tags
184  vector<int> tags;
185  tags.push_back(0); // composite
186 
187  // Read element node list
188  st >> id;
189  vector<NodeSharedPtr> nodeList;
190  for (int k = 0; k < 3; ++k)
191  {
192  int node = 0;
193  st >> node;
194  nodeList.push_back(m_mesh->m_node[node]);
195  }
196 
197  // Create element
198  ElmtConfig conf(elType,1,false,false);
200  CreateInstance(elType,conf,nodeList,tags);
201 
202  // Determine mesh expansion dimension
203  if (E->GetDim() > m_mesh->m_expDim)
204  {
205  m_mesh->m_expDim = E->GetDim();
206  }
207  m_mesh->m_element[E->GetDim()].push_back(E);
208  }
209  }
210  }
211  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< Element > ElementSharedPtr
Shared pointer to an element.
Definition: MeshElements.h:63
ElementFactory & GetElementFactory()

Member Data Documentation

ModuleKey Nektar::Utilities::InputPly::className
static
Initial value:
=
"Reads ply triangulation format.")

Definition at line 53 of file InputPly.h.