Commit 588b0692 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~thery/CGoGN

parents 797c28a9 8bfd76d1
......@@ -249,8 +249,11 @@ void MyQT::cb_keyPress(int code)
svg.setWidth(1.0f);
svg.setColor(Geom::Vec3f(0.0f,0.0f,0.5f));
Algo::Render::SVG::renderEdges<PFP>(svg,myMap,position);
svg.setColor(Geom::Vec3f(0.0f,0.8f,0.0f));
svg.setWidth(5.0f);
Algo::Render::SVG::renderVertices<PFP>(svg,myMap,position);
svg.setColor(Geom::Vec3f(1.0f,0.0f,0.0f));
m_strings->toSVG(svg);
//svg destruction close the file
}
if (code == 't')
......@@ -333,6 +336,7 @@ int main(int argc, char **argv)
sqt.m_selected = myMap.begin();
sqt.setGeometry(100,100,1024,1024);
sqt.show();
sqt.slider_balls(50);
......
......@@ -26,6 +26,9 @@
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Geometry/centroid.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
using namespace CGoGN ;
......@@ -164,14 +167,10 @@ void MyQT::createMap(int n)
grid.grid_topo(n,n);
grid.embedGrid(1.,1.,0.);
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
// send BB info to interface for centering on GL screen
setParamObject(lWidthObj, lPosObj.data());
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f;
// first show for be sure that GL context is binded
show();
......@@ -296,6 +295,30 @@ void MyQT::cb_keyPress(int keycode)
}
}
break;
case Qt::Key_Up:
if (m_selected!=NIL)
position[m_selected][1] +=m_shift;
updateMap();
updateGL();
break;
case Qt::Key_Down:
if (m_selected!=NIL)
position[m_selected][1] -= m_shift;
updateMap();
updateGL();
break;
case Qt::Key_Left:
if (m_selected!=NIL)
position[m_selected][0] -= m_shift;
updateMap();
updateGL();
break;
case Qt::Key_Right:
if (m_selected!=NIL)
position[m_selected][0] += m_shift;
updateMap();
updateGL();
break;
}
updateGL();
}
......@@ -306,6 +329,74 @@ void MyQT::svg()
m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix());
}
void MyQT::cb_Open()
{
std::string filters("all (*.*);; trian (*.trian);; off (*.off);; ply (*.ply);; map (*.map)") ;
std::string filename = selectFile("Open Mesh", "", filters) ;
if (!filename.empty())
importMesh(filename);
updateGL();
}
void MyQT::cb_Save()
{
std::string filename = selectFileSave("Export SVG file ",".","(*.off)");
Algo::Export::exportOFF<PFP>(myMap,position,filename.c_str());
}
void MyQT::importMesh(std::string& filename)
{
myMap.clear(true) ;
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
if (extension == std::string(".map"))
{
myMap.loadMapBin(filename);
position = myMap.getAttribute<PFP::VEC3>(VERTEX, "position") ;
}
else
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ;
}
colorDarts = myMap.getAttribute<PFP::VEC3>(DART, "color");
if (!colorDarts.isValid())
{
colorDarts = myMap.addAttribute<PFP::VEC3>(DART, "color");
for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
{
if (dm.isMarked(d) && (!myMap.isBoundaryMarked(d)))
{
int n = random();
float r = float(n&0x7f)/255.0f + 0.25f;
float g = float((n>>8)&0x7f)/255.0f + 0.25f;
float b = float((n>>16)&0x7f)/255.0 + 0.25f;
colorDarts[d] = Geom::Vec3f(r,g,b);
m_render_topo->setDartColor(d,r,g,b);
}
}
}
m_selected = NIL;
m_selected2 = NIL;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f;
updateMap();
updateGLMatrices() ;
}
void MyQT::width(int w)
{
m_render_topo->setDartWidth(w);
......
......@@ -67,12 +67,14 @@ class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap) {}
MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f) {}
void cb_redraw();
void cb_initGL();
void cb_mousePress(int button, int x, int y);
void cb_keyPress(int code);
void cb_Open();
void cb_Save();
Utils::QT::uiDockInterface dock;
......@@ -90,6 +92,7 @@ protected:
Dart m_selected;
Dart m_selected2;
DartMarker dm;
float m_shift;
// just for more compact writing
inline Dart PHI1(Dart d) {return myMap.phi1(d);}
......@@ -102,6 +105,7 @@ public:
// example of simple map creation
void createMap(int n);
void updateMap();
void importMesh(std::string& filename);
public slots:
void operation(int x);
......
......@@ -87,11 +87,11 @@ public:
Dart alpha_1(Dart d) ;
virtual Dart begin() ;
virtual Dart begin() const ;
virtual Dart end() ;
virtual Dart end() const ;
virtual Dart next(Dart& d) ;
virtual void next(Dart& d) const ;
virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ;
......
......@@ -139,7 +139,7 @@ inline Dart ImplicitHierarchicalMap::alpha_1(Dart d)
return Map2::alpha_1(d) ;
}
inline Dart ImplicitHierarchicalMap::begin()
inline Dart ImplicitHierarchicalMap::begin() const
{
Dart d = Map2::begin() ;
while(d != Map2::end() && m_dartLevel[d] > m_curLevel)
......@@ -147,18 +147,17 @@ inline Dart ImplicitHierarchicalMap::begin()
return d ;
}
inline Dart ImplicitHierarchicalMap::end()
inline Dart ImplicitHierarchicalMap::end() const
{
return Map2::end() ;
}
inline Dart ImplicitHierarchicalMap::next(Dart& d)
inline void ImplicitHierarchicalMap::next(Dart& d) const
{
do
{
Map2::next(d) ;
} while(d != Map2::end() && m_dartLevel[d] > m_curLevel) ;
return d;
}
inline bool ImplicitHierarchicalMap::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
......
......@@ -360,11 +360,11 @@ public:
*************************************************************************/
//@{
virtual Dart begin() ;
virtual Dart begin() const;
virtual Dart end() ;
virtual Dart end() const;
virtual Dart next(Dart& d) ;
virtual void next(Dart& d) const ;
virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ;
......
......@@ -200,7 +200,7 @@ inline Dart ImplicitHierarchicalMap3::alpha_2(Dart d)
return phi2(phi3(d));
}
inline Dart ImplicitHierarchicalMap3::begin()
inline Dart ImplicitHierarchicalMap3::begin() const
{
Dart d = Map3::begin() ;
while(m_dartLevel[d] > m_curLevel)
......@@ -208,18 +208,17 @@ inline Dart ImplicitHierarchicalMap3::begin()
return d ;
}
inline Dart ImplicitHierarchicalMap3::end()
inline Dart ImplicitHierarchicalMap3::end() const
{
return Map3::end() ;
}
inline Dart ImplicitHierarchicalMap3::next(Dart& d)
inline void ImplicitHierarchicalMap3::next(Dart& d) const
{
do
{
Map3::next(d) ;
} while(d != Map3::end() && m_dartLevel[d] > m_curLevel) ;
return d;
}
inline bool ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
......
......@@ -245,6 +245,14 @@ public:
void updateDataGMap(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts);
/**
* render to svg struct
*/
void toSVG(Utils::SVG::SVGOut& svg);
/**
* render svg into svg file
*/
void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
};
......
......@@ -189,7 +189,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC
*positionF1++ = fv1[d];
*positionF1++ = fv11[e];
}
m_nbRel1 = vecDarts.size()/2;
m_nbRel1 = vecDarts.size();
m_vbo1->bind();
glUnmapBuffer(GL_ARRAY_BUFFER);
......@@ -204,7 +204,7 @@ template<typename PFP>
//void TopoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good)
void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good)
{
GMap2& map = reinterpret_cast<GMap2&>(mapx);
GMap2& map = dynamic_cast<GMap2&>(mapx);
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
......
......@@ -53,9 +53,9 @@ namespace CGoGN
class MapBrowser
{
public:
virtual Dart begin() = 0;
virtual Dart end() = 0;
virtual Dart next(Dart& d) = 0;
virtual Dart begin() const = 0;
virtual Dart end() const = 0;
virtual void next(Dart& d) const = 0;
};
class AttributeHandlerGen ;
......@@ -259,7 +259,7 @@ public:
/**
* get the insertion level of a dart (use only in MRMaps)
*/
unsigned int getDartLevel(Dart d) ;
unsigned int getDartLevel(Dart d) const ;
/**
* get the number of darts inserted in the given leveldart (use only in MRMaps)
......@@ -526,20 +526,20 @@ public:
* Begin of map
* @return the first dart of the map
*/
Dart begin() ;
Dart begin() const;
/**
* End of map
* @return the end iterator (next of last) of the map
*/
Dart end() ;
Dart end() const;
/**
* allow to go from a dart to the next
* in the order of storage
* @param d reference to the dart to be modified
*/
Dart next(Dart& d) ;
void next(Dart& d) const ;
/**
* Apply a functor on each dart of the map
......
......@@ -194,7 +194,7 @@ inline unsigned int GenericMap::dartIndex(Dart d) const
return d.index;
}
inline unsigned int GenericMap::getDartLevel(Dart d)
inline unsigned int GenericMap::getDartLevel(Dart d) const
{
return (*m_mrLevels)[d.index] ;
}
......@@ -339,7 +339,7 @@ inline AttributeMultiVector<unsigned int>* GenericMap::getEmbeddingAttributeVect
* DARTS TRAVERSALS *
****************************************/
inline Dart GenericMap::begin()
inline Dart GenericMap::begin() const
{
if (m_isMultiRes)
{
......@@ -352,7 +352,7 @@ inline Dart GenericMap::begin()
return Dart::create(m_attribs[DART].begin()) ;
}
inline Dart GenericMap::end()
inline Dart GenericMap::end() const
{
if (m_isMultiRes)
return Dart::create(m_mrattribs.end()) ;
......@@ -360,7 +360,7 @@ inline Dart GenericMap::end()
return Dart::create(m_attribs[DART].end()) ;
}
inline Dart GenericMap::next(Dart& d)
inline void GenericMap::next(Dart& d) const
{
if (m_isMultiRes)
{
......@@ -371,7 +371,6 @@ inline Dart GenericMap::next(Dart& d)
}
else
m_attribs[DART].next(d.index) ;
return d;
}
/****************************************
......
......@@ -47,17 +47,17 @@ public:
m_map(m), m_selector(fs)
{}
Dart begin()
Dart begin() const
{
return m_map.begin() ;
}
Dart end()
Dart end() const
{
return m_map.end() ;
}
void next(Dart& d)
void next(Dart& d) const
{
do
{
......@@ -112,17 +112,17 @@ public:
m_end = NIL ;
}
Dart begin()
Dart begin() const
{
return m_first ;
}
Dart end()
Dart end() const
{
return NIL ;
}
void next(Dart& d)
void next(Dart& d) const
{
assert(d != NIL) ;
d = m_links[d] ;
......
......@@ -57,7 +57,7 @@ Dart TraversorCell<MAP>::begin()
current = m.begin() ;
while(current != m.end() && (m.isBoundaryMarked(current) || !m_good(current)))
current = m.next(current) ;
m.next(current) ;
if(current == m.end())
current = NIL ;
......@@ -92,7 +92,7 @@ Dart TraversorCell<MAP>::next()
while(current != NIL && (ismarked || m.isBoundaryMarked(current) || !m_good(current)))
{
current = m.next(current) ;
m.next(current) ;
if(current == m.end())
current = NIL ;
else
......
......@@ -200,6 +200,12 @@ public:
*/
void setFocal(float f) { m_glWidget->setFocal(f); }
/**
* set geometry (override buggy Qt function)
*/
void setGeometry(int x, int y, int w, int h);
/**
* get the mouse position in GL widget
*/
......
......@@ -28,6 +28,7 @@
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include "Geometry/vector_gen.h"
......@@ -48,11 +49,24 @@ namespace SVG
{
struct DepthSort
{
unsigned int obj;
unsigned int id;
float depth;
DepthSort(unsigned int o, unsigned int i, float d):
obj(o),id(i),depth(d) {}
bool operator<(const DepthSort& ds) const { return depth > ds.depth; /* inverse depth sortin*/}
};
class SvgObj
{
protected:
std::vector<Geom::Vec3f> m_vertices;
std::vector<Geom::Vec3f> m_colors;
std::vector<std::string> m_strings;
std::vector<Geom::Vec3f> m_vertices3D;
Geom::Vec3f m_color;
float m_width;
......@@ -67,16 +81,26 @@ public:
void addVertex3D(const Geom::Vec3f& v, const Geom::Vec3f& C);
void addString(const Geom::Vec3f& v, const std::string& str);
void addString(const Geom::Vec3f& v, const std::string& str, const Geom::Vec3f& C);
void setColor(const Geom::Vec3f& c);
void setWidth(float w);
void close();
virtual void save(std::ofstream& out)=0;
virtual void save(std::ofstream& out) const = 0;
virtual void saveOne(std::ofstream& out, unsigned int i, unsigned int bbl = 0) const = 0;
unsigned int nbv() const;
virtual unsigned int nbPrimtives() const = 0;
virtual void fillDS(std::vector<DepthSort>& vds, unsigned int idObj) const = 0;
const Geom::Vec3f& P(unsigned int i) const;
Geom::Vec3f normal();
......@@ -88,30 +112,50 @@ public:
class SvgPoints: public SvgObj
{
public:
void save(std::ofstream& out);
void save(std::ofstream& out) const;
void saveOne(std::ofstream& out, unsigned int i, unsigned int bbl = 0) const;
unsigned int nbPrimtives() const;
void fillDS(std::vector<DepthSort>& vds, unsigned int idObj) const;
};
class SvgLines: public SvgObj
{
public:
void save(std::ofstream& out);
void save(std::ofstream& out) const;
void saveOne(std::ofstream& out, unsigned int i, unsigned int bbl = 0) const;
unsigned int nbPrimtives() const;
void fillDS(std::vector<DepthSort>& vds, unsigned int idObj) const;
};
class SvgPolyline: public SvgObj
{
public:
void save(std::ofstream& out);
};
class SvgPolygon: public SvgObj
class SvgStrings: public SvgObj
{
protected:
Geom::Vec3f m_colorFill;
float m_sf;
public:
void setColorFill(const Geom::Vec3f& c);
void save(std::ofstream& out);
SvgStrings(float scalefactor = 1.0f) : m_sf(scalefactor) {}
void save(std::ofstream& out) const;
void saveOne(std::ofstream& out, unsigned int i, unsigned int bbl = 0) const;
unsigned int nbPrimtives() const;
void fillDS(std::vector<DepthSort>& vds, unsigned int idObj) const;
};
//class SvgPolyline: public SvgObj
//{
//public:
// void save(std::ofstream& out);
//};
//
//class SvgPolygon: public SvgObj
//{
//protected:
// Geom::Vec3f m_colorFill;
//public:
// void setColorFill(const Geom::Vec3f& c);
// void save(std::ofstream& out);
//};
class SVGOut
......@@ -129,6 +173,14 @@ protected:
std::vector<SvgObj*> m_objs;
SvgObj* m_current;
unsigned int m_bbX0;
unsigned int m_bbY0;
unsigned int m_bbX1;
unsigned int m_bbY1;
protected:
void computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsigned& d);
......@@ -165,6 +217,15 @@ public:
void addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2);
void addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, const Geom::Vec3f& C);
void beginStrings(float scalefactor = 1.0f);
void endStrings();
void addString(const Geom::Vec3f& P, const std::string& str);
void addString(const Geom::Vec3f& P, const Geom::Vec3f& Q, const std::string& str);
void addString(const Geom::Vec3f& P, const std::string& str, const Geom::Vec3f& C);
void sortSimpleDepth( std::vector<DepthSort>& vds);
};
......
......@@ -28,10 +28,10 @@
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } }
namespace CGoGN
{
namespace Utils
{
......@@ -67,6 +67,8 @@ protected:
Utils::VBO* m_vbo1;
float m_scale;
unsigned int sendOneStringToVBO(const std::string& str, float **buffer);
GLuint m_uniform_texture;
......@@ -137,6 +139,8 @@ public:
*/
void setScale(float scale);
void toSVG(Utils::SVG::SVGOut& svg);
};
} // namespace Utils
......
......@@ -284,7 +284,11 @@ void TopoRender::popColors()
void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj)
{
Utils::SVG::SVGOut svg(filename,model,proj);
toSVG(svg);
}
void TopoRender::toSVG(Utils::SVG::SVGOut& svg)
{
svg.setWidth(m_topo_relation_width);
// PHI2 / beta2
......@@ -293,7 +297,7 @@ void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, c
svg.beginLines();
for (unsigned int i=0; i<m_nbRel2; ++i)
svg.addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(1.0f,0.0f,0.0f));
svg.addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.8f,0.0f,0.0f));
svg.endLines();
m_vbo2->releasePtr();
......@@ -303,7 +307,7 @@ void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, c
svg.beginLines();
for (unsigned int i=0; i<m_nbRel1; ++i)
svg.addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,1.0f,1.0f));
svg.addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f));
svg.endLines();
m_vbo1->releasePtr();
......@@ -329,6 +333,7 @@ void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, c
}
}//end namespace GL2
}//end namespace Render
......
......@@ -520,6 +520,12 @@ void SimpleQT::snapshot(const QString& filename)
im.save(filename);
}
void SimpleQT::setGeometry(int x, int y, int w, int h)
{
move(x,y);
resize(w,h);
}
} // namespace QT
} // namespace Utils
......
......@@ -211,6 +211,7 @@ void GLWidget::mousePressEvent(QMouseEvent* event)
if (m_cbs)
m_cbs->cb_mousePress(event->button(), event->x(), getHeight() - event->y()); </