1 |
francois |
979 |
#include "poly_build_occ.h" |
2 |
|
|
#include "poly_voro.h" |
3 |
|
|
#include "poly_noeud.h" |
4 |
|
|
#include "poly_face.h" |
5 |
|
|
#include "poly_cellule.h" |
6 |
|
|
#include <iostream> |
7 |
|
|
|
8 |
|
|
// include OCC |
9 |
|
|
#include <TopoDS_Shape.hxx> |
10 |
|
|
#include <gp_Pnt.hxx> |
11 |
|
|
#include <BRepPrimAPI_MakeBox.hxx> |
12 |
|
|
#include <BRepAlgoAPI_BuilderAlgo.hxx> |
13 |
|
|
#include <STEPCAFControl_Writer.hxx> |
14 |
|
|
#include <BRepTools.hxx> |
15 |
|
|
#include <BRepBuilderAPI_MakeVertex.hxx> |
16 |
|
|
#include <BRepBuilderAPI_MakeEdge.hxx> |
17 |
|
|
#include <BRepBuilderAPI_MakeWire.hxx> |
18 |
|
|
#include <BRepBuilderAPI_MakeFace.hxx> |
19 |
|
|
#include <BRepBuilderAPI_Sewing.hxx> |
20 |
|
|
#include <BRepBuilderAPI_MakeSolid.hxx> |
21 |
|
|
#include <TopoDS.hxx> |
22 |
|
|
#include <TopTools_IndexedMapOfShape.hxx> |
23 |
|
|
#include <TopExp.hxx> |
24 |
|
|
#include <BRep_Builder.hxx> |
25 |
|
|
|
26 |
francois |
983 |
Poly_Build_OCC::Poly_Build_OCC(Poly_Voro* voro,std::string nom):nomfichier(nom) |
27 |
francois |
979 |
{ |
28 |
|
|
TopTools_ListOfShape list_shell; |
29 |
|
|
|
30 |
|
|
// conteneur (boite) |
31 |
|
|
Poly_Point* pnt_min = voro->get_point(0); |
32 |
|
|
Poly_Point* pnt_max = voro->get_point(6); |
33 |
|
|
gp_Pnt coin_min(pnt_min->get_x(), pnt_min->get_y(), pnt_min->get_z()); |
34 |
|
|
gp_Pnt coin_max(pnt_max->get_x(), pnt_max->get_y(), pnt_max->get_z()); |
35 |
|
|
TopoDS_Shape boite = BRepPrimAPI_MakeBox(coin_min,coin_max).Shape(); |
36 |
|
|
list_shell.Append(boite); |
37 |
|
|
|
38 |
|
|
for (int i=0; i < voro->get_nb_cell(); i++) |
39 |
|
|
{ |
40 |
|
|
BRepBuilderAPI_Sewing sewing; |
41 |
|
|
Poly_Cellule* cell = voro->get_cell(i); |
42 |
|
|
|
43 |
|
|
// création des vertex |
44 |
|
|
std::vector< TopoDS_Vertex > cell_vertex; |
45 |
|
|
for(int j=0; j < cell->get_nb_noeud(); j++) |
46 |
|
|
{ |
47 |
|
|
Poly_Noeud* noeud = cell->get_noeud(j); |
48 |
|
|
double x = noeud->get_x(); |
49 |
|
|
double y = noeud->get_y(); |
50 |
|
|
double z = noeud->get_z(); |
51 |
|
|
gp_Pnt pnt(x, y, z); |
52 |
|
|
TopoDS_Vertex vtx = BRepBuilderAPI_MakeVertex(pnt); |
53 |
|
|
cell_vertex.push_back(vtx); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
// création des edges, faces et shell |
57 |
|
|
for(int j=0; j < cell->get_nb_face(); j++) |
58 |
|
|
{ |
59 |
|
|
Poly_Face* cell_face = cell->get_face(j); |
60 |
|
|
BRepBuilderAPI_MakeWire brep_wire; |
61 |
|
|
|
62 |
|
|
for(int k=0; k < cell_face->get_nb_noeud()-1; k++) |
63 |
|
|
{ |
64 |
|
|
int v1 = cell_face->get_noeud(k); |
65 |
|
|
int v2 = cell_face->get_noeud(k+1); |
66 |
|
|
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(cell_vertex[v1], cell_vertex[v2]); |
67 |
|
|
brep_wire.Add(edge); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
int v1 = cell_face->get_last_noeud(); |
71 |
|
|
int v2 = cell_face->get_noeud(0); |
72 |
|
|
TopoDS_Edge lastedge = BRepBuilderAPI_MakeEdge(cell_vertex[v1], cell_vertex[v2]); |
73 |
|
|
brep_wire.Add(lastedge); |
74 |
|
|
|
75 |
|
|
TopoDS_Wire Wire_face = brep_wire.Wire(); |
76 |
|
|
TopoDS_Face newFace = BRepBuilderAPI_MakeFace(Wire_face); |
77 |
|
|
sewing.Add(newFace); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
sewing.Perform(); |
81 |
|
|
TopoDS_Shell shell = TopoDS::Shell(sewing.SewedShape()); |
82 |
|
|
list_shell.Append(shell); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
BRepAlgoAPI_BuilderAlgo fragments; |
86 |
|
|
fragments.SetArguments(list_shell); |
87 |
|
|
fragments.Build(); |
88 |
|
|
TopoDS_Shape resultat = fragments.Shape(); |
89 |
|
|
|
90 |
|
|
TopTools_IndexedMapOfShape map_TopoDS_Solid; |
91 |
|
|
TopExp::MapShapes(resultat, TopAbs_SOLID,map_TopoDS_Solid); |
92 |
|
|
|
93 |
|
|
BRep_Builder brep_builder; |
94 |
|
|
TopoDS_Compound Compound; |
95 |
|
|
brep_builder.MakeCompound(Compound); |
96 |
|
|
for(TopTools_IndexedMapOfShape::Iterator it_solid(map_TopoDS_Solid);it_solid.More();it_solid.Next()) |
97 |
|
|
{ |
98 |
|
|
|
99 |
|
|
brep_builder.Add(Compound,it_solid.Value()); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
francois |
983 |
BRepTools::Write(Compound,(char*)nomfichier.c_str()); |
106 |
francois |
979 |
|
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
Poly_Build_OCC::~Poly_Build_OCC() |
111 |
|
|
{ |
112 |
|
|
} |