CGI/exercise3/src/SurfaceArea.cpp

147 lines
3.1 KiB
C++
Raw Normal View History

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;
}
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;
}
};
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);
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);
}
}
}
}
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;
};
2018-09-06 12:35:43 +00:00
float ComputeSurfaceArea(const HEMesh& m)
{
float area = 0;
/* Task 2.2.2 */
std::cout << "Area computation is not implemented." << std::endl;
2019-01-05 15:44:14 +00:00
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);
SimpleFace simple_face;
for (; fh_it.is_valid(); ++fh_it) {
simple_face.he_handles.emplace_back(*fh_it);
}
if (!simple_face.is_triangulated()) {
need_triangulation = true;
break;
}
simple_faces.emplace_back(simple_face);
}
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;
}
}
2018-09-06 12:35:43 +00:00
return area;
}