0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepMesh / BRepMesh_FaceDiscret.cxx
CommitLineData
7bd071ed 1// Created on: 2016-04-19
2// Copyright (c) 2016 OPEN CASCADE SAS
3// Created by: Oleg AGASHIN
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <BRepMesh_FaceDiscret.hxx>
17#include <IMeshData_Model.hxx>
7bd071ed 18#include <IMeshData_Wire.hxx>
19#include <IMeshData_Edge.hxx>
20#include <IMeshTools_MeshAlgo.hxx>
21#include <OSD_Parallel.hxx>
22
4945e8be 23IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FaceDiscret, IMeshTools_ModelAlgo)
24
7bd071ed 25//=======================================================================
26// Function: Constructor
27// Purpose :
28//=======================================================================
29BRepMesh_FaceDiscret::BRepMesh_FaceDiscret(
30 const Handle(IMeshTools_MeshAlgoFactory)& theAlgoFactory)
31 : myAlgoFactory(theAlgoFactory)
32{
33}
34
35//=======================================================================
36// Function: Destructor
37// Purpose :
38//=======================================================================
39BRepMesh_FaceDiscret::~BRepMesh_FaceDiscret()
40{
41}
42
ce97cd97 43//! Auxiliary functor for parallel processing of Faces.
44class BRepMesh_FaceDiscret::FaceListFunctor
45{
46public:
47 FaceListFunctor (BRepMesh_FaceDiscret* theAlgo,
48 const Message_ProgressRange& theRange)
49 : myAlgo (theAlgo),
50 myScope (theRange, "Face Discret", theAlgo->myModel->FacesNb())
51 {
52 myRanges.reserve (theAlgo->myModel->FacesNb());
53 for (Standard_Integer aFaceIter = 0; aFaceIter < theAlgo->myModel->FacesNb(); ++aFaceIter)
54 {
55 myRanges.push_back (myScope.Next());
56 }
57 }
58
59 void operator() (const Standard_Integer theFaceIndex) const
60 {
61 if (!myScope.More())
62 {
63 return;
64 }
65 Message_ProgressScope aFaceScope(myRanges[theFaceIndex], NULL, 1);
66 myAlgo->process(theFaceIndex, aFaceScope.Next());
67 }
68
69private:
70 mutable BRepMesh_FaceDiscret* myAlgo;
71 Message_ProgressScope myScope;
72 std::vector<Message_ProgressRange> myRanges;
73};
74
7bd071ed 75//=======================================================================
76// Function: Perform
77// Purpose :
78//=======================================================================
c2a25d52 79Standard_Boolean BRepMesh_FaceDiscret::performInternal(
7bd071ed 80 const Handle(IMeshData_Model)& theModel,
ce97cd97 81 const IMeshTools_Parameters& theParameters,
82 const Message_ProgressRange& theRange)
7bd071ed 83{
84 myModel = theModel;
85 myParameters = theParameters;
86 if (myModel.IsNull())
87 {
88 return Standard_False;
89 }
90
ce97cd97 91 FaceListFunctor aFunctor(this, theRange);
92 OSD_Parallel::For(0, myModel->FacesNb(), aFunctor, !(myParameters.InParallel && myModel->FacesNb() > 1));
93 if (!theRange.More())
94 {
95 return Standard_False;
96 }
7bd071ed 97
98 myModel.Nullify(); // Do not hold link to model.
99 return Standard_True;
100}
101
102//=======================================================================
103// Function: process
104// Purpose :
105//=======================================================================
ce97cd97 106void BRepMesh_FaceDiscret::process(const Standard_Integer theFaceIndex,
107 const Message_ProgressRange& theRange) const
7bd071ed 108{
109 const IMeshData::IFaceHandle& aDFace = myModel->GetFace(theFaceIndex);
110 if (aDFace->IsSet(IMeshData_Failure) ||
111 aDFace->IsSet(IMeshData_Reused))
112 {
113 return;
114 }
115
c2a25d52 116 try
117 {
118 OCC_CATCH_SIGNALS
7bd071ed 119
c2a25d52 120 Handle(IMeshTools_MeshAlgo) aMeshingAlgo =
121 myAlgoFactory->GetAlgo(aDFace->GetSurface()->GetType(), myParameters);
122
123 if (aMeshingAlgo.IsNull())
124 {
125 aDFace->SetStatus(IMeshData_Failure);
126 return;
127 }
128
ce97cd97 129 if (!theRange.More())
130 {
131 aDFace->SetStatus (IMeshData_UserBreak);
132 return;
133 }
134 aMeshingAlgo->Perform(aDFace, myParameters, theRange);
c2a25d52 135 }
136 catch (Standard_Failure const&)
7bd071ed 137 {
c2a25d52 138 aDFace->SetStatus (IMeshData_Failure);
7bd071ed 139 }
7bd071ed 140}