Skip to content
Merged

Lrz #41

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,11 @@ MigrationBackup/
# Executables
*.exe
*.out
*.app
*.app

## CMake build
CMakeFiles/
*.vcxproj*
cmake_install.cmake
CMakeCache.txt
*.sln
1 change: 1 addition & 0 deletions Model-Modifier/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ set(Source_Files
"src/scene/surface/Surface_CatmullClark.cpp"
"src/scene/surface/Surface_DooSabin.cpp"
"src/scene/surface/Surface_GarlandHeckbert.cpp"
"src/scene/surface/Surface_LiuRahimzadehZordan.cpp"
"src/scene/surface/Surface_Loop.cpp"
"src/scene/util/OrderVertices.cpp"
"src/scene/util/PlaneProjection.cpp"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Model-Modifier/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,20 @@ int main()
ImGui::Indent();
ImGui::SliderInt("Desired count", &desiredTriCount, triCount/5, triCount);
ImGui::Unindent();
if (ImGui::Button("Liu Rahimzadeh Zordan Simplification Surface"))
{
obj.MakeTriangleMesh(); // Triangulate first
Surface LRZ(obj);
static float alpha = 0.5f; // default balanced weight
obj = LRZ.LineQEM(desiredTriCount, alpha);
ModifyModel = true;
}
ImGui::Indent();
ImGui::SliderInt("Desired count", &desiredTriCount, triCount/5, triCount);
static float alpha = 0.5f;
ImGui::SliderFloat("Alpha (edge preservation)", &alpha, 0.0f, 1.0f);
ImGui::Text("0.0 = smooth, 0.5 = balanced, 1.0 = sharp edges");
ImGui::Unindent();

ImGui::Unindent();
}
Expand Down
13 changes: 11 additions & 2 deletions Model-Modifier/src/scene/surface/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ struct ValidPair
bool edge;
float error;
glm::vec3 newVert;
// weight parameter balancing point vs line quadrics
// only for augmented version
float alpha;
};

struct CompareValidPairs
Expand Down Expand Up @@ -80,11 +83,16 @@ class Surface
std::unordered_map<unsigned int, std::vector<glm::vec3>> pointsPerEdge
);
Object LoOutputOBJ(std::vector<glm::vec3> edgePoints);
glm::mat4 ComputeQuadric(VertexRecord v0);
// Shared QEM helpers
glm::mat4 ComputePlaneQuadric(VertexRecord v0);
glm::mat4 BuildQuadricSolverMatrix(const glm::mat4& Quad);
void ComputeOptimalVertexAndError(ValidPair& validPair, const glm::mat4& quadric1, const glm::mat4& quadric2);
void UpdateAdjacencyIndices(std::vector<unsigned int>& adjFaces, const std::vector<unsigned int>& removedFaceIndices);
Object GHOutputOBJ();
Object QEMOutputOBJ(); // shared output builder for both QEM variants
// Line Quadric specific helpers
glm::vec3 ComputeVertexNormal(VertexRecord v0);
glm::mat4 ComputeLineQuadric(VertexRecord v0);
glm::mat4 ComputeWeightedQuadric(const glm::mat4& planeQuadric, const glm::mat4& lineQuadric, float alpha);

// Modification algorithms
Object Beehive();
Expand All @@ -93,6 +101,7 @@ class Surface
Object DooSabin();
Object Loop();
Object QEM(unsigned int desiredCount);
Object LineQEM(unsigned int desiredCount, float alpha = 0.5f);

public:
std::vector<VertexRecord> m_Vertices;
Expand Down
15 changes: 8 additions & 7 deletions Model-Modifier/src/scene/surface/Surface_GarlandHeckbert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

////////// helpers to build the Object //////////

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

// computer quadric matrix by summing all K_p matrices of a vertice v0
glm::mat4 Surface::ComputeQuadric(VertexRecord v0)
glm::mat4 Surface::ComputePlaneQuadric(VertexRecord v0)
{
glm::mat4 quadric{ 0.0f };
// for each neighbouring face, compute K_p
Expand All @@ -74,9 +75,9 @@ glm::mat4 Surface::ComputeQuadric(VertexRecord v0)
glm::mat4 Surface::BuildQuadricSolverMatrix(const glm::mat4& Quad)
{
glm::mat4 MatQ;
MatQ[0][0] = Quad[0][0]; MatQ[1][0] = Quad[1][0]; MatQ[2][0] = Quad[2][0]; MatQ[3][0] = Quad[3][0];
MatQ[0][1] = Quad[0][1]; MatQ[1][1] = Quad[1][1]; MatQ[2][1] = Quad[2][1]; MatQ[3][1] = Quad[3][1];
MatQ[0][2] = Quad[0][2]; MatQ[1][2] = Quad[1][2]; MatQ[2][2] = Quad[2][2]; MatQ[3][2] = Quad[3][2];
MatQ[0][0] = Quad[0][0]; MatQ[1][0] = Quad[0][1]; MatQ[2][0] = Quad[0][2]; MatQ[3][0] = Quad[0][3];
MatQ[0][1] = Quad[0][1]; MatQ[1][1] = Quad[1][1]; MatQ[2][1] = Quad[1][2]; MatQ[3][1] = Quad[1][3];
MatQ[0][2] = Quad[0][2]; MatQ[1][2] = Quad[1][2]; MatQ[2][2] = Quad[2][2]; MatQ[3][2] = Quad[2][3];
MatQ[0][3] = 0; MatQ[1][3] = 0; MatQ[2][3] = 0; MatQ[3][3] = 1;
return MatQ;
}
Expand Down Expand Up @@ -179,7 +180,7 @@ Object Surface::QEM(unsigned int desiredCount)

for (unsigned int i = 0; i < numVertices; i++)
{
glm::mat4 quadric = ComputeQuadric(m_Vertices[i]);
glm::mat4 quadric = ComputePlaneQuadric(m_Vertices[i]);

// add penalty quadric for boundary vertices
bool isBoundaryVertex = false;
Expand Down Expand Up @@ -517,5 +518,5 @@ Object Surface::QEM(unsigned int desiredCount)
}
}

return GHOutputOBJ();
return QEMOutputOBJ();
}
Loading