-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyHEMesh.h
109 lines (96 loc) · 2.81 KB
/
MyHEMesh.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
#pragma once
#ifndef _MYMESH_H_
#define _MYMESH_H_
#if __INTELLISENSE__ //solve intellisence error on arm mac.
#undef __ARM_NEON //see https://github.com/microsoft/vscode-cpptools/issues/7413
#undef __ARM_NEON__
#endif
#include <vector>
#include <string>
#include <map>
#include <set>
#include <Eigen/Dense>
struct HEdge;
struct Face;
struct Vertex;
struct VertexPair;
struct HEdge {
HEdge* pair = nullptr;
HEdge* next = nullptr; //paired HEdge and next HEdge
Vertex* v; //point at v
Face* f; //left face
bool isBound = false;
};
struct Face {
Vertex* v[3];
HEdge* h; //arbitrary Hedge of the face
};
struct Vertex {
double x, y, z;
unsigned char r=255, g=255, b=255;
Eigen::Matrix4d Q = Eigen::Matrix4d::Zero();
int index; //works when output
HEdge* h = nullptr;
bool isBound = false;
};
inline Eigen::Vector3d GetPosVec(const Vertex* v);
struct VertexPairKey {
Vertex* start;
Vertex* end;
VertexPairKey(Vertex* v1, Vertex* v2) {
start = v1;
end = v2;
}
bool operator< (const VertexPairKey& other) const {
return start == other.start ? end < other.end : start < other.start;
}
};
struct VertexPair {
Vertex* v1;
Vertex* v2;
double cost = INFINITY;
Eigen::Vector4d v;
bool operator< (const VertexPair& other) const {
return cost < other.cost;
}
bool operator> (const VertexPair& other) const {
return cost > other.cost;
}
};
struct VPairPtrGreater {
bool operator() (const VertexPair* v1, const VertexPair* v2) {
return v1->cost > v2->cost;
}
};
class MyHEMesh {
private:
std::map<VertexPairKey, HEdge*> HEdgeMap_;
std::set<Face*> FaceSet_;
std::vector<Vertex*> VertexVec_;
std::set<Vertex*> VertexSet_;
std::vector<VertexPair*> VPairHeap_;
std::set<VertexPairKey> DelVPairSet_;
Vertex* InsertrVertex(double x, double y, double z);
Face* InsertFace(Vertex* v1, Vertex* v2, Vertex* v3);
HEdge* InsertHEdge(Vertex* v1, Vertex* v2);
double BoundPenalty = 10;
bool HasFoldFace(const VertexPair* vpair, const std::vector<Face*>& NeighbFaceVec);
bool IsCollapseable(const std::vector<Vertex*>& VertexVec, const Vertex* v1, const Vertex* v2);
void CheckBound(Vertex* v);
public:
void ReadFromOBJ(const std::string& path);
void SaveToOBJ(const std::string& path);
void UpdateQMatrix(Vertex& v);
void UpdateAllQMatrix();
void UpdateVPairCost(VertexPair* vpair);
void UpdateAllVPairCost();
void MakeVPairHeap();
void ReaddVPair(double threshold);
void ContractModel(long facenum);
void ContractLeastCostPair();
void ContractVPair(VertexPair* vpair);
void ContractInitModel(long v1index, long v2index);
long GetFaceNum() {return FaceSet_.size();}
static Eigen::Vector4d CalcP(const Face* f);
};
#endif