0029296: Data Exchange - implement import of mesh data from files in OBJ format
[occt.git] / src / BRepMesh / BRepMesh_IncrementalMesh.cxx
CommitLineData
b311480e 1// Created on: 1995-06-20
2// Created by: Stagiaire Alain JOURDAIN
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
9bdafcbe 17#include <BRepMesh_IncrementalMesh.hxx>
7bd071ed 18#include <BRepMesh_Context.hxx>
0b97567d 19#include <BRepMesh_PluginMacro.hxx>
7bd071ed 20#include <IMeshData_Status.hxx>
21#include <IMeshData_Face.hxx>
22#include <IMeshData_Wire.hxx>
23#include <IMeshTools_MeshBuilder.hxx>
92efcf78 24
0b97567d
K
25namespace
26{
27 //! Default flag to control parallelization for BRepMesh_IncrementalMesh
28 //! tool returned for Mesh Factory
29 static Standard_Boolean IS_IN_PARALLEL = Standard_False;
a3f6f591 30}
0b97567d 31
9bdafcbe 32//=======================================================================
fc9b36d6 33//function : Default constructor
9bdafcbe 34//purpose :
35//=======================================================================
fc9b36d6 36BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh()
7bd071ed 37: myModified(Standard_False),
38 myStatus(IMeshData_NoError)
7fd59977 39{
7fd59977 40}
41
42//=======================================================================
fc9b36d6 43//function : Constructor
7fd59977 44//purpose :
45//=======================================================================
e71669c6 46BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( const TopoDS_Shape& theShape,
47 const Standard_Real theLinDeflection,
48 const Standard_Boolean isRelative,
49 const Standard_Real theAngDeflection,
7bd071ed 50 const Standard_Boolean isInParallel)
51: myModified(Standard_False),
52 myStatus(IMeshData_NoError)
e71669c6 53{
54 myParameters.Deflection = theLinDeflection;
7bd071ed 55 myParameters.Angle = theAngDeflection;
56 myParameters.Relative = isRelative;
e71669c6 57 myParameters.InParallel = isInParallel;
e71669c6 58
59 myShape = theShape;
60 Perform();
61}
62
63//=======================================================================
64//function : Constructor
65//purpose :
66//=======================================================================
7bd071ed 67BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh(
68 const TopoDS_Shape& theShape,
69 const IMeshTools_Parameters& theParameters)
e71669c6 70 : myParameters(theParameters)
7fd59977 71{
7bd071ed 72 myShape = theShape;
0b97567d 73 Perform();
7fd59977 74}
75
76//=======================================================================
fc9b36d6 77//function : Destructor
7fd59977 78//purpose :
79//=======================================================================
fc9b36d6 80BRepMesh_IncrementalMesh::~BRepMesh_IncrementalMesh()
7fd59977 81{
82}
83
84//=======================================================================
fc9b36d6 85//function : Perform
86//purpose :
7fd59977 87//=======================================================================
fc9b36d6 88void BRepMesh_IncrementalMesh::Perform()
7fd59977 89{
7bd071ed 90 initParameters();
fc9b36d6 91
7bd071ed 92 Handle(BRepMesh_Context) aContext = new BRepMesh_Context;
93 aContext->SetShape(Shape());
94 aContext->ChangeParameters() = myParameters;
95 aContext->ChangeParameters().CleanModel = Standard_False;
fc9b36d6 96
7bd071ed 97 IMeshTools_MeshBuilder aIncMesh(aContext);
98 aIncMesh.Perform();
fc9b36d6 99
7bd071ed 100 myStatus = IMeshData_NoError;
101 const Handle(IMeshData_Model)& aModel = aContext->GetModel();
102 for (Standard_Integer aFaceIt = 0; aFaceIt < aModel->FacesNb(); ++aFaceIt)
fc9b36d6 103 {
7bd071ed 104 const IMeshData::IFaceHandle& aDFace = aModel->GetFace(aFaceIt);
105 myStatus |= aDFace->GetStatusMask();
fc9b36d6 106
7bd071ed 107 for (Standard_Integer aWireIt = 0; aWireIt < aDFace->WiresNb(); ++aWireIt)
ab58a62b 108 {
7bd071ed 109 const IMeshData::IWireHandle& aDWire = aDFace->GetWire(aWireIt);
110 myStatus |= aDWire->GetStatusMask();
ab58a62b 111 }
7fd59977 112 }
113
7bd071ed 114 setDone();
7fd59977 115}
0b97567d
K
116
117//=======================================================================
118//function : Discret
119//purpose :
120//=======================================================================
fc9b36d6 121Standard_Integer BRepMesh_IncrementalMesh::Discret(
122 const TopoDS_Shape& theShape,
123 const Standard_Real theDeflection,
124 const Standard_Real theAngle,
ceb418e1 125 BRepMesh_DiscretRoot* &theAlgo)
0b97567d
K
126{
127 BRepMesh_IncrementalMesh* anAlgo = new BRepMesh_IncrementalMesh();
e71669c6 128 anAlgo->ChangeParameters().Deflection = theDeflection;
7bd071ed 129 anAlgo->ChangeParameters().Angle = theAngle;
e71669c6 130 anAlgo->ChangeParameters().InParallel = IS_IN_PARALLEL;
7bd071ed 131 anAlgo->SetShape (theShape);
0b97567d
K
132 theAlgo = anAlgo;
133 return 0; // no error
134}
135
136//=======================================================================
137//function : IsParallelDefault
138//purpose :
139//=======================================================================
140Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault()
141{
0b97567d 142 return IS_IN_PARALLEL;
0b97567d
K
143}
144
145//=======================================================================
146//function : Discret
147//purpose :
148//=======================================================================
fc9b36d6 149void BRepMesh_IncrementalMesh::SetParallelDefault(
150 const Standard_Boolean theInParallel)
0b97567d
K
151{
152 IS_IN_PARALLEL = theInParallel;
153}
154
155//! Export Mesh Plugin entry function
156DISCRETPLUGIN(BRepMesh_IncrementalMesh)