Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 (NekMeshUtils::MeshSharedPtr m)
 
virtual ~InputPly ()
 
virtual void Process ()
 Populate and validate required data structures. More...
 
void ReadPly (io::filtering_istream &mshFile, NekDouble scale=1.0)
 
- Public Member Functions inherited from Nektar::NekMeshUtils::InputModule
NEKMESHUTILS_EXPORT InputModule (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void OpenStream ()
 Open a file for input. More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT Module (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void RegisterConfig (std::string key, std::string value)
 Register a configuration option with a module. More...
 
NEKMESHUTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
NEKMESHUTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
NEKMESHUTILS_EXPORT MeshSharedPtr GetMesh ()
 
virtual NEKMESHUTILS_EXPORT void ProcessVertices ()
 Extract element vertices. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessElements ()
 Generate element IDs. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessComposites ()
 Generate composites. More...
 
virtual NEKMESHUTILS_EXPORT void ClearElementLinks ()
 

Static Public Member Functions

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

Static Public Attributes

static NekMeshUtils::ModuleKey className
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::NekMeshUtils::InputModule
NEKMESHUTILS_EXPORT void PrintSummary ()
 Print summary of elements. More...
 
- Protected Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
NEKMESHUTILS_EXPORT void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::NekMeshUtils::InputModule
io::filtering_istream m_mshFile
 Input stream. More...
 
std::ifstream m_mshFileStream
 Input stream. More...
 
- Protected Attributes inherited from Nektar::NekMeshUtils::Module
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 ( NekMeshUtils::MeshSharedPtr  m)

Definition at line 53 of file InputPly.cpp.

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

Definition at line 57 of file InputPly.cpp.

58 {
59 }

Member Function Documentation

static NekMeshUtils::ModuleSharedPtr Nektar::Utilities::InputPly::create ( NekMeshUtils::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::NekMeshUtils::Module.

Definition at line 65 of file InputPly.cpp.

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

66 {
67 
68  // Open the file stream.
69  OpenStream();
70 
72 
73  m_mshFile.reset();
74 
76  ProcessEdges();
77  ProcessFaces();
80 }
io::filtering_istream m_mshFile
Input stream.
NEKMESHUTILS_EXPORT void OpenStream()
Open a file for input.
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
virtual NEKMESHUTILS_EXPORT void ProcessVertices()
Extract element vertices.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
void ReadPly(io::filtering_istream &mshFile, NekDouble scale=1.0)
Definition: InputPly.cpp:82
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
void Nektar::Utilities::InputPly::ReadPly ( io::filtering_istream &  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(), Nektar::NekMeshUtils::Module::m_mesh, and class_topology::Node.

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:198
Basic information about an element.
Definition: ElementConfig.h:50
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
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49

Member Data Documentation

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

Definition at line 55 of file InputPly.h.