square.h 9.16 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#include "Algo/Tiling/tiling.h"

#ifndef _TILING_SQUARE_H_
#define _TILING_SQUARE_H_

namespace CGoGN
{

namespace Algo
{

namespace Surface
{

namespace Tilings
{

namespace Square
{


/*! \brief The class of regular grid square tiling
 */
template <typename PFP>
class Grid : public Tiling<PFP>
{
    typedef typename PFP::MAP MAP;
    typedef typename PFP::VEC3 VEC3;

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

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

Lionel Untereiner's avatar
Lionel Untereiner committed
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
    /*! @name Embedding Operators
     * Tiling creation
     *************************************************************************/

    //@{
    //! 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)
     */
    void embedIntoGrid(VertexAttribute<VEC3>& position, float x, float y, float z = 0.0f);

    //! 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
     */
    void embedIntoTwistedStrip(VertexAttribute<VEC3>& position, float radius_min, float radius_max, float turns);

    //! 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
     */
    void embedIntoHelicoid(VertexAttribute<VEC3>& position, float radius_min,  float radius_max, float maxHeight, float nbTurn, int orient = 1);
    //@}

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

    //@{
    //! 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
     */
untereiner's avatar
untereiner committed
109
    void grid(unsigned int x, unsigned int y, bool close);
Lionel Untereiner's avatar
Lionel Untereiner committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123
    //@}

};

/*! \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;
untereiner's avatar
untereiner committed
124 125
    bool m_top_triangulated, m_bottom_triangulated;
    Dart m_topVertDart, m_bottomVertDart;
Lionel Untereiner's avatar
Lionel Untereiner committed
126 127

public:
untereiner's avatar
untereiner committed
128
    Cylinder(MAP& map, unsigned int n, unsigned int z, bool close_top, bool close_bottom):
Lionel Untereiner's avatar
Lionel Untereiner committed
129
        Tiling<PFP>(map, n, -1, z),
untereiner's avatar
untereiner committed
130 131 132 133
        m_top_closed(close_top),
        m_bottom_closed(close_bottom),
        m_top_triangulated(false),
        m_bottom_triangulated(false)
Lionel Untereiner's avatar
Lionel Untereiner committed
134 135 136 137
    {
        cylinder(n,z);
    }

untereiner's avatar
untereiner committed
138
    Cylinder(MAP& map, unsigned int n, unsigned int z):
139 140 141 142 143 144 145 146
	  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);
	}
untereiner's avatar
untereiner committed
147

Lionel Untereiner's avatar
Lionel Untereiner committed
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
    /*! @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();

untereiner's avatar
untereiner committed
193
protected:
Lionel Untereiner's avatar
Lionel Untereiner committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    //! 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);
    //@}
};

/*! \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):
untereiner's avatar
untereiner committed
215
        Cylinder<PFP>(map,2*(x+y),z, false, false)
Lionel Untereiner's avatar
Lionel Untereiner committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
    {
        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);
    //@}

untereiner's avatar
untereiner committed
234
protected:
Lionel Untereiner's avatar
Lionel Untereiner committed
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
    /*! @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):
untereiner's avatar
untereiner committed
260
        Cylinder<PFP>(map,n,m)
Lionel Untereiner's avatar
Lionel Untereiner committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    {
        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
     *************************************************************************/

    //@{
untereiner's avatar
untereiner committed
283
protected:
Lionel Untereiner's avatar
Lionel Untereiner committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
    //! 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);
    //@}
};

} // namespace Square

} // namespace Tilings

} // namespace Surface

} // namespace Algo

} // namespace CGoGN

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

#endif // _TILING_SQUARE_H_