Initial commit

This commit is contained in:
Paolo Cignoni 2004-02-19 13:11:06 +00:00
parent b3469007e8
commit 2c061402f5
7 changed files with 2165 additions and 0 deletions

440
vcg/complex/trimesh/base.h Normal file
View File

@ -0,0 +1,440 @@
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
****************************************************************************/
#pragma warning( disable : 4804 )
/*
People should subclass his vertex class from these one...
*/
#ifndef __VCG_MESH
#define __VCG_MESH
#include <assert.h>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#include <iterator>
//#include <vcg/Mesh/Selection.h>
#include <vcg/TriTriIntersection.h>
#include <vcg/tools/plylib.h>
namespace vcg {
/** Class Mesh.
This is class for definition of a mesh.
@param STL_VERT_CONT (Template Parameter) Specifies the type of the vertices container any the vertex type.
@param STL_FACE_CONT (Template Parameter) Specifies the type of the faces container any the face type.
*/
template < class STL_VERT_CONT, class STL_FACE_CONT >
class Mesh{
public:
/// The face container
typedef STL_FACE_CONT face_container;
/// The face container
typedef STL_VERT_CONT vertex_container;
/// The vertex type
typedef typename STL_VERT_CONT::value_type MVTYPE;
/// The face type
typedef typename STL_FACE_CONT::value_type MFTYPE;
/// The scalar type
typedef typename MVTYPE::scalar_type MCTYPE;
/// The type of the vectors
typedef typename MFTYPE::vectorial_type vectorial_type;
/// The type of the scalars
typedef MCTYPE scalar_type;
/// The vertex type
typedef MVTYPE vertex_type;
/// Tipo vertice originario
typedef typename MVTYPE::vertex_base vertex_base;
/// The face type
typedef MFTYPE face_type;
/// The type of vertex iterator
typedef typename STL_VERT_CONT::iterator vertex_iterator;
/// The type of face iterator
typedef typename STL_FACE_CONT::iterator face_iterator;
/// The type of constant vertex iterator
typedef typename STL_VERT_CONT::const_iterator const_vertex_iterator;
/// The type of constant face iterator
typedef typename STL_FACE_CONT::const_iterator const_face_iterator;
/// The vertex pointer type
typedef MVTYPE * vertex_pointer;
/// The face pointer type
typedef MFTYPE * face_pointer;
/// The type of the constant vertex pointer
typedef const MVTYPE * const_vertex_pointer;
/// The type of the constant face pointer
typedef const MFTYPE * const_face_pointer;
/// The vertex base pointer type
typedef typename MVTYPE::vertex_base * vertex_base_pointer;
/// The type of the constant vertex base pointer
typedef const typename MVTYPE::vertex_base * const_vertex_base_pointer;
/// The face base pointer type
typedef typename MFTYPE::face_base face_base;
typedef typename MFTYPE::face_base * face_base_pointer;
/// The type of the constant face base pointer
typedef const typename MFTYPE::face_base * const_face_base_pointer;
/// The mesh type
typedef Mesh<STL_VERT_CONT,STL_FACE_CONT> MMTYPE;
/// The edge type for FF topology
typedef FEdgePosB<MFTYPE> fedgepos_type;
/// The edge type for VF topology
typedef VEdgePosB<MFTYPE> vedgepos_type;
/// The half edge type
typedef HEdgePosB<MFTYPE> hedgepos_type;
/// The half edge type with the normal
typedef HEdgePosBN<MFTYPE> hedgeposn_type;
/// The ear type
typedef Ear<MFTYPE> ear_type;
/// The Box3 type
typedef Box3<MCTYPE> BOX_TYPE;
/// Set of vertices
STL_VERT_CONT vert;
/// Real number of vertices
int vn;
/// Set of faces
STL_FACE_CONT face;
/// Real number of faces
int fn;
/// Bounding box of the mesh
Box3<MCTYPE> bbox;
/// Internal status
int status;
/// Nomi di textures
vector<string> textures;
vector<string> normalmaps;
/// La camera
Camera<scalar_type> camera;
/// Il colore della mesh
private:
ColorUB c;
public:
inline const ColorUB & C() const
{
return c;
}
inline ColorUB & C()
{
return c;
}
/// Default constructor
Mesh()
{
fn = vn = 0;
imark = 0;
}
inline int MemUsed() const
{
return sizeof(MMTYPE)+sizeof(MVTYPE)*vert.size()+sizeof(MFTYPE)*face.size();
}
inline int MemNeeded() const
{
return sizeof(MMTYPE)+sizeof(MVTYPE)*vn+sizeof(MFTYPE)*fn;
}
/// Function to destroy the mesh
MMTYPE & Clear()
{
vert.clear();
face.clear();
textures.clear();
normalmaps.clear();
vn = 0;
fn = 0;
return *this;
}
/* Funzioni di info sulle caratteristiche della mesh */
static bool HasPerVertexNormal() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_N)); }
static bool HasPerVertexColor() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_C)); }
static bool HasPerVertexMark() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_M)); }
static bool HasPerVertexQuality() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_Q)); }
static bool HasPerVertexTexture() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_T)); }
static bool HasPerFaceColor() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_C)); }
static bool HasPerFaceNormal() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_N)); }
static bool HasPerFaceMark() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_M)); }
static bool HasPerFaceQuality() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_Q)); }
static bool HasPerWedgeColor() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_WC)); }
static bool HasPerWedgeNormal() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_WN)); }
static bool HasPerWedgeTexture() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_WT)); }
static bool HasFFTopology() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_A)) || HasSTopology(); }
static bool HasVFTopology() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_V)) || HasSTopology(); }
static bool HasSTopology() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_S)); }
static bool HasTopology() { return HasFFTopology() || HasVFTopology(); }
/// Initialize the imark-system of the faces
void InitFaceIMark()
{
face_iterator f;
for(f=face.begin();f!=face.end();++f)
if( !(*f).IsDeleted() && (*f).IsR() && (*f).IsW() )
(*f).InitIMark();
}
/// Initialize the imark-system of the vertices
void InitVertexIMark()
{
vertex_iterator vi;
for(vi=vert.begin();vi!=vert.end();++vi)
if( !(*vi).IsDeleted() && (*vi).IsRW() )
(*vi).InitIMark();
}
// Warning assignament should take a const mesh in input
/** Assignment operator for mesh. The mesh content is losed.
*/
inline MMTYPE & operator = (MMTYPE & m )
{
Clear();
SelectedMerge(m,true);
return *this;
}
/// The incremental mark
int imark;
/** Check if the vertex incremental mark matches the one of the mesh.
@param v Vertex pointer
*/
inline bool IsMarked( MVTYPE * const v ) const { return v->IMark() == imark; }
/** Check if the face incremental mark matches the one of the mesh.
@param v Face pointer
*/
inline bool IsMarked( MFTYPE * const f ) const { return f->IMark() == imark; }
/** Set the vertex incremental mark of the vertex to the one of the mesh.
@param v Vertex pointer
*/
inline void Mark( MVTYPE * const v ) const { v->IMark() = imark; }
/** Set the face incremental mark of the vertex to the one of the mesh.
@param v Vertex pointer
*/
inline void Mark( MFTYPE * const f ) const { f->IMark() = imark; }
/// Unmark the mesh
inline void UnMarkAll() { ++imark; }
/** Function to add n vertices to the mesh. The second parameter hold a vector of
pointers to pointer to elements of the mesh that should be updated after a
possible vector realloc.
@param n Il numero di vertici che si vuole aggiungere alla mesh.
@param local_var Vettore di variabili locali che rappresentano puntatori a vertici.
restituisce l'iteratore al primo elemento aggiunto.
*/
vertex_iterator AddVertices(int n, vector<vertex_base **> &local_var)
{
vertex_iterator oldbegin, newbegin;
oldbegin = vert.begin();
vertex_iterator last=vert.end();
if(vert.empty()) last=0; // if the vector is empty we cannot find the last valid element
else --last;
unsigned int siz=0;
#ifdef __STL_CONFIG_H
if(last!=0) distance(vert.begin(),last,siz);
#else
if(last!=0) siz=distance(vert.begin(),last);
#endif
for(int i=0; i<n; ++i)
{
vert.push_back(MVTYPE());
vert.back().Supervisor_Flags() = 0;
}
vn+=n;
newbegin = vert.begin();
if(newbegin != oldbegin)
{
face_iterator f;
for (f=face.begin(); f!=face.end(); ++f)
if(!(*f).IsD())
for(int k=0; k<(*f).size(); ++k)
(*f).V(k) = (*f).V(k)-&*oldbegin+&*newbegin;
for(int j=0; j<local_var.size(); ++j)
if((*local_var[j]) !=0 ) *local_var[j] = *local_var[j]-&*oldbegin+&*newbegin;
// deve restituire l'iteratore alla prima faccia aggiunta;
// e poiche' lo spazio e' cambiato si ricalcola last da zero
if(last!=0)
{
last = vert.begin();
advance(last,siz+1);
}
else last=vert.begin();
}
else
{
// se non e'cambiato lo spazio (vector abbastanza grande o lista)
if(last==0) last = vert.begin(); // se il vettore era vuoto si restituisce begin
else advance(last,1); // altrimenti il primo dopo quello che era in precedenza l'ultimo valido.
}
return last;
}
vertex_iterator AddVertices(int n)
{
vector<vertex_base **> local_var;
return AddVertices(n,local_var);
}
/** Function to add n faces to the mesh.
@param n Il numero di facce che si vuole aggiungere alla mesh
*/
face_iterator AddFaces(int n)
{
vector<face_base **> local_var;
return AddFaces(n,local_var);
}
/** Function to add n faces to the mesh.
NOTA: Aggiorna fn;
The second parameter hold a vector of
pointers to pointer to elements of the mesh that should be updated after a
possible vector realloc.
@param n Facce da aggiungere
@param local_var Vettore di variabili locali che rappresentano puntatori a facce, occorre,
perche' questi valori siano consistenti, aggiornarli ogni qual volta venga eseguito un resize
del contenitore delle facce.
*/
face_iterator AddFaces(int n, vector<face_base **> &local_var)
{
face_iterator oldbegin, newbegin;
oldbegin = face.begin();
face_iterator last=face.end();
if(face.empty()) last=0;
else last--;
unsigned int siz=0;
#ifdef __STL_CONFIG_H
if(last!=0) distance(face.begin(),last,siz);
#else
if(last!=0) siz=distance(face.begin(),last);
#endif
MFTYPE dum;
dum.Supervisor_Flags()=0;
for(int i=0; i<n; ++i)
face.push_back(dum);
fn+=n;
newbegin = face.begin();
if(newbegin != oldbegin)// se e' cambiato lo spazio (vector abbastanza grande o lista)
{
if(MFTYPE::OBJ_TYPE & MFTYPE::OBJ_TYPE_A)
{
face_iterator f;
for (f=face.begin(); f!=face.end(); ++f)
for(int k=0; k<(*f).size(); ++k)if(!(*f).IsD())
(*f).F(k) = (*f).F(k)-&*oldbegin+&*newbegin;
}
vector<face_base **>::iterator jit;
for(jit=local_var.begin(); jit!=local_var.end(); ++jit)
if((**jit) !=0 ) **jit = **jit-&*oldbegin+&*newbegin;
// deve restituire l'iteratore alla prima faccia aggiunta;
if(last!=0)
{
last = face.begin();
advance(last,siz+1);
}
else last=face.begin();
}
else //
{ assert(newbegin == oldbegin);
// se non e'cambiato lo spazio (vector abbastanza grande o lista)
if(last==0) last = face.begin(); // se il vettore era vuoto si restituisce begin
else advance(last,1); // altrimenti il primo dopo quello che era in precedenza l'ultimo valido.
}
return last;
}
/// Calcolo del volume di una mesh chiusa
scalar_type Volume()
{
face_iterator f;
int j,k;
scalar_type V = 0;
vectorial_type T,N,B;
for(f = face.begin(); f!=face.end(); ++f)
{
for(j = 0; j < 3; ++j)
{
/*calcolo tangente, normale e binormale (6 volte)*/
k = (j+1)%3;
T = (*f).V(k)->P() - (*f).V(j)->P();
T.Normalize();
T = ( (*f).V( k )->P() - (*f).V(j)->P() ) ^
( (*f).V((k+1)%3)->P() - (*f).V(j)->P() ) ;
B.Normalize();
N = T ^ B;
vectorial_type pj = (*f).V(j)->P();
vectorial_type pk = (*f).V(k)->P();
V += (pj* T )*(pj*N)*(pj*B);
V += (pk*(-T))*(pk*N)*(pk*B);
}
}
return V/6;
}
}; // end class Mesh
} // end namespace
#endif

