First working version!
This commit is contained in:
parent
5332b4ac5b
commit
d52cbb2602
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.1 2004/02/19 13:11:06 cignoni
|
||||||
|
Initial commit
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
@ -36,127 +39,69 @@ People should subclass his vertex class from these one...
|
||||||
#ifndef __VCG_MESH
|
#ifndef __VCG_MESH
|
||||||
#define __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 {
|
namespace vcg {
|
||||||
|
namespace tri {
|
||||||
|
|
||||||
/** Class Mesh.
|
/** Class Mesh.
|
||||||
This is class for definition of a 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 VertContainer (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.
|
@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 >
|
template < class STL_VERT_CONT, class STL_FACE_CONT >
|
||||||
class Mesh{
|
class TriMesh{
|
||||||
public:
|
public:
|
||||||
/// The face container
|
typedef STL_FACE_CONT FaceContainer;
|
||||||
typedef STL_FACE_CONT face_container;
|
typedef STL_VERT_CONT VertContainer;
|
||||||
/// The face container
|
typedef typename VertContainer::value_type VertexType;
|
||||||
typedef STL_VERT_CONT vertex_container;
|
typedef typename FaceContainer::value_type FaceType;
|
||||||
/// The vertex type
|
typedef typename VertexType::ScalarType ScalarType;
|
||||||
typedef typename STL_VERT_CONT::value_type MVTYPE;
|
typedef typename VertexType::CoordType CoordType;
|
||||||
/// The face type
|
typedef typename VertContainer::iterator VertexIterator;
|
||||||
typedef typename STL_FACE_CONT::value_type MFTYPE;
|
typedef typename FaceContainer::iterator FaceIterator;
|
||||||
/// The scalar type
|
typedef typename VertContainer::const_iterator ConstVertexIterator;
|
||||||
typedef typename MVTYPE::scalar_type MCTYPE;
|
typedef typename FaceContainer::const_iterator ConstFaceIterator;
|
||||||
/// The type of the vectors
|
typedef VertexType * VertexPointer;
|
||||||
typedef typename MFTYPE::vectorial_type vectorial_type;
|
typedef const VertexType * ConstVertexPointer;
|
||||||
/// The type of the scalars
|
typedef FaceType * FacePointer;
|
||||||
typedef MCTYPE scalar_type;
|
typedef const FaceType * ConstFacePointer;
|
||||||
/// The vertex type
|
typedef Box3<ScalarType> BoxType;
|
||||||
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
|
/// Set of vertices
|
||||||
STL_VERT_CONT vert;
|
VertContainer vert;
|
||||||
/// Real number of vertices
|
/// Real number of vertices
|
||||||
int vn;
|
int vn;
|
||||||
/// Set of faces
|
/// Set of faces
|
||||||
STL_FACE_CONT face;
|
FaceContainer face;
|
||||||
/// Real number of faces
|
/// Real number of faces
|
||||||
int fn;
|
int fn;
|
||||||
/// Bounding box of the mesh
|
/// Bounding box of the mesh
|
||||||
Box3<MCTYPE> bbox;
|
Box3<ScalarType> bbox;
|
||||||
/// Internal status
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/// Nomi di textures
|
/// Nomi di textures
|
||||||
vector<string> textures;
|
//vector<string> textures;
|
||||||
vector<string> normalmaps;
|
//vector<string> normalmaps;
|
||||||
|
|
||||||
/// La camera
|
/// La camera
|
||||||
Camera<scalar_type> camera;
|
//Camera<ScalarType> camera;
|
||||||
|
|
||||||
/// Il colore della mesh
|
/// Il colore della mesh
|
||||||
private:
|
private:
|
||||||
ColorUB c;
|
Color4b c;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline const ColorUB & C() const
|
inline const Color4b & C() const
|
||||||
{
|
{
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ColorUB & C()
|
inline Color4b & C()
|
||||||
{
|
{
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Default constructor
|
/// Default constructor
|
||||||
Mesh()
|
TriMesh()
|
||||||
{
|
{
|
||||||
fn = vn = 0;
|
fn = vn = 0;
|
||||||
imark = 0;
|
imark = 0;
|
||||||
|
@ -175,42 +120,39 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/// Function to destroy the mesh
|
/// Function to destroy the mesh
|
||||||
MMTYPE & Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
vert.clear();
|
vert.clear();
|
||||||
face.clear();
|
face.clear();
|
||||||
textures.clear();
|
// textures.clear();
|
||||||
normalmaps.clear();
|
// normalmaps.clear();
|
||||||
vn = 0;
|
vn = 0;
|
||||||
fn = 0;
|
fn = 0;
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Funzioni di info sulle caratteristiche della mesh */
|
/* Funzioni di info sulle caratteristiche della mesh */
|
||||||
|
|
||||||
static bool HasPerVertexNormal() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_N)); }
|
static bool HasPerVertexNormal() { return VertexType::HasNormal() ; }
|
||||||
static bool HasPerVertexColor() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_C)); }
|
static bool HasPerVertexColor() { return VertexType::HasColor() ; }
|
||||||
static bool HasPerVertexMark() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_M)); }
|
static bool HasPerVertexMark() { return VertexType::HasMark() ; }
|
||||||
static bool HasPerVertexQuality() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_Q)); }
|
static bool HasPerVertexQuality() { return VertexType::HasQuality(); }
|
||||||
static bool HasPerVertexTexture() { return bool(vertex_type::OBJ_TYPE & (vertex_type::OBJ_TYPE_T)); }
|
static bool HasPerVertexTexture() { return VertexType::HasTexture(); }
|
||||||
|
|
||||||
static bool HasPerFaceColor() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_C)); }
|
static bool HasPerFaceColor() { return FaceType::HasFaceNormal() ; }
|
||||||
static bool HasPerFaceNormal() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_N)); }
|
static bool HasPerFaceNormal() { return FaceType::HasFaceColor() ; }
|
||||||
static bool HasPerFaceMark() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_M)); }
|
static bool HasPerFaceMark() { return FaceType::HasFaceMark() ; }
|
||||||
static bool HasPerFaceQuality() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_Q)); }
|
static bool HasPerFaceQuality() { return FaceType::HasFaceQuality(); }
|
||||||
|
|
||||||
static bool HasPerWedgeColor() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_WC)); }
|
static bool HasPerWedgeColor() { return bool(FaceType::OBJ_TYPE & (FaceType::OBJ_TYPE_WC)); }
|
||||||
static bool HasPerWedgeNormal() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_WN)); }
|
static bool HasPerWedgeNormal() { return bool(FaceType::OBJ_TYPE & (FaceType::OBJ_TYPE_WN)); }
|
||||||
static bool HasPerWedgeTexture() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_WT)); }
|
static bool HasPerWedgeTexture() { return bool(FaceType::OBJ_TYPE & (FaceType::OBJ_TYPE_WT)); }
|
||||||
|
|
||||||
static bool HasFFTopology() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_A)) || HasSTopology(); }
|
static bool HasFFTopology() { return bool(FaceType::OBJ_TYPE & (FaceType::OBJ_TYPE_A)) || HasSTopology(); }
|
||||||
static bool HasVFTopology() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_V)) || HasSTopology(); }
|
static bool HasVFTopology() { return bool(FaceType::OBJ_TYPE & (FaceType::OBJ_TYPE_V)) || HasSTopology(); }
|
||||||
static bool HasSTopology() { return bool(face_type::OBJ_TYPE & (face_type::OBJ_TYPE_S)); }
|
static bool HasSTopology() { return bool(FaceType::OBJ_TYPE & (FaceType::OBJ_TYPE_S)); }
|
||||||
static bool HasTopology() { return HasFFTopology() || HasVFTopology(); }
|
static bool HasTopology() { return HasFFTopology() || HasVFTopology(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Initialize the imark-system of the faces
|
/// Initialize the imark-system of the faces
|
||||||
void InitFaceIMark()
|
void InitFaceIMark()
|
||||||
{
|
{
|
||||||
|
@ -231,178 +173,37 @@ void InitVertexIMark()
|
||||||
(*vi).InitIMark();
|
(*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
|
/// The incremental mark
|
||||||
int imark;
|
int imark;
|
||||||
|
|
||||||
/** Check if the vertex incremental mark matches the one of the mesh.
|
/** Check if the vertex incremental mark matches the one of the mesh.
|
||||||
@param v Vertex pointer
|
@param v Vertex pointer
|
||||||
*/
|
*/
|
||||||
inline bool IsMarked( MVTYPE * const v ) const { return v->IMark() == imark; }
|
inline bool IsMarked( ConstVertexPointer v ) const { return v->IMark() == imark; }
|
||||||
/** Check if the face incremental mark matches the one of the mesh.
|
/** Check if the face incremental mark matches the one of the mesh.
|
||||||
@param v Face pointer
|
@param v Face pointer
|
||||||
*/
|
*/
|
||||||
inline bool IsMarked( MFTYPE * const f ) const { return f->IMark() == imark; }
|
inline bool IsMarked( ConstFacePointer f ) const { return f->IMark() == imark; }
|
||||||
/** Set the vertex incremental mark of the vertex to the one of the mesh.
|
/** Set the vertex incremental mark of the vertex to the one of the mesh.
|
||||||
@param v Vertex pointer
|
@param v Vertex pointer
|
||||||
*/
|
*/
|
||||||
inline void Mark( MVTYPE * const v ) const { v->IMark() = imark; }
|
inline void Mark( ConstVertexPointer v ) const { v->IMark() = imark; }
|
||||||
/** Set the face incremental mark of the vertex to the one of the mesh.
|
/** Set the face incremental mark of the vertex to the one of the mesh.
|
||||||
@param v Vertex pointer
|
@param v Vertex pointer
|
||||||
*/
|
*/
|
||||||
inline void Mark( MFTYPE * const f ) const { f->IMark() = imark; }
|
inline void Mark( ConstFacePointer f ) const { f->IMark() = imark; }
|
||||||
/// Unmark the mesh
|
/// Unmark the mesh
|
||||||
inline void UnMarkAll() { ++imark; }
|
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
|
/// Calcolo del volume di una mesh chiusa
|
||||||
scalar_type Volume()
|
ScalarType Volume()
|
||||||
{
|
{
|
||||||
|
|
||||||
face_iterator f;
|
face_iterator f;
|
||||||
int j,k;
|
int j,k;
|
||||||
scalar_type V = 0;
|
ScalarType V = 0;
|
||||||
vectorial_type T,N,B;
|
vectorial_type T,N,B;
|
||||||
|
|
||||||
for(f = face.begin(); f!=face.end(); ++f)
|
for(f = face.begin(); f!=face.end(); ++f)
|
||||||
|
@ -433,6 +234,7 @@ scalar_type Volume()
|
||||||
}; // end class Mesh
|
}; // end class Mesh
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace
|
||||||
} // end namespace
|
} // end namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,150 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* 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 $
|
||||||
|
Revision 1.1 2004/02/19 13:11:06 cignoni
|
||||||
|
Initial commit
|
||||||
|
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __VCG_TRI_UPDATE_NORMALS
|
||||||
|
#define __VCG_TRI_UPDATE_NORMALS
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
namespace tri {
|
||||||
|
|
||||||
|
template <class ComputeMeshType>
|
||||||
|
class UpdateNormals
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef ComputeMeshType MeshType;
|
||||||
|
typedef typename MeshType::VertexType VertexType;
|
||||||
|
typedef typename MeshType::VertexPointer VertexPointer;
|
||||||
|
typedef typename MeshType::VertexIterator VertexIterator;
|
||||||
|
typedef typename MeshType::FaceType FaceType;
|
||||||
|
typedef typename MeshType::FacePointer FacePointer;
|
||||||
|
typedef typename MeshType::FaceIterator FaceIterator;
|
||||||
|
|
||||||
|
static void PerFaceRW(ComputeMeshType &m, bool normalize=false)
|
||||||
|
{
|
||||||
|
if( !m.HasPerFaceNormal()) return;
|
||||||
|
|
||||||
|
FaceIterator f;
|
||||||
|
bool cn = true;
|
||||||
|
|
||||||
|
if(normalize)
|
||||||
|
{
|
||||||
|
for(f=m.m.face.begin();f!=m.m.face.end();++f)
|
||||||
|
if( !(*f).IsD() && (*f).IsRW() )
|
||||||
|
{
|
||||||
|
for(int j=0; j<3); ++j)
|
||||||
|
if( !(*f).V(j)->IsR()) cn = false;
|
||||||
|
if( cn ) (*f).ComputeNormalizedNormal();
|
||||||
|
cn = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(f=m.m.face.begin();f!=m.m.face.end();++f)
|
||||||
|
if( !(*f).IsD() && (*f).IsRW() )
|
||||||
|
{
|
||||||
|
for(int j=0; j<3; ++j)
|
||||||
|
if( !(*f).V(j)->IsR()) cn = false;
|
||||||
|
|
||||||
|
if( cn )
|
||||||
|
(*f).ComputeNormal();
|
||||||
|
cn = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void PerFaceNormalized(ComputeMeshType &m)
|
||||||
|
{
|
||||||
|
if( !m.HasPerFaceNormal()) return;
|
||||||
|
FaceIterator f;
|
||||||
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
|
if( !(*f).IsD() ) (*f).ComputeNormalizedNormal();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PerFace(ComputeMeshType &m)
|
||||||
|
{
|
||||||
|
if( !m.HasPerFaceNormal()) return;
|
||||||
|
FaceIterator f;
|
||||||
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
|
if( !(*f).IsD() ) (*f).ComputeNormal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculates the vertex normal
|
||||||
|
static void PerVertexNormalized(ComputeMeshType &m)
|
||||||
|
{
|
||||||
|
if( !m.HasPerVertexNormal()) return;
|
||||||
|
PerVertex(m);
|
||||||
|
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
|
if( !(*vi).IsD() && (*vi).IsRW() )
|
||||||
|
(*vi).N().Normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculates the vertex normal
|
||||||
|
static void PerVertex(ComputeMeshType &m)
|
||||||
|
{
|
||||||
|
if( !m.HasPerVertexNormal()) return;
|
||||||
|
|
||||||
|
VertexIterator vi;
|
||||||
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
|
if( !(*vi).IsD() && (*vi).IsRW() )
|
||||||
|
(*vi).N() = VertexType::NormalType(0,0,0);
|
||||||
|
|
||||||
|
FaceIterator f;
|
||||||
|
|
||||||
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
|
if( !(*f).IsD() && (*f).IsR() )
|
||||||
|
{
|
||||||
|
FaceType::NormalType t = (*f).Normal();
|
||||||
|
|
||||||
|
for(int j=0; j<3; ++j)
|
||||||
|
if( !(*f).V(j)->IsD() && (*f).V(j)->IsRW() )
|
||||||
|
(*f).V(j)->N() += t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ComputeE()
|
||||||
|
{
|
||||||
|
FaceIterator f;
|
||||||
|
|
||||||
|
for(f = m.face.begin(); f!=m.face.end(); ++f)
|
||||||
|
(*f).ComputeE();
|
||||||
|
}
|
||||||
|
|
||||||
|
}; // end class
|
||||||
|
|
||||||
|
} // End namespace
|
||||||
|
} // End namespace
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue