Open Mesh
Open Mesh
OpenMesh
ACG RWTHAachen
ACG
RWTH Aachen
C++library
Implementshalfedgedatastructure
l
h lf d d
Integratedbasicgeometricoperations
3Dmodelfilereader/writer
OpenMesh
Flexible
Randomaccesstovertices,edges,andfaces
Arbitraryscalartypes
y
yp
Arraysorlistsasunderlyingkernels
Efficientinspaceandtime
Efficient in space and time
Dynamicmemorymanagementforarraybased
meshes
Extendabletospecializedkernelsfornonmanifold
meshes
Exercise 1
Exercise1
ValenceViewer
Valence Viewer
Exercise 1
Exercise1
MicrosoftVisualStudio2008
Microsoft Visual Studio 2008
Solutionfilehastwoprojects:
S l i fil h
j
OpenMesh library
compileitonce
neverneedtoedit
GLUTbasedmeshviewer
GLUT b d
h i
extendwithyourcode
Exercise 1
Exercise1
Classes
GlutViewer
GlutExaminer
MeshViewer
ValenceViewer
Exercise 1
Exercise1
Computevalencesinacustommeshproperty
Compute valences in a custom mesh property
C
Computecolorsoutofvalencesandstore
l
f l
d
theminthepredefinedproperty
Exercise 1
Exercise1
Send
Sendzipofyoursourcefiles,projectfilesand
zip of your source files project files and
solutionfiles
Describeyoursolutioninreadme.txt.
Describe your solution in readme txt
Dontsendbinariesandotherintermediary
files
fil
CanusetheclearSolution.bat
!deletesrecursivelyalldebugandrelease
directoriesandintermediarysolutionfiles
OpenMesh
GeometricOperations
Geometric Operations
OpenMesh::Vec3f x y n crossproductXY;
OpenMesh::Vec3fx,y,n,crossproductXY;
...
l=(xy).length();
n=x.normalize();
scalarProductXY
l
=(x|y);
( | )
crossProductXY =x%y;
...
OpenMesh
Meshdefinition
Mesh definition
#include<OpenMesh/Core/IO/MeshIO.hh>
#include<OpenMesh/Core/Mesh/Types/TriMesh_ArrayKernelT.hh>
typedef Openmesh::TriMesh_ArrayKernelT<>Mesh;
name space
namespace
meshtype:
h
trianglemesh
arraykernel
defaulttraits
default traits
OpenMesh
Loading/WritingaMesh
Loading/Writing a Mesh
Mesh*myMesh;
OpenMesh::IO::OptionsreadOptions;
OpenMesh::IO::read_mesh(*myMesh,/path/to/bunny.off,readOptions)
reader/writersettings:
enablevertexnormals/colors/texturecoordinates?
enable vertex normals/colors / texture coordinates?
enablefacenormals/colors?
OpenMesh
AddingAttributes
Adding Attributes
Mesh*myMesh;
O
OpenMesh::IO::OptionsreadOptions;
M h IO O ti
dO ti
OpenMesh::IO::read_mesh(*myMesh,/path/to/bunny.off ,readOptions)
if(!readOptions.check(OpenMesh::IO::Options::FaceNormal))
if(!readOptions
check(OpenMesh::IO::Options::FaceNormal))
{
myMesh>update_face_normals();
}
if(!readOptions.check(OpenMesh::IO::Options::VertexNormal))
{
myMesh>update_vertex_normals();
}
OpenMesh
Iteratingoververtices
Iterating over vertices
typedef Openmesh::TriMesh_ArrayKernelT<>Mesh;
M h* M h
Mesh*myMesh;
Mesh::VertexIter vIt , vBegin , vEnd;
vBegin =myMesh>vertices_begin();
vEnd =myMesh>vertices_end();
for(vIt =vBegin ;vIt !=vEnd ;++vIt )
{
doSomethingWithVertex(vIt.handle());
g
(
())
}
OpenMesh
Iteratingoverfaces
Iterating over faces
Mesh::VertexIter Mesh::FaceIter
vertices_begin()faces_begin()
vertices end() faces end()
vertices_end()faces_end()
OpenMesh
Circulatingoverfacesaroundavertex
Circulating over faces around a vertex
Mesh::VertexIter vIt , vBegin , vEnd;
vBegin =myMesh>vertices_begin();
vEnd =myMesh>vertices_end();
for(vIt =vBegin ;vIt !=vEnd ;++vIt )
{
Mesh::VertexFaceIter vfIt , vfBegin;
vfBegin =myMesh
myMesh>vf
vf_iter(vIt);
iter(vIt);
for(vfIt =vfBegin ;vfIt ;++vfIt)
{
d S
doSomethingWithFace(vfIt.handle());
thi WithF ( fIt h dl ())
}
}
OpenMesh
Vertices,perimeter,areaofatriangle
Vertices perimeter area of a triangle
voidanalyzeTriangle(OpenMesh::FaceHandle &_fh)
{
OpenMesh::Vec3fpointA , pointB , pointC;
Mesh::ConstFaceVertexIter cfvIt;
cfvIt =myMesh>cfv_iter(_fh);
pointA =myMesh>point(cfvIt.handle());
pointB =myMesh>point((++cfvIt).handle());
pointC =myMesh
myMesh>point((++cfvIt).handle());
point(( cfvIt).handle());
perimeter(pointA,pointB,pointC);
area(pointA,pointB,pointC)
}
OpenMesh
NeighborAccessinO(1)
OpenMesh::VertexHandle endVH;
OpenMesh::HalfEdgeHandle ,startHEH
startHEH , twinHEH , nextHEH;
startHEH =hehIt.handle();
twinHEH=myMesh>opposite_halfedge_handle(startHEH);
nextHEH =myMesh>next_halfedge_handle(twinHEH);
endVH =myMesh>to_vertex_handle(nextHEH);
next
endVH
twin start
start
OpenMesh
Modifyingthegeometry
for(vIt =vBegin ;vIt !=vEnd ;++vIt )
{
scale(vIt.handle() , 2.0);
}
voidscale(OpenMesh::VertexHandle &_vh , double_alpha)
{
OpenMesh::Vec3f newCoordinate;
OpenMesh::Vec3fnewCoordinate;
newCoordinate =myMesh>point(_vh);
myMesh>set_point(_vh , newCoordinate *_alpha);
}
OpenMesh
Modifyingthetopology
myMesh>request_vertex_status();
myMesh >request edge status();
myMesh>request_edge_status();
myMesh>request_face_status();
OpenMesh::HalfedgeHandlecurrentHEH
OpenMesh::HalfedgeHandle
currentHEH =heIt.handle();
heIt.handle();
myMesh>collapse(currentHEH);
myMesh>garbage_collection();
currentHEH
collapse
OpenMesh
AddingCustomTraits
#include<OpenMesh/Core/IO/MeshIO.hh>
#include<OpenMesh/Core/Mesh/Types/TriMesh_ArrayKernelT.hh>
structmyMeshTraits:publicOpenMesh::DefaultTraits
{
typedefOpenMesh::Vec4fColor;
VertexAttributes(
OpenMesh::Attributes::Normal|
OpenMesh::Attributes::Color);
FaceAttributes((
FaceAttributes
OpenMesh::Attributes::Normal|
OpenMesh::Attributes::Color);
}
typedefOpenmesh::TriMesh_ArrayKernelT<myMeshTraits>Mesh;
OpenMesh
Setting/GettingPredefinedAttributes
typedef Openmesh::TriMesh_ArrayKernelT<>Mesh;
Mesh*myMesh;
...//loadfileintomyMesh
myMesh>request_vertex_normals();
myMesh>request_vertex_colors();
myMesh>request_face_normals();
y
q
_
_
();
...
myMesh >set color(currentVH Mesh::Color(0 0 255));
myMesh>set_color(currentVH,Mesh::Color(0,0,255));
blueColor =myMesh>color(currentVH);
OpenMesh
Setting/GettingCustomAttributes
OpenMesh::FPropHandleT<bool>marked;
myMesh>add
myMesh
add_property(marked);
property(marked);
for(fIt =fBegin;fIt !=fEnd;++fIt)
{
if( h ldM k(fIt))
if(shouldMark(fIt))
myMesh>property(marked,fIt)=true;
else
myMesh>property(marked,fIt)=false;
y
p p y(
, )
;
}
for(fIt =fBegin;fIt !=fEnd;++fIt)
{
if(myMesh>property(marked,fIt))
doSomething(fIt);
}
OpenMesh
Formoreexamples,tutorials,documentation:www.openmesh.org