Commit 8bfd76d1 authored by Sylvain Thery's avatar Sylvain Thery

small bug in svg render topo

parent 60b3b83a
......@@ -336,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);
......
......@@ -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;
......
......@@ -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
......
......@@ -206,25 +206,7 @@ void SvgLines::save(std::ofstream& out) const
unsigned int nb = m_vertices.size()/2;
for (unsigned int i=0; i<nb; ++i)
{
saveOne(out,i);
// out << "<polyline fill=\"none\" stroke=\"#";
// out << std::hex;
// unsigned int wp = out.width(2);
// char prev = out.fill('0');
// out << int(m_colors[i][0]*255);
// out.width(2); out.fill('0');
// out<< int(m_colors[i][1]*255);
// out.width(2); out.fill('0');
// out << int(m_colors[i][2]*255)<<std::dec;
// out <<"\" stroke-width=\""<<m_width<<"\" points=\"";
// out.fill(prev);
// out.width(wp);
// out << m_vertices[i][0] << ","<< m_vertices[i][1]<< " ";
// i++;
// out << m_vertices[i][0] << ","<< m_vertices[i][1];
// out <<"\"/>"<< std::endl;
}
}
void SvgLines::saveOne(std::ofstream& out, unsigned int i, unsigned int bbl) const
......@@ -235,11 +217,11 @@ void SvgLines::saveOne(std::ofstream& out, unsigned int i, unsigned int bbl) con
out << std::hex;
unsigned int wp = out.width(2);
char prev = out.fill('0');
out << int(m_colors[i][0]*255);
out << int(m_colors[2*i][0]*255);
out.width(2); out.fill('0');
out<< int(m_colors[i][1]*255);
out<< int(m_colors[2*i][1]*255);
out.width(2); out.fill('0');
out << int(m_colors[i][2]*255)<<std::dec;
out << int(m_colors[2*i][2]*255)<<std::dec;
out <<"\" stroke-width=\""<<m_width<<"\" points=\"";
out.fill(prev);
out.width(wp);
......@@ -525,24 +507,18 @@ void SVGOut::addPoint(const Geom::Vec3f& P)
glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport);
glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport);
m_current->addVertex(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])));
// m_current->addVertex3D(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2]));
}
void SVGOut::addPoint(const Geom::Vec3f& P, const Geom::Vec3f& C)
{
glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport);
glm::vec3 R = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,glm::mat4(1.0),m_viewport);
// m_current->addVertex(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2]),C);
m_current->addVertex(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])),C);
// m_current->addVertex3D(Geom::Vec3f(Q[0],float(m_viewport[3])-Q[1],Q[2]),C);
}
void SVGOut::beginLines()
{
// glm::i32vec4 viewport;
// glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
m_current = new SvgLines();
m_current->setColor(global_color);
m_current->setWidth(global_width);
......@@ -565,9 +541,6 @@ void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2)
m_current->addVertex(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])));
m_current->addVertex(Geom::Vec3f(float(Q2[0]),float(m_viewport[3])-float(Q2[1]),float(Q2[2])));
// m_current->addVertex3D(Geom::Vec3f(R[0],float(m_viewport[3])-R[1],R[2]));
// m_current->addVertex3D(Geom::Vec3f(R2[0],float(m_viewport[3])-R2[1],R2[2]));
}
......@@ -582,9 +555,6 @@ void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, const Geom::Ve
m_current->addVertex(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])),C);
m_current->addVertex(Geom::Vec3f(float(Q2[0]),float(m_viewport[3])-float(Q2[1]),float(Q2[2])),C);
// m_current->addVertex3D(Geom::Vec3f(R[0],float(m_viewport[3])-R[1],R[2]),C);
// m_current->addVertex3D(Geom::Vec3f(R2[0],float(m_viewport[3])-R2[1],R2[2]),C);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment