triangular.hpp 4.14 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/*******************************************************************************
* 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 Triangular
{

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

template <typename PFP>
void Grid<PFP>::grid(unsigned int x, unsigned int y, bool close)
{
    // nb vertices
    int nb = x*y +1;

    // vertice reservation
    this->m_tableVertDarts.reserve(nb);

    // creation of triangles and storing vertices
    for (unsigned int i = 0; i < y; ++i)
    {
        for (unsigned int j = 1; j <= x; ++j)
        {
            Dart d = this->m_map.newFace(3, false);
            this->m_tableVertDarts.push_back(d);
            if (j == x)
                this->m_tableVertDarts.push_back(this->m_map.phi1(d));
        }
    }

    // store last row of vertices
    for (unsigned int i = 0; i < x; ++i)
    {
67 68
		this->m_tableVertDarts.push_back(this->m_map.phi_1(this->m_tableVertDarts[(y-1)*(x+1) + i]) );
    }    
untereiner's avatar
untereiner committed
69 70 71 72 73 74 75 76

    //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
            {
77 78 79 80 81
//				int pos = i*(x+1)+j;
//				Dart d = this->m_tableVertDarts[pos];
//				Dart e = this->m_tableVertDarts[pos-(x+1)];
//				e = this->m_map.phi_1(e);
//				this->m_map.sewFaces(d, e, false);
untereiner's avatar
untereiner committed
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
            }
            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>
void Grid<PFP>::embedIntoGrid(VertexAttribute<VEC3>& position, float x, float y, float z)
{
    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)
        {
109
			position[this->m_tableVertDarts[i*(this->m_nx+1)+j] ] = VEC3(dx*float(j) + 0.5f*float(i), dy*float(i) * sqrtf(3.0f)/2.0f, z);
untereiner's avatar
untereiner committed
110 111 112 113 114 115 116 117 118 119 120 121 122
        }
    }
}

} // namespace Triangular

} // namespace Tilings

} // namespace Surface

} // namespace Algo

} // namespace CGoGN