Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

polyhedron.h 10.6 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
#include "Utils/os_spec.h"


namespace CGoGN
{

namespace Algo
{

42
43
44
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
45
46
47
namespace Modelisation
{

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

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

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

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




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

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

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

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

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

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

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

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

131
132
133
134
135
136
137
138
139
//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);


untereiner's avatar
untereiner committed
140
141
142
template <typename PFP>
Dart embedPrism(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, unsigned int n, bool withBoundary, float bottom_radius, float top_radius, float height);

143

untereiner's avatar
untereiner committed
144
145
template <typename PFP>
Dart embedPyramid(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, unsigned int n, bool withBoundary, float radius, float height);
146
147
148
149




150
151


Pierre Kraemer's avatar
Pierre Kraemer committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* 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;
169
	typedef typename PFP::VEC3 VEC3;
Pierre Kraemer's avatar
Pierre Kraemer committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

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
199
	unsigned int m_nx;
Pierre Kraemer's avatar
Pierre Kraemer committed
200

Pierre Kraemer's avatar
Pierre Kraemer committed
201
	unsigned int m_ny;
Pierre Kraemer's avatar
Pierre Kraemer committed
202

Pierre Kraemer's avatar
Pierre Kraemer committed
203
	unsigned int m_nz;
Pierre Kraemer's avatar
Pierre Kraemer committed
204
205
206
207
208

	bool m_top_closed;

	bool m_bottom_closed;

209
	VertexAttribute<VEC3>& m_positions;
Pierre Kraemer's avatar
Pierre Kraemer committed
210

211
	VEC3 m_center;
Pierre Kraemer's avatar
Pierre Kraemer committed
212
213
214
215
216
217
218
219
220
221
222
223
224

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

225
226
	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
227
228
229
230
231
232
public:
	/**
	* Constructor
	* @param map the map in which we want to work
	* @param idPositions id of attribute position
	*/
233
	Polyhedron(MAP& map, VertexAttribute<VEC3>& position):
Pierre Kraemer's avatar
Pierre Kraemer committed
234
235
236
237
238
239
		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
240
		computeCenter();
Pierre Kraemer's avatar
Pierre Kraemer committed
241
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
242
243
244
245
246
247
248
249
250
251
252

	/**
	* 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
	*/
253
	Dart getDart() { return m_dart; }
Pierre Kraemer's avatar
Pierre Kraemer committed
254
255
256
257

	/*
	* get the center of Polyhedron
	*/
258
	const typename PFP::VEC3&  getCenter() { return m_center; }
Pierre Kraemer's avatar
Pierre Kraemer committed
259
260
261
262

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

265
266


Pierre Kraemer's avatar
Pierre Kraemer committed
267
268
269
270
271
272
273
274
	/**
	* 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
275
	Dart grid_topo(unsigned int x, unsigned int y);
Pierre Kraemer's avatar
Pierre Kraemer committed
276
277
278
279
280
281
282
283
284

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

	/**
	* 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
294
	Dart cone_topo(unsigned int n, unsigned int z, bool bottom_closed);
Pierre Kraemer's avatar
Pierre Kraemer committed
295
296
297
298
299
300
301
302
303

	/**
	* 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
304
	Dart cube_topo(unsigned int x, unsigned int y, unsigned int z);
Pierre Kraemer's avatar
Pierre Kraemer committed
305
306
307
308

	/**
	* Create a subdivided (surface) cylinder
	* @param m nb of quads around big circunference
309
	* @param n nb of quads around small circunference
Pierre Kraemer's avatar
Pierre Kraemer committed
310
311
312
313
	* @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
314
	Dart tore_topo(unsigned int m, unsigned int n);
Pierre Kraemer's avatar
Pierre Kraemer committed
315
316
317
318
319
320
321

	/**
	* embed the topo grid Polyhedron
	* Grid has size x,y centered on 0
	* @param x
	* @param y
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
322
	void embedGrid(float x, float y, float z = 0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
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

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

361
362
	void embedCube(VEC3 origin, float sx, float sy, float sz);

Pierre Kraemer's avatar
Pierre Kraemer committed
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
	/**
	* 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
	*/
379
	void embedHelicoid(float radius_min,  float radius_max, float maxHeight, float nbTurn, int orient = 1);
Pierre Kraemer's avatar
Pierre Kraemer committed
380
381
382
383
384
385
386
387
388

	/**
	* 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
389
	* @param m the CellMarker(VERTEX) to use
Pierre Kraemer's avatar
Pierre Kraemer committed
390
	*/
391
	void mark(CellMarker<VERTEX>& m);
Pierre Kraemer's avatar
Pierre Kraemer committed
392
393
394
395
396

	/**
	* mark all embedded vertices of the Polyhedron
	* @param m the marker to use
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
397
//	void markEmbVertices(Mark m);
Pierre Kraemer's avatar
Pierre Kraemer committed
398
399
400
401
402
403
404
405
406
407

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

} // namespace Modelisation

408
409
}

Pierre Kraemer's avatar
Pierre Kraemer committed
410
411
412
413
414
415
416
} // namespace Algo

} // namespace CGoGN

#include "Algo/Modelisation/polyhedron.hpp"

#endif