hexagonal.hpp 4.58 KB
Newer Older
untereiner's avatar
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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

namespace Surface
{

namespace Tilings
{

namespace Hexagonal
{

/*! Grid
 *************************************************************************/

template <typename PFP>
void Grid<PFP>::grid(unsigned int x, unsigned int y, bool close)
{
    // nb vertices
47 48
	unsigned int nbV = x*y +1;
	unsigned int nbF = x*y;
untereiner's avatar
untereiner committed
49 50

    // vertice reservation
51 52
	this->m_tableVertDarts.reserve(nbV);
	this->m_tableFaceDarts.reserve(nbF);
untereiner's avatar
untereiner committed
53 54 55 56 57 58

    // creation of triangles and storing vertices
    for (unsigned int i = 0; i < y; ++i)
    {
        for (unsigned int j = 1; j <= x; ++j)
        {
59
            Dart d = this->m_map.newFace(6, false);
untereiner's avatar
untereiner committed
60
            this->m_tableVertDarts.push_back(d);
61 62 63
            this->m_tableVertDarts.push_back(this->m_map.phi1(d));
            if (j== 1)
                this->m_tableVertDarts.push_back(this->m_map.phi_1(d));
untereiner's avatar
untereiner committed
64
            if (j == x)
65
                this->m_tableVertDarts.push_back(this->m_map.phi1(this->m_map.phi1(d)));
66
			this->m_tableFaceDarts.push_back(d);
untereiner's avatar
untereiner committed
67 68 69 70 71 72
        }
    }

    // store last row of vertices
    for (unsigned int i = 0; i < x; ++i)
    {
73
        this->m_tableVertDarts.push_back(this->m_map.phi_1(this->m_tableVertDarts[(y-1)*(x+1) + i]) );
untereiner's avatar
untereiner committed
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
    }
    //this-> m_tableVertDarts.push_back(this->m_map.phi1(this->m_tableVertDarts[(y-1)*(x+1) +x]) );

    //sewing the triangles
    for (unsigned int i = 0; i < y; ++i)
    {
        for (unsigned int j = 0; j < x; ++j)
        {
            if (i > 0) // sew with preceeding row
            {
                int pos = i*(x+1)+j;
                Dart d = this->m_tableVertDarts[pos];
                Dart e = this->m_tableVertDarts[pos-(x+1)];
                e = this->m_map.phi1(this->m_map.phi1(e));
                this->m_map.sewFaces(d, e, false);
            }
            if (j > 0) // sew with preceeding column
            {
                int pos = i*(x+1)+j;
                Dart d = this->m_tableVertDarts[pos];
                d = this->m_map.phi_1(d);
                Dart e = this->m_tableVertDarts[pos-1];
                e = this->m_map.phi1(e);
                this->m_map.sewFaces(d, e, false);
            }
        }
    }

    if(close)
        this->m_map.closeHole(this->m_tableVertDarts[0]) ;
}

template <typename PFP>
107
void Grid<PFP>::embedIntoGrid(VertexAttribute<VEC3, MAP>& position, float x, float y, float z)
untereiner's avatar
untereiner committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
{
    float dx = x / float(this->m_nx);
    float dy = y / float(this->m_ny);

    for(unsigned int i = 0; i <= this->m_ny; ++i)
    {
        for(unsigned int j = 0; j <= this->m_nx;++j)
        {
            position[this->m_tableVertDarts[i*(this->m_nx+1)+j] ] = VEC3(-x/2 + dx*float(j), -y/2 + dy*float(i), z);
        }
    }
}

} // namespace Hexagonal

} // namespace Tilings

} // namespace Surface

} // namespace Algo

} // namespace CGoGN