polyhedron.h 10.2 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
25
26
27
28
29
30
* 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
#include "Utils/os_spec.h"


namespace CGoGN
{

namespace Algo
{

namespace Modelisation
{

45
enum { NONE, GRID, CUBE, CYLINDER, CONE, SPHERE, TORE, COMPOSED };
Pierre Kraemer's avatar
Pierre Kraemer committed
46

Sylvain Thery's avatar
Sylvain Thery committed
47
48
49
50
51
52
//template <typename PFP>
//void sewFaceEmb(typename PFP::MAP& map, Dart d, Dart e);
//
//template <typename PFP>
//Dart newFaceEmb(typename PFP::MAP& map, unsigned int n);

Pierre Kraemer's avatar
Pierre Kraemer committed
53
/**
Sylvain Thery's avatar
Sylvain Thery committed
54
* sudivide the all quads of a CC into 2 triangles
Pierre Kraemer's avatar
Pierre Kraemer committed
55
*/
Sylvain Thery's avatar
Sylvain Thery committed
56
57
 template <typename PFP>
 void quads2TrianglesCC(typename PFP::MAP& the_map, Dart primd);
Pierre Kraemer's avatar
Pierre Kraemer committed
58
59
60
61
62
63
64
65
66
67

/**
* 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);

untereiner's avatar
untereiner committed
68
69

/**
70
 * Unsex the Umbrella around a vertex, close the hole and then
untereiner's avatar
untereiner committed
71
72
73
74
 * create a symetric to construct a polyedron
 * @param d a dart from the vertex
 */
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
75
void explodPolyhedron(typename PFP::MAP& map, Dart d, VertexAttribute<typename PFP::VEC3>& position);
76
77
78
79
80
81
82
83




/**
 * create a n-sided pyramid
 */
template <typename PFP>
84
Dart createPyramid(typename PFP::MAP& map, unsigned int nbSides, bool withBoundary = true);
85
86
87
88
89

/**
 * create a n-sided prism
 */
template <typename PFP>
90
Dart createPrism(typename PFP::MAP& map, unsigned int nbSides, bool withBoundary = true);
91
92
93
94
95

/**
 * create a n-sided diamond
 */
template <typename PFP>
96
Dart createDiamond(typename PFP::MAP& map, unsigned int nbSides, bool withBoundary = true);
97
98
99
100
101

/**
 * create a tetrahedron
 */
template <typename PFP>
102
Dart createTetrahedron(typename PFP::MAP& map, bool withBoundary = true);
103
104
105
106
107

/**
 * create a hexahedron
 */
template <typename PFP>
108
Dart createHexahedron(typename PFP::MAP& map, bool withBoundary = true);
109
110
111
112
113

/**
 * create a 3-sided prism
 */
template <typename PFP>
114
Dart createTriangularPrism(typename PFP::MAP& map, bool withBoundary = true);
115
116

/**
117
 * create a 4-sided pyramid
118
119
 */
template <typename PFP>
120
Dart createQuadrangularPyramid(typename PFP::MAP& map, bool withBoundary = true);
121
122
123
124
125

/**
 * create 4-sided diamond (i.e. an octahedron)
 */
template <typename PFP>
126
Dart createOctahedron(typename PFP::MAP& map, bool withBoundary = true);
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
//TODO optimize
template <typename PFP>
bool isPyra(typename PFP::MAP& map, Dart d, unsigned int thread = 0);

//TODO optimize
template <typename PFP>
bool isPrism(typename PFP::MAP& map, Dart d, unsigned int thread = 0);







142
143


Pierre Kraemer's avatar
Pierre Kraemer committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* 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;
161
	typedef typename PFP::VEC3 VEC3;
Pierre Kraemer's avatar
Pierre Kraemer committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

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
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
191
	unsigned int m_nx;
Pierre Kraemer's avatar
Pierre Kraemer committed
192

Pierre Kraemer's avatar
Pierre Kraemer committed
193
	unsigned int m_ny;
Pierre Kraemer's avatar
Pierre Kraemer committed
194

Pierre Kraemer's avatar
Pierre Kraemer committed
195
	unsigned int m_nz;
Pierre Kraemer's avatar
Pierre Kraemer committed
196
197
198
199
200

