2019-01-05 15:44:14 +00:00
|
|
|
|
// This source code is property of the Computer Graphics and Visualization
|
|
|
|
|
// chair of the TU Dresden. Do not distribute!
|
2018-09-06 12:35:43 +00:00
|
|
|
|
// Copyright (C) CGV TU Dresden - All Rights Reserved
|
|
|
|
|
|
|
|
|
|
#include "SurfaceArea.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2019-01-05 15:44:14 +00:00
|
|
|
|
struct SimpleFace {
|
|
|
|
|
std::vector<OpenMesh::HalfedgeHandle> he_handles;
|
|
|
|
|
|
|
|
|
|
bool is_triangulated() {
|
|
|
|
|
if (he_handles.size() != 3) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Triangle {
|
|
|
|
|
Triangle(std::vector<OpenMesh::Vec3f> vpoints) {
|
|
|
|
|
if (vpoints.size() != 3) {
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
points[i] = vpoints[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenMesh::Vec3f points[3];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
2019-01-05 15:51:18 +00:00
|
|
|
|
triangles.emplace_back(points);
|
2019-01-05 15:44:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<OpenMesh::Vec3f> face_points(SimpleFace& simple_face, const HEMesh& m) {
|
|
|
|
|
std::vector<OpenMesh::Vec3f> points;
|
|
|
|
|
|
|
|
|
|
for (auto he : simple_face.he_handles) {
|
|
|
|
|
OpenMesh::VertexHandle vertex_handle = m.from_vertex_handle(he);
|
|
|
|
|
|
|
|
|
|
points.emplace_back(m.point(vertex_handle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return points;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float surface_area() { return 0.0f; }
|
|
|
|
|
|
|
|
|
|
std::vector<Triangle> triangles;
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-05 15:51:18 +00:00
|
|
|
|
bool gather_faces(const HEMesh& m, std::vector<SimpleFace>& simple_faces) {
|
2019-01-05 15:44:14 +00:00
|
|
|
|
auto faces = m.all_faces();
|
|
|
|
|
|
|
|
|
|
for (auto face_handle : faces) {
|
|
|
|
|
HEMesh::ConstFaceHalfedgeIter fh_it = m.cfh_iter(face_handle);
|
|
|
|
|
|
|
|
|
|
SimpleFace simple_face;
|
|
|
|
|
|
|
|
|
|
for (; fh_it.is_valid(); ++fh_it) {
|
|
|
|
|
simple_face.he_handles.emplace_back(*fh_it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!simple_face.is_triangulated()) {
|
2019-01-05 15:51:18 +00:00
|
|
|
|
return false;
|
2019-01-05 15:44:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
simple_faces.emplace_back(simple_face);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 15:51:18 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2019-01-05 15:44:14 +00:00
|
|
|
|
std::cout << "face count: " << simple_faces.size() << std::endl;
|
|
|
|
|
|
|
|
|
|
for (auto sf : simple_faces) {
|
|
|
|
|
std::cout << "half edge count: " << sf.he_handles.size() << std::endl;
|
|
|
|
|
|
|
|
|
|
std::vector<OpenMesh::VertexHandle> vertex_handles;
|
|
|
|
|
|
|
|
|
|
for (auto he: sf.he_handles) {
|
|
|
|
|
vertex_handles.emplace_back(m.to_vertex_handle(he));
|
|
|
|
|
vertex_handles.emplace_back(m.from_vertex_handle(he));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto vh: vertex_handles) {
|
|
|
|
|
std::cout << "vertex handle id: " << vh.idx() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-05 15:51:18 +00:00
|
|
|
|
*/
|
2019-01-05 15:44:14 +00:00
|
|
|
|
|
2018-09-06 12:35:43 +00:00
|
|
|
|
return area;
|
|
|
|
|
}
|