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 |
|
|
|
7 |
francois |
1007 |
|
8 |
francois |
979 |
// 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 |
francois |
1007 |
#include <BRepGProp.hxx> |
26 |
|
|
#include <GProp_GProps.hxx> |
27 |
|
|
#include <STEPControl_Writer.hxx> |
28 |
francois |
979 |
|
29 |
francois |
1007 |
Poly_Build_OCC::Poly_Build_OCC(Poly_Voro* vorotmp,std::string nom):POLY_AFFICHE(),nomfichier(nom),voro(vorotmp) |
30 |
francois |
979 |
{ |
31 |
francois |
1007 |
} |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
void Poly_Build_OCC::construit(bool avecstep) |
35 |
|
|
{ |
36 |
francois |
979 |
TopTools_ListOfShape list_shell; |
37 |
|
|
|
38 |
|
|
// conteneur (boite) |
39 |
|
|
Poly_Point* pnt_min = voro->get_point(0); |
40 |
|
|
Poly_Point* pnt_max = voro->get_point(6); |
41 |
|
|
gp_Pnt coin_min(pnt_min->get_x(), pnt_min->get_y(), pnt_min->get_z()); |
42 |
|
|
gp_Pnt coin_max(pnt_max->get_x(), pnt_max->get_y(), pnt_max->get_z()); |
43 |
|
|
TopoDS_Shape boite = BRepPrimAPI_MakeBox(coin_min,coin_max).Shape(); |
44 |
francois |
1007 |
GProp_GProps vprops; |
45 |
|
|
BRepGProp::VolumeProperties(boite,vprops); |
46 |
|
|
double volumeboite=vprops.Mass(); |
47 |
francois |
979 |
list_shell.Append(boite); |
48 |
francois |
1007 |
|
49 |
francois |
979 |
for (int i=0; i < voro->get_nb_cell(); i++) |
50 |
|
|
{ |
51 |
francois |
1007 |
bool passeface=true; |
52 |
francois |
979 |
BRepBuilderAPI_Sewing sewing; |
53 |
|
|
Poly_Cellule* cell = voro->get_cell(i); |
54 |
|
|
|
55 |
|
|
// création des vertex |
56 |
|
|
std::vector< TopoDS_Vertex > cell_vertex; |
57 |
|
|
for(int j=0; j < cell->get_nb_noeud(); j++) |
58 |
francois |
1007 |
{ |
59 |
francois |
979 |
Poly_Noeud* noeud = cell->get_noeud(j); |
60 |
francois |
1007 |
if (noeud->get_maitre_fusion()==noeud) |
61 |
|
|
{ |
62 |
|
|
double x = noeud->get_x(); |
63 |
|
|
double y = noeud->get_y(); |
64 |
|
|
double z = noeud->get_z(); |
65 |
|
|
gp_Pnt pnt(x, y, z); |
66 |
|
|
TopoDS_Vertex vtx = BRepBuilderAPI_MakeVertex(pnt); |
67 |
|
|
cell_vertex.push_back(vtx); |
68 |
|
|
noeud->change_vertex(vtx); |
69 |
|
|
} |
70 |
francois |
979 |
} |
71 |
|
|
// création des edges, faces et shell |
72 |
|
|
for(int j=0; j < cell->get_nb_face(); j++) |
73 |
|
|
{ |
74 |
|
|
Poly_Face* cell_face = cell->get_face(j); |
75 |
|
|
BRepBuilderAPI_MakeWire brep_wire; |
76 |
francois |
1007 |
bool passe=false; |
77 |
francois |
979 |
for(int k=0; k < cell_face->get_nb_noeud()-1; k++) |
78 |
|
|
{ |
79 |
|
|
int v1 = cell_face->get_noeud(k); |
80 |
|
|
int v2 = cell_face->get_noeud(k+1); |
81 |
francois |
1007 |
Poly_Noeud* n1=cell->get_noeud(v1); |
82 |
|
|
Poly_Noeud* n2=cell->get_noeud(v2); |
83 |
|
|
TopoDS_Vertex vtx1=n1->get_maitre_fusion()->get_vertex(); |
84 |
|
|
TopoDS_Vertex vtx2=n2->get_maitre_fusion()->get_vertex(); |
85 |
|
|
/*gp_Pnt pnt1=BRep_Tool::Pnt(vtx1); |
86 |
|
|
gp_Pnt pnt2=BRep_Tool::Pnt(vtx2); |
87 |
|
|
double x = pnt1.X(); |
88 |
|
|
double y = pnt1.Y(); |
89 |
|
|
double z = pnt1.Z(); |
90 |
|
|
double x2 = pnt2.X(); |
91 |
|
|
double y2 = pnt2.Y(); |
92 |
|
|
double z2 = pnt2.Z();*/ |
93 |
|
|
if (vtx1!=vtx2) |
94 |
|
|
{ |
95 |
|
|
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(vtx1,vtx2); |
96 |
|
|
brep_wire.Add(edge); |
97 |
|
|
passe=true; |
98 |
|
|
} |
99 |
francois |
979 |
} |
100 |
|
|
|
101 |
|
|
int v1 = cell_face->get_last_noeud(); |
102 |
|
|
int v2 = cell_face->get_noeud(0); |
103 |
francois |
1007 |
Poly_Noeud* n1=cell->get_noeud(v1); |
104 |
|
|
Poly_Noeud* n2=cell->get_noeud(v2); |
105 |
|
|
TopoDS_Vertex vtx1=n1->get_maitre_fusion()->get_vertex(); |
106 |
|
|
TopoDS_Vertex vtx2=n2->get_maitre_fusion()->get_vertex(); |
107 |
|
|
if (vtx1!=vtx2) |
108 |
|
|
{ |
109 |
|
|
TopoDS_Edge lastedge = BRepBuilderAPI_MakeEdge(vtx1,vtx2); |
110 |
|
|
brep_wire.Add(lastedge); passe=true; |
111 |
|
|
} |
112 |
francois |
979 |
|
113 |
francois |
1007 |
if (passe) |
114 |
|
|
{ |
115 |
|
|
TopoDS_Wire Wire_face = brep_wire.Wire(); |
116 |
|
|
BRepBuilderAPI_MakeFace facemaker(Wire_face); |
117 |
|
|
if (facemaker.IsDone()) |
118 |
|
|
{ |
119 |
|
|
const TopoDS_Face newFace = facemaker.Face(); |
120 |
|
|
sewing.Add(newFace); |
121 |
|
|
} |
122 |
|
|
else |
123 |
|
|
passeface=false; |
124 |
|
|
} |
125 |
|
|
else passeface=false; |
126 |
francois |
979 |
} |
127 |
|
|
|
128 |
francois |
1007 |
if (passeface==true) |
129 |
|
|
{ |
130 |
|
|
sewing.Perform(); |
131 |
|
|
TopoDS_Shell shell = TopoDS::Shell(sewing.SewedShape()); |
132 |
|
|
/*BRepBuilderAPI_MakeSolid solidmaker(shell); |
133 |
|
|
TopoDS_Solid solid = solidmaker.Solid(); |
134 |
|
|
list_shell.Append(solid);*/ |
135 |
|
|
list_shell.Append(shell); |
136 |
|
|
} |
137 |
francois |
979 |
} |
138 |
francois |
1007 |
char message[2000]; |
139 |
|
|
sprintf(message," Nombre de cristaux construits = %d",list_shell.Size()-1); |
140 |
|
|
affiche(message); |
141 |
francois |
979 |
BRepAlgoAPI_BuilderAlgo fragments; |
142 |
|
|
fragments.SetArguments(list_shell); |
143 |
|
|
fragments.Build(); |
144 |
|
|
TopoDS_Shape resultat = fragments.Shape(); |
145 |
|
|
|
146 |
|
|
TopTools_IndexedMapOfShape map_TopoDS_Solid; |
147 |
|
|
TopExp::MapShapes(resultat, TopAbs_SOLID,map_TopoDS_Solid); |
148 |
|
|
|
149 |
|
|
BRep_Builder brep_builder; |
150 |
|
|
TopoDS_Compound Compound; |
151 |
|
|
brep_builder.MakeCompound(Compound); |
152 |
francois |
1007 |
double volumetotal=0.; |
153 |
francois |
979 |
for(TopTools_IndexedMapOfShape::Iterator it_solid(map_TopoDS_Solid);it_solid.More();it_solid.Next()) |
154 |
|
|
{ |
155 |
francois |
1007 |
GProp_GProps vprops; |
156 |
|
|
BRepGProp::VolumeProperties(it_solid.Value(),vprops); |
157 |
|
|
double volume=vprops.Mass(); |
158 |
|
|
if (volume<0.95*volumeboite) |
159 |
|
|
if (volume>1e-10) |
160 |
|
|
{ |
161 |
|
|
brep_builder.Add(Compound,it_solid.Value()); |
162 |
|
|
volumetotal=volumetotal+volume; |
163 |
|
|
} |
164 |
francois |
979 |
} |
165 |
francois |
1007 |
sprintf(message," Volume des cristaux assemblés = %lf",volumetotal); |
166 |
|
|
affiche(message); |
167 |
|
|
|
168 |
francois |
983 |
BRepTools::Write(Compound,(char*)nomfichier.c_str()); |
169 |
francois |
1007 |
|
170 |
|
|
if (avecstep) |
171 |
|
|
{ |
172 |
|
|
STEPControl_Writer stepwriter; |
173 |
|
|
stepwriter.Transfer(Compound,STEPControl_ManifoldSolidBrep); |
174 |
|
|
std::string nomstep=nomfichier.substr(0,nomfichier.find_last_of("."))+".stp"; |
175 |
|
|
stepwriter.Write(nomstep.c_str()); |
176 |
|
|
affiche((char*)""); |
177 |
|
|
} |
178 |
francois |
979 |
} |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
Poly_Build_OCC::~Poly_Build_OCC() |
182 |
|
|
{ |
183 |
|
|
} |
184 |
francois |
1007 |
|