diff --git a/Apps/Tuto/show_traversors.cpp b/Apps/Tuto/show_traversors.cpp index c6c872f87a1468dc5ab2d823a522c7e28cc85268..5bb8f85603cda8c1c5a1352ee921b2dfaa7bce79 100644 --- a/Apps/Tuto/show_traversors.cpp +++ b/Apps/Tuto/show_traversors.cpp @@ -163,15 +163,15 @@ void MyQT::cb_Save() Utils::SVG::SVGOut svg1(modelViewMatrix(), projectionMatrix()); m_drawer.toSVG(svg1); - svg1.addOpacityAnimation(1.0f); - svg1.addOpacityAnimation(1.0f); - svg1.addOpacityAnimation(0.0f); +// svg1.addOpacityAnimation(1.0f); +// svg1.addOpacityAnimation(1.0f); +// svg1.addOpacityAnimation(0.0f); Utils::SVG::SVGOut svg2(modelViewMatrix(), projectionMatrix()); m_render_topo->toSVG(svg2); - svg2.addOpacityAnimation(1.0f); - svg2.addOpacityAnimation(0.0f); - svg2.addOpacityAnimation(1.0f); +// svg2.addOpacityAnimation(1.0f); +// svg2.addOpacityAnimation(0.0f); +// svg2.addOpacityAnimation(1.0f); Utils::SVG::AnimatedSVGOut anim; diff --git a/Apps/Tuto/tuto5.cpp b/Apps/Tuto/tuto5.cpp index fd6d2828103b21df529dd194c932254cc80c9d18..aec212820723cd4e567da76cc02ed20bf2a2c4a5 100644 --- a/Apps/Tuto/tuto5.cpp +++ b/Apps/Tuto/tuto5.cpp @@ -237,13 +237,13 @@ void MyQT::cb_keyPress(int code) { std::string filename = selectFileSave("Export SVG file ",".","(*.svg)"); Utils::SVG::SVGOut svg(filename, modelViewMatrix(), projectionMatrix()); - svg.setWidth(1.0f); - svg.setColor(Geom::Vec3f(0.0f,0.0f,0.5f)); +// svg.setWidth(1.0f); +// svg.setColor(Geom::Vec3f(0.0f,0.0f,0.5f)); Algo::Render::SVG::renderEdges(svg, myMap, position); - svg.setColor(Geom::Vec3f(0.0f,0.8f,0.0f)); - svg.setWidth(5.0f); +// svg.setColor(Geom::Vec3f(0.0f,0.8f,0.0f)); +// svg.setWidth(5.0f); Algo::Render::SVG::renderVertices(svg, myMap, position); - svg.setColor(Geom::Vec3f(1.0f,0.0f,0.0f)); + // svg.setColor(Geom::Vec3f(1.0f,0.0f,0.0f)); m_strings->toSVG(svg); //svg destruction close the file } diff --git a/Apps/Tuto/tuto_oper3.cpp b/Apps/Tuto/tuto_oper3.cpp index c80aca2c7a485d77b99138575afc7af60eb723b9..af43ad884f1789435ce3024c5a619b3bd353dea8 100644 --- a/Apps/Tuto/tuto_oper3.cpp +++ b/Apps/Tuto/tuto_oper3.cpp @@ -235,6 +235,16 @@ void MyQT::operation(int x) std::cout << "nb darts after = " << myMap.getNbDarts() << std::endl; } break; + case 11 : + CGoGNout <<"unsew volumes"<splitVertex + + + unsewVolumes + + diff --git a/SCHNApps/CMakeLists.txt b/SCHNApps/CMakeLists.txt index 80660f48b17be73afaa25029bafba22e9839981b..5f59a3b746f6773f6e32896f8aaf65ba06a0d9ac 100644 --- a/SCHNApps/CMakeLists.txt +++ b/SCHNApps/CMakeLists.txt @@ -134,6 +134,7 @@ SET(SCHNApps_QOBJECT_FILES ${SCHNApps_ROOT_DIR}/include/dialogs/cameraViewDialog.h ${SCHNApps_ROOT_DIR}/include/dialogs/pluginsViewDialog.h ${SCHNApps_ROOT_DIR}/include/dialogs/mapsViewDialog.h + ${SCHNApps_ROOT_DIR}/include/colorComboBox.h ) diff --git a/SCHNApps/Plugins/renderTopoSurface/forms/renderTopoSurface.ui b/SCHNApps/Plugins/renderTopoSurface/forms/renderTopoSurface.ui index db0935f60614eaf0c3beb6fad814ac2b8e79eaa0..e8fd2906ea6f8521f14a8f6ce0d3f13626f2c801 100644 --- a/SCHNApps/Plugins/renderTopoSurface/forms/renderTopoSurface.ui +++ b/SCHNApps/Plugins/renderTopoSurface/forms/renderTopoSurface.ui @@ -6,14 +6,14 @@ 0 0 - 204 + 206 547 Form - + @@ -55,8 +55,14 @@ + + 100 + - 50 + 100 + + + 100 Qt::Horizontal @@ -72,9 +78,15 @@ - + 50 + + 100 + + + 100 + Qt::Horizontal @@ -83,6 +95,68 @@ + + + + + + + + draw darts + + + true + + + false + + + + + + + + 0 + 0 + + + + + + + + draw phi1 + + + true + + + false + + + + + + + + + + draw phi2 + + + true + + + false + + + + + + + + + Qt::Vertical @@ -97,6 +171,13 @@ + + + ColorComboBox + QComboBox +
colorComboBox.h
+
+
diff --git a/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurface.cpp b/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurface.cpp index 9c9d00237c2c44fa3e5dd4658336439c578da221..acee8b390de9dab1c3cc07e2b7cefa9e290e825a 100644 --- a/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurface.cpp +++ b/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurface.cpp @@ -215,7 +215,8 @@ void RenderTopoSurfacePlugin::changeEdgesScaleFactor(View* view, MapHandlerGen* { ParameterSet* params = h_viewParams[view]; PerMapParameterSet* perMap = params->perMap[map->getName()]; - perMap->edgesScaleFactor = i / 50.0; + perMap->edgesScaleFactor = i / 100.0; + std::cout << "i = " << perMap->edgesScaleFactor << std::endl; perMap->updateRender(); if(view->isCurrentView()) @@ -230,7 +231,7 @@ void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* { ParameterSet* params = h_viewParams[view]; PerMapParameterSet* perMap = params->perMap[map->getName()]; - perMap->facesScaleFactor = i / 50.0; + perMap->facesScaleFactor = i / 100.0; perMap->updateRender(); if(view->isCurrentView()) @@ -243,7 +244,21 @@ void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* void RenderTopoSurfacePlugin::attributeModified(unsigned int orbit, QString nameAttr) { - +// if(orbit == VERTEX) +// { +// MapHandlerGen* map = static_cast(QObject::sender()); +// if(h_viewParams.contains(map->getName())) +// { +// ParameterSet* params = h_viewParams[view]; +// +// if(params->perMap.contains(map->getName())) +// PerMapParameterSet* perMap = params->perMap[map->getName()]; +// perMap->updateRender(); +// +// //if(params.positionName == nameAttr && params.autoUpdate) +// // computeNormal(map->getName(), params.positionName, params.normalName); +// } +// } } void RenderTopoSurfacePlugin::connectivityModified() diff --git a/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurfaceDockTab.cpp b/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurfaceDockTab.cpp index dd98c265f81f262be348cda64a1a5b5c332d27ae..a11ee149cc3dfd18ee53572f1418c50e8f66c5a7 100644 --- a/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurfaceDockTab.cpp +++ b/SCHNApps/Plugins/renderTopoSurface/src/renderTopoSurfaceDockTab.cpp @@ -63,8 +63,8 @@ void RenderTopoSurfaceDockTab::refreshUI(ParameterSet* params) } } - slider_edgesScaleFactor->setSliderPosition(p->edgesScaleFactor * 50.0); - slider_facesScaleFactor->setSliderPosition(p->facesScaleFactor * 50.0); + slider_edgesScaleFactor->setSliderPosition(p->edgesScaleFactor * 100.0); + slider_facesScaleFactor->setSliderPosition(p->facesScaleFactor * 100.0); } ++i; } diff --git a/SCHNApps/bin/init.py b/SCHNApps/bin/init.py index f0a9dc7adc4a2fe3a053fd46f228d17011f5bc70..64d5a96428cd5b0b640eb5c17b8c7a7e56c49582 100644 --- a/SCHNApps/bin/init.py +++ b/SCHNApps/bin/init.py @@ -4,6 +4,7 @@ renderVectorPlugin = schnapps.loadPlugin("RenderVectorD"); differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties"); subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface"); surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation"); +renderTopoSurface = schnapps.loadPlugin("RenderTopoSurface"); obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/lowRes/iphi_good_9k.off"); @@ -12,6 +13,7 @@ v = schnapps.getView("view_0"); schnapps.linkViewAndPlugin(v.getName(), renderPlugin.getName()); schnapps.linkViewAndPlugin(v.getName(), renderVectorPlugin.getName()); schnapps.linkViewAndPlugin(v.getName(), surfaceDeformationPlugin.getName()); +schnapps.linkViewAndPlugin(v.getName(), renderTopoSurface.getName()); schnapps.linkViewAndMap(v.getName(), obj.getName()); diff --git a/SCHNApps/include/colorComboBox.h b/SCHNApps/include/colorComboBox.h new file mode 100644 index 0000000000000000000000000000000000000000..6d8da3967310f15b722be800fc03ce8426f7b9b9 --- /dev/null +++ b/SCHNApps/include/colorComboBox.h @@ -0,0 +1,28 @@ +#ifndef COLORCOMBOBOX_H +#define COLORCOMBOBOX_H + +#include + +class QColor; +class QWidget; + +class ColorComboBox : public QComboBox +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor USER true) + +public: + QColor color() const; + void setColor(QColor c); + +public: + ColorComboBox(QWidget *widget = 0); + +private: + void populateList(); + +public slots: + void slotHighlight(int index); +}; + +#endif diff --git a/SCHNApps/src/colorComboBox.cpp b/SCHNApps/src/colorComboBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94feec1672c673c1d85caf47ef283d887d8cf921 --- /dev/null +++ b/SCHNApps/src/colorComboBox.cpp @@ -0,0 +1,43 @@ +#include + +#include "colorComboBox.h" + +ColorComboBox::ColorComboBox(QWidget *widget) : QComboBox(widget) +{ + //connect( this, SIGNAL(highlighted(int)), this, SLOT(slotHighlight(int)) ); + populateList(); +} + +QColor ColorComboBox::color() const +{ + return qvariant_cast(itemData(currentIndex(), Qt::DecorationRole)); +} + +void ColorComboBox::setColor(QColor color) +{ + setCurrentIndex(findData(color, int(Qt::DecorationRole))); +} + +void ColorComboBox::populateList() +{ + //QStringList colorNames = QColor::colorNames(); + QStringList colorNames; + colorNames <<"darkGreen"<<"green"<<"gray"<<"red"<<"white"<<"blue"<<"cyan"<<"darkMagenta"<<"yellow"<<"darkRed"<<"black"<<"magenta"; + + for (int i = 0; i < colorNames.size(); ++i) { + QColor color(colorNames[i]); + + insertItem(i, colorNames[i]); + setItemData(i, color, Qt::DecorationRole); + } +} + +void ColorComboBox::slotHighlight(int index) +{ + const QStringList colorNames = QColor::colorNames(); + QColor color(colorNames.at(index)); + + QPalette palette = this->palette(); + palette.setColor(QPalette::Highlight, color); + setPalette(palette); +} diff --git a/include/Algo/Render/SVG/mapSVGRender.hpp b/include/Algo/Render/SVG/mapSVGRender.hpp index f5b6ac9b666c8b8639dd09402c2c90eb52f31980..8d8f27e0dc5943af6e696afa4b03a1f5d964e434 100644 --- a/include/Algo/Render/SVG/mapSVGRender.hpp +++ b/include/Algo/Render/SVG/mapSVGRender.hpp @@ -37,41 +37,49 @@ namespace SVG template void renderVertices(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const VertexAttribute& position, unsigned int thread) { + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("vertices", svg.m_model, svg.m_proj); TraversorV trac(map); - svg.beginPoints(); + svg1->beginPoints(); for (Dart d = trac.begin(); d != trac.end(); d = trac.next()) - svg.addPoint(position[d]); - svg.endPoints(); + svg1->addPoint(position[d]); + svg1->endPoints(); + svg.addGroup(svg1); } template void renderVertices(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const VertexAttribute& position, const VertexAttribute& color, unsigned int thread) { + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("vertices", svg.m_model, svg.m_proj); TraversorV trac(map); - svg.beginPoints(); + svg1->beginPoints(); for (Dart d = trac.begin(); d != trac.end(); d = trac.next()) - svg.addPoint(position[d], color[d]); - svg.endPoints(); + svg1->addPoint(position[d], color[d]); + svg1->endPoints(); + svg.addGroup(svg1); } template void renderEdges(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const VertexAttribute& position, unsigned int thread) { + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("edges", svg.m_model, svg.m_proj); TraversorE trac(map); - svg.beginLines(); + svg1->beginLines(); for (Dart d = trac.begin(); d != trac.end(); d = trac.next()) - svg.addLine(position[d], position[map.phi1(d)]); - svg.endLines(); + svg1->addLine(position[d], position[map.phi1(d)]); + svg1->endLines(); + svg.addGroup(svg1); } template void renderEdges(Utils::SVG::SVGOut& svg, typename PFP::MAP& map, const VertexAttribute& position, const VertexAttribute& color, unsigned int thread) { + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("edges", svg.m_model, svg.m_proj); TraversorE trac(map); - svg.beginLines(); + svg1->beginLines(); for (Dart d = trac.begin(); d != trac.end(); d = trac.next()) - svg.addLine(position[d], position[map.phi1(d)], color[d]); - svg.endLines(); + svg1->addLine(position[d], position[map.phi1(d)], color[d]); + svg1->endLines(); + svg.addGroup(svg1); } } // namespace SVG diff --git a/include/Utils/svg.h b/include/Utils/svg.h index 102203eefc200173e6457fed970d612eb7f7d19c..7b6043076ba289aa222a40219591bda06194f71e 100644 --- a/include/Utils/svg.h +++ b/include/Utils/svg.h @@ -157,13 +157,11 @@ public: class AnimatedSVGOut; -class SVGOut +class SvgGroup { - friend class AnimatedSVGOut; - -protected: - std::ofstream* m_out; +public: + std::string m_name; const glm::mat4& m_model; const glm::mat4& m_proj; glm::i32vec4 m_viewport; @@ -176,15 +174,9 @@ protected: std::vector m_opacities_animations; - unsigned int m_bbX0; - unsigned int m_bbY0; - unsigned int m_bbX1; - unsigned int m_bbY1; - + bool m_isLayer; -protected: - void computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsigned& d); public: @@ -194,7 +186,7 @@ public: * @param model the modelview matrix * @param proj the projection matrix */ - SVGOut(const std::string& filename, const glm::mat4& model, const glm::mat4& proj); + SvgGroup(const std::string& name, const glm::mat4& model, const glm::mat4& proj); /** * Object that allow the rendering/exporting in svg file @@ -202,19 +194,18 @@ public: * @param model the modelview matrix * @param proj the projection matrix */ - SVGOut(const glm::mat4& model, const glm::mat4& proj); + //SvgGroup(const glm::mat4& model, const glm::mat4& proj); /** * destructor * flush and close the file */ - ~SVGOut(); + ~SvgGroup(); void setColor(const Geom::Vec3f& col); void setWidth(float w); - void closeFile(); void beginPoints(); void endPoints(); @@ -234,15 +225,63 @@ public: 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& vds); void addOpacityAnimation(float val) { m_opacities_animations.push_back(val);} void clearpacityAnimation() { m_opacities_animations.clear();} - static void animateSVG(const std::string& filename, const std::vector& outs, float timestep); + void setToLayer() { m_isLayer = true; } + //static void animateSVG(const std::string& filename, const std::vector& outs, float timestep); }; + +class SVGOut +{ +public: + std::ofstream* m_out; + + const glm::mat4& m_model; + const glm::mat4& m_proj; + glm::i32vec4 m_viewport; + + std::vector m_groups; + + 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); + +public: + + /** + * Object that allow the rendering/exporting in svg file + * @param filename file name ended by .svg + * @param model the modelview matrix + * @param proj the projection matrix + */ + SVGOut(const std::string& filename, const glm::mat4& model, const glm::mat4& proj); + + /** + * Object that allow the rendering/exporting in svg file + * no file parameter for use in animateSVG + * @param model the modelview matrix + * @param proj the projection matrix + */ + SVGOut(const glm::mat4& model, const glm::mat4& proj); + + ~SVGOut(); + + void addGroup(SvgGroup* group) { m_groups.push_back(group); } + + void write(); +}; + + class AnimatedSVGOut { protected: diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp index 8940d5359e0cb5d35741e6462f04c6b3c5330c49..4746743556b2bcee94701a12f53b3e0a0cf1346e 100644 --- a/src/Algo/Render/topo3Render.cpp +++ b/src/Algo/Render/topo3Render.cpp @@ -384,71 +384,82 @@ void Topo3Render::svgout2D(const std::string& filename, const glm::mat4& model, void Topo3Render::toSVG(Utils::SVG::SVGOut& svg) { - svg.setWidth(m_topo_relation_width); // PHI3 / beta3 - + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi3", svg.m_model, svg.m_proj); const Geom::Vec3f* ptr = reinterpret_cast(m_vbo3->lockPtr()); - - svg.beginLines(); + svg1->setWidth(m_topo_relation_width); + svg1->beginLines(); for (unsigned int i=0; iaddLine(P, Q,Geom::Vec3f(0.8f,0.8f,0.0f)); } - svg.endLines(); + svg1->endLines(); m_vbo3->releasePtr(); + svg.addGroup(svg1); // PHI2 / beta2 - + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); ptr = reinterpret_cast(m_vbo2->lockPtr()); - - svg.beginLines(); + svg2->setWidth(m_topo_relation_width); + svg2->beginLines(); for (unsigned int i=0; iaddLine(P, Q,Geom::Vec3f(0.8f,0.0f,0.0f)); } - svg.endLines(); + svg2->endLines(); m_vbo2->releasePtr(); + svg.addGroup(svg2); + //PHI1 /beta1 + Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); ptr = reinterpret_cast(m_vbo1->lockPtr()); - - svg.beginLines(); + svg3->setWidth(m_topo_relation_width); + svg3->beginLines(); for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); + svg3->endLines(); m_vbo1->releasePtr(); + svg.addGroup(svg3); const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo4->lockPtr()); ptr= reinterpret_cast(m_vbo0->lockPtr()); - svg.setWidth(m_topo_dart_width); + Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); + svg4->setWidth(m_topo_dart_width); - svg.beginLines(); + svg4->beginLines(); for (unsigned int i=0; i2.9f) col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg.addLine(ptr[2*i], ptr[2*i+1], col); + svg4->addLine(ptr[2*i], ptr[2*i+1], col); } - svg.endLines(); + svg4->endLines(); - svg.beginPoints(); + svg.addGroup(svg4); + + Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); + svg5->setWidth(m_topo_dart_width); + svg5->beginPoints(); for (unsigned int i=0; i2.9f) col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg.addPoint(ptr[2*i], col); + svg5->addPoint(ptr[2*i], col); } - svg.endPoints(); + svg5->endPoints(); + + svg.addGroup(svg5); m_vbo0->releasePtr(); m_vbo4->releasePtr(); diff --git a/src/Algo/Render/topoRender.cpp b/src/Algo/Render/topoRender.cpp index 126e184bf54c88a8b99dc8683e838cd0a32794f0..c27d706e16e1cd4e935f5bac284b8a8dd172cf23 100644 --- a/src/Algo/Render/topoRender.cpp +++ b/src/Algo/Render/topoRender.cpp @@ -297,48 +297,97 @@ void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, c { Utils::SVG::SVGOut svg(filename,model,proj); toSVG(svg); + svg.write(); } void TopoRender::toSVG(Utils::SVG::SVGOut& svg) { - svg.setWidth(m_topo_relation_width); +// svg.setWidth(m_topo_relation_width); +// +// // PHI2 / beta2 +// const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); +// svg.beginLines(); +// for (unsigned int i=0; ireleasePtr(); +// +// //PHI1 /beta1 +// ptr = reinterpret_cast(m_vbo1->lockPtr()); +// svg.beginLines(); +// for (unsigned int i=0; ireleasePtr(); +// +// +// const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); +// ptr= reinterpret_cast(m_vbo0->lockPtr()); +// +// svg.setWidth(m_topo_dart_width); +// svg.beginLines(); +// for (unsigned int i=0; ireleasePtr(); +// m_vbo3->releasePtr(); - // PHI2 / beta2 + // PHI2 / beta2 + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); + svg1->setToLayer(); const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); - - svg.beginLines(); + svg1->setWidth(m_topo_relation_width); + svg1->beginLines(); for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.8f,0.0f,0.0f)); + svg1->endLines(); m_vbo2->releasePtr(); + svg.addGroup(svg1); + //PHI1 /beta1 + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); + svg2->setToLayer(); ptr = reinterpret_cast(m_vbo1->lockPtr()); - - svg.beginLines(); + svg2->setWidth(m_topo_relation_width); + svg2->beginLines(); for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); + svg2->endLines(); m_vbo1->releasePtr(); + svg.addGroup(svg2); const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); ptr= reinterpret_cast(m_vbo0->lockPtr()); - svg.setWidth(m_topo_dart_width); - - svg.beginLines(); + Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); + svg3->setToLayer(); + svg3->setWidth(m_topo_dart_width); + svg3->beginLines(); for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1], colorsPtr[2*i]); + svg3->endLines(); - svg.beginPoints(); + svg.addGroup(svg3); + + Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); + svg4->setWidth(m_topo_dart_width); + svg4->setToLayer(); + svg4->beginPoints(); for (unsigned int i=0; iaddPoint(ptr[2*i], colorsPtr[2*i]); + svg4->endPoints(); + + svg.addGroup(svg4); m_vbo0->releasePtr(); m_vbo3->releasePtr(); diff --git a/src/Utils/drawer.cpp b/src/Utils/drawer.cpp index 0bac97cccd13bb6c5ac162578fb55e5f7aaa5f66..b1229486a7976d421c392accf0929dc860101d97 100644 --- a/src/Utils/drawer.cpp +++ b/src/Utils/drawer.cpp @@ -261,63 +261,73 @@ void Drawer::toSVG(Utils::SVG::SVGOut& svg) const Geom::Vec3f* ptrP = reinterpret_cast(m_vboPos->lockPtr()); const Geom::Vec3f* ptrC = reinterpret_cast(m_vboCol->lockPtr()); + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("points", svg.m_model, svg.m_proj); + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("lines", svg.m_model, svg.m_proj); + Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("faces", svg.m_model, svg.m_proj); + for (std::vector::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp) { - svg.setWidth(pp->width); + svg1->setWidth(pp->width); if (pp->mode == GL_POINTS) { unsigned int end = pp->begin + pp->nb; - svg.beginPoints(); + svg1->beginPoints(); for (unsigned int i=pp->begin; iaddPoint(ptrP[i], ptrC[i]); + svg1->endPoints(); } + svg2->setWidth(pp->width); if (pp->mode == GL_LINES) { unsigned int end = pp->begin + pp->nb; - svg.beginLines(); + svg2->beginLines(); for (unsigned int i=pp->begin; iaddLine(ptrP[i], ptrP[i+1], ptrC[i]); + svg2->endLines(); } + svg3->setWidth(pp->width); if ((pp->mode == GL_LINE_LOOP) || (pp->mode == GL_POLYGON)) { unsigned int end = pp->begin + pp->nb-1; - svg.beginLines(); + svg3->beginLines(); for (unsigned int i=pp->begin; i<=end; ++i) - svg.addLine(ptrP[i], ptrP[i+1], ptrC[i]); - svg.addLine(ptrP[end], ptrP[pp->begin], ptrC[end]); - svg.endLines(); + svg3->addLine(ptrP[i], ptrP[i+1], ptrC[i]); + svg3->addLine(ptrP[end], ptrP[pp->begin], ptrC[end]); + svg3->endLines(); } if (pp->mode == GL_TRIANGLES) { unsigned int end = pp->begin + pp->nb; - svg.beginLines(); + svg3->beginLines(); for (unsigned int i=pp->begin; iaddLine(ptrP[i], ptrP[i+1], ptrC[i]); + svg3->addLine(ptrP[i+1], ptrP[i+2], ptrC[i+1]); + svg3->addLine(ptrP[i+2], ptrP[i], ptrC[i+2]); } - svg.endLines(); + svg3->endLines(); } if (pp->mode == GL_QUADS) { unsigned int end = pp->begin + pp->nb; - svg.beginLines(); + svg3->beginLines(); for (unsigned int i=pp->begin; iaddLine(ptrP[i], ptrP[i+1], ptrC[i]); + svg3->addLine(ptrP[i+1], ptrP[i+2], ptrC[i+1]); + svg3->addLine(ptrP[i+2], ptrP[i+3], ptrC[i+2]); + svg3->addLine(ptrP[i+3], ptrP[i], ptrC[i+3]); } - svg.endLines(); + svg3->endLines(); } } + svg.addGroup(svg1); + svg.addGroup(svg2); + svg.addGroup(svg3); + m_vboPos->releasePtr(); m_vboCol->releasePtr(); } diff --git a/src/Utils/svg.cpp b/src/Utils/svg.cpp index aea98aff6f0245a936c667fdf726f35e451a589b..cd98771dbbdff4e5dbc5eb03fadb3df07e69010e 100644 --- a/src/Utils/svg.cpp +++ b/src/Utils/svg.cpp @@ -362,147 +362,80 @@ void SvgStrings::fillDS(std::vector& vds, unsigned int idObj) const // //} +//void SvgLayers::save(std::ofstream& out) const +//{ +// saveOne(out,0,0); +//} +// +//void SvgLayers::saveOne(std::ofstream& out, unsigned int i, unsigned int bbl) const +//{ +// if(m_end) +// { +// out << "" << std::endl; +// } +// else +// { +// out << "" << std::endl; +// } +//} - -SVGOut::SVGOut(const std::string& filename, const glm::mat4& model, const glm::mat4& proj): - m_model(model),m_proj(proj),global_color(Geom::Vec3f(0.0f,0.0f,0.0f)), global_width(2.0f) +SvgGroup::SvgGroup(const std::string& name, const glm::mat4& model, const glm::mat4& proj): + m_name(name), m_model(model),m_proj(proj),global_color(Geom::Vec3f(0.0f,0.0f,0.0f)), global_width(2.0f), m_isLayer(false) { m_objs.reserve(1000); - - m_out = new std::ofstream(filename.c_str()) ; - if (!m_out->good()) - { - CGoGNerr << "Unable to open file " << CGoGNendl ; - // ???? - } - glGetIntegerv(GL_VIEWPORT, &(m_viewport[0])); } -SVGOut::SVGOut(const glm::mat4& model, const glm::mat4& proj): - m_model(model),m_proj(proj),global_color(Geom::Vec3f(0.0f,0.0f,0.0f)), global_width(2.0f) -{ - m_objs.reserve(1000); - - m_out = NULL; - - glGetIntegerv(GL_VIEWPORT, &(m_viewport[0])); -} +//SvgGroup::SvgGroup(const glm::mat4& model, const glm::mat4& proj): +// m_groupName(""), m_model(model),m_proj(proj),global_color(Geom::Vec3f(0.0f,0.0f,0.0f)), global_width(2.0f), m_isLayer(false) +//{ +// m_objs.reserve(1000); +// glGetIntegerv(GL_VIEWPORT, &(m_viewport[0])); +//} -SVGOut::~SVGOut() +SvgGroup::~SvgGroup() { - if (m_out && (m_out->good())) - { - closeFile(); - } - delete m_out; - for (std::vector::iterator it = m_objs.begin(); it != m_objs.end(); ++it) delete (*it); } -void SVGOut::setColor(const Geom::Vec3f& col) +void SvgGroup::setColor(const Geom::Vec3f& col) { global_color = col; } -void SVGOut::setWidth(float w) +void SvgGroup::setWidth(float w) { global_width = w; } -void SVGOut::closeFile() -{ - m_bbX0 = 100000; - m_bbY0 = 100000; - m_bbX1 = 0; - m_bbY1 = 0; - computeBB(m_bbX0, m_bbY0, m_bbX1, m_bbY1); - - *m_out << ""<< std::endl; - *m_out << ""<< std::endl; - *m_out << "test"<< std::endl; - *m_out << ""<< std::endl; - *m_out << "Rendered from CGoGN"<< std::endl; - - *m_out << ""<< std::endl; - *m_out << ""<< std::endl; - *m_out << ""<< std::endl; - *m_out << "" << std::endl; - - std::vector vds; - sortSimpleDepth(vds); - - - for (std::vector::iterator it = vds.begin(); it != vds.end(); ++it) - { - m_objs[it->obj]->saveOne(*m_out,it->id, m_bbX1-m_bbX0); - } - - - *m_out << "" << std::endl; - *m_out << "" << std::endl; - m_out->close(); -} - - -void SVGOut::computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsigned& d) -{ - - for (std::vector::iterator it = m_objs.begin(); it != m_objs.end(); ++it) - { - const std::vector& vert = (*it)->vertices(); - for (std::vector::const_iterator j = vert.begin(); j != vert.end(); ++j) - { - const Geom::Vec3f& P = *j; - if (P[0]c) - c = (unsigned int)(P[0]); - if (P[1]>d) - d = (unsigned int)(P[1]); - } - - if (a>10) - a-=10; - if (b>10) - b-=10; - c+=10; - d+=10; - } -} - - - -void SVGOut::beginPoints() +void SvgGroup::beginPoints() { m_current = new SvgPoints(); m_current->setColor(global_color); m_current->setWidth(global_width); } -void SVGOut::endPoints() +void SvgGroup::endPoints() { m_objs.push_back(m_current); m_current = NULL; } -void SVGOut::addPoint(const Geom::Vec3f& P) +void SvgGroup::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]))); } -void SVGOut::addPoint(const Geom::Vec3f& P, const Geom::Vec3f& C) +void SvgGroup::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); @@ -510,7 +443,7 @@ void SVGOut::addPoint(const Geom::Vec3f& P, const Geom::Vec3f& C) } -void SVGOut::beginLines() +void SvgGroup::beginLines() { m_current = new SvgLines(); m_current->setColor(global_color); @@ -518,13 +451,13 @@ void SVGOut::beginLines() } -void SVGOut::endLines() +void SvgGroup::endLines() { m_objs.push_back(m_current); m_current = NULL; } -void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2) +void SvgGroup::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2) { 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); @@ -536,9 +469,7 @@ void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2) m_current->addVertex(Geom::Vec3f(float(Q2[0]),float(m_viewport[3])-float(Q2[1]),float(Q2[2]))); } - - -void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, const Geom::Vec3f& C) +void SvgGroup::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, 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); @@ -550,35 +481,33 @@ void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, const Geom::Ve m_current->addVertex(Geom::Vec3f(float(Q2[0]),float(m_viewport[3])-float(Q2[1]),float(Q2[2])),C); } - -void SVGOut::beginStrings(float scalefactor) +void SvgGroup::beginStrings(float scalefactor) { m_current = new SvgStrings(scalefactor); m_current->setColor(global_color); m_current->setWidth(global_width); } -void SVGOut::endStrings() +void SvgGroup::endStrings() { m_objs.push_back(m_current); m_current = NULL; } -void SVGOut::addString(const Geom::Vec3f& P, const std::string& str) +void SvgGroup::addString(const Geom::Vec3f& P, const std::string& str) { glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); m_current->addString(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])), str); } -void SVGOut::addString(const Geom::Vec3f& P, const std::string& str, const Geom::Vec3f& C) +void SvgGroup::addString(const Geom::Vec3f& P, const std::string& str, const Geom::Vec3f& C) { glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport); m_current->addString(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])), str, C); } - -void SVGOut::sortSimpleDepth(std::vector& vds) +void SvgGroup::sortSimpleDepth(std::vector& vds) { unsigned int nb=0; for (std::vector::iterator it = m_objs.begin(); it != m_objs.end(); ++it) @@ -594,74 +523,190 @@ void SVGOut::sortSimpleDepth(std::vector& vds) } +SVGOut::SVGOut(const std::string& filename, const glm::mat4& model, const glm::mat4& proj): + m_model(model),m_proj(proj) +{ + m_groups.reserve(1000); + m_out = new std::ofstream(filename.c_str()) ; + if (!m_out->good()) + { + CGoGNerr << "Unable to open file " << CGoGNendl ; + } - - -void AnimatedSVGOut::add(SVGOut* svg) -{ - m_svgs.push_back(svg); + glGetIntegerv(GL_VIEWPORT, &(m_viewport[0])); } -void AnimatedSVGOut::write(const std::string& filename, float timeStep) +SVGOut::SVGOut(const glm::mat4& model, const glm::mat4& proj): + m_model(model),m_proj(proj) { - std::ofstream outfile(filename.c_str()) ; - - unsigned int bbX0=1000000; - unsigned int bbY0=1000000; - unsigned int bbX1=0; - unsigned int bbY1=0; + m_groups.reserve(1000); - for (unsigned int i=0; i< m_svgs.size(); ++i) - m_svgs[i]->computeBB(bbX0, bbY0, bbX1, bbY1); + m_out = NULL; - outfile << ""<< std::endl; - outfile << ""<< std::endl; - outfile << "Animated SVG"<< std::endl; - outfile << ""<< std::endl; - outfile << "Rendered from CGoGN"<< std::endl; - outfile << ""<< std::endl; + glGetIntegerv(GL_VIEWPORT, &(m_viewport[0])); +} - outfile << ""<< std::endl; +SVGOut::~SVGOut() +{ + delete m_out; + for (std::vector::iterator it = m_groups.begin(); it != m_groups.end(); ++it) + delete (*it); +} - for (unsigned int i=0; i< m_svgs.size(); ++i) +void SVGOut::computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsigned& d) +{ + for (std::vector::iterator it = m_groups.begin(); it != m_groups.end(); ++it) { - std::vector vds; - m_svgs[i]->sortSimpleDepth(vds); + const std::vector& objs = (*it)->m_objs; - outfile << "" << std::endl; - for (std::vector::iterator it = vds.begin(); it != vds.end(); ++it) - m_svgs[i]->m_objs[it->obj]->saveOne(outfile,it->id, bbX1-bbX0); - outfile << "" << std::endl; + for (std::vector::const_iterator ito = objs.begin(); ito != objs.end(); ++ito) + { + const std::vector& vert = (*ito)->vertices(); + for (std::vector::const_iterator j = vert.begin(); j != vert.end(); ++j) + { + const Geom::Vec3f& P = *j; + if (P[0]c) + c = (unsigned int)(P[0]); + if (P[1]>d) + d = (unsigned int)(P[1]); + } + + if (a>10) + a-=10; + if (b>10) + b-=10; + c+=10; + d+=10; + } } +} - outfile << ""<< std::endl; +void SVGOut::write() +{ + m_bbX0 = 100000; + m_bbY0 = 100000; + m_bbX1 = 0; + m_bbY1 = 0; + computeBB(m_bbX0, m_bbY0, m_bbX1, m_bbY1); + + *m_out << ""<< std::endl; + *m_out << ""<< std::endl; + *m_out << "test"<< std::endl; + *m_out << ""<< std::endl; + *m_out << "Rendered from CGoGN"<< std::endl; - for (unsigned int i=0; i< m_svgs.size(); ++i) + *m_out << ""<< std::endl; + *m_out << ""<< std::endl; + *m_out << ""<< std::endl; + //*m_out << "" << std::endl; + + for(std::vector::iterator it = m_groups.begin() ; it != m_groups.end() ; ++it) { - unsigned int nbo = m_svgs[i]->m_opacities_animations.size(); + if((*it)->m_isLayer) + { + *m_out << "m_name << "\"" << std::endl; + *m_out << "inkscape:label=\"" << (*it)->m_name << "\">" << std::endl; - outfile << "" << std::endl; - outfile << "m_name << "\">" << std::endl; + } + + std::vector vds; + (*it)->sortSimpleDepth(vds); - for (unsigned int j = 0; j < nbo; ++j) + for (std::vector::iterator itd = vds.begin(); itd != vds.end(); ++itd) { - outfile << m_svgs[i]->m_opacities_animations[j]; - if ( j != (nbo-1)) - outfile<< ";"; + (*it)->m_objs[itd->obj]->saveOne(*m_out,itd->id, m_bbX1-m_bbX0); } - outfile << "\" calcMode=\"discrete\" repeatCount=\"indefinite\" />" << std::endl; - outfile << "" << std::endl; + *m_out << "" << std::endl; } - outfile << "" << std::endl; - outfile.close(); + //*m_out << "" << std::endl; + *m_out << "" << std::endl; + m_out->close(); +} + + + +void AnimatedSVGOut::add(SVGOut* svg) +{ + m_svgs.push_back(svg); +} + +void AnimatedSVGOut::write(const std::string& filename, float timeStep) +{ +// std::ofstream outfile(filename.c_str()) ; +// +// unsigned int bbX0=1000000; +// unsigned int bbY0=1000000; +// unsigned int bbX1=0; +// unsigned int bbY1=0; +// +// for (unsigned int i=0; i< m_svgs.size(); ++i) +// m_svgs[i]->computeBB(bbX0, bbY0, bbX1, bbY1); +// +// outfile << ""<< std::endl; +// outfile << ""<< std::endl; +// outfile << "Animated SVG"<< std::endl; +// outfile << ""<< std::endl; +// outfile << "Rendered from CGoGN"<< std::endl; +// outfile << ""<< std::endl; +// +// outfile << ""<< std::endl; +// +// +// for (unsigned int i=0; i< m_svgs.size(); ++i) +// { +// std::vector vds; +// m_svgs[i]->sortSimpleDepth(vds); +// +// outfile << "" << std::endl; +// for (std::vector::iterator it = vds.begin(); it != vds.end(); ++it) +// m_svgs[i]->m_objs[it->obj]->saveOne(outfile,it->id, bbX1-bbX0); +// outfile << "" << std::endl; +// } +// +// outfile << ""<< std::endl; +// +// +// for (unsigned int i=0; i< m_svgs.size(); ++i) +// { +// unsigned int nbo = m_svgs[i]->m_opacities_animations.size(); +// +// outfile << "" << std::endl; +// outfile << "m_opacities_animations[j]; +// if ( j != (nbo-1)) +// outfile<< ";"; +// } +// +// outfile << "\" calcMode=\"discrete\" repeatCount=\"indefinite\" />" << std::endl; +// outfile << "" << std::endl; +// } +// +// outfile << "" << std::endl; +// outfile.close(); } diff --git a/src/Utils/text3d.cpp b/src/Utils/text3d.cpp index 12ef70c99815848560d02ac85062dc50cc5adb85..680b40b6c95e036a8e5c2bf3b50e560bbcedfdac 100644 --- a/src/Utils/text3d.cpp +++ b/src/Utils/text3d.cpp @@ -344,11 +344,14 @@ void Strings3D::updateString(unsigned int idSt, const std::string& str) void Strings3D::toSVG(Utils::SVG::SVGOut& svg) { - svg.beginStrings(m_scale); + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("strings3D", svg.m_model, svg.m_proj); + svg1->beginStrings(m_scale); unsigned int nb = m_strings.size(); for(unsigned int i=0; iaddString(m_strTranslate[i],m_strings[i]); + svg1->endStrings(); + + svg.addGroup(svg1); } } // namespace Utils