Skip to content

Commit def4a44

Browse files
committed
Add LRZ QEM simplification
1 parent 4ae5daf commit def4a44

File tree

7 files changed

+526
-6
lines changed

7 files changed

+526
-6
lines changed

Model-Modifier/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ set(Source_Files
485485
"src/scene/surface/Surface_CatmullClark.cpp"
486486
"src/scene/surface/Surface_DooSabin.cpp"
487487
"src/scene/surface/Surface_GarlandHeckbert.cpp"
488+
"src/scene/surface/Surface_LiuRahimzadehZordan.cpp"
488489
"src/scene/surface/Surface_Loop.cpp"
489490
"src/scene/util/OrderVertices.cpp"
490491
"src/scene/util/PlaneProjection.cpp"
57.7 KB
Loading

Model-Modifier/src/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,20 @@ int main()
380380
ImGui::Indent();
381381
ImGui::SliderInt("Desired count", &desiredTriCount, triCount/5, triCount);
382382
ImGui::Unindent();
383+
if (ImGui::Button("Liu Rahimzadeh Zordan Simplification Surface"))
384+
{
385+
obj.MakeTriangleMesh(); // Triangulate first
386+
Surface LRZ(obj);
387+
static float alpha = 0.5f; // default balanced weight
388+
obj = LRZ.LineQEM(desiredTriCount, alpha);
389+
ModifyModel = true;
390+
}
391+
ImGui::Indent();
392+
ImGui::SliderInt("Desired count", &desiredTriCount, triCount/5, triCount);
393+
static float alpha = 0.5f;
394+
ImGui::SliderFloat("Alpha (edge preservation)", &alpha, 0.0f, 1.0f);
395+
ImGui::Text("0.0 = smooth, 0.5 = balanced, 1.0 = sharp edges");
396+
ImGui::Unindent();
383397

384398
ImGui::Unindent();
385399
}

Model-Modifier/src/scene/surface/Surface.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ struct ValidPair
4646
bool edge;
4747
float error;
4848
glm::vec3 newVert;
49+
// weight parameter balancing point vs line quadrics
50+
// only for augmented version
51+
float alpha;
4952
};
5053

5154
struct CompareValidPairs
@@ -80,11 +83,16 @@ class Surface
8083
std::unordered_map<unsigned int, std::vector<glm::vec3>> pointsPerEdge
8184
);
8285
Object LoOutputOBJ(std::vector<glm::vec3> edgePoints);
83-
glm::mat4 ComputeQuadric(VertexRecord v0);
86+
// Shared QEM helpers
87+
glm::mat4 ComputePlaneQuadric(VertexRecord v0);
8488
glm::mat4 BuildQuadricSolverMatrix(const glm::mat4& Quad);
8589
void ComputeOptimalVertexAndError(ValidPair& validPair, const glm::mat4& quadric1, const glm::mat4& quadric2);
8690
void UpdateAdjacencyIndices(std::vector<unsigned int>& adjFaces, const std::vector<unsigned int>& removedFaceIndices);
87-
Object GHOutputOBJ();
91+
Object QEMOutputOBJ(); // shared output builder for both QEM variants
92+
// Line Quadric specific helpers
93+
glm::vec3 ComputeVertexNormal(VertexRecord v0);
94+
glm::mat4 ComputeLineQuadric(VertexRecord v0);
95+
glm::mat4 ComputeWeightedQuadric(const glm::mat4& planeQuadric, const glm::mat4& lineQuadric, float alpha);
8896

8997
// Modification algorithms
9098
Object Beehive();
@@ -93,6 +101,7 @@ class Surface
93101
Object DooSabin();
94102
Object Loop();
95103
Object QEM(unsigned int desiredCount);
104+
Object LineQEM(unsigned int desiredCount, float alpha = 0.5f);
96105

97106
public:
98107
std::vector<VertexRecord> m_Vertices;

Model-Modifier/src/scene/surface/Surface_GarlandHeckbert.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
////////// helpers to build the Object //////////
55

6-
Object Surface::GHOutputOBJ()
6+
// Shared output builder for both QEM and LineQEM
7+
Object Surface::QEMOutputOBJ()
78
{
89
// build new Object class
910
std::vector<glm::vec3> VertexPos;
@@ -53,7 +54,7 @@ Object Surface::GHOutputOBJ()
5354
////////// helpers for the GH algorithm //////////
5455

5556
// computer quadric matrix by summing all K_p matrices of a vertice v0
56-
glm::mat4 Surface::ComputeQuadric(VertexRecord v0)
57+
glm::mat4 Surface::ComputePlaneQuadric(VertexRecord v0)
5758
{
5859
glm::mat4 quadric{ 0.0f };
5960
// for each neighbouring face, compute K_p
@@ -179,7 +180,7 @@ Object Surface::QEM(unsigned int desiredCount)
179180

180181
for (unsigned int i = 0; i < numVertices; i++)
181182
{
182-
glm::mat4 quadric = ComputeQuadric(m_Vertices[i]);
183+
glm::mat4 quadric = ComputePlaneQuadric(m_Vertices[i]);
183184

184185
// add penalty quadric for boundary vertices
185186
bool isBoundaryVertex = false;
@@ -517,5 +518,5 @@ Object Surface::QEM(unsigned int desiredCount)
517518
}
518519
}
519520

520-
return GHOutputOBJ();
521+
return QEMOutputOBJ();
521522
}

0 commit comments

Comments
 (0)