Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2016-04-07
0002 // Copyright (c) 2016 OPEN CASCADE SAS
0003 // Created by: Oleg AGASHIN
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 _IMeshTools_Context_HeaderFile
0017 #define _IMeshTools_Context_HeaderFile
0018 
0019 #include <Standard_Type.hxx>
0020 #include <IMeshTools_ModelBuilder.hxx>
0021 #include <IMeshData_Model.hxx>
0022 #include <IMeshTools_Parameters.hxx>
0023 #include <IMeshTools_ModelAlgo.hxx>
0024 #include <Message_ProgressRange.hxx>
0025 
0026 //! Interface class representing context of BRepMesh algorithm.
0027 //! Intended to cache discrete model and instances of tools for
0028 //! its processing.
0029 class IMeshTools_Context : public IMeshData_Shape
0030 {
0031 public:
0032   //! Constructor.
0033   IMeshTools_Context() = default;
0034 
0035   //! Destructor.
0036   ~IMeshTools_Context() override = default;
0037 
0038   //! Builds model using assigned model builder.
0039   //! @return True on success, False elsewhere.
0040   virtual bool BuildModel()
0041   {
0042     if (myModelBuilder.IsNull())
0043     {
0044       return false;
0045     }
0046 
0047     myModel = myModelBuilder->Perform(GetShape(), myParameters);
0048 
0049     return !myModel.IsNull();
0050   }
0051 
0052   //! Performs discretization of model edges using assigned edge discret algorithm.
0053   //! @return True on success, False elsewhere.
0054   virtual bool DiscretizeEdges()
0055   {
0056     if (myModel.IsNull() || myEdgeDiscret.IsNull())
0057     {
0058       return false;
0059     }
0060 
0061     // Discretize edges of a model.
0062     return myEdgeDiscret->Perform(myModel, myParameters, Message_ProgressRange());
0063   }
0064 
0065   //! Performs healing of discrete model built by DiscretizeEdges() method
0066   //! using assigned healing algorithm.
0067   //! @return True on success, False elsewhere.
0068   virtual bool HealModel()
0069   {
0070     if (myModel.IsNull())
0071     {
0072       return false;
0073     }
0074 
0075     return myModelHealer.IsNull()
0076              ? true
0077              : myModelHealer->Perform(myModel, myParameters, Message_ProgressRange());
0078   }
0079 
0080   //! Performs pre-processing of discrete model using assigned algorithm.
0081   //! Performs auxiliary actions such as cleaning shape from old triangulation.
0082   //! @return True on success, False elsewhere.
0083   virtual bool PreProcessModel()
0084   {
0085     if (myModel.IsNull())
0086     {
0087       return false;
0088     }
0089 
0090     return myPreProcessor.IsNull()
0091              ? true
0092              : myPreProcessor->Perform(myModel, myParameters, Message_ProgressRange());
0093   }
0094 
0095   //! Performs meshing of faces of discrete model using assigned meshing algorithm.
0096   //! @return True on success, False elsewhere.
0097   virtual bool DiscretizeFaces(const Message_ProgressRange& theRange)
0098   {
0099     if (myModel.IsNull() || myFaceDiscret.IsNull())
0100     {
0101       return false;
0102     }
0103 
0104     // Discretize faces of a model.
0105     return myFaceDiscret->Perform(myModel, myParameters, theRange);
0106   }
0107 
0108   //! Performs post-processing of discrete model using assigned algorithm.
0109   //! @return True on success, False elsewhere.
0110   virtual bool PostProcessModel()
0111   {
0112     if (myModel.IsNull())
0113     {
0114       return false;
0115     }
0116 
0117     return myPostProcessor.IsNull()
0118              ? true
0119              : myPostProcessor->Perform(myModel, myParameters, Message_ProgressRange());
0120   }
0121 
0122   //! Cleans temporary context data.
0123   virtual void Clean()
0124   {
0125     if (myParameters.CleanModel)
0126     {
0127       myModel.Nullify();
0128     }
0129   }
0130 
0131   //! Gets instance of a tool to be used to build discrete model.
0132   const occ::handle<IMeshTools_ModelBuilder>& GetModelBuilder() const { return myModelBuilder; }
0133 
0134   //! Sets instance of a tool to be used to build discrete model.
0135   void SetModelBuilder(const occ::handle<IMeshTools_ModelBuilder>& theBuilder)
0136   {
0137     myModelBuilder = theBuilder;
0138   }
0139 
0140   //! Gets instance of a tool to be used to discretize edges of a model.
0141   const occ::handle<IMeshTools_ModelAlgo>& GetEdgeDiscret() const { return myEdgeDiscret; }
0142 
0143   //! Sets instance of a tool to be used to discretize edges of a model.
0144   void SetEdgeDiscret(const occ::handle<IMeshTools_ModelAlgo>& theEdgeDiscret)
0145   {
0146     myEdgeDiscret = theEdgeDiscret;
0147   }
0148 
0149   //! Gets instance of a tool to be used to heal discrete model.
0150   const occ::handle<IMeshTools_ModelAlgo>& GetModelHealer() const { return myModelHealer; }
0151 
0152   //! Sets instance of a tool to be used to heal discrete model.
0153   void SetModelHealer(const occ::handle<IMeshTools_ModelAlgo>& theModelHealer)
0154   {
0155     myModelHealer = theModelHealer;
0156   }
0157 
0158   //! Gets instance of pre-processing algorithm.
0159   const occ::handle<IMeshTools_ModelAlgo>& GetPreProcessor() const { return myPreProcessor; }
0160 
0161   //! Sets instance of pre-processing algorithm.
0162   void SetPreProcessor(const occ::handle<IMeshTools_ModelAlgo>& thePreProcessor)
0163   {
0164     myPreProcessor = thePreProcessor;
0165   }
0166 
0167   //! Gets instance of meshing algorithm.
0168   const occ::handle<IMeshTools_ModelAlgo>& GetFaceDiscret() const { return myFaceDiscret; }
0169 
0170   //! Sets instance of meshing algorithm.
0171   void SetFaceDiscret(const occ::handle<IMeshTools_ModelAlgo>& theFaceDiscret)
0172   {
0173     myFaceDiscret = theFaceDiscret;
0174   }
0175 
0176   //! Gets instance of post-processing algorithm.
0177   const occ::handle<IMeshTools_ModelAlgo>& GetPostProcessor() const { return myPostProcessor; }
0178 
0179   //! Sets instance of post-processing algorithm.
0180   void SetPostProcessor(const occ::handle<IMeshTools_ModelAlgo>& thePostProcessor)
0181   {
0182     myPostProcessor = thePostProcessor;
0183   }
0184 
0185   //! Gets parameters to be used for meshing.
0186   const IMeshTools_Parameters& GetParameters() const { return myParameters; }
0187 
0188   //! Gets reference to parameters to be used for meshing.
0189   IMeshTools_Parameters& ChangeParameters() { return myParameters; }
0190 
0191   //! Returns discrete model of a shape.
0192   const occ::handle<IMeshData_Model>& GetModel() const { return myModel; }
0193 
0194   DEFINE_STANDARD_RTTIEXT(IMeshTools_Context, IMeshData_Shape)
0195 
0196 private:
0197   occ::handle<IMeshTools_ModelBuilder> myModelBuilder;
0198   occ::handle<IMeshData_Model>         myModel;
0199   occ::handle<IMeshTools_ModelAlgo>    myEdgeDiscret;
0200   occ::handle<IMeshTools_ModelAlgo>    myModelHealer;
0201   occ::handle<IMeshTools_ModelAlgo>    myPreProcessor;
0202   occ::handle<IMeshTools_ModelAlgo>    myFaceDiscret;
0203   occ::handle<IMeshTools_ModelAlgo>    myPostProcessor;
0204   IMeshTools_Parameters                myParameters;
0205 };
0206 
0207 #endif