polyhedron.h 8.89 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef POLYHEDRON_H
#define POLYHEDRON_H

#include <vector>
#include "Algo/Modelisation/subdivision.h"
#include "Geometry/transfo.h"
Sylvain Thery's avatar
Sylvain Thery committed
31 32
#include "Topology/generic/cellmarker.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
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 161
#include "Utils/os_spec.h"


namespace CGoGN
{

namespace Algo
{

namespace Modelisation
{

enum {NONE,GRID, CUBE, CYLINDER, CONE, SPHERE, TORE, COMPOSED};


/**
* sudivide the all quads of primtive into 2 triangles
* the vertex darts table remain valid (adding only darts, no remove)
*/
// template <typename PFP>
// void onlyTriangles(typename PFP::MAP& the_map, Dart primd);

/**
* Create a triangle fans (to close cylinders)
* simple topo creation  no modification of Polyhedron
* @param n nb of triangles in the fan in n
* @return the dart
*/
// template <typename PFP>
// Dart triangleFan_topo(typename PFP::MAP& the_map, int n);

/**
* class of geometric Polyhedron
* It alloaw the creation of:
* - grid 2D
* - subdivided cube
* - subdivided cone
* - subdivided cylinder
* - subdivided tore
* - subdivided sphere (with pole)
*
* Topological creation methods are separated from embedding to
* easily allow specific embedding.

*/
template <typename PFP>
class Polyhedron
{
	typedef typename PFP::MAP MAP;

public:
	enum {NONE,GRID, CUBE, CYLINDER, CONE, SPHERE, TORE, COMPOSED};

protected:
	/**
	* Map in which we are working
	*/
	MAP& m_map;

	/**
	* Reference dart of Polyhedron
	*/
	Dart m_dart;

	/**
	* Kind of Polyhedron (grid, cylinder,
	*/
	int m_kind;

	/**
	* Table of vertex darts (one dart per vertex)
	* Order depend on Polyhedron kind
	*/
	std::vector<Dart> m_tableVertDarts;

	/**
	* numbers that defined the subdivision of  Polyhedron
	*/
	int m_nx;

	int m_ny;

	int m_nz;

	bool m_top_closed;

	bool m_bottom_closed;

	typename PFP::TVEC3& m_positions;

	typename PFP::VEC3 m_center;

	/**
	* return the dart of next vertex when traversing the boundary of a quad or trifan grid
	*/
	Dart nextDV(Dart d) { return m_map.phi1(m_map.phi2(m_map.phi1(d))); }

	/**
	* return the dart of preceding vertex when traversing the boundary of a quad or trifan grid
	*/
	Dart precDV(Dart d) { return m_map.phi_1(m_map.phi2(m_map.phi_1(d))); }

	void computeCenter();


public:
	/**
	* Constructor
	* @param map the map in which we want to work
	* @param idPositions id of attribute position
	*/
	Polyhedron(MAP& map, typename PFP::TVEC3& position):
	 m_map(map),
	 m_kind(NONE),
	 m_nx(-1), m_ny(-1), m_nz(-1),
	 m_top_closed(false), m_bottom_closed(false),
	 m_positions(position)
	 {
		computeCenter();
	 }

	/**
	* Polyhedron fusion: give a COMPOSED type
	* @param p1 first Polyhedron
	* @param p1 second Polyhedron
	*/
	Polyhedron(const Polyhedron<PFP>& p1, const Polyhedron<PFP>& p2);

	/**
162
	 * create simple simple polyhedron (not handled by Polyhedron object)
Pierre Kraemer's avatar
Pierre Kraemer committed
163 164 165
	 */
	static Dart createOrientedPolyhedron(typename PFP::MAP& the_map, int nbFaces);

166 167 168
	/**
	 * create simple simple tetrahedron (not handled by Polyhedron object)
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
169 170
	static Dart createOrientedTetra(typename PFP::MAP& the_map);

171 172 173
	/**
	 * create simple simple pyramid (not handled by Polyhedron object)
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
174 175
	static Dart createOrientedPyra(typename PFP::MAP& the_map);

176 177 178
	/**
	 * create simple simple hexaedron (not handled by Polyhedron object)
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
179 180
	static Dart createOrientedHexa(typename PFP::MAP& the_map);

181 182 183
	/**
	 * create simple simple prism (not handled by Polyhedron object)
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
	static Dart createOrientedPrism(typename PFP::MAP& the_map);

	/*
	* get the reference dart
	*/
	Dart getDart() { return m_dart;}

	/*
	* get the center of Polyhedron
	*/
	const typename PFP::VEC3&  getCenter() { return m_center;}

	/**
	* get the table of darts (one per vertex)
	*/
	std::vector<Dart>& getVertexDarts() { return m_tableVertDarts;}

	/**
	* Create a 2D grid
	* quads are oriented counter-clockwise and the returned dart
	* is the lower left dart (upper right it is symetric)
	* @param x nb of quads in x
	* @param y nb of quads in y
	* @return the dart
	*/
	Dart grid_topo(int x, int y);

	/**
	* Create a subdivided (surface) cylinder
	* @param n nb of quads around circunference
	* @param z nb of quads in height
	* @param top_closed close the top with triangles fan
	* @param bottom_closed close the bottom with triangles fan
	* @return the dart
	*/
	Dart cylinder_topo(int n, int z, bool top_closed, bool bottom_closed);

	/**
	* Create a subdivided (surface) cone (with param 1,3,true create tetrahedron)
	* @param n nb of quads around circunference (must be >=3)
	* @param z nb of quads in height (must be >=1)
	* @param bottom_closed close the bottom with triangles fan
	* @return the dart
	*/
	Dart cone_topo(int n, int z, bool bottom_closed);

	/**
	* Create a subdived (surface) cube
	* quads are oriented counter-clockwise
	* @param x nb of quads in x
	* @param y nb of quads in y
	* @param z nb of quads in z
	* @return the dart
	*/
	Dart cube_topo(int x, int y, int z);

	/**
	* Create a subdivided (surface) cylinder
	* @param m nb of quads around big circunference
243
	* @param n nb of quads around small circunference
Pierre Kraemer's avatar
Pierre Kraemer committed
244 245 246 247
	* @param top_closed close the top with triangles fan
	* @param bottom_closed close the bottom with triangles fan
	* @return the dart
	*/
248
	Dart tore_topo(int m, int n);
Pierre Kraemer's avatar
Pierre Kraemer committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310

	/**
	* embed the topo grid Polyhedron
	* Grid has size x,y centered on 0
	* @param x
	* @param y
	*/
	void embedGrid(float x, float y, float z=0.0f);

	/**
	* embed the topo cylinder Polyhedron
	* @param bottom_radius
	* @parma top_radius
	* @param height
	*/
	void embedCylinder(float bottom_radius, float top_radius, float height);

	/**
	* embed the topo cylinder Polyhedron
	* @param radius
	* @param height
	*/
	void embedCone(float radius, float height);

	/**
	* embed the topo sphere Polyhedron
	* @param radius
	* @param height
	*/
	void embedSphere(float radius);

	/**
	* embed the topo tore Polyhedron
	* @param big_radius
	* @param small_radius
	*/
	void embedTore(float big_radius, float small_radius);

	/**
	* embed the topo cube Polyhedron
	* @param sx size of cube in X
	* @param sy size of cube in Y
	* @param sz size of cube in Z
	*/
	void embedCube(float sx, float sy, float sz);

	/**
	* embed the a grid into a twister open ribbon
	* with turns=PI it is a Moebius strip, needs only to be closed (if model allow it)
	* @param radius_min
	* @param radius_max
	* @param turns number of turn multiplied by 2*PI
	*/
	void embedTwistedStrip(float radius_min, float radius_max, float turns);

	/**
	* embed a grid into a helicoid
	* @param radius_min
	* @param radius_max
	* @param maxHeight height to reach
	* @param turns number of turn
	*/
Thomas's avatar
Thomas committed
311
	void embedHelicoid( float radius_min,  float radius_max, float maxHeight, float nbTurn, int orient=1);
Pierre Kraemer's avatar
Pierre Kraemer committed
312 313 314 315 316 317 318 319 320

	/**
	* transform the Polyhedron with transformation matrice
	* @param matrice
	*/
	void transform(const Geom::Matrix44f& matrice);

	/**
	* mark all darts of the Polyhedron
Sylvain Thery's avatar
Sylvain Thery committed
321
	* @param m the CellMarker(VERTEX) to use
Pierre Kraemer's avatar
Pierre Kraemer committed
322
	*/
Sylvain Thery's avatar
Sylvain Thery committed
323
	void mark(CellMarker m);
Pierre Kraemer's avatar
Pierre Kraemer committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

	/**
	* mark all embedded vertices of the Polyhedron
	* @param m the marker to use
	*/
	void markEmbVertices(Marker m);

	/**
	* test if a vertex is in the Polyhedron
	* @param d a dart of the vertex to test
	*/
	bool containVertex(Dart d);
};

} // namespace Modelisation

} // namespace Algo

} // namespace CGoGN

#include "Algo/Modelisation/polyhedron.hpp"

#endif