*** empty log message ***

This commit is contained in:
Nico Pietroni 2004-05-12 13:52:11 +00:00
parent 8a4f1f166f
commit 51d795b795
3 changed files with 144 additions and 283 deletions

View File

@ -1,265 +0,0 @@
/****************************************************************************
* 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
Revision 1.1 2004/19/04 13:05 pietroni
Initial commit
****************************************************************************/
#ifndef __VCG_TETRA_ALLOCATE
#define __VCG_TETRA_ALLOCATE
#include <vector>
using namespace std;
namespace vcg {
namespace tetra {
/** \addtogroup tetramesh */
/*@{*/
/** Class Allocate.
This is class for Allocate new vertices or tetrahedron on the mesh.
@param TM_TYPE (Template Parameter) Specifies the type of the tetrahedral mesh.
*/
template < class TM_TYPE >
class Allocator
{
public:
/// The tetramesh type
typedef TM_TYPE TetraMeshType;
/// The vertex type
typedef typename TM_TYPE::VertexType VertexType;
/// The tetrahedron type
typedef typename TM_TYPE::TetraType TetraType;
/// The type of vertex iterator
typedef typename TM_TYPE::VertexIterator VertexIterator;
/// The type of tetra iterator
typedef typename TM_TYPE::TetraIterator TetraIterator;
/// The type of constant vertex iterator
typedef typename TM_TYPE::const_VertexIterator const_VertexIterator;
/// The type of constant face iterator
typedef typename TM_TYPE::const_TetraIterator const_TetraIterator;
public:
/** 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.
*/
VertexIterator AddVertices(TetraMeshType &m,int n, vector<VertexType **> &local_var)
{
VertexIterator oldbegin, newbegin;
oldbegin = m.vert.begin();
VertexIterator last=m.vert.end();
if(m.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(m.vert.begin(),last,siz);
#else
if(last!=0) siz=distance(m.vert.begin(),last);
#endif
for(unsigned int i=0; i<n; ++i)
{
m.vert.push_back(VertexType());
m.vert.back().ClearFlags();
}
m.vn+=n;
newbegin = m.vert.begin();
if(newbegin != oldbegin)
{
TetraIterator f;
for (f=m.tetra.begin(); f!=m.tetra.end(); ++f)
if(!(*f).IsD())
for(unsigned int k=0; k<4; ++k)
(*f).V(k)= (*f).V(k)-&*oldbegin+&*newbegin;
for(unsigned 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 = m.vert.begin();
advance(last,siz+1);
}
else last=m.vert.begin();
}
else
{
// se non e'cambiato lo spazio (vector abbastanza grande o lista)
if(last==0) last = m.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;
}
/** Function to add n vertices to the mesh.
@param n Il numero di vertici che si vuole aggiungere alla mesh.
*/
VertexIterator AddVertices(TetraMeshType &m,int n)
{
VertexIterator oldbegin, newbegin;
oldbegin = m.vert.begin();
VertexIterator last=m.vert.end();
if(m.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(m.vert.begin(),last,siz);
#else
if(last!=0) siz=distance(m.vert.begin(),last);
#endif
for(unsigned int i=0; i<n; ++i)
{
m.vert.push_back(VertexType());
m.vert.back().ClearFlags();
}
m.vn+=n;
newbegin = m.vert.begin();
if(newbegin != oldbegin)
{
TetraIterator f;
for (f=m.tetra.begin(); f!=m.tetra.end(); ++f)
if(!(*f).IsD())
for(unsigned int k=0; k<4; ++k)
(*f).V(k)= (*f).V(k)-&*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 = m.vert.begin();
advance(last,siz+1);
}
else last=m.vert.begin();
}
else
{
// se non e'cambiato lo spazio (vector abbastanza grande o lista)
if(last==0) last = m.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;
}
template <class MESH_TYPE >
struct InsertedVT{
InsertedVT( MESH_TYPE::VertexType *_v,
MESH_TYPE::TetraType *_t,
int _z):v(_v),t(_t),z(_z){}
MESH_TYPE::VertexType *v;
MESH_TYPE::TetraType *t;
int z;
const bool operator <(const InsertedVT & o){
return (v<o.v);
}
const bool operator ==(const InsertedVT & o){
return (v==o.v);
}
const bool operator !=(const InsertedVT & o){
return (v!=o.v);
}
};
/** Crate a copy of the mesh with tetrahedron that are into the templated container
@param ST_CONT (Template Parameter) Specifies the type of the container of tetrahedron.
@param subSet Container of tetrahedron.
@param m destination mesh.
*/
template <class STL_CONT >
void SubSetT(STL_CONT & subSet, TetraMeshType & m)
{
vector< InsertedVT< TetraMeshType > > newVertices;
STL_CONT :: iterator pfi;
newVertices.clear();
for(pfi = subSet.begin(); pfi != subSet.end(); ++pfi)
m.tetra.push_back((*pfi));
TetraIterator fi;
for(fi = m.tetra.begin(); fi != m.tetra.end(); ++fi)
{
newVertices.push_back(InsertedVT< TetraMeshType >( (*fi).V(0),&(*fi),0));
newVertices.push_back(InsertedVT< TetraMeshType >( (*fi).V(1),&(*fi),1));
newVertices.push_back(InsertedVT< TetraMeshType >( (*fi).V(2),&(*fi),2));
newVertices.push_back(InsertedVT< TetraMeshType >( (*fi).V(3),&(*fi),3));
}
sort(newVertices.begin(),newVertices.end());
vector< InsertedVT< TetraMeshType > >::iterator curr,next;
int pos = 0;
curr = next = newVertices.begin();
while( next != newVertices.end())
{
if((*curr)!=(*next))
pos++;
(*next).t->V( (*next).z) = (VertexType *)pos;
curr = next;
next++;
}
vector<InsertedVT< TetraMeshType > >::iterator newE = unique(newVertices.begin(),newVertices.end());
for(curr = newVertices.begin();curr!= newE;++curr)
m.vert.push_back(*((*curr).v));
for(fi = m.tetra.begin(); fi != m.tetra.end(); ++fi)
{
(*fi).V(0) = &(m.vert[(int)(*fi).V(0)]);
(*fi).V(1) = &(m.vert[(int)(*fi).V(1)]);
(*fi).V(2) = &(m.vert[(int)(*fi).V(2)]);
(*fi).V(3) = &(m.vert[(int)(*fi).V(3)]);
}
m.vn = m.vert.size();
m.tn = m.tetra.size();
}
}; // end class
/*@}*/
} // End namespace
} // End namespace
#endif

View File

@ -0,0 +1,127 @@
/****************************************************************************
* 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.2 2004/03/12 15:22:19 pietroni
Written some documentation and added to the trimes doxygen module
****************************************************************************/
#ifndef __VCG_TETRA_UPDATE_NORMALS
#define __VCG_TETRA_UPDATE_NORMALS
#include<complex\tetramesh\update\triconvert.h>
#include<simplex\face\face.h>
#include<complex\trimesh\base.h>
#include<complex\trimesh\update\normal.h>
#include<vector>
namespace vcg {
namespace tetra {
/** \addtogroup trimesh */
/*@{*/
/// Management, updating and computation of per-vertex and per-face normals.
/// This class is used to compute or update the normals that can be stored in the vertex or face component of a mesh.
template <class ComputeMeshType>
class UpdateNormals
{
public:
typedef ComputeMeshType TetraMeshType;
typedef typename TetraMeshType::VertexType VertexType;
typedef typename TetraMeshType::VertexPointer VertexPointer;
typedef typename TetraMeshType::VertexIterator VertexIterator;
typedef typename TetraMeshType::TetraType TetraType;
typedef typename TetraMeshType::TetraPointer TetraPointer;
typedef typename TetraMeshType::TetraIterator TetraIterator;
typedef vcg::Face<VertexType> FaceTemp;
typedef vcg::tri::TriMesh< vector<VertexType>,vector<FaceTemp> > TriMeshTemp;
/// Calculates the vertex normal (if stored in the current face type)
static void PerTetraFace(TetraMeshType &m)
{
if( !m.HasPerTetraNormal()) return;
TetraIterator t;
for(t=m.tetra.begin();t!=m.tetra.end();++t)
if( !(*t).IsD() ) (*t).ComputeNormal();
}
/// Calculates the vertex normal. Without exploiting or touching face normals
/// The normal of a vertex v is the weigthed average of the normals of the faces incident on v.
static void PerVertex(TetraMeshType &m)
{
if( !m.HasPerVertexNormal()) return;
_ClearNormal(m);
TriMeshTemp tri_mesh=TriMeshTemp();
TriConverter <TetraMeshType,TriMeshTemp>tric=TriConverter<TetraMeshType,TriMeshTemp>();
tric.Convert(m,tri_mesh);
vcg::tri::UpdateNormals<TriMeshTemp> UNT=vcg::tri::UpdateNormals<TriMeshTemp>();
UNT.PerVertexNormalized(tri_mesh);
}
private:
static void _ClearNormal(TetraMeshType &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);
}
///// Calculates both vertex and face normals.
///// The normal of a vertex v is the weigthed average of the normals of the faces incident on v.
//static void PerVertexPerFace(ComputeTetraMeshType &m)
//{
// if( !m.HasPerVertexNormal() || !m.HasPerFaceNormal()) return;
//
//
//}
//
//
//static void PerFaceNormalized(ComputeTetraMeshType &m)
//{
//
//}
//
//
///// Calculates the vertex normal
//static void PerVertexNormalized(ComputeTetraMeshType &m)
//{
//
//}
}; // end class
} // End namespace
} // End namespace
#endif

View File

@ -48,14 +48,14 @@ class TriConverter
public:
/// The tetrahedral mesh type
typedef TETRA_MESH TetraMeshType;
typedef typename TETRA_MESH TetraMeshType;
/// The triangle mesh type
typedef TRI_MESH TriangleMeshType;
typedef typename TRI_MESH TriangleMeshType;
/// The tetrahedron type
typedef TetraMeshType::TetraType TetraType;
typedef typename TetraMeshType::TetraType TetraType;
/// The triangle type
typedef TriangleMeshType::FaceType FaceType;
typedef typename TriangleMeshType::FaceType FaceType;
/// The vertex type of tetrahedreal Mesh
typedef typename TetraMeshType::VertexType TetraVertexType;
@ -73,12 +73,12 @@ public:
typedef typename TriangleMeshType::FaceIterator FaceIterator;
/// The type of const tetra iterator
typedef TetraMeshType::const_TetraIterator const_TetraIterator;
typedef typename TetraMeshType::const_TetraIterator const_TetraIterator;
/// The type of const face iterator
typedef TriangleMeshType::ConstFaceIterator ConstFaceIterator;
typedef typename TriangleMeshType::ConstFaceIterator ConstFaceIterator;
/// The type of const vertex pointer of tetrahedral mesh
typedef TetraMeshType::const_VertexPointer const_VertexPointer;
typedef typename TetraMeshType::const_VertexPointer const_VertexPointer;
public:
@ -121,14 +121,13 @@ void Convert(TetraMeshType &tetram,TriangleMeshType &trim)
}
template <class I_MESH_TYPE>
struct InsertedV{
InsertedV( I_MESH_TYPE::VertexType *_v,
I_MESH_TYPE::FacePointer _f,
InsertedV( TriVertexType *_v,
FaceType* _f,
int _z):v(_v),f(_f),z(_z){}
I_MESH_TYPE::VertexType *v;
I_MESH_TYPE::FacePointer f;
TriVertexType *v;
FaceType* f;
int z;
const bool operator <(const InsertedV & o){
@ -147,7 +146,7 @@ struct InsertedV{
void ConvertCopy(TetraMeshType &tetram,TriangleMeshType &trim)
{
vector<InsertedV<TriangleMeshType > > newVertices;
vector<InsertedV > newVertices;
TriVertexIterator vi;
vector<TriVertexType*> redirect;
@ -157,14 +156,14 @@ void ConvertCopy(TetraMeshType &tetram,TriangleMeshType &trim)
FaceIterator fi;
for(fi = trim.face.begin(); fi != trim.face.end(); ++fi){
newVertices.push_back(InsertedV<TriangleMeshType >( (*fi).V(0),&(*fi),0));
newVertices.push_back(InsertedV<TriangleMeshType >( (*fi).V(1),&(*fi),1));
newVertices.push_back(InsertedV<TriangleMeshType >( (*fi).V(2),&(*fi),2));
newVertices.push_back(InsertedV( (*fi).V(0),&(*fi),0));
newVertices.push_back(InsertedV( (*fi).V(1),&(*fi),1));
newVertices.push_back(InsertedV( (*fi).V(2),&(*fi),2));
}
sort(newVertices.begin(),newVertices.end());
vector<InsertedV<TriangleMeshType > >::iterator curr,next;
vector<InsertedV>::iterator curr,next;
int pos = 0;
curr = next = newVertices.begin();
while( next != newVertices.end()){
@ -175,7 +174,7 @@ void ConvertCopy(TetraMeshType &tetram,TriangleMeshType &trim)
next++;
}
vector<InsertedV<TriangleMeshType > >::iterator newE = unique(newVertices.begin(),newVertices.end());
vector<InsertedV>::iterator newE = unique(newVertices.begin(),newVertices.end());
for(curr = newVertices.begin();curr!= newE;++curr)
trim.vert.push_back(*((*curr).v));