File: boundary.h

package info (click to toggle)
meshlab 1.3.2%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,060 kB
  • ctags: 33,549
  • sloc: cpp: 224,813; ansic: 8,170; xml: 119; makefile: 80
file content (160 lines) | stat: -rw-r--r-- 5,642 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/****************************************************************************
* 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  2007/07/31 12:31:34  ganovelli
added


****************************************************************************/
#ifndef __VCG_TETRA_TRI_CONVERTER
#define __VCG_TETRA_TRI_CONVERTER
#include <map>
#include <vector>
#include <vcg/space/tetra3.h>
#include <vcg/complex/tetramesh/allocate.h>
namespace vcg {

/** Class Boundary.
This is class for exporting the boundary of a d simplicial complex as a d-1 simplicial complex
*/
class Boundary{
public:

///this function build a triangle mesh using the same pointers to the tetrahedral mesh vertex
template <class TetraContainer, class TriangleMeshType>
static void OfTetramesh(TetraContainer &tetra,TriangleMeshType &trim)
{
typedef typename TetraContainer::iterator TetraIterator;
typedef typename TetraContainer::value_type TetraVertexType;
typedef typename TriangleMeshType::FaceType FaceType;
typedef typename TriangleMeshType::VertexType TriangleVertexType;

TetraIterator ti;
TetraVertexType *v0;
TetraVertexType *v2;

trim.Clear();
for (ti=tetra.begin();ti<tetra.end();ti++)
{
if (!(ti->IsD()))
	{
		if ((ti->IsBorderF(0))||(ti->IsBorderF(1))||(ti->IsBorderF(2))||(ti->IsBorderF(3)))
			for (int i=0;i<4;i++)
				if (ti->IsBorderF(i))
					{
						FaceType f=FaceType();
						f.ClearFlags();
						f.V(0)=(TriangleVertexType*)ti->V(Tetra::VofF(i,0));
						f.V(1)=(TriangleVertexType*)ti->V(Tetra::VofF(i,1));
						f.V(2)=(TriangleVertexType*)ti->V(Tetra::VofF(i,2));
						trim.face.push_back(f);
					}
		}
	}
}

template <class TriVertexType >
struct InsertedV{

typedef typename TriVertexType::FaceType FaceType;
InsertedV( TriVertexType *_v, FaceType* _f,int _z):v(_v),f(_f),z(_z){}

TriVertexType *v;
FaceType* f;
int z;

const bool operator <(const InsertedV & o){
return (v<o.v);
}
const bool operator ==(const InsertedV & o){
return (v==o.v);
}
const bool operator !=(const InsertedV & o){
return (v!=o.v);
}
};


/// this function build a triangle mesh using new pointers to the tetrahedral mesh vertex
template <class TetraContainer, class TriangleMeshType>
static void OfTetrameshCopy(TetraContainer &tetra,TriangleMeshType &trim)
{
	typedef typename TetraContainer::iterator TetraIterator;
	typedef typename TetraContainer::value_type::VertexType TetraVertexType;
	typedef typename TriangleMeshType::FaceType FaceType;
	typedef typename TriangleMeshType::FaceIterator FaceIterator;
	typedef typename TriangleMeshType::VertexIterator TriVertexIterator;
	typedef typename TriangleMeshType::VertexType TriVertexType;

	vector<InsertedV<TriVertexType> > newVertices;
	typename vector<InsertedV<TriVertexType> >::iterator curr,next;
	TriVertexIterator vi;
	vector<TriVertexType*> redirect;

	OfTetramesh(tetra,trim);

	FaceIterator fi;

	for(fi = trim.face.begin(); fi != trim.face.end(); ++fi){
		newVertices.push_back(InsertedV<TriVertexType>( (*fi).V(0),&(*fi),0));
		newVertices.push_back(InsertedV<TriVertexType>( (*fi).V(1),&(*fi),1));
		newVertices.push_back(InsertedV<TriVertexType>( (*fi).V(2),&(*fi),2));
	}

sort(newVertices.begin(),newVertices.end());


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++;
}

typename vector<InsertedV<TriVertexType> >::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


#endif