Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:03

0001 // Created on: 2018-03-29
0002 // Created by: Eugeny MALTCHIKOV
0003 // Copyright (c) 2018 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BOPAlgo_MakeConnected_HeaderFile
0017 #define _BOPAlgo_MakeConnected_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 #include <Standard_Handle.hxx>
0022 
0023 #include <BOPAlgo_Options.hxx>
0024 #include <BOPAlgo_MakePeriodic.hxx>
0025 
0026 #include <BRepTools_History.hxx>
0027 
0028 #include <NCollection_DataMap.hxx>
0029 
0030 
0031 //! BOPAlgo_MakeConnected is the algorithm for making the touching
0032 //! shapes connected or glued, i.e. for making the coinciding geometries
0033 //! be topologically shared among the shapes.
0034 //!
0035 //! The input shapes should be of the same dimension, otherwise
0036 //! the gluing will not make any sense.
0037 //!
0038 //! After the shapes are made connected, the border elements of input shapes
0039 //! are associated with the shapes to which they belong. At that, the orientation of
0040 //! the border element in the shape is taken into account.
0041 //! The associations are made for the following types:
0042 //! - For input SOLIDS, the resulting FACES are associated with the input solids;
0043 //! - For input FACES, the resulting EDGES are associated with the input faces;
0044 //! - For input EDGES, the resulting VERTICES are associated with the input edges.
0045 //!
0046 //! In frames of this algorithm the input shapes are called materials,
0047 //! and the association process is called the material association.
0048 //! The material association allows finding the coinciding elements for the opposite
0049 //! input shapes. These elements will be associated to at least two materials.
0050 //!
0051 //! After making the shapes connected, it is possible to make the connected
0052 //! shape periodic using the *BOPAlgo_MakePeriodic* tool.
0053 //! After making the shape periodic, the material associations will be updated
0054 //! to correspond to the actual state of the result shape.
0055 //! Repetition of the periodic shape is also possible here. Material associations
0056 //! are not going to be lost.
0057 //!
0058 //! The algorithm supports history of shapes modification, thus it is possible
0059 //! to track the modification of the input shapes during the operations.
0060 //! Additionally to standard history methods, the algorithm provides the
0061 //! the method *GetOrigins()* which allows obtaining the input shapes from which
0062 //! the resulting shape has been created.
0063 //!
0064 //! The algorithm supports the parallel processing mode, which allows faster
0065 //! completion of the operations.
0066 //!
0067 //! The algorithm returns the following Error/Warning messages:
0068 //! - *BOPAlgo_AlertTooFewArguments* - error alert is given on the attempt to run
0069 //!     the algorithm without the arguments;
0070 //! - *BOPAlgo_AlertMultiDimensionalArguments* - error alert is given on the attempt
0071 //!     to run the algorithm on multi-dimensional arguments;
0072 //! - *BOPAlgo_AlertUnableToGlue* - error alert is given if the gluer algorithm
0073 //!     is unable to glue the given arguments;
0074 //! - *BOPAlgo_AlertUnableToMakePeriodic* - warning alert is given if the periodicity
0075 //!     maker is unable to make the connected shape periodic with given options;
0076 //! - *BOPAlgo_AlertShapeIsNotPeriodic* - warning alert is given on the attempt to
0077 //!     repeat the shape before making it periodic.
0078 //!
0079 //! Here is the example of usage of the algorithm:
0080 //! ~~~~
0081 //! TopTools_ListOfShape anArguments = ...;  // Shapes to make connected
0082 //! Standard_Boolean bRunParallel = ...;     // Parallel processing mode
0083 //!
0084 //! BOPAlgo_MakeConnected aMC;               // Tool for making the shapes connected
0085 //! aMC.SetArguments(anArguments);           // Set the shapes
0086 //! aMC.SetRunParallel(bRunParallel);        // Set parallel processing mode
0087 //! aMC.Perform();                           // Perform the operation
0088 //!
0089 //! if (aMC.HasErrors())                     // Check for the errors
0090 //! {
0091 //!   // errors treatment
0092 //!   Standard_SStream aSStream;
0093 //!   aMC.DumpErrors(aSStream);
0094 //!   return;
0095 //! }
0096 //! if (aMC.HasWarnings())                   // Check for the warnings
0097 //! {
0098 //!   // warnings treatment
0099 //!   Standard_SStream aSStream;
0100 //!   aMC.DumpWarnings(aSStream);
0101 //! }
0102 //!
0103 //! const TopoDS_Shape& aGluedShape = aMC.Shape(); // Connected shape
0104 //!
0105 //! // Checking material associations
0106 //! TopAbs_ShapeEnum anElemType = ...;       // Type of border element
0107 //! TopExp_Explorer anExp(anArguments.First(), anElemType);
0108 //! for (; anExp.More(); anExp.Next())
0109 //! {
0110 //!   const TopoDS_Shape& anElement = anExp.Current();
0111 //!   const TopTools_ListOfShape& aNegativeM = aMC.MaterialsOnNegativeSide(anElement);
0112 //!   const TopTools_ListOfShape& aPositiveM = aMC.MaterialsOnPositiveSide(anElement);
0113 //! }
0114 //!
0115 //! // Making the connected shape periodic
0116 //! BOPAlgo_MakePeriodic::PeriodicityParams aParams = ...; // Options for periodicity of the connected shape
0117 //! aMC.MakePeriodic(aParams);
0118 //!
0119 //! // Shape repetition after making it periodic
0120 //! // Check if the shape has been made periodic successfully
0121 //! if (aMC.PeriodicityTool().HasErrors())
0122 //! {
0123 //!   // Periodicity maker error treatment
0124 //! }
0125 //!
0126 //! // Shape repetition in periodic directions
0127 //! aMC.RepeatShape(0, 2);
0128 //!
0129 //! const TopoDS_Shape& aShape = aMC.PeriodicShape(); // Periodic and repeated shape
0130 //! ~~~~
0131 //!
0132 class BOPAlgo_MakeConnected : public BOPAlgo_Options
0133 {
0134 public:
0135 
0136   DEFINE_STANDARD_ALLOC
0137 
0138 public: //! @name Constructor
0139 
0140   //! Empty constructor
0141   BOPAlgo_MakeConnected() : BOPAlgo_Options()
0142   {
0143   }
0144 
0145 
0146 public: //! @name Setters for the shapes to make connected
0147 
0148   //! Sets the shape for making them connected.
0149   //! @param theArgs [in] The arguments for the operation.
0150   void SetArguments(const TopTools_ListOfShape& theArgs)
0151   {
0152     myArguments = theArgs;
0153   }
0154 
0155   //! Adds the shape to the arguments.
0156   //! @param theS [in] One of the argument shapes.
0157   void AddArgument(const TopoDS_Shape& theS)
0158   {
0159     myArguments.Append(theS);
0160   }
0161 
0162   //! Returns the list of arguments of the operation.
0163   const TopTools_ListOfShape& Arguments() const
0164   {
0165     return myArguments;
0166   }
0167 
0168 public: //! @name Performing the operations
0169 
0170   //! Performs the operation, i.e. makes the input shapes connected.
0171   Standard_EXPORT void Perform();
0172 
0173 
0174 public: //! @name Shape periodicity & repetition
0175 
0176   //! Makes the connected shape periodic.
0177   //! Repeated calls of this method overwrite the previous calls
0178   //! working with the basis connected shape.
0179   //! @param theParams [in] Periodic options.
0180   Standard_EXPORT void MakePeriodic(const BOPAlgo_MakePeriodic::PeriodicityParams& theParams);
0181 
0182   //! Performs repetition of the periodic shape in specified direction
0183   //! required number of times.
0184   //! @param theDirectionID [in] The direction's ID (0 for X, 1 for Y, 2 for Z);
0185   //! @param theTimes [in] Requested number of repetitions (sign of the value defines
0186   //!                      the side of the repetition direction (positive or negative)).
0187   Standard_EXPORT void RepeatShape(const Standard_Integer theDirectionID,
0188                                    const Standard_Integer theTimes);
0189 
0190   //! Clears the repetitions performed on the periodic shape,
0191   //! keeping the shape periodic.
0192   Standard_EXPORT void ClearRepetitions();
0193 
0194   //! Returns the periodicity tool.
0195   const BOPAlgo_MakePeriodic& PeriodicityTool() const
0196   {
0197     return myPeriodicityMaker;
0198   }
0199 
0200 
0201 public: //! @name Material transitions
0202 
0203   //! Returns the original shapes which images contain the
0204   //! the given shape with FORWARD orientation.
0205   //! @param theS [in] The shape for which the materials are necessary.
0206   const TopTools_ListOfShape& MaterialsOnPositiveSide(const TopoDS_Shape& theS)
0207   {
0208     const TopTools_ListOfShape* pLM = myMaterials.Seek(theS.Oriented(TopAbs_FORWARD));
0209     return (pLM ? *pLM : EmptyList());
0210   }
0211 
0212   //! Returns the original shapes which images contain the
0213   //! the given shape with REVERSED orientation.
0214   //! @param theS [in] The shape for which the materials are necessary.
0215   const TopTools_ListOfShape& MaterialsOnNegativeSide(const TopoDS_Shape& theS)
0216   {
0217     const TopTools_ListOfShape* pLM = myMaterials.Seek(theS.Oriented(TopAbs_REVERSED));
0218     return (pLM ? *pLM : EmptyList());
0219   }
0220 
0221 
0222 public: //! @name History methods
0223 
0224   //! Returns the history of operations
0225   const Handle(BRepTools_History)& History() const
0226   {
0227     return myHistory;
0228   }
0229 
0230   //! Returns the list of shapes modified from the given shape.
0231   //! @param theS [in] The shape for which the modified shapes are necessary.
0232   const TopTools_ListOfShape& GetModified(const TopoDS_Shape& theS)
0233   {
0234     return (myHistory.IsNull() ? EmptyList() : myHistory->Modified(theS));
0235   }
0236 
0237   //! Returns the list of original shapes from which the current shape has been created.
0238   //! @param theS [in] The shape for which the origins are necessary.
0239   const TopTools_ListOfShape& GetOrigins(const TopoDS_Shape& theS)
0240   {
0241     const TopTools_ListOfShape* pLOr = myOrigins.Seek(theS);
0242     return (pLOr ? *pLOr : EmptyList());
0243   }
0244 
0245 
0246 public: //! @name Getting the result shapes
0247 
0248   //! Returns the resulting connected shape
0249   const TopoDS_Shape& Shape() const
0250   {
0251     return myGlued;
0252   }
0253 
0254   //! Returns the resulting periodic & repeated shape
0255   const TopoDS_Shape& PeriodicShape() const
0256   {
0257     return myShape;
0258   }
0259 
0260 
0261 public: //! @name Clearing the contents of the algorithm from previous runs
0262 
0263   //! Clears the contents of the algorithm.
0264   void Clear()
0265   {
0266     BOPAlgo_Options::Clear();
0267     myArguments.Clear();
0268     myAllInputsMap.Clear();
0269     myPeriodicityMaker.Clear();
0270     myOrigins.Clear();
0271     myMaterials.Clear();
0272     if (!myGlueHistory.IsNull())
0273       myGlueHistory->Clear();
0274     if (!myHistory.IsNull())
0275       myHistory->Clear();
0276     myGlued.Nullify();
0277     myShape.Nullify();
0278   }
0279 
0280 
0281 protected: //! @name Protected methods performing the operation
0282 
0283   //! Checks the validity of input data.
0284   Standard_EXPORT void CheckData();
0285 
0286   //! Makes the argument shapes connected (or glued).
0287   Standard_EXPORT void MakeConnected();
0288 
0289   //! Associates the materials transitions for the border elements:
0290   //! - For input Solids, associates the Faces to Solids;
0291   //! - For input Faces, associates the Edges to Faces;
0292   //! - For input Edges, associates the Vertices to Edges.
0293   Standard_EXPORT void AssociateMaterials();
0294 
0295   //! Fills the map of origins
0296   Standard_EXPORT void FillOrigins();
0297 
0298   //! Updates the history, material associations, origins map
0299   //! after periodicity operations.
0300   Standard_EXPORT void Update();
0301 
0302 private:
0303 
0304   //! Returns an empty list.
0305   const TopTools_ListOfShape& EmptyList()
0306   {
0307     static const TopTools_ListOfShape anEmptyList;
0308     return anEmptyList;
0309   }
0310 
0311 protected: //! @name Fields
0312 
0313   // Inputs
0314   TopTools_ListOfShape myArguments;          //!< Input shapes for making them connected
0315   TopTools_IndexedMapOfShape myAllInputsMap; //!< Map of all BRep sub-elements of the input shapes
0316 
0317   // Tools
0318   BOPAlgo_MakePeriodic myPeriodicityMaker;   //!< Tool for making the shape periodic
0319 
0320   // Results
0321   NCollection_DataMap
0322     <TopoDS_Shape,
0323      TopTools_ListOfShape> myMaterials;            //!< Map of the materials associations
0324                                                    //! for the border elements
0325   TopTools_DataMapOfShapeListOfShape myOrigins;    //!< Map of origins
0326                                                    //! (allows tracking the shape's ancestors)
0327 
0328   Handle(BRepTools_History) myGlueHistory;         //!< Gluing History
0329   Handle(BRepTools_History) myHistory;             //!< Final History of shapes modifications
0330                                                    //! (including making the shape periodic and repetitions)
0331 
0332   TopoDS_Shape myGlued;                            //!< The resulting connected (glued) shape
0333   TopoDS_Shape myShape;                            //!< The resulting shape
0334 };
0335 
0336 #endif // _BOPAlgo_MakeConnected_HeaderFile