Commit 6afbce7f authored by Sylvain Thery's avatar Sylvain Thery

update MC + some upgrade in parallel algo

parent 4bb1ab67
......@@ -158,6 +158,90 @@ void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute<ty
vertex_area[d] = vertexVoronoiArea<PFP>(map, d, position) ;
}
namespace Parallel
{
template <typename PFP>
class FunctorConvexFaceArea: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
FaceAttribute<typename PFP::REAL>& m_area;
public:
FunctorConvexFaceArea<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::REAL>& area):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_area(area)
{ }
void run(Dart d, unsigned int threadID)
{
m_area[d] = convexFaceArea<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::REAL>& area, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorConvexFaceArea<PFP> funct(map,position,area);
Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, nbth, false, select, current_thread);
}
template <typename PFP>
class FunctorVertexOneRingArea: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VertexAttribute<typename PFP::REAL>& m_area;
public:
FunctorVertexOneRingArea<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::REAL>& area):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_area(area)
{ }
void run(Dart d, unsigned int threadID)
{
m_area[d] = vertexOneRingArea<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::REAL>& area, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorConvexFaceArea<PFP> funct(map,position,area);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, false, select, current_thread);
}
template <typename PFP>
class FunctorVertexVoronoiArea: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VertexAttribute<typename PFP::REAL>& m_area;
public:
FunctorVertexVoronoiArea<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::REAL>& area):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_area(area)
{ }
void run(Dart d, unsigned int threadID)
{
m_area[d] = vertexVoronoiArea<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::REAL>& area, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorConvexFaceArea<PFP> funct(map,position,area);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, false, select, current_thread);
}
}
} // namespace Geometry
} // namespace Algo
......
......@@ -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<unsigned long long>* m_zslice;
unsigned int m_currentZSlice;
#endif
/**
* voxel image
*/
......@@ -258,6 +265,12 @@ public:
void removeFacesOfBoundary(VertexAttribute<unsigned char>& boundVertices, unsigned int frameWidth);
void recalPoints(const Geom::Vec3f& origin);
#ifdef MC_WIDTH_EDGE_Z_EMBEDED
void setZSliceAttrib(EdgeAttribute<unsigned long long>* zsatt, unsigned int zbound, unsigned int nbZone);
#endif
};
} // namespace MC
......
......@@ -46,6 +46,11 @@ MarchingCube<DataType, Windowing, PFP>::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<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* 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<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* img, L_MAP* map, VertexAttribute<VEC3>& position, Windowing<DataType> wind, bool boundRemoved):
......@@ -70,7 +81,12 @@ MarchingCube<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* 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<DataType, Windowing, PFP>::simpleMeshing()
lY++;
}
lZ++;
#ifdef MC_WIDTH_EDGE_Z_EMBEDED
m_currentZSlice++;
#endif
m_Buffer->nextSlice();
// middles slices
......@@ -218,6 +238,9 @@ void MarchingCube<DataType, Windowing, PFP>::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<DataType, Windowing, PFP>::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<DataType, Windowing, PFP>::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<DataType, Windowing, PFP>::recalPoints(const Geom::Vec3f& orig
}
}
#ifdef MC_WIDTH_EDGE_Z_EMBEDED
template< typename DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::setZSliceAttrib(EdgeAttribute<unsigned long long>* zsatt, unsigned int zbound, unsigned int nbZone)
{
m_zslice = zsatt;
m_zbound = zbound;
m_sliceGroup = m_Image->getWidthZ()/nbZone;
}
#endif
} // namespace MC
} // namespace Algo
......
......@@ -163,7 +163,6 @@ void foreach_cell(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, bool n
unsigned int nbth = funcs.size();
std::vector<Dart>* vd = new std::vector<Dart>[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<FunctorMapThreaded<MAP>*>& funcs, bool n
map.addThreadMarker(nbth+1-nbth_prec);
}
boost::thread** threads = new boost::thread*[nbth];
ThreadFunction<MAP>** tfs = new ThreadFunction<MAP>*[nbth];
for (unsigned int i = 0; i < nbth; ++i)
threads[i] = new boost::thread(ThreadFunction<MAP>(funcs[i], vd[i],sync1,sync2, finished,1+i));
{
tfs[i] = new ThreadFunction<MAP>(funcs[i], vd[i],sync1,sync2, finished,1+i);
threads[i] = new boost::thread( boost::ref( *(tfs[i]) ) );
}
// threads[i] = new boost::thread(ThreadFunction<MAP>(funcs[i], vd[i],sync1,sync2, finished,1+i));
// and continue to traverse the map
std::vector<Dart>* tempo = new std::vector<Dart>[nbth];
......@@ -332,7 +339,9 @@ void foreach_cell(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, bool n
{
threads[i]->join();
delete threads[i];
delete tfs[i];
}
delete[] tfs;
delete[] threads;
delete[] vd;
delete[] tempo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment