diff --git a/include/Algo/Geometry/centroid.h b/include/Algo/Geometry/centroid.h index f8989304bdd758492f5ce9eb7be5d98f399aed23..f25c4354b28f1d7c6dec10b8660607534b9d394d 100644 --- a/include/Algo/Geometry/centroid.h +++ b/include/Algo/Geometry/centroid.h @@ -54,6 +54,21 @@ namespace Geometry template EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0); +/** +* Compute volume centroid weighted by edge length (generic version) +* Pre: closed volume & embedded vertices +* Template param: +* PFP: as usual +* EMBV: attributes vector type or cell type (VertexCell, FaceCell, ...) +* EMB: type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...) +* @param map the map +* @param d a dart of the face +* @param attributs the vector of attribute or cell +*/ +template +EMB volumeCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0); + + /** * Compute volume centroid * Pre: closed volume & embedded vertices @@ -62,11 +77,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns * @param position the vector of attribute */ template -typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread = 0) +inline typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread = 0) { return volumeCentroidGen, typename PFP::VEC3>(map, d, position, thread); } +/** +* Compute volume centroid weighted by edge length +* Pre: closed volume & embedded vertices + * @param map the map + * @param d a dart of the face + * @param position the vector of attribute + */ +template +inline typename PFP::VEC3 volumeCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread = 0) +{ + return volumeCentroidELWGen, typename PFP::VEC3>(map, d, position, thread); +} + + /** * Compute face centroid (generic version) * Template param: @@ -80,6 +109,19 @@ typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAt template EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); +/** + * Compute face centroid weighted by edge length (generic version) + * Template param: + * PFP: as usual + * EMBV: attributes vector type or cell type (VertexCell, FaceCell, ...) + * EMB: type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...) + * @param map the map + * @param d a dart of the face + * @param attributs the vector of attribute or cell + */ +template +EMB faceCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); + /** * Compute face centroid * Pre: closed face & embedded vertices @@ -93,6 +135,20 @@ typename PFP::VEC3 faceCentroid(typename PFP::MAP& map, Dart d, const VertexAttr return faceCentroidGen, typename PFP::VEC3>(map, d, position); } +/** +* Compute face centroid weighted by edge length +* Pre: closed face & embedded vertices + * @param map the map + * @param d a dart of the face + * @param position the vector of attribute + */ +template +typename PFP::VEC3 faceCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +{ + return faceCentroidELWGen, typename PFP::VEC3>(map, d, position); +} + + /** * Compute vertex neighbours centroid (generic version) * Template param: @@ -118,11 +174,41 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co return vertexNeighborhoodCentroidGen, typename PFP::VEC3>(map, d, position); } +/** + * Compute centroid of all faces + * @param map the map + * @param position position vertex attribute + * @param face_centroid centroid face attribute + * @param select the selector + * @param thread the thread id (default 0) + */ template void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; +/** + * Compute centroid of all faces (Edge Length Weighted) + * @param map the map + * @param position position vertex attribute + * @param face_centroid centroid face attribute + * @param select the selector + * @param thread the thread id (default 0) + */ +template +void computeCentroidELWFaces(typename PFP::MAP& map, + const VertexAttribute& position, FaceAttribute& face_centroid, + const FunctorSelect& select = allDarts, unsigned int thread = 0) ; + + +/** + * Compute neighborhood centroid of all vertices + * @param map the map + * @param position position vertex attribute + * @param vertex_centroid centroid vertex attribute + * @param select the selector + * @param thread the thread id (default 0) + */ template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, @@ -131,11 +217,40 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, namespace Parallel { +/** + * Compute centroid of all faces + * @param map the map + * @param position position vertex attribute + * @param face_centroid centroid face attribute + * @param select the selector + * @param nbth the number of threads + */ template void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; +/** + * Compute centroid of all faces (Edge Length Weighted) + * @param map the map + * @param position position vertex attribute + * @param face_centroid centroid face attribute + * @param select the selector + * @param nbth the number of threads + */ +template +void computeCentroidELWFaces(typename PFP::MAP& map, + const VertexAttribute& position, FaceAttribute& face_centroid, + const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; + +/** + * Compute neighborhood centroid of all vertices (in parallel) + * @param map the map + * @param position position vertex attribute + * @param vertex_centroid centroid vertex attribute + * @param select the selector + * @param nbth the number of threads + */ template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, @@ -185,6 +300,11 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; +template +void computeCentroidELWVolumes(typename PFP::MAP& map, + const VertexAttribute& position, VolumeAttribute& vol_centroid, + const FunctorSelect& select = allDarts, unsigned int thread = 0) ; + /** * compute centroid of all vertices * @param map the map @@ -206,6 +326,12 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; +template +void computeCentroidELWVolumes(typename PFP::MAP& map, + const VertexAttribute& position, VolumeAttribute& vol_centroid, + const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; + + template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, diff --git a/include/Algo/Geometry/centroid.hpp b/include/Algo/Geometry/centroid.hpp index bb5b1841e5c43a8bc6779bc27e44838280873e2b..bc3e91b3acb90720b4903ebc495bb69a034aaae7 100644 --- a/include/Algo/Geometry/centroid.hpp +++ b/include/Algo/Geometry/centroid.hpp @@ -59,6 +59,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns return center ; } +template +EMB volumeCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread) +{ + EMB center = AttribOps::zero(); + double count=0.0; + Traversor3WE t(map, d,false,thread) ; + for(Dart it = t.begin(); it != t.end();it = t.next()) + { + EMB e1 = attributs[it]; + EMB e2 = attributs[map.phi1(it)]; + double l = (e2-e1).norm(); + center += (e1+e2)*l; + count += 2.0*l ; + } + center /= double(count); + return center ; +} + + template EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { @@ -74,6 +93,26 @@ EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) return center ; } + +template +EMB faceCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) +{ + EMB center = AttribOps::zero(); + double count=0.0; + Traversor2FE t(map, d) ; + for(Dart it = t.begin(); it != t.end(); it = t.next()) + { + EMB e1 = attributs[it]; + EMB e2 = attributs[map.phi1(it)]; + double l = (e2-e1).norm(); + center += (e1+e2)*l; + count += 2.0*l ; + } + center /= double(count); + return center ; +} + + template EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { @@ -98,6 +137,14 @@ void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute(map, d, position) ; } +template +void computeCentroidELWFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select, unsigned int thread) +{ + TraversorF t(map, select,thread) ; + for(Dart d = t.begin(); d != t.end(); d = t.next()) + face_centroid[d] = faceCentroidELW(map, d, position) ; +} + template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select, unsigned int thread) { @@ -127,6 +174,23 @@ public: } }; +template +class FunctorComputeCentroidELWFaces: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + FaceAttribute& m_fcentroid; +public: + FunctorComputeCentroidELWFaces( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& fcentroid): + FunctorMapThreaded(map), m_position(position), m_fcentroid(fcentroid) + { } + + void run(Dart d, unsigned int threadID) + { + m_fcentroid[d] = faceCentroidELW(this->m_map, d, m_position) ; + } +}; + + template void computeCentroidFaces(typename PFP::MAP& map, @@ -137,6 +201,15 @@ void computeCentroidFaces(typename PFP::MAP& map, Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); } +template +void computeCentroidELWFaces(typename PFP::MAP& map, + const VertexAttribute& position, FaceAttribute& face_centroid, + const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorComputeCentroidELWFaces funct(map,position,face_centroid); + Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); +} + template class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded @@ -195,6 +268,15 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute(map, d, position,thread) ; } +template +void computeCentroidELWVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select, unsigned int thread) +{ + TraversorW t(map, select,thread) ; + for(Dart d = t.begin(); d != t.end(); d = t.next()) + vol_centroid[d] = Surface::Geometry::volumeCentroidELW(map, d, position,thread) ; +} + + namespace Parallel { template @@ -212,6 +294,22 @@ public: m_vol_centroid[d] = Surface::Geometry::volumeCentroid(this->m_map, d, m_position,threadID) ; } }; + +template +class FunctorComputeCentroidELWVolumes: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + VolumeAttribute& m_vol_centroid; +public: + FunctorComputeCentroidELWVolumes( typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid): + FunctorMapThreaded(map), m_position(position), m_vol_centroid(vol_centroid) + { } + + void run(Dart d, unsigned int threadID) + { + m_vol_centroid[d] = Surface::Geometry::volumeCentroidELW(this->m_map, d, m_position,threadID) ; + } +}; template void computeCentroidVolumes(typename PFP::MAP& map, @@ -223,6 +321,16 @@ void computeCentroidVolumes(typename PFP::MAP& map, } +template +void computeCentroidELWVolumes(typename PFP::MAP& map, + const VertexAttribute& position, VolumeAttribute& vol_centroid, + const FunctorSelect& select, unsigned int nbth) +{ + FunctorComputeCentroidELWVolumes funct(map,position,vol_centroid); + Algo::Parallel::foreach_cell(map, funct, nbth, true, select); +} + + template class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded { @@ -256,8 +364,6 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, - - } // namespace Algo } // namespace CGoGN diff --git a/include/Algo/Render/GL2/explodeVolumeRender.hpp b/include/Algo/Render/GL2/explodeVolumeRender.hpp index b3ec03c9cf248f9d15bffa2c29cd1cceca5f6702..e7bd4302015f8c9b2bc2a5f58a5dcfb1b08d94fe 100644 --- a/include/Algo/Render/GL2/explodeVolumeRender.hpp +++ b/include/Algo/Render/GL2/explodeVolumeRender.hpp @@ -28,7 +28,7 @@ #include "Topology/generic/cellmarker.h" #include "Algo/Geometry/centroid.h" #include "Topology/generic/autoAttributeHandler.h" - +#include "Algo/Geometry/normal.h" #include "Algo/Geometry/basic.h" namespace CGoGN @@ -99,7 +99,7 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri typedef typename PFP::REAL REAL; VolumeAutoAttribute centerVolumes(map, "centerVolumes"); - Algo::Volume::Geometry::Parallel::computeCentroidVolumes(map, positions, centerVolumes, good); + Algo::Volume::Geometry::computeCentroidELWVolumes(map, positions, centerVolumes, good); std::vector buffer; buffer.reserve(16384); @@ -108,120 +108,145 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri bufferColors.reserve(16384); std::vector bufferNormals; bufferNormals.reserve(16384); + std::vector normals; bufferNormals.reserve(20); + std::vector vertices; + bufferNormals.reserve(20); + TraversorCell traFace(map, good); for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { - // compute normals normals.clear(); - VEC3 centerFace(0); - unsigned int nbs=0; + vertices.clear(); + VEC3 centerFace = Algo::Surface::Geometry::faceCentroid(map, d, positions); + VEC3 centerNormalFace = Algo::Surface::Geometry::newellNormal(map,d,positions); + Dart a = d; do { - VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart(map,a,positions); + VEC3 v1 = positions[a] - centerFace; + v1.normalize(); Dart e = map.phi1(a); - VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart(map,e,positions); + VEC3 v2 = positions[map.phi1(e)] - centerFace; + v2.normalize(); VEC3 N = v1^v2; + double l = N.norm(); - if (l>0.000001) - { - N /= l; - normals.push_back(N); - } + if (l<0.01) + N = centerNormalFace; else { - normals.push_back(VEC3(9,9,9)); + N /= l; + if (N*centerNormalFace < 0.707) + N = centerNormalFace; } - centerFace += positions[a]; + normals.push_back(N); + vertices.push_back(positions[e]); + +// VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart(map,a,positions); +// Dart e = map.phi1(a); +// VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart(map,e,positions); +// v1.normalize(); +// v2.normalize(); +// VEC3 N = v1^v2; +// double l = N.norm(); +// double ll = fabs(N*centerNormalFace()); +// if ((l<0.2) && l<0 + +// if (l<0.3) +// { +// N = centerNormalFace; +// } +// else +// { +// if (N*centerNormalFace < 0.0) +// N /= -l; +// else +// N /= l; +// } +// if ((l < 0.5) || (N*centerNormalFace < 0.0)) +// { +// N = centerNormalFace; +// } + + + + + +// if (N*centerNormalFace < 0.0) +// { +// std::cout << "INVERTED" <::iterator iv = vertices.begin(); typename std::vector::iterator in = normals.begin(); - typename std::vector::iterator inb = normals.begin(); - typename std::vector::iterator inc = normals.begin(); - a = map.phi1(d); - while ((*in)[0]>1.0) - { - a = map.phi1(a); - ++in; - } - inb = in; - ++inb; - Dart b = map.phi1(a); - while ((*inb)[0]>1.0) - { - b = map.phi1(b); - ++inb; - } - inc = inb; - ++inc; - Dart c = map.phi1(b); - while ((*inc)[0]>1.0) + + if (nbs == 3) { - c = map.phi1(c); - ++inc; + buffer.push_back(centerVolumes[d]); + bufferColors.push_back(centerFace); + bufferNormals.push_back(centerNormalFace); // unsused just for fill + + buffer.push_back(*iv++); + bufferNormals.push_back(*in++); + bufferColors.push_back(volCol); + + buffer.push_back(*iv++); + bufferNormals.push_back(*in++); + bufferColors.push_back(volCol); + + buffer.push_back(*iv++); + bufferNormals.push_back(*in++); + bufferColors.push_back(volCol); } - // loop to cut a polygon in triangle on the fly (works only with convex faces) - do + else { - buffer.push_back(centerVolumes[a]); - bufferColors.push_back(centerFace); - bufferNormals.push_back(centerFace); // unsused just for fill - buffer.push_back(positions[a]); - bufferColors.push_back(colorPerXXX[a]); - bufferNormals.push_back(*in); - buffer.push_back(positions[b]); - bufferColors.push_back(colorPerXXX[b]); - bufferNormals.push_back(*inb); - buffer.push_back(positions[c]); - bufferColors.push_back(colorPerXXX[c]); - bufferNormals.push_back(*inc); - b = c; - inb = inc; - inc++; - c = map.phi1(b); - while ((*inc)[0]>1.0) + for (unsigned int i=0; i::iterator in = normals.begin(); - a = d; - Dart b = map.phi1(a); - Dart c = map.phi1(b); - // loop to cut a polygon in triangle on the fly (works only with convex faces) - do - { - buffer.push_back(centerVolumes[a]); - bufferColors.push_back(centerFace); - bufferNormals.push_back(centerFace); // unsused just for fill - buffer.push_back(positions[a]); - bufferColors.push_back(colorPerXXX[a]); - bufferNormals.push_back(normals.back()); - buffer.push_back(positions[b]); - bufferColors.push_back(colorPerXXX[b]); - bufferNormals.push_back(*in++); - buffer.push_back(positions[c]); - bufferColors.push_back(colorPerXXX[c]); - bufferNormals.push_back(*in); - b = c; - c = map.phi1(b); - } while (c != a); - */ + } } @@ -274,7 +299,7 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri typedef typename PFP::REAL REAL; VolumeAutoAttribute centerVolumes(map, "centerVolumes"); - Algo::Volume::Geometry::Parallel::computeCentroidVolumes(map, positions, centerVolumes, good); + Algo::Volume::Geometry::computeCentroidELWVolumes(map, positions, centerVolumes, good); std::vector buffer; buffer.reserve(16384); @@ -283,19 +308,22 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri bufferColors.reserve(16384); std::vector bufferNormals; bufferNormals.reserve(16384); + std::vector normals; bufferNormals.reserve(20); + std::vector vertices; + bufferNormals.reserve(20); TraversorCell traFace(map, good); for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { - // compute normals - normals.clear(); + vertices.clear(); VEC3 centerFace(0); - unsigned int nbs=0; + VEC3 centerNormalFace(0); + Dart a = d; do { @@ -303,93 +331,68 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri Dart e = map.phi1(a); VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart(map,e,positions); VEC3 N = v1^v2; - N.normalize(); - normals.push_back(N); + double l = N.norm(); + if (l>0.000001) + { + N /= l; + normals.push_back(N); + centerNormalFace += N; + vertices.push_back(positions[e]); + centerFace += positions[e]; + } a = e; - centerFace += positions[a]; - nbs++; } while (a != d); - centerFace /= float(nbs); - + centerFace /= float(vertices.size()); + centerNormalFace.normalize(); + + unsigned int nbs = vertices.size(); + // just to have more easy algo further + vertices.push_back(vertices.front()); + normals.push_back(normals.front()); + typename std::vector::iterator iv = vertices.begin(); typename std::vector::iterator in = normals.begin(); - typename std::vector::iterator inb = normals.begin(); - typename std::vector::iterator inc = normals.begin(); - a = map.phi1(d); - while ((*in)[0]>1.0) - { - a = map.phi1(a); - ++in; - } - inb = in; - ++inb; - Dart b = map.phi1(a); - while ((*inb)[0]>1.0) - { - b = map.phi1(b); - ++inb; - } - inc = inb; - ++inc; - Dart c = map.phi1(b); - while ((*inc)[0]>1.0) - { - c = map.phi1(c); - ++inc; - } - // loop to cut a polygon in triangle on the fly (works only with convex faces) - do - { - buffer.push_back(centerVolumes[a]); - bufferColors.push_back(centerFace); - bufferNormals.push_back(centerFace); // unsused just for fill - buffer.push_back(positions[a]); - bufferColors.push_back(m_globalColor); - bufferNormals.push_back(*in); - buffer.push_back(positions[b]); - bufferColors.push_back(m_globalColor); - bufferNormals.push_back(*inb); - buffer.push_back(positions[c]); - bufferColors.push_back(m_globalColor); - bufferNormals.push_back(*inc); - b = c; - inb = inc; - inc++; - c = map.phi1(b); - while (*inc[0]>1.0) - { - c = map.phi1(c); - ++inc; - } - } while (c != a); - -/* - typename std::vector::iterator in = normals.begin(); - a = d; - Dart b = map.phi1(a); - Dart c = map.phi1(b); - // loop to cut a polygon in triangle on the fly (works only with convex faces) - do + if (nbs == 3) { buffer.push_back(centerVolumes[d]); bufferColors.push_back(centerFace); - bufferNormals.push_back(centerFace); // unsused just for fill - buffer.push_back(positions[d]); - bufferColors.push_back(m_globalColor); - bufferNormals.push_back(normals.back()); - buffer.push_back(positions[b]); + bufferNormals.push_back(centerNormalFace); // unsused just for fill + + buffer.push_back(*iv++); + bufferNormals.push_back(*in++); bufferColors.push_back(m_globalColor); + + buffer.push_back(*iv++); bufferNormals.push_back(*in++); - buffer.push_back(positions[c]); bufferColors.push_back(m_globalColor); - bufferNormals.push_back(*in); - b = c; - c = map.phi1(b); - } while (c != d); -*/ + buffer.push_back(*iv++); + bufferNormals.push_back(*in++); + bufferColors.push_back(m_globalColor); + } + else + { + for (unsigned int i=0; i centerVolumes(map, "centerVolumes"); - Algo::Volume::Geometry::Parallel::computeCentroidVolumes(map, positions, centerVolumes, good); + Algo::Volume::Geometry::computeCentroidELWVolumes(map, positions, centerVolumes, good); std::vector buffer; buffer.reserve(16384); @@ -469,25 +472,46 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { - VEC3 centerFace = Algo::Surface::Geometry::faceCentroid(map, d, positions); - - Dart a = d; - Dart b = map.phi1(a); + VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW(map, d, positions); + VEC3 volColor = colorPerXXX[d]; + + Dart b = d; Dart c = map.phi1(b); - // loop to cut a polygon in triangle on the fly (works only with convex faces) - do + Dart a = map.phi1(c); + + if (map.phi1(a) == d) { buffer.push_back(centerVolumes[d]); bufferColors.push_back(centerFace); - buffer.push_back(positions[d]); - bufferColors.push_back(colorPerXXX[d]); + buffer.push_back(positions[b]); - bufferColors.push_back(colorPerXXX[b]); + bufferColors.push_back(volColor); + buffer.push_back(positions[c]); + bufferColors.push_back(volColor); + c = map.phi1(c); buffer.push_back(positions[c]); - bufferColors.push_back(colorPerXXX[c]); - b = c; - c = map.phi1(b); - } while (c != d); + bufferColors.push_back(volColor); + } + else + { + + // loop to cut a polygon in triangle on the fly (ceter point method) + do + { + buffer.push_back(centerVolumes[d]); + bufferColors.push_back(centerFace); + + buffer.push_back(centerFace); + bufferColors.push_back(volColor); + + buffer.push_back(positions[b]); + bufferColors.push_back(volColor); + buffer.push_back(positions[c]); + bufferColors.push_back(volColor); + b = c; + c = map.phi1(b); + } while (b != d); + } } m_nbTris = buffer.size()/4; @@ -545,7 +569,7 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu typedef typename PFP::REAL REAL; VolumeAutoAttribute centerVolumes(map, "centerVolumes"); - Algo::Volume::Geometry::Parallel::computeCentroidVolumes(map, positions, centerVolumes, good); + Algo::Volume::Geometry::computeCentroidELWVolumes(map, positions, centerVolumes, good); std::vector buffer; buffer.reserve(16384); @@ -558,27 +582,48 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { - VEC3 centerFace = Algo::Surface::Geometry::faceCentroid(map, d, positions); + VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW(map, d, positions); - Dart a = d; - Dart b = map.phi1(a); + Dart b = d; Dart c = map.phi1(b); - // loop to cut a polygon in triangle on the fly (works only with convex faces) - do + Dart a = map.phi1(c); + + if (map.phi1(a) == d) { buffer.push_back(centerVolumes[d]); bufferColors.push_back(centerFace); - buffer.push_back(positions[d]); - bufferColors.push_back(m_globalColor); + buffer.push_back(positions[b]); bufferColors.push_back(m_globalColor); buffer.push_back(positions[c]); bufferColors.push_back(m_globalColor); - b = c; - c = map.phi1(b); - } while (c != d); + c = map.phi1(c); + buffer.push_back(positions[c]); + bufferColors.push_back(m_globalColor); + } + else + { + + // loop to cut a polygon in triangle on the fly (ceter point method) + do + { + buffer.push_back(centerVolumes[d]); + bufferColors.push_back(centerFace); + + buffer.push_back(centerFace); + bufferColors.push_back(m_globalColor); + + buffer.push_back(positions[b]); + bufferColors.push_back(m_globalColor); + buffer.push_back(positions[c]); + bufferColors.push_back(m_globalColor); + b = c; + c = map.phi1(b); + } while (b != d); + } } + m_nbTris = buffer.size()/4; m_vboPos->allocate(buffer.size()); @@ -686,9 +731,7 @@ inline void ExplodeVolumeRender::setAmbiant(const Geom::Vec4f& ambiant) inline void ExplodeVolumeRender::setBackColor(const Geom::Vec4f& color) { - if (m_smooth) - m_shaderS->setBackColor(color); - else + if (!m_smooth) m_shader->setBackColor(color); } diff --git a/include/Geometry/vector_gen.h b/include/Geometry/vector_gen.h index 35098f33db06d3d6aa3b5baf76d984a712d1b49f..8ebed15b0b16273d6d6fd0b3636a32405263f982 100644 --- a/include/Geometry/vector_gen.h +++ b/include/Geometry/vector_gen.h @@ -114,6 +114,8 @@ public: Vector operator+(const Vector& v) const ; Vector operator-(const Vector& v) const ; + + Vector operator-() const ; Vector operator*(T a) const ; diff --git a/include/Geometry/vector_gen.hpp b/include/Geometry/vector_gen.hpp index 4456e9fad5803ed6cf46b38066fc57c0aa884e39..bb6dbc5a79e3cf40c0cfbbbb492408bc96aac3d3 100644 --- a/include/Geometry/vector_gen.hpp +++ b/include/Geometry/vector_gen.hpp @@ -210,6 +210,16 @@ inline Vector Vector::operator-(const Vector& v) const return res ; } +template +inline Vector Vector::operator-() const +{ + Vector res ; + for (unsigned int i = 0; i < DIM; ++i) + res[i] = - m_data[i] ; + return res ; +} + + template inline Vector Vector::operator*(T a) const { diff --git a/include/Utils/Shaders/shaderExplodeSmoothVolumes.frag b/include/Utils/Shaders/shaderExplodeSmoothVolumes.frag index 9cf951a9e1649d85b9cf15ff6e83af76ea863647..658c4cd3f594203c3c6ebef2145b9eb296c04635 100644 --- a/include/Utils/Shaders/shaderExplodeSmoothVolumes.frag +++ b/include/Utils/Shaders/shaderExplodeSmoothVolumes.frag @@ -1,7 +1,6 @@ // ShaderExplodeSmoothVolumes::fragmentShaderText uniform vec4 ambient; -uniform vec4 backColor; VARYING_FRAG vec3 normalFS; VARYING_FRAG vec3 lightFS; @@ -10,10 +9,6 @@ VARYING_FRAG vec3 colorVert; void main() { - float lambertTerm = dot(normalize(normalFS),normalize(lightFS)); - if (lambertTerm > 0.0) - gl_FragColor = ambient + vec4(colorVert*lambertTerm, 1.0); - else - gl_FragColor = ambient - backColor*lambertTerm; - + float lambertTerm = abs(dot(normalize(normalFS),normalize(lightFS))); + gl_FragColor = ambient + vec4(colorVert*lambertTerm, 1.0); } diff --git a/include/Utils/Shaders/shaderExplodeSmoothVolumes.h b/include/Utils/Shaders/shaderExplodeSmoothVolumes.h index 299d393bef2633e57900a6bd4a7d8db5ec9da7e7..8f3d8108615020e76ca1e1e7cad919a3748fbc48 100644 --- a/include/Utils/Shaders/shaderExplodeSmoothVolumes.h +++ b/include/Utils/Shaders/shaderExplodeSmoothVolumes.h @@ -44,7 +44,6 @@ protected: // uniform locations CGoGNGLuint m_unif_ambiant; - CGoGNGLuint m_unif_backColor; CGoGNGLuint m_unif_lightPos; CGoGNGLuint m_unif_explodeV; CGoGNGLuint m_unif_explodeF; @@ -54,7 +53,6 @@ protected: float m_explodeV; float m_explodeF; Geom::Vec4f m_ambiant; - Geom::Vec4f m_backColor; Geom::Vec3f m_light_pos; Geom::Vec4f m_plane; @@ -79,13 +77,11 @@ public: void setAmbiant(const Geom::Vec4f& ambiant); - void setBackColor(const Geom::Vec4f& backColor); - void setLightPosition(const Geom::Vec3f& lp); void setClippingPlane(const Geom::Vec4f& plane); - void setParams(float explodeV, float explodeF, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane); + void setParams(float explodeV, float explodeF, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane); unsigned int setAttributePosition(VBO* vbo); diff --git a/src/Utils/Shaders/shaderExplodeSmoothVolumes.cpp b/src/Utils/Shaders/shaderExplodeSmoothVolumes.cpp index 8a5da0b35fb3e20d3af745c16241cec23cb74eea..82a294dee0d41297d47c58bba14fe10d9d52a473 100644 --- a/src/Utils/Shaders/shaderExplodeSmoothVolumes.cpp +++ b/src/Utils/Shaders/shaderExplodeSmoothVolumes.cpp @@ -67,11 +67,10 @@ ShaderExplodeSmoothVolumes::ShaderExplodeSmoothVolumes(bool withColorPerFace, bo m_explodeV = 0.9f; m_explodeF = 0.9f; m_ambiant = Geom::Vec4f(0.05f, 0.05f, 0.1f, 0.0f); - m_backColor = Geom::Vec4f(1.0f, 0.1f, 0.1f, 0.0f); m_light_pos = Geom::Vec3f(10.0f, 10.0f, 1000.0f); m_plane = Geom::Vec4f(0.0f, 0.0f, 1000.f, 1000000000000000000000000000.0f); - setParams(m_explodeV, m_explodeF, m_ambiant, m_backColor, m_light_pos, m_plane); + setParams(m_explodeV, m_explodeF, m_ambiant, m_light_pos, m_plane); } void ShaderExplodeSmoothVolumes::getLocations() @@ -80,7 +79,6 @@ void ShaderExplodeSmoothVolumes::getLocations() *m_unif_explodeV = glGetUniformLocation(program_handler(),"explodeV"); *m_unif_explodeF = glGetUniformLocation(program_handler(),"explodeF"); *m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient"); - *m_unif_backColor = glGetUniformLocation(program_handler(),"backColor"); *m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition"); *m_unif_plane = glGetUniformLocation(program_handler(),"plane"); unbind(); @@ -114,7 +112,7 @@ unsigned int ShaderExplodeSmoothVolumes::setAttributeNormal(VBO* vbo) } -void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom::Vec4f& ambiant, const Geom::Vec4f& backColor, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane) +void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane) { bind(); m_explodeV = explV; @@ -123,9 +121,6 @@ void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom: glUniform1f(*m_unif_explodeF, explF); m_ambiant = ambiant; glUniform4fv(*m_unif_ambiant, 1, ambiant.data()); - m_backColor = backColor; - glUniform4fv(*m_unif_backColor, 1, backColor.data()); - m_light_pos = lightPos; glUniform3fv(*m_unif_lightPos, 1, lightPos.data()); @@ -159,13 +154,7 @@ void ShaderExplodeSmoothVolumes::setAmbiant(const Geom::Vec4f& ambiant) unbind(); } -void ShaderExplodeSmoothVolumes::setBackColor(const Geom::Vec4f& backColor) -{ - m_backColor = backColor; - bind(); - glUniform4fv(*m_unif_backColor, 1, backColor.data()); - unbind(); -} + void ShaderExplodeSmoothVolumes::setLightPosition(const Geom::Vec3f& lp) { @@ -196,9 +185,6 @@ void ShaderExplodeSmoothVolumes::restoreUniformsAttribs() *m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient"); glUniform4fv(*m_unif_ambiant, 1, m_ambiant.data()); - *m_unif_backColor = glGetUniformLocation(program_handler(),"backColor"); - glUniform4fv(*m_unif_backColor, 1, m_backColor.data()); - *m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition"); glUniform3fv(*m_unif_lightPos, 1, m_light_pos.data());