MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / extract_surface_from_tets

Method extract_surface_from_tets

src/IO/MSHParser.cpp:127–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127void MSHParser::extract_surface_from_tets() {
128 const VectorI& voxels = m_voxels;
129 const size_t num_vertex_per_voxel = vertex_per_voxel();
130 typedef std::map<Triplet, unsigned short> FaceCounter;
131 FaceCounter face_counter;
132
133 for (size_t i=0; i<voxels.size(); i+= num_vertex_per_voxel) {
134 VectorI voxel = voxels.segment(i, num_vertex_per_voxel);
135 // TODO: only tet mesh is handled.
136 // Note that the order of vertices below are predefined by MSH format,
137 // each face should have normal pointing outward.
138 assert(voxel.size() == 4);
139 Triplet voxel_faces[4] = {
140 Triplet(voxel[0], voxel[2], voxel[1]),
141 Triplet(voxel[0], voxel[1], voxel[3]),
142 Triplet(voxel[0], voxel[3], voxel[2]),
143 Triplet(voxel[1], voxel[2], voxel[3])
144 };
145 for (size_t j=0; j<4; j++) {
146 if (face_counter.find(voxel_faces[j]) == face_counter.end()) {
147 face_counter[voxel_faces[j]] = 1;
148 } else {
149 face_counter[voxel_faces[j]] += 1;
150 }
151 }
152 }
153
154 std::vector<int> vertex_buffer;
155 for (FaceCounter::const_iterator itr = face_counter.begin();
156 itr!=face_counter.end(); itr++) {
157 assert(itr->second == 1 || itr->second == 2);
158 if (itr->second == 1) {
159 const VectorI& f = itr->first.get_ori_data();
160 // TODO: only triangles is handled.
161 assert(f.size() == 3);
162 vertex_buffer.push_back(f[0]);
163 vertex_buffer.push_back(f[1]);
164 vertex_buffer.push_back(f[2]);
165 }
166 }
167
168 m_faces.resize(vertex_buffer.size());
169 std::copy(vertex_buffer.begin(), vertex_buffer.end(), m_faces.data());
170}
171
172void MSHParser::extract_surface_from_hexs() {
173 const VectorI& voxels = m_voxels;

Callers

nothing calls this directly

Calls 5

TripletClass · 0.85
findMethod · 0.80
sizeMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected