Force Push

This commit is contained in:
hodasemi 2019-01-05 16:44:14 +01:00
parent a936625996
commit 54383e6c10
2 changed files with 173 additions and 8 deletions

View file

@ -20,6 +20,39 @@ void CreateCube(HEMesh& mesh)
{
mesh.clear();
/* Task 2.2.1 */
/*
4 ----------- 3
/. /|
/ . / |
/ . / |
1 ----------- 2 |
| 8 . . . . | . 7
| . | /
| . | /
|. |/
5 ----------- 6
*/
std::vector<OpenMesh::VertexHandle> vhandles;
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(0.0f, 0.0f, 1.0f))); // 1
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(1.0f, 0.0f, 1.0f))); // 2
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(1.0f, 1.0f, 1.0f))); // 3
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(0.0f, 1.0f, 1.0f))); // 4
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(0.0f, 0.0f, 0.0f))); // 5
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(1.0f, 0.0f, 0.0f))); // 6
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(1.0f, 1.0f, 0.0f))); // 7
vhandles.push_back(mesh.add_vertex(OpenMesh::Vec3f(0.0f, 1.0f, 0.0f))); // 8
mesh.add_face(vhandles[0], vhandles[1], vhandles[2], vhandles[3]);
mesh.add_face(vhandles[1], vhandles[5], vhandles[6], vhandles[2]);
mesh.add_face(vhandles[5], vhandles[4], vhandles[7], vhandles[6]);
mesh.add_face(vhandles[4], vhandles[0], vhandles[3], vhandles[7]);
mesh.add_face(vhandles[4], vhandles[5], vhandles[1], vhandles[0]);
mesh.add_face(vhandles[6], vhandles[7], vhandles[3], vhandles[2]);
}
void CreateTetrahedron(HEMesh& mesh, float a)

View file

@ -6,10 +6,142 @@
#include <iostream>
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;
};
float ComputeSurfaceArea(const HEMesh& m)
{
float area = 0;
/* Task 2.2.2 */
std::cout << "Area computation is not implemented." << std::endl;
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;
}
}
return area;
}