subdivision.h 7.15 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
26
#ifndef __SUBDIVISION_H__
#define __SUBDIVISION_H__
Pierre Kraemer's avatar
Pierre Kraemer committed
27

28
29
#include <cmath>

Pierre Kraemer's avatar
Pierre Kraemer committed
30
#include <vector>
Sylvain Thery's avatar
Sylvain Thery committed
31
#include "Algo/Geometry/centroid.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32
33
34
35
36
37
38

namespace CGoGN
{

namespace Algo
{

39
40
41
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace Modelisation
{

/**
* Triangule a face with central vertex
* @param d dart of face
* @return a dart of the central vertex
*/
template <typename PFP>
Dart trianguleFace(typename PFP::MAP& map, Dart d);

/**
 * Triangule all the faces of the mesh
 */
template <typename PFP, typename EMBV, typename EMB>
57
void trianguleFaces(typename PFP::MAP& map, EMBV& attributs) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
58

59
60
//template <typename PFP>
//void trianguleFaces(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position) ;
61

Pierre Kraemer's avatar
Pierre Kraemer committed
62
63
64
65
66
67
68
/**
 * Triangule all the faces of the mesh
 * positions for new vertices are given as face attribute
 */
template <typename PFP>
void trianguleFaces(
	typename PFP::MAP& map,
69
70
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
	const FaceAttribute<typename PFP::VEC3, typename PFP::MAP>& positionF) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
71

Pierre Kraemer's avatar
Pierre Kraemer committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Quadrangule a face with central vertex
* warning: edges are considered here as already cut !!
* A face with 2n edges give n quads
* @param d dart of face with belong to a vertex introduce when cutting the edge
* @return a dart of central point
*/
template <typename PFP>
Dart quadranguleFace(typename PFP::MAP& map, Dart d);

/**
 * Quadrangule all the faces of the mesh
 */
template <typename PFP, typename EMBV, typename EMB>
86
void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
87

Pierre Kraemer's avatar
Pierre Kraemer committed
88
//template <typename PFP>
89
//void quadranguleFaces(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position) ;
90

Pierre Kraemer's avatar
Pierre Kraemer committed
91
92
93
/**
 * Catmull-Clark subdivision scheme
 */
94
template <typename PFP, typename EMBV>
95
void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
96

Sylvain Thery's avatar
Sylvain Thery committed
97
98
99
100
101
102
/**
* Interpolant Catmull-Clark subdivision scheme
*/
template <typename PFP, typename EMBV>
void CatmullClarkInterpolSubdivision(typename PFP::MAP& map, EMBV& attributs);

Pierre Kraemer's avatar
Pierre Kraemer committed
103
104
105
/**
 * Loop subdivision scheme
 */
106
template <typename PFP, typename EMBV>
107
void LoopSubdivision(typename PFP::MAP& map, EMBV& attributs) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
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
161
162
163
164
165
166
167
template <typename PFP>
void LoopSubdivisionGen(typename PFP::MAP& map, VertexAttributeGen& attrib)
{
	auto va3 = dynamic_cast<VertexAttribute<typename PFP::VEC3, typename PFP::MAP>*>(&attrib);
	if (va3 != NULL)
		return LoopSubdivision<PFP>(map,*va3);

	auto va4 = dynamic_cast<VertexAttribute<typename PFP::VEC4, typename PFP::MAP>*>(&attrib);
	if (va4 != NULL)
		return LoopSubdivision<PFP>(map,*va4);

	auto var = dynamic_cast<VertexAttribute<typename PFP::REAL, typename PFP::MAP>*>(&attrib);
	if (var != NULL)
		return LoopSubdivision<PFP>(map,*var);

	CGoGNerr << "LoopSubdivision not supported on attribute of type "<< attrib.typeName() << CGoGNendl;
}

/**
 * Loop typed version with attribute name parameter
 */
template <typename PFP, typename T>
inline void LoopSubdivisionAttribNameTyped(typename PFP::MAP& map, const std::string& nameAttrib)
{
	VertexAttribute<T,typename PFP::MAP> va = map.template getAttribute<T,VERTEX,typename PFP::MAP>(nameAttrib) ;
}

/**
 * Loop genereo version with attribute name parameter
 */
template <typename PFP>
void LoopSubdivisionAttribName(typename PFP::MAP& map, const std::string& nameAttrib)
{
	typedef typename PFP::MAP MAP;

	switch(map.template getAttributeTypeCode<VERTEX>(nameAttrib))
	{
	case CGoGNFLOAT:
		return LoopSubdivisionAttribNameTyped<PFP,float>(map,nameAttrib);
		break;
	case CGoGNDOUBLE:
		return LoopSubdivisionAttribNameTyped<PFP,double>(map,nameAttrib);
		break;
	case CGoGNVEC3F:
		return LoopSubdivisionAttribNameTyped<PFP,Geom::Vec3f>(map,nameAttrib);
		break;
	case CGoGNVEC3D:
		return LoopSubdivisionAttribNameTyped<PFP,Geom::Vec3d>(map,nameAttrib);
		break;
	case CGoGNVEC4F:
		return LoopSubdivisionAttribNameTyped<PFP,Geom::Vec4f>(map,nameAttrib);
		break;
	case CGoGNVEC4D:
		return LoopSubdivisionAttribNameTyped<PFP,Geom::Vec4d>(map,nameAttrib);
		break;
	}
	CGoGNerr << "LoopSubdivision not supported on attribute "<< nameAttrib << CGoGNendl;
}

168

169

170
171
172
173
/**
 * Cut 1 face of degree n in 2n+1 faces (cut 2 times each edge and "insert" a face in the middle)
 * @param size indicates where to cut edges, its value must stay between 0 and 0.5 excluded
 */
174
template <typename PFP, typename EMBV, typename EMB>
175
void TwoNPlusOneSubdivision(typename PFP::MAP& map, EMBV& attributs, float size=1.0f/3.0f) ;
176

Sylvain Thery's avatar
Sylvain Thery committed
177
178
179
/**
 * Doo-Sabin subdivision scheme
 */
180
181
template <typename PFP, typename EMBV>
void DooSabin(typename PFP::MAP& map, EMBV& position);
Sylvain Thery's avatar
Sylvain Thery committed
182

183
184
185
///**
// * Reverse the orientation of the map
// * NOW  IN THE MAP
Pierre Kraemer's avatar
Pierre Kraemer committed
186
187
// */
//template <typename PFP>
188
//void Sqrt3Subdivision(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
189
190


191
192
193
194
///**
// * Sqrt(3) subdivision scheme
// */
//template <typename PFP>
195
//void Sqrt3Subdivision(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
196
197

template <typename PFP>
198
void computeDual(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position);
199
200

template <typename PFP>
201
void computeBoundaryConstraintDual(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position);
202
203

template <typename PFP>
204
void computeBoundaryConstraintKeepingOldVerticesDual(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position);
205

Pierre Kraemer's avatar
Pierre Kraemer committed
206
207
} // namespace Modelisation

208
} // namespace Surface
209

Pierre Kraemer's avatar
Pierre Kraemer committed
210
211
212
213
214
215
216
} // namespace Algo

} // namespace CGoGN

#include "Algo/Modelisation/subdivision.hpp"

#endif