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:
[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=std::string())
 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, ConfigOptionm_config
 List of configuration values. More...
 

Detailed Description

Converter for Ply files.

Definition at line 46 of file InputPly.h.

Constructor & Destructor Documentation

◆ InputPly()

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

Definition at line 52 of file InputPly.cpp.

52  : InputModule(m)
53 {
54 }
NEKMESHUTILS_EXPORT InputModule(MeshSharedPtr p_m)

◆ ~InputPly()

Nektar::Utilities::InputPly::~InputPly ( )
virtual

Definition at line 56 of file InputPly.cpp.

57 {
58 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 50 of file InputPly.h.

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

51  {
53  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

◆ Process()

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 64 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().

65 {
66 
67  // Open the file stream.
68  OpenStream();
69 
71 
72  m_mshFile.reset();
73 
75  ProcessEdges();
76  ProcessFaces();
79 }
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:81
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.

◆ ReadPly()

void Nektar::Utilities::InputPly::ReadPly ( io::filtering_istream &  mshFile,
NekDouble  scale = 1.0 
)

Definition at line 81 of file InputPly.cpp.

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

Referenced by Process().

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

Member Data Documentation

◆ className

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

Definition at line 54 of file InputPly.h.