This commit is contained in:
hodasemi 2019-01-05 16:51:18 +01:00
parent 54383e6c10
commit f396f96f41

View file

@ -15,23 +15,6 @@ struct SimpleFace {
}
return true;
}
std::vector<SimpleFace> triangulate() {
if (he_handles.size() == 3) {
return std::vector<SimpleFace>();
}
std::vector<SimpleFace> simple_faces;
std::vector<OpenMesh::HalfedgeHandle> all_handles = he_handles;
// replace internal handles
std::vector<OpenMesh::HalfedgeHandle> new_handles(he_handles.begin(), he_handles.begin() + 2);
he_handles = new_handles;
}
};
@ -53,31 +36,7 @@ struct Triangles {
Triangles(std::vector<SimpleFace> simple_faces, const HEMesh& m) {
for (auto simple_face: simple_faces) {
std::vector<OpenMesh::Vec3f> points = face_points(simple_face, m);
if (simple_face.is_triangulated()) {
triangles.emplace_back(points);
} else {
// triangulate
std::vector<Triangle> triangles;
std::vector<int> split_indices;
int current_split = 0;
split_indices.emplace_back(current_split);
int i = 0;
while(1) {
if (current_split)
}
// insert triangles (slow, but it works)
for (Triangle triangle : triangles) {
this->triangles.emplace_back(triangle);
}
}
triangles.emplace_back(points);
}
}
@ -98,17 +57,9 @@ struct Triangles {
std::vector<Triangle> triangles;
};
float ComputeSurfaceArea(const HEMesh& m)
{
float area = 0;
/* Task 2.2.2 */
std::cout << "Area computation is not implemented." << std::endl;
bool gather_faces(const HEMesh& m, std::vector<SimpleFace>& simple_faces) {
auto faces = m.all_faces();
std::vector<SimpleFace> simple_faces;
bool need_triangulation = false;
for (auto face_handle : faces) {
HEMesh::ConstFaceHalfedgeIter fh_it = m.cfh_iter(face_handle);
@ -119,13 +70,36 @@ float ComputeSurfaceArea(const HEMesh& m)
}
if (!simple_face.is_triangulated()) {
need_triangulation = true;
break;
return false;
}
simple_faces.emplace_back(simple_face);
}
return true;
}
float ComputeSurfaceArea(const HEMesh& _m)
{
float area = 0;
/* Task 2.2.2 */
std::cout << "Area computation is not implemented." << std::endl;
// copy mesh for mutability
HEMesh private_mesh = _m;
std::vector<SimpleFace> simple_faces;
if (!gather_faces(private_mesh, simple_faces)) {
simple_faces.clear();
private_mesh.triangulate();
if (!gather_faces(private_mesh, simple_faces)) {
abort();
}
}
/*
std::cout << "face count: " << simple_faces.size() << std::endl;
for (auto sf : simple_faces) {
@ -142,6 +116,7 @@ float ComputeSurfaceArea(const HEMesh& m)
std::cout << "vertex handle id: " << vh.idx() << std::endl;
}
}
*/
return area;
}