triangular.h 9.05 KB
Newer Older
Lionel Untereiner's avatar
Lionel Untereiner 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
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

untereiner's avatar
untereiner committed
25
26
#include "Algo/Tiling/tiling.h"

Lionel Untereiner's avatar
Lionel Untereiner committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef _TILING_TRIANGULAR_H_
#define _TILING_TRIANGULAR_H_

namespace CGoGN
{

namespace Algo
{

namespace Surface
{

namespace Tilings
{

untereiner's avatar
untereiner committed
42
43
44
45
46
namespace Triangular
{


/*! \brief The class of regular grid square tiling
Lionel Untereiner's avatar
Lionel Untereiner committed
47
48
 */
template <typename PFP>
untereiner's avatar
untereiner committed
49
class Grid : public Tiling<PFP>
Lionel Untereiner's avatar
Lionel Untereiner committed
50
51
{
    typedef typename PFP::MAP MAP;
52
	typedef typename PFP::MAP::IMPL MAP_IMPL;
Lionel Untereiner's avatar
Lionel Untereiner committed
53
54
55
    typedef typename PFP::VEC3 VEC3;

public:
untereiner's avatar
untereiner committed
56
    Grid(MAP& map, unsigned int x, unsigned int y, bool close):
57
		Tiling<PFP>(map, x, y, -1)
untereiner's avatar
untereiner committed
58
    {
59
		grid(x, y, close);
untereiner's avatar
untereiner committed
60
61
62
    }

    Grid(MAP& map, unsigned int x, unsigned int y):
63
		Tiling<PFP>(map, x, y, -1)
64
	{
65
		grid(x, y, true);
66
	}
Lionel Untereiner's avatar
Lionel Untereiner committed
67

untereiner's avatar
untereiner committed
68
    /*! @name Embedding Operators
Lionel Untereiner's avatar
Lionel Untereiner committed
69
70
71
72
     * Tiling creation
     *************************************************************************/

    //@{
untereiner's avatar
untereiner committed
73
74
75
76
77
78
    //! Embed a topological grid
    /*! @param position Attribute used to store vertices positions
     *  @param x size in X
     *  @param x size in Y
     *  @param y position in Z (centered on 0 by default)
     */
79
	void embedIntoGrid(VertexAttribute<VEC3, MAP_IMPL>& position, float x, float y, float z = 0.0f);
untereiner's avatar
untereiner committed
80
81
82
83
84
85
86

    //! Embed a topological grid into a twister open ribbon with turns=PI it is a Moebius strip, needs only to be closed (if model allow it)
    /*! @param position Attribute used to store vertices positions
     *  @param radius_min
     *  @param radius_max
     *  @param turns number of turn multiplied by 2*PI
     */
87
	void embedIntoTwistedStrip(VertexAttribute<VEC3, MAP_IMPL>& position, float radius_min, float radius_max, float turns);
untereiner's avatar
untereiner committed
88
89
90
91
92
93
94

    //! Embed a topological grid into a helicoid
    /*! @param position Attribute used to store vertices positions
     *  @param radius_min
     *  @param radius_max
     *  @param maxHeight height to reach
     *  @param turns number of turn
Lionel Untereiner's avatar
Lionel Untereiner committed
95
     */
96
	void embedIntoHelicoid(VertexAttribute<VEC3, MAP_IMPL>& position, float radius_min,  float radius_max, float maxHeight, float nbTurn, int orient = 1);
Lionel Untereiner's avatar
Lionel Untereiner committed
97
98
    //@}

untereiner's avatar
untereiner committed
99
100
protected:
    /*! @name Topological Operators
Lionel Untereiner's avatar
Lionel Untereiner committed
101
102
103
104
     * Tiling creation
     *************************************************************************/

    //@{
untereiner's avatar
untereiner committed
105
106
107
108
    //! Create a 2D grid
    /*! @param x nb of squares in x
     *  @param y nb of squares in y
     *  @param closed close the boundary face of the 2D grid
Lionel Untereiner's avatar
Lionel Untereiner committed
109
     */
untereiner's avatar
untereiner committed
110
    void grid(unsigned int x, unsigned int y, bool close);
Lionel Untereiner's avatar
Lionel Untereiner committed
111
    //@}
untereiner's avatar
untereiner committed
112

Lionel Untereiner's avatar
Lionel Untereiner committed
113
114
};

untereiner's avatar
untereiner committed
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
168
169
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
199
200
201
202
203
204
205
/*! \brief The class of regular cylinder square tiling or subdivided sphere (with pole)
 */
template <typename PFP>
class Cylinder : public Tiling<PFP>
{
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

private:
	bool m_top_closed, m_bottom_closed;
	bool m_top_triangulated, m_bottom_triangulated;
	Dart m_topVertDart, m_bottomVertDart;

public:
	Cylinder(MAP& map, unsigned int n, unsigned int z, bool close_top, bool close_bottom):
		Tiling<PFP>(map, n, -1, z),
		m_top_closed(close_top),
		m_bottom_closed(close_bottom),
		m_top_triangulated(false),
		m_bottom_triangulated(false)
	{
		cylinder(n,z);
	}

