Commit 55cb77c0 authored by untereiner's avatar untereiner

some changes ?

parent 1a280155
......@@ -212,7 +212,7 @@ void Viewer::cb_keyPress(int keycode)
Geom::Plane3D<PFP::REAL> plan(n,o);
CellMarker<FACE> over(myMap);
Algo::Surface::Modelisation::planeCut<PFP>(myMap, position, plan, over, false,true);
Algo::Surface::Modelisation::planeCut<PFP>(myMap, position, plan, over, true, true);
std::cout << "PlaneCut Ok"<< std::endl;
n *= bb.diagSize()/20.0f;
......@@ -236,8 +236,44 @@ void Viewer::cb_keyPress(int keycode)
m_topoRender->updateData<PFP>(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ;
updateGL();
break;
}
case 'P':
{
std::cout << "PlaneCut"<< std::endl;
Geom::Vec3f n(0.1,0.1,1.0);
Geom::Vec3f o = bb.center();
Geom::Plane3D<PFP::REAL> plan(n,o);
CellMarker<FACE> over(myMap);
Algo::Surface::Modelisation::planeCut2<PFP>(myMap, position, plan, over, true);
std::cout << "PlaneCut Ok"<< std::endl;
n *= bb.diagSize()/20.0f;
TraversorV<PFP::MAP> trav(myMap);
for (Dart d=trav.begin(); d!=trav.end(); d=trav.next())
{
if (over.isMarked(d))
position[d]+= n;
}
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES) ;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
m_topoRender->updateData<PFP>(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ;
updateGL();
break;
}
case 'd':
{
......@@ -256,8 +292,10 @@ void Viewer::cb_keyPress(int keycode)
}
std::cout << "Dist="<< sqrt(dist) << " of "<< nb << "faces in "<< ch.elapsed()<< " ms"<< std::endl;
}
break;
}
......@@ -290,7 +328,7 @@ void Viewer::importMesh(std::string& filename)
position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
}
// myMap.enableQuickTraversal<VERTEX>() ;
// myMap.enableQuickTraversal<VERTEX>() ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ;
......@@ -300,7 +338,7 @@ void Viewer::importMesh(std::string& filename)
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize / 5.0f ;
// vertexBaseSize = normalBaseSize / 5.0f ;
normal = myMap.getAttribute<VEC3, VERTEX>("normal") ;
if(!normal.isValid())
......
......@@ -106,6 +106,8 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoGrid(position,50,50);
g.exportPositions(position, "grid.bs");
break;
}
case 2:
......@@ -114,14 +116,18 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoTwistedStrip(position, 0.3, 0.8, 5);
g.exportPositions(position, "gridtwisted.bs");
break;
}
case 3:
{
std::cout << "square grid helocoid tiling" << std::endl;
std::cout << "square grid helicoid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true);
g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0);
g.exportPositions(position, "gridhelicoid.bs");
break;
}
case 4:
......@@ -130,6 +136,8 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.embedIntoCylinder(position,0.5,0.7,5.0);
c.exportPositions(position, "cylinder.bs");
break;
}
case 5:
......@@ -168,14 +176,17 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20);
c.embedIntoCube(position,5.0,5.0, 5.0);
c.exportPositions(position, "cube.bs");
break;
}
case 9:
{
std::cout << "square cylinder cone tiling" << std::endl;
std::cout << "square tore tiling" << std::endl;
Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10);
c.embedIntoTore(position,5.0,2.0);
c.exportPositions(position, "tore.bs");
break;
}
......@@ -184,6 +195,8 @@ void MyQT::squareTiling(int code)
break;
}
}
myMap.check();
}
// mouse picking
......
......@@ -85,8 +85,8 @@ void subdivideFace(typename PFP::MAP& map, Dart d, AttributeHandler<typename PFP
unsigned int cur = map.getCurrentLevel() ;
map.setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges
unsigned int vLevel = map.volumeLevel(old);
//one level of subdivision in the neighbordhood
// unsigned int vLevel = map.volumeLevel(old);
// Traversor3VW<typename PFP::MAP> trav3EW(map, old);
// for(Dart dit = trav3EW.begin() ; dit != trav3EW.end() ; dit = trav3EW.next())
// {
......@@ -114,7 +114,6 @@ void subdivideFace(typename PFP::MAP& map, Dart d, AttributeHandler<typename PFP
map.setCurrentLevel(fLevel + 1) ; // go to the next level to perform face subdivision
Dart res;
if(degree == 3 && sType == IHM::S_TRI) //subdiviser une face triangulaire
{
......@@ -146,47 +145,6 @@ void subdivideFace(typename PFP::MAP& map, Dart d, AttributeHandler<typename PFP
map.setFaceId(dd, idface, FACE) ;
map.setFaceId(e, idface, FACE) ;
// Dart stop = map.phi2(map.phi1(old));
// Dart dit = stop;
// do
// {
// unsigned int dId = map.getEdgeId(map.phi_1(map.phi2(dit)));
// unsigned int eId = map.getEdgeId(map.phi1(map.phi2(dit)));
// unsigned int t = dId + eId;
// if(t == 0)
// {
// map.setEdgeId(dit, 1, EDGE) ;
// map.setEdgeId(map.phi2(dit), 1, EDGE) ;
// }
// else if(t == 1)
// {
// map.setEdgeId(dit, 2, EDGE) ;
// map.setEdgeId(map.phi2(dit), 2, EDGE) ;
// }
// else if(t == 2)
// {
// if(dId == eId)
// {
// map.setEdgeId(dit, 0, EDGE) ;
// map.setEdgeId(map.phi2(dit), 0, EDGE) ;
// }
// else
// {
// map.setEdgeId(dit, 1, EDGE) ;
// map.setEdgeId(map.phi2(dit), 1, EDGE) ;
// }
// }
// else if(t == 3)
// {
// map.setEdgeId(dit, 0, EDGE) ;
// map.setEdgeId(map.phi2(dit), 0, EDGE) ;
// }
// dit = map.phi1(dit);
// }while(dit != stop);
}
else
{
......
......@@ -31,6 +31,7 @@
#include "Topology/generic/cellmarker.h"
#include "Topology/generic/traversorCell.h"
#include "Algo/Modelisation/triangulation.h"
#include "Algo/Modelisation/subdivision.h"
namespace CGoGN
{
......@@ -50,11 +51,28 @@ template <typename PFP>
void planeCut(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, const Geom::Plane3D<typename PFP::REAL>& plane,
CellMarker<FACE>& cmf_over, bool keepTriangles=false, bool with_unsew = true);
template <typename PFP>
void planeCut2(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, const Geom::Plane3D<typename PFP::REAL>& plane,
CellMarker<FACE>& cmf_over, bool with_unsew);
} // namespace Modelisation
} // namespace Surface
namespace Volume
{
namespace Modelisation
{
template <typename PFP>
void planeCut(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, const Geom::Plane3D<typename PFP::REAL>& plane,
CellMarker<FACE>& cmv_over, bool keepTetrahedra=false, bool with_unsew = true);
} // namespace Modelisation
} // namespace Volume
} // namespace Algo
} // namespace CGoGN
......
......@@ -252,11 +252,215 @@ void planeCut(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& posit
delete triangulator;
}
template <typename PFP>
void planeCut2(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, const Geom::Plane3D<typename PFP::REAL>& plane,
CellMarker<FACE>& cmf_over, bool with_unsew)
{
typedef typename PFP::REAL REAL;
//marker for vertices on the plane
CellMarker<VERTEX> cmv(map);
// marker for vertices over the plane
CellMarker<VERTEX> cmv_over(map);
EdgeAutoAttribute<VEC3> positionEdge(map);
CellMarker<EDGE> cme(map);
TraversorE<typename PFP::MAP> traEdg(map);
for (Dart d=traEdg.begin(); d!=traEdg.end();d=traEdg.next())
{
Dart dd = map.phi1(d);
REAL dist1;
REAL dist2;
Geom::Orientation3D or1 = plane.orient(position[d],dist1);
Geom::Orientation3D or2 = plane.orient(position[dd],dist2);
if (or1 == Geom::ON)
cmv.mark(d);
if (or2 == Geom::ON)
cmv.mark(dd);
if ((or1!=Geom::ON) && (or2!=Geom::ON) && (or1 != or2))
{
if (dist1<0.0)
dist1 = -dist1;
if (dist2<0.0) // no abs() to avoid type problem with REAL template
dist2 = -dist2;
positionEdge[d] = (position[d]*dist2 + position[dd]*dist1)/(dist1+dist2);
cme.mark(d);
if (or1 == Geom::OVER)
cmv_over.mark(d);
else
cmv_over.mark(dd);
}
else
{
if (or1 == Geom::OVER)
{
cmv_over.mark(d);
cmv_over.mark(dd);
}
}
}
TraversorF<typename PFP::MAP> traFac(map);
for (Dart d=traFac.begin(); d!=traFac.end();d=traFac.next())
{
// turn in the face to search if there are 2 edges marked as intersecting the plane
Traversor2FE<typename PFP::MAP> traFE(map,d);
Dart e=traFE.begin();
while ((e!=traFE.end())&&(!cme.isMarked(e)))
e=traFE.next();
Dart E1=NIL;
if (e!=traFE.end())
E1 = e;
e=traFE.next();
while ((e!=traFE.end())&&(!cme.isMarked(e)))
e=traFE.next();
Dart E2=NIL;
if (e!=traFE.end())
E2 = e;
// is there 2 edges intersecting the plane
if ((E1!=NIL) && (E2!=NIL))// && (V2!=map.phi1(V1)) && (V1!=map.phi1(V2)))
{
Dart x = Algo::Surface::Modelisation::trianguleFace<PFP>(map,E1);
position[x] = (positionEdge[E1] + positionEdge[E2] ) * 0.5;
//ensure to not scan this three new faces
traFac.skip(x);
traFac.skip(map.phi2(x));
traFac.skip(map.phi2(map.phi_1(x)));
if (cmv_over.isMarked(E1))
cmf_over.mark(map.phi2((map.phi_1(E1))));
if (cmv_over.isMarked(E2))
cmf_over.mark(map.phi2((map.phi_1(E2))));
}
else
{
// find the first vertex not on the plane
Dart e = d;
while (cmv.isMarked(e))
e = map.phi1(e);
// face is all on same side than vertex
if (cmv_over.isMarked(e))
cmf_over.mark(e);
}
}
for (Dart d=traEdg.begin(); d!=traEdg.end();d=traEdg.next())
{
if(cme.isMarked(d))
{
map.flipBackEdge(d);
if (with_unsew)
{
Dart d2 = map.phi2(d);
map.unsewFaces(d); // ne marche pas !
if(cmv_over.isMarked(map.phi_1(d)))
cmf_over.mark(d);
if(cmv_over.isMarked(map.phi_1(d2)))
cmf_over.mark(d2);
}
}
}
}
} // namespace Modelisation
} // namespace Surface
namespace Volume
{
namespace Modelisation
{
template <typename PFP>
void planeCut(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, const Geom::Plane3D<typename PFP::REAL>& plane,
CellMarker<FACE>& cmf_over, bool keepTetrahedra=false, bool with_unsew = true)
{
typedef typename PFP::REAL REAL;
//marker for vertices on the plane
CellMarker<VERTEX> cmv(map);
// marker for vertices over the plane
CellMarker<VERTEX> cmv_over(map);
TraversorE<typename PFP::MAP> traEdg(map);
for (Dart d=traEdg.begin(); d!=traEdg.end();d=traEdg.next())
{
Dart dd = map.phi1(d);
REAL dist1;
REAL dist2;
Geom::Orientation3D or1 = plane.orient(position[d],dist1);
Geom::Orientation3D or2 = plane.orient(position[dd],dist2);
if (or1 == Geom::ON)
cmv.mark(d);
if (or2 == Geom::ON)
cmv.mark(dd);
if ((or1!=Geom::ON) && (or2!=Geom::ON) && (or1 != or2))
{
Dart x = map.cutEdge(d);
if (dist1<0.0)
dist1 = -dist1;
if (dist2<0.0) // no abs() to avoid type problem with REAL template
dist2 = -dist2;
position[x] = (position[d]*dist2 + position[dd]*dist1)/(dist1+dist2);
traEdg.skip(x);
traEdg.skip(map.phi_1(x));
cmv.mark(x);
if (or1 == Geom::OVER)
cmv_over.mark(d);
else
cmv_over.mark(dd);
}
else
{
if (or1 == Geom::OVER)
{
cmv_over.mark(d);
cmv_over.mark(dd);
}
}
}
TraversorW<typename PFP::MAP> traVol(map);
for (Dart d=traVol.begin(); d!=traVol.end();d=traVol.next())
{
// turn in the volume to search if there are ? vertices marked as on the plane
}
}
} // namespace Modelisation
} // namespace Volume
} // namespace Algo
} // namespace CGoGN
......@@ -144,265 +144,6 @@ Dart embedPrism(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& pos
template <typename PFP>
Dart embedPyramid(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, unsigned int n, bool withBoundary, float radius, float height);
///**
//* class of geometric Polyhedron
//* It alloaw the creation of:
//* - grid 2D
//* - subdivided cube
//* - subdivided cone
//* - subdivided cylinder
//* - subdivided tore
//* - subdivided sphere (with pole)
//*
//* Topological creation methods are separated from embedding to
//* easily allow specific embedding.
//*/
//template <typename PFP>
//class Polyhedron
//{
// typedef typename PFP::MAP MAP;
// typedef typename PFP::VEC3 VEC3;
//public:
// enum {NONE,GRID, CUBE, CYLINDER, CONE, SPHERE, TORE, COMPOSED};
//protected:
// /**
// * Map in which we are working
// */
// MAP& m_map;
// /**
// * Reference dart of Polyhedron
// */
// Dart m_dart;
// /**
// * Kind of Polyhedron (grid, cylinder,
// */
// int m_kind;
// /**
// * Table of vertex darts (one dart per vertex)
// * Order depend on Polyhedron kind
// */
// std::vector<Dart> m_tableVertDarts;
// /**
// * numbers that defined the subdivision of Polyhedron
// */
// unsigned int m_nx;
// unsigned int m_ny;
// unsigned int m_nz;
// bool m_top_closed;
// bool m_bottom_closed;
// VertexAttribute<VEC3>& m_positions;
// VEC3 m_center;
// /**
// * return the dart of next vertex when traversing the boundary of a quad or trifan grid
// */
// Dart nextDV(Dart d) { return m_map.phi1(m_map.phi2(m_map.phi1(d))); }
// /**
// * return the dart of preceding vertex when traversing the boundary of a quad or trifan grid
// */
// Dart precDV(Dart d) { return m_map.phi_1(m_map.phi2(m_map.phi_1(d))); }
// void computeCenter();
// Dart grid_topo_open(unsigned int x, unsigned int y);
// Dart cylinder_topo_open(unsigned int n, unsigned int z);
//public:
// /**
// * Constructor
// * @param map the map in which we want to work
// * @param idPositions id of attribute position
// */
// Polyhedron(MAP& map, VertexAttribute<VEC3>& position):
// m_map(map),
// m_kind(NONE),
// m_nx(-1), m_ny(-1), m_nz(-1),
// m_top_closed(false), m_bottom_closed(false),
// m_positions(position)
// {
// computeCenter();
// }
// /**
// * Polyhedron fusion: give a COMPOSED type
// * @param p1 first Polyhedron
// * @param p1 second Polyhedron
// */
// Polyhedron(const Polyhedron<PFP>& p1, const Polyhedron<PFP>& p2);
// /*
// * get the reference dart
// */
// Dart getDart() { return m_dart; }
// /*
// * get the center of Polyhedron
// */
// const typename PFP::VEC3& getCenter() { return m_center; }
// /**
// * get the table of darts (one per vertex)
// */
// std::vector<Dart>& getVertexDarts() { return m_tableVertDarts; }
// /**
// * Create a 2D grid
// * quads are oriented counter-clockwise and the returned dart
// * is the lower left dart (upper right it is symetric)
// * @param x nb of quads in x
// * @param y nb of quads in y
// * @return the dart
// */
// Dart grid_topo(unsigned int x, unsigned int y);
// /**
// * Create a subdivided (surface) cylinder
// * @param n nb of quads around circunference
// * @param z nb of quads in height
// * @param top_closed close the top with triangles fan
// * @param bottom_closed close the bottom with triangles fan
// * @return the dart
// */
// Dart cylinder_topo(unsigned int n, unsigned int z, bool top_closed, bool bottom_closed);
// /**
// * Create a subdivided (surface) cone (with param 1,3,true create tetrahedron)
// * @param n nb of quads around circunference (must be >=3)
// * @param z nb of quads in height (must be >=1)
// * @param bottom_closed close the bottom with triangles fan
// * @return the dart
// */
// Dart cone_topo(unsigned int n, unsigned int z, bool bottom_closed);
// /**
// * Create a subdived (surface) cube
// * quads are oriented counter-clockwise
// * @param x nb of quads in x
// * @param y nb of quads in y
// * @param z nb of quads in z
// * @return the dart
// */
// Dart cube_topo(unsigned int x, unsigned int y, unsigned int z);
// /**
// * Create a subdivided (surface) cylinder