primitives3d.hpp 6.81 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-2011, 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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

namespace Modelisation
{

//TEMPORAIRE
template <typename PFP>
36
Dart Primitive3D<PFP>::createHexa()
Pierre Kraemer's avatar
Pierre Kraemer committed
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 67 68 69
{
	Dart base = m_map.newFace(4);

	Dart side1 = m_map.newFace(4);
	m_map.sewFaces(base,side1);

	Dart side2 = m_map.newFace(4);
	m_map.sewFaces(m_map.phi1(base),side2);
	m_map.sewFaces(m_map.phi_1(side1), m_map.phi1(side2));

	Dart side3 = m_map.newFace(4);
	m_map.sewFaces(m_map.phi1(m_map.phi1(base)),side3);
	m_map.sewFaces(m_map.phi_1(side2), m_map.phi1(side3));

	Dart side4 = m_map.newFace(4);
	m_map.sewFaces(m_map.phi_1(base),side4);
	m_map.sewFaces(m_map.phi_1(side3), m_map.phi1(side4));

	m_map.sewFaces(m_map.phi_1(side4), m_map.phi1(side1));

	Dart top = m_map.newFace(4);
	m_map.sewFaces(top,m_map.phi1(m_map.phi1(side1)));
	m_map.sewFaces(m_map.phi_1(top),m_map.phi1(m_map.phi1(side2)));
	m_map.sewFaces(m_map.phi1(m_map.phi1(top)),m_map.phi1(m_map.phi1(side3)));
	m_map.sewFaces(m_map.phi1(top),m_map.phi1(m_map.phi1(side4)));

	return base;
}

template <typename PFP>
Dart Primitive3D<PFP>::HexaGrid1Topo(int nx)
{
	// first cube
untereiner's avatar
untereiner committed
70
<<<<<<< HEAD
untereiner's avatar
untereiner committed
71 72
	Dart d0 = createOrientedHexa(); //return a dart from the base of the cube
	m_tableVertDarts.push_back(d0); //push_back darts frome the base of cubes
untereiner's avatar
untereiner committed
73
=======
74
	Dart d0 = createHexa();
Pierre Kraemer's avatar
Pierre Kraemer committed
75
	m_tableVertDarts.push_back(d0);
untereiner's avatar
untereiner committed
76
>>>>>>> 9d09fe01ab3a12525ca57c400eb2777dfbc5b528
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78 79 80
	Dart d1 = m_map.template phi<2112>(d0);

	for (int i=1; i< nx; ++i)
	{
81
		Dart d2 = createHexa();
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83 84 85 86 87
		m_tableVertDarts.push_back(d2);
		m_map.sewVolumes(d1,d2);
		d1 = m_map.template phi<2112>(d2);
	}

	// add last vertex (x=nx)
untereiner's avatar
untereiner committed
88
	d1 = m_map.phi2(d1); //TODO can take phi1 instead > same vertex ??
Pierre Kraemer's avatar
Pierre Kraemer committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 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
	m_tableVertDarts.push_back(d1);

	return d0;
}

template <typename PFP>
Dart Primitive3D<PFP>::HexaGrid2Topo( int nx, int ny)
{
	// creation premiere ligne
	Dart d0 = HexaGrid1Topo(nx);
	Dart d1 = m_map.template phi<112>(d0);

	for (int i=1; i< ny; ++i)
	{
		// creation ligne suivante
		Dart d2 = HexaGrid1Topo(nx);
		Dart d3 =  m_map.phi2(d2);

		// couture des deux lignes de cubes
		for (int i=0; i< nx; ++i)
		{
			m_map.sewVolumes(d1,d3);
			d1 = m_map.template phi<11232>(d1);
			d3 = m_map.template phi<11232>(d3);
		}
		// passage a lignes suivante
		d1 = m_map.template phi<112>(d2);
	}

	// add last row of vertices (y = ny)

	int index = m_tableVertDarts.size()-(nx+1); // pos of last inserted row of dart
	for (int i = 0; i< nx; ++i)
	{
		Dart dd = m_tableVertDarts[index++];
		dd =m_map.template phi<112>(dd);
		m_tableVertDarts.push_back(dd);	
	}
	// warning last vertex of row has not same dart
	Dart dd = m_tableVertDarts[index++];
	dd =m_map.template phi<211>(dd);
	m_tableVertDarts.push_back(dd);	


	return d0;
}


template <typename PFP>
Dart Primitive3D<PFP>::hexaGrid_topo( int nx, int ny, int nz)
{
	m_kind = HEXAGRID;
	m_nx = nx;
	m_ny = ny;
	m_nz = nz;
	m_tableVertDarts.clear();
	m_tableVertDarts.reserve((nx+1)*(ny+1)*(nz+1));
	

	Dart d0 = HexaGrid2Topo(nx,ny);
	Dart d1 = m_map.template phi<12>(d0);

	for (int i=1; i< nz; ++i)
	{
		// creation grille suivante
		Dart d2 = HexaGrid2Topo(nx,ny);
		Dart d3 = m_map.phi2(m_map.phi_1(d2));
		
		// couture des deux grilles 2D de cubes
		for (int j=0; j< ny; ++j)
		{
			Dart da = d1;
			Dart db = d3;
			for (int k=0; k< nx; ++k)
			{
				m_map.sewVolumes(da,db);
				da = m_map.template phi<11232>(da);
				db = m_map.template phi<11232>(db);
			}
			d1 = m_map.phi_1(d1);
			d1 = m_map.template phi<232>(d1);
			d1 = m_map.phi_1(d1);
			d3 = m_map.template phi<12321>(d3);
		}
		// passage a lignes suivante
		d1 = m_map.template phi<12>(d2);
	}

	// add last slice of vertices to the table
	int nb = (nx+1)*(ny+1);	// nb of vertices in one slice XY
	int index = nb*(nz-1);	// last slice
	for (int i=0; i < nb; ++i)
	{
		Dart dd = m_tableVertDarts[index++];
		dd =m_map.phi2(dd);
		m_tableVertDarts.push_back(dd);
	}

	return d0;
}


template <typename PFP>
void Primitive3D<PFP>::embedHexaGrid( float x, float y, float z)
{
	if (m_kind != HEXAGRID)
	{
196
		CGoGNerr << "Warning try to embedHexaGrid something that is not a grid of hexahedron"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
		return;
	}

	float dx = x/float(m_nx);
	float dy = y/float(m_ny);
	float dz = z/float(m_nz);

	int nbs = (m_nx+1)*(m_ny+1);

	for(int i=0; i<=m_nz; ++i)
	{
		for(int j=0; j<=m_ny; ++j)
		{
			for(int k=0; k<=m_nx;++k)
			{
				typename PFP::VEC3 pos(-x/2.0f + dx*float(k), -y/2.0f + dy*float(j), -z/2.0f + dz*float(i));
				Dart d = m_tableVertDarts[ i*nbs+j*(m_nx+1)+k ];

215
				m_map.embedNewCell(VERTEX,d);
Pierre Kraemer's avatar
Pierre Kraemer committed
216 217 218 219 220 221 222 223 224 225
				m_positions[d] = pos;
			}
		}
	}
}


template <typename PFP>
void Primitive3D<PFP>::transform(const Geom::Matrix44f& matrice)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
226
	for(typename std::vector<Dart>::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di)
Pierre Kraemer's avatar
Pierre Kraemer committed
227 228 229 230 231 232 233
	{
		typename PFP::VEC3& pos = m_positions[*di];
		pos = Geom::transform(pos, matrice);
	}

}

Pierre Kraemer's avatar
Pierre Kraemer committed
234 235 236 237 238 239 240 241
//template <typename PFP>
//void Primitive3D<PFP>::mark(Mark m)
//{
//	for(typename std::vector<Dart>::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di)
//	{
//		m_map.markOrbit(0, *di, m);
//	}
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
242 243 244 245

}//end namespace
}//end namespace
}//end namespace