Commit 81c34b08 authored by untereiner's avatar untereiner

Merge cgogn:~jund/CGoGN

parents f6a8a6a8 4e3c81e2
......@@ -54,6 +54,11 @@ add_executable( texturesExampleD ../texturesExample.cpp ${texturesExample_moc} )
target_link_libraries( texturesExampleD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(simpleGMap2_moc ../simpleGMap2.h)
add_executable( simpleGMap2D ../simpleGMap2.cpp ${simpleGMap2_moc} )
target_link_libraries( simpleGMap2D
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h)
add_executable( extrusionViewD ../extrusionView.cpp ${extrusionView_moc})
target_link_libraries( extrusionViewD
......
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <iostream>
#include "Utils/qtSimple.h"
#include "Topology/generic/parameters.h"
#include "Topology/gmap/gmap2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Algo/Render/GL1/topo_render.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2<GMap2> MAP ;
};
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3 ;
class SimpleGMap2 : public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MAP myMap ;
SelectorTrue allDarts ;
PFP::TVEC3 position ;
SimpleGMap2() ;
void initGUI() ;
void cb_initGL() ;
void cb_redraw() ;
};
......@@ -31,6 +31,7 @@
#include "Topology/generic/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/boundingbox.h"
......
......@@ -144,8 +144,8 @@ int main(int argc, char **argv)
/// on reprend la carte de tuto1
Dart d2 = myMap.newOrientedFace(3);
Dart d3 = myMap.newOrientedFace(4);
Dart d2 = myMap.newFace(3);
Dart d3 = myMap.newFace(4);
myMap.sewFaces(d2, d3);
position = myMap.addAttribute<Geom::Vec3f>(VERTEX, "position");
......
......@@ -109,8 +109,8 @@ int main(int argc, char **argv)
PFP::TVEC3 normal ;
AttributeHandler<Geom::Vec3f> color ;
Dart d2 = myMap.newOrientedFace(3);
Dart d3 = myMap.newOrientedFace(4);
Dart d2 = myMap.newFace(3);
Dart d3 = myMap.newFace(4);
myMap.sewFaces(d2,d3);
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
......@@ -203,7 +203,7 @@ int main(int argc, char **argv)
PFP::TVEC3 position2 ;
AttributeHandler<Geom::Vec3f> color2 ;
Dart dx = myMap2.newOrientedFace(4);
Dart dx = myMap2.newFace(4);
position2 = myMap2.addAttribute<PFP::VEC3>(VERTEX, "position");
color2 = myMap2.addAttribute<PFP::VEC3>(VERTEX, "couleur");
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __SUBDIVISION3MAP_H__
#define __SUBDIVISION3MAP_H__
#include <math.h>
#include <vector>
namespace CGoGN
{
namespace Algo
{
namespace Modelisation
{
/**
* Cut a 3D ear from a mesh : the ear is sewn by phi3 to the rest of the volume
* @param d dart of the point of the ear
* @return a dart from the new face connecting the ear and the rest of the volume
*/
template <typename PFP>
Dart cut3Ear(typename PFP::MAP& map, Dart d);
/**
* subdivide a hexahedron into 5 tetrahedron
* @param d dart of the hexahedron
*/
template <typename PFP>
void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d);
/**
* catmull clark volumic : do not move the original vertices
* @param map the map
* @param attributs geometric attributes of the vertices
* @param selected a functor to select volumes to subdivide
* TODO : test if it works for the functorselect
*/
template <typename PFP, typename EMBV, typename EMB>
void catmullClarkVol(typename PFP::MAP& map, EMBV& attributs, const FunctorSelect& selected= SelectorTrue());
template <typename PFP>
void catmullClarkVol(typename PFP::MAP& map, typename PFP::TVEC3& position, const FunctorSelect& selected= SelectorTrue())
{
catmullClarkVol<PFP,typename PFP::TVEC3, typename PFP::VEC3>(map, position, selected);
}
} // namespace Modelisation
} // namespace Algo
} // namespace CGoGN
#include "Algo/Modelisation/subdivision3map.hpp"
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Algo/Geometry/centroid.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Modelisation/extrusion.h"
namespace CGoGN
{
namespace Algo
{
namespace Modelisation
{
template <typename PFP>
Dart cut3Ear(typename PFP::MAP& map, Dart d)
{
Dart e=d;
int nb=0;
Dart dNew;
Dart dRing;
Dart dRing2;
//count the valence of the vertex
do
{
nb++;
e=map.phi1(map.phi2(e));
} while (e!=d);
if(nb<3)
{
CGoGNout << "Warning : cannot cut 2 volumes without creating a degenerated face " << CGoGNendl;
return d;
}
else
{
//triangulate around the vertex
do
{
Dart dN = map.phi1(map.phi2(e));
if(map.template phi<111>(e)!=e)
map.splitFace(map.phi_1(e), map.phi1(e));
dRing = map.phi1(e);
dRing2 = map.phi2(dRing);
map.unsewFaces(dRing);
e= dN;
} while (e!=d);
map.closeHole(dRing);
map.closeHole(dRing2);
map.sewVolumes(map.phi2(dRing),map.phi2(dRing2));
}
return map.phi2(dRing);
}
template <typename PFP>
void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d)
{
Dart d1 = d;
Dart d2 = map.phi1(map.phi1(d));
Dart d3 = map.phi_1(map.phi2(d));
Dart d4 = map.phi1(map.phi1(map.phi2(map.phi_1(d3))));
cut3Ear<PFP>(map,d1);
cut3Ear<PFP>(map,d2);
cut3Ear<PFP>(map,d3);
cut3Ear<PFP>(map,d4);
}
template <typename PFP, typename EMBV, typename EMB>
void catmullClarkVol(typename PFP::MAP& map, EMBV& attributs, const FunctorSelect& selected)
{
std::vector<Dart> l_centers;
std::vector<Dart> l_vertices;
DartMarkerNoUnmark mv(map);
CellMarkerNoUnmark me(map, EDGE);
CellMarker mf(map, FACE);
AutoAttributeHandler< EMB > attBary(map,VOLUME);
CellMarker vol(map,VOLUME);
//pre-computation : compute the centroid of all volume
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if(selected(d) && !vol.isMarked(d))
{
vol.mark(d);
attBary[d] = Algo::Geometry::volumeCentroidGen<PFP,EMBV,EMB>(map,d,attributs);
}
}
// mv.unmarkAll();
// first pass: cut edges
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
//memorize each vertices per volumes
if(selected(d) && !mv.isMarked(d))
{
l_vertices.push_back(d);
Dart dd = d;
do {
mv.mark(dd);
dd = map.phi1(map.phi2(dd));
} while(dd!=d);
}
//cut edges
if (selected(d) && !me.isMarked(d))
{
std::cout << "edge to cut " << d << std::endl;
std::cout << "edge degree " << map.edgeDegree(d) << std::endl;
Dart f = map.phi1(d);
map.cutEdge(d);
Dart e = map.phi1(d) ;
std::cout << "cut cut cut " << std::endl;
attributs[e] = attributs[d];
attributs[e] += attributs[f];
attributs[e] *= 0.5;
me.mark(d);
me.mark(e);
//mark new vertices
mv.markOrbit(VERTEX, e);
Dart dd = d;
do
{
mf.mark(dd) ;
mf.mark(map.phi2(dd));
dd = map.alpha2(dd);
} while(dd != d);
}
}
std::cout << "edge cut" << std::endl;
// second pass: quandrangule faces
std::map<Dart,Dart> toSew;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
mv.unmark(d);
if (selected(d) && mf.isMarked(d)) // for each face not subdivided
{
mf.unmark(d);
// compute center skip darts of new vertices non embedded
EMB center = AttribOps::zero<EMB,PFP>();
unsigned int count = 0 ;
Dart it = d;
do
{
me.unmark(it);
me.unmark(map.phi1(it));
center += attributs[it];
++count ;
it = map.template phi<11>(it) ;
} while(it != d) ;
center /= double(count);
Dart cf = quadranguleFace<PFP>(map, d); // quadrangule the face
attributs[cf] = center; // affect the data to the central vertex
}
}
std::cout << "nb vertices " << l_vertices.size() << std::endl;
//third pass : create the inner faces
for (std::vector<Dart>::iterator it = l_vertices.begin(); it != l_vertices.end(); ++it)
{
Dart d = *it;
//unsew all around the vertex
//there are 2 links to unsew for each face around (-> quadrangulation)
do
{
Dart dN = map.phi1(map.phi2(d));
Dart dRing = map.phi1(d);
if(map.phi2(dRing)!=dRing)
{
toSew.insert(std::pair<Dart,Dart>(dRing,map.phi2(dRing)));
map.unsewFaces(dRing);
}
dRing = map.phi1(dRing);
if(map.phi2(dRing)!=dRing)
{
toSew.insert(std::pair<Dart,Dart>(dRing,map.phi2(dRing)));
map.unsewFaces(dRing);
}
d= dN;
} while (*it!=d);
//close the generated hole and create the central vertex
unsigned int degree = map.closeHole(map.phi1(d));
Dart dd = map.phi1(map.phi2(map.phi1(d)));
map.splitFace(map.phi_1(dd),map.phi1(dd));
Dart dS = map.phi1(dd);
map.cutEdge(dS);
attributs[map.phi1(dS)] = attBary[d];
//TODO : test with vertices with degree higher than 3
for(unsigned int i=0; i < (degree/2)-2; ++i)
{
map.splitFace(map.phi2(dS),map.template phi<111>(map.phi2(dS)));
dS = map.template phi<111>(map.phi2(dS));
}
}
//sew all faces leading to the central vertex
for (std::map<Dart,Dart>::iterator it = toSew.begin(); it != toSew.end(); ++it)
{
Dart dT = map.phi2(it->first);
if(dT==map.phi3(dT))
{
map.sewVolumes(dT,map.phi2(it->second));
}
}
}
} //namespace Modelisation
} //namespace Algo
} //namespace CGoGN
......@@ -59,7 +59,7 @@ namespace GL1
* @param drawPhi1 draw the phi1 relation ?
* @param drawPhi2 draw the phi2 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
*/
template <typename PFP>
......@@ -74,15 +74,43 @@ void renderTopoMD2(typename PFP::MAP& the_map, const typename PFP::TVEC3& positi
* @param drawPhi2 draw the phi2 relation ?
* @param drawPhi3 draw the phi3 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for edge (1.0 normal draw)
* @param kv exploding coefficient for volumes (0.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
* @param kv exploding coefficient for volumes (1.0 normal draw)
*/
template <typename PFP>
void renderTopoMD3(typename PFP::MAP& the_map, const typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv, FunctorType& good);
void renderTopoMD3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv, FunctorType& good);
template <typename PFP>
void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv);
/**
* Render darts of g-map
*
* @param the_map map to render
* @param drawPhi1 draw the beta1 relation ?
* @param drawPhi2 draw the beta2 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
*/
template <typename PFP>
void renderTopoGMD2(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawBeta0, bool drawBeta1, bool drawBeta2, float ke, float kf);
/**
* Render darts of g-map
*
* @param the_map map to render
* @param drawPhi1 draw the beta1 relation ?
* @param drawPhi2 draw the beta2 relation ?
* @param drawPhi3 draw the beta3 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
* @param kv exploding coefficient for volumes (1.0 normal draw)
*/
template <typename PFP>
void renderTopoGMD3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawBeta0, bool drawBeta1, bool drawBeta2, bool drawBeta3, float kd, float ke, float kf, float kv);
} // namespace GL1
} // namespace Render
......
......@@ -479,14 +479,12 @@ void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
AutoAttributeHandler<Geom::Vec3f> fv1(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv11(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv2(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv2x(map, DART);
AutoAttributeHandler<Geom::Vec3f> vert(map, DART);
int m_nbDarts = 0;
// table of center of volume
......@@ -642,6 +640,307 @@ void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool
}
template <typename PFP>
void renderTopoGMD2(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawBeta0, bool drawBeta1, bool drawBeta2, float kd, float ke, float kf)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
AutoAttributeHandler<Geom::Vec3f> posBeta1(map, DART);
AutoAttributeHandler<Geom::Vec3f> posBeta2(map, DART);
AutoAttributeHandler<Geom::Vec3f> vert(map, DART);
glLineWidth(2.0f);
glColor3f(0.9f,0.9f,0.9f);
glBegin(GL_LINES);
DartMarker mf(map);
//draw all darts and potentially all beta0
for(Dart d = map.begin(); d!= map.end(); map.next(d))
{
if (!mf.isMarked(d))
{
std::vector<VEC3> vecPos;
vecPos.reserve(32);
// store the face & center
VEC3 center(0);
Dart dd = d;
do
{
const VEC3& P = positions[dd];
vecPos.push_back(positions[dd]);
center += P;
dd = map.phi1(dd);
} while (dd!=d);
center /= REAL(vecPos.size());
//shrink the face
unsigned int nb = vecPos.size();
float k = 1.0f - kf;
for (unsigned int i=0; i<nb; ++i)
vecPos[i] = center*k + vecPos[i]*kf;
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
k = 1.0f - ke;
for (unsigned int i=0; i<nb; ++i)
{
VEC3 P = vecPos[i]*ke + vecPos[i+1]*k;
VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k;
VEC3 P_mid = P+(Q-P)*kd*0.5f;
VEC3 Q_mid = Q+(P-Q)*kd*0.5f;
glVertex3fv(P.data());
glVertex3fv(P_mid.data());
if(drawBeta0)
{
glColor3f(0.0f,0.0f,1.0f);
glVertex3fv(P_mid.data());
glVertex3fv(Q_mid.data());
}
glColor3f(0.9f,0.9f,0.9f);
glVertex3fv(Q.data());
glVertex3fv(Q_mid.data());
vert[d] = P;
posBeta2[d] = P*0.5f + P_mid*0.5f;
posBeta2[map.beta0(d)] = Q*0.5f + Q_mid*0.5f;
posBeta1[d] = P*0.9f + P_mid*0.1f;
posBeta1[map.beta0(d)] = Q*0.9f + Q_mid*0.1f;
d = map.phi1(d);
}
mf.markOrbit(FACE, d);
}
}
//draw links beta 1 and beta 2
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
Dart e = map.beta2(d);
if (drawBeta2)
{
glColor3f(1.0,0.0,0.0);
glVertex3fv(posBeta2[d].data());
glVertex3fv(posBeta2[e].data());
}
e = map.beta1(d);
if ((d<e) && drawBeta1)
{
glColor3f(0.0f,1.0f,1.0f);
glVertex3fv(posBeta1[d].data());
glVertex3fv(posBeta1[e].data());
}
}
glEnd(); // LINES
//draw vertices
glPointSize(5.0f);
glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_POINTS);
for(Dart d = map.begin(); d!= map.end(); map.next(d))
{
glVertex3fv(vert[d].data());
}
glEnd();
}
template <typename PFP>
void renderTopoGMD3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawBeta0, bool drawBeta1, bool drawBeta2, bool drawBeta3, float kd, float ke, float kf, float kv)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;