MCPcopy Create free account
hub / github.com/OpenWebCAD/node-occ / extractFaceMesh

Method extractFaceMesh

src/Mesh.cc:100–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100int Mesh::extractFaceMesh(const TopoDS_Face& face, bool qualityNormals)
101{
102
103 if (face.IsNull()) {
104 StdFail_NotDone::Raise("Face is Null");
105 }
106 auto& hashMap = this->_faceHashMap;
107 int hash = face.HashCode(std::numeric_limits<int>::max());
108 // find hash in edgehash.push_back(hash);
109 if (hashMap.end() != hashMap.find(hash)) {
110 return 0;
111 }
112
113 hashMap[hash] = (uint32_t)this->_faceRanges.size();
114 this->_faceRanges.push_back((uint32_t)this->_triangles.size());
115
116 TopLoc_Location loc;
117 occHandle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(face, loc);
118 if (triangulation.IsNull()) {
119 StdFail_NotDone::Raise("No triangulation created");
120 }
121
122 bool reversed = (face.Orientation() == TopAbs_REVERSED);
123 int nb_points = triangulation->NbNodes();
124
125 gp_Trsf tr = loc;
126 std::vector<uint32_t> translationTable;
127 translationTable.reserve(nb_points);
128
129 std::vector<uint32_t> normalTranslationTable;
130 normalTranslationTable.reserve(nb_points);
131
132 // ------------------------------------------------------------------------------
133 // import face points into index
134 // ------------------------------------------------------------------------------
135 const TColgp_Array1OfPnt& nodes = triangulation->Nodes();
136 Coord3f vert;
137 double x, y, z;
138 for (int i = 1; i <= nb_points; i++) {
139 const gp_Pnt& pnt = nodes(i);
140 x = pnt.X();
141 y = pnt.Y();
142 z = pnt.Z();
143 tr.Transforms(x, y, z);
144 vert.x = (float)x;
145 vert.y = (float)y;
146 vert.z = (float)z;
147 uint32_t index = push_point(vert);
148 translationTable.push_back(index);
149 }
150
151 // ------------------------------------------------------------------------------
152 // import vertex normal
153 // ------------------------------------------------------------------------------
154 std::vector<gp_Vec> local_normals;
155 local_normals.reserve(nb_points);
156
157 if (!qualityNormals) {

Callers 2

createMeshMethod · 0.80
createMeshMethod · 0.80

Calls 1

push_normalMethod · 0.95

Tested by

no test coverage detected