|
|
|||
File indexing completed on 2026-09-16 09:16:26
0001 // Created on: 1992-11-24 0002 // Created by: Didier PIFFAULT 0003 // Copyright (c) 1992-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _Bnd_BoundSortBox_HeaderFile 0018 #define _Bnd_BoundSortBox_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Handle.hxx> 0023 0024 #include <Bnd_Box.hxx> 0025 #include <NCollection_Array1.hxx> 0026 #include <NCollection_HArray1.hxx> 0027 #include <NCollection_DynamicArray.hxx> 0028 #include <Standard_Integer.hxx> 0029 #include <NCollection_DataMap.hxx> 0030 #include <NCollection_List.hxx> 0031 0032 #include <array> 0033 0034 class gp_Pln; 0035 class Bnd_VoxelGrid; 0036 0037 //! A tool to compare a bounding box or a plane with a set of 0038 //! bounding boxes. It sorts the set of bounding boxes to give 0039 //! the list of boxes which intersect the element being compared. 0040 //! The boxes being sorted generally bound a set of shapes, 0041 //! while the box being compared bounds a shape to be 0042 //! compared. The resulting list of intersecting boxes therefore 0043 //! gives the list of items which potentially intersect the shape to be compared. 0044 //! How to use this class: 0045 //! - Create an instance of this class. 0046 //! - Initialize it with the set of boxes to be sorted using one of the 0047 //! Initialize() methods. 0048 //! - Call the Compare() method with the box or plane to be compared. 0049 //! Compare() will return the list of indices of the boxes which intersect 0050 //! the box or plane passed as argument. 0051 class Bnd_BoundSortBox 0052 { 0053 public: 0054 DEFINE_STANDARD_ALLOC 0055 0056 private: 0057 using VectorInt = NCollection_DynamicArray<int>; 0058 0059 public: 0060 //! Constructs an empty comparison algorithm for bounding boxes. 0061 //! The bounding boxes are then defined using the Initialize function. 0062 Standard_EXPORT Bnd_BoundSortBox(); 0063 0064 //! Initializes this comparison algorithm with the set of boxes. 0065 //! @param theSetOfBoxes The set of bounding boxes to be used by this algorithm. 0066 Standard_EXPORT void Initialize(const occ::handle<NCollection_HArray1<Bnd_Box>>& theSetOfBoxes); 0067 0068 //! Initializes this comparison algorithm with the set of boxes and the bounding box 0069 //! that encloses all those boxes. This version of initialization can be used if complete 0070 //! box is known in advance to avoid calculating it again inside the algorithm. 0071 //! @param theEnclosingBox The bounding box that contains all the boxes in @p theSetOfBoxes. 0072 //! @param theSetOfBoxes The set of bounding boxes to be used by this algorithm. 0073 Standard_EXPORT void Initialize(const Bnd_Box& theEnclosingBox, 0074 const occ::handle<NCollection_HArray1<Bnd_Box>>& theSetOfBoxes); 0075 0076 //! Initializes this comparison algorithm with the bounding box that encloses all the boxes 0077 //! that will be used by this algorithm. and the expected number of those boxes. 0078 //! Boxes to be considered can then be added using the Add() method. 0079 //! @param theEnclosingBox The bounding box that contains all the boxes to be sorted. 0080 //! @param theNbComponents The number of components to be added. 0081 Standard_EXPORT void Initialize(const Bnd_Box& theEnclosingBox, const int theNbBoxes); 0082 0083 //! Adds the bounding box theBox at position boxIndex in the internal array of boxes 0084 //! to be sorted by this comparison algorithm. This function is used only in 0085 //! conjunction with the Initialize(const Bnd_Box&, const int) method. 0086 //! Exceptions: 0087 //! - Standard_OutOfRange if boxIndex is not in the range [ 1,nbComponents ] where 0088 //! nbComponents is the maximum number of bounding boxes declared for this algorithm at 0089 //! initialization. 0090 //! - Standard_MultiplyDefined if a box already exists at position @p theIndex in the 0091 //! internal array of boxes. 0092 //! @param theBox The bounding box to be added. 0093 //! @param theIndex The index of the bounding box in the internal array where the box 0094 //! will be added. The index is 1-based. 0095 Standard_EXPORT void Add(const Bnd_Box& theBox, const int theIndex); 0096 0097 //! Compares the bounding box theBox, with the set of bounding boxes provided to this 0098 //! algorithm at initialization, and returns the list of indices of bounding boxes 0099 //! that intersect the @p theBox or are inside it. 0100 //! The indices correspond to the indices of the bounding boxes in the array provided 0101 //! to this algorithm at initialization. 0102 //! @param theBox The bounding box to be compared. 0103 //! @return The list of indices of bounding boxes that intersect the bounding box theBox 0104 //! or are inside it. 0105 Standard_EXPORT const NCollection_List<int>& Compare(const Bnd_Box& theBox); 0106 0107 //! Compares the plane @p thePlane with the set of bounding boxes provided to this 0108 //! algorithm at initialization, and returns the list of indices of bounding boxes 0109 //! that intersect the @p thePlane. 0110 //! The indices correspond to the indices of the bounding boxes in the array provided 0111 //! to this algorithm at initialization. 0112 //! @param thePlane The plane to be compared. 0113 //! @return The list of indices of bounding boxes that intersect the plane thePlane. 0114 Standard_EXPORT const NCollection_List<int>& Compare(const gp_Pln& thePlane); 0115 0116 private: 0117 //! Precalculates the coefficients for the voxel grid based on the enclosing box dimensions. 0118 //! The coefficients will be used to map the box coordinates to the voxel grid. 0119 void calculateCoefficients(); 0120 0121 //! Resets the voxel grid and clears the list of large boxes. 0122 void resetVoxelGrid(); 0123 0124 //! Performs the sorting of the boxes in the voxel grid. 0125 //! This method is called after the boxes have been added to the voxel grid. 0126 void sortBoxes(); 0127 0128 //! Returns indices of voxels that contain minimum and maximum points of the box. 0129 //! @param theBox The bounding box to be compared. 0130 //! @return The indices of the voxels that contain the minimum and maximum points of the box 0131 //! in the order: [minX, minY, minZ, maxX, maxY, maxZ]. 0132 std::array<int, 6> getBoundingVoxels(const Bnd_Box& theBox) const; 0133 0134 //! Adds the box stored in myBoxes to the voxel map. 0135 //! @param theBox The bounding box to be added. 0136 //! @param theIndex The index of the bounding box in myBoxes. 0137 void addBox(const Bnd_Box& theBox, const int theIndex); 0138 0139 Bnd_Box myEnclosingBox; //!< The bounding box that contains all the boxes to be sorted. 0140 occ::handle<NCollection_HArray1<Bnd_Box>> myBoxes; //!< The set of bounding boxes to be sorted. 0141 double myCoeffX; //!< Coefficient for X direction. 0142 double myCoeffY; //!< Coefficient for Y direction. 0143 double myCoeffZ; //!< Coefficient for Z direction. 0144 int myResolution; //!< The number of voxels in each direction. 0145 NCollection_List<int> myLastResult; //!< The last result of the Compare() method. 0146 VectorInt myLargeBoxes; //!< The list of large boxes. 0147 occ::handle<Bnd_VoxelGrid> myVoxelGrid; //!< The voxel grid used for sorting the boxes. 0148 }; 0149 0150 #endif // _Bnd_BoundSortBox_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|