Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (std::string key, std::string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 
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...
 
virtual void ClearElementLinks ()
 

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 ()
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::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...
 
std::map< std::string,
ConfigOption
m_config
 List of configuration values. More...
 

Detailed Description

Converter for Ply files.

Definition at line 47 of file InputPly.h.

Constructor & Destructor Documentation

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

Definition at line 53 of file InputPly.cpp.

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

Definition at line 57 of file InputPly.cpp.

58 {
59 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 51 of file InputPly.h.

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

52  {
54  }
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 65 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().

66 {
67 
68  // Open the file stream.
69  OpenStream();
70 
72 
73  m_mshFile.close();
74 
76  ProcessEdges();
77  ProcessFaces();
80 }
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:82
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 82 of file InputPly.cpp.

References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), Nektar::LibUtilities::eTriangle, Nektar::NekMeshUtils::GetElementFactory(), and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

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

Member Data Documentation

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

Definition at line 55 of file InputPly.h.