From 6d04f844de2c02cb589d63d4559e915fea2901a0 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Wed, 28 Apr 2004 11:37:14 +0000 Subject: [PATCH] *** empty log message *** --- vcg/complex/tetramesh/base.h | 5 +- vcg/complex/tetramesh/update/triconvert.h | 200 ++++++++++++++++++++++ 2 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 vcg/complex/tetramesh/update/triconvert.h diff --git a/vcg/complex/tetramesh/base.h b/vcg/complex/tetramesh/base.h index 11548984..f67c62db 100644 --- a/vcg/complex/tetramesh/base.h +++ b/vcg/complex/tetramesh/base.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/04/20 12:41:39 pietroni +*** empty log message *** + Revision 1.1 2004/04/15 08:54:20 pietroni *** empty log message *** @@ -218,7 +221,7 @@ void LoadTs(char * filename, double meshscale ) fscanf(f, "%f", &x ); fscanf(f, "%f", &y ); fscanf(f, "%f", &z ); - fscanf(f, "%f", &mass ); + //fscanf(f, "%f", &mass ); p1.P()=Point3d(x*meshscale, y*meshscale ,z*meshscale ); vert.push_back(p1); } diff --git a/vcg/complex/tetramesh/update/triconvert.h b/vcg/complex/tetramesh/update/triconvert.h new file mode 100644 index 00000000..eeb726cb --- /dev/null +++ b/vcg/complex/tetramesh/update/triconvert.h @@ -0,0 +1,200 @@ +/**************************************************************************** +* 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/22/04 14:32 pietroni +Initial commit + + +****************************************************************************/ +#ifndef __VCG_TETRA_TRI_CONVERTER +#define __VCG_TETRA_TRI_CONVERTER +#include +#include +namespace vcg { +namespace tetra { + + + /** Class TriConverter. + This is class for convetr tetrahedral mesh into triangle mesh + @param STL_VERT_CONT (Template Parameter) Specifies the type of the vertices container any the vertex type. + @param STL_TETRA_CONT (Template Parameter) Specifies the type of the tetrahedrons container any the tetrahedrons type. + */ +template < class TETRA_MESH ,class TRI_MESH > +class TriConverter +{ + +public: + + /// The tetrahedral mesh type + typedef TETRA_MESH TetraMeshType; + /// The triangle mesh type + typedef TRI_MESH TriangleMeshType; + + /// The tetrahedron type + typedef TetraMeshType::TetraType TetraType; + /// The triangle type + typedef TriangleMeshType::FaceType FaceType; + + /// The vertex type of tetrahedreal Mesh + typedef typename TetraMeshType::VertexType TetraVertexType; + /// The vertex type of triangular Mesh + typedef typename TriangleMeshType::VertexType TriVertexType; + + /// The type of vertex iterator on tetrahedral mesh + typedef typename TetraMeshType::VertexIterator TetraVertexIterator; + /// The type of vertex iterator on tetrahedral mesh + typedef typename TriangleMeshType::VertexIterator TriVertexIterator; + + /// The type of tetra iterator + typedef typename TetraMeshType::TetraIterator TetraIterator; + /// The type of tetra iterator + typedef typename TriangleMeshType::FaceIterator FaceIterator; + + /// The type of const tetra iterator + typedef TetraMeshType::const_TetraIterator const_TetraIterator; + /// The type of const face iterator + typedef TriangleMeshType::ConstFaceIterator ConstFaceIterator; + + /// The type of const vertex pointer of tetrahedral mesh + typedef TetraMeshType::const_VertexPointer const_VertexPointer; + + +public: + +/***********************************************/ +/** @Convert to triangle-mesh functions +**/ +//@{ + +///this function build a triangle mesh using the same pointers to the tetrahedral mesh vertex +void Convert(TetraMeshType &tetram,TriangleMeshType &trim) +{ + TetraIterator ti; + + TetraVertexType *v0; + TetraVertexType *v1; + TetraVertexType *v2; + + trim.Clear(); + for (ti=tetram.tetra.begin();tiIsD())) + { + if ((ti->IsBorderF(0))||(ti->IsBorderF(1))||(ti->IsBorderF(2))||(ti->IsBorderF(3))) + for (int i=0;i<4;i++) + if (ti->IsBorderF(i)) + { + v0=ti->V(Tetra4::VofF(i,0)); + v1=ti->V(Tetra4::VofF(i,1)); + v2=ti->V(Tetra4::VofF(i,2)); + FaceType f=FaceType(); + f.ClearFlags(); + f.V(0)=v0; + f.V(1)=v1; + f.V(2)=v2; + trim.face.push_back(f); + } + } + } + +} + +template +struct InsertedV{ + InsertedV( I_MESH_TYPE::VertexType *_v, + I_MESH_TYPE::FacePointer _f, + int _z):v(_v),f(_f),z(_z){} + + I_MESH_TYPE::VertexType *v; + I_MESH_TYPE::FacePointer f; + int z; + + const bool operator <(const InsertedV & o){ + return (v > newVertices; + + TriVertexIterator vi; + vector redirect; + + Convert(tetram,trim); + + FaceIterator fi; + + for(fi = trim.face.begin(); fi != trim.face.end(); ++fi){ + 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 >::iterator curr,next; + int pos = 0; + curr = next = newVertices.begin(); + while( next != newVertices.end()){ + if((*curr)!=(*next)) + pos++; + (*next).f->V( (*next).z) = (TriVertexType*)pos; + curr = next; + next++; + } + + vector >::iterator newE = unique(newVertices.begin(),newVertices.end()); + for(curr = newVertices.begin();curr!= newE;++curr) + trim.vert.push_back(*((*curr).v)); + + for(vi = trim.vert.begin(); vi != trim.vert.end(); ++vi) + redirect.push_back(&(*vi)); + + for(fi = trim.face.begin(); fi != trim.face.end(); ++fi){ + (*fi).V(0) = redirect[(int)(*fi).V(0)]; + (*fi).V(1) = redirect[(int)(*fi).V(1)]; + (*fi).V(2) = redirect[(int)(*fi).V(2)]; + } + trim.vn = trim.vert.size(); + trim.fn = trim.face.size(); +} + + };// End class +/*@}*/ +} // End namespace +} // End namespace + + +#endif