|
||||
File indexing completed on 2025-01-18 10:03:03
0001 // Created by: Peter KURNEV 0002 // Copyright (c) 2010-2014 OPEN CASCADE SAS 0003 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE 0004 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, 0005 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 0006 // 0007 // This file is part of Open CASCADE Technology software library. 0008 // 0009 // This library is free software; you can redistribute it and/or modify it under 0010 // the terms of the GNU Lesser General Public License version 2.1 as published 0011 // by the Free Software Foundation, with special exception defined in the file 0012 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0013 // distribution for complete text of the license and disclaimer of any warranty. 0014 // 0015 // Alternatively, this file may be used under the terms of Open CASCADE 0016 // commercial license or contractual agreement. 0017 0018 #ifndef _BOPAlgo_Builder_HeaderFile 0019 #define _BOPAlgo_Builder_HeaderFile 0020 0021 #include <Standard.hxx> 0022 #include <Standard_DefineAlloc.hxx> 0023 #include <Standard_Handle.hxx> 0024 0025 #include <BOPAlgo_PPaveFiller.hxx> 0026 #include <BOPAlgo_BuilderShape.hxx> 0027 #include <BOPAlgo_GlueEnum.hxx> 0028 #include <BOPAlgo_Operation.hxx> 0029 #include <BOPDS_PDS.hxx> 0030 #include <NCollection_BaseAllocator.hxx> 0031 #include <Standard_Integer.hxx> 0032 #include <Standard_Real.hxx> 0033 #include <TopTools_DataMapOfShapeListOfShape.hxx> 0034 #include <TopTools_DataMapOfShapeShape.hxx> 0035 #include <TopTools_ListOfShape.hxx> 0036 #include <TopTools_MapOfShape.hxx> 0037 #include <TopAbs_ShapeEnum.hxx> 0038 class IntTools_Context; 0039 class TopoDS_Shape; 0040 0041 //! 0042 //! The class is a General Fuse algorithm - base algorithm for the 0043 //! algorithms in the Boolean Component. Its main purpose is to build 0044 //! the split parts of the argument shapes from which the result of 0045 //! the operations is combined.<br> 0046 //! The result of the General Fuse algorithm itself is a compound 0047 //! containing all split parts of the arguments. <br> 0048 //! 0049 //! Additionally to the options of the base classes, the algorithm has 0050 //! the following options:<br> 0051 //! - *Safe processing mode* - allows to avoid modification of the input 0052 //! shapes during the operation (by default it is off);<br> 0053 //! - *Gluing options* - allows to speed up the calculation of the intersections 0054 //! on the special cases, in which some sub-shapes are coinciding.<br> 0055 //! - *Disabling the check for inverted solids* - Disables/Enables the check of the input solids 0056 //! for inverted status (holes in the space). The default value is TRUE, 0057 //! i.e. the check is performed. Setting this flag to FALSE for inverted solids, 0058 //! most likely will lead to incorrect results. 0059 //! 0060 //! The algorithm returns the following warnings: 0061 //! - *BOPAlgo_AlertUnableToOrientTheShape* - in case the check on the orientation of the split shape 0062 //! to match the orientation of the original shape has failed. 0063 //! 0064 //! The algorithm returns the following Error statuses: 0065 //! - *BOPAlgo_AlertTooFewArguments* - in case there are no enough arguments to perform the operation; 0066 //! - *BOPAlgo_AlertNoFiller* - in case the intersection tool has not been created; 0067 //! - *BOPAlgo_AlertIntersectionFailed* - in case the intersection of the arguments has failed; 0068 //! - *BOPAlgo_AlertBuilderFailed* - in case building splits of arguments has failed with some unexpected error. 0069 //! 0070 class BOPAlgo_Builder : public BOPAlgo_BuilderShape 0071 { 0072 public: 0073 0074 DEFINE_STANDARD_ALLOC 0075 0076 //! Empty constructor. 0077 Standard_EXPORT BOPAlgo_Builder(); 0078 Standard_EXPORT virtual ~BOPAlgo_Builder(); 0079 0080 Standard_EXPORT BOPAlgo_Builder(const Handle(NCollection_BaseAllocator)& theAllocator); 0081 0082 //! Clears the content of the algorithm. 0083 Standard_EXPORT virtual void Clear() Standard_OVERRIDE; 0084 0085 //! Returns the PaveFiller, algorithm for sub-shapes intersection. 0086 BOPAlgo_PPaveFiller PPaveFiller() 0087 { 0088 return myPaveFiller; 0089 } 0090 0091 //! Returns the Data Structure, holder of intersection information. 0092 BOPDS_PDS PDS() 0093 { 0094 return myDS; 0095 } 0096 0097 //! Returns the Context, tool for cashing heavy algorithms. 0098 Handle(IntTools_Context) Context() const 0099 { 0100 return myContext; 0101 } 0102 0103 0104 public: //! @name Arguments 0105 0106 //! Adds the argument to the operation. 0107 Standard_EXPORT virtual void AddArgument (const TopoDS_Shape& theShape); 0108 0109 //! Sets the list of arguments for the operation. 0110 Standard_EXPORT virtual void SetArguments (const TopTools_ListOfShape& theLS); 0111 0112 //! Returns the list of arguments. 0113 const TopTools_ListOfShape& Arguments() const 0114 { 0115 return myArguments; 0116 } 0117 0118 public: //! @name Options 0119 0120 //! Sets the flag that defines the mode of treatment. 0121 //! In non-destructive mode the argument shapes are not modified. Instead 0122 //! a copy of a sub-shape is created in the result if it is needed to be updated. 0123 //! This flag is taken into account if internal PaveFiller is used only. 0124 //! In the case of calling PerformWithFiller the corresponding flag of that PaveFiller 0125 //! is in force. 0126 void SetNonDestructive(const Standard_Boolean theFlag) 0127 { 0128 myNonDestructive = theFlag; 0129 } 0130 0131 //! Returns the flag that defines the mode of treatment. 0132 //! In non-destructive mode the argument shapes are not modified. Instead 0133 //! a copy of a sub-shape is created in the result if it is needed to be updated. 0134 Standard_Boolean NonDestructive() const 0135 { 0136 return myNonDestructive; 0137 } 0138 0139 //! Sets the glue option for the algorithm 0140 void SetGlue(const BOPAlgo_GlueEnum theGlue) 0141 { 0142 myGlue = theGlue; 0143 } 0144 0145 //! Returns the glue option of the algorithm 0146 BOPAlgo_GlueEnum Glue() const 0147 { 0148 return myGlue; 0149 } 0150 0151 //! Enables/Disables the check of the input solids for inverted status 0152 void SetCheckInverted(const Standard_Boolean theCheck) 0153 { 0154 myCheckInverted = theCheck; 0155 } 0156 0157 //! Returns the flag defining whether the check for input solids on inverted status 0158 //! should be performed or not. 0159 Standard_Boolean CheckInverted() const 0160 { 0161 return myCheckInverted; 0162 } 0163 0164 0165 public: //! @name Performing the operation 0166 0167 //! Performs the operation. 0168 //! The intersection will be performed also. 0169 Standard_EXPORT virtual void Perform(const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE; 0170 0171 //! Performs the operation with the prepared filler. 0172 //! The intersection will not be performed in this case. 0173 Standard_EXPORT virtual void PerformWithFiller (const BOPAlgo_PaveFiller& theFiller, const Message_ProgressRange& theRange = Message_ProgressRange()); 0174 0175 0176 public: //! @name BOPs on open solids 0177 0178 //! Builds the result shape according to the given states for the objects 0179 //! and tools. These states can be unambiguously converted into the Boolean operation type. 0180 //! Thus, it performs the Boolean operation on the given groups of shapes. 0181 //! 0182 //! The result is built basing on the result of Builder operation (GF or any other). 0183 //! The only condition for the Builder is that the splits of faces should be created 0184 //! and classified relatively solids. 0185 //! 0186 //! The method uses classification approach for choosing the faces which will 0187 //! participate in building the result shape: 0188 //! - All faces from each group having the given state for the opposite group 0189 //! will be taken into result. 0190 //! 0191 //! Such approach shows better results (in comparison with BOPAlgo_BuilderSolid approach) 0192 //! when working with open solids. However, the result may not be always 0193 //! correct on such data (at least, not as expected) as the correct classification 0194 //! of the faces relatively open solids is not always possible and may vary 0195 //! depending on the chosen classification point on the face. 0196 //! 0197 //! History is not created for the solids in this method. 0198 //! 0199 //! To avoid pollution of the report of Builder algorithm, there is a possibility to pass 0200 //! the different report to collect the alerts of the method only. But, if the new report 0201 //! is not given, the Builder report will be used. 0202 //! So, even if Builder passed without any errors, but some error has been stored into its report 0203 //! in this method, for the following calls the Builder report must be cleared. 0204 //! 0205 //! The method may set the following errors: 0206 //! - BOPAlgo_AlertBuilderFailed - Building operation has not been performed yet or failed; 0207 //! - BOPAlgo_AlertBOPNotSet - invalid BOP type is given (COMMON/FUSE/CUT/CUT21 are supported); 0208 //! - BOPAlgo_AlertTooFewArguments - arguments are not given; 0209 //! - BOPAlgo_AlertUnknownShape - the shape is unknown for the operation. 0210 //! 0211 //! Parameters: 0212 //! @param theObjects - The group of Objects for BOP; 0213 //! @param theObjState - State for objects faces to pass into result; 0214 //! @param theTools - The group of Tools for BOP; 0215 //! @param theToolsState - State for tools faces to pass into result; 0216 //! @param theReport - The alternative report to avoid pollution of the main one. 0217 Standard_EXPORT virtual void BuildBOP(const TopTools_ListOfShape& theObjects, 0218 const TopAbs_State theObjState, 0219 const TopTools_ListOfShape& theTools, 0220 const TopAbs_State theToolsState, 0221 const Message_ProgressRange& theRange, 0222 Handle(Message_Report) theReport = NULL); 0223 0224 //! Builds the result of Boolean operation of given type 0225 //! basing on the result of Builder operation (GF or any other). 0226 //! 0227 //! The method converts the given type of operation into the states 0228 //! for the objects and tools required for their face to pass into result 0229 //! and performs the call to the same method, but with states instead 0230 //! of operation type. 0231 //! 0232 //! The conversion looks as follows: 0233 //! - COMMON is built from the faces of objects located IN any of the tools 0234 //! and vice versa. 0235 //! - FUSE is built from the faces OUT of all given shapes; 0236 //! - CUT is built from the faces of the objects OUT of the tools and 0237 //! faces of the tools located IN solids of the objects. 0238 //! 0239 //! @param theObjects - The group of Objects for BOP; 0240 //! @param theTools - The group of Tools for BOP; 0241 //! @param theOperation - The BOP type; 0242 //! @param theRange - The parameter to progressIndicator 0243 //! @param theReport - The alternative report to avoid pollution of the global one. 0244 void BuildBOP(const TopTools_ListOfShape& theObjects, 0245 const TopTools_ListOfShape& theTools, 0246 const BOPAlgo_Operation theOperation, 0247 const Message_ProgressRange& theRange, 0248 Handle(Message_Report) theReport = NULL) 0249 { 0250 TopAbs_State anObjState, aToolsState; 0251 switch (theOperation) 0252 { 0253 case BOPAlgo_COMMON: 0254 { 0255 anObjState = TopAbs_IN; 0256 aToolsState = TopAbs_IN; 0257 break; 0258 } 0259 case BOPAlgo_FUSE: 0260 { 0261 anObjState = TopAbs_OUT; 0262 aToolsState = TopAbs_OUT; 0263 break; 0264 } 0265 case BOPAlgo_CUT: 0266 { 0267 anObjState = TopAbs_OUT; 0268 aToolsState = TopAbs_IN; 0269 break; 0270 } 0271 case BOPAlgo_CUT21: 0272 { 0273 anObjState = TopAbs_IN; 0274 aToolsState = TopAbs_OUT; 0275 break; 0276 } 0277 default: 0278 { 0279 anObjState = TopAbs_UNKNOWN; 0280 aToolsState = TopAbs_UNKNOWN; 0281 break; 0282 } 0283 } 0284 BuildBOP(theObjects, anObjState, theTools, aToolsState, theRange, theReport); 0285 } 0286 0287 protected: //! @name History methods 0288 0289 //! Prepare information for history support. 0290 Standard_EXPORT void PrepareHistory(const Message_ProgressRange& theRange); 0291 0292 //! Prepare history information for the input shapes taking into account possible 0293 //! operation-specific modifications. 0294 //! For instance, in the CellsBuilder operation, additionally to splitting input shapes 0295 //! the splits of the shapes (or the shapes themselves) may be unified during removal of internal 0296 //! boundaries. In this case each split should be linked to the unified shape. 0297 //! 0298 //! To have correct history information, the method should be redefined in each operation 0299 //! where such additional modification is possible. The input shape <theS> should be the one from arguments, 0300 //! and the returning list should contain all final elements to which the input shape has evolved, 0301 //! including those not contained in the result shape. 0302 //! 0303 //! The method returns pointer to the list of modified elements. 0304 //! NULL pointer means that the shape has not been modified at all. 0305 //! 0306 //! The General Fuse operation does not perform any other modification than splitting the input 0307 //! shapes basing on their intersection information. This information is contained in myImages map. 0308 //! Thus, here the method returns only splits (if any) contained in this map. 0309 Standard_EXPORT virtual const TopTools_ListOfShape* LocModified(const TopoDS_Shape& theS); 0310 0311 //! Returns the list of shapes generated from the shape theS. 0312 //! Similarly to *LocModified* must be redefined for specific operations, 0313 //! obtaining Generated elements differently. 0314 Standard_EXPORT virtual const TopTools_ListOfShape& LocGenerated(const TopoDS_Shape& theS); 0315 0316 public: //! @name Images/Origins 0317 0318 //! Returns the map of images. 0319 const TopTools_DataMapOfShapeListOfShape& Images() const 0320 { 0321 return myImages; 0322 } 0323 0324 //! Returns the map of origins. 0325 const TopTools_DataMapOfShapeListOfShape& Origins() const 0326 { 0327 return myOrigins; 0328 } 0329 0330 //! Returns the map of Same Domain (SD) shapes - coinciding shapes 0331 //! from different arguments. 0332 const TopTools_DataMapOfShapeShape& ShapesSD() const 0333 { 0334 return myShapesSD; 0335 } 0336 0337 protected://! @name Analyze progress of the operation 0338 0339 //! List of operations to be supported by the Progress Indicator 0340 enum BOPAlgo_PIOperation 0341 { 0342 PIOperation_TreatVertices = 0, 0343 PIOperation_TreatEdges, 0344 PIOperation_TreatWires, 0345 PIOperation_TreatFaces, 0346 PIOperation_TreatShells, 0347 PIOperation_TreatSolids, 0348 PIOperation_TreatCompsolids, 0349 PIOperation_TreatCompounds, 0350 PIOperation_FillHistory, 0351 PIOperation_PostTreat, 0352 PIOperation_Last 0353 }; 0354 0355 0356 //! Auxiliary structure to get information about number of shapes 0357 //! of each type participated in operation. 0358 class NbShapes 0359 { 0360 public: 0361 NbShapes() 0362 { 0363 for (Standard_Integer i = 0; i < 8; ++i) 0364 { 0365 myNbShapesArr[i] = 0; 0366 } 0367 } 0368 0369 Standard_Integer NbVertices() const { return myNbShapesArr[0]; } 0370 Standard_Integer NbEdges() const { return myNbShapesArr[1]; } 0371 Standard_Integer NbWires() const { return myNbShapesArr[2]; } 0372 Standard_Integer NbFaces() const { return myNbShapesArr[3]; } 0373 Standard_Integer NbShells() const { return myNbShapesArr[4]; } 0374 Standard_Integer NbSolids() const { return myNbShapesArr[5]; } 0375 Standard_Integer NbCompsolids() const { return myNbShapesArr[6]; } 0376 Standard_Integer NbCompounds() const { return myNbShapesArr[7]; } 0377 0378 Standard_Integer& NbVertices() { return myNbShapesArr[0]; } 0379 Standard_Integer& NbEdges() { return myNbShapesArr[1]; } 0380 Standard_Integer& NbWires() { return myNbShapesArr[2]; } 0381 Standard_Integer& NbFaces() { return myNbShapesArr[3]; } 0382 Standard_Integer& NbShells() { return myNbShapesArr[4]; } 0383 Standard_Integer& NbSolids() { return myNbShapesArr[5]; } 0384 Standard_Integer& NbCompsolids() { return myNbShapesArr[6]; } 0385 Standard_Integer& NbCompounds() { return myNbShapesArr[7]; } 0386 0387 private: 0388 Standard_Integer myNbShapesArr[8]; 0389 }; 0390 0391 protected: 0392 0393 //! Compute number of shapes of certain type participating in operation 0394 Standard_EXPORT NbShapes getNbShapes() const; 0395 0396 //! Filling steps for constant operations 0397 Standard_EXPORT void fillPIConstants(const Standard_Real theWhole, BOPAlgo_PISteps& theSteps) const Standard_OVERRIDE; 0398 0399 //! Filling steps for all other operations 0400 Standard_EXPORT void fillPISteps(BOPAlgo_PISteps& theSteps) const Standard_OVERRIDE; 0401 0402 protected: //! @name Methods for building the result 0403 0404 //! Performs the building of the result. 0405 //! The method calls the PerformInternal1() method surrounded by a try-catch block. 0406 Standard_EXPORT virtual void PerformInternal (const BOPAlgo_PaveFiller& thePF, const Message_ProgressRange& theRange); 0407 0408 //! Performs the building of the result. 0409 //! To build the result of any other operation 0410 //! it will be necessary to override this method. 0411 Standard_EXPORT virtual void PerformInternal1 (const BOPAlgo_PaveFiller& thePF, const Message_ProgressRange& theRange); 0412 0413 //! Builds the result of operation. 0414 //! The method is called for each of the arguments type and 0415 //! adds into the result the splits of the arguments of that type. 0416 Standard_EXPORT virtual void BuildResult (const TopAbs_ShapeEnum theType); 0417 0418 0419 protected: //! @name Checking input arguments 0420 0421 //! Checks the input data. 0422 Standard_EXPORT virtual void CheckData() Standard_OVERRIDE; 0423 0424 //! Checks if the intersection algorithm has Errors/Warnings. 0425 Standard_EXPORT void CheckFiller(); 0426 0427 //! Prepares the result shape by making it empty compound. 0428 Standard_EXPORT virtual void Prepare(); 0429 0430 0431 protected: //! @name Fill Images of VERTICES 0432 0433 //! Fills the images of vertices. 0434 Standard_EXPORT void FillImagesVertices(const Message_ProgressRange& theRange); 0435 0436 0437 protected: //! @name Fill Images of EDGES 0438 0439 //! Fills the images of edges. 0440 Standard_EXPORT void FillImagesEdges(const Message_ProgressRange& theRange); 0441 0442 0443 protected: //! @name Fill Images of CONTAINERS 0444 0445 //! Fills the images of containers (WIRES/SHELLS/COMPSOLID). 0446 Standard_EXPORT void FillImagesContainers (const TopAbs_ShapeEnum theType, const Message_ProgressRange& theRange); 0447 0448 //! Builds the image of the given container using the splits 0449 //! of its sub-shapes. 0450 Standard_EXPORT void FillImagesContainer (const TopoDS_Shape& theS, const TopAbs_ShapeEnum theType); 0451 0452 0453 protected: //! @name Fill Images of FACES 0454 0455 //! Fills the images of faces. 0456 //! The method consists of three steps: 0457 //! 1. Build the splits of faces; 0458 //! 2. Find SD faces; 0459 //! 3. Add internal vertices (if any) to faces. 0460 Standard_EXPORT void FillImagesFaces(const Message_ProgressRange& theRange); 0461 0462 //! Builds the splits of faces using the information from the 0463 //! intersection stage stored in Data Structure. 0464 Standard_EXPORT virtual void BuildSplitFaces(const Message_ProgressRange& theRange); 0465 0466 //! Looks for the same domain faces among the splits of the faces. 0467 //! Updates the map of images with SD faces. 0468 Standard_EXPORT void FillSameDomainFaces(const Message_ProgressRange& theRange); 0469 0470 //! Classifies the alone vertices on faces relatively its splits 0471 //! and adds them as INTERNAL into the splits. 0472 Standard_EXPORT void FillInternalVertices(const Message_ProgressRange& theRange); 0473 0474 0475 protected: //! @name Fill Images of SOLIDS 0476 0477 //! Fills the images of solids. 0478 //! The method consists of four steps: 0479 //! 1. Build the draft solid - just rebuild the solid using the splits of faces; 0480 //! 2. Find faces from other arguments located inside the solids; 0481 //! 3. Build splits of solid using the inside faces; 0482 //! 4. Fill internal shapes for the splits (Wires and vertices). 0483 Standard_EXPORT void FillImagesSolids(const Message_ProgressRange& theRange); 0484 0485 //! Builds the draft solid by rebuilding the shells of the solid 0486 //! with the splits of faces. 0487 Standard_EXPORT void BuildDraftSolid (const TopoDS_Shape& theSolid, 0488 TopoDS_Shape& theDraftSolid, 0489 TopTools_ListOfShape& theLIF); 0490 0491 //! Finds faces located inside each solid. 0492 Standard_EXPORT virtual void FillIn3DParts(TopTools_DataMapOfShapeShape& theDraftSolids, 0493 const Message_ProgressRange& theRange); 0494 0495 //! Builds the splits of the solids using their draft versions 0496 //! and faces located inside. 0497 Standard_EXPORT void BuildSplitSolids(TopTools_DataMapOfShapeShape& theDraftSolids, 0498 const Message_ProgressRange& theRange); 0499 0500 //! Classifies the vertices and edges from the arguments relatively 0501 //! splits of solids and makes them INTERNAL for solids. 0502 Standard_EXPORT void FillInternalShapes(const Message_ProgressRange& theRange); 0503 0504 0505 protected: //! @name Fill Images of COMPOUNDS 0506 0507 //! Fills the images of compounds. 0508 Standard_EXPORT void FillImagesCompounds(const Message_ProgressRange& theRange); 0509 0510 //! Builds the image of the given compound. 0511 Standard_EXPORT void FillImagesCompound (const TopoDS_Shape& theS, 0512 TopTools_MapOfShape& theMF); 0513 0514 protected: //! @name Post treatment 0515 0516 //! Post treatment of the result of the operation. 0517 //! The method checks validity of the sub-shapes of the result 0518 //! and updates the tolerances to make them valid. 0519 Standard_EXPORT virtual void PostTreat(const Message_ProgressRange& theRange); 0520 0521 protected: //! @name Fields 0522 0523 TopTools_ListOfShape myArguments; //!< Arguments of the operation 0524 TopTools_MapOfShape myMapFence; //!< Fence map providing the uniqueness of the shapes in the list of arguments 0525 BOPAlgo_PPaveFiller myPaveFiller; //!< Pave Filler - algorithm for sub-shapes intersection 0526 BOPDS_PDS myDS; //!< Data Structure - holder of intersection information 0527 Handle(IntTools_Context) myContext; //!< Context - tool for cashing heavy algorithms such as Projectors and Classifiers 0528 Standard_Integer myEntryPoint; //!< EntryPoint - controls the deletion of the PaveFiller, which could live longer than the Builder 0529 TopTools_DataMapOfShapeListOfShape myImages; //!< Images - map of Images of the sub-shapes of arguments 0530 TopTools_DataMapOfShapeShape myShapesSD; //!< ShapesSD - map of SD Shapes 0531 TopTools_DataMapOfShapeListOfShape myOrigins; //!< Origins - map of Origins, back map of Images 0532 TopTools_DataMapOfShapeListOfShape myInParts; //!< InParts - map of own and acquired IN faces of the arguments solids 0533 Standard_Boolean myNonDestructive; //!< Safe processing option allows avoiding modification of the input shapes 0534 BOPAlgo_GlueEnum myGlue; //!< Gluing option allows speeding up the intersection of the input shapes 0535 Standard_Boolean myCheckInverted; //!< Check inverted option allows disabling the check of input solids on inverted status 0536 0537 }; 0538 0539 #endif // _BOPAlgo_Builder_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |