File: occ_utils.cpp

package info (click to toggle)
netgen 6.2.2601%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,076 kB
  • sloc: cpp: 166,627; tcl: 6,310; python: 2,868; sh: 528; makefile: 90
file content (81 lines) | stat: -rw-r--r-- 2,487 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>
#include <BRep_TVertex.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRepTools.hxx>

#include "occ_utils.hpp"
#include "occgeom.hpp"

namespace netgen
{
    Point<3> occ2ng (const TopoDS_Shape& shape)
    {
      if(shape.ShapeType() != TopAbs_VERTEX)
        throw Exception("Try to convert non vertex to point!");
      return occ2ng( BRep_Tool::Pnt(TopoDS::Vertex(shape)) );
    }

    Transformation<3> occ2ng (const gp_Trsf & occ_trafo)
    {
        Transformation<3> trafo;
        auto v = occ_trafo.TranslationPart();
        auto m = occ_trafo.VectorialPart();
        auto & tv = trafo.GetVector();
        auto & tm = trafo.GetMatrix();
        for(auto i : Range(3))
        {
            tv[i] = v.Coord(i+1);
            for(auto k : Range(3))
                tm(i,k) = m(i+1,k+1);
        }
        return trafo;
    }

  Transformation<3> occ2ng (const gp_GTrsf & occ_trafo)
    {
        Transformation<3> trafo;
        auto v = occ_trafo.TranslationPart();
        auto m = occ_trafo.VectorialPart();
        auto & tv = trafo.GetVector();
        auto & tm = trafo.GetMatrix();
        for(auto i : Range(3))
        {
            tv[i] = v.Coord(i+1);
            for(auto k : Range(3))
                tm(i,k) = m(i+1,k+1);
        }
        return trafo;
    }

    Box<3> GetBoundingBox( const TopoDS_Shape & shape )
    {
        Bnd_Box bb;
#if OCC_VERSION_HEX < 0x070000
        BRepBndLib::Add (shape, bb);
#else
        BRepBndLib::Add (shape, bb, true);
#endif
        return {occ2ng(bb.CornerMin()), occ2ng(bb.CornerMax())};
    }

    Standard_Integer BuildTriangulation( const TopoDS_Shape & shape )
    {
       BRepTools::Clean (shape);
       // double deflection = 0.01;

       // https://dev.opencascade.org/doc/overview/html/occt_user_guides__mesh.html
       // from Standard_Boolean meshing_imeshtools_parameters()
       IMeshTools_Parameters aMeshParams;
       aMeshParams.Deflection               = 0.01;
       aMeshParams.Angle                    = 0.5;
       aMeshParams.Relative                 = Standard_True;
       aMeshParams.InParallel               = Standard_True;
       aMeshParams.MinSize                  = Precision::Confusion();
       aMeshParams.InternalVerticesMode     = Standard_True;
       aMeshParams.ControlSurfaceDeflection = Standard_True;

       BRepMesh_IncrementalMesh aMesher (shape, aMeshParams);
       return  aMesher.GetStatusFlags();
    }
}