Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:19:37

0001 // Copyright (c) 2026 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepGraphInc_Reconstruct_HeaderFile
0015 #define _BRepGraphInc_Reconstruct_HeaderFile
0016 
0017 #include <BRepGraph_NodeId.hxx>
0018 #include <NCollection_IncAllocator.hxx>
0019 #include <NCollection_DynamicArray.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 #include <TopoDS_Shape.hxx>
0022 
0023 class BRepGraph;
0024 
0025 //! @brief Backend reconstruction helpers over incidence-table storage.
0026 //!
0027 //! Converts BRepGraphInc_Storage entity data back into TopoDS shapes.
0028 //! This class is part of the BRepGraphInc backend; external callers should
0029 //! prefer BRepGraph::Shapes() so reconstruction stays behind the facade.
0030 //! Supports single-node and cached multi-face reconstruction with
0031 //! shared edge/vertex reuse via the Cache.
0032 class BRepGraphInc_Reconstruct
0033 {
0034 public:
0035   DEFINE_STANDARD_ALLOC
0036 
0037   //! Per-Kind dense vector cache for O(1) shape lookup by entity index.
0038   //! Replaces NCollection_DataMap to eliminate hash/equality overhead.
0039   struct Cache
0040   {
0041     //! Number of Kind slots used by BRepGraph_NodeId dense-kind indexing.
0042     //! Includes topology kinds, assembly kinds, and the reserved gap at kind 9.
0043     static constexpr int THE_KIND_COUNT        = BRepGraph_NodeId::THE_KIND_COUNT;
0044     static constexpr int THE_DEFAULT_INCREMENT = 32;
0045 
0046     occ::handle<NCollection_IncAllocator>  myAllocator;
0047     occ::handle<NCollection_IncAllocator>  myTempAllocator;
0048     NCollection_DynamicArray<TopoDS_Shape> myKinds[THE_KIND_COUNT];
0049     int                                    myTempScopeDepth = 0;
0050 
0051     struct TempScope
0052     {
0053       Cache& myCache;
0054 
0055       explicit TempScope(Cache& theCache);
0056       ~TempScope();
0057     };
0058 
0059     Cache();
0060 
0061     //! Seek a cached shape. Returns nullptr if not yet cached.
0062     [[nodiscard]] Standard_EXPORT const TopoDS_Shape* Seek(const BRepGraph_NodeId theNode) const;
0063 
0064     //! Bind a reconstructed shape to a node. Grows the vector as needed.
0065     Standard_EXPORT void Bind(const BRepGraph_NodeId theNode, const TopoDS_Shape& theShape);
0066 
0067     //! Check if a node is already cached.
0068     [[nodiscard]] bool IsBound(const BRepGraph_NodeId theNode) const
0069     {
0070       return Seek(theNode) != nullptr;
0071     }
0072   };
0073 
0074   //! Reconstruct a TopoDS_Shape from an entity node.
0075   //! Creates a local cache internally; shared vertices/edges are not reused
0076   //! across calls.
0077   //! @param[in] theGraph  graph owning the storage and caches
0078   //! @param[in] theNode   entity node id
0079   //! @return reconstructed shape
0080   static Standard_EXPORT TopoDS_Shape Node(BRepGraph& theGraph, const BRepGraph_NodeId theNode);
0081 
0082   //! Reconstruct a TopoDS_Shape with a shared cache for sub-shape reuse.
0083   //! Vertices and edges already in theCache are returned directly.
0084   //! @param[in]     theGraph  graph owning the storage and caches
0085   //! @param[in]     theNode   entity node id
0086   //! @param[in,out] theCache  shared cache for vertex/edge/face shapes
0087   //! @return reconstructed shape
0088   static Standard_EXPORT TopoDS_Shape Node(BRepGraph&             theGraph,
0089                                            const BRepGraph_NodeId theNode,
0090                                            Cache&                 theCache);
0091 
0092   //! Reconstruct a face with shared edge/vertex cache for multi-face contexts.
0093   //! @param[in]     theGraph   graph owning the storage and caches
0094   //! @param[in]     theFaceId  face entity id
0095   //! @param[in,out] theCache   shared cache for edge and vertex shapes
0096   //! @return reconstructed face shape
0097   static Standard_EXPORT TopoDS_Shape FaceWithCache(BRepGraph&             theGraph,
0098                                                     const BRepGraph_FaceId theFaceId,
0099                                                     Cache&                 theCache);
0100 
0101   BRepGraphInc_Reconstruct() = delete;
0102 };
0103 
0104 #endif // _BRepGraphInc_Reconstruct_HeaderFile