	bool m_top_closed;

	bool m_bottom_closed;

201
	VertexAttribute<VEC3>& m_positions;
Pierre Kraemer's avatar
Pierre Kraemer committed
202

203
	VEC3 m_center;
Pierre Kraemer's avatar
Pierre Kraemer committed
204
205
206
207
208
209
210
211
212
213
214
215
216

	/**
	* 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();

217
218
	Dart grid_topo_open(unsigned int x, unsigned int y);
	Dart cylinder_topo_open(unsigned int n, unsigned int z);
Pierre Kraemer's avatar
Pierre Kraemer committed
219
220
221
222
223
224
public:
	/**
	* Constructor
	* @param map the map in which we want to work
	* @param idPositions id of attribute position
	*/
225
	Polyhedron(MAP& map, VertexAttribute<VEC3>& position):
Pierre Kraemer's avatar
Pierre Kraemer committed
226
227
228
229
230
231
		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)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
232
		computeCenter();
Pierre Kraemer's avatar
Pierre Kraemer committed
233
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
234
235
236
237
238
239
240
241
242
243
244

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

	/*
	* get the reference dart
	*/
245
	Dart getDart() { return m_dart; }
Pierre Kraemer's avatar
Pierre Kraemer committed
246
247
248
249

	/*
	* get the center of Polyhedron
	*/
250
	const typename PFP::VEC3&  getCenter() { return m_center; }
Pierre Kraemer's avatar
Pierre Kraemer committed
251
252
253
254

	/**
	* get the table of darts (one per vertex)
	*/
255
	std::vector<Dart>& getVertexDarts() { return m_tableVertDarts; }
Pierre Kraemer's avatar
Pierre Kraemer committed
256

257
258


Pierre Kraemer's avatar
Pierre Kraemer committed
259
260
261
262
263
264
265
266
	/**
	* 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
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
267
	Dart grid_topo(unsigned int x, unsigned int y);
Pierre Kraemer's avatar
Pierre Kraemer committed
268
269
270
271
272
273
274
275
276

	/**
	* 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
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
277
	Dart cylinder_topo(unsigned int n, unsigned int z, bool top_closed, bool bottom_closed);
Pierre Kraemer's avatar
Pierre Kraemer committed
278
279
280
281
282
283
284
285

	/**
	* 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
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
286
	Dart cone_topo(unsigned int n, unsigned int z, bool bottom_closed);
Pierre Kraemer's avatar
Pierre Kraemer committed
287
288
289
290
291
292
293
294
295

	/**
	* 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
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
296
	Dart cube_topo(unsigned int x, unsigned int y, unsigned int z);
Pierre Kraemer's avatar
Pierre Kraemer committed
297
298
299
300

	/**
	* Create a subdivided (surface) cylinder
	* @param m nb of quads around big circunference
301
	* @param n nb of quads around small circunference
Pierre Kraemer's avatar
Pierre Kraemer committed
302
303
304
305
	* @param top_closed close the top with triangles fan
	* @param bottom_closed close the bottom with triangles fan
	* @return the dart
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
306
	Dart tore_topo(unsigned int m, unsigned int n);
Pierre Kraemer's avatar
Pierre Kraemer committed
307
308
309
310
311
312
313

	/**
	* embed the topo grid Polyhedron
	* Grid has size x,y centered on 0
	* @param x
	* @param y
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
314
	void embedGrid(float x, float y, float z = 0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

	/**
	* 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
	*/
369
	void embedHelicoid(float radius_min,  float radius_max, float maxHeight, float nbTurn, int orient = 1);
Pierre Kraemer's avatar
Pierre Kraemer committed
370
371
372
373
374
375
376
377
378

	/**
	* 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
379
	* @param m the CellMarker(VERTEX) to use
Pierre Kraemer's avatar
Pierre Kraemer committed
380
	*/
381
	void mark(CellMarker<VERTEX>& m);
Pierre Kraemer's avatar
Pierre Kraemer committed
382
383
384
385
386

	/**
	* mark all embedded vertices of the Polyhedron
	* @param m the marker to use
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
387
//	void markEmbVertices(Mark m);
Pierre Kraemer's avatar
Pierre Kraemer committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

	/**
	* 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