VCG: a General Purpose Library for Simplicial Complexes

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
High-Quality Simplification with Generalized Pair Contractions Pavel Borodin,* Stefan Gumhold, # Michael Guthe,* Reinhard Klein* *University of Bonn, Germany.
CS CS 175 – Week 4 Mesh Decimation General Framework, Progressive Meshes.
SpiderGL Marko Leppänen WebGL Seminar Tampere University of Technology, Finland.
Polygonal Mesh – Data Structure and Smoothing
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
1 Fall Chapter 4 ADT Sorted List. 2 Goals Describe the Abstract Data Type Sorted List from three perspectives Implement the following Sorted List.
Visualization and graphics research group CIPIC January 21, 2003Multiresolution (ECS 289L) - Winter Surface Simplification Using Quadric Error Metrics.
C++ fundamentals.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
OOP Languages: Java vs C++
Pointers (Continuation) 1. Data Pointer A pointer is a programming language data type whose value refers directly to ("points to") another value stored.
1 ATPESC 2014 Vijay Mahadevan Tutorial Session for Scalable Interfaces for Geometry and Mesh based Applications (SIGMA) FASTMath SciDAC Institute.
Antigone Engine Kevin Kassing – Period
Object Oriented Data Structures
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Compressing Multiresolution Triangle Meshes Emanuele Danovaro, Leila De Floriani, Paola Magillo, Enrico Puppo Department of Computer and Information Sciences.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Surface Simplification Using Quadric Error Metrics Michael Garland Paul S. Heckbert.
Data Structures Using C++ 2E
Dynamic Meshing Using Adaptively Sampled Distance Fields
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
A lightweight approach to repairing digitized polygon meshes Marco Attene IMATI-GE / CNR 2010 Presented by Naitsat Alexander.
File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.
Mesh Data Structure. Meshes Boundary edge: adjacent to 1 face Regular edge: adjacent to 2 faces Singular edge: adjacent to >2 faces Mesh: straight-line.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Pointers OVERVIEW.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
1 5. Abstract Data Structures & Algorithms 5.2 Static Data Structures.
Iterator for linked-list traversal, Template & STL COMP171 Fall 2005.
1 Outline Previous work on geometric and solid modeling Multiresolution models based on tetrahedral meshes for volume data analysis Current work on non-manifold.
Lecture by: Prof. Pooja Vaishnav.  Language Processor implementations are highly influenced by the kind of storage structure used for program variables.
CE Operating Systems Lecture 17 File systems – interface and implementation.
CS418 Computer Graphics John C. Hart
3D Polyhedral Surfaces in Pierre Alliez.
Containers Jason Goffeney 2/23/2006. Containers The STL is a standard part of probably all C++ implementations It features implementations of most of.
I MPLEMENTING FILES. Contiguous Allocation:  The simplest allocation scheme is to store each file as a contiguous run of disk blocks (a 50-KB file would.
Solid Modeling 2002 A Multi-resolution Topological Representation for Non-manifold Meshes Leila De Floriani, Paola Magillo, Enrico Puppo, Davide Sobrero.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Overview of Previous Lesson(s) Over View VP is the methodology in which development allows the user to grab and use the desired tools like menus, buttons,
1 Data Structures and Algorithms Outline This topic will describe: –The concrete data structures that can be used to store information –The basic forms.
11/16/04© University of Wisconsin, CS559 Fall 2004 Last Time Texture Anti-Aliasing Texture boundaries Modeling introduction.
11/12/02(c) University of Wisconsin, CS559 Last Time Texturing Details Homework 5.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
Arrays Chapter 7.
File System Implementation
Model Optimization Wed Nov 16th 2016 Garrett Morrison.
Andy Wang Object Oriented Programming in C++ COP 3330
Programming with ANSI C ++
Regarding homework 9 Many low grades
CENG 789 – Digital Geometry Processing 04- Mesh Data Structures
Week 4 - Friday CS221.
Chapter 4 Linked Lists.
This pointer, Dynamic memory allocation, Constructors and Destructor
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Chapter 11: File System Implementation
Simulated Pointers.
Discussion section #2 HW1 questions?
Simulated Pointers.
Andy Wang Object Oriented Programming in C++ COP 3330
Meshes.
Programming Abstractions
Introduction to Data Structure
Data Structures & Algorithms
Chap 10. Geometric Level of Detail
Presentation transcript:

VCG: a General Purpose Library for Simplicial Complexes Visual Computing Laboratory ISTI – CNR Pisa

VCG: the goals A framework to implement algorithms on Simplicial Complexes of order d=0..3 in R^n: Efficient code Easy to understand Flexible Reusable Multiplatform (MS 7.1,Intel,gnu) Open Source: http://vcg.sourceforge.org

VCG Structure root The library: definitions and algorithms. Only standard c++ e STL here. Entirely self-contained. No inclusion to external file or linking of other libraries vcg Wrapping the library concepts,e.g.: draw a mesh using opengl.... Trackball/decorators.... file importers/exporters.. wrap apps Applications made with the library docs Documentation: styleguide and manual generated by Doc++

VCG vcg simplex Definition of simplex (order 0..3) - Definition of complex Iterators to walk on the mesh Local operators (edge split, edge collapse etc..) Algorithms (simplification, smoothing, mesh generation..) complex container Specialization of STL vector used to handle optional attributes of simplices Basic geometric entities intersection between geometric entities - Spatial indexing data structures space math Some linear algebra

Outline The core of VCG: The basic algorithms The applications Definition of simplex and complex Dynamic attributes Surfing the mesh Manifoldness The basic algorithms updating algorithms: bounding box, smoothing... creation algorithms: refine, platonic The applications Metro, Tridecimator, MeshLab Comparison with other libraries OpenMesh

Simplex VCG simplices: Vertex,Edge,Face,Tetrahedron A simplex can have attributes other then its geometrical position: normal, color,quality, connectivity information, etc. One may want: To have a vertex with any combination of these attributes To choose a set of attributes dynamically To create user-defined attributes

Example: Vertex All the desired attributes are passed as template class to the vertex: The template parameters can be passed in any order How? Template list are unrolled in a chain of derivations typedef VertexSimp1< Vertex0, EdgeProto, vcg::vert::VFAdj, vcg::vert::Normal3f, vcg::vert::Color4b> MyVertex; vcg::vert::EmptyInfo vcg::vert::EmptyVFAdj vcg::vert::Color4b ... vcg::vert::EmptyFlags vcg::vert::Normal3f vcg::vert::EmptyInfo vcg::vert::VFAdj vcg::vert::EmptyNormal MyVertex vcg::vert::EmptyColor

Example: Normal In the chain Normal is derived by EmptyNormal The member N() is overridden template <class T> class EmptyNormal: public T { public: typedef vcg::Point3s NormalType; NormalType &N() { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } static bool HasNormal() { return false; } }; template <class A, class T> class Normal: public T { typedef A NormalType; NormalType &N() { return _norm; } static return HasNormal() { return true; } private: NormalType _norm; template <class T> class Normal3s: public Normal<vcg::Point3s, T> {}; template <class T> class Normal3f: public Normal<vcg::Point3f, T> {}; template <class T> class Normal3d: public Normal<vcg::Point3d, T> {};

Complex (ex: TriMesh) A complex is a collection of simplices Only max and min order simplices are kept explicitly template < class VertContainerType, class FaceContainerType > class TriMesh{ public: /// Set of vertices VertContainer vert; /// Actual number of vertices int vn; /// Set of faces FaceContainer face; /// Actual number of faces int fn; ... };

Hello Mesh The type vertex stores only its position #include <vcg/simplex/vertexplus/base.h> #include <vcg/simplex/faceplus/base.h> #include <vcg/complex/trimesh/base.h> class MyEdge; class MyVertex: public VertexSimp2<MyVertex,MyEdge,MyFace,vcg::Coord3f>{}; class MyFace : public Face<MyVertex,MyEdge,MyFace,face::VertexRef>{}; class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace > >{}; The type vertex stores only its position The type face stores only the pointers to its 3 vertices

Optional attributes You may want some attributes only temporarily (ex: the normal per vertex) Examples: to load a mesh without wasting space to use an algorithm that requires an attribute you don’ t need often The easy way: allocate a vector of normals: the i-th element is the normal of the i-th vertex. Easy but: not transparent: algorithms need to be know if the normal is an optional attribute to read/write its value Need to keep track of memory relocation of STL containers

Optional attributes VCG provides 2 alternative ways Optional Component Fast [Ocf] Optional Component Compact [Occ] Ocf requires a 4 bytes overhead per vertex, Occ requires a small overhead per mesh Ocf efficiency is not affected by the number of elements in memory, Occ's is.

Ocf Include vector_ocf.h Add the suffix Ocf to the #include <vcg/space/point3.h> #include <vcg/simplex/vertexplus/base.h> #include <vcg/simplex/vertexplus/component_ocf.h> using namespace vcg; class MyE; class MyVertex:public VertexSimp2<MyVertex,MyE,vert::InfoOcf,vert::Normal3fOcf>{}; int main(int,char**){ vector_ocf<MyVertex> v; // put some vertices in the vector for( i= 0; i < 10; i++) v.push_back(MyVertex()); // activate the attribute v.EnableNormal(); // put some more vertices in the vector v[2].N()=Point3f(1.0,2,3); // drop the attribute v.DisableNormal(); } Add the suffix Ocf to the class name of the attibute Add attribute InfoOcf Store the vertices in a vector_ocf container

Occ Include vector_occ.h and component.h Add the suffix Occ to the class name of the attibute #include <vcg/space/point3.h> #include <vcg/container/vector_occ.h> #include <vcg/simplex/vertexplus/base.h> #include <vcg/simplex/vertexplus/component_occ.h> using namespace vcg; class MyE; class MyVertex: public VertexSimp2< MyVertex,MyE,vcg::vert::Normal3fOcc>{}; int main(int,char**){ vector_occ<MyVertex> v; // put some vertices in the vector for( i= 0; i < 10; i++) v.push_back(MyVertex()); // activate the attribute v.EnableAttribute< MyVertex::NormalType>(); // put some more vertices in the vector v[2].N()=Point3f(1.0,2,3); // drop the attribute v.DisableAttribute< MyVertex::NormalType >(); } Stores the vertices in a vector_occ container

User-defined optional attr. Only in Occ style ..... vector_occ<MyVertex> v; // put some vertices in the vector for( i= 0; i < 10; i++) v.push_back(MyVertex()); // define a user-defined optional attribute TempData<vector_occ<MyVertex>,USER_TYPE> handle = v.NewTempData<USER_TYPE>(); // activate the user defined attribute c2.EnableAttribute< USER_TYPE>(); // put some more vertices in the vector for( i= 0; i < 10; i++) c1.push_back(MyVertex()); handle[&c1[2]] = USER_TYPE_value; // drop the attribute c1.DisableAttribute< USER_TYPE >(); }

ocf/occ implementation Mesh: STL vector of NormalOc? vector_oc? of vertices v.N() vector of faces …. template <class T> class NormalOcf: public T { public: typedef vcg::Point3s NormalType; NormalType &N() { // Need to know the position of (*this) in the // vector } vcg::vert::Normal3fOcf ….

ocf implementation Mesh: STL vector of NormalOcf vector_ocf of vertices v.N() vector of faces …. Every element of the vector_ocf stores a pointer to the first position of the vector. The vector contains one pointer to the first position of every vector of optional attributes. vcg::vert::Normal3fOcf ….

occ implementation Container Allocation Table Mesh: vector_occ of vertices STL vector of NormalOcc v.N() vector of faces …. A static class keeps track of where are the vector_occ Instances in a list sorted by the address of their first element. vcg::vert::Normal3fOcc ….

Surfing the mesh Based on the concept of pos (position) a pos is a d+1-tuple: v2 e2 f e1 v0 e0 v1 { v0,e2,f }

Pos any component of a pos can only be changed in another value to obtain another pos v2 v2 e2 p.FlipV() e2 f e1 f e1 {v0,e2,f}  {v2,e2,f} v0 e0 v0 e0 v1 v1 v2 v2 e2 e2 p.FlipE() f e1 f e1 {v0,e2,f}  {v0,e0,f} v0 e0 v0 e0 v1 v1 v2 v2 f1 f1 e2 e2 p.FlipF() f e1 f e1 {v0,e2,f}  {v2,e2,f1} v0 e0 v0 e0 v1 v1

Pos Example: running over the faces around a vertex p.FlipE() template <typename FaceType> class Pos { ... void NextE() { assert( f->V(z)==v || f->V((z+1)%3)==v ); FlipE(); FlipF(); } }; <vcg/simplex/face/pos.h> v2 v2 v2 e2 e2 e2 p.FlipE() p.FlipF() f e1 f e1 f e1 v0 v0 v0 e0 e0 e0 v1 v1 v1 f2 f2 f2

Pos Implementation Three pointers to face and three integers in each face: f.FFp(1)==&f1 f.FFi(1) == 2 f.FFp(2) == &f2 f.FFi(2) == 1 f.FFp(0) == &f f.FFi(0) == -1 If it is manifold along the edge “i”: f.FFp(i)->f.FFp(f.FFi(i)) == &f v2 v1 v2 v0 v2 f1 f2 2 f 2 1 v1 v0 v0 v1 border

Pos: non manifoldness Pos works also for non manifold meshes If an edge is non manifold, then for some face adjacent to it: f.FFp(i)->f.FFp(f.FFi(i)) != &f

Pos: example One ring neighborood #include <vcg/simplex/vertexplus/base.h> #include <vcg/simplex/faceplus/base.h> #include <vcg/simplex/face/pos.h> #include <vcg/complex/trimesh/base.h> class MyEdge; class MyVertex: public VertexSimp2<MyVertex,MyEdge,MyFace,vert::Coord3f>{}; class MyFace : public Face<MyVertex,MyEdge,MyFace,face::VertexRef,face::FFAdj>{}; class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace > >{}; MyMesh mesh; void ring(FaceType * f){ Pos<MyMesh::FaceType> p(f,f->V(0),0); for(;p.F()!= f;p.NextE()){ //do something with p; } }

VFIterator Used to run through the list of faces sharing a vertex A VFIterator is a couple: 3 possible VFIterator for each face

VFIterator The vertex holds a pointer to one of the adjacent the face The face holds, for each of its tree vertices, a pointer to the next face on the respective lists v.VFp() ==&f v.VFi() == 0; f.VFp(0)==&f2 f.VFi(1) == 2 f2.VFp(2) == &f2 f2.VFi(2) == 1 f1.VFp(1) == null f1.VFi(1) == -1 f v v0 null v1 v2 f1 f2

VFIterator: example One ring neighborood #include <vcg/simplex/vertexplus/base.h> #include <vcg/simplex/faceplus/base.h> #include <vcg/simplex/face/pos.h> #include <vcg/complex/trimesh/base.h> class MyEdge; class MyVertex: public VertexSimp2<MyVertex,MyEdge,MyFace,vert::Coord3f,vert::VFAdj>{}; class MyFace : public Face<MyVertex,MyEdge,MyFace,face::VertexRef,face::VFAdj>{}; class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace > >{}; MyMesh mesh; void ring(MyMesh::VertexType * v){ VFIterator<MyMesh::FaceType> vi(v); for(;!=vi.End();++vi){ //do something with p; } }

Manifoldness A trimesh is not manifold iff: There are more than 2 faces sharing the same edge OR The number of faces adjacent to a vertex counted by running a pos around the vertex are less then running with a VFIterator

Basic Algorithms vcg complex trimesh Algorithms that create a mesh: Marching cubes by refinement from platonic shapes Ball Pivoting Subset from another mesh resampling… create Algorithms that update attributes FFAdjacency VFAdjacency Bounding Box Normals per face Normals per vertex ……. update

Wrap Render vcg objects with OpenGl root Wrap wrap gl Render vcg objects with OpenGl Import from (export to) fome formats: export(import)_3ds export(import)_dae export(import)_dxf export(import)_iv export(import)_obj export(import)_off export(import)_ply export(import)_smf export(import)_stl export(import)_vrml export(import)_raw ….. gui io_trimesh …..

Comparison to OpenMesh VCG Data structure Half edge Indexed with adjacencies Memory (bytes per vertex) 84 24 face-vert + 32 face-face + 36 vert-face generality General for polygonal meshes General for simplicial complexes Access to items Handle() pointer Non manifoldness Only at vertices complete

Comparison to OpenMesh Test: iterate over all the faces of a triangle mesh. For each face read position and normal. Time do to 1000 test (ms) Vert / tri VCG OpenMesh 2619 4881 146 707 27861 49954 2188 8113 543652 1087716 47362 222177

Comparison to OpenMesh Test: iterate over all the vertices of a triangle mesh. For each vertex read position and normal. Time do to 1000 test (ms) Vert / tri VCG OpenMesh 2619 4881 21 60 27861 49954 405 699 543652 1087716 8050 14425

Comparison to OpenMesh Test: iterate over all the vertices of a triangle mesh. For each vertex read position and normal of all the vertices in the ring. Time do to 100 test (ms) Vert / tri VCG OpenMesh 2619 4881 88 58 27861 49954 913 590 543652 1087716 19600 12812

Comparison to OpenMesh Test: iterate over all the vertices of a triangle mesh. For each vertex find all the faces connected to it. For each face read position and normal of its 3 vertices Time do to 100 test (ms) Vert / tri VCG OpenMesh 2619 4881 121 217 27861 49954 1226 2194 543652 1087716 26787 47856

Comparison to OpenMesh Decimation by edge collapse with quadric error Vert / tri reduce to # face VCG OpenMesh 2619 4881 400 94 211 27861 49954 10000 547 2710 543652 1087716 100000 16578 1m13s