subdivision.h 6.98 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 <math.h>
#include <vector>
Sylvain Thery's avatar
Sylvain Thery committed
30
#include "Algo/Geometry/centroid.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
31 32 33 34 35 36 37

namespace CGoGN
{

namespace Algo
{

38 39 40
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
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>
56
void trianguleFaces(typename PFP::MAP& map, EMBV& attributs) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
57

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

Pierre Kraemer's avatar
Pierre Kraemer committed
61 62 63 64 65 66 67
/**
 * 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,
68 69
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
	const FaceAttribute<typename PFP::VEC3, typename PFP::MAP>& positionF) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
70

Pierre Kraemer's avatar
Pierre Kraemer committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84
/**
* 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>
85
void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
86

87
//template <typename PFP>
88
//void quadranguleFaces(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position) ;
89

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

/**
 * Loop subdivision scheme
 */
99
template <typename PFP, typename EMBV>
100
void LoopSubdivision(typename PFP::MAP& map, EMBV& attributs) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
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
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;
}

161

162

163 164 165 166
/**
 * 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
 */
167
template <typename PFP, typename EMBV, typename EMB>
168
void TwoNPlusOneSubdivision(typename PFP::MAP& map, EMBV& attributs, float size=1.0f/3.0f) ;
169

Sylvain Thery's avatar
Sylvain Thery committed
170 171 172
/**
 * Doo-Sabin subdivision scheme
 */
173 174
template <typename PFP, typename EMBV>
void DooSabin(typename PFP::MAP& map, EMBV& position);
Sylvain Thery's avatar
Sylvain Thery committed
175

176 177 178
///**
// * Reverse the orientation of the map
// * NOW  IN THE MAP
Pierre Kraemer's avatar
Pierre Kraemer committed
179 180
// */
//template <typename PFP>
181
//void Sqrt3Subdivision(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
182 183


184 185 186 187
///**
// * Sqrt(3) subdivision scheme
// */
//template <typename PFP>
188
//void Sqrt3Subdivision(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
189 190

template <typename PFP>
191
void computeDual(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position);
192 193

template <typename PFP>
194
void computeBoundaryConstraintDual(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position);
195 196

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

Pierre Kraemer's avatar
Pierre Kraemer committed
199 200
} // namespace Modelisation

201
} // namespace Surface
202

Pierre Kraemer's avatar
Pierre Kraemer committed
203 204 205 206 207 208 209
} // namespace Algo

} // namespace CGoGN

#include "Algo/Modelisation/subdivision.hpp"

#endif