00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __VCG_TETRA_TRI_CONVERTER
00033 #define __VCG_TETRA_TRI_CONVERTER
00034 #include <map>
00035 #include <vector>
00036 #include <vcg/space/tetra3.h>
00037 #include <vcg/complex/tetramesh/allocate.h>
00038 namespace vcg {
00039
00043 class Boundary{
00044 public:
00045
00047 template <class TetraContainer, class TriangleMeshType>
00048 static void OfTetramesh(TetraContainer &tetra,TriangleMeshType &trim)
00049 {
00050 typedef typename TetraContainer::iterator TetraIterator;
00051 typedef typename TetraContainer::value_type TetraVertexType;
00052 typedef typename TriangleMeshType::FaceType FaceType;
00053 typedef typename TriangleMeshType::VertexType TriangleVertexType;
00054
00055 TetraIterator ti;
00056 TetraVertexType *v0;
00057 TetraVertexType *v2;
00058
00059 trim.Clear();
00060 for (ti=tetra.begin();ti<tetra.end();ti++)
00061 {
00062 if (!(ti->IsD()))
00063 {
00064 if ((ti->IsBorderF(0))||(ti->IsBorderF(1))||(ti->IsBorderF(2))||(ti->IsBorderF(3)))
00065 for (int i=0;i<4;i++)
00066 if (ti->IsBorderF(i))
00067 {
00068 FaceType f=FaceType();
00069 f.ClearFlags();
00070 f.V(0)=(TriangleVertexType*)ti->V(Tetra::VofF(i,0));
00071 f.V(1)=(TriangleVertexType*)ti->V(Tetra::VofF(i,1));
00072 f.V(2)=(TriangleVertexType*)ti->V(Tetra::VofF(i,2));
00073 trim.face.push_back(f);
00074 }
00075 }
00076 }
00077 }
00078
00079 template <class TriVertexType >
00080 struct InsertedV{
00081
00082 typedef typename TriVertexType::FaceType FaceType;
00083 InsertedV( TriVertexType *_v, FaceType* _f,int _z):v(_v),f(_f),z(_z){}
00084
00085 TriVertexType *v;
00086 FaceType* f;
00087 int z;
00088
00089 const bool operator <(const InsertedV & o){
00090 return (v<o.v);
00091 }
00092 const bool operator ==(const InsertedV & o){
00093 return (v==o.v);
00094 }
00095 const bool operator !=(const InsertedV & o){
00096 return (v!=o.v);
00097 }
00098 };
00099
00100
00102 template <class TetraContainer, class TriangleMeshType>
00103 static void OfTetrameshCopy(TetraContainer &tetra,TriangleMeshType &trim)
00104 {
00105 typedef typename TetraContainer::iterator TetraIterator;
00106 typedef typename TetraContainer::value_type::VertexType TetraVertexType;
00107 typedef typename TriangleMeshType::FaceType FaceType;
00108 typedef typename TriangleMeshType::FaceIterator FaceIterator;
00109 typedef typename TriangleMeshType::VertexIterator TriVertexIterator;
00110 typedef typename TriangleMeshType::VertexType TriVertexType;
00111
00112 vector<InsertedV<TriVertexType> > newVertices;
00113 typename vector<InsertedV<TriVertexType> >::iterator curr,next;
00114 TriVertexIterator vi;
00115 vector<TriVertexType*> redirect;
00116
00117 OfTetramesh(tetra,trim);
00118
00119 FaceIterator fi;
00120
00121 for(fi = trim.face.begin(); fi != trim.face.end(); ++fi){
00122 newVertices.push_back(InsertedV<TriVertexType>( (*fi).V(0),&(*fi),0));
00123 newVertices.push_back(InsertedV<TriVertexType>( (*fi).V(1),&(*fi),1));
00124 newVertices.push_back(InsertedV<TriVertexType>( (*fi).V(2),&(*fi),2));
00125 }
00126
00127 sort(newVertices.begin(),newVertices.end());
00128
00129
00130 int pos = 0;
00131 curr = next = newVertices.begin();
00132 while( next != newVertices.end()){
00133 if((*curr)!=(*next))
00134 pos++;
00135 (*next).f->V( (*next).z) = (TriVertexType*)pos;
00136 curr = next;
00137 next++;
00138 }
00139
00140 typename vector<InsertedV<TriVertexType> >::iterator newE = unique(newVertices.begin(),newVertices.end());
00141 for(curr = newVertices.begin();curr!= newE;++curr)
00142 trim.vert.push_back(*((*curr).v));
00143
00144 for(vi = trim.vert.begin(); vi != trim.vert.end(); ++vi)
00145 redirect.push_back(&(*vi));
00146
00147 for(fi = trim.face.begin(); fi != trim.face.end(); ++fi){
00148 (*fi).V(0) = redirect[(int)(*fi).V(0)];
00149 (*fi).V(1) = redirect[(int)(*fi).V(1)];
00150 (*fi).V(2) = redirect[(int)(*fi).V(2)];
00151 }
00152 trim.vn = trim.vert.size();
00153 trim.fn = trim.face.size();
00154 }
00155
00156 };
00157 }
00158
00159
00160 #endif