	Cylinder(MAP& map, unsigned int n, unsigned int z):
	  Tiling<PFP>(map, n, -1, z),
	  m_top_closed(true),
	  m_bottom_closed(true),
	  m_top_triangulated(false),
	  m_bottom_triangulated(false)
	{
		cylinder(n,z);
	}

	/*! @name Embedding Operators
	 * Tiling creation
	 *************************************************************************/

	//@{
	//! Embed a topological cylinder
	/*! @param position Attribute used to store vertices positions
	 *  @param bottom_radius
	 *  @param top_radius
	 *  @param height
	 */
	void embedIntoCylinder(VertexAttribute<VEC3>& position, float bottom_radius, float top_radius, float height);

	//! Embed a topological sphere
	/*! @param position Attribute used to store vertices positions
	 *  @param radius
	 *  @param height
	 */
	void embedIntoSphere(VertexAttribute<VEC3>& position, float radius);

	//! Embed a topological cone
	/*! @param position Attribute used to store vertices positions
	 *  @param radius
	 *  @param height
	 */
	void embedIntoCone(VertexAttribute<VEC3>& position, float radius, float height);
	//@}

	/*! @name Topological Operators
	 * Tiling creation
	 *************************************************************************/

	//@{
	//! Close the top with a n-sided face
	void closeTop();

	//! Triangulate the top face with triangles fan
	void triangleTop();

	//! Close the bottom with a n-sided face
	void closeBottom();

	//! Triangulate the bottom face with triangles fan
	void triangleBottom();

protected:
	//! Create a subdivided 2D cylinder
	/*! @param n nb of squares around circumference
	 *  @param z nb of squares in height
	 *  @param top_closed close the top (with triangles fan)
	 *  @param bottom_closed close the bottom (with triangles fan)
	 */
	//square -> cylinder -> grid + finish sewing -> open or closed (closeHole) -> triangule face ?
	void cylinder(unsigned int n, unsigned int z);
	//@}
};

Lionel Untereiner's avatar
Lionel Untereiner committed
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
243
244
245
246
247
248
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
/*! \brief The class of regular cube square tiling
 */
template <typename PFP>
class Cube : public Cylinder<PFP>
{
    typedef typename PFP::MAP MAP;
    typedef typename PFP::VEC3 VEC3;

public:
    Cube(MAP& map, unsigned int x, unsigned int y, unsigned int z):
        Cylinder<PFP>(map,2*(x+y),z, false, false)
    {
        cube(x,y,z);
    }

    /*! @name Embedding Operators
     * Tiling creation
     *************************************************************************/

    //@{
    //! Embed a topological cube
    /*! @param position Attribute used to store vertices positions
     *  @param x
     *  @param y
     *  @param z
     */
    void embedIntoCube(VertexAttribute<VEC3>& position, float x, float y, float z);
    //@}

protected:
    /*! @name Topological Operators
     * Tiling creation
     *************************************************************************/

    //@{
    //! Create a subdivided 2D cube
    /*! @param x nb of squares in x
     *  @param y nb of squares in y
     *  @param z nb of squares un z
     */
    void cube(unsigned int x, unsigned int y, unsigned int z);
    //@}

};

/*! \brief The class of regular tore square tiling
 */
template <typename PFP>
class Tore : public Cylinder<PFP>
{
    typedef typename PFP::MAP MAP;
    typedef typename PFP::VEC3 VEC3;

public:
    Tore(MAP& map, unsigned int n, unsigned int m):
        Cylinder<PFP>(map,n,m)
    {
        tore(n,m);
    }

    /*! @name Embedding Operators
     * Tiling creation
     *************************************************************************/

    //@{
    //! Embed a topological tore
    /*! @param position Attribute used to store vertices positions
     *  @param big_radius
     *  @param small_radius
     */
    void embedIntoTore(VertexAttribute<VEC3>& position, float big_radius, float small_radius);
    //@}

    /*! @name Topological Operators
     * Tiling creation
     *************************************************************************/

    //@{
protected:
    //! Create a subdivided 2D tore
    /*! @param n nb of squares around big circumference
     *  @param m nb of squares around small circumference
     */
    //square -> tore -> cylinder + finish sewing
    void tore(unsigned int n, unsigned int m);
    //@}
};

untereiner's avatar
untereiner committed
294
295
} // namespace Triangular

Lionel Untereiner's avatar
Lionel Untereiner committed
296
297
298
299
300
301
302
303
} // namespace Tilings

} // namespace Surface

} // namespace Algo

} // namespace CGoGN

untereiner's avatar
untereiner committed
304
#include "Algo/Tiling/Surface/triangular.hpp"
Lionel Untereiner's avatar
Lionel Untereiner committed
305
306

#endif //_TILING_TRIANGULAR_H_