0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BRepMesh / BRepMesh_ModelBuilder.cxx
CommitLineData
7bd071ed 1// Created on: 2016-04-07
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_ModelBuilder.hxx>
17#include <BRepMeshData_Model.hxx>
18#include <BRepMesh_ShapeVisitor.hxx>
19#include <BRepMesh_ShapeTool.hxx>
20#include <IMeshTools_ShapeExplorer.hxx>
7bd071ed 21
22#include <Bnd_Box.hxx>
23#include <BRepBndLib.hxx>
24
25//=======================================================================
26// Function: Constructor
27// Purpose :
28//=======================================================================
29BRepMesh_ModelBuilder::BRepMesh_ModelBuilder ()
30{
31}
32
33//=======================================================================
34// Function: Destructor
35// Purpose :
36//=======================================================================
37BRepMesh_ModelBuilder::~BRepMesh_ModelBuilder ()
38{
39}
40
41//=======================================================================
42// Function: Perform
43// Purpose :
44//=======================================================================
c2a25d52 45Handle (IMeshData_Model) BRepMesh_ModelBuilder::performInternal (
7bd071ed 46 const TopoDS_Shape& theShape,
47 const IMeshTools_Parameters& theParameters)
48{
7bd071ed 49 Handle (BRepMeshData_Model) aModel;
7bd071ed 50
c2a25d52 51 Bnd_Box aBox;
52 BRepBndLib::Add (theShape, aBox, Standard_False);
7bd071ed 53
c2a25d52 54 if (!aBox.IsVoid ())
55 {
56 // Build data model for further processing.
57 aModel = new BRepMeshData_Model (theShape);
7bd071ed 58
c2a25d52 59 if (theParameters.Relative)
60 {
61 Standard_Real aMaxSize;
62 BRepMesh_ShapeTool::BoxMaxDimension (aBox, aMaxSize);
63 aModel->SetMaxSize(aMaxSize);
7bd071ed 64 }
65 else
66 {
c2a25d52 67 aModel->SetMaxSize(Max(theParameters.Deflection,
68 theParameters.DeflectionInterior));
7bd071ed 69 }
c2a25d52 70
71 Handle (IMeshTools_ShapeVisitor) aVisitor =
72 new BRepMesh_ShapeVisitor (aModel);
73
74 IMeshTools_ShapeExplorer aExplorer (theShape);
75 aExplorer.Accept (aVisitor);
76 SetStatus (Message_Done1);
7bd071ed 77 }
c2a25d52 78 else
7bd071ed 79 {
c2a25d52 80 SetStatus (Message_Fail1);
7bd071ed 81 }
82
83 return aModel;
84}