Implementation of
a Mesh Simplification Algorithm

ROLE

Graphics Programmer

Graphics Programmer

Tools

VS2022/ C++/ OpenGL/ GLUI

VS2022/ C++/ OpenGL/ GLUI

YEAR

2024

2024

Introduction

This project is my final project for the Computer Graphics course in my third year. It aims to implement an edge-collapse-based mesh simplification algorithm and visualize the process with a GUI interface. The core functionalities of the project include mesh simplification, reading and writing of Obj models, and 3D model display.

Project description

Project description

Project description

I will introduce the specific implementation of four key features: an edge-collapse-based mesh simplification algorithm, the GUI, reading and writing of Obj models, and 3D model display.

edge-collapse-based mesh simplification algorithm

Since most meshes are composed of triangles, simplifying a model can be achieved by reducing the number of triangles, which essentially reduces the number of vertices and edges. In this approach, mesh simplification is carried out by removing edges of the triangles.This method involves maintaining a heap for each edge in the model's mesh graph, where a cost is computed for each edge. In each iteration, the edge with the minimum cost is removed from the heap, and the loss values for the remaining edges are recalculated to update the heap, continuing until the desired simplification ratio is reached.For a collapsed edge (v1, v2), where the new vertex after collapse is vbar, we define the error matrix for vertex vbar as π‘„π‘π‘Žπ‘Ÿ=𝑄1+𝑄2. There are two strategies for computing the position of vertex vbar: 

1. A simple strategy selects the position from v1, v2, or (v1+v2)/2 that minimizes the collapse cost Ξ”(vbar). 

2. A more advanced strategy computes the position of vbar numerically to minimize Ξ”(vbar).

GUI

The core code can be found in the meshSimplify.cpp file within the void myGlui() function. The specific UI layout can be viewed in the system operation demonstration video located in the project’s README folder. Below is an introduction to the key components of the UI:

- Open Button: This button allows the user to select a .obj model from the specified directory. The program can then read the selected model and display it in the 3D view.

- Quit Button: Closes the program.

- Type Panel: This panel contains selection boxes for points, wire, and flat, which are used to toggle between different display modes for the 3D model: 

- points: Displays the model's vertices. 

- wire: Displays the model in a wireframe. 

- flat: Displays the model's faces.

- Simplify Panel: This panel is used to perform the model simplification function. 

- File Textbox: Used to input the filename for saving the simplified model. 

- Ratio Input Box: Used to set the simplification ratio of the model. 

- Simplify Start Button: Begins the model simplification process.

reading and writing of Obj models

The parsing of .obj models is implemented by constructing the CObj class and its member methods. The core code can be found in the CObj class within the ObjParser.cpp file.

3D model display

This part handles all rendering tasks in the 3D view. It includes rendering the 3D scene, drawing all the graphics, and handling user interactions with the model. Specifically, the scene models can be translated, rotated, and scaled. The core code can be found in the myInit() function within meshSimplify.cpp.