View File

@ -0,0 +1,115 @@
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
****************************************************************************/
template <class ComputeMeshType>
class TriMeshCompute
{
public:
static void FaceNormalRW(ComputeMeshType &m, bool normalize=false)
{
if( !m.HasPerFaceNormal()) return;
face_iterator f;
bool cn = true;
if(normalize)
{
for(f=m.face.begin();f!=m.face.end();++f)
if( !(*f).IsD() && (*f).IsRW() )
{
for(int j=0; j<(*f).size(); ++j)
if( !(*f).V(j)->IsR()) cn = false;
if( cn ) (*f).ComputeNormalizedNormal();
cn = true;
}
}
else
{
for(f=m.face.begin();f!=m.face.end();++f)
if( !(*f).IsD() && (*f).IsRW() )
{
for(int j=0; j<(*f).size(); ++j)
if( !(*f).V(j)->IsR()) cn = false;
if( cn )
(*f).ComputeNormal();
cn = true;
}
}
}
static void NormalizedFaceNormal(ComputeMeshType &m)
{
ComputeFaceNormal(true);
}
/// Calculates the vertex normal
static void NormalizedVertexNormal(ComputeMeshType &m)
{
VertexNormal(true);
}
/// Calculates the vertex normal
static void VertexNormal(ComputeMeshType &m, bool normalize=false)
{
if( m.HasPerVertexNormal())
{
vertex_iterator vi;
for(vi=vert.begin();vi!=vert.end();++vi)
if( !(*vi).IsDeleted() && (*vi).IsRW() )
(*vi).Normal() = vectorial_type(0,0,0);
face_iterator f;
for(f=face.begin();f!=face.end();++f)
if( !(*f).IsDeleted() && (*f).IsR() )
{
vectorial_type t = (*f).Normal();
for(int j=0; j<(*f).size(); ++j)
if( !(*f).V(j)->IsD() && (*f).V(j)->IsR() && (*f).V(j)->IsW() )
(*f).V(j)->Normal() += t;
}
if(normalize)
for(vi=vert.begin();vi!=vert.end();++vi)
if( !(*vi).IsDeleted() && (*vi).IsRW() )
(*vi).Normal().Normalize();
}
}
void ComputeE()
{
face_iterator f;
for(f = face.begin(); f!=face.end(); ++f)
(*f).ComputeE();
}
}; // end class

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,518 @@
/*#***************************************************************************
* VertexBase.h o o *
* o o *
* Visual Computing Group _ O _ *
* IEI Institute, CNUCE Institute, CNR Pisa \/)\/ *
* /\/| *
* Copyright(C) 1999 by Paolo Cignoni, Claudio Rocchini | *
* All rights reserved. \ *
* *
* Permission to use, copy, modify, distribute and sell this software and *
* its documentation for any purpose is hereby granted without fee, provided *
* that the above copyright notice appear in all copies and that both that *
* copyright notice and this permission notice appear in supporting *
* documentation. the author makes no representations about the suitability *
* of this software for any purpose. It is provided "as is" without express *
* or implied warranty. *
* *
*****************************************************************************/
/****************************************************************************
History
2000 Jul 23 First Working release (only the tetrahedron)
30 Added Octahedron
Aug 4 Added Icosahedron
Nov 22 Added Hexahedron (cube)
2001 Apr 19 Added HalfOctahedron
20 Added Square
May 16 Added Sphere Function (CR) (PC)
" Cone " " "
" Box (CR)
Jul 09 Aggiunta Build (CR)
****************************************************************************/
#ifndef __VCGLIB_PLATONIC
#define __VCGLIB_PLATONIC
#include <vcg/Mesh/Refine.h>
template <class MESH_TYPE>
void Tetrahedron(MESH_TYPE &in)
{
in.vn=4;
in.fn=4;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
f.V(0)=index[0]; f.V(1)=index[1];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[2];f.V(2)=index[3]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[3];f.V(2)=index[1]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[2];f.V(2)=index[1]; in.face.push_back(f);
}
template <class MESH_TYPE>
void Octahedron(MESH_TYPE &in)
{
in.vn=6;
in.fn=8;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 0, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 0,-1); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
f.V(0)=index[0]; f.V(1)=index[1];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[2];f.V(2)=index[4]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[4];f.V(2)=index[5]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[5];f.V(2)=index[1]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[1];f.V(2)=index[5]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[5];f.V(2)=index[4]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[4];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[2];f.V(2)=index[1]; in.face.push_back(f);
}
template <class MESH_TYPE>
void Icosahedron(MESH_TYPE &in)
{
MESH_TYPE::scalar_type L=(Sqrt(5.0)+1.0)/2.0;
MESH_TYPE::vectorial_type vv[12]={
MESH_TYPE::vectorial_type ( 0, L, 1),
MESH_TYPE::vectorial_type ( 0, L,-1),
MESH_TYPE::vectorial_type ( 0,-L, 1),
MESH_TYPE::vectorial_type ( 0,-L,-1),
MESH_TYPE::vectorial_type ( L, 1, 0),
MESH_TYPE::vectorial_type ( L,-1, 0),
MESH_TYPE::vectorial_type (-L, 1, 0),
MESH_TYPE::vectorial_type (-L,-1, 0),
MESH_TYPE::vectorial_type ( 1, 0, L),
MESH_TYPE::vectorial_type (-1, 0, L),
MESH_TYPE::vectorial_type ( 1, 0,-L),
MESH_TYPE::vectorial_type (-1, 0,-L)
};
int ff[20][3]={
{1,0,4},{0,1,6},{2,3,5},{3,2,7},
{4,5,10},{5,4,8},{6,7,9},{7,6,11},
{8,9,2},{9,8,0},{10,11,1},{11,10,3},
{0,8,4},{0,6,9},{1,4,10},{1,11,6},
{2,5,8},{2,9,7},{3,10,5},{3,7,11}
};
in.vn=12;
in.fn=20;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
for(int i=0;i<in.vn;i++)
{
tv.P()=vv[i];
in.vert.push_back(tv);
}
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
for(j=0;j<in.fn;++j)
{
f.V(0)=index[ff[j][0]];
f.V(1)=index[ff[j][1]];
f.V(2)=index[ff[j][2]];
in.face.push_back(f);
}
}
template <class MESH_TYPE>
void Hexahedron(MESH_TYPE &in)
{
in.vn=8;
in.fn=12;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type (-1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
f.V(0)=index[0]; f.V(1)=index[1];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[2];f.V(2)=index[1]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[2];f.V(2)=index[4]; in.face.push_back(f);
f.V(0)=index[6]; f.V(1)=index[4];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[4];f.V(2)=index[1]; in.face.push_back(f);
f.V(0)=index[5]; f.V(1)=index[1];f.V(2)=index[4]; in.face.push_back(f);
f.V(0)=index[7]; f.V(1)=index[5];f.V(2)=index[6]; in.face.push_back(f);
f.V(0)=index[4]; f.V(1)=index[6];f.V(2)=index[5]; in.face.push_back(f);
f.V(0)=index[7]; f.V(1)=index[6];f.V(2)=index[3]; in.face.push_back(f);
f.V(0)=index[2]; f.V(1)=index[3];f.V(2)=index[6]; in.face.push_back(f);
f.V(0)=index[7]; f.V(1)=index[3];f.V(2)=index[5]; in.face.push_back(f);
f.V(0)=index[1]; f.V(1)=index[5];f.V(2)=index[3]; in.face.push_back(f);
}
template <class MESH_TYPE>
void HalfOctahedron(MESH_TYPE &in)
{
in.vn=5;
in.fn=4;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 0, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
f.V(0)=index[0]; f.V(1)=index[1];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[2];f.V(2)=index[4]; in.face.push_back(f);
//f.V(0)=index[0]; f.V(1)=index[4];f.V(2)=index[5]; in.face.push_back(f);
//f.V(0)=index[0]; f.V(1)=index[5];f.V(2)=index[1]; in.face.push_back(f);
//f.V(0)=index[3]; f.V(1)=index[1];f.V(2)=index[5]; in.face.push_back(f);
//f.V(0)=index[3]; f.V(1)=index[5];f.V(2)=index[4]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[4];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[2];f.V(2)=index[1]; in.face.push_back(f);
}
template <class MESH_TYPE>
void Square(MESH_TYPE &in)
{
in.vn=4;
in.fn=2;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
f.V(0)=index[0]; f.V(1)=index[1];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[2];f.V(2)=index[3]; in.face.push_back(f);
}
template <class MESH_TYPE>
void Sphere(MESH_TYPE &in, const int subdiv = 3 )
{
Icosahedron(in);
in.ComputeBorderFlag();
int lastsize = 0;
for(int i=0;i<subdiv;++i)
{
Refine<MESH_TYPE, MidPoint<MESH_TYPE> >(in,MidPoint<MESH_TYPE>(),0);
MESH_TYPE::vertex_iterator vi;
for(vi = in.vert.begin()+lastsize;vi!=in.vert.end();++vi)
vi->P().Normalize();
lastsize = in.vert.size();
}
}
/// r1 = raggio 1, r2 = raggio2, h = altezza (asse y)
template <class MESH_TYPE>
void Cone( MESH_TYPE & in,
const MESH_TYPE::scalar_type r1,
const MESH_TYPE::scalar_type r2,
const MESH_TYPE::scalar_type h )
{
const int D = 24;
int i,b1,b2;
if(r1==0 || r2==0)
{
in.vn=D+2;
in.fn=D*2;
}
else
{
in.vn=D*2+2;
in.fn=D*4;
}
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 0,-h/2,0 );
tv.P()=tp;
in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, h/2,0 );
tv.P()=tp;
in.vert.push_back(tv);
b1 = b2 = 2;
if(r1!=0)
{
for(i=0;i<D;++i)
{
double a = i*3.14159265358979323846*2/D;
double s = sin(a);
double c = cos(a);
double x,y,z;
x = r1*c;
z = r1*s;
y = -h/2;
tp=MESH_TYPE::vectorial_type ( x,y,z );
tv.P()=tp;
in.vert.push_back(tv);
}
b2 += D;
}
if(r2!=0)
{
for(i=0;i<D;++i)
{
double a = i*3.14159265358979323846*2/D;
double s = sin(a);
double c = cos(a);
double x,y,z;
x = r2*c;
z = r2*s;
y = h/2;
tp=MESH_TYPE::vectorial_type ( x,y,z );
tv.P()=tp;
in.vert.push_back(tv);
}
}
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;
f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
if(r1!=0)
{
for(i=0;i<D;++i)
{
f.V(0)=index[0];
f.V(1)=index[b1+i];
f.V(2)=index[b1+(i+1)%D];
in.face.push_back(f);
}
}
if(r2!=0)
{
for(i=0;i<D;++i)
{
f.V(0)=index[1];
f.V(1)=index[b2+(i+1)%D];
f.V(2)=index[b2+i];
in.face.push_back(f);
}
}
if(r1==0)
{
for(i=0;i<D;++i)
{
f.V(0)=index[0];
f.V(1)=index[b2+i];
f.V(2)=index[b2+(i+1)%D];
in.face.push_back(f);
}
}
else if(r2==0)
{
for(i=0;i<D;++i)
{
f.V(0)=index[1];
f.V(2)=index[b1+i];
f.V(1)=index[b1+(i+1)%D];
in.face.push_back(f);
}
}
else
{
for(i=0;i<D;++i)
{
f.V(0)=index[b1+i];
f.V(1)=index[b2+i];
f.V(2)=index[b2+(i+1)%D];
in.face.push_back(f);
f.V(0)=index[b1+i];
f.V(1)=index[b2+(i+1)%D];
f.V(2)=index[b1+(i+1)%D];
in.face.push_back(f);
}
}
}
template <class MESH_TYPE>
void Box(MESH_TYPE &in, const MESH_TYPE::BOX_TYPE & bb )
{
in.vn=8;
in.fn=12;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.min[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.min[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.max[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.max[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.min[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.min[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.max[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.max[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
f.V(0)=index[0]; f.V(1)=index[1];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[2];f.V(2)=index[1]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[2];f.V(2)=index[4]; in.face.push_back(f);
f.V(0)=index[6]; f.V(1)=index[4];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[4];f.V(2)=index[1]; in.face.push_back(f);
f.V(0)=index[5]; f.V(1)=index[1];f.V(2)=index[4]; in.face.push_back(f);
f.V(0)=index[7]; f.V(1)=index[5];f.V(2)=index[6]; in.face.push_back(f);
f.V(0)=index[4]; f.V(1)=index[6];f.V(2)=index[5]; in.face.push_back(f);
f.V(0)=index[7]; f.V(1)=index[6];f.V(2)=index[3]; in.face.push_back(f);
f.V(0)=index[2]; f.V(1)=index[3];f.V(2)=index[6]; in.face.push_back(f);
f.V(0)=index[7]; f.V(1)=index[3];f.V(2)=index[5]; in.face.push_back(f);
f.V(0)=index[1]; f.V(1)=index[5];f.V(2)=index[3]; in.face.push_back(f);
}
/// Questa funzione costruisce una mesh a partire da un insieme di coordiante
/// ed un insieme di terne di indici di vertici
template <class M,class V, class F >
void Build( M & in, const V & v, const F & f)
{
in.vn = v.size();
in.fn = f.size();
in.vert.clear();
in.face.clear();
V::const_iterator vi;
M::vertex_type tv;
tv.Supervisor_Flags()=0;
for(vi=v.begin();vi!=v.end();++vi)
{
tv.P() = M::vectorial_type(
(M::scalar_type)(*vi).Ext(0),
(M::scalar_type)(*vi).Ext(1),
(M::scalar_type)(*vi).Ext(2)
);
in.vert.push_back(tv);
}
vector<M::vertex_pointer> index(in.vn);
M::vertex_iterator j;
int k;
for(k=0,j=in.vert.begin();j!=in.vert.end();++j,++k)
index[k] = &*j;
F::const_iterator fi;
M::face_type ft;
ft.Supervisor_Flags()=0;
for(fi=f.begin();fi!=f.end();++fi)
{
assert( (*fi)[0]>=0 );
assert( (*fi)[1]>=0 );
assert( (*fi)[2]>=0 );
assert( (*fi)[0]<in.vn );
assert( (*fi)[1]<in.vn );
assert( (*fi)[2]<in.vn );
ft.V(0) = index[ (*fi)[0] ];
ft.V(1) = index[ (*fi)[1] ];
ft.V(2) = index[ (*fi)[2] ];
in.face.push_back(ft);
}
}
#endif

View File

@ -0,0 +1,14 @@
#ifndef __VCGLIB_FACE_FA_TYPE
#define __VCGLIB_FACE_FA_TYPE
#define FACE_TYPE FaceFA
#define __VCGLIB_FACE_FA
#include <vcg/simplex/face/base.h>
#undef FACE_TYPE
#undef __VCGLIB_FACE_FA
#endif

View File

@ -0,0 +1,14 @@
#ifndef __VCGLIB_FACE_FC_TYPE
#define __VCGLIB_FACE_FC_TYPE
#define FACE_TYPE FaceFC
#define __VCGLIB_FACE_FC
#include <vcg/simplex/face/base.h>
#undef FACE_TYPE
#undef __VCGLIB_FACE_FC
#endif

View File

@ -0,0 +1,14 @@
#ifndef __VCGLIB_FACE_FN_TYPE
#define __VCGLIB_FACE_FN_TYPE
#define FACE_TYPE FaceFN
#define __VCGLIB_FACE_FN
#include <vcg/simplex/face/base.h>
#undef FACE_TYPE
#undef __VCGLIB_FACE_FN
#endif