diff --git a/include/Algo/Geometry/area.hpp b/include/Algo/Geometry/area.hpp index bfd51e44096d608742dcefaa20f164454be0fa83..516991915737494bb1d79232a6496684d6e8807b 100644 --- a/include/Algo/Geometry/area.hpp +++ b/include/Algo/Geometry/area.hpp @@ -158,6 +158,90 @@ void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute(map, d, position) ; } + +namespace Parallel +{ +template +class FunctorConvexFaceArea: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + FaceAttribute& m_area; +public: + FunctorConvexFaceArea( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area): + FunctorMapThreaded(map), m_position(position), m_area(area) + { } + + void run(Dart d, unsigned int threadID) + { + m_area[d] = convexFaceArea(this->m_map, d, m_position) ; + } +}; + +template +void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorConvexFaceArea funct(map,position,area); + Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); +} + + +template +class FunctorVertexOneRingArea: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + VertexAttribute& m_area; +public: + FunctorVertexOneRingArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): + FunctorMapThreaded(map), m_position(position), m_area(area) + { } + + void run(Dart d, unsigned int threadID) + { + m_area[d] = vertexOneRingArea(this->m_map, d, m_position) ; + } +}; + +template +void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorConvexFaceArea funct(map,position,area); + Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); +} + + + +template +class FunctorVertexVoronoiArea: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + VertexAttribute& m_area; +public: + FunctorVertexVoronoiArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): + FunctorMapThreaded(map), m_position(position), m_area(area) + { } + + void run(Dart d, unsigned int threadID) + { + m_area[d] = vertexVoronoiArea(this->m_map, d, m_position) ; + } +}; + +template +void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorConvexFaceArea funct(map,position,area); + Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); +} + + +} + + + + + + + } // namespace Geometry } // namespace Algo diff --git a/include/Algo/MC/marchingcube.h b/include/Algo/MC/marchingcube.h index 71dc36fe57ed0c30baf158cbbcf3ce30291cf7dd..f8cb40f1c3de31db89b81ecbadce4bebf25edd69 100644 --- a/include/Algo/MC/marchingcube.h +++ b/include/Algo/MC/marchingcube.h @@ -54,6 +54,13 @@ protected: typedef typename PFP::MAP L_MAP ; typedef Dart L_DART ; +#ifdef MC_WIDTH_EDGE_Z_EMBEDED + unsigned int m_zbound; + unsigned int m_sliceGroup; + EdgeAttribute* m_zslice; + unsigned int m_currentZSlice; +#endif + /** * voxel image */ @@ -258,6 +265,12 @@ public: void removeFacesOfBoundary(VertexAttribute& boundVertices, unsigned int frameWidth); void recalPoints(const Geom::Vec3f& origin); + + + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + void setZSliceAttrib(EdgeAttribute* zsatt, unsigned int zbound, unsigned int nbZone); + #endif + }; } // namespace MC diff --git a/include/Algo/MC/marchingcube.hpp b/include/Algo/MC/marchingcube.hpp index 33a9c5e5bee26c90ed80a62c9782021296c59012..cdd37f30ca18ed19f4830f23c0b521ad5fd8b289 100644 --- a/include/Algo/MC/marchingcube.hpp +++ b/include/Algo/MC/marchingcube.hpp @@ -46,6 +46,11 @@ MarchingCube::MarchingCube(const char* _cName) m_fOrigin = typename PFP::VEC3(0.0,0.0,0.0); m_fScal = typename PFP::VEC3(1.0,1.0,1.0); + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + m_currentZSlice = 0; + m_zslice = NULL; + #endif + } @@ -58,7 +63,13 @@ MarchingCube::MarchingCube(Image* img, Windo m_fOrigin(typename PFP::VEC3(0.0,0.0,0.0)), m_fScal(typename PFP::VEC3(1.0,1.0,1.0)), m_brem(boundRemoved) -{} +{ + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + m_currentZSlice = 0; + m_zslice = NULL; + #endif + +} template< typename DataType, template < typename D2 > class Windowing, typename PFP > MarchingCube::MarchingCube(Image* img, L_MAP* map, VertexAttribute& position, Windowing wind, bool boundRemoved): @@ -70,7 +81,12 @@ MarchingCube::MarchingCube(Image* img, L_MAP m_fOrigin(typename PFP::VEC3(0.0,0.0,0.0)), m_fScal(typename PFP::VEC3(1.0,1.0,1.0)), m_brem(boundRemoved) -{} +{ + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + m_currentZSlice = 0; + m_zslice = NULL; + #endif +} template< typename DataType, template < typename D2 > class Windowing, typename PFP > @@ -185,6 +201,10 @@ void MarchingCube::simpleMeshing() lY++; } lZ++; + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + m_currentZSlice++; + #endif + m_Buffer->nextSlice(); // middles slices @@ -218,6 +238,9 @@ void MarchingCube::simpleMeshing() } lZ++; + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + m_currentZSlice++; + #endif m_Buffer->nextSlice(); } @@ -898,14 +921,34 @@ 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,false); + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + if (m_zslice!=NULL) + { + unsigned int val = (m_currentZSlice - m_zbound)/m_sliceGroup; + std::cout << "ZSLICE=" << val << std::endl; + m_zslice->operator[](d1) = val; + } + #endif + } } 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,false); + #ifdef MC_WIDTH_EDGE_Z_EMBEDED + if (m_zslice!=NULL) + { + unsigned int val = (m_currentZSlice - m_zbound)/m_sliceGroup; + std::cout << "ZSLICE=" << val << std::endl; + m_zslice->operator[](d1) = val; + } + #endif + } } template< typename DataType, template < typename D2 > class Windowing, typename PFP > @@ -1191,6 +1234,19 @@ void MarchingCube::recalPoints(const Geom::Vec3f& orig } } + +#ifdef MC_WIDTH_EDGE_Z_EMBEDED +template< typename DataType, template < typename D2 > class Windowing, typename PFP > +void MarchingCube::setZSliceAttrib(EdgeAttribute* zsatt, unsigned int zbound, unsigned int nbZone) +{ + m_zslice = zsatt; + m_zbound = zbound; + m_sliceGroup = m_Image->getWidthZ()/nbZone; +} +#endif + + + } // namespace MC } // namespace Algo diff --git a/include/Algo/Parallel/parallel_foreach.hpp b/include/Algo/Parallel/parallel_foreach.hpp index 0dc91e0af6e8bcb8b73034f7c6539d2c778e3a79..2bdfaa5d3af6658c27138e062d3d80c75e9ed22e 100644 --- a/include/Algo/Parallel/parallel_foreach.hpp +++ b/include/Algo/Parallel/parallel_foreach.hpp @@ -163,7 +163,6 @@ void foreach_cell(MAP& map, std::vector*>& funcs, bool n unsigned int nbth = funcs.size(); std::vector* vd = new std::vector[nbth]; - boost::thread** threads = new boost::thread*[nbth]; // nbth new functions, new thread (with good darts !) for (unsigned int i = 0; i < nbth; ++i) @@ -243,8 +242,16 @@ void foreach_cell(MAP& map, std::vector*>& funcs, bool n map.addThreadMarker(nbth+1-nbth_prec); } + boost::thread** threads = new boost::thread*[nbth]; + ThreadFunction** tfs = new ThreadFunction*[nbth]; + for (unsigned int i = 0; i < nbth; ++i) - threads[i] = new boost::thread(ThreadFunction(funcs[i], vd[i],sync1,sync2, finished,1+i)); + { + tfs[i] = new ThreadFunction(funcs[i], vd[i],sync1,sync2, finished,1+i); + threads[i] = new boost::thread( boost::ref( *(tfs[i]) ) ); + } +// threads[i] = new boost::thread(ThreadFunction(funcs[i], vd[i],sync1,sync2, finished,1+i)); + // and continue to traverse the map std::vector* tempo = new std::vector[nbth]; @@ -332,7 +339,9 @@ void foreach_cell(MAP& map, std::vector*>& funcs, bool n { threads[i]->join(); delete threads[i]; + delete tfs[i]; } + delete[] tfs; delete[] threads; delete[] vd; delete[] tempo;