diff --git a/Apps/Tuto/tuto_oper2.cpp b/Apps/Tuto/tuto_oper2.cpp index b596a6fa168419ddc3d8aca4b79830a7b86e25fd..10be95efceff872d232c617b0f5f7943e503f7d3 100644 --- a/Apps/Tuto/tuto_oper2.cpp +++ b/Apps/Tuto/tuto_oper2.cpp @@ -149,6 +149,17 @@ void MyQT::operation(int x) m_selected=NIL; } break; + case 9: + CGoGNout <<"delete face"<setDartColor(m_selected,0.8f,0.0f,0.0f); + if (m_selected2!=NIL) + m_render_topo->setDartColor(m_selected2,0.0f,0.8f,0.0f); + std::string filename = selectFileSave("snapshot file", ".", "(*.svg)"); m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix()); } diff --git a/Apps/Tuto/tuto_oper2.ui b/Apps/Tuto/tuto_oper2.ui index 341fc335c41247016adbb23e6438e14eebb7a3fb..043b923abdb58aaf77193aceef41bc22241bd3e5 100644 --- a/Apps/Tuto/tuto_oper2.ui +++ b/Apps/Tuto/tuto_oper2.ui @@ -94,6 +94,11 @@ mergeFace + + + deleteFace + + diff --git a/include/Algo/Decimation/basic.h b/include/Algo/Decimation/basic.h deleted file mode 100644 index 34d69a5a75a34970ac52b24c06171e332b4654ea..0000000000000000000000000000000000000000 --- a/include/Algo/Decimation/basic.h +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, 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.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#ifndef __DECIMATION_BASIC_H_ -#define __DECIMATION_BASIC_H_ - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Decimation -{ - -template -bool edgeCanCollapse(typename PFP::MAP& map, Dart d, AttributeHandler& valences) -{ - Dart dd = map.phi2(d); - Dart dp = map.phi_1(d); - Dart ddp = map.phi_1(dd); - - // Check valency conditions - - unsigned int val_vd = valences[d]; - unsigned int val_vdd = valences[dd]; - unsigned int val_vd1 = valences[dp]; - unsigned int val_vdd1 = valences[ddp]; - - if(val_vd + val_vdd < 8 || val_vd + val_vdd > 11 || val_vd1 < 5 || val_vdd1 < 5) - return false; - - // Check vertex sharing condition - - unsigned int vu1[32]; // pas de vector mais un tableau (find a la main, mais pas d'allocation par reserve) - val_vd -= 3; // evite le -3 dans la boucle - val_vdd -= 3; - Dart vit1 = map.phi2_1(map.phi2_1(d)); - - for (unsigned int i = 0; i< val_vd; ++i) - { - unsigned int ve = map.getEmbedding(map.phi2(vit1),VERTEX); - vu1[i] = ve; - vit1 = map.phi2_1(vit1); - } - - val_vd--; // pour le parcours avec while >=0 - - Dart vit2 = map.phi2_1(map.phi2_1(dd)); - for (unsigned int i = 0; i< val_vdd; ++i) - { - unsigned int ve = map.getEmbedding(map.phi2(vit2),VERTEX); - - int j = val_vd; - while ( j>=0) - { - if (vu1[j] == ve) - return false; - --j; - } - vit2 = map.phi2_1(vit2); - } - - return true; -} - -template -bool edgeCanCollapse(typename PFP::MAP& map, Dart d) -{ - Dart dd = map.phi2(d); - Dart dp = map.phi_1(d); - Dart ddp = map.phi_1(dd); - - // Check valency conditions - - int val_vd = 0 ; - Dart tmp = d ; - do { ++val_vd ; tmp = map.phi2_1(tmp) ; } while(tmp != d) ; - int val_vdd = 0 ; - tmp = dd ; - do { ++val_vdd ; tmp = map.phi2_1(tmp) ; } while(tmp != dd) ; - int val_vdp = 0 ; - tmp = dp ; - do { ++val_vdp ; tmp = map.phi2_1(tmp) ; } while(tmp != dp) ; - int val_vddp = 0 ; - tmp = ddp ; - do { ++val_vddp ; tmp = map.phi2_1(tmp) ; } while(tmp != ddp) ; - - if(val_vd + val_vdd < 8 || val_vd + val_vdd > 11 || val_vdp < 5 || val_vddp < 5) - return false; - - // Check vertex sharing condition - - unsigned int vu1[32]; // pas de vector mais un tableau (find a la main, mais pas d'allocation par reserve) - val_vd -= 3; // evite le -3 dans la boucle - val_vdd -= 3; - Dart vit1 = map.phi2_1(map.phi2_1(d)); - - for (int i = 0; i < val_vd; ++i) - { - unsigned int ve = map.getEmbedding(map.phi2(vit1),VERTEX); - vu1[i] = ve; - vit1 = map.phi2_1(vit1); - } - - val_vd--; // pour le parcours avec while >=0 - - Dart vit2 = map.phi2_1(map.phi2_1(dd)); - for (int i = 0; i < val_vdd; ++i) - { - unsigned int ve = map.getEmbedding(map.phi2(vit2),VERTEX); - - int j = val_vd; - while (j >= 0) - { - if (vu1[j] == ve) - return false; - --j; - } - vit2 = map.phi2_1(vit2); - } - - return true; -} - -} // namespace Decimation - -} // namespace Algo - -} // namespace CGoGN - -#endif diff --git a/include/Algo/MC/image.h b/include/Algo/MC/image.h index e6dc231254165f00e2b630298a9d934e087efcf4..9c0e8f276b50cd832181ce3cf996b1f026309cb3 100644 --- a/include/Algo/MC/image.h +++ b/include/Algo/MC/image.h @@ -30,7 +30,9 @@ #include "Utils/img3D_IO.h" +#ifdef WITH_ZINRI #include "Zinrimage.h" +#endif namespace CGoGN { @@ -121,11 +123,12 @@ protected: */ //bool correct(const gmtl::Vec3i& _V); +#ifdef WITH_ZINRI /** * internal inrimage prt */ PTRINRIMAGE mImage; - +#endif public: diff --git a/include/Algo/MC/image.hpp b/include/Algo/MC/image.hpp index 03541b15f6370a743383602983c08ca1e1ca891d..a0d7898a9bb4a14e047e90f932503f871b25da76 100644 --- a/include/Algo/MC/image.hpp +++ b/include/Algo/MC/image.hpp @@ -29,9 +29,6 @@ #include #include -#include "Utils/img3D_IO.h" -#include "Zinrimage.h" - namespace CGoGN { @@ -177,6 +174,7 @@ void Image::loadVox(char *filename) m_Alloc=true; } +#ifdef WITH_QT template< typename DataType > bool Image::loadPNG3D(const char* filename) { @@ -199,8 +197,9 @@ bool Image::loadPNG3D(const char* filename) return true; } +#endif - +#ifdef WITH_ZINRI template< typename DataType > bool Image::loadInrgz(const char* filename) { @@ -230,7 +229,7 @@ bool Image::loadInrgz(const char* filename) return true; } - +#endif @@ -472,9 +471,52 @@ Image* Image::Blur3() return newImg; } +//template +//void Image::createMaskOffsetSphere(std::vector& table, int _i32radius) +//{ +// // compute the width of the sphere for memory allocation +// int i32Width = 2*_i32radius + 1; +// // squared radius +// float fRad2 = (float)(_i32radius*_i32radius); +// +// // memory allocation +// // difficult to know how many voxels before computing, +// // so the reserve for the BB +// table.reserve(i32Width*i32Width*i32Width); +// table.clear(); +// +// // scan all the BB of the sphere +// for (int z = -_i32radius; z<=_i32radius; z++) +// { +// for (int y = -_i32radius; y<=_i32radius; y++) +// { +// for (int x = -_i32radius; x<=_i32radius; x++) +// { +// Geom::Vec3f v((float)x,(float)y,(float)z); +// float fLength = v.norm2(); +// // if inside the sphere +// if (fLength<=fRad2) +// { +// // the the index of the voxel +// int index = z * m_WXY + y * m_WX + x; +// table.push_back(index); +// } +// } +// } +// } +//} + + template void Image::createMaskOffsetSphere(std::vector& table, int _i32radius) { + float smin = std::min(m_SX, std::min(m_SY,m_SZ)); + + float xs = m_SX/smin; + float ys = m_SY/smin; + float zs = m_SZ/smin; + + // compute the width of the sphere for memory allocation int i32Width = 2*_i32radius + 1; // squared radius @@ -493,7 +535,7 @@ void Image::createMaskOffsetSphere(std::vector& table, int _i32ra { for (int x = -_i32radius; x<=_i32radius; x++) { - Geom::Vec3f v((float)x,(float)y,(float)z); + Geom::Vec3f v(float(x)*xs,float(y)*ys,float(z)*zs); float fLength = v.norm2(); // if inside the sphere if (fLength<=fRad2) @@ -507,6 +549,7 @@ void Image::createMaskOffsetSphere(std::vector& table, int _i32ra } } + template float Image::computeCurvatureCount(const DataType *ptrVox, const std::vector& sphere, DataType val) { diff --git a/include/Algo/MC/marchingcube.h b/include/Algo/MC/marchingcube.h index 70f9c0dffb07d03bff41558fd05d43bc8a643a46..5caa7e1b50e83b7f3c82b01340ccc01f3a5fd8c0 100644 --- a/include/Algo/MC/marchingcube.h +++ b/include/Algo/MC/marchingcube.h @@ -189,14 +189,7 @@ protected: void setNeighbour(L_DART d1, L_DART d2); - L_DART createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3) { - L_DART d = m_map->newFace(3); - //TODO change this which work only with 2-maps - m_map->setDartEmbedding(VERTEX,d,e1); d = m_map->phi1(d); - m_map->setDartEmbedding(VERTEX,d,e2); d = m_map->phi1(d); - m_map->setDartEmbedding(VERTEX,d,e3); d = m_map->phi1(d); - return d; - } + L_DART createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3); public: /** @@ -261,7 +254,7 @@ public: void removeFacesOfBoundary(AttributeHandler& boundVertices, unsigned int frameWidth); - void recalPoints(); + void recalPoints(const Geom::Vec3f& origin); }; diff --git a/include/Algo/MC/marchingcube.hpp b/include/Algo/MC/marchingcube.hpp index 772496c030499cda335f7cae6d2355b0dd4f3f68..de8522d74b0dcbc8f6fb9cb28b9ffc0da6ef7a63 100644 --- a/include/Algo/MC/marchingcube.hpp +++ b/include/Algo/MC/marchingcube.hpp @@ -100,6 +100,29 @@ void MarchingCube::deleteMesh() } } + +template< typename DataType, template < typename D2 > class Windowing, typename PFP > +Dart MarchingCube::createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3) +{ + L_DART d = m_map->newFace(3,false); + //TODO change this which work only with 2-maps +// m_map->setDartEmbedding(VERTEX,d,e1); d = m_map->phi1(d); +// m_map->setDartEmbedding(VERTEX,d,e2); d = m_map->phi1(d); +// m_map->setDartEmbedding(VERTEX,d,e3); d = m_map->phi1(d); + + FunctorSetEmb fsetemb(*m_map, VERTEX, e1); + m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb); + d = m_map->phi1(d); + fsetemb.changeEmb(e2); + m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb); + d = m_map->phi1(d); + fsetemb.changeEmb(e3); + m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb); + d = m_map->phi1(d); + + return d; +} + template< typename DataType, template < typename D2 > class Windowing, typename PFP > void MarchingCube::simpleMeshing() { @@ -120,7 +143,7 @@ void MarchingCube::simpleMeshing() // compute value to transform points directly to final system coordinate -// m_fOrigin = typename PFP::VEC3((float)(m_Image->getOrigin()[0]),(float)(m_Image->getOrigin()[1]),(float)(m_Image->getOrigin()[2])); + m_fOrigin = typename PFP::VEC3((float)(m_Image->getOrigin()[0]),(float)(m_Image->getOrigin()[1]),(float)(m_Image->getOrigin()[2])); m_fScal[0] = m_Image->getVoxSizeX(); m_fScal[1] = m_Image->getVoxSizeY(); @@ -483,7 +506,9 @@ void MarchingCube::createFaces_1(DataType *vox, const unsigned int lVertTable[12]; - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); +// typename PFP::VEC3 vPos(float(_lX) , float(_lY) , float(_lZ) ); +// typename PFP::VEC3 vPos(float(_lX) + 0.5f, float(_lY) + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices @@ -545,8 +570,7 @@ void MarchingCube::createFaces_2(DataType *vox, const return; unsigned int lVertTable[12]; -// typename PFP::VEC3 vPos((float)_lX , (float)_lY, (float)_lZ); - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices int lX = _lX; @@ -603,8 +627,7 @@ void MarchingCube::createFaces_3(DataType *vox, const return; unsigned int lVertTable[12]; -// typename PFP::VEC3 vPos((float)_lX , (float)_lY, (float)_lZ); - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices int lX = _lX; @@ -659,8 +682,7 @@ void MarchingCube::createFaces_4(DataType *vox, const return; unsigned int lVertTable[12]; -// typename PFP::VEC3 vPos((float)_lX , (float)_lY, (float)_lZ); - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices int lX = _lX; @@ -718,8 +740,7 @@ void MarchingCube::createFaces_5(DataType *vox, const return; unsigned int lVertTable[12]; -// typename PFP::VEC3 vPos((float)_lX , (float)_lY, (float)_lZ); - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices int lX = _lX; @@ -775,8 +796,7 @@ void MarchingCube::createFaces_6(DataType *vox, const return; unsigned int lVertTable[12]; -// typename PFP::VEC3 vPos((float)_lX , (float)_lY, (float)_lZ); - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices int lX = _lX+1; @@ -837,8 +857,7 @@ void MarchingCube::createFaces_7(DataType *vox, const return; unsigned int lVertTable[12]; -// typename PFP::VEC3 vPos((float)_lX , (float)_lY, (float)_lZ); - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices int lX = _lX+1; @@ -899,8 +918,7 @@ void MarchingCube::createFaces_8(DataType *vox, const return; unsigned int lVertTable[12]; -// typename PFP::VEC3 vPos((float)_lX , (float)_lY, (float)_lZ); - typename PFP::VEC3 vPos((float)_lX + 0.5f, (float)_lY + 0.5f, (float)_lZ + 0.5f); + typename PFP::VEC3 vPos(_lX, _lY, _lZ); // create the new vertices int lX = _lX+1; @@ -953,14 +971,14 @@ template< typename DataType, template < typename D2 > class Windowing, typename void MarchingCube::setNeighbourSimple(L_DART d1, L_DART d2) { if (m_map->phi2(d1) != d2) - m_map->sewFaces(d1,d2); + m_map->sewFaces(d1,d2,false); } template< typename DataType, template < typename D2 > class Windowing, typename PFP > void MarchingCube::setNeighbour(L_DART d1, L_DART d2) { if (m_map->phi2(d1) != d2) - m_map->sewFaces(d1,d2); + m_map->sewFaces(d1,d2,false); } template< typename DataType, template < typename D2 > class Windowing, typename PFP > @@ -1241,7 +1259,7 @@ void MarchingCube::removeFacesOfBoundary(AttributeHand } template< typename DataType, template < typename D2 > class Windowing, typename PFP > -void MarchingCube::recalPoints() +void MarchingCube::recalPoints(const Geom::Vec3f& origin) { for(unsigned int i=m_positions.begin(); i != m_positions.end(); m_positions.next(i)) @@ -1251,7 +1269,7 @@ void MarchingCube::recalPoints() P[0] = P[0] * m_fScal[0]; P[1] = P[1] * m_fScal[1]; P[2] = P[2] * m_fScal[2]; - + P+=origin; } } diff --git a/include/Algo/Modelisation/subdivision3.hpp b/include/Algo/Modelisation/subdivision3.hpp index d837d7ad8b019dd549f8c872d638dd91da2e6898..64d2bd226c5e6e6de6ac56a8af1194cfce69c0b9 100644 --- a/include/Algo/Modelisation/subdivision3.hpp +++ b/include/Algo/Modelisation/subdivision3.hpp @@ -302,8 +302,8 @@ void catmullClarkVol(typename PFP::MAP& map, EMBV& attributs, const FunctorSelec attributs[e] += attributs[f]; attributs[e] *= 0.5; - travE.mark(d) ; - travE.mark(e) ; + travE.skip(d) ; + travE.skip(e) ; } //2. split faces - quadrangule faces @@ -318,7 +318,7 @@ void catmullClarkVol(typename PFP::MAP& map, EMBV& attributs, const FunctorSelec Dart ne = map.phi2(map.phi_1(dd)) ; map.cutEdge(ne) ; - travF.mark(dd) ; + travF.skip(dd) ; attributs[map.phi1(ne)] = center; @@ -327,11 +327,11 @@ void catmullClarkVol(typename PFP::MAP& map, EMBV& attributs, const FunctorSelec { Dart tmp = map.phi1(ne) ; map.splitFace(tmp, dd) ; - travF.mark(tmp) ; + travF.skip(tmp) ; dd = map.phi1(map.phi1(dd)) ; } - travF.mark(ne) ; + travF.skip(ne) ; } //3. create inside volumes diff --git a/include/Algo/Render/GL2/topo3Render.h b/include/Algo/Render/GL2/topo3Render.h index d3cd4c1a0415bbaa08811deb1dfead18eff434b8..688c042f6484e8cee46468a41af2fd407c797fdc 100644 --- a/include/Algo/Render/GL2/topo3Render.h +++ b/include/Algo/Render/GL2/topo3Render.h @@ -36,6 +36,7 @@ #include "Geometry/vector_gen.h" #include "Utils/vbo.h" +#include "Utils/svg.h" // forward namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } @@ -83,6 +84,11 @@ protected: */ GLuint m_nbDarts; + /** + * number of relations 2 to draw + */ + GLuint m_nbRel1; + /** * number of relations 2 to draw */ @@ -266,8 +272,6 @@ public: void dartToCol(Dart d, float& r, float& g, float& b); - - /** * update all drawing buffers to render a dual map * @param map the map @@ -280,6 +284,14 @@ public: template void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); + /** + * update color buffer with color attributte handler + * @param map the map + * @param good selector + * @param colors attribute of dart's colors + */ + template + void updateColors(typename PFP::MAP& map, const typename PFP::TVEC3& colors, const FunctorSelect& good = allDarts); /** * Get back middle position of drawed darts @@ -290,8 +302,15 @@ public: template void computeDartMiddlePositions(typename PFP::MAP& map, typename PFP::TVEC3& posExpl, const FunctorSelect& good = allDarts); - template - void updateDataMap3OldFashioned(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good); + /** + * 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); protected: /** @@ -304,7 +323,7 @@ protected: * @param good selector */ template - void updateDataMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); + void updateDataMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good); /** * update all drawing buffers to render a gmap @@ -316,7 +335,7 @@ protected: * @param good selector */ template - void updateDataGMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); + void updateDataGMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good); }; diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index d4e83e9e48f12cf335514b4334b57c8625b1dc26..66972e95458772568f44346a30a29e69fb8cde4e 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -33,8 +33,6 @@ #include "Topology/generic/traversorCell.h" #include "Algo/Geometry/centroid.h" -#include - namespace CGoGN { @@ -65,10 +63,6 @@ void Topo3Render::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& template void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good) { - typedef typename PFP::VEC3 VEC3; - typedef typename PFP::REAL REAL; - -// Map3& map = dynamic_cast(mapx); typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -92,8 +86,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV CellMarker cmv(mapx,VOLUME); AutoAttributeHandler centerVolumes(mapx,VOLUME,"centerVolumes"); - Algo::Geometry::computeCentroidVolumes(mapx,positions,centerVolumes,good); - + Algo::Geometry::computeCentroidVolumes(mapx,positions,centerVolumes, allDarts); // debut phi1 AutoAttributeHandler fv1(mapx, DART); @@ -120,7 +113,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV unsigned int posDBI=0; // traverse each face of each volume - TraversorCell traFace(mapx, PFP::MAP::ORBIT_IN_PARENT(FACE),good); + TraversorCell traFace(mapx, PFP::MAP::ORBIT_IN_PARENT(FACE),allDarts); for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next()) { vecDartFaces.push_back(d); @@ -159,22 +152,25 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV float oke = 1.0f - ke; for (unsigned int i = 0; i < nb; ++i) { - VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke; - VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke; + if (good(d)) + { + VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke; + VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke; - m_attIndex[d] = posDBI; - posDBI+=2; + m_attIndex[d] = posDBI; + posDBI+=2; - *positionDartBuf++ = P; - *positionDartBuf++ = Q; - *colorDartBuf++ = m_dartsColor; - *colorDartBuf++ = m_dartsColor; + *positionDartBuf++ = P; + *positionDartBuf++ = Q; + *colorDartBuf++ = m_dartsColor; + *colorDartBuf++ = m_dartsColor; - fv1[d] = P*0.1f + Q*0.9f; - fv11[d] = P*0.9f + Q*0.1f; + fv1[d] = P*0.1f + Q*0.9f; + fv11[d] = P*0.9f + Q*0.1f; - fv2[d] = P*0.52f + Q*0.48f; - fv2x[d] = P*0.48f + Q*0.52f; + fv2[d] = P*0.52f + Q*0.48f; + fv2x[d] = P*0.48f + Q*0.52f; + } d = mapx.phi1(d); } @@ -186,25 +182,16 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV m_vbo4->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); - // phi1 - m_vbo1->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer1 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - //phi2 - m_vbo2->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - //phi3 - m_vbo3->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer3 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + VEC3* positioniF1 = new VEC3[ 2*m_nbDarts]; + VEC3* positioniF2 = new VEC3[ 2*m_nbDarts]; + VEC3* positioniF3 = new VEC3[ 2*m_nbDarts]; - VEC3* positionF1 = reinterpret_cast(PositionBuffer1); - VEC3* positionF2 = reinterpret_cast(PositionBuffer2); - VEC3* positionF3 = reinterpret_cast(PositionBuffer3); + VEC3* positionF1 = positioniF1; + VEC3* positionF2 = positioniF2; + VEC3* positionF3 = positioniF3; + m_nbRel1=0; m_nbRel2=0; m_nbRel3=0; @@ -214,7 +201,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV do { Dart e = mapx.phi2(d); - if (d < e) + if ((d < e) && good(d) && good(e)) { *positionF2++ = fv2[d]; *positionF2++ = fv2x[e]; @@ -223,7 +210,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV m_nbRel2++; } e = mapx.phi3(d); - if (!mapx.isBoundaryMarked(e) && (d < e)) + if (!mapx.isBoundaryMarked(e) && (d < e) && good(d) && good(e)) { *positionF3++ = fv2[d]; *positionF3++ = fv2x[e]; @@ -232,24 +219,28 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV m_nbRel3++; } e = mapx.phi1(d); - *positionF1++ = fv1[d]; - *positionF1++ = fv11[e]; - + if (good(d) && good(e)) + { + *positionF1++ = fv1[d]; + *positionF1++ = fv11[e]; + m_nbRel1++; + } d = mapx.phi1(d); } while (d != *face ); } m_vbo3->bind(); - glUnmapBufferARB(GL_ARRAY_BUFFER); + glBufferData(GL_ARRAY_BUFFER, 4*m_nbRel3*sizeof(typename PFP::VEC3), positioniF3, GL_STREAM_DRAW); m_vbo2->bind(); - glUnmapBufferARB(GL_ARRAY_BUFFER); + glBufferData(GL_ARRAY_BUFFER, 4*m_nbRel2*sizeof(typename PFP::VEC3), positioniF2, GL_STREAM_DRAW); m_vbo1->bind(); - glUnmapBuffer(GL_ARRAY_BUFFER); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbRel1*sizeof(typename PFP::VEC3), positioniF1, GL_STREAM_DRAW); - m_vbo4->bind(); - glUnmapBuffer(GL_ARRAY_BUFFER); + delete[] positioniF1; + delete[] positioniF2; + delete[] positioniF3; } @@ -282,7 +273,7 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g } else { - CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl; + CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl; break; } } @@ -290,6 +281,34 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g glUnmapBuffer(GL_ARRAY_BUFFER); } + +template +void Topo3Render::updateColors(typename PFP::MAP& map, const typename PFP::TVEC3& colors, const FunctorSelect& good) +{ + m_vbo4->bind(); + Geom::Vec3f* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); + unsigned int nb=0; + + for (Dart d = map.begin(); d != map.end(); map.next(d)) + { + if (good(d)) + { + if (nb < m_nbDarts) + { + colorBuffer[m_attIndex[d]] = colors[d]; + nb++; + } + else + { + CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl; + break; + } + } + } + glUnmapBuffer(GL_ARRAY_BUFFER); +} + + template Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good) { diff --git a/include/Container/attributeContainer.h b/include/Container/attributeContainer.h index 2f3adb56513306ea3280eb2656a9f8cff7d2bf8b..a4acb3e66008d12d547715bf6019cdccc8f2e698 100644 --- a/include/Container/attributeContainer.h +++ b/include/Container/attributeContainer.h @@ -530,6 +530,13 @@ public: * @param id ?? */ bool loadBin(CGoGNistream& fs); + + /** + * copy container + * TODO a version that compact on the fly ? + */ + void copyFrom(const AttributeContainer& cont); + }; } // namespace CGoGN diff --git a/include/Container/attributeMultiVector.h b/include/Container/attributeMultiVector.h index 54c4593fc370919eaee00efcde26c947ad3d1c3e..4d842466e8de46c2fab30253b441471fbdc6301a 100644 --- a/include/Container/attributeMultiVector.h +++ b/include/Container/attributeMultiVector.h @@ -126,6 +126,8 @@ public: */ virtual void setNbBlocks(unsigned int nbb) = 0; + virtual unsigned int getNbBlocks() const = 0; + virtual void addBlocksBefore(unsigned int nbb) = 0; virtual bool copy(const AttributeMultiVectorGen* atmvg) = 0; @@ -244,6 +246,8 @@ public: void setNbBlocks(unsigned int nbb); + unsigned int getNbBlocks() const; + void addBlocksBefore(unsigned int nbb); bool copy(const AttributeMultiVectorGen* atmvg); diff --git a/include/Container/attributeMultiVector.hpp b/include/Container/attributeMultiVector.hpp index f6d4502c1754ce0c2c6d3a1883d4ac2e1f3b0a95..8668aac8591e2416660a0eee00b0df36f2ab0f37 100644 --- a/include/Container/attributeMultiVector.hpp +++ b/include/Container/attributeMultiVector.hpp @@ -132,7 +132,9 @@ AttributeMultiVector::~AttributeMultiVector() template inline AttributeMultiVectorGen* AttributeMultiVector::new_obj() { - return new AttributeMultiVector; + AttributeMultiVectorGen* ptr = new AttributeMultiVector; + ptr->setTypeName(m_typeName); + return ptr; } /************************************** @@ -166,6 +168,12 @@ void AttributeMultiVector::setNbBlocks(unsigned int nbb) } } +template +unsigned int AttributeMultiVector::getNbBlocks() const +{ + return m_tableData.size(); +} + template void AttributeMultiVector::addBlocksBefore(unsigned int nbb) { diff --git a/include/Container/holeblockref.h b/include/Container/holeblockref.h index dc85a78e35a9a55bb680b5505f92e49519a8e7d0..0489842f079d75888dd0d158efdaf443ebcaba22 100644 --- a/include/Container/holeblockref.h +++ b/include/Container/holeblockref.h @@ -27,6 +27,7 @@ #include #include +#include #include "Container/sizeblock.h" @@ -49,7 +50,7 @@ protected: unsigned int m_nbref; /** - * nb element in block + * nb elements in block */ unsigned int m_nb; @@ -59,6 +60,11 @@ public: */ HoleBlockRef(); + /** + * copy constructor + */ + HoleBlockRef(const HoleBlockRef& hb); + /** * destructor */ @@ -149,6 +155,7 @@ public: */ inline bool unref(unsigned int i) { +// assert(m_refCount[i] > 1); m_refCount[i]--; if (m_refCount[i] == 1) { @@ -165,7 +172,7 @@ public: /** * number of references of element i - * @return the number of references (0 = no elements) + * @return the number of references +1 (stored as n+1, 0 = not used, 1 used but not refs, ...) */ inline unsigned int nbRefs(unsigned int i) { return m_refCount[i]; } diff --git a/include/Topology/generic/functor.h b/include/Topology/generic/functor.h index a907d5c73a488bb304b4514f3ea4700320638bd7..eae54e2d46c299e124492f575b0e112948a0332a 100644 --- a/include/Topology/generic/functor.h +++ b/include/Topology/generic/functor.h @@ -253,6 +253,7 @@ public: this->m_map.setDartEmbedding(orbit, d, emb); return false; } + void changeEmb(unsigned int e) { emb = e;} }; // Functor Check Embedding : to check the embeddings of the given map diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index 2e575e8710ebe7865468bdedafedce99a56d6c0c..6a1943d4151edcbcfc35ce7ae05b0f36b8b141c5 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -150,7 +150,7 @@ public: ~GenericMap() ; - virtual std::string mapTypeName() = 0 ; + virtual std::string mapTypeName() const = 0 ; /** * Clear the map @@ -503,6 +503,11 @@ public: */ bool loadMapBin(const std::string& filename) ; + /** + * copy from another map (of same type) + */ + bool copyFrom(const GenericMap& map); + /** * Dump attributes types and names per orbit */ diff --git a/include/Topology/gmap/gmap0.h b/include/Topology/gmap/gmap0.h index 22895d14d3df15df187ce71a1f218c4bedac02ed..1134f84d276052a2707de2c5e0792aed3149063c 100644 --- a/include/Topology/gmap/gmap0.h +++ b/include/Topology/gmap/gmap0.h @@ -46,7 +46,7 @@ protected: public: GMap0(); - virtual std::string mapTypeName(); + virtual std::string mapTypeName() const; virtual unsigned int dimension(); diff --git a/include/Topology/gmap/gmap0.hpp b/include/Topology/gmap/gmap0.hpp index d10da62874bd3fd665fbdbff31efedd58bbd8455..d1e83947416793ebcff276e91693a23e3dc3eb07 100644 --- a/include/Topology/gmap/gmap0.hpp +++ b/include/Topology/gmap/gmap0.hpp @@ -37,7 +37,7 @@ inline GMap0::GMap0() : AttribMap() init() ; } -inline std::string GMap0::mapTypeName() +inline std::string GMap0::mapTypeName() const { return "GMap0"; } diff --git a/include/Topology/gmap/gmap1.h b/include/Topology/gmap/gmap1.h index 961007f5bd8df6ca5a3082b27e56102b2e2c855d..1a7ef86b3c7bcb4cced5088884ec083ddee29bf3 100644 --- a/include/Topology/gmap/gmap1.h +++ b/include/Topology/gmap/gmap1.h @@ -45,7 +45,7 @@ public: GMap1(); - virtual std::string mapTypeName(); + virtual std::string mapTypeName() const; virtual unsigned int dimension(); diff --git a/include/Topology/gmap/gmap1.hpp b/include/Topology/gmap/gmap1.hpp index 32ca4d1d7291cccbc9762764e3336cd35444985e..65fe243458f9f2b95aa6a9262d658d5dba3b93ce 100644 --- a/include/Topology/gmap/gmap1.hpp +++ b/include/Topology/gmap/gmap1.hpp @@ -35,7 +35,7 @@ inline GMap1::GMap1() : GMap0() init() ; } -inline std::string GMap1::mapTypeName() +inline std::string GMap1::mapTypeName() const { return "GMap1"; } diff --git a/include/Topology/gmap/gmap2.h b/include/Topology/gmap/gmap2.h index b347cc7c69d546aa3bc5688097f42bf6d09c96b2..c98271d3b223ce12c99300cf2596e7224b4c8a7d 100644 --- a/include/Topology/gmap/gmap2.h +++ b/include/Topology/gmap/gmap2.h @@ -50,7 +50,7 @@ public: GMap2(); - virtual std::string mapTypeName(); + virtual std::string mapTypeName() const; virtual unsigned int dimension(); diff --git a/include/Topology/gmap/gmap2.hpp b/include/Topology/gmap/gmap2.hpp index f35c1134d21405551d93e8cab8963fcf8357a6d5..e31d96199ae399c5304f0927a756bdbf850b2d43 100644 --- a/include/Topology/gmap/gmap2.hpp +++ b/include/Topology/gmap/gmap2.hpp @@ -35,7 +35,7 @@ inline GMap2::GMap2() : GMap1() init() ; } -inline std::string GMap2::mapTypeName() +inline std::string GMap2::mapTypeName() const { return "GMap2"; } diff --git a/include/Topology/gmap/gmap3.h b/include/Topology/gmap/gmap3.h index cd82a326c7b94f617522050cf58ca6a2380b68af..3de5c92be34c2639e7ad74685cfaa9b921df50a0 100644 --- a/include/Topology/gmap/gmap3.h +++ b/include/Topology/gmap/gmap3.h @@ -55,7 +55,7 @@ public: GMap3(); - virtual std::string mapTypeName(); + virtual std::string mapTypeName() const; virtual unsigned int dimension(); diff --git a/include/Topology/gmap/gmap3.hpp b/include/Topology/gmap/gmap3.hpp index d25d431ebc3b6860b597ba7778e08a0c9fdffd55..90a704339434b883e2d408ca97855552763e96d0 100644 --- a/include/Topology/gmap/gmap3.hpp +++ b/include/Topology/gmap/gmap3.hpp @@ -35,7 +35,7 @@ inline GMap3::GMap3() : GMap2() init() ; } -inline std::string GMap3::mapTypeName() +inline std::string GMap3::mapTypeName() const { return "GMap3"; } diff --git a/include/Topology/map/map1.h b/include/Topology/map/map1.h index f1f5ccd806e194f03632688a7d93e6f6a9793535..a4ab07243de4e094469054d7c378cad517bcccd1 100644 --- a/include/Topology/map/map1.h +++ b/include/Topology/map/map1.h @@ -51,7 +51,7 @@ protected: public: Map1(); - virtual std::string mapTypeName(); + virtual std::string mapTypeName() const; virtual unsigned int dimension(); diff --git a/include/Topology/map/map1.hpp b/include/Topology/map/map1.hpp index 2643f76bfa5edb8bc295836d2cc8ab8274b9bfb5..5f1b93f332932cf2fb36ca4448dc51a791f52d3e 100644 --- a/include/Topology/map/map1.hpp +++ b/include/Topology/map/map1.hpp @@ -38,7 +38,7 @@ inline Map1::Map1() : AttribMap() init() ; } -inline std::string Map1::mapTypeName() +inline std::string Map1::mapTypeName() const { return "Map1" ; } diff --git a/include/Topology/map/map2.h b/include/Topology/map/map2.h index ceba3d713bbdec97c2a065b4440045cd9f2826d5..6e9a294bcd390df96c648bb41505202d301ad963 100644 --- a/include/Topology/map/map2.h +++ b/include/Topology/map/map2.h @@ -62,7 +62,7 @@ public: Map2(); - virtual std::string mapTypeName(); + virtual std::string mapTypeName() const; virtual unsigned int dimension(); diff --git a/include/Topology/map/map2.hpp b/include/Topology/map/map2.hpp index 5689d499303fc3a37b1d6841e194a571d11ecabb..9b9ecd13e549c77b5b668ad207e3fe400a4cc4f3 100644 --- a/include/Topology/map/map2.hpp +++ b/include/Topology/map/map2.hpp @@ -37,7 +37,7 @@ inline Map2::Map2() : Map1() init() ; } -inline std::string Map2::mapTypeName() +inline std::string Map2::mapTypeName() const { return "Map2" ; } diff --git a/include/Topology/map/map3.h b/include/Topology/map/map3.h index 578143a82ed274edcf0213fda206be51ece82ef6..d755f14cbc3877012886e857488cb2ed0d38335e 100644 --- a/include/Topology/map/map3.h +++ b/include/Topology/map/map3.h @@ -69,7 +69,7 @@ public: Map3(); - virtual std::string mapTypeName(); + virtual std::string mapTypeName() const; virtual unsigned int dimension(); diff --git a/include/Topology/map/map3.hpp b/include/Topology/map/map3.hpp index c018718e540dcf02623efd43be62e28d316b1d37..efcceb5511aa78a412667639674845bd80a578cf 100644 --- a/include/Topology/map/map3.hpp +++ b/include/Topology/map/map3.hpp @@ -35,7 +35,7 @@ inline Map3::Map3() : Map2() init() ; } -inline std::string Map3::mapTypeName() +inline std::string Map3::mapTypeName() const { return "Map3"; } diff --git a/include/Topology/map/map3MR/map3MR_PrimalAdapt.h b/include/Topology/map/map3MR/map3MR_PrimalAdapt.h index 879b208d333283e7ccd41bf0583cf177ea05d055..2ca73f4ef985b10fc76ce5c573af562532312be4 100644 --- a/include/Topology/map/map3MR/map3MR_PrimalAdapt.h +++ b/include/Topology/map/map3MR/map3MR_PrimalAdapt.h @@ -72,6 +72,12 @@ public: */ bool isTetrahedron(Dart d); + void splitSurfaceInVolume(std::vector& vd, bool firstSideClosed = true, bool secondSideClosed = false); + Dart cutEdgeInVolume(Dart d); + void splitFaceInVolume(Dart d, Dart e); + + void splitVolume(std::vector& vd); + //! /*! */ @@ -81,6 +87,9 @@ public: /*! */ void unsewAroundVertex(std::vector >& vd); + + Dart cutEdge(Dart d) ; + void splitFace(Dart d, Dart e) ; //@} /*! @name Cells informations @@ -141,6 +150,10 @@ protected: */ void addNewLevel() ; + void propagateDartRelation(Dart d, AttributeMultiVector* rel) ; + void propagateDartEmbedding(Dart d, unsigned int orbit) ; + void propagateOrbitEmbedding(Dart d, unsigned int orbit) ; + //! Subdivide the edge of d to the next level /*! @param d Dart from the edge */ @@ -161,6 +174,8 @@ public: /*! @param d Dart from the volume */ void subdivideVolumeTetOcta(Dart d) ; + + void subdivideVolumeTetOctaTemp(Dart d); //@} /*! @name Vertices Attributes management diff --git a/include/Utils/Shaders/shaderExplodeVolumes.geom b/include/Utils/Shaders/shaderExplodeVolumes.geom index 141b99e064452007f12ba4d68ab68ee79bddd2da..f402a4462dfae2a29730947fe95d0817f0980e8b 100644 --- a/include/Utils/Shaders/shaderExplodeVolumes.geom +++ b/include/Utils/Shaders/shaderExplodeVolumes.geom @@ -10,7 +10,7 @@ uniform vec4 ambient; uniform vec4 backColor; uniform vec4 plane; -VARYING_IN vec3 colorVertex[]; +VARYING_IN vec3 colorVertex[4]; VARYING_OUT vec4 ColorFS; diff --git a/include/Utils/svg.h b/include/Utils/svg.h index 3ced3668d7b4a99404a12d4bfac66d03e4832c91..a1f874960665847f895daa3f83f2e24fdadde36c 100644 --- a/include/Utils/svg.h +++ b/include/Utils/svg.h @@ -156,10 +156,12 @@ public: //}; - +class AnimatedSVGOut; class SVGOut { + friend class AnimatedSVGOut; + protected: std::ofstream* m_out; @@ -173,6 +175,7 @@ protected: std::vector m_objs; SvgObj* m_current; + std::vector m_opacities_animations; unsigned int m_bbX0; unsigned int m_bbY0; @@ -194,6 +197,14 @@ public: */ 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); + /** * destructor * flush and close the file @@ -226,9 +237,25 @@ public: 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); + }; +class AnimatedSVGOut +{ +protected: + std::vector m_svgs; + +public: + + void write(const std::string& filename, float timeStep); + void add(SVGOut* svg); + +}; } // namespace SVG diff --git a/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp b/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp index 257408ec498fdb5dadb8ff87e59c15cbb3f89883..bfa903b5e240517fc8375a562d593b45ed457d08 100644 --- a/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp +++ b/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp @@ -47,9 +47,9 @@ ImplicitHierarchicalMap3::ImplicitHierarchicalMap3() : m_curLevel(0), m_maxLevel ImplicitHierarchicalMap3::~ImplicitHierarchicalMap3() { - Map3::removeAttribute(m_edgeId) ; - Map3::removeAttribute(m_faceId) ; - Map3::removeAttribute(m_dartLevel) ; + removeAttribute(m_edgeId) ; + removeAttribute(m_faceId) ; + removeAttribute(m_dartLevel) ; } void ImplicitHierarchicalMap3::init() diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp index f2dcc2336e6d523fb68e6fc4d96ac9e5529f3fe4..f1f47d2e6ab36e143040aee801f8ee92762bcc88 100644 --- a/src/Algo/Render/topo3Render.cpp +++ b/src/Algo/Render/topo3Render.cpp @@ -43,7 +43,7 @@ namespace GL2 { Topo3Render::Topo3Render(): -m_nbDarts(0),m_nbRel2(0),m_nbRel3(0), +m_nbDarts(0),m_nbRel1(0),m_nbRel2(0),m_nbRel3(0), m_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL), m_dartsColor(1.0f,1.0f,1.0f) { @@ -192,7 +192,7 @@ void Topo3Render::drawRelation1() m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); m_shader1->enableVertexAttribs(); - glDrawArrays(GL_LINES, 0, m_nbDarts*2); + glDrawArrays(GL_LINES, 0, m_nbRel1*2); m_shader1->disableVertexAttribs(); @@ -370,6 +370,83 @@ Dart Topo3Render::pickColor(unsigned int x, unsigned int y) return colToDart(color); } +void Topo3Render::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) +{ + Utils::SVG::SVGOut svg(filename,model,proj); + toSVG(svg); +} + +void Topo3Render::toSVG(Utils::SVG::SVGOut& svg) +{ + svg.setWidth(m_topo_relation_width); + + // PHI3 / beta3 + + const Geom::Vec3f* ptr = reinterpret_cast(m_vbo3->lockPtr()); + + svg.beginLines(); + for (unsigned int i=0; ireleasePtr(); + + + // PHI2 / beta2 + + 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_vbo4->lockPtr()); + ptr= reinterpret_cast(m_vbo0->lockPtr()); + + svg.setWidth(m_topo_dart_width); + + svg.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); + } + svg.endLines(); + + svg.beginPoints(); + for (unsigned int i=0; i2.9f) + col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; + svg.addPoint(ptr[2*i], col); + } + svg.endPoints(); + + m_vbo0->releasePtr(); + m_vbo4->releasePtr(); +} diff --git a/src/Container/attributeContainer.cpp b/src/Container/attributeContainer.cpp index db784d429e822f564cc24bc8788003ac43001640..c80fabb960f79f69d4cfc42eb1192191aa1995c2 100644 --- a/src/Container/attributeContainer.cpp +++ b/src/Container/attributeContainer.cpp @@ -690,4 +690,57 @@ bool AttributeContainer::loadBin(CGoGNistream& fs) return true; } + +void AttributeContainer::copyFrom(const AttributeContainer& cont) +{ +// clear is done from the map + + m_size = cont.m_size; + m_maxSize = cont.m_maxSize; + m_orbit = cont.m_orbit; + m_nbUnknown = cont.m_nbUnknown; + m_nbAttributes = cont.m_nbAttributes; + m_lineCost = cont.m_lineCost; + + // blocks + unsigned int sz = cont.m_holesBlocks.size(); + m_holesBlocks.resize(sz); + for (unsigned int i = 0; i < sz; ++i) + m_holesBlocks[i] = new HoleBlockRef(*(cont.m_holesBlocks[i])); + + // blocks with free + sz = cont.m_tableBlocksWithFree.size(); + m_tableBlocksWithFree.resize(sz); + for (unsigned int i = 0; i < sz; ++i) + m_tableBlocksWithFree[i] = cont.m_tableBlocksWithFree[i]; + + // empty blocks + sz = cont.m_tableBlocksEmpty.size(); + m_tableBlocksEmpty.resize(sz); + for (unsigned int i = 0; i < sz; ++i) + m_tableBlocksEmpty[i] = cont.m_tableBlocksEmpty[i]; + + //attributes (warning attribute can have different numbers than in original) + m_tableAttribs.reserve(m_nbAttributes); + sz = cont.m_tableAttribs.size(); + for (unsigned int i = 0; i < sz; ++i) + { + if (cont.m_tableAttribs[i] != NULL) + { + AttributeMultiVectorGen* ptr = cont.m_tableAttribs[i]->new_obj(); + ptr->setName(cont.m_tableAttribs[i]->getName()); + ptr->setOrbit(cont.m_tableAttribs[i]->getIndex()); + ptr->setIndex(m_tableAttribs.size()); + ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks()); + ptr->copy(cont.m_tableAttribs[i]); + if (cont.m_tableAttribs[i]->toProcess()) + ptr->toggleProcess(); + else + ptr->toggleNoProcess(); + m_tableAttribs.push_back(ptr); + } + } +} + + } diff --git a/src/Container/holeblockref.cpp b/src/Container/holeblockref.cpp index f353948cd1a10b0d79f664d094d5109e3b7eeadc..677f300cccb26d4a19b928186ca40526084128e0 100644 --- a/src/Container/holeblockref.cpp +++ b/src/Container/holeblockref.cpp @@ -43,10 +43,24 @@ namespace CGoGN HoleBlockRef::HoleBlockRef(): m_nbfree(0),m_nbref(0),m_nb(0) { - m_tableFree = new unsigned int[_BLOCKSIZE_]; + m_tableFree = new unsigned int[_BLOCKSIZE_ + 10]; m_refCount = new unsigned int[_BLOCKSIZE_]; } +HoleBlockRef::HoleBlockRef(const HoleBlockRef& hb) +{ + m_nbfree = hb.m_nbfree; + m_nbref = hb.m_nbref; + m_nb = hb.m_nb; + + m_tableFree = new unsigned int[_BLOCKSIZE_ +10]; + memcpy(m_tableFree, hb.m_tableFree, (_BLOCKSIZE_+ 10) * sizeof(unsigned int)); + + m_refCount = new unsigned int[_BLOCKSIZE_]; + memcpy(m_refCount, hb.m_refCount, _BLOCKSIZE_ * sizeof(unsigned int)); + +} + HoleBlockRef::~HoleBlockRef() { delete[] m_tableFree; diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index 0eeee84b0c72fef3f4056f3972410028b449ccbc..0c898e5b381547011aa81a00feaa7be07c1b01f7 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -578,6 +578,45 @@ bool GenericMap::loadMapBin(const std::string& filename) return true; } + + +bool GenericMap::copyFrom(const GenericMap& map) +{ + if (mapTypeName() != map.mapTypeName()) + { + CGoGNerr <<"try to copy from incompatible type map" << CGoGNendl; + return false; + } + + GenericMap::clear(true); + + + + // load attrib container + for (unsigned int i = 0; i < NB_ORBITS; ++i) + m_attribs[i].copyFrom(map.m_attribs[i]); + + if (m_isMultiRes) + { + m_mrattribs.copyFrom(map.m_mrattribs); + m_mrCurrentLevel = map.m_mrCurrentLevel; + + unsigned int nb= map.m_mrNbDarts.size(); + m_mrNbDarts.resize(nb); + for (unsigned int i=0; i& vd, bool firstSideClosed, bool secondSideClosed) +{ + std::vector vd2 ; + vd2.reserve(vd.size()); + + // save the edge neighbors darts + for(std::vector::iterator it = vd.begin() ; it != vd.end() ; ++it) + { + vd2.push_back(phi2(*it)); + } + + assert(vd2.size() == vd.size()); + + Map2::splitSurface(vd, firstSideClosed, secondSideClosed); + + // follow the edge path a second time to embed the vertex, edge and volume orbits + for(unsigned int i = 0; i < vd.size(); ++i) + { + Dart dit = vd[i]; + Dart dit2 = vd2[i]; + +// propagateDartRelation(dit, m_phi1) ; +// propagateDartRelation(dit, m_phi_1) ; +// propagateDartRelation(dit, m_phi2) ; +// +// propagateDartRelation(dit2, m_phi1) ; +// propagateDartRelation(dit2, m_phi_1) ; +// propagateDartRelation(dit2, m_phi2) ; + + // embed the vertex embedded from the origin volume to the new darts + if(isOrbitEmbedded(VERTEX)) + { + copyDartEmbedding(VERTEX, phi2(dit), phi1(dit)); + copyDartEmbedding(VERTEX, phi2(dit2), phi1(dit2)); + } + } + +} + +void Map3MR_PrimalAdapt::splitFaceInVolume(Dart d, Dart e) +{ + Dart dprev = phi_1(d) ; + Dart eprev = phi_1(e) ; + Map2::splitFace(d, e) ; + Dart dd = phi1(dprev) ; + Dart ee = phi1(eprev) ; + + propagateDartRelation(d, m_phi_1) ; + propagateDartRelation(e, m_phi_1) ; + propagateDartRelation(dd, m_phi1) ; + propagateDartRelation(dd, m_phi_1) ; + propagateDartRelation(dd, m_phi2) ; + propagateDartRelation(ee, m_phi1) ; + propagateDartRelation(ee, m_phi_1) ; + propagateDartRelation(ee, m_phi2) ; + propagateDartRelation(dprev, m_phi1) ; + propagateDartRelation(eprev, m_phi1) ; + + propagateDartEmbedding(dd, VERTEX) ; + propagateDartEmbedding(ee, VERTEX) ; +} + +Dart Map3MR_PrimalAdapt::cutEdgeInVolume(Dart d) +{ + Dart dd = phi2(d) ; + Dart d1 = Map2::cutEdge(d) ; + Dart dd1 = phi1(dd) ; + Dart d11 = phi1(d1) ; + Dart dd11 = phi1(dd1) ; + + propagateDartRelation(d, m_phi1) ; + propagateDartRelation(d, m_phi2) ; + propagateDartRelation(dd, m_phi1) ; + propagateDartRelation(dd, m_phi2) ; + propagateDartRelation(d1, m_phi1) ; + propagateDartRelation(d1, m_phi_1) ; + propagateDartRelation(d1, m_phi2) ; + propagateDartRelation(dd1, m_phi1) ; + propagateDartRelation(dd1, m_phi_1) ; + propagateDartRelation(dd1, m_phi2) ; + propagateDartRelation(d11, m_phi_1) ; + propagateDartRelation(dd11, m_phi_1) ; + + return d1 ; +} + bool Map3MR_PrimalAdapt::isTetrahedron(Dart d) { unsigned int nbFaces = 0; @@ -93,43 +194,106 @@ bool Map3MR_PrimalAdapt::isTetrahedron(Dart d) return true; } -void Map3MR_PrimalAdapt::saveRelationsAroundVertex(Dart d, std::vector >& vd) +Dart Map3MR_PrimalAdapt::cutEdge(Dart d) { - assert(getDartLevel(d) <= getCurrentLevel() || !"saveRelationsAroundVertex : called with a dart inserted after current level") ; - - //le brin est forcement du niveau cur - Dart dit = d; + Dart nd = EmbeddedMap3::cutEdge(d); + Dart it = d; do { - vd.push_back(std::pair(dit,phi2(dit))); - - dit = phi2(phi_1(dit)); - - }while(dit != d); + Dart d1 = phi1(it); + Dart dd = phi2(d1) ; + Dart dd1 = phi1(dd) ; + Dart d11 = phi1(d1) ; + Dart dd11 = phi1(dd1) ; + + propagateDartRelation(d, m_phi1) ; + propagateDartRelation(d, m_phi2) ; + propagateDartRelation(d, m_phi3) ; + propagateDartRelation(dd, m_phi1) ; + propagateDartRelation(dd, m_phi2) ; + propagateDartRelation(dd, m_phi3) ; + propagateDartRelation(d1, m_phi1) ; + propagateDartRelation(d1, m_phi_1) ; + propagateDartRelation(d1, m_phi2) ; + propagateDartRelation(d1, m_phi3) ; + propagateDartRelation(dd1, m_phi1) ; + propagateDartRelation(dd1, m_phi_1) ; + propagateDartRelation(dd1, m_phi2) ; + propagateDartRelation(dd1, m_phi3) ; + propagateDartRelation(d11, m_phi_1) ; + propagateDartRelation(dd11, m_phi_1) ; + + it = alpha2(it); + }while(it != d); + + return nd; } -void Map3MR_PrimalAdapt::unsewAroundVertex(std::vector >& vd) +void Map3MR_PrimalAdapt::splitFace(Dart d, Dart e) { - //unsew the edge path - for(std::vector >::iterator it = vd.begin() ; it != vd.end() ; ++it) - { - Dart dit = (*it).first; - Dart dit2 = (*it).second; - - Map2::unsewFaces(dit); - - if(isOrbitEmbedded(VERTEX)) - { - copyDartEmbedding(VERTEX, phi2(dit2), dit); - copyDartEmbedding(VERTEX, phi2(dit), dit2); - } + Dart dprev = phi_1(d) ; + Dart eprev = phi_1(e) ; + EmbeddedMap3::splitFace(d,e); + Dart dd = phi1(dprev) ; + Dart ee = phi1(eprev) ; + + propagateDartRelation(d, m_phi_1) ; + propagateDartRelation(e, m_phi_1) ; + propagateDartRelation(dd, m_phi1) ; + propagateDartRelation(dd, m_phi_1) ; + propagateDartRelation(dd, m_phi2) ; + propagateDartRelation(ee, m_phi1) ; + propagateDartRelation(ee, m_phi_1) ; + propagateDartRelation(ee, m_phi2) ; + propagateDartRelation(dprev, m_phi1) ; + propagateDartRelation(eprev, m_phi1) ; + + propagateDartRelation(phi3(dprev), m_phi_1) ; + propagateDartRelation(phi3(eprev), m_phi_1) ; + propagateDartRelation(phi3(dd), m_phi1) ; + propagateDartRelation(phi3(dd), m_phi_1) ; + propagateDartRelation(phi3(dd), m_phi2) ; + propagateDartRelation(phi3(ee), m_phi1) ; + propagateDartRelation(phi3(ee), m_phi_1) ; + propagateDartRelation(phi3(ee), m_phi2) ; + propagateDartRelation(phi3(d), m_phi1) ; + propagateDartRelation(phi3(e), m_phi1) ; + + propagateDartEmbedding(dd, VERTEX) ; + propagateDartEmbedding(ee, VERTEX) ; + propagateDartEmbedding(phi3(dd), VERTEX) ; + propagateDartEmbedding(phi3(ee), VERTEX) ; +} - if(isOrbitEmbedded(EDGE)) - { +void Map3MR_PrimalAdapt::splitVolume(std::vector& vd) +{ + EmbeddedMap3::splitVolume(vd); - } + for(std::vector::iterator it = vd.begin() ; it != vd.end() ; ++it) + { + Dart dit = *it; + propagateDartRelation(dit, m_phi2) ; + + Dart dit2 = phi2(dit); + propagateDartRelation(dit2, m_phi1) ; + propagateDartRelation(dit2, m_phi_1) ; + propagateDartRelation(dit2, m_phi2) ; + propagateDartRelation(dit2, m_phi3) ; + + Dart dit23 = phi3(dit2); + propagateDartRelation(dit23, m_phi1) ; + propagateDartRelation(dit23, m_phi_1) ; + propagateDartRelation(dit23, m_phi2) ; + propagateDartRelation(dit23, m_phi3) ; + + Dart dit232 = phi2(dit23); + propagateDartRelation(dit232, m_phi2) ; + + propagateDartEmbedding(dit2, VERTEX) ; + propagateDartEmbedding(dit23, VERTEX) ; } + } /*! @name Cells informations @@ -223,13 +387,29 @@ Dart Map3MR_PrimalAdapt::faceOldestDart(Dart d) { assert(getDartLevel(d) <= getCurrentLevel() || !"faceOldestDart : called with a dart inserted after current level") ; +// Dart it = d ; +// Dart oldest = it ; +// unsigned int l_old = getDartLevel(oldest) ; +// do +// { +// unsigned int l = getDartLevel(it) ; +// if(l < l_old || (l == l_old && it < oldest)) +// { +// oldest = it ; +// l_old = l ; +// } +// it = phi1(it) ; +// } while(it != d) ; +// return oldest ; Dart it = d ; Dart oldest = it ; unsigned int l_old = getDartLevel(oldest) ; do { unsigned int l = getDartLevel(it) ; - if(l < l_old || (l == l_old && it < oldest)) + if(l == 0) + return it ; + if(l < l_old) { oldest = it ; l_old = l ; @@ -281,16 +461,31 @@ bool Map3MR_PrimalAdapt::faceIsSubdivided(Dart d) return false ; // a face whose level in the current level map is lower than - // the current level can not be subdivided to higher levels + // the current level can be subdivided to higher levels unsigned int fLevel = faceLevel(d) ; if(fLevel < getCurrentLevel()) return false ; bool subd = false ; - incCurrentLevel() ; - if(getDartLevel(phi1(phi1(d))) == getCurrentLevel()) - subd = true ; - decCurrentLevel() ; + + //Une face dont toute les aretes sont subdivise mais pas la face elle meme renvoie false .. sinon c'est true + Dart dit = d; + bool edgesAreSubdivided = true; + do + { + edgesAreSubdivided &= edgeIsSubdivided(dit); + dit = phi1(dit); + }while(dit != d); + + if(edgesAreSubdivided) + { + incCurrentLevel() ; + if(getDartLevel(phi1(phi1(d))) == getCurrentLevel()) + subd = true ; + decCurrentLevel() ; + } + else + return false; return subd ; } @@ -324,39 +519,91 @@ bool Map3MR_PrimalAdapt::volumeIsSubdivided(Dart d) *************************************************************************/ void Map3MR_PrimalAdapt::addNewLevel() { - addLevel(); -} + //pushLevel() ; + addLevel() ; + //setCurrentLevel(getMaxLevel()) ; -void Map3MR_PrimalAdapt::subdivideEdge(Dart d) + //popLevel() ; +} + +void Map3MR_PrimalAdapt::propagateDartRelation(Dart d, AttributeMultiVector* rel) { - assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideEdge : called with a dart inserted after current level") ; - assert(!edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ; + Dart dd = (*rel)[dartIndex(d)] ; + pushLevel() ; + for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i) + { + setCurrentLevel(i) ; + (*rel)[dartIndex(d)] = dd ; + } + popLevel() ; +} - incCurrentLevel() ; +void Map3MR_PrimalAdapt::propagateDartEmbedding(Dart d, unsigned int orbit) +{ + unsigned int emb = getEmbedding(orbit, d) ; + pushLevel() ; + for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i) + { + setCurrentLevel(i) ; + setDartEmbedding(orbit, d, emb) ; + } + popLevel() ; +} - //Duplicate all darts around the edge - Dart dit = d; - do +void Map3MR_PrimalAdapt::propagateOrbitEmbedding(Dart d, unsigned int orbit) +{ + unsigned int emb = getEmbedding(orbit, d) ; + pushLevel() ; + for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i) { - duplicateDart(dit); + setCurrentLevel(i) ; + embedOrbit(orbit, d, emb) ; + } + popLevel() ; +} - Dart dd = phi2(dit) ; - duplicateDart(dd) ; - Dart d1 = phi1(dit) ; - duplicateDart(d1) ; - Dart dd1 = phi1(dd) ; - duplicateDart(dd1) ; +void Map3MR_PrimalAdapt::subdivideEdge(Dart d) +{ + assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideEdge : called with a dart inserted after current level") ; + assert(!edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ; - dit = alpha2(dit); - }while(dit != d); + incCurrentLevel(); - cutEdge(d) ; - (*edgeVertexFunctor)(phi1(d)); + Dart d1 = cutEdge(d); + + (*edgeVertexFunctor)(d1) ; + propagateOrbitEmbedding(d1, VERTEX); decCurrentLevel() ; + + +// incCurrentLevel() ; +// +// //Duplicate all darts around the edge +// Dart dit = d; +// do +// { +// duplicateDart(dit); +// +// Dart dd = phi2(dit) ; +// duplicateDart(dd) ; +// +// Dart d1 = phi1(dit) ; +// duplicateDart(d1) ; +// +// Dart dd1 = phi1(dd) ; +// duplicateDart(dd1) ; +// +// dit = alpha2(dit); +// }while(dit != d); +// +// cutEdge(d) ; +// (*edgeVertexFunctor)(phi1(d)); +// +// decCurrentLevel() ; } void Map3MR_PrimalAdapt::subdivideFace(Dart d, SubdivideType sType) @@ -388,18 +635,21 @@ void Map3MR_PrimalAdapt::subdivideFace(Dart d, SubdivideType sType) Dart dd = phi1(old) ; Dart e = phi1(dd) ; (*vertexVertexFunctor)(e) ; + propagateOrbitEmbedding(e, VERTEX) ; e = phi1(e) ; splitFace(dd, e) ; dd = e ; e = phi1(dd) ; (*vertexVertexFunctor)(e) ; + propagateOrbitEmbedding(e, VERTEX) ; e = phi1(e) ; splitFace(dd, e) ; dd = e ; e = phi1(dd) ; (*vertexVertexFunctor)(e) ; + propagateOrbitEmbedding(e, VERTEX) ; e = phi1(e) ; splitFace(dd, e) ; } @@ -408,6 +658,7 @@ void Map3MR_PrimalAdapt::subdivideFace(Dart d, SubdivideType sType) Dart dd = phi1(old) ; Dart next = phi1(dd) ; (*vertexVertexFunctor)(next) ; + propagateOrbitEmbedding(next, VERTEX) ; next = phi1(next) ; splitFace(dd, next) ; // insert a first edge Dart ne = phi2(phi_1(dd)); @@ -416,16 +667,19 @@ void Map3MR_PrimalAdapt::subdivideFace(Dart d, SubdivideType sType) dd = phi1(next) ; (*vertexVertexFunctor)(dd) ; + propagateOrbitEmbedding(dd, VERTEX) ; dd = phi1(dd) ; while(dd != ne) // turn around the face and insert new edges { // linked to the central vertex splitFace(phi1(ne), dd) ; dd = phi1(dd) ; (*vertexVertexFunctor)(dd) ; + propagateOrbitEmbedding(dd, VERTEX) ; dd = phi1(dd) ; } (*faceVertexFunctor)(phi2(ne)) ; + propagateOrbitEmbedding(phi2(ne), VERTEX) ; } popLevel() ; @@ -439,99 +693,146 @@ void Map3MR_PrimalAdapt::subdivideVolume(Dart d) unsigned int vLevel = volumeLevel(d); Dart old = volumeOldestDart(d); - Traversor3WV traV(*this, old); - pushLevel() ; - setCurrentLevel(vLevel) ; // go to the level of the face to subdivide its edges + setCurrentLevel(vLevel) ; // go to the level of the volume to subdivide its faces if(getCurrentLevel() == getMaxLevel()) addNewLevel() ; // - // Subdivide Faces + // Subdivide Faces and Edges // - std::vector > subdividedFaces; - subdividedFaces.reserve(128); - + unsigned int j = 0; Traversor3WF traF(*this, old); for(Dart dit = traF.begin(); dit != traF.end(); dit = traF.next()) { + std::cout << "CurrentLevel = " << getCurrentLevel() << std::endl; + std::cout << "d = " << dit << " is Subdivided ? " << faceIsSubdivided(dit) << std::endl; + //if needed subdivide face if(!faceIsSubdivided(dit)) + { + std::cout << "subdivide face = " << dit << std::endl; subdivideFace(dit); - - //save darts from the central vertex of each subdivided face - incCurrentLevel() ; - saveRelationsAroundVertex(phi2(phi1(dit)), subdividedFaces); - decCurrentLevel() ; + ++j; + } } - - incCurrentLevel() ; - unsewAroundVertex(subdividedFaces); - decCurrentLevel() ; + std::cout << "nb subd faces = " << j << std::endl; // // Create inside volumes // Dart centralDart = NIL; - setCurrentLevel(vLevel + 1) ; // go to the next level to perform volume subdivision - for(Dart dit = traV.begin(); dit != traV.end(); dit = traV.next()) + std::vector > subdividedFaces; + subdividedFaces.reserve(128); + unsigned int i = 0; + Traversor3WV traWV(*this, old); + for(Dart ditWV = traWV.begin(); ditWV != traWV.end(); ditWV = traWV.next()) { - Map2::fillHole(phi1(dit)); + ++i; - Dart old = phi2(phi1(dit)); - Dart bc = newBoundaryCycle(faceDegree(old)); - sewVolumes(old, bc, false); + std::cout << "get max Level then creating new volumes = " << getMaxLevel() << std::endl; - if (isOrbitEmbedded(VERTEX)) + setCurrentLevel(getMaxLevel()) ; + Dart e = ditWV; + std::vector v ; + + do { - Dart it = bc; - do - { - copyDartEmbedding(VERTEX, it, phi1(phi3(it))); - it = phi1(it) ; - } while(it != bc) ; + v.push_back(phi1(e)); + v.push_back(phi1(phi1(e))); + + if(!Map2::isBoundaryEdge(phi1(e))) + subdividedFaces.push_back(std::pair(phi1(e),phi2(phi1(e)))); + + if(!Map2::isBoundaryEdge(phi1(phi1(e)))) + subdividedFaces.push_back(std::pair(phi1(phi1(e)),phi2(phi1(phi1(e))))); + + e = phi2(phi_1(e)); } + while(e != ditWV); - Dart dd = phi1(phi1(old)) ; - splitFace(old,dd) ; + splitSurfaceInVolume(v); - Dart ne = phi1(phi1(old)) ; + Dart dd = phi2(phi1(ditWV)); + Dart next = phi1(phi1(dd)) ; + //Map2::splitFace(dd, next) ; + splitFaceInVolume(dd, next); - cutEdge(ne); + Dart ne = phi2(phi_1(dd)); + //Map2::cutEdge(ne) ; + cutEdgeInVolume(ne); centralDart = phi1(ne); - Dart stop = phi2(phi1(ne)); - ne = phi2(ne); - do + dd = phi1(phi1(next)) ; + while(dd != ne) { - dd = phi1(phi1(phi1(ne))); - - splitFace(ne, dd) ; - - ne = phi2(phi_1(ne)); - dd = phi1(phi1(dd)); + Dart tmp = phi1(ne) ; + //Map2::splitFace(tmp, dd) ; + splitFaceInVolume(tmp, dd); + dd = phi1(phi1(dd)) ; } - while(dd != stop); + + setCurrentLevel(getMaxLevel() - 1) ; } - // - // Sew inside volumes - // + std::cout << "nb Vertices incident to volume : " << i << std::endl; + + setCurrentLevel(getMaxLevel()) ; + DartMarkerNoUnmark mf(*this); + + std::cout << "subdFaces size = " << subdividedFaces.size() << std::endl; for (std::vector >::iterator it = subdividedFaces.begin(); it != subdividedFaces.end(); ++it) { Dart f1 = phi2((*it).first); Dart f2 = phi2((*it).second); - if(isBoundaryFace(f1) && isBoundaryFace(f2)) + //if(isBoundaryFace(f1) && isBoundaryFace(f2)) + if(phi3(f1) == f1 && phi3(f2) == f2) + //if(!mf.isMarked(phi3(f1)) && !mf.isMarked(phi3(f2))) { - std::cout << "plop" << std::endl; sewVolumes(f1, f2, false); + mf.markOrbit(FACE, f1); + + Dart temp = f1; + do + { + propagateDartRelation(temp, m_phi3) ; + propagateDartRelation(phi3(temp), m_phi3) ; + temp = phi1(temp); + }while(temp != f1); } } (*volumeVertexFunctor)(centralDart) ; - popLevel() ; + embedOrbit(VERTEX, centralDart, getEmbedding(VERTEX, centralDart)); + propagateOrbitEmbedding(centralDart, VERTEX) ; + + + //A optimiser + setCurrentLevel(getMaxLevel()-1) ; + TraversorE travE2(*this); + for (Dart d = travE2.begin(); d != travE2.end(); d = travE2.next()) + { + setCurrentLevel(getMaxLevel()) ; + setCurrentLevel(getMaxLevel()-1) ; + embedOrbit(VERTEX, phi1(d), getEmbedding(VERTEX, phi1(d))); + } + setCurrentLevel(getMaxLevel()) ; + + setCurrentLevel(getMaxLevel()-1) ; + TraversorF travF2(*this) ; + for (Dart d = travF2.begin(); d != travF2.end(); d = travF2.next()) + { + setCurrentLevel(getMaxLevel()) ; + embedOrbit(VERTEX, phi2(phi1(d)), getEmbedding(VERTEX, phi2(phi1(d)))); + setCurrentLevel(getMaxLevel()-1) ; + } + setCurrentLevel(getMaxLevel()) ; + + std::cout << std::endl; + + popLevel(); } void Map3MR_PrimalAdapt::subdivideVolumeTetOcta(Dart d) @@ -548,38 +849,36 @@ void Map3MR_PrimalAdapt::subdivideVolumeTetOcta(Dart d) if(getCurrentLevel() == getMaxLevel()) addNewLevel() ; + unsigned int j = 0; + // - // Subdivide Faces + // Subdivide Faces and Edges // - std::vector > subdividedFaces; - subdividedFaces.reserve(128); - Traversor3WF traF(*this, old); for(Dart dit = traF.begin(); dit != traF.end(); dit = traF.next()) { + std::cout << "CurrentLevel = " << getCurrentLevel() << std::endl; + std::cout << "face level = " << faceLevel(dit) << std::endl; + //std::cout << "d = " << dit << " is Subdivided ? " << faceIsSubdivided(dit) << std::endl; + //if needed subdivide face if(!faceIsSubdivided(dit)) + { + std::cout << "subdivide face = " << dit << std::endl; subdivideFace(dit, S_TRI); + ++j; + } } // // Create inside volumes // Dart centralDart = NIL; - bool isNotTet = false; Traversor3WV traV(*this, old); - setCurrentLevel(getMaxLevel()) ; + setCurrentLevel(vLevel + 1) ; for(Dart dit = traV.begin(); dit != traV.end(); dit = traV.next()) { -// //check if neighboring volumes have to be subdivided -// Traversor3VW traVN(*this, dit); -// for(Dart ditN = traVN.begin(); ditN != traVN.end(); ditN = traVN.next()) -// { -// if(volumeLevel(ditN) == vLevel -1) -// std::cout << "to subdivide" << std::endl;//subdivideVolumeTetOcta(ditN); -// } - Dart f1 = phi1(dit); Dart e = dit; std::vector v ; @@ -591,6 +890,8 @@ void Map3MR_PrimalAdapt::subdivideVolumeTetOcta(Dart d) } while(e != dit); + std::cout << "v size = " << v.size() << std::endl; + splitVolume(v) ; //if is not a tetrahedron @@ -606,7 +907,8 @@ void Map3MR_PrimalAdapt::subdivideVolumeTetOcta(Dart d) cutEdge(ne); centralDart = phi1(ne); - (*volumeVertexFunctor)(centralDart) ; + //(*volumeVertexFunctor)(centralDart) ; + //propagateOrbitEmbedding(centralDart, VERTEX) ; Dart stop = phi2(phi1(ne)); ne = phi2(ne); @@ -626,14 +928,13 @@ void Map3MR_PrimalAdapt::subdivideVolumeTetOcta(Dart d) //switch inner faces if(isNotTet) { + DartMarkerStore me(*this); for(Dart dit = traV.begin(); dit != traV.end(); dit = traV.next()) { Dart x = phi_1(phi2(phi1(dit))); Dart f = x; - DartMarkerStore me(*this); - do { Dart f3 = phi3(f); @@ -641,7 +942,7 @@ void Map3MR_PrimalAdapt::subdivideVolumeTetOcta(Dart d) if(!me.isMarked(f3)) { Dart tmp = phi_1(phi2(phi_1(phi2(phi_1(f3))))); //future voisin par phi2 - centralDart = tmp; + //centralDart = tmp; Dart f32 = phi2(f3); swapEdges(f3, tmp); @@ -655,11 +956,211 @@ void Map3MR_PrimalAdapt::subdivideVolumeTetOcta(Dart d) } embedOrbit(VERTEX, centralDart, getEmbedding(VERTEX, centralDart)); - - //(*volumeVertexFunctor)(centralDart) ; + (*volumeVertexFunctor)(centralDart) ; + propagateOrbitEmbedding(centralDart, VERTEX) ; } popLevel(); } +//void Map3MR_PrimalAdapt::subdivideVolumeTetOctaTemp(Dart d) +//{ +// assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideVolumeTetOcta : called with a dart inserted after current level") ; +// assert(!volumeIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ; +// +// unsigned int vLevel = volumeLevel(d); +// Dart old = volumeOldestDart(d); +// +// pushLevel() ; +// setCurrentLevel(vLevel) ; // go to the level of the face to subdivide its edges +// +// if(getCurrentLevel() == getMaxLevel()) +// addNewLevel() ; +// +// unsigned int j = 0; +// +// // +// // Subdivide Faces and Edges +// // +// Traversor3WF traF(*this, old); +// for(Dart dit = traF.begin(); dit != traF.end(); dit = traF.next()) +// { +// std::cout << "CurrentLevel = " << getCurrentLevel() << std::endl; +// std::cout << "face level = " << faceLevel(dit) << std::endl; +// +// //if needed subdivide face +// if(!faceIsSubdivided(dit)) +// { +// std::cout << "subdivide face = " << dit << std::endl; +// subdivideFace(dit, S_TRI); +// ++j; +// } +// } +// +// // +// // Create inside volumes +// // +// Dart centralDart = NIL; +// bool isNotTet = false; +// Traversor3WV traV(*this, old); +// setCurrentLevel(vLevel + 1) ; +// for(Dart dit = traV.begin(); dit != traV.end(); dit = traV.next()) +// { +// Dart f1 = phi1(dit); +// Dart e = dit; +// std::vector v ; +// +// do +// { +// v.push_back(phi1(e)); +// e = phi2(phi_1(e)); +// } +// while(e != dit); +// +// std::cout << "v size = " << v.size() << std::endl; +// +// } +// +// +// popLevel(); +//} + } //end namespace CGoGN + + +//void Map3MR_PrimalAdapt::saveRelationsAroundVertex(Dart d, std::vector >& vd) +//{ +// assert(getDartLevel(d) <= getCurrentLevel() || !"saveRelationsAroundVertex : called with a dart inserted after current level") ; +// +// //le brin est forcement du niveau cur +// Dart dit = d; +// +// do +// { +// vd.push_back(std::pair(dit,phi2(dit))); +// +// dit = phi2(phi_1(dit)); +// +// }while(dit != d); +//} +// +//void Map3MR_PrimalAdapt::unsewAroundVertex(std::vector >& vd) +//{ +// //unsew the edge path +// for(std::vector >::iterator it = vd.begin() ; it != vd.end() ; ++it) +// { +// Dart dit = (*it).first; +// Dart dit2 = (*it).second; +// +// Map2::unsewFaces(dit); +// +// if(isOrbitEmbedded(VERTEX)) +// { +// copyDartEmbedding(VERTEX, phi2(dit2), dit); +// copyDartEmbedding(VERTEX, phi2(dit), dit2); +// } +// +// if(isOrbitEmbedded(EDGE)) +// { +// +// } +// } +//} +// unsigned int vLevel = volumeLevel(d); +// Dart old = volumeOldestDart(d); +// +// Traversor3WV traV(*this, old); +// +// pushLevel() ; +// setCurrentLevel(vLevel) ; // go to the level of the face to subdivide its edges +// +// if(getCurrentLevel() == getMaxLevel()) +// addNewLevel() ; +// +// // +// // Subdivide Faces +// // +// std::vector > subdividedFaces; +// subdividedFaces.reserve(128); +// +// Traversor3WF traF(*this, old); +// for(Dart dit = traF.begin(); dit != traF.end(); dit = traF.next()) +// { +// //if needed subdivide face +// if(!faceIsSubdivided(dit)) +// subdivideFace(dit); +// +// //save darts from the central vertex of each subdivided face +// incCurrentLevel() ; +// saveRelationsAroundVertex(phi2(phi1(dit)), subdividedFaces); +// decCurrentLevel() ; +// } +// +// incCurrentLevel() ; +// unsewAroundVertex(subdividedFaces); +// decCurrentLevel() ; +// +// // +// // Create inside volumes +// // +// Dart centralDart = NIL; +// setCurrentLevel(vLevel + 1) ; // go to the next level to perform volume subdivision +// for(Dart dit = traV.begin(); dit != traV.end(); dit = traV.next()) +// { +// Map2::fillHole(phi1(dit)); +// +// Dart old = phi2(phi1(dit)); +// Dart bc = newBoundaryCycle(faceDegree(old)); +// sewVolumes(old, bc, false); +// +// if (isOrbitEmbedded(VERTEX)) +// { +// Dart it = bc; +// do +// { +// copyDartEmbedding(VERTEX, it, phi1(phi3(it))); +// it = phi1(it) ; +// } while(it != bc) ; +// } +// +// Dart dd = phi1(phi1(old)) ; +// splitFace(old,dd) ; +// +// Dart ne = phi1(phi1(old)) ; +// +// cutEdge(ne); +// centralDart = phi1(ne); +// +// Dart stop = phi2(phi1(ne)); +// ne = phi2(ne); +// do +// { +// dd = phi1(phi1(phi1(ne))); +// +// splitFace(ne, dd) ; +// +// ne = phi2(phi_1(ne)); +// dd = phi1(phi1(dd)); +// } +// while(dd != stop); +// } +// +// // +// // Sew inside volumes +// // +// for (std::vector >::iterator it = subdividedFaces.begin(); it != subdividedFaces.end(); ++it) +// { +// Dart f1 = phi2((*it).first); +// Dart f2 = phi2((*it).second); +// +// if(isBoundaryFace(f1) && isBoundaryFace(f2)) +// { +// std::cout << "plop" << std::endl; +// sewVolumes(f1, f2, false); +// } +// } +// +// (*volumeVertexFunctor)(centralDart) ; +// popLevel() ; + + diff --git a/src/Topology/map/map3MR/map3MR_PrimalRegular.cpp b/src/Topology/map/map3MR/map3MR_PrimalRegular.cpp index e999c38b17b8db5334e105f3f43dd4543c2d1add..49a6e96d6daca401e7180f4c0598ddb3b0e8727f 100644 --- a/src/Topology/map/map3MR/map3MR_PrimalRegular.cpp +++ b/src/Topology/map/map3MR/map3MR_PrimalRegular.cpp @@ -146,8 +146,8 @@ void Map3MR_PrimalRegular::addNewLevelTetraOcta(bool embedNewVertices) } cutEdge(d) ; - travE.mark(d) ; - travE.mark(phi1(d)) ; + travE.skip(d) ; + travE.skip(phi1(d)) ; // When importing MR files // if(embedNewVertices) @@ -165,19 +165,19 @@ void Map3MR_PrimalRegular::addNewLevelTetraOcta(bool embedNewVertices) Dart dd = phi1(old) ; Dart e = phi1(phi1(dd)) ; splitFace(dd, e) ; - travF.mark(dd) ; + travF.skip(dd) ; dd = e ; e = phi1(phi1(dd)) ; splitFace(dd, e) ; - travF.mark(dd) ; + travF.skip(dd) ; dd = e ; e = phi1(phi1(dd)) ; splitFace(dd, e) ; - travF.mark(dd) ; + travF.skip(dd) ; - travF.mark(e) ; + travF.skip(e) ; } //3. create inside volumes @@ -308,8 +308,8 @@ void Map3MR_PrimalRegular::addNewLevel(bool embedNewVertices) } cutEdge(d) ; - travE.mark(d) ; - travE.mark(phi1(d)) ; + travE.skip(d) ; + travE.skip(phi1(d)) ; // When importing MR files : activated for DEBUG if(embedNewVertices) @@ -330,7 +330,7 @@ void Map3MR_PrimalRegular::addNewLevel(bool embedNewVertices) Dart ne = phi2(phi_1(dd)) ; cutEdge(ne) ; // cut the new edge to insert the central vertex - travF.mark(dd) ; + travF.skip(dd) ; // When importing MR files : activated for DEBUG if(embedNewVertices) @@ -341,10 +341,10 @@ void Map3MR_PrimalRegular::addNewLevel(bool embedNewVertices) { // linked to the central vertex Dart tmp = phi1(ne) ; splitFace(tmp, dd) ; - travF.mark(tmp) ; + travF.skip(tmp) ; dd = phi1(phi1(dd)) ; } - travF.mark(ne) ; + travF.skip(ne) ; } //3. create inside volumes @@ -359,7 +359,7 @@ void Map3MR_PrimalRegular::addNewLevel(bool embedNewVertices) Traversor3WV traWV(*this, dit); for(Dart ditWV = traWV.begin(); ditWV != traWV.end(); ditWV = traWV.next()) { - setCurrentLevel(getMaxLevel()) ; + setCurrentLevel(getMaxLevel()) ; //Utile ? Dart e = ditWV; std::vector v ; @@ -397,7 +397,7 @@ void Map3MR_PrimalRegular::addNewLevel(bool embedNewVertices) dd = phi1(phi1(dd)) ; } - setCurrentLevel(getMaxLevel() - 1) ; + setCurrentLevel(getMaxLevel() - 1) ; //Utile ? } setCurrentLevel(getMaxLevel()) ; diff --git a/src/Utils/frameManipulator.cpp b/src/Utils/frameManipulator.cpp index 87846548cdc9f5bc7e1659fbcd331fff6652daac..7d7eebdef465672d2546fd753a3556e953872c3a 100644 --- a/src/Utils/frameManipulator.cpp +++ b/src/Utils/frameManipulator.cpp @@ -865,7 +865,7 @@ float FrameManipulator::distanceFromMouse(int dx, int dy) float FrameManipulator::scaleFromMouse(int dx, int dy) { - if (fabs(dx) > fabs(dy)) + if (abs(dx) > abs(dy)) { if (dx>0) return 1.01; diff --git a/src/Utils/svg.cpp b/src/Utils/svg.cpp index ad76bffd0ed9a12c9cb0e8ce2ffb8df11f729693..d3ebe4b40da933c7b6a5f20027c5efbd60b61509 100644 --- a/src/Utils/svg.cpp +++ b/src/Utils/svg.cpp @@ -379,24 +379,23 @@ SVGOut::SVGOut(const std::string& filename, const glm::mat4& model, const glm::m } glGetIntegerv(GL_VIEWPORT, &(m_viewport[0])); -// -// *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; } + +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])); +} + + SVGOut::~SVGOut() { - if (m_out->good()) + if (m_out && (m_out->good())) { closeFile(); } @@ -418,6 +417,10 @@ void SVGOut::setWidth(float 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; @@ -433,7 +436,6 @@ void SVGOut::closeFile() *m_out << ""<< std::endl; *m_out << "" << std::endl; - // here do the sort in necessary ? std::vector vds; sortSimpleDepth(vds); @@ -443,10 +445,6 @@ void SVGOut::closeFile() m_objs[it->obj]->saveOne(*m_out,it->id, m_bbX1-m_bbX0); } -// for (std::vector::iterator it = m_objs.begin(); it != m_objs.end(); ++it) -// { -// (*it)->save(*m_out); -// } *m_out << "" << std::endl; *m_out << "" << std::endl; @@ -456,11 +454,6 @@ void SVGOut::closeFile() void SVGOut::computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsigned& d) { - // here do the sort in necessary - a = 100000; - b = 100000; - c = 0; - d = 0; for (std::vector::iterator it = m_objs.begin(); it != m_objs.end(); ++it) { @@ -602,6 +595,76 @@ void SVGOut::sortSimpleDepth(std::vector& vds) + + + +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(); +} + + } // namespace SVG } // namespace Utils } // namespace CGoGN