Commit b2e6f0ef authored by untereiner's avatar untereiner
Browse files

triangular tiling

parent c052557b
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
#include "Utils/GLSLShader.h" #include "Utils/GLSLShader.h"
//#include "Algo/Geometry/area.h" //#include "Algo/Geometry/area.h"
#include "Algo/Geometry/normal.h" #include "Algo/Geometry/normal.h"
#include "Geometry/matrix.h"
#include "Geometry/transfo.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
#include "Utils/chrono.h" #include "Utils/chrono.h"
...@@ -104,7 +105,12 @@ void MyQT::squareTiling(int code) ...@@ -104,7 +105,12 @@ void MyQT::squareTiling(int code)
{ {
std::cout << "square grid tiling" << std::endl; std::cout << "square grid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true); Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoGrid(position,50,50); g.embedIntoGrid(position,1.0,1.0, 0.0);
Geom::Matrix44f trf;
trf.identity();
Geom::translate<float>(0.5,0.5,0.0,trf);
g.transform(position, trf);
g.exportPositions(position, "grid.bs"); g.exportPositions(position, "grid.bs");
...@@ -114,7 +120,13 @@ void MyQT::squareTiling(int code) ...@@ -114,7 +120,13 @@ void MyQT::squareTiling(int code)
{ {
std::cout << "square grid twisted strip tiling" << std::endl; std::cout << "square grid twisted strip tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true); Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoTwistedStrip(position, 0.3, 0.8, 5); g.embedIntoTwistedStrip(position, 0.2, 0.7, 5);
Geom::Matrix44f trf;
trf.identity();
Geom::translate<float>(0.5,0.5,0.0,trf);
g.transform(position, trf);
g.exportPositions(position, "gridtwisted.bs"); g.exportPositions(position, "gridtwisted.bs");
...@@ -124,7 +136,13 @@ void MyQT::squareTiling(int code) ...@@ -124,7 +136,13 @@ void MyQT::squareTiling(int code)
{ {
std::cout << "square grid helicoid tiling" << std::endl; std::cout << "square grid helicoid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true); Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true);
g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0); g.embedIntoHelicoid(position, 0.2, 0.3, 0.8, 2.0);
// Geom::Matrix44f trf;
// trf.identity();
// Geom::translate<float>(0.5,0.5,0.0,trf);
// g.transform(position, trf);
g.exportPositions(position, "gridhelicoid.bs"); g.exportPositions(position, "gridhelicoid.bs");
...@@ -134,7 +152,13 @@ void MyQT::squareTiling(int code) ...@@ -134,7 +152,13 @@ void MyQT::squareTiling(int code)
{ {
std::cout << "square cylinder tiling" << std::endl; std::cout << "square cylinder tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20); Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.embedIntoCylinder(position,0.5,0.7,5.0); c.embedIntoCylinder(position,0.5,0.7,1.0);
Geom::Matrix44f trf;
trf.identity();
Geom::translate<float>(0.5,0.5,0.0,trf);
c.transform(position, trf);
c.exportPositions(position, "cylinder.bs"); c.exportPositions(position, "cylinder.bs");
...@@ -146,7 +170,7 @@ void MyQT::squareTiling(int code) ...@@ -146,7 +170,7 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20); Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleBottom(); c.triangleBottom();
c.triangleTop(); c.triangleTop();
c.embedIntoCylinder(position,0.5,0.7,5.0); c.embedIntoCylinder(position,0.5,0.7,1.0);
break; break;
} }
...@@ -166,7 +190,7 @@ void MyQT::squareTiling(int code) ...@@ -166,7 +190,7 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20); Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleTop(); c.triangleTop();
c.triangleBottom(); c.triangleBottom();
c.embedIntoCone(position,0.5, 5.0); c.embedIntoCone(position,0.5, 1.0);
break; break;
} }
...@@ -174,7 +198,12 @@ void MyQT::squareTiling(int code) ...@@ -174,7 +198,12 @@ void MyQT::squareTiling(int code)
{ {
std::cout << "square cylinder cone tiling" << std::endl; std::cout << "square cylinder cone tiling" << std::endl;
Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20); Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20);
c.embedIntoCube(position,5.0,5.0, 5.0); c.embedIntoCube(position,1.0, 1.0, 1.0);
Geom::Matrix44f trf;
trf.identity();
Geom::translate<float>(0.5,0.5,0.5,trf);
c.transform(position, trf);
c.exportPositions(position, "cube.bs"); c.exportPositions(position, "cube.bs");
...@@ -184,7 +213,7 @@ void MyQT::squareTiling(int code) ...@@ -184,7 +213,7 @@ void MyQT::squareTiling(int code)
{ {
std::cout << "square tore tiling" << std::endl; std::cout << "square tore tiling" << std::endl;
Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10); Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10);
c.embedIntoTore(position,5.0,2.0); c.embedIntoTore(position, 0.9, 0.5);
c.exportPositions(position, "tore.bs"); c.exportPositions(position, "tore.bs");
break; break;
...@@ -206,69 +235,69 @@ void MyQT::triangularTiling(int code) ...@@ -206,69 +235,69 @@ void MyQT::triangularTiling(int code)
{ {
case 1: case 1:
{ {
std::cout << "square grid tiling" << std::endl; std::cout << "triangle grid tiling" << std::endl;
Algo::Surface::Tilings::Triangular::Grid<PFP> g(myMap,10,10,true); Algo::Surface::Tilings::Triangular::Grid<PFP> g(myMap,10,6,true);
g.embedIntoGrid(position,50,50); g.embedIntoGrid(position,1,1);
break; break;
} }
case 2: case 2:
{ {
// std::cout << "square grid twisted strip tiling" << std::endl; std::cout << "triangle grid twisted strip tiling" << std::endl;
// Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true); Algo::Surface::Tilings::Triangular::Grid<PFP> g(myMap,10,10,true);
// g.embedIntoTwistedStrip(position, 0.3, 0.8, 5); g.embedIntoTwistedStrip(position, 0.3, 0.8, 5);
break; break;
} }
case 3: case 3:
{ {
// std::cout << "square grid helocoid tiling" << std::endl; std::cout << "triangle grid helocoid tiling" << std::endl;
// Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true); Algo::Surface::Tilings::Triangular::Grid<PFP> g(myMap,20,20,true);
// g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0); g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0);
break; break;
} }
case 4: case 4:
{ {
// std::cout << "square cylinder tiling" << std::endl; std::cout << "triangle cylinder tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20); Algo::Surface::Tilings::Triangular::Cylinder<PFP> c(myMap,20,20);
// c.embedIntoCylinder(position,0.5,0.7,5.0); c.embedIntoCylinder(position,0.5,0.7,5.0);
break; break;
} }
case 5: case 5:
{ {
// std::cout << "square cylinder tiling" << std::endl; std::cout << "triangle cylinder tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20); Algo::Surface::Tilings::Triangular::Cylinder<PFP> c(myMap,20,20);
// c.triangleBottom(); c.triangleBottom();
// c.triangleTop(); c.triangleTop();
// c.embedIntoCylinder(position,0.5,0.7,5.0); c.embedIntoCylinder(position,0.5,0.7,5.0);
break; break;
} }
case 6: case 6:
{ {
// std::cout << "square cylinder sphere tiling" << std::endl; std::cout << "triangle cylinder sphere tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20); Algo::Surface::Tilings::Triangular::Cylinder<PFP> c(myMap,20,20);
// c.triangleTop(); c.triangleTop();
// c.triangleBottom(); c.triangleBottom();
// c.embedIntoSphere(position,0.5); c.embedIntoSphere(position,0.5);
break; break;
} }
case 7: case 7:
{ {
// std::cout << "square cylinder cone tiling" << std::endl; std::cout << "triangle cylinder cone tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20); Algo::Surface::Tilings::Triangular::Cylinder<PFP> c(myMap,20,20);
// c.triangleTop(); c.triangleTop();
// c.triangleBottom(); c.triangleBottom();
// c.embedIntoCone(position,0.5, 5.0); c.embedIntoCone(position,0.5, 5.0);
break; break;
} }
case 8: case 8:
{ {
// std::cout << "square cylinder cone tiling" << std::endl; // std::cout << "triangle cylinder cone tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20); // Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20);
// c.embedIntoCube(position,5.0,5.0, 5.0); // c.embedIntoCube(position,5.0,5.0, 5.0);
...@@ -276,7 +305,7 @@ void MyQT::triangularTiling(int code) ...@@ -276,7 +305,7 @@ void MyQT::triangularTiling(int code)
} }
case 9: case 9:
{ {
// std::cout << "square cylinder cone tiling" << std::endl; // std::cout << "triangle cylinder cone tiling" << std::endl;
// Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10); // Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10);
// c.embedIntoTore(position,5.0,2.0); // c.embedIntoTore(position,5.0,2.0);
......
...@@ -111,6 +111,97 @@ protected: ...@@ -111,6 +111,97 @@ protected:
}; };
/*! \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);
//@}
};
} // namespace Triangular } // namespace Triangular
} // namespace Tilings } // namespace Tilings
......
...@@ -44,9 +44,9 @@ template <typename PFP> ...@@ -44,9 +44,9 @@ template <typename PFP>
void Grid<PFP>::grid(unsigned int x, unsigned int y, bool close) void Grid<PFP>::grid(unsigned int x, unsigned int y, bool close)
{ {
// nb vertices // nb vertices
int nb = x*y +1; int nb = (x+1)*(y+1);
// vertice reservation // vertices reservation
this->m_tableVertDarts.reserve(nb); this->m_tableVertDarts.reserve(nb);
// creation of triangles and storing vertices // creation of triangles and storing vertices
...@@ -55,62 +55,354 @@ void Grid<PFP>::grid(unsigned int x, unsigned int y, bool close) ...@@ -55,62 +55,354 @@ void Grid<PFP>::grid(unsigned int x, unsigned int y, bool close)
for (unsigned int j = 1; j <= x; ++j) for (unsigned int j = 1; j <= x; ++j)
{ {
Dart d = this->m_map.newFace(3, false); Dart d = this->m_map.newFace(3, false);
this->m_tableVertDarts.push_back(d); Dart d2 = this->m_map.newFace(3, false);
this->m_map.sewFaces(this->m_map.phi1(d), this->m_map.phi_1(d2), false);
this->m_tableVertDarts.push_back(d);
if (j == x) if (j == x)
this->m_tableVertDarts.push_back(this->m_map.phi1(d)); this->m_tableVertDarts.push_back(d2);
} }
} }
// store last row of vertices // store last row of vertices
for (unsigned int i = 0; i < x; ++i) for (unsigned int i = 0; i < x; ++i)
{ {
this->m_tableVertDarts.push_back(this->m_map.phi_1(this->m_tableVertDarts[(y-1)*(x+1) + i]) ); this->m_tableVertDarts.push_back(this->m_map.phi_1(this->m_tableVertDarts[(y-1)*(x+1) + i]));
} }
this-> m_tableVertDarts.push_back(this->m_map.phi1(this->m_tableVertDarts[(y-1)*(x+1) +x]));
//sewing the triangles //sewing pairs of triangles
for (unsigned int i = 0; i < y; ++i) for (unsigned int i = 0; i < y; ++i)
{ {
for (unsigned int j = 0; j < x; ++j) for (unsigned int j = 0; j < x; ++j)
{ {
if (i > 0) // sew with preceeding row
{ if (i > 0) // sew with preceeding row
// int pos = i*(x+1)+j; {
// Dart d = this->m_tableVertDarts[pos]; int pos = i*(x+1)+j;
// Dart e = this->m_tableVertDarts[pos-(x+1)]; Dart d = this->m_tableVertDarts[pos];
// e = this->m_map.phi_1(e); Dart e = this->m_tableVertDarts[pos-(x+1)];
// this->m_map.sewFaces(d, e, false); e = this->m_map.phi_1(this->m_map.phi2(this->m_map.phi1(e)));
} this->m_map.sewFaces(d, e, false);
if (j > 0) // sew with preceeding column }
{ if (j > 0) // sew with preceeding column
int pos = i*(x+1)+j; {
Dart d = this->m_tableVertDarts[pos]; int pos = i*(x+1)+j;
d = this->m_map.phi_1(d); Dart d = this->m_tableVertDarts[pos];
Dart e = this->m_tableVertDarts[pos-1]; d = this->m_map.phi_1(d);
e = this->m_map.phi1(e); Dart e = this->m_tableVertDarts[pos-1];
this->m_map.sewFaces(d, e, false); e = this->m_map.phi1(this->m_map.phi2(this->m_map.phi1(e)));
} this->m_map.sewFaces(d, e, false);
}
} }
} }
if(close) if(close)
this->m_map.closeHole(this->m_tableVertDarts[0]) ; this->m_map.closeHole(this->m_tableVertDarts[0]) ;
this->m_dart = this->m_tableVertDarts[0];
} }
template <typename PFP> template <typename PFP>
void Grid<PFP>::embedIntoGrid(VertexAttribute<VEC3>& position, float x, float y, float z) void Grid<PFP>::embedIntoGrid(VertexAttribute<VEC3>& position, float x, float y, float z)
{ {
float dx = x / float(this->m_nx); float dx = x / float(this->m_nx);
float dy = y / float(this->m_ny); float dy = y / float(this->m_ny);
for(unsigned int i = 0; i <= this->m_ny; ++i) for(unsigned int i = 0; i <= this->m_ny; ++i)
{ {
for(unsigned int j = 0; j <= this->m_nx;++j) for(unsigned int j = 0; j <= this->m_nx;++j)
{ {
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); position[this->m_tableVertDarts[i*(this->m_nx+1)+j]] = VEC3(dx*float(j) + dx*0.5f*float(i), dy*float(i) * sqrtf(3.0f)/2.0f, z);
} }
} }
} }
template <typename PFP>
void Grid<PFP>::embedIntoTwistedStrip(VertexAttribute<VEC3>& position, float radius_min, float radius_max, float turns)
{
float alpha = float(2.0*M_PI/this->m_ny);
float beta = turns/float(this->m_ny);
float radius = (radius_max + radius_min)/2.0f;
float rdiff = (radius_max - radius_min)/2.0f;
for(unsigned int i = 0; i <= this->m_ny; ++i)
{
for(unsigned int j = 0; j <= this->m_nx; ++j)
{
float rw = -rdiff + float(j)*2.0f*rdiff/float(this->m_nx);
float r = radius + rw*cos(beta*float(i));
VEC3 pos(r*cos(alpha*float(i)), r*sin(alpha*float(i)), rw*sin(beta*float(i)));
position[this->m_tableVertDarts[ i*(this->m_nx+1)+j ] ] = pos;
}
}
}
template <typename PFP>
void Grid<PFP>::embedIntoHelicoid(VertexAttribute<VEC3>& position, float radius_min, float radius_max, float maxHeight, float nbTurn, int orient)
{
float alpha = float(2.0*M_PI/this->m_nx)*nbTurn;
float hS = maxHeight/this->m_nx;
// float radius = (radius_max + radius_min)/2.0f;
// float rdiff = (radius_max - radius_min)/2.0f;
for(unsigned int i = 0; i <= this->m_ny; ++i)
{
for(unsigned int j = 0; j <= this->m_nx; ++j)
{
// float r = radius_max + radius_min*cos(beta*float(j));
float r,x,y;
// if(i==1) {
// r = radius_max;
// }
// else {
r = radius_min+(radius_max-radius_min)*float(i)/float(this->m_ny);
// }
x = orient*r*sin(alpha*float(j));
y = orient*r*cos(alpha*float(j));
VEC3 pos(x, y, j*hS);
Dart d = this->m_tableVertDarts[i*(this->m_nx+1)+j];
position[d] = pos;
}
}
}
/*! Cylinder
*************************************************************************/
template <typename PFP>
void Cylinder<PFP>::cylinder(unsigned int n, unsigned int z)
{
// nb vertices
int nb = (n)*(z+1)+2;
// vertices reservation
this->m_tableVertDarts.reserve(nb);
// creation of triangles and storing vertices
for (unsigned int i = 0; i < z; ++i)
{
for (unsigned int j = 0; j < n; ++j)
{
Dart d = this->m_map.newFace(3, false);
Dart d2 = this->m_map.newFace(3, false);
this->m_map.sewFaces(this->m_map.phi1(d), this->m_map.phi_1(d2), false);
this->m_tableVertDarts.push_back(d);
}
}
// store last row of vertices
for (unsigned int i = 0; i < n; ++i)
{