From 2bfa530f3ed6c18ba2fab965bb25a7bbab4a542d Mon Sep 17 00:00:00 2001 From: nicolas le goff Date: Mon, 22 Jan 2024 10:11:29 +0100 Subject: [PATCH] removed the static global id for CurvedBlocking entities in favor of a local counter for each blocking --- blocking/inc/gmds/blocking/CurvedBlocking.h | 45 ++++++++++++++++----- blocking/src/CurvedBlocking.cpp | 36 +++++++++++++---- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/blocking/inc/gmds/blocking/CurvedBlocking.h b/blocking/inc/gmds/blocking/CurvedBlocking.h index 05ccc8e3e..47149d57d 100644 --- a/blocking/inc/gmds/blocking/CurvedBlocking.h +++ b/blocking/inc/gmds/blocking/CurvedBlocking.h @@ -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: @@ -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; + } } }; /*----------------------------------------------------------------------------*/ @@ -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) { } }; @@ -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(); } }; @@ -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(); } }; /*----------------------------------------------------------------------------*/ @@ -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(); @@ -685,6 +704,11 @@ class LIB_GMDS_BLOCKING_API CurvedBlocking */ std::vector> get_projection_info(math::Point &AP, std::vector &AEdges); + Counter* getCounter() + { + return &m_counter; + } + private: /**@brief Mark with @p AMark all the darts of orbit <0,1>(@p ADart) @@ -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 diff --git a/blocking/src/CurvedBlocking.cpp b/blocking/src/CurvedBlocking.cpp index b6ff874cc..de461f295 100644 --- a/blocking/src/CurvedBlocking.cpp +++ b/blocking/src/CurvedBlocking.cpp @@ -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}; @@ -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() {} @@ -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)); } /*----------------------------------------------------------------------------*/