vcglib/vcg/complex/trimesh/base.h

282 lines
8.3 KiB
C
Raw Normal View History

2004-03-04 01:08:15 +01:00
/****************************************************************************
* 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 $
2004-10-28 02:56:44 +02:00
Revision 1.11 2004/10/07 14:25:38 ganovelli
added camera and shot
2004-10-07 16:25:38 +02:00
Revision 1.10 2004/09/08 15:15:05 ganovelli
changes for gcc
2004-09-08 17:15:05 +02:00
Revision 1.9 2004/07/15 12:03:50 ganovelli
access to imark added
2004-07-15 14:03:50 +02:00
Revision 1.8 2004/07/15 11:39:24 ganovelli
IsDeleted to IsD
2004-07-15 13:39:24 +02:00
Revision 1.7 2004/07/09 10:18:19 ganovelli
added access functions to vn and fn
2004-07-09 12:18:19 +02:00
Revision 1.6 2004/05/04 02:29:54 ganovelli
removed Const from ConstFacePointer and ConstVertexPointer in the arguement function Mark, which are meant to be changed
Revision 1.5 2004/03/18 16:00:10 cignoni
minor changes
2004-03-18 17:00:10 +01:00
Revision 1.4 2004/03/10 00:57:44 cignoni
minor changes
2004-03-10 02:00:21 +01:00
Revision 1.3 2004/03/07 21:54:56 cignoni
some more reflection functions
2004-03-07 22:54:56 +01:00
Revision 1.2 2004/03/04 00:08:15 cignoni
First working version!
2004-03-04 01:08:15 +01:00
Revision 1.1 2004/02/19 13:11:06 cignoni
Initial commit
****************************************************************************/
2004-09-08 17:15:05 +02:00
#ifndef __GNUC
2004-03-04 01:08:15 +01:00
#pragma warning( disable : 4804 )
2004-09-08 17:15:05 +02:00
#endif
2004-07-15 14:03:50 +02:00
#include <vcg/space/box3.h>
2004-10-07 16:25:38 +02:00
#include <vcg/math/shot.h>
2004-03-04 01:08:15 +01:00
/*
People should subclass his vertex class from these one...
*/
#ifndef __VCG_MESH
#define __VCG_MESH
namespace vcg {
namespace tri {
2004-03-18 17:00:10 +01:00
/** \addtogroup trimesh */
/*@{*/
2004-10-28 02:56:44 +02:00
/*@{*/
2004-03-04 01:08:15 +01:00
/** Class Mesh.
This is class for definition of a mesh.
2004-10-28 02:56:44 +02:00
@param VertContainerType (Template Parameter) Specifies the type of the vertices container any the vertex type.
@param FaceContainerType (Template Parameter) Specifies the type of the faces container any the face type.
2004-03-04 01:08:15 +01:00
*/
2004-03-10 02:00:21 +01:00
template < class VertContainerType, class FaceContainerType >
2004-03-04 01:08:15 +01:00
class TriMesh{
public:
2004-03-10 02:00:21 +01:00
typedef FaceContainerType FaceContainer;
typedef VertContainerType VertContainer;
2004-03-04 01:08:15 +01:00
typedef typename VertContainer::value_type VertexType;
typedef typename FaceContainer::value_type FaceType;
typedef typename VertexType::ScalarType ScalarType;
typedef typename VertexType::CoordType CoordType;
typedef typename VertContainer::iterator VertexIterator;
typedef typename FaceContainer::iterator FaceIterator;
typedef typename VertContainer::const_iterator ConstVertexIterator;
typedef typename FaceContainer::const_iterator ConstFaceIterator;
typedef VertexType * VertexPointer;
typedef const VertexType * ConstVertexPointer;
typedef FaceType * FacePointer;
typedef const FaceType * ConstFacePointer;
typedef Box3<ScalarType> BoxType;
/// Set of vertices
VertContainer vert;
/// Real number of vertices
int vn;
/// Set of faces
FaceContainer face;
/// Real number of faces
int fn;
/// Bounding box of the mesh
Box3<ScalarType> bbox;
/// Nomi di textures
//vector<string> textures;
//vector<string> normalmaps;
/// La camera
2004-10-07 16:25:38 +02:00
Camera<ScalarType> camera; // intrinsic
Shot<ScalarType> shot; // extrinsic
2004-03-04 01:08:15 +01:00
/// Il colore della mesh
private:
Color4b c;
public:
inline const Color4b & C() const
{
return c;
}
inline Color4b & C()
{
return c;
}
/// Default constructor
2004-10-07 16:25:38 +02:00
TriMesh():shot(camera)
2004-03-04 01:08:15 +01:00
{
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
void Clear()
{
vert.clear();
face.clear();
// textures.clear();
// normalmaps.clear();
vn = 0;
fn = 0;
}
2004-03-07 22:54:56 +01:00
/// Reflection functions that speak about vertex and face properties.
2004-03-04 01:08:15 +01:00
static bool HasPerVertexNormal() { return VertexType::HasNormal() ; }
static bool HasPerVertexColor() { return VertexType::HasColor() ; }
static bool HasPerVertexMark() { return VertexType::HasMark() ; }
static bool HasPerVertexQuality() { return VertexType::HasQuality(); }
static bool HasPerVertexTexture() { return VertexType::HasTexture(); }
2004-03-10 02:00:21 +01:00
static bool HasPerFaceColor() { return FaceType::HasFaceColor() ; }
static bool HasPerFaceNormal() { return FaceType::HasFaceNormal() ; }
2004-03-04 01:08:15 +01:00
static bool HasPerFaceMark() { return FaceType::HasFaceMark() ; }
static bool HasPerFaceQuality() { return FaceType::HasFaceQuality(); }
2004-03-10 02:00:21 +01:00
static bool HasPerWedgeColor() { return FaceType::HasWedgeColor() ; }
static bool HasPerWedgeNormal() { return FaceType::HasWedgeNormal() ; }
2004-03-07 22:54:56 +01:00
static bool HasPerWedgeMark() { return FaceType::HasWedgeMark() ; }
static bool HasPerWedgeQuality() { return FaceType::HasWedgeQuality(); }
2004-03-10 02:00:21 +01:00
static bool HasPerWedgeTexture() { return FaceType::HasWedgeTexture(); }
2004-03-04 01:08:15 +01:00
2004-03-07 22:54:56 +01:00
static bool HasFFTopology() { return FaceType::HasFFAdjacency(); }
static bool HasVFTopology() { return FaceType::HasVFAdjacency(); }
2004-03-04 01:08:15 +01:00
static bool HasTopology() { return HasFFTopology() || HasVFTopology(); }
2004-07-09 12:18:19 +02:00
int & SimplexNumber(){ return fn;}
int & VertexNumber(){ return vn;}
2004-03-04 01:08:15 +01:00
/// Initialize the imark-system of the faces
void InitFaceIMark()
{
2004-03-10 02:00:21 +01:00
FaceIterator f;
2004-03-04 01:08:15 +01:00
for(f=face.begin();f!=face.end();++f)
2004-07-15 13:39:24 +02:00
if( !(*f).IsD() && (*f).IsR() && (*f).IsW() )
2004-03-04 01:08:15 +01:00
(*f).InitIMark();
}
/// Initialize the imark-system of the vertices
void InitVertexIMark()
{
2004-03-10 02:00:21 +01:00
VertexIterator vi;
2004-03-04 01:08:15 +01:00
for(vi=vert.begin();vi!=vert.end();++vi)
2004-07-15 13:39:24 +02:00
if( !(*vi).IsD() && (*vi).IsRW() )
2004-03-04 01:08:15 +01:00
(*vi).InitIMark();
}
/// The incremental mark
int imark;
2004-07-15 14:03:50 +02:00
/** Access function to the incremental mark.
*/
inline int & IMark(){return imark;}
2004-03-04 01:08:15 +01:00
/** Check if the vertex incremental mark matches the one of the mesh.
@param v Vertex pointer
*/
inline bool IsMarked( ConstVertexPointer 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( ConstFacePointer 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( VertexPointer v ) const { v->IMark() = imark; }
2004-03-04 01:08:15 +01:00
/** Set the face incremental mark of the vertex to the one of the mesh.
@param v Vertex pointer
*/
inline void Mark( FacePointer f ) const { f->IMark() = imark; }
2004-03-04 01:08:15 +01:00
/// Unmark the mesh
inline void UnMarkAll() { ++imark; }
/// Calcolo del volume di una mesh chiusa
ScalarType Volume()
{
2004-03-10 02:00:21 +01:00
FaceIterator fi;
2004-03-04 01:08:15 +01:00
int j,k;
ScalarType V = 0;
2004-03-10 02:00:21 +01:00
CoordType T,N,B;
2004-03-04 01:08:15 +01:00
2004-03-10 02:00:21 +01:00
for(fi = face.begin(); fi!=face.end(); ++fi)
2004-03-04 01:08:15 +01:00
{
2004-03-10 02:00:21 +01:00
for(j = 0; j < 3; ++j)
{
/*calcolo tangente, normale e binormale (6 volte)*/
k = (j+1)%3;
T = (*fi).P(k) - (*fi).P(j);
T.Normalize();
T = ( (*fi).P( k ) - (*fi).P(j) ) ^
( (*fi).P((k+1)%3) - (*fi).P(j) ) ;
B.Normalize();
N = T ^ B;
CoordType pj = (*fi).P(j);
CoordType pk = (*fi).P(k);
2004-03-04 01:08:15 +01:00
2004-03-10 02:00:21 +01:00
V += (pj* T )*(pj*N)*(pj*B);
V += (pk*(-T))*(pk*N)*(pk*B);
}
2004-03-04 01:08:15 +01:00
}
2004-03-10 02:00:21 +01:00
return V/6.0;
2004-03-04 01:08:15 +01:00
}
}; // end class Mesh
2004-10-28 02:56:44 +02:00
/*@}*/
2004-03-18 17:00:10 +01:00
/*@}*/
2004-03-04 01:08:15 +01:00
} // end namespace
} // end namespace
#endif