0% found this document useful (0 votes)
8 views

A1

The document outlines Exercise 1 for Computer Graphics I, focusing on polygon mesh processing, with a due date of November 7th, 2024. It includes theoretical tasks related to transformations and matrix operations, as well as practical tasks involving C++ programming for mesh generation, surface area and volume calculations, and vertex valence computations. The exercise emphasizes the use of OpenMesh's halfedge data structure and provides instructions for downloading and setting up the source code for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

A1

The document outlines Exercise 1 for Computer Graphics I, focusing on polygon mesh processing, with a due date of November 7th, 2024. It includes theoretical tasks related to transformations and matrix operations, as well as practical tasks involving C++ programming for mesh generation, surface area and volume calculations, and vertex valence computations. The exercise emphasizes the use of OpenMesh's halfedge data structure and provides instructions for downloading and setting up the source code for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Computer Graphics I, WS 2024/2025

Exercise 1: Polygon Mesh Processing Due date: November 7th , 11:59pm

1 Polygon Mesh Processing


The practical part of this exercise is the first in a 2-part complex of tasks about processing surfaces repre-
sented as polygonal meshes. This exercise focuses on computations which can be accomplished on a simple
mesh data structure without advanced connectivity information.
The theory part is reviewing transformations and their representation as matrices.
All exercises and source code is property of the Chair of Computer Graphics and Visualization. Pub-
lication and distribution is prohibited.

1.1 Theory (5 Points)


1.1.1 Vectors, Matrices, Transforms (2.5 Points)

(a) Transforms like rotations, scalings, translations, or reflections can be represented by matrices. What
is the geometric meaning of multiplying these matrices and how can the inverse of a transform be
interpreted? Explain briefly. (0.5 Point)
(b) The matrix product does not commute in general. Which of the following products are exceptions that
do commute? R1 · R2 , T1 · T2 , S1 · S2 , R · T , R · S, S · T . The symbols R, S, and T represent rotation,
scaling, and translation matrices, respectively. Explain your answer for both cases (commuting and
non-commuting). (2 Points)

1.1.2 Four Interpretations of the Matrix Product (2.5 Points)

Depending on the problem, different interpretations of the matrix product can be helpful. The following list
describes the four views at a simple 2 × 2 example.
 
b11 b12
   b21 b22   
a11 a12 c11 c12 a11 b11 + a12 b21 a11 b12 + a12 b21
=
a21 a22 c21 c22 a21 b11 + a22 b21 a21 b12 + a22 b21

Dot Product An element cij is the dot product of row i of A and the column j of B. Example: c11 =
⟨(a11 a12 ), (b11 b21 )⟩

Linear Combination of Rows A row of C is the linear combination of the rows of B with coefficients from
the respective row in A. Example: (c11 c12 ) = a11 · (b11 b12 ) + a12 · (b21 b22 )
Linear Combination of Columns A column of C is the linear combination of the columns of A with coef-
ficients from the respective column in B. Example: (c11 c21 )T = b11 · (a11 a21 )T + b21 · (a12 a22 )T

Sum of Outer Products The matrix C is the sum of the outer products of the k-th column of A with the
k-th row of B. Example: C = (a11 a21 )T · (b11 b12 ) + (a12 a22 )T · (b21 b22 )

1
Computer Graphics I, WS 2024/2025
Exercise 1: Polygon Mesh Processing Due date: November 7th , 11:59pm

Tasks:

(a) Given a set of n points in form of a 3 × n matrix P , where every column represents one point pi . Find
a matrix product that swaps all y and z components of each point in P . (0.5 Points)
(b) Find the matrix product that produces the sum of all points (which can be used for, e.g., centroid
calculations). (0.5 Points)
(c) When setting up a view frustum for perspective projection with depth buffering, the near and far
clipping planes (znear und zf ar ) have to be known. These are distances from the eye e that bound the
view frustum along the normalized view direction d. ˆ The distances znear und zf ar should be chosen
such that the frustum is tight and all object points are within the frustum (see figure 1). To find these
distances, the points pi have to be projected onto dˆ and the minimum and maximum distance have
to be found. Let the point positions be given in form of the matrix P . e and dˆ are given as column

zfar

(
P = p1 | p2 | ... | pn ) p1
znear
… p2
p3
y d̂
e
x

Figure 1: Determination of znear and zf ar

vectors. Find a compact expression (meaning that it can be used to express the solution with a single
equation) that produces a row vector containing the projected distances for each point. znear and zf ar
are the minimum and maximum of this vector, repsectively. (1 Points)
Calculate a specific example with the following values: e = (5, 10, 5)T , d⃗ = (−2, −1, −1)T and
 
−1 2 2 −1 3
P =  −1 1 1 −2 −1 
1 −2 −3 1 0
Then, determine znear and zf ar . (0.5 Points)

Hint: You can denote a m × n matrix that is filled with 1 with 1m×n . Attention: In contrast to
ˆ the direction d⃗ is not normalized.
d,

1.1.3 Bonus Task (max. +2 Points)

Given a plane through the origin with normal ⃗n. Derive a transformation matrix N that is able to reflect
directions ⃗r at the plane through r⃗′ = N · ⃗r. Draw a figure in which you define the orientations of the
incoming and outgoing directions.

2
Computer Graphics I, WS 2024/2025
Exercise 1: Polygon Mesh Processing Due date: November 7th , 11:59pm

1.2 Practical Part (9 Points)


Remarks regarding the source code

You are given a C++ project collection that you are supposed to extend. The build system uses CMake and
can thus be built and run on all common platforms with a conforming C++17 compiler. In the following
section, you will find a short introduction to CMake and instructions on how to download and compile the
source code. For this, you will need a Git client and CMake (https://cmake.org/). Obviously, you
also need a working compiler suite.

Step 1: Downloading the source code The source code is distributed via a git repository under the address
https://bitbucket.org/cgvtud/cg1.git. In a first step, you have to clone this repository onto
your local machine. Make sure that you clone the repository recursively to resolve all dependencies (those
are realized as submodules). Using the command line, this can be done as follows:
git clone https://bitbucket.org/cgvtud/cg1.git --recursive

Should you omit the recursive option by accident, you have to recursively initialize all submodules after
that.

Step 2: Create the projects CMake generates project files for your chosen build system (e.g., a Visual
Studio solution or Makefiles for gcc). If your development environment supports CMake (e.g. Visual Studio
≥ 2017 or KDevelop), you can open the cloned folder directly in your development environment. Otherwise,
you use the CMake application to generate project files.
if you want to use the CMake-GUI, open the GUI and enter the path of the cloned folder under Where is the
source code. Then, enter a new build folder under Where to build the binaries. This is the folder where the
project files will be created. We recommend to create a new folder (e.g., build) at the root of the cloned
folder. After entering the two paths, click Configure, Generate, and Open Project to generate the project
collection and open it.
If you want to use the command line, navigate to the cloned folder and execute the following commands.
The last command assumes that you use make as your build system and compiles all exercises. The option
j8 forces the compiler to use 8 processors.
mkdir build
cd build
cmake ..
make -j8

Step 3: Develop You are ready to solve the exercise now. Open the source code in your development envi-
ronment and start editing. The code is comprised of several subprojects. These subprojects include multiple
ExerciseX projects, where each represents the application for one of the exercises. For testing purposes,
make sure that you are starting the correct project (e.g., you have to set an appropriate startup project under
Visual Studio). Now, run the program for the first exercise and test if everything starts correctly.

3
Computer Graphics I, WS 2024/2025
Exercise 1: Polygon Mesh Processing Due date: November 7th , 11:59pm

Remarks regarding the OpenGL version


To run the practical exercises, your machine must at least have OpenGL 3.0 and GLSL 1.3. This standard
has been ratified in 2008 and should be supported on virtually all common graphics cards. You can test if
your machine supports the required OpenGL version by starting the project or the solution. If your OpenGL
version is too old, the console prints the following error: ,,ERROR: YOUR VERSION OF OPENGL IS
TOO OLD!”. In this case, please try to update your graphics driver or use the PCs in the computer pools of
the department.
Remarks regarding the halfedge datastructure implementation
The exercise uses OpenMesh’s halfedge data structure to represent polygon meshes. The data structure
can be accessed via the type HEMesh (which is actually a typedef of OpenMesh::PolyMesh_Array-
KernelT<>). Make yourself familiar with the data structure by looking at the online documentation and
the code examples in the appendix at the end of this exercise sheet.
NOTE: for this exercise, you do NOT need to to know about halfedges and related concepts! OpenMesh
provides facilities for basic mesh access also, and those are sufficient to solve this exercise.

1.2.1 Mesh Generation (1 Point)

Implement the creation of a unit cube in function CreateCube in file Primitives.cpp. The file
already contains other primitives, which you can use for reference. You can choose several primitives in the
GUI using the corresponding buttons.

1.2.2 Surface Area and Volume Calculation (2 Points)

After solving the following tasks, you can test the functionality using the respective GUI buttons. These will
display a message box with the calculated measures. You can sanity-check your implementation with a unit
cube (surface area 6, volume 1).

(a) Implement the calculation of surface area of triangle meshes in function ComputeSurfaceArea
in file SurfaceArea.cpp. (0.5 Points)
(b) Extend the method such that it can be used for arbitrary polygon meshes. (1 Point)
(c) Implement the calculation of the enclosed volume of a closed triangle mesh in function
ComputeVolume in file Volume.cpp. (0.5 Points)

1.2.3 Computing Vertex Valence (6 points)

Despite having no advanced connectivity information, many computations can still be done efficiently on a
simple mesh data structure if they are to be performed for the whole mesh instead of for individual elements.
One such example is the computation of vertex valence, which is defined as the number of edges incident to
a node/vertex. Equivalent definitions include the number of directly connected or adjacent vertices, or the
size of the 1-ring of the vertex. In this task, you will implement computation of a valence histogram showing
how many vertices in the mesh have a certain valence.

4
Computer Graphics I, WS 2024/2025
Exercise A: OpenMesh Due date: ERROR

(a) Custom attributes: We will store vertex valence as an additional per-vertex attribute. For conve-
nience, OpenMesh should manage storage for it, meaning that you will have to register an additional
custom vertex attribute with the mesh.
Define an OpenMesh attribute type suitable for storing valence per vertex by completing the defini-
tion of VertexValenceProperty in Valence.h. (1 Point). You will implement two strategies
for valence computation, so edit the function AddValenceProperties() in Valence.cpp
such that it registers two instances of your custom property with the mesh and return the resulting
handles in the fields of the result struct. (0.5 Points)
Hint: you can use the other custom attributes defined in Viewer.h as a reference.
(b) Using face incidence: In a closed manifold mesh, the valence of a vertex is equivalent to its number of
incident faces, simplifying the algorithm. Implement the function ComputeVertexFaceValences()
such that it computes the number of faces incident to each vertex using only information available in
a simple mesh data structure, and store the results in your custom valence property. (1.5 Points)
The results of your computation should be presented in the form of a histogram. Implement the
function ComputeValenceHistogram() to turn the per-vertex valence information into a his-
togram of how many vertices have a certain valence. (1 Point).
You can check your results with the procedural primitives available from the GUI – except for the
disc and the quad, all are closed meshes without boundary. For example, all torus vertices should have
valence 4 (or 6, if the mesh was triangulated by a previous volume query).
(c) Using vertex adjacency: For a mesh with boundaries, relying on face incidence gives incorrect re-
sults. Implement the function ComputeVertexVertexValences() such that it counts the ac-
tual adjacent vertices forming the 1-ring in an efficient way using only information available from a
simple mesh data structure. (2 Points) In the context of mesh processing, an algorithm computing
information for a whole mesh can be considered efficient if it scales linearly with the size of the mesh.

Submission
Zip all source code files in the folder exercise1_2 that you modified for exercise 1 into a zip archive and
upload it to Opal.

A OpenMesh
You can find the online documentation of OpenMesh under
https://www.graphics.rwth-aachen.de/media/openmesh_static/Documentations/
OpenMesh-Doc-Latest/index.html
The following pages present a few important usage details.
All operations and queries on a mesh data structure are done through element handles. Possible handle types
are:

• OpenMesh::VertexHandle
• OpenMesh::EdgeHandle
• OpenMesh::FaceHandle
• OpenMesh::HalfedgeHandle (relevant for next exercise)

5
Computer Graphics I, WS 2024/2025
Exercise A: OpenMesh Due date: ERROR

Sometimes, it is necessary to use element indices instead of element handles. In this case, the .idx()
method of the handles can be used. To convert an index back to a handle, you can use (here, for vertices)
mesh.vertex_handle(idx).
Modern OpenMesh also introduces smart handles extending the plain element handles, which allow very
easy and concise access to linked mesh elements:

• face.vertices(): a C++ range object enumerating all vertices incident to the given face
• face.edges(): a C++ range object enumerating all edges (i.e.vertex pairs in face winding order)
of the given face
• edge.v0(): the first vertex of the pair forming the edge
• edge.v1(): the second vertex of the pair forming the edge
• ...

Similarly, the list of all mesh elements of a certain kind can be queried directly from the mesh, in the
ascending order of their internal indices:

• mesh.faces(): a C++ range object enumerating all faces in the mesh


• mesh.vertices(): a C++ range object enumerating all vertices in the mesh
• ...

A.1 Access to Vertex Attributes


• Vertex position: mesh.point(vertexHandle)
• Texture coordinate: mesh.set_texcoord2D(vertexHandle, texCoord)
• Custom attribute: mesh.property(propertyHandle, elementHandle)

The attributes are usually represented as OpenMesh vectors. Use the utility function from util/OpenMeshUtils.h
to convert between OpenMesh vectors and Eigen vectors.

You might also like