Skip to content

Instantly share code, notes, and snippets.

@christopherhelf
Created March 10, 2015 16:20
Show Gist options
  • Save christopherhelf/326adcbe0ced08d88bec to your computer and use it in GitHub Desktop.
Save christopherhelf/326adcbe0ced08d88bec to your computer and use it in GitHub Desktop.
MeshConversion Openmesh
bool IsotropicRemesher::getMesh(TriMesh& mesh) {
OpenMesh::VPropHandleT<int> id;
mesh.add_property(id);
std::vector<TriMesh::VertexHandle> vHandles;
for(int i=0; i<nPointsIn; i++) {
PointM pt = getPoint(this->pointsIn, i);
/*PointM is a simple Point struct, pointsIn contains my points*/
TriMesh::VertexHandle vhandle = mesh.add_vertex(TriMesh::Point(pt.x, pt.y, pt.z));
mesh.property(id,vhandle) = i;
vHandles.push_back(vhandle);
}
std::vector<TriMesh::VertexHandle> face_vhandles;
int nF = this->nfacetsIn;
for(int i=0; i<nF; i++) {
FacetM ft = getFacet(this->facetsIn, i);
/*FacetM is a simple Facet struct, facetsIn contains the ids of the points*/
face_vhandles.clear();
face_vhandles.push_back(vHandles[ft.a]);
face_vhandles.push_back(vHandles[ft.b]);
face_vhandles.push_back(vHandles[ft.c]);
mesh.add_face(face_vhandles);
}
mesh.request_edge_status();
mesh.request_halfedge_status();
mesh.request_face_status();
mesh.request_vertex_status();
mesh.request_face_normals();
mesh.request_vertex_normals();
if (!mesh.has_face_normals() || !mesh.has_vertex_normals() ) mesh.update_normals();
// Features
if(nFeaturesIn > 0) {
TriMesh::EdgeIter e_it;
TriMesh::EdgeIter e_end = mesh.edges_end();
for (e_it = mesh.edges_sbegin(); e_it != e_end; ++e_it) {
const TriMesh::HalfedgeHandle & hh = mesh.halfedge_handle( *e_it, 0 );
const TriMesh::VertexHandle & v0 = mesh.from_vertex_handle(hh);
const TriMesh::VertexHandle & v1 = mesh.to_vertex_handle(hh);
int a = mesh.property(id,v0);
int b = mesh.property(id,v1);
if(isFeatureVertex(a) && isFeatureVertex(b)) {
mesh.status( *e_it ).set_feature( true );
}
}
}
mesh.remove_property(id);
mesh.garbage_collection();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment