Commit 3a8ecd23 authored by Thery Sylvain's avatar Thery Sylvain
Browse files

finish (??) Volume/Surface namspace for Algo

parent 4fa2f232
......@@ -64,15 +64,15 @@ int main(int argc, char **argv)
PFP::MAP myMap;
std::vector<std::string> attrNames ;
Algo::Import::importMesh<PFP>(myMap, argv[1], attrNames);
Algo::Surface::Import::importMesh<PFP>(myMap, argv[1], attrNames);
// get a handler to the 3D vector attribute created by the import
VertexAttribute<PFP::VEC3> position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]);
for(unsigned int i = 0; i < nbSteps; ++i)
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position);
Algo::Export::exportOFF<PFP>(myMap, position, "result.off");
Algo::Surface::Export::exportOFF<PFP>(myMap, position, "result.off");
return 0;
}
......@@ -59,7 +59,7 @@ typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAt
else
{
float area = 0.0f ;
VEC3 centroid = Algo::Geometry::faceCentroid<PFP>(map, d, position) ;
VEC3 centroid = faceCentroid<PFP>(map, d, position) ;
Traversor2FE<typename PFP::MAP> t(map, d) ;
for(Dart it = t.begin(); it != t.end(); it = t.next())
{
......
......@@ -119,21 +119,86 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co
}
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
namespace Parallel
{
template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
}
} // namespace Geometry
}
namespace Volume
{
namespace Geometry
{
/**
* Compute vertex neighbours centroid in map of dimension 3(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 position the vector of attribute or cell
*/
template <typename PFP, typename EMBV, typename EMB>
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);
/**
* Compute vertex neighbours centroid in map of dimension 3
* @param map the map
* @param d a dart of the face
* @param position the vector of attribute
*/
template <typename PFP>
typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{
return vertexNeighborhoodCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
}
/**
* compute centroid of all volumes
* @param map the map
* @param position vertex attribute of position
* @param vol_centroid volume attribute where to store the centroids
* @param select the selector
*/
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
/**
* compute centroid of all vertices
* @param map the map
* @param position vertex attribute of position
* @param vertex_centroid vertex attribute to store the centroids
* @param select the selector
*/
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
namespace Parallel
{
template <typename PFP>
......@@ -141,20 +206,15 @@ void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
}
}
}
} // namespace Geometry
}
} // namespace Algo
......
......@@ -89,13 +89,6 @@ EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& at
return center ;
}
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const FunctorSelect& select, unsigned int thread)
{
TraversorW<typename PFP::MAP> t(map, select,thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
vol_centroid[d] = volumeCentroid<PFP>(map, d, position,thread) ;
}
template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid, const FunctorSelect& select, unsigned int thread)
......@@ -117,32 +110,6 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAtt
namespace Parallel
{
template <typename PFP>
class FunctorComputeCentroidVolumes: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VolumeAttribute<typename PFP::VEC3>& m_vol_centroid;
public:
FunctorComputeCentroidVolumes<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_vol_centroid(vol_centroid)
{ }
void run(Dart d, unsigned int threadID)
{
m_vol_centroid[d] = volumeCentroid<PFP>(this->m_map, d, m_position,threadID) ;
}
};
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select, unsigned int nbth)
{
FunctorComputeCentroidVolumes<PFP> funct(map,position,vol_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, funct, nbth, true, select);
}
template <typename PFP>
class FunctorComputeCentroidFaces: public FunctorMapThreaded<typename PFP::MAP >
......@@ -197,22 +164,100 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
}
}
} // namespace Geometry
} // namespace Surface
namespace Volume
{
namespace Geometry
{
template <typename PFP, typename EMBV, typename EMB>
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{
EMB center = AttribOps::zero<EMB,PFP>();
unsigned int count = 0 ;
Traversor3VVaE<typename PFP::MAP> t(map, d) ;
for(Dart it = t.begin(); it != t.end(); it = t.next())
{
center += attributs[it];
++count ;
}
center /= count ;
return center ;
}
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const FunctorSelect& select, unsigned int thread)
{
TraversorW<typename PFP::MAP> t(map, select,thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
vol_centroid[d] = Surface::Geometry::volumeCentroid<PFP>(map, d, position,thread) ;
}
namespace Parallel
{
template <typename PFP>
class FunctorComputeCentroidVolumes: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VolumeAttribute<typename PFP::VEC3>& m_vol_centroid;
public:
FunctorComputeCentroidVolumes<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_vol_centroid(vol_centroid)
{ }
void run(Dart d, unsigned int threadID)
{
m_vol_centroid[d] = Surface::Geometry::volumeCentroid<PFP>(this->m_map, d, m_position,threadID) ;
}
};
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select, unsigned int nbth)
{
FunctorComputeCentroidVolumes<PFP> funct(map,position,vol_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, funct, nbth, true, select);
}
template <typename PFP>
class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VertexAttribute<typename PFP::VEC3>& m_vcentroid;
public:
FunctorComputeNeighborhoodCentroidVertices<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vcentroid):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_vcentroid(vcentroid)
{ }
void run(Dart d, unsigned int threadID)
{
m_vcentroid[d] = vertexNeighborhoodCentroid<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeNeighborhoodCentroidVertices<PFP> funct(map,position,vertex_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, false, select, current_thread);
}
} // namespace Geometry
}
}
}
} // namespace Algo
......
......@@ -34,6 +34,9 @@ namespace CGoGN
namespace Algo
{
namespace Surface
{
namespace Geometry
{
......@@ -89,6 +92,8 @@ void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const VertexAttr
} // namespace Geometry
}
} // namespace Algo
} // namespace CGoGN
......
......@@ -38,6 +38,9 @@ namespace CGoGN
namespace Algo
{
namespace Surface
{
namespace Geometry
{
......@@ -287,6 +290,8 @@ void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const VertexAttr
} // namespace Geometry
}
} // namespace Algo
} // namespace CGoGN
......@@ -62,12 +62,12 @@ typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const
{
typedef typename PFP::VEC3 VEC3;
if(Modelisation::Tetrahedralization::isTetrahedron<PFP>(map,d,thread))
if (Volume::Modelisation::Tetrahedralization::isTetrahedron<PFP>(map,d,thread))
return tetrahedronVolume<PFP>(map,d,position) ;
else
{
typename PFP::REAL vol = 0 ;
VEC3 vCentroid = Algo::Geometry::volumeCentroid<PFP>(map, d, position, thread) ;
VEC3 vCentroid = Algo::Surface::Geometry::volumeCentroid<PFP>(map, d, position, thread) ;
DartMarkerStore mark(map,thread); // Lock a marker
......@@ -89,7 +89,7 @@ typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const
}
else
{
VEC3 fCentroid = Algo::Geometry::faceCentroid<PFP>(map, e, position) ;
VEC3 fCentroid = Algo::Surface::Geometry::faceCentroid<PFP>(map, e, position) ;
Dart f = e ;
do
{
......
......@@ -170,7 +170,7 @@ protected:
*/
std::vector<unsigned int> m_emb;
static ImportVolumique::ImportType getFileType(const std::string& filename);
static ImportType getFileType(const std::string& filename);
public:
typedef typename PFP::VEC3 VEC3 ;
......
......@@ -35,39 +35,39 @@ namespace Import
{
template <typename PFP>
ImportVolumique::ImportType MeshTablesVolume<PFP>::getFileType(const std::string& filename)
ImportType MeshTablesVolume<PFP>::getFileType(const std::string& filename)
{
if ((filename.rfind(".tet")!=std::string::npos) || (filename.rfind(".TET")!=std::string::npos))
return ImportVolumique::TET;
return TET;
if ((filename.rfind(".node")!=std::string::npos) || (filename.rfind(".NODE")!=std::string::npos))
return ImportVolumique::NODE;
return NODE;
if ((filename.rfind(".off")!=std::string::npos) || (filename.rfind(".OFF")!=std::string::npos))
return ImportVolumique::OFF;
return OFF;
if ((filename.rfind(".ts")!=std::string::npos) || (filename.rfind(".TS")!=std::string::npos))
return ImportVolumique::TS;
return TS;
if ((filename.rfind(".moka")!=std::string::npos) || (filename.rfind(".MOKA")!=std::string::npos))
return ImportVolumique::MOKA;
return MOKA;
return ImportVolumique::UNKNOWNVOLUME;
return UNKNOWNVOLUME;
}
template <typename PFP>
bool MeshTablesVolume<PFP>::importMesh(const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor)
{
ImportVolumique::ImportType kind = getFileType(filename);
ImportType kind = getFileType(filename);
switch (kind)
{
case ImportVolumique::TET:
case TET:
return importTet(filename, attrNames, scaleFactor);
break;
case ImportVolumique::NODE:
case NODE:
break;
case ImportVolumique::TS:
case TS:
break;
// case ImportVolumique::MOKA:
// return importMoka(filename,attrNames);
......
......@@ -302,7 +302,7 @@ bool importMeshSToV(typename PFP::MAP& map, Surface::Import::MeshTablesSurface<P
nbe = edgesBuffer.size();
if (nbe > 2)
{
Dart d = Algo::Modelisation::createPrism<PFP>(map, nbe);
Dart d = Surface::Modelisation::createPrism<PFP>(map, nbe);
//Embed the base faces
for (unsigned int j = 0; j < nbe; ++j)
......@@ -370,7 +370,7 @@ bool importMeshSToV(typename PFP::MAP& map, Surface::Import::MeshTablesSurface<P
}
template <typename PFP>
bool importMeshSurfToVol(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts, float scale, unsigned int nbStage)
bool importMeshSurfToVol(typename PFP::MAP& map, Surface::Import::MeshTablesSurface<PFP>& mts, float scale, unsigned int nbStage)
{
VertexAutoAttribute< NoMathIONameAttribute< std::vector<Dart> > > vecDartsPerVertex(map);
unsigned nbf = mts.getNbFaces();
......@@ -414,7 +414,7 @@ bool importMeshSurfToVol(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts, fl
for(unsigned int k = 0 ; k < nbStage ; ++k)
{
Dart d = Algo::Modelisation::createPrism<PFP>(map, nbe);
Dart d = Surface::Modelisation::createPrism<PFP>(map, nbe);
//Embed the base faces
for (unsigned int j = 0; j < nbe; ++j)
......@@ -509,45 +509,45 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume<PFP>& mtv)
template <typename PFP>
bool importMeshV(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, bool mergeCloseVertices)
{
Volume::Import::ImportType kind = Volume::Import::UNKNOWNVOLUME;
ImportType kind = Volume::Import::UNKNOWNVOLUME;
if ((filename.rfind(".tet") != std::string::npos) || (filename.rfind(".TET") != std::string::npos))
kind = Volume::Import::TET;
kind = TET;
if ((filename.rfind(".off") != std::string::npos) || (filename.rfind(".OFF") != std::string::npos))
kind = Volume::Import::OFF;
kind = OFF;
if ((filename.rfind(".node") != std::string::npos) || (filename.rfind(".NODE") != std::string::npos))
kind = Volume::Import::NODE;
kind = NODE;
if ((filename.rfind(".ts") != std::string::npos) || (filename.rfind(".TS") != std::string::npos))
kind = Volume::Import::TS;
kind = TS;
switch (kind)
{
case Volume::Import::TET:
return Algo::Import::importTet<PFP>(map, filename, attrNames, 1.0f);
case TET:
return importTet<PFP>(map, filename, attrNames, 1.0f);
break;
case Volume::Import::OFF:
case OFF:
{
size_t pos = filename.rfind(".");
std::string fileEle = filename;
fileEle.erase(pos);
fileEle.append(".ele");
return Algo::Import::importOFFWithELERegions<PFP>(map, filename, fileEle, attrNames);
return importOFFWithELERegions<PFP>(map, filename, fileEle, attrNames);
break;
}
case Volume::Import::NODE:
case NODE:
{
size_t pos = filename.rfind(".");
std::string fileEle = filename;
fileEle.erase(pos);
fileEle.append(".ele");
return Algo::Import::importNodeWithELERegions<PFP>(map, filename, fileEle, attrNames);
return importNodeWithELERegions<PFP>(map, filename, fileEle, attrNames);
break;
}
case Volume::Import::TS:
Algo::Import::importTs<PFP>(map, filename, attrNames, 1.0f);
return importTs<PFP>(map, filename, attrNames, 1.0f);
break;
default:
CGoGNerr << "Not yet supported" << CGoGNendl;
......
......@@ -31,6 +31,9 @@ namespace CGoGN
namespace Algo
{
namespace Volume
{
namespace Import
{
......@@ -146,7 +149,7 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
std::stringstream oss(line);
oss >> nbe;
Dart d = Algo::Modelisation::createTetrahedron<PFP>(map);
Dart d = Surface::Modelisation::createTetrahedron<PFP>(map);
Geom::Vec4ui pt;
oss >> pt[0];
--(pt[0]);
......@@ -243,6 +246,8 @@ bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenam
} // namespace Import
}
} // namespace Algo
} // namespace CGoGN
......@@ -31,6 +31,9 @@ namespace CGoGN
namespace Algo
{
namespace Volume
{
namespace Import
{
......@@ -145,7 +148,7 @@ bool importOFFWithELERegions(typename PFP::MAP& map, const std::string& filename
std::stringstream oss(line);
oss >> nbe;
Dart d = Algo::Modelisation::createTetrahedron<PFP>(map);
Dart d = Surface::Modelisation::createTetrahedron<PFP>(map);
Geom::Vec4ui pt;
oss >> pt[0];
oss >> pt[1];
......@@ -237,7 +240,6 @@ bool importOFFWithELERegions(typename PFP::MAP& map, const std::string& filename
}
} // namespace Import
}
} // namespace Algo
} // namespace CGoGN
......@@ -28,6 +28,8 @@ namespace CGoGN
{
namespace Algo
{
namespace Surface
{
namespace Import
{
......@@ -231,7 +233,7 @@ bool importObjWithTex(typename PFP::MAP& map, const std::string& filename)
return true;
}
}
}
} // end namespaces
}
......@@ -116,7 +116,7 @@ bool importTet(typename PFP::MAP& map, const std::string& filename, std::vector<
std::stringstream oss(ligne);
oss >> nbe; //number of vertices = 4 or used for region mark
Dart d = Algo::Modelisation::createTetrahedron<PFP>(map);
Dart d = Surface::Modelisation::createTetrahedron<PFP>(map);
Geom::Vec4ui pt;
oss >> pt[0];
......
......@@ -123,7 +123,7 @@ bool importTs(typename PFP::MAP& map, const std::string& filename, std::vector<s
oss >> nbe; //number of vertices = 4
assert(nbe == 4);
Dart d = Algo::Modelisation::createTetrahedron<PFP>(map);
Dart d = Surface::Modelisation::createTetrahedron<PFP>(map);
Geom::Vec4ui pt;
oss >> pt[0];
......
......@@ -281,7 +281,7 @@ Dart extrudeFace(typename PFP::MAP& the_map, VertexAttribute<typename PFP::VEC3>