-
Notifications
You must be signed in to change notification settings - Fork 0
/
meshcontractor.h
executable file
·122 lines (113 loc) · 4.06 KB
/
meshcontractor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef SEGMENTCONTRACTOR_H
#define SEGMENTCONTRACTOR_H
//#include <algorithm>
#include <vector>
#include <CGAL/Polygon_mesh_processing/Weights.h>
//#include <CGAL/Polygon_mesh_processing/measure.h>
#include <CGAL/Polygon_mesh_processing/triangulate_hole.h>
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
#include <CGAL/extract_mean_curvature_flow_skeleton.h>
#include <Eigen/Eigen>
#include <Eigen/Sparse>
#include <boost/graph/graph_traits.hpp>
#include "cgaltypedefs.h"
// Cotangent weight calculator
using Weight_calculator = CGAL::internal::Cotangent_weight<
CGALSurfaceMesh,
boost::property_map<CGALSurfaceMesh, boost::vertex_point_t>::type,
CGAL::internal::Cotangent_value_minimum_zero<
CGALSurfaceMesh,
boost::property_map<CGALSurfaceMesh, boost::vertex_point_t>::type,
CGAL::internal::Cotangent_value_Meyer_secure<CGALSurfaceMesh>>>;
using halfedge_descriptor =
boost::graph_traits<CGALSurfaceMesh>::halfedge_descriptor;
using EigenMatrix = Eigen::MatrixXd;
using Vector = Eigen::VectorXd;
using SpMatrix = Eigen::SparseMatrix<double>;
using DiagMatrix = Eigen::Diagonal<double>;
using EigenTriplet = Eigen::Triplet<double>;
static constexpr double maxNumber{500000};
class MeshContractor {
public:
MeshContractor() {}
MeshContractor(
CGALSurfaceMesh meshToContract /*, std::vector<uint> indices*/);
CGALSurfaceMesh getContractedMesh() const;
size_t contractMesh();
void executeContractionStep();
void executeContractionReversingStep();
void setVolumeThreshold(double volumeThreshold);
//~~~~~~~~DEBUG~~~~~~
typedef CGAL::Mean_curvature_flow_skeletonization<CGALSurfaceMesh>
Skeletonization;
void executeCGALContraction() { /*Skeletonization mcs(m_M);*/
}
size_t getMaxLToWhIndex() { return maxLtoWhIndex; }
size_t getPreviousMaxLToWhIndex() { return previousMaxLtoWhIndex; }
std::vector<size_t> getVerticesForWhichPreviousCotWeightWasUsed() {
return problematicVertices;
}
std::vector<size_t> getLowOneRingAreaVertices() {
return std::vector<size_t>{lowOneRingAreaVertices.begin(),
lowOneRingAreaVertices.end()};
}
std::vector<size_t> getHighOneRingAreaVertices() {
return std::vector<size_t>{highOneRingAreaVertices.begin(),
highOneRingAreaVertices.end()};
}
void printFixedVertices(EigenMatrix verticesMatrix);
std::vector<double> getLaplacianValues();
private:
// CGALSurfaceMesh &m_M;
CGALSurfaceMesh m_M;
double m_originalVolume;
static double m_volumeThreshold; // m_originalVolume/currentVolume
// least ratio so the
double m_originalArea;
static double m_areaThreshold;
// contraction process stops
double m_Sl{2};
SpMatrix m_Wh;
double m_Wh0{1.0};
SpMatrix m_Wl;
SpMatrix m_L;
SpMatrix previousLaplaceOperator;
EigenMatrix m_previousDeltaCoords;
Vector m_A0;
Vector m_A;
Eigen::MatrixXi F;
static constexpr size_t m_maxNumOfIterations{100};
size_t m_iterationsCompleted{0};
std::set<size_t> lowOneRingAreaVertices;
std::set<size_t> highOneRingAreaVertices;
std::vector<double> m_initialFaceAreas;
std::vector<bool> isVertexFixed;
std::vector<EigenMatrix> m_previousVertexPositions;
private:
void computeLaplaceOperator();
void computeFixedVertices();
SpMatrix computeLaplaceOperatorUsingIGL();
double computeAngleOppositeToEdge(CGALSurfaceMesh::Edge_index,
size_t edgeSide) const;
EigenMatrix constructVertexMatrix() const;
EigenMatrix solveForNewVertexPositions(
EigenMatrix currentVertexPositions);
void updateMeshPositions(EigenMatrix Vnew);
void detectDegeneracies();
void updateWl();
void updateWh();
void computeOneRingAreaVector();
double computeOneRingAreaAroundVertex(
CGALSurfaceMesh::Vertex_index) const;
boost::optional<double> computeCotangentWeight(
CGALSurfaceMesh::edge_index ei);
boost::optional<double> computeCotangentWeight(
CGALSurfaceMesh::halfedge_index hei);
boost::optional<double> computeCotangentValue(Kernel::Vector_3,
Kernel::Vector_3);
int maxLtoWhIndex{-1};
int previousMaxLtoWhIndex{-1};
std::vector<size_t> problematicVertices;
bool m_degenerateFaceIsPresent{false};
};
#endif // SEGMENTCONTRACTOR_H