Skip to content

Commit

Permalink
removed the static global id for CurvedBlocking entities in favor of …
Browse files Browse the repository at this point in the history
…a local counter for each blocking
  • Loading branch information
nicolaslg committed Jan 22, 2024
1 parent 5ffaab5 commit 2bfa530
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
45 changes: 36 additions & 9 deletions blocking/inc/gmds/blocking/CurvedBlocking.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ namespace gmds {
/*----------------------------------------------------------------------------*/
namespace blocking {
/*----------------------------------------------------------------------------*/
class Counter{
public:
Counter(int c)
: m_counter_global_id(c){}
int get_and_increment_id(){return m_counter_global_id++;}
int value(){return m_counter_global_id;}
private:
int m_counter_global_id;
};
/**@struct CellInfo
* @brief This structure gather the pieces of data that are shared by any
* blocking cell. Each cell is defined by:
Expand All @@ -41,22 +50,29 @@ struct CellInfo
int topo_id;
/*** link to the cad manager to have access to geometric cells */
cad::GeomManager* geom_manager;
/*** link to the counter used to assign a unique id to each entity */
Counter* counter;
/*** dimension of the geometrical cell we are classifid on */
int geom_dim;
/*** unique id of the geomtrical cell */
int geom_id;
/*** global counter used to assign an unique id to each block */
static int m_counter_global_id;

/** @brief Constructor
* @param Ac the id counter; the CGAL gmap copy constructor requires a CellInfo()
* call with no params
* @param AManager the geometric manager to access cells
* @param ATopoDim Cell dimension
* @param AGeomDim on-classify geometric cell dimension (4 if not classified)
* @param AGeomId on-classify geometric cell unique id
*/
CellInfo(cad::GeomManager* AManager=NULL, const int ATopoDim = 4, const int AGeomDim = 4, const int AGeomId = NullID) :
topo_dim(ATopoDim), topo_id(m_counter_global_id++), geom_manager(AManager),geom_dim(AGeomDim), geom_id(AGeomId)
CellInfo(Counter* Ac=nullptr, cad::GeomManager* AManager=nullptr, const int ATopoDim = 4, const int AGeomDim = 4, const int AGeomId = NullID) :
topo_dim(ATopoDim), geom_manager(AManager), counter(Ac), geom_dim(AGeomDim), geom_id(AGeomId)
{
if(Ac != nullptr) {
topo_id = Ac->get_and_increment_id();
} else {
topo_id = -1;
}
}
};
/*----------------------------------------------------------------------------*/
Expand All @@ -69,13 +85,15 @@ struct NodeInfo : CellInfo
/*** node location in space, i.e. a single point */
math::Point point;
/** @brief Constructor
* @param Ac the id counter; the CGAL gmap copy constructor requires a CellInfo()
* call with no params
* @param AManager the geometric manager to access cells
* @param AGeomDim on-classify geometric cell dimension (4 if not classified)
* @param AGeomId on-classify geometric cell unique id
* @param APoint geometric location
*/
NodeInfo(cad::GeomManager* AManager=NULL, const int AGeomDim = 4, const int AGeomId = NullID, const math::Point &APoint = math::Point(0, 0, 0)) :
CellInfo(AManager, 0, AGeomDim, AGeomId), point(APoint)
NodeInfo(Counter* Ac=nullptr, cad::GeomManager* AManager=nullptr, const int AGeomDim = 4, const int AGeomId = NullID, const math::Point &APoint = math::Point(0, 0, 0)) :
CellInfo(Ac, AManager, 0, AGeomDim, AGeomId), point(APoint)
{
}
};
Expand Down Expand Up @@ -208,8 +226,7 @@ struct SplitFunctor
ca2.info().geom_dim = ca1.info().geom_dim;
ca2.info().geom_id = ca1.info().geom_id;
ca2.info().topo_dim = ca1.info().topo_dim;
ca2.info().topo_id = CellInfo::m_counter_global_id++;

ca2.info().topo_id = ca1.info().counter->get_and_increment_id();
}
};

Expand All @@ -227,7 +244,7 @@ struct SplitFunctorNode
ca2.info().geom_id = ca1.info().geom_id;
ca2.info().point = ca1.info().point;
ca2.info().topo_dim = ca1.info().topo_dim;
ca2.info().topo_id = CellInfo::m_counter_global_id++;
ca2.info().topo_id = ca1.info().counter->get_and_increment_id();
}
};
/*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -278,6 +295,8 @@ class LIB_GMDS_BLOCKING_API CurvedBlocking
*/
CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundingBox = false);

CurvedBlocking(const CurvedBlocking &ABl);

/** @brief Destructor
*/
virtual ~CurvedBlocking();
Expand Down Expand Up @@ -685,6 +704,11 @@ class LIB_GMDS_BLOCKING_API CurvedBlocking
*/
std::vector<std::pair<double, double>> get_projection_info(math::Point &AP, std::vector<CurvedBlocking::Edge> &AEdges);

Counter* getCounter()
{
return &m_counter;
}

private:

/**@brief Mark with @p AMark all the darts of orbit <0,1>(@p ADart)
Expand Down Expand Up @@ -736,6 +760,9 @@ class LIB_GMDS_BLOCKING_API CurvedBlocking
cad::GeomManager *m_geom_model;
/*** the underlying n-g-map model*/
GMap3 m_gmap;

/*** id counter*/
Counter m_counter;
};
/*----------------------------------------------------------------------------*/
} // namespace blocking
Expand Down
36 changes: 29 additions & 7 deletions blocking/src/CurvedBlocking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using namespace gmds;
using namespace gmds::blocking;
/*----------------------------------------------------------------------------*/
int CellInfo::m_counter_global_id = 0;
//int CellInfo::m_counter_global_id = 0;

/*----------------------------------------------------------------------------*/
CurvedBlocking::CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundingBox) : m_geom_model(AGeomModel) {
CurvedBlocking::CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundingBox)
: m_geom_model(AGeomModel), m_counter(0)
{
if (AInitAsBoundingBox) {
TCoord min[3] = {MAXFLOAT, MAXFLOAT, MAXFLOAT};
TCoord max[3] = {-MAXFLOAT, -MAXFLOAT, -MAXFLOAT};
Expand All @@ -32,7 +34,27 @@ CurvedBlocking::CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundin
create_block(p1, p2, p3, p4, p5, p6, p7, p8);
}
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::CurvedBlocking(const CurvedBlocking &ABl)
: m_geom_model(ABl.m_geom_model), m_gmap(ABl.m_gmap), m_counter(ABl.m_counter)
{
auto listBlocks = get_all_blocks();
for(auto b : listBlocks){
b->info().counter = &m_counter;
}
auto listFaces = get_all_faces();
for(auto b : listFaces){
b->info().counter = &m_counter;
}
auto listEdges = get_all_edges();
for(auto b : listEdges){
b->info().counter = &m_counter;
}
auto listNodes = get_all_nodes();
for(auto b : listNodes){
b->info().counter = &m_counter;
}
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::~CurvedBlocking() {}

Expand All @@ -51,25 +73,25 @@ CurvedBlocking::geom_model() {
/*----------------------------------------------------------------------------*/
CurvedBlocking::Node
CurvedBlocking::create_node(const int AGeomDim, const int AGeomId, const math::Point &APoint) {
return m_gmap.create_attribute<0>(NodeInfo(m_geom_model,AGeomDim, AGeomId, APoint));
return m_gmap.create_attribute<0>(NodeInfo(this->getCounter(),m_geom_model,AGeomDim, AGeomId, APoint));
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::Edge
CurvedBlocking::create_edge(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<1>(CellInfo(m_geom_model,1, AGeomDim, AGeomId));
return m_gmap.create_attribute<1>(CellInfo(this->getCounter(),m_geom_model,1, AGeomDim, AGeomId));
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::Face
CurvedBlocking::create_face(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<2>(CellInfo(m_geom_model,2, AGeomDim, AGeomId));
return m_gmap.create_attribute<2>(CellInfo(this->getCounter(),m_geom_model,2, AGeomDim, AGeomId));
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::Block
CurvedBlocking::create_block(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<3>(CellInfo(m_geom_model,3, AGeomDim, AGeomId));
return m_gmap.create_attribute<3>(CellInfo(this->getCounter(),m_geom_model,3, AGeomDim, AGeomId));
}

/*----------------------------------------------------------------------------*/
Expand Down

0 comments on commit 2bfa530

Please sign in to comment.