ROOT  6.06/09
Reference Guide
TGeoToOCC.cxx
Go to the documentation of this file.
1 // @(#)geom/geocad:$Id$
2 // Author: Cinzia Luzzi 5/5/2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 ////////////////////////////////////////////////////////////////////////////////
13 // TGeoToOCC Class //
14 // -------------------- //
15 // //
16 // This class contains implementation of converting ROOT's //
17 // geometry shapes to OpenCascade shapes. // //
18 // Each ROOT shape is translated in the corrispondent OCC shape using the //
19 // following methods: //
20 // //
21 // TGeoBBox -> OCC_Box(..) //
22 // TGeoSphere -> OCC_Sphere(..) //
23 // TGeoArb8 -> OCC_Arb8(..) //
24 // TGeoConeSeg -> OCC_Cones(..) //
25 // TGeoCone -> OCC_Cones(..) //
26 // TGeoPara -> OCC_ParaTrap(..) //
27 // TGeoTrap -> OCC_ParaTrap(..) //
28 // TGeoGtra -> OCC_ParaTrap(..) //
29 // TGeoTrd1 -> OCC_Trd(..) //
30 // TGeoTrd2 -> OCC_Trd(..) //
31 // TGeoTubeSeg -> OCC_Tube(..) //
32 // TGeoCtub -> OCC_Cuttub(..) //
33 // TGeoTube -> OCC_TubeSeg(..) //
34 // TGeoPcon -> OCC_Pcon(..) //
35 // TGeoTorus -> OCC_Torus(..) //
36 // TGeoPgon -> OCC_Pgon(..) //
37 // TGeoEltu -> OCC_Eltu(..) //
38 // TGeoHype -> OCC_Hype(..) //
39 // TGeoXtru -> OCC_Xtru(..) //
40 // TGeoCompositeShape -> OCC_CompositeShape(..) //
41 // //
42 // A log file is created in /tmp/TGeoCad.log //
43 // //
44 ////////////////////////////////////////////////////////////////////////////////
45 
46 
47 #include "TGeoToOCC.h"
48 
49 
50 //Cascade
51 
52 #include <TopoDS.hxx>
53 #include <TopoDS_Shell.hxx>
54 #include <TopoDS_Face.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Solid.hxx>
57 #include <gp_Pnt.hxx>
58 #include <gp_Ax1.hxx>
59 #include <gp_Circ.hxx>
60 #include <gp_Dir.hxx>
61 #include <gp_Hypr.hxx>
62 #include <gp_Pln.hxx>
63 #include <GC_MakeArcOfCircle.hxx>
64 #include <GC_MakeEllipse.hxx>
65 #include <BRepBuilderAPI_MakeVertex.hxx>
66 #include <BRepBuilderAPI_MakeEdge.hxx>
67 #include <BRepBuilderAPI_MakeWire.hxx>
68 #include <BRepBuilderAPI_MakeFace.hxx>
69 #include <BRepBuilderAPI_MakeShell.hxx>
70 #include <BRepBuilderAPI_MakeSolid.hxx>
71 #include <BRepBuilderAPI_Transform.hxx>
72 #include <BRepBuilderAPI_MakePolygon.hxx>
73 #include <BRepBuilderAPI_Sewing.hxx>
74 #include <BRepAlgo_Section.hxx>
75 #include <BRepPrimAPI_MakeSphere.hxx>
76 #include <BRepOffsetAPI_ThruSections.hxx>
77 #include <BRepPrimAPI_MakeCylinder.hxx>
78 #include <BRepPrimAPI_MakeCone.hxx>
79 #include <BRepPrimAPI_MakeTorus.hxx>
80 #include <BRepPrimAPI_MakeRevol.hxx>
81 #include <BRepPrimAPI_MakePrism.hxx>
82 #include <BRepPrimAPI_MakeWedge.hxx>
83 #include <BRepPrimAPI_MakeBox.hxx>
84 #include <TopExp_Explorer.hxx>
85 #include <BRepAlgoAPI_Cut.hxx>
86 #include <BRepAlgoAPI_Fuse.hxx>
87 #include <BRepAlgoAPI_Common.hxx>
88 #include <BRepAlgo_Cut.hxx>
89 #include <Geom_Plane.hxx>
90 #include <BRepClass3d_SolidClassifier.hxx>
91 #include <BRepGProp.hxx>
92 #include <GProp_GProps.hxx>
93 #include <TColgp_HArray1OfPnt.hxx>
94 #include <ShapeFix_ShapeTolerance.hxx>
95 
96 //ROOT
97 #include "TString.h"
98 #include "TClass.h"
99 #include "TGeoBoolNode.h"
100 #include "TGeoShapeAssembly.h"
101 #include "TGeoTrd1.h"
102 #include "TGeoTrd2.h"
103 #include "TGeoArb8.h"
104 #include "TGeoPara.h"
105 #include "TGeoTorus.h"
106 #include "TGeoCone.h"
107 #include "TGeoTube.h"
108 #include "TGeoEltu.h"
109 #include "TGeoSphere.h"
110 #include "TGeoPcon.h"
111 #include "TGeoPgon.h"
112 #include "TGeoHype.h"
113 #include "TGeoPolygon.h"
114 #include "TGeoMatrix.h"
115 
116 #include <exception>
117 
118 
119 TGeoToOCC::TGeoToOCC():fOccShape()
120 {
121 
122 }
123 
125 {
126 
127 }
128 
129 TopoDS_Shape TGeoToOCC::OCC_SimpleShape(TGeoShape *TG_Shape)
130 {
131  TString type = TG_Shape->IsA()->GetName();
132  out.open("/tmp/TGeoCad.log",ios::app);
133  out<<"Translating: "<<type<<endl;
134  out.close();
135  if(TG_Shape->IsA()==TGeoTube::Class()) {
136  TGeoTube* TG_Tube=(TGeoTube*)TG_Shape;
137  return OCC_Tube(TG_Tube->GetRmin(), TG_Tube->GetRmax(),TG_Tube->GetDz(),0, 0);
138  } else if(TG_Shape->IsA()==TGeoTubeSeg::Class()) {
139  TGeoTubeSeg* TG_TubeSeg=(TGeoTubeSeg*)TG_Shape;
140  Double_t r = (TG_TubeSeg->GetPhi2()-TG_TubeSeg->GetPhi1());
141  return OCC_Tube(TG_TubeSeg->GetRmin(), TG_TubeSeg->GetRmax(),TG_TubeSeg->GetDz(),(TG_TubeSeg->GetPhi1())*M_PI/180., r*M_PI/180.);
142  } else if(TG_Shape->IsA()==TGeoEltu::Class()) {
143  TGeoEltu* TG_Eltu=(TGeoEltu*)TG_Shape;
144  return OCC_EllTube(TG_Eltu->GetA(),TG_Eltu->GetB() , TG_Eltu->GetDz());
145  } else if(TG_Shape->IsA()==TGeoCtub::Class()) {
146  TGeoCtub* TG_Ctub=(TGeoCtub*)TG_Shape;
147  Double_t r = (TG_Ctub->GetPhi2()-TG_Ctub->GetPhi1());
148  return OCC_Cuttub(TG_Ctub->GetRmin(), TG_Ctub->GetRmax(), TG_Ctub->GetDz(),
149  TG_Ctub->GetPhi1()*M_PI/180.,r*M_PI/180.,TG_Ctub->GetNlow(),TG_Ctub->GetNhigh());
150  } else if(TG_Shape->IsA()==TGeoCone::Class()) {
151  TGeoCone* TG_Cone=(TGeoCone*)TG_Shape;
152  return OCC_Cones(TG_Cone->GetRmin1(),TG_Cone->GetRmax1(),TG_Cone->GetRmin2(), TG_Cone->GetRmax2(),TG_Cone->GetDz(), 0, 2*M_PI);
153  } else if(TG_Shape->IsA()==TGeoConeSeg::Class()) {
154  TGeoConeSeg* TG_ConeSeg=(TGeoConeSeg*)TG_Shape;
155  Double_t r = (TG_ConeSeg->GetPhi2()-TG_ConeSeg->GetPhi1());
156  return OCC_Cones(TG_ConeSeg->GetRmin1(), TG_ConeSeg->GetRmax1(),TG_ConeSeg->GetRmin2(), TG_ConeSeg->GetRmax2(),
157  TG_ConeSeg->GetDz(), (TG_ConeSeg->GetPhi1())*M_PI/180., r*M_PI/180.);
158  } else if(TG_Shape->IsA()==TGeoTorus::Class()) {
159  TGeoTorus* TG_Torus=(TGeoTorus*)TG_Shape;
160  Double_t DPhi=(Double_t)TG_Torus->GetDphi()-TG_Torus->GetPhi1();
161  if (DPhi<0)
162  DPhi=(Double_t)TG_Torus->GetPhi1()-TG_Torus->GetDphi();
163  Double_t Phi1= (Double_t)TG_Torus->GetPhi1();
164  return OCC_Torus((Double_t)TG_Torus->GetRmin(),(Double_t)TG_Torus->GetRmax(),(Double_t)TG_Torus->GetR(),
165  Phi1*M_PI/180., DPhi*M_PI/180.);
166  } else if(TG_Shape->IsA()==TGeoSphere::Class()) {
167  TGeoSphere* TG_Sphere=(TGeoSphere*)TG_Shape;
168  Double_t DPhi = (TG_Sphere->GetPhi2()-TG_Sphere->GetPhi1());
169  Double_t DTheta = (TG_Sphere->GetTheta2()-TG_Sphere->GetTheta1());
170  return OCC_Sphere(TG_Sphere->GetRmin(), TG_Sphere->GetRmax(),(TG_Sphere->GetPhi1())*M_PI/180., DPhi*M_PI/180.,
171  TG_Sphere->GetTheta1()*M_PI/180., DTheta*M_PI/180.);
172  } else if(TG_Shape->IsA()==TGeoPcon::Class()) {
173  TGeoPcon* TG_Pcon=(TGeoPcon*)TG_Shape;
174  return OCC_Pcon((TG_Pcon->GetPhi1())*M_PI/180.,
175  (TG_Pcon->GetDphi())*M_PI/180.,TG_Pcon->GetNz(),TG_Pcon->GetRmin(),TG_Pcon->GetRmax(),TG_Pcon->GetZ());
176  } else if(TG_Shape->IsA()==TGeoPgon::Class()) {
177  TGeoPgon* TG_Pgon=(TGeoPgon*)TG_Shape;
178  Int_t numpoints=TG_Pgon->GetNmeshVertices();
179  Double_t *p = new Double_t[3*numpoints];
180  TG_Pgon->SetPoints(p);
181  return OCC_Pgon(TG_Pgon->GetNsegments(),TG_Pgon->GetNz(),p,TG_Pgon->GetPhi1(),TG_Pgon->GetDphi(),numpoints*3);
182  } else if(TG_Shape->IsA()==TGeoHype::Class()) {
183  TGeoHype* TG_Hype=(TGeoHype*)TG_Shape;
184  return OCC_Hype(TG_Hype->GetRmin(), TG_Hype->GetRmax(), TG_Hype->GetStIn(), TG_Hype->GetStOut(),TG_Hype->GetDz());
185  } else if(TG_Shape->IsA()==TGeoXtru::Class()) {
186  return OCC_Xtru((TGeoXtru*)TG_Shape);
187  } else if (TG_Shape->IsA()==TGeoBBox::Class()) {
188  TGeoBBox * TG_Box=(TGeoBBox*)TG_Shape;
189  const Double_t * Origin = TG_Box->GetOrigin();
190  return OCC_Box(TG_Box->GetDX(),TG_Box->GetDY(),TG_Box->GetDZ(),Origin[0],Origin[1],Origin[2]);
191  } else if (TG_Shape->IsA()==TGeoTrd1::Class()) {
192  TGeoTrd1 * TG_Trd1=(TGeoTrd1*)TG_Shape;
193  return OCC_Trd(TG_Trd1->GetDx1(),TG_Trd1->GetDx2(),TG_Trd1->GetDy(),TG_Trd1->GetDy(),TG_Trd1->GetDz());
194  } else if (TG_Shape->IsA()==TGeoTrd2::Class()) {
195  TGeoTrd2 * TG_Trd2=(TGeoTrd2*)TG_Shape;
196  return OCC_Trd(TG_Trd2->GetDx1(),TG_Trd2->GetDx2(),TG_Trd2->GetDy1(),TG_Trd2->GetDy2(),TG_Trd2->GetDz());
197  } else if (TG_Shape->IsA()==TGeoArb8::Class()) {
198  TGeoArb8 * TG_Arb8=(TGeoArb8*)TG_Shape;
199  Double_t vertex[24];
200  TG_Shape->SetPoints(vertex);
201  return OCC_Arb8(TG_Arb8->GetDz(),TG_Arb8->GetVertices(),vertex);
202  } else if (TG_Shape->IsA()==TGeoShapeAssembly::Class()) {
203  TGeoBBox * TG_Ass=(TGeoBBox*)TG_Shape;
204  return OCC_Box(TG_Ass->GetDX(),TG_Ass->GetDY(),TG_Ass->GetDZ(),0,0,0);
205  } else if (TG_Shape->IsA()==TGeoPara::Class()) {
206  //TGeoPara * TG_Para=(TGeoPara*)TG_Shape;
207  Double_t vertex[24];
208  TG_Shape->SetPoints(vertex);
209  return OCC_ParaTrap(vertex);
210  } else if (TG_Shape->IsA()==TGeoTrap::Class()) {
211  //TGeoTrap * TG_Trap=(TGeoTrap*)TG_Shape;
212  Double_t vertex[24];
213  TG_Shape->SetPoints(vertex);
214  return OCC_ParaTrap(vertex);
215  } else if (TG_Shape->IsA()==TGeoGtra::Class()) {
216  //TGeoGtra * TG_Tra=(TGeoGtra*)TG_Shape;
217  Double_t vertex[24];
218  TG_Shape->SetPoints(vertex);
219  return OCC_ParaTrap(vertex);
220  } else {
221  throw std::domain_error("Unknown Shape");
222  }
223 }
224 
226 {
227  Double_t const *t;
228  Double_t const *r;
229  gp_Trsf Transl;
230  gp_Trsf Transf;
231  out.open("/tmp/TGeoCad.log",ios::app);
232  TopoDS_Shape leftOCCShape;
233  TopoDS_Shape rightOCCShape;
234  TopoDS_Shape result;
235  GProp_GProps System;
236  GProp_GProps System2;
237  TGeoBoolNode *boolNode=comp->GetBoolNode();
238  TGeoShape *rightShape=boolNode->GetRightShape();
239  TString rightSName = rightShape->IsA()->GetName();
240  TGeoShape *leftShape=boolNode->GetLeftShape();
241  TString leftSName = leftShape->IsA()->GetName();
242  TGeoMatrix *leftMtx=boolNode->GetLeftMatrix();
243  TGeoMatrix *rightMtx=boolNode->GetRightMatrix();
244  TGeoHMatrix leftGlobMatx=m*(*leftMtx);
245  if(leftSName == "TGeoCompositeShape") {
246  leftOCCShape=OCC_CompositeShape((TGeoCompositeShape*)leftShape, leftGlobMatx);
247  } else {
248  t=leftGlobMatx.GetTranslation();
249  r=leftGlobMatx.GetRotationMatrix();
250  Transl.SetTranslation(gp_Vec(t[0],t[1],t[2]));
251  Transf.SetValues(r[0],r[1],r[2],0,
252  r[3],r[4],r[5],0,
253  r[6],r[7],r[8],0
254 #if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8
255  ,0,1
256 #endif
257  );
258  BRepBuilderAPI_Transform Transformation(Transf);
259  BRepBuilderAPI_Transform Translation(Transl);
260  Transformation.Perform(OCC_SimpleShape(leftShape),true);
261  TopoDS_Shape shapeTransf = Transformation.Shape();
262  Translation.Perform(shapeTransf, Standard_True);
263  leftOCCShape = Translation.Shape();
264  }
265  TGeoHMatrix rightGlobMatx=m*(*rightMtx);
266  if(rightSName == "TGeoCompositeShape" ) {
267  rightOCCShape=OCC_CompositeShape((TGeoCompositeShape*)rightShape, leftGlobMatx);
268  } else {
269  t=rightGlobMatx.GetTranslation();
270  r=rightGlobMatx.GetRotationMatrix();
271  Transl.SetTranslation(gp_Vec(t[0],t[1],t[2]));
272  Transf.SetValues(
273  r[0],r[1],r[2],0,
274  r[3],r[4],r[5],0,
275  r[6],r[7],r[8],0
276 #if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8
277  ,0,1
278 #endif
279  );
280  BRepBuilderAPI_Transform Transformation(Transf);
281  BRepBuilderAPI_Transform Translation(Transl);
282  TopoDS_Shape sh=OCC_SimpleShape(rightShape);
283  Transformation.Perform(sh,true);
284  TopoDS_Shape shapeTransf = Transformation.Shape();
285  Translation.Perform(shapeTransf, Standard_True);
286  rightOCCShape = Translation.Shape();
287  }
288  TGeoBoolNode::EGeoBoolType boolOper=boolNode->GetBooleanOperator();
289  if(TGeoBoolNode::kGeoUnion == boolOper){
290  if (leftOCCShape.IsNull())out<<"leftshape is null"<<endl;
291  if (rightOCCShape.IsNull())out<<"rightshape is null"<<endl;
292  leftOCCShape.Closed(true);
293  rightOCCShape.Closed(true);
294  BRepAlgoAPI_Fuse Result(leftOCCShape, rightOCCShape);
295  Result.Build();
296  result=Result.Shape();
297  result.Closed(true);
298  return Reverse(result);
299  } else if(TGeoBoolNode::kGeoIntersection == boolOper) {
300  BRepAlgoAPI_Common Result(rightOCCShape,leftOCCShape);
301  Result.Build();
302  result=Result.Shape();
303  result.Closed(true);
304  return Reverse(result);
305  } else if(TGeoBoolNode::kGeoSubtraction ==boolOper) {
306  if (leftOCCShape.IsNull())out<<"leftshape is null"<<endl;
307  if (rightOCCShape.IsNull())out<<"rightshape is null"<<endl;
308  out.close();
309  BRepGProp::VolumeProperties(rightOCCShape, System);
310  if (System.Mass() < 0.0) rightOCCShape.Reverse();
311  BRepGProp::VolumeProperties(leftOCCShape, System2);
312  if (System2.Mass() < 0.0) leftOCCShape.Reverse();
313  BRepAlgoAPI_Cut Result(leftOCCShape,rightOCCShape);
314  Result.Build();
315  result=Result.Shape();
316  return Reverse(result);
317  } else {
318  throw std::domain_error( "Unknown operation" );
319  }
320 }
321 
323 {
324  gp_Pnt p (0.,0.,-dz);
325  gp_Dir d (0,0,1);
326  gp_Ax2 ax2 (p,d);
327  TopoDS_Edge e;
328  TopoDS_Wire w;
329  TopoDS_Face f;
330  if(a>b)
331  e=BRepBuilderAPI_MakeEdge(GC_MakeEllipse (ax2, a, b));
332  else
333  e=BRepBuilderAPI_MakeEdge(GC_MakeEllipse (ax2, b, a));
334  w=BRepBuilderAPI_MakeWire(e);
335  f=BRepBuilderAPI_MakeFace(w);
336  gp_Vec v(0 , 0 , dz*2);
337  fOccShape = BRepPrimAPI_MakePrism(f , v);
338  if(a<b) {
339  gp_Trsf t;
340  t.SetRotation(gp::OZ(), M_PI/2.);
341  BRepBuilderAPI_Transform brepT(fOccShape , t);
342  fOccShape = brepT.Shape();
343  }
344  return Reverse(fOccShape);
345 }
346 
347 TopoDS_Shape TGeoToOCC::OCC_Torus(Double_t Rmin, Double_t Rmax, Double_t Rtor,
348  Double_t SPhi, Double_t DPhi)
349 {
350  TopoDS_Solid torMin;
351  TopoDS_Solid torMax;
352  TopoDS_Shape tor;
353  gp_Trsf t;
354  if (Rmin==0) Rmin=0.000001;
355  if (Rmax==0) Rmax=0.000001;
356  if (Rtor==0) Rtor=0.000001;
357  torMin = BRepPrimAPI_MakeTorus(Rtor,Rmin,DPhi);
358  torMax = BRepPrimAPI_MakeTorus(Rtor,Rmax,DPhi);
359  BRepAlgoAPI_Cut cutResult(torMax, torMin);
360  cutResult.Build();
361  tor=cutResult.Shape();
362  TopExp_Explorer anExp1 (tor, TopAbs_SOLID);
363  if (anExp1.More()) {
364  TopoDS_Shape aTmpShape = anExp1.Current();
365  tor = TopoDS::Solid (aTmpShape);
366  }
367  t.SetRotation(gp::OZ(), SPhi);
368  BRepBuilderAPI_Transform brepT(tor , t);
369  fOccShape = brepT.Shape();
370  return Reverse(fOccShape);
371 }
372 
373 
374 TopoDS_Shape TGeoToOCC::OCC_Sphere(Double_t rmin, Double_t rmax,
375  Double_t phi1, Double_t Dphi,
376  Double_t theta1, Double_t Dtheta)
377 {
378  TopoDS_Edge eO;
379  TopoDS_Edge e1;
380  TopoDS_Edge e2;
381  TopoDS_Edge eI;
382  TopoDS_Face f;
383  TopoDS_Wire w;
384 
385 
386  if(rmin==0&&phi1==0&&Dphi==2*M_PI&&theta1==0&&Dtheta==M_PI) {
387  TopoDS_Solid s= BRepPrimAPI_MakeSphere(rmax);
388  return s;
389  }
390  Handle(Geom_TrimmedCurve) arcO = GC_MakeArcOfCircle (gp_Circ (gp_Ax2 (gp_Pnt(0., 0., 0.),
391  gp_Dir (0, 1,0)),rmax),theta1,
392  theta1+Dtheta, true);
393  BRepBuilderAPI_MakeEdge makeEO(arcO);
394  eO = TopoDS::Edge(makeEO.Shape());
395  if(rmin>0) {
396  Handle(Geom_TrimmedCurve) arcI = GC_MakeArcOfCircle (gp_Circ (gp_Ax2 (gp_Pnt(0.,0., 0.),
397  gp_Dir (0,1, 0)),rmin),
398  theta1, theta1+Dtheta,true);
399 
400  BRepBuilderAPI_MakeEdge makeEI(arcI);
401  eI = TopoDS::Edge(makeEI.Shape());
402  e1 = BRepBuilderAPI_MakeEdge(makeEO.Vertex1(), makeEI.Vertex1());
403  e2 = BRepBuilderAPI_MakeEdge(makeEO.Vertex2(), makeEI.Vertex2());
404  w = BRepBuilderAPI_MakeWire(eO , e2 , eI, e1);
405  f = BRepBuilderAPI_MakeFace(w);
406  } else {
407  gp_Pnt pZero(0.,0.,0.);
408  TopoDS_Vertex vZero = BRepBuilderAPI_MakeVertex(pZero);
409  e1 = BRepBuilderAPI_MakeEdge(makeEO.Vertex1(),vZero );
410  e2 = BRepBuilderAPI_MakeEdge(makeEO.Vertex2(),vZero );
411  w = BRepBuilderAPI_MakeWire(eO , e2 , e1);
412  f = BRepBuilderAPI_MakeFace(w);
413  }
414  gp_Trsf t;
415  t.SetRotation(gp::OZ(), phi1);
416  BRepBuilderAPI_Transform brepT(f , t);
417  fOccShape= brepT.Shape();
418  fOccShape = BRepPrimAPI_MakeRevol(fOccShape,gp::OZ(),Dphi);
419  return Reverse(fOccShape);
420 }
421 
422 TopoDS_Shape TGeoToOCC::OCC_Tube(Double_t rmin, Double_t rmax,
423  Double_t dz, Double_t phi1,
424  Double_t phi2)
425 {
426  TopoDS_Solid innerCyl;
427  TopoDS_Solid outerCyl;
428  TopoDS_Shape tubs;
429  TopoDS_Shape tubsT;
430  gp_Trsf TT;
431  gp_Trsf TR;
432  if (rmin==0) rmin=rmin+0.00001;
433  if (rmax==0) rmax=rmax+0.00001;
434  if (phi1==0&&phi2==0) {
435  innerCyl = BRepPrimAPI_MakeCylinder(rmin,dz*2);
436  outerCyl = BRepPrimAPI_MakeCylinder(rmax,dz*2);
437  } else {
438  innerCyl = BRepPrimAPI_MakeCylinder(rmin,dz*2,phi2);
439  outerCyl = BRepPrimAPI_MakeCylinder(rmax,dz*2,phi2);
440  }
441  BRepAlgoAPI_Cut cutResult(outerCyl, innerCyl);
442  cutResult.Build();
443  tubs=cutResult.Shape();
444  TopExp_Explorer anExp1 (tubs, TopAbs_SOLID);
445  if (anExp1.More()) {
446  TopoDS_Shape aTmpShape = anExp1.Current();
447  tubs = TopoDS::Solid (aTmpShape);
448  }
449  TT.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Vec(0., 0., 1.)), phi1);
450  BRepBuilderAPI_Transform theTT(TT);
451  theTT.Perform(tubs, Standard_True);
452  tubsT=theTT.Shape();
453  TR.SetTranslation(gp_Vec(0,0,-dz ));
454  BRepBuilderAPI_Transform theTR(TR);
455  theTR.Perform(tubsT, Standard_True);
456  fOccShape=theTR.Shape();
457  return Reverse(fOccShape);
458 }
459 
460 TopoDS_Shape TGeoToOCC::OCC_Cones(Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2, Double_t dz, Double_t phi1, Double_t phi2)
461 {
462  TopoDS_Solid innerCon;
463  TopoDS_Solid outerCon;
464  TopoDS_Shape cons;
465  gp_Trsf TT;
466  gp_Trsf TR;
467  if (rmin1==0) rmin1=rmin1+0.000001;
468  if (rmax1==0) rmax1=rmax1+0.000001;
469  if(rmin1!=rmin2)
470  innerCon = BRepPrimAPI_MakeCone(rmin1,rmin2,dz*2,phi2);
471  else
472  innerCon = BRepPrimAPI_MakeCylinder(rmin1,dz*2,phi2);
473  if(rmax1!=rmax2)
474  outerCon = BRepPrimAPI_MakeCone(rmax1,rmax2,dz*2,phi2);
475  else
476  outerCon = BRepPrimAPI_MakeCylinder(rmax1,dz*2,phi2);
477  BRepAlgoAPI_Cut cutResult(outerCon, innerCon);
478  cutResult.Build();
479  cons = cutResult.Shape();
480  TT.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Vec(0., 0., 1.)), phi1);
481  BRepBuilderAPI_Transform theTT(TT);
482  theTT.Perform(cons, Standard_True);
483  cons=theTT.Shape();
484  TR.SetTranslation(gp_Vec(0,0,-dz ));
485  BRepBuilderAPI_Transform theTR(TR);
486  theTR.Perform(cons, Standard_True);
487  fOccShape=theTR.Shape();
488  return Reverse(fOccShape);
489 }
490 
491 TopoDS_Shape TGeoToOCC::OCC_Cuttub(Double_t rmin, Double_t rmax, Double_t dz,
492  Double_t, Double_t Dphi,const Double_t * Nlow,const Double_t * Nhigh)
493 {
494  out.open("/tmp/TGeoCad.log",ios::app);
495  out<<"siamo in ctube"<<rmin<<" "<<rmax<<" "<<Dphi<<" "<<dz<<" "<<Nlow[0]<<" "<<Nlow[1]<<" "<<Nlow[2]<<" "<<Nhigh[0]<<" "<<Nhigh[1]<<" "<<Nhigh[2]<<endl;
496  Double_t nlow0=Nlow[0];
497  Double_t nlow1=Nlow[1];
498  Double_t nhigh0=Nhigh[0];
499  Double_t nhigh1=Nhigh[1];
500  TopoDS_Shape tubs;
501  TopoDS_Shell sH, sL;
502  ShapeFix_ShapeTolerance FTol;
503  Double_t tolerance=1;
504 
505  gp_Trsf TT;
506  gp_Trsf TR;
507  if (rmin==0) rmin=rmin+0.000001;
508  if (rmax==0) rmax=rmax+0.000001;
509  TopoDS_Solid rminCyl= BRepPrimAPI_MakeCylinder(rmin,2*dz,Dphi);
510  TopoDS_Solid rmaxCyl = BRepPrimAPI_MakeCylinder(rmax,2*dz,Dphi);
511  BRepAlgoAPI_Cut cutResult(rmaxCyl, rminCyl);
512  cutResult.Build();
513  tubs=cutResult.Shape();
514  TopExp_Explorer anExp2 (tubs, TopAbs_SOLID);
515  if (anExp2.More()) {
516  TopoDS_Shape aTmpShape = anExp2.Current();
517  tubs = TopoDS::Solid (aTmpShape);
518  }
519  /*TT.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Vec(0., 0., 1.)),phi1);
520  BRepBuilderAPI_Transform theTT(TT);
521  theTT.Perform(tubs, Standard_True);
522  tubs=theTT.Shape();*/
523  TR.SetTranslation(gp_Vec(0,0,-dz));
524  BRepBuilderAPI_Transform theTR(TR);
525  theTR.Perform(tubs, Standard_True);
526  tubs=theTR.Shape();
527  if ((Nhigh[0]>-1e-4)||(Nhigh[0]<1e-4)) nhigh0=0;
528  if ((Nhigh[1]>-1e-4)||(Nhigh[1]<1e-4)) nhigh1=0;
529  if ((Nlow[0]>-1e-4)||(Nlow[0]<1e-4)) nlow0=0;
530  if ((Nlow[1]>-1e-4)||(Nlow[1]<1e-4)) nlow1=0;
531  Handle(Geom_Plane) pH = new Geom_Plane (gp_Pnt(0,0,dz), gp_Dir(nhigh0,nhigh1,Nhigh[2]));
532  Handle(Geom_Plane) pL = new Geom_Plane (gp_Pnt(0,0,-dz), gp_Dir(nlow0,nlow1,Nlow[2]));
533 
534  /* gp_Dir D(nhigh0,nhigh1,Nhigh[2]);
535  gp_Pnt P(0,0,dz);
536  gp_Pln Plan(P,D);
537  TopoDS_Face maLame = BRepBuilderAPI_MakeFace(Plan);
538  if (maLame.IsNull()) cout<<"null face"<<endl;
539  TopoDS_Shape Inter = BRepAlgo_Section(tubs, maLame);
540  FTol.SetTolerance(maLame, tolerance ,TopAbs_FACE);
541  BRepAlgoAPI_Cut Result(tubs, Inter);*/
542 
543  /*gp_Dir D2(nlow0,nlow1,Nlow[2]);
544  gp_Pnt P2(0,0,-dz);
545  gp_Pln Plan2(P,D);
546  TopoDS_Face maLame2 = BRepBuilderAPI_MakeFace(Plan2);
547  TopoDS_Shape Inter2 = BRepAlgo_Section(tubs, maLame2);
548  BRepAlgoAPI_Fuse Result(Inter, Inter2);
549  Result.Build();
550  */
551  BRepBuilderAPI_MakeShell shell(pH);
552  if (shell.IsDone())
553  sH=shell.Shell();
554  else
555  out<<"error shell 1"<<shell.Error()<<endl;
556  BRepBuilderAPI_MakeShell shell2 (pL);
557  if (shell2.IsDone())
558  sL=shell2.Shell();
559  else
560  out<<"error shell 2"<<shell2.Error()<<endl;
561 
562  FTol.SetTolerance(sH, tolerance ,TopAbs_SHELL);
563  FTol.SetTolerance(sL, tolerance ,TopAbs_SHELL);
564 
565  BRepBuilderAPI_MakeSolid solid (sH, sL);
566  solid.Build();
567  TopoDS_Solid cut=solid.Solid();
568  FTol.SetTolerance(cut, tolerance ,TopAbs_SOLID);
569  BRepBuilderAPI_MakeSolid(sL, sH);
570  if (!solid.IsDone())
571  out<<"error solid"<<endl;
572 
573  //BRepAlgoAPI_Cut Result(tubs, cut);
574  BRepAlgoAPI_Cut Result(tubs, cut);
575  Result.Build();
576  out<<"dopo la seconda cut"<<Result.ErrorStatus()<<endl;
577  /* TopoDS_Solid newSolid;
578  TopExp_Explorer anExp1 (tubs, TopAbs_SOLID);
579  if (anExp1.More()) {
580  TopoDS_Shape aTmpShape = anExp1.Current();
581  newSolid = TopoDS::Solid (aTmpShape);
582  }*/
583  return Reverse(Result.Shape());
584  // return maLame;
585 }
586 
587 
588 TopoDS_Shape TGeoToOCC::OCC_Xtru(TGeoXtru * TG_Xtru)
589 {
590  Int_t vert=TG_Xtru->GetNvert();
591  Int_t nz=TG_Xtru->GetNz();
592  Double_t x [vert];
593  Double_t y [vert];
594  Double_t z [nz];
595  gp_Trsf TR;
596  TopoDS_Wire w;
597  BRepOffsetAPI_ThruSections sect(true,true);
598  for (Int_t i=0;i<nz;i++) {
599  for (Int_t pp=0;pp<vert;pp++) {
600  x[pp]=TG_Xtru->GetXOffset(i)+(TG_Xtru->GetScale(i)*TG_Xtru->GetX(pp));
601  y[pp]=TG_Xtru->GetYOffset(i)+(TG_Xtru->GetScale(i)*TG_Xtru->GetY(pp));
602  }
603  z[i]=TG_Xtru->GetZ(i);
604  w=TGeoToOCC::Polygon(x,y,z[i],vert);
605  sect.AddWire(w);
606  }
607  sect.Build();
608  if (sect.IsDone()) fOccShape = sect.Shape();
609  return fOccShape;
610 }
611 
612 
613 TopoDS_Shape TGeoToOCC::OCC_Hype(Double_t rmin, Double_t rmax,Double_t stin, Double_t stout, Double_t dz )
614 {
615  gp_Pnt p(0, 0, 0);
616  gp_Dir d(0, 0, 1);
617  TopoDS_Vertex vIn,vOut;
618  TopoDS_Vertex vIn1,vOut1;
619  TopoDS_Edge hyEO;
620  TopoDS_Edge hyEI;
621  TopoDS_Edge eT;
622  TopoDS_Edge eB;
623  TopoDS_Edge eT1;
624  TopoDS_Wire hyW;
625  TopoDS_Face hyF;
626  gp_Trsf t;
627  BRepBuilderAPI_MakeEdge makeHyEO;
628  BRepBuilderAPI_MakeEdge makeHyEI;
629  Double_t xO,xI;
630  if(stout>0) {
631  Double_t aO = rmax;
632  Double_t bO = (rmax/(tan(stout)));
633  xO = aO*sqrt(1+(dz*dz)/(bO*bO));
634  gp_Hypr hyO( gp_Ax2 (p, d ), aO, bO);
635  vOut = BRepBuilderAPI_MakeVertex(gp_Pnt(xO,dz,0));
636  vOut1 = BRepBuilderAPI_MakeVertex(gp_Pnt(xO,-dz,0));
637  makeHyEO=BRepBuilderAPI_MakeEdge(hyO,vOut,vOut1);
638  }
639  else
640  makeHyEO=BRepBuilderAPI_MakeEdge(gp_Pnt(rmax,-dz,0), gp_Pnt(rmax,dz,0));
641  if(stin>0) {
642  Double_t aI = rmin;
643  Double_t bI = (rmin/(tan(stin)));
644  xI = aI*sqrt(1+(dz*dz)/(bI*bI));
645  gp_Hypr hyI( gp_Ax2 (p, d ), aI, bI);
646  vIn = BRepBuilderAPI_MakeVertex(gp_Pnt(xI,dz,0));
647  vIn1 = BRepBuilderAPI_MakeVertex(gp_Pnt(xI,-dz,0));
648  makeHyEI=BRepBuilderAPI_MakeEdge(hyI,vIn,vIn1);
649  }
650  else
651  makeHyEI=BRepBuilderAPI_MakeEdge(gp_Pnt(rmin,-dz,0), gp_Pnt(rmin,dz,0));
652  hyEO=TopoDS::Edge(makeHyEO.Shape());
653  hyEI=TopoDS::Edge(makeHyEI.Shape());
654  eT= BRepBuilderAPI_MakeEdge(makeHyEO.Vertex1(), makeHyEI.Vertex1());
655  eB= BRepBuilderAPI_MakeEdge(makeHyEO.Vertex2(), makeHyEI.Vertex2());
656  eT1 =BRepBuilderAPI_MakeEdge(makeHyEO.Vertex1(), makeHyEO.Vertex2());
657  BRepBuilderAPI_MakeWire WIRE(hyEO,eB,hyEI,eT);
658  WIRE.Add(eT1);
659  hyW=WIRE.Wire();
660  BRepBuilderAPI_MakeFace face(hyW);
661  hyF=face.Face();
662  t.SetRotation(gp::OX(), M_PI/2.);
663  BRepBuilderAPI_Transform TF(t);
664  TF.Perform(hyF,Standard_True);
665  hyF = TopoDS::Face(TF.Shape());
666  fOccShape = BRepPrimAPI_MakeRevol (hyF,gp::OZ(),2*M_PI);
667  return Reverse(fOccShape);
668 }
669 
671 {
672  BRepOffsetAPI_ThruSections sect(true,true);
673  TopoDS_Wire w;
674  TopoDS_Face ff;
675  //Int_t punti=0;
676  Int_t f=0;
677  TopoDS_Edge e1;
678  TopoDS_Edge e2;
679  TopoDS_Edge e3;
680  TopoDS_Edge e4;
681  gp_Pnt p1;
682  gp_Pnt p2;
683  gp_Pnt p3;
684  gp_Pnt p4;
685 
686  while (f<24) {
687  p1=gp_Pnt(vertex[f],vertex[f+1],vertex[f+2]);
688  p2=gp_Pnt(vertex[f+3],vertex[f+4],vertex[f+5]);
689  p3=gp_Pnt(vertex[f+6],vertex[f+7],vertex[f+8]);
690  p4=gp_Pnt(vertex[f+9],vertex[f+10],vertex[f+11]);
691  e1=BRepBuilderAPI_MakeEdge(p1,p2 );
692  e2=BRepBuilderAPI_MakeEdge(p2,p3 );
693  e3=BRepBuilderAPI_MakeEdge(p3,p4 );
694  e4=BRepBuilderAPI_MakeEdge(p4,p1 );
695  w = BRepBuilderAPI_MakeWire(e1,e2,e3,e4);
696  sect.AddWire(w);
697  f += 12;
698  }
699  sect.Build();
700  fOccShape=sect.Shape();
701  return fOccShape;
702 }
703 
704 
706 {
707  out.open("/tmp/TGeoCad.log",ios::app);
708  TopoDS_Shell newShell;
709  TopoDS_Shape sewedShape;
710  TopoDS_Shape aTmpShape;
711  Int_t count=0;
712  ShapeFix_ShapeTolerance FTol;
713  Double_t tolerance=1;
714  Handle(TColgp_HArray1OfPnt) pathArray =new TColgp_HArray1OfPnt(0,8);
715  BRepBuilderAPI_Sewing sew(1.0);//e-02);
716  TopoDS_Wire wire1,wire2,wire3,wire4,wire5,wire6;
717  TopoDS_Face ff,ff1,ff2,ff3,ff4,ff5;
718  BRepBuilderAPI_MakePolygon poly1,poly2,poly3,poly4,poly5,poly6;
719  Int_t x=0,y=0,z=0;
720  gp_Pnt point;
721  for (Int_t i=0;i<8;i++) {
722 
723  x=count++;y=count++;z=count++;
724  point=gp_Pnt(points[x],points[y],points[z]);
725  if (points[x]<=0.1) { tolerance=1;}
726  if (points[y]<=0.1) { tolerance=1;}
727  if (points[z]<=0.1) { tolerance=1;}
728  pathArray->SetValue(i,point);
729  }
730  poly1.Add(pathArray->Value(0));
731  out<<pathArray->Value(0).X()<<" "<<pathArray->Value(0).Y()<<" "<<pathArray->Value(0).Z()<<endl;
732  poly1.Add(pathArray->Value(3));
733  out<<pathArray->Value(3).X()<<pathArray->Value(3).Y()<<pathArray->Value(3).Z()<<endl;
734  poly1.Add(pathArray->Value(2));
735  out<<pathArray->Value(2).X()<<pathArray->Value(2).Y()<<pathArray->Value(2).Z()<<endl;
736  poly1.Add(pathArray->Value(1));
737  out<<pathArray->Value(1).X()<<" "<<pathArray->Value(1).Y()<<" "<<pathArray->Value(1).Z()<<endl;
738  poly1.Close();
739  wire1=poly1.Wire();
740 
741  poly2.Add(pathArray->Value(0));
742  out<<pathArray->Value(0).X()<<pathArray->Value(0).Y()<<pathArray->Value(0).Z()<<endl;
743  poly2.Add(pathArray->Value(1));
744  out<<pathArray->Value(1).X()<<pathArray->Value(1).Y()<<pathArray->Value(1).Z()<<endl;
745  poly2.Add(pathArray->Value(5));
746  out<<pathArray->Value(5).X()<<pathArray->Value(5).Y()<<pathArray->Value(5).Z()<<endl;
747  poly2.Add(pathArray->Value(4));
748  out<<pathArray->Value(4).X()<<pathArray->Value(4).Y()<<pathArray->Value(4).Z()<<endl;
749  poly2.Close();
750  wire2=poly2.Wire();
751  poly3.Add(pathArray->Value(0));
752  out<<pathArray->Value(0).X()<<pathArray->Value(0).Y()<<pathArray->Value(0).Z()<<endl;
753  poly3.Add(pathArray->Value(4));
754  out<<pathArray->Value(4).X()<<pathArray->Value(4).Y()<<pathArray->Value(4).Z()<<endl;
755  poly3.Add(pathArray->Value(7));
756  out<<pathArray->Value(7).X()<<pathArray->Value(7).Y()<<pathArray->Value(7).Z()<<endl;
757  poly3.Add(pathArray->Value(3));
758  out<<pathArray->Value(3).X()<<pathArray->Value(3).Y()<<pathArray->Value(3).Z()<<endl;
759  poly3.Close();
760  wire3=poly3.Wire();
761  poly4.Add(pathArray->Value(3));
762  out<<pathArray->Value(3).X()<<pathArray->Value(3).Y()<<pathArray->Value(3).Z()<<endl;
763  poly4.Add(pathArray->Value(2));
764  out<<pathArray->Value(2).X()<<pathArray->Value(2).Y()<<pathArray->Value(2).Z()<<endl;
765  poly4.Add(pathArray->Value(6));
766  out<<pathArray->Value(6).X()<<pathArray->Value(6).Y()<<pathArray->Value(6).Z()<<endl;
767  poly4.Add(pathArray->Value(7));
768  out<<pathArray->Value(7).X()<<pathArray->Value(7).Y()<<pathArray->Value(7).Z()<<endl;
769  poly4.Close();
770  wire4=poly4.Wire();
771  poly5.Add(pathArray->Value(4));
772  out<<pathArray->Value(4).X()<<pathArray->Value(4).Y()<<pathArray->Value(4).Z()<<endl;
773  poly5.Add(pathArray->Value(5));
774  out<<pathArray->Value(5).X()<<pathArray->Value(5).Y()<<pathArray->Value(5).Z()<<endl;
775  poly5.Add(pathArray->Value(6));
776  out<<pathArray->Value(6).X()<<pathArray->Value(6).Y()<<pathArray->Value(6).Z()<<endl;
777  poly5.Add(pathArray->Value(7));
778  out<<pathArray->Value(7).X()<<pathArray->Value(7).Y()<<pathArray->Value(7).Z()<<endl;
779  poly5.Close();
780  wire5=poly5.Wire();
781  poly6.Add(pathArray->Value(1));
782  out<<pathArray->Value(1).X()<<pathArray->Value(1).Y()<<pathArray->Value(1).Z()<<endl;
783  poly6.Add(pathArray->Value(2));
784  out<<pathArray->Value(2).X()<<pathArray->Value(2).Y()<<pathArray->Value(2).Z()<<endl;
785  poly6.Add(pathArray->Value(6));
786  out<<pathArray->Value(6).X()<<pathArray->Value(6).Y()<<pathArray->Value(6).Z()<<endl;
787  poly6.Add(pathArray->Value(5));
788  out<<pathArray->Value(5).X()<<pathArray->Value(5).Y()<<pathArray->Value(5).Z()<<endl;
789 
790  poly6.Close();
791  wire6=poly6.Wire();
792 
793  FTol.SetTolerance(wire1, tolerance ,TopAbs_WIRE);
794  FTol.SetTolerance(wire2, tolerance ,TopAbs_WIRE);
795  FTol.SetTolerance(wire3, tolerance ,TopAbs_WIRE);
796  FTol.SetTolerance(wire4, tolerance ,TopAbs_WIRE);
797  FTol.SetTolerance(wire5, tolerance ,TopAbs_WIRE);
798  FTol.SetTolerance(wire6, tolerance ,TopAbs_WIRE);
799 
800  ff = BRepBuilderAPI_MakeFace(wire1);
801  if (ff.IsNull()) out<<"face1 is null"<<endl;
802  ff1 = BRepBuilderAPI_MakeFace(wire2);
803  if (ff1.IsNull()) out<<"face2 is null"<<endl;
804  ff2 = BRepBuilderAPI_MakeFace(wire3);
805  if (ff2.IsNull()) out<<"face3 is null"<<endl;
806  ff3 = BRepBuilderAPI_MakeFace(wire4);
807  if (ff3.IsNull()) out<<"face4 is null"<<endl;
808  ff4 = BRepBuilderAPI_MakeFace(wire5);
809  if (ff4.IsNull()) out<<"face5 is null"<<endl;
810  ff5 = BRepBuilderAPI_MakeFace(wire6);
811  if (ff5.IsNull()) out<<"face6 is null"<<endl;
812  sew.Add(ff);
813  sew.Add(ff1);
814  sew.Add(ff2);
815  sew.Add(ff3);
816  sew.Add(ff4);
817  sew.Add(ff5);
818 
819  sew.Perform();
820  sewedShape=sew.SewedShape();
821 
822  if (sewedShape.IsNull()) out<<"Arb8 error"<<endl;
823 
824  TopExp_Explorer anExp (sewedShape, TopAbs_SHELL);
825  if (anExp.More()) {
826  aTmpShape = anExp.Current();
827  newShell = TopoDS::Shell (aTmpShape);
828  }
829  BRepBuilderAPI_MakeSolid mySolid(newShell);
830  out.close();
831  return Reverse(mySolid.Solid());
832 }
833 
834 
835 
837 {
838  TopoDS_Solid box;
839  if (dz==0)dz=0.1;
840  if (dy==0)dy=0.1;if (dx==0)dx=0.1;
841  box = BRepPrimAPI_MakeBox( gp_Pnt(OX-dx, OY-dy, OZ-dz), dx*2, dy*2, dz*2);
842  return Reverse(box);
843 }
844 
845 
846 TopoDS_Shape TGeoToOCC::OCC_Trd(Double_t dx1, Double_t dx2, Double_t dy1, Double_t dy2, Double_t dz)
847 {
848  TopoDS_Wire wire;
849  BRepOffsetAPI_ThruSections sect(true,true);
850 
851  TopoDS_Edge edge1;
852  TopoDS_Edge edge2;
853  TopoDS_Edge edge3;
854  TopoDS_Edge edge4;
855  gp_Pnt point1;
856  gp_Pnt point2;
857  gp_Pnt point3;
858  gp_Pnt point4;
859  for (Int_t i=0;i<2;i++) {
860  BRepBuilderAPI_MakePolygon poly;
861  if (i==1) {
862  dx1=dx2;
863  dy1=dy2;
864  dz=-dz;
865  }
866  point1=gp_Pnt(-dx1,-dy1,-dz);
867  point2=gp_Pnt(dx1,-dy1,-dz);
868  point3=gp_Pnt(dx1,dy1,-dz);
869  point4=gp_Pnt(-dx1,dy1,-dz);
870  poly.Add(point1);
871  poly.Add(point2);
872  poly.Add(point3);
873  poly.Add(point4);
874  poly.Close();
875  wire=poly.Wire();
876  sect.AddWire(wire);
877  poly.Delete();
878  }
879 
880  sect.Build();
881  fOccShape=sect.Shape();
882 
883  return fOccShape;
884 }
885 
887 {
888  BRepBuilderAPI_MakePolygon poly;
889  TopoDS_Wire w ;
890  Int_t i;
891  for(i=0; i<num; i++) {
892  poly.Add(gp_Pnt(x[i], y[i],z));
893  }
894  poly.Add(gp_Pnt(x[0], y[0], z));
895  poly.Close();
896  w=poly.Wire();
897  return w;
898 }
899 
900 
901 TopoDS_Shape TGeoToOCC::OCC_Pcon(Double_t startPhi, Double_t deltaPhi,
902  Int_t zNum, Double_t *rMin, Double_t *rMax, Double_t *z)
903 {
904 
905  TopoDS_Shape pCone;
906  TopoDS_Shape cone;
907  Double_t zHalf=0.0;
908  gp_Trsf Transl;
909  gp_Trsf Transf;
910  for(Int_t nCon=0; nCon<zNum-1; nCon++) {
911  zHalf = (z[nCon+1]-z[nCon])/2.;
912  if ((zHalf==0)||(zHalf<0)) zHalf=0.1;
913  cone = OCC_Cones(rMin[nCon], rMax[nCon], rMin[(nCon+1)], rMax[(nCon+1)],zHalf, startPhi, deltaPhi);
914  Double_t r[] = {1,0,0,0,1,0,0,0,1};
915  Double_t t[] = {0,0,zHalf+z[nCon]};
916  Transl.SetTranslation(gp_Vec(t[0],t[1],t[2]));
917  Transf.SetValues(r[0],r[1],r[2],0,
918  r[3],r[4],r[5],0,
919  r[6],r[7],r[8],0
920 #if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8
921  ,0,1
922 #endif
923  );
924  BRepBuilderAPI_Transform Transformation(Transf);
925  BRepBuilderAPI_Transform Translation(Transl);
926  Transformation.Perform(cone,true);
927  cone = Transformation.Shape();
928  Translation.Perform(cone, Standard_True);
929  cone = Translation.Shape();
930  if(nCon>0) {
931  BRepAlgoAPI_Fuse fuse(pCone, cone);
932  pCone=fuse.Shape();
933  } else
934  pCone=cone;
935  }
936  return Reverse(pCone);
937 }
938 
939 
940 TopoDS_Shape TGeoToOCC::OCC_Pgon(Int_t, Int_t nz, Double_t * p, Double_t phi1, Double_t DPhi, Int_t numpoint)
941 {
942  BRepOffsetAPI_ThruSections sectInner(true,true);
943  BRepOffsetAPI_ThruSections sectOuter(true,true);
944  BRepLib_MakePolygon aPoly2;
945  TopoDS_Face f;
946  TopoDS_Wire w1,w2;
947  TopoDS_Solid myCut;
948  Int_t i=2;
949  Double_t z=p[2];
950  Int_t nzvert=0;
951  Double_t xx=0.0,yy=0.0,zz=0.0;
952  Double_t Xmax=0.0,Ymax=0.0, Zmax=0.0, max=0.0;
953  Int_t aa=0,bb=1,cc=2;
954  Int_t ind=0;
955  Int_t check=0;
956  //Int_t k=0;
957  gp_Pnt point;
958  gp_Trsf TR;
959  gp_Trsf TT;
960  while (i<numpoint){
961  if (IsEqual(p[i],z))
962  nzvert=nzvert+1;
963  i=i+3;
964  }
965  nzvert=nzvert/2;
966  for(Int_t c=0;c<numpoint;c++){
967  if ((p[check]>-1e-4)&&(p[check]<1e-4))
968  p[check]=0;
969  check=check+1;
970  }
971  for (i=0;i<nz;i++) {
972  for(Int_t j=0; j<2; j++) {
973  BRepLib_MakePolygon aPoly;
974  for (Int_t h=0;h<nzvert;h++){
975  xx=p[ind++];yy=p[ind++];zz=p[ind++];
976  point=gp_Pnt(xx,yy,zz);
977  aPoly.Add(point);
978  }
979  aPoly.Close();
980  if (j==0) {
981  w1 = aPoly.Wire();
982  sectInner.AddWire(w1);
983  }
984  if (j==1) {
985  w2 = aPoly.Wire();
986  sectOuter.AddWire(w2);
987  }
988  aPoly.Delete();
989  }
990  }
991  sectInner.Build();
992  sectOuter.Build();
993 
994  BRepAlgoAPI_Cut Result(sectOuter.Shape(),sectInner.Shape() );
995  Result.Build();
996 
997  for (Int_t e=0;e<numpoint;e++){
998  if (fabs(p[aa])>Xmax) {
999  Xmax=fabs(p[aa]);
1000  }
1001  if (fabs(p[bb])>Ymax) {
1002  Ymax=fabs(p[bb]);
1003  }
1004  if (fabs(p[cc])>Zmax) {
1005  Zmax=fabs(p[cc]);
1006  }
1007  if(numpoint-1==cc) break;
1008  aa=aa+3;
1009  bb=bb+3;
1010  cc=cc+3;
1011  }
1012  if (Xmax>Ymax)
1013  max=Xmax;
1014  else
1015  max=Ymax;
1016  if ((IsEqual(DPhi,360.0))||(IsEqual(DPhi,0.))) {
1017  fOccShape=Result.Shape();
1018  return Reverse(fOccShape);
1019  } else {
1020  myCut=BRepPrimAPI_MakeCylinder (max+1,2*Zmax,(360.-DPhi)*M_PI/180.);
1021  TT.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Vec(0., 0., 1.)), (-90.0+phi1)*M_PI/180.0);
1022  BRepBuilderAPI_Transform theTT(TT);
1023  theTT.Perform(myCut, Standard_True);
1024  fOccShape=theTT.Shape();
1025  TR.SetTranslation(gp_Vec(0,0,-Zmax));
1026  BRepBuilderAPI_Transform theTR(TR);
1027  theTR.Perform(fOccShape, Standard_True);
1028  fOccShape=theTR.Shape();
1029  BRepAlgoAPI_Cut Result2(Result.Shape(),fOccShape );
1030  Result2.Build();
1031  fOccShape=Result2.Shape();
1032  //if (fOccShape.IsNull()) cout<<"The Pgon shae is null. Cut Operation Error: "<<Result2.ErrorStatus()<<endl;
1033  return Reverse(fOccShape);
1034  }
1035 }
1036 
1037 
1038 TopoDS_Shape TGeoToOCC::Reverse(TopoDS_Shape Shape)
1039 {
1040  BRepClass3d_SolidClassifier * setPrecision= new BRepClass3d_SolidClassifier (Shape);
1041  setPrecision->PerformInfinitePoint(Precision::Confusion());
1042  if (setPrecision->State() == TopAbs_IN) {
1043  //cout<<"reverse"<<endl;
1044  Shape.Reverse();
1045  }
1046  delete(setPrecision);
1047  return Shape;
1048 }
1049 
TopoDS_Shape OCC_Pgon(Int_t np, Int_t nz, Double_t *p, Double_t phi1, Double_t DPhi, Int_t numpoint)
Definition: TGeoToOCC.cxx:940
Double_t GetStOut() const
Definition: TGeoHype.h:99
TopoDS_Shape OCC_Cuttub(Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t Dphi, const Double_t *Nlow, const Double_t *Nhigh)
Definition: TGeoToOCC.cxx:491
TopoDS_Shape OCC_Xtru(TGeoXtru *TG_Xtru)
Definition: TGeoToOCC.cxx:588
virtual Double_t GetRmin1() const
Definition: TGeoCone.h:87
static double p3(double t, double a, double b, double c, double d)
TopoDS_Shape OCC_Torus(Double_t Rmin, Double_t Rmax, Double_t Rtor, Double_t SPhi, Double_t DPhi)
Definition: TGeoToOCC.cxx:347
virtual Int_t GetNmeshVertices() const
Return number of vertices of the mesh representation.
Definition: TGeoPgon.cxx:1913
Double_t GetR() const
Definition: TGeoTorus.h:82
virtual Double_t GetRmax2() const
Definition: TGeoCone.h:90
Double_t GetDy() const
Definition: TGeoTrd1.h:68
TH1 * h
Definition: legend2.C:5
TGeoShape * GetLeftShape() const
Definition: TGeoBoolNode.h:88
Double_t GetScale(Int_t i) const
Definition: TGeoXtru.h:107
Double_t GetPhi2() const
Definition: TGeoCone.h:184
Double_t GetDphi() const
Definition: TGeoTorus.h:86
Basic string class.
Definition: TString.h:137
Double_t GetPhi1() const
Definition: TGeoPcon.h:85
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
TopoDS_Shape OCC_Arb8(Double_t dz, Double_t *ivert, Double_t *points)
Definition: TGeoToOCC.cxx:705
TopoDS_Shape OCC_Trd(Double_t dx1, Double_t dx2, Double_t dy1, Double_t dy2, Double_t dz)
Definition: TGeoToOCC.cxx:846
virtual Double_t GetDY() const
Definition: TGeoBBox.h:83
virtual EGeoBoolType GetBooleanOperator() const =0
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
Int_t GetNvert() const
Definition: TGeoXtru.h:102
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:84
Double_t GetDy1() const
Definition: TGeoTrd2.h:69
virtual Double_t GetRmax1() const
Definition: TGeoCone.h:88
Double_t GetDx1() const
Definition: TGeoTrd2.h:67
double sqrt(double)
Double_t GetPhi2() const
Definition: TGeoTube.h:169
Double_t x[n]
Definition: legend1.C:17
TGeoMatrix * GetRightMatrix() const
Definition: TGeoBoolNode.h:87
void Class()
Definition: Class.C:29
Double_t GetY(Int_t i) const
Definition: TGeoXtru.h:104
virtual Double_t GetA() const
Definition: TGeoEltu.h:54
Double_t GetRmax() const
Definition: TGeoTorus.h:84
Double_t * GetZ() const
Definition: TGeoXtru.h:108
virtual Double_t GetRmax() const
Definition: TGeoSphere.h:82
static double p2(double t, double a, double b, double c)
Int_t GetNz() const
Definition: TGeoXtru.h:101
virtual const Double_t * GetRotationMatrix() const
Definition: TGeoMatrix.h:456
Double_t GetPhi1() const
Definition: TGeoTorus.h:85
const Double_t * GetNlow() const
Definition: TGeoTube.h:238
virtual void SetPoints(Double_t *points) const =0
Double_t GetXOffset(Int_t i) const
Definition: TGeoXtru.h:105
virtual const Double_t * GetOrigin() const
Definition: TGeoBBox.h:85
REAL * vertex
Definition: triangle.c:512
Double_t GetDy2() const
Definition: TGeoTrd2.h:70
point * points
Definition: X3DBuffer.c:20
virtual Double_t GetDX() const
Definition: TGeoBBox.h:82
Double_t GetDphi() const
Definition: TGeoPcon.h:86
ofstream out
Definition: TGeoToOCC.h:54
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
TopoDS_Shape OCC_Pcon(Double_t startPhi, Double_t deltaPhi, Int_t zNum, Double_t *rMin, Double_t *rMax, Double_t *z)
Definition: TGeoToOCC.cxx:901
Double_t GetDz() const
Definition: TGeoTrd2.h:71
TopoDS_Shape OCC_Cones(Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2, Double_t dz, Double_t phi1, Double_t phi2)
Definition: TGeoToOCC.cxx:460
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual Double_t GetRmin2() const
Definition: TGeoCone.h:89
#define M_PI
Definition: Rotated.cxx:105
TopoDS_Shape OCC_EllTube(Double_t Dx, Double_t Dy, Double_t Dz)
Definition: TGeoToOCC.cxx:322
SVector< double, 2 > v
Definition: Dict.h:5
virtual Double_t GetRmin() const
Definition: TGeoTube.h:77
Double_t GetTheta2() const
Definition: TGeoSphere.h:84
TMarker * m
Definition: textangle.C:8
Double_t * GetZ() const
Definition: TGeoPcon.h:93
TGeoBoolNode * GetBoolNode() const
#define TR(N1, N2)
static double p1(double t, double a, double b)
Double_t GetPhi1() const
Definition: TGeoCone.h:183
virtual Double_t GetDz() const
Definition: TGeoCone.h:82
Double_t GetStIn() const
Definition: TGeoHype.h:98
TGeoMatrix * GetLeftMatrix() const
Definition: TGeoBoolNode.h:86
const Double_t * GetNhigh() const
Definition: TGeoTube.h:239
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:247
virtual Double_t GetRmin() const
Definition: TGeoSphere.h:81
Double_t GetDz() const
Definition: TGeoTrd1.h:69
TopoDS_Shape OCC_Box(Double_t dx, Double_t dy, Double_t dz, Double_t OX, Double_t OY, Double_t OZ)
Definition: TGeoToOCC.cxx:836
TGeoShape * GetRightShape() const
Definition: TGeoBoolNode.h:89
TopoDS_Shape OCC_Tube(Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2)
Definition: TGeoToOCC.cxx:422
Double_t GetYOffset(Int_t i) const
Definition: TGeoXtru.h:106
TopoDS_Wire Polygon(Double_t *x, Double_t *y, Double_t z, Int_t num)
Definition: TGeoToOCC.cxx:886
Double_t GetPhi1() const
Definition: TGeoTube.h:168
Double_t * GetRmin() const
Definition: TGeoPcon.h:89
double f(double x)
double Double_t
Definition: RtypesCore.h:55
Double_t GetPhi1() const
Definition: TGeoSphere.h:85
int type
Definition: TGX11.cxx:120
Double_t GetDx2() const
Definition: TGeoTrd2.h:68
Double_t GetTheta1() const
Definition: TGeoSphere.h:83
TopoDS_Shape OCC_CompositeShape(TGeoCompositeShape *cs, TGeoHMatrix matrix)
Definition: TGeoToOCC.cxx:225
Double_t y[n]
Definition: legend1.C:17
virtual void SetPoints(Double_t *points) const
create polygone mesh points
Definition: TGeoPgon.cxx:1840
TopoDS_Shape OCC_Sphere(Double_t rmin, Double_t rmax, Double_t phi1, Double_t Dphi, Double_t theta1, Double_t Dtheta)
Definition: TGeoToOCC.cxx:374
bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
TopoDS_Shape OCC_ParaTrap(Double_t *vertex)
Definition: TGeoToOCC.cxx:670
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
TopoDS_Shape OCC_SimpleShape(TGeoShape *TG_Shape)
Definition: TGeoToOCC.cxx:129
Double_t GetX(Int_t i) const
Definition: TGeoXtru.h:103
Double_t * GetRmax() const
Definition: TGeoPcon.h:91
Double_t GetPhi2() const
Definition: TGeoSphere.h:86
double tan(double)
TopoDS_Shape Reverse(TopoDS_Shape Shape)
Definition: TGeoToOCC.cxx:1038
virtual Double_t GetDz() const
Definition: TGeoTube.h:79
Double_t GetDx1() const
Definition: TGeoTrd1.h:66
TopoDS_Shape fOccShape
Definition: TGeoToOCC.h:55
double result[121]
virtual const Double_t * GetTranslation() const
Definition: TGeoMatrix.h:455
virtual ~TGeoToOCC()
Definition: TGeoToOCC.cxx:124
Double_t GetRmin() const
Definition: TGeoTorus.h:83
Double_t GetDx2() const
Definition: TGeoTrd1.h:67
TopoDS_Shape OCC_Hype(Double_t rmin, Double_t rmax, Double_t stin, Double_t stout, Double_t dz)
Definition: TGeoToOCC.cxx:613
double poly2(const double *x, const double *p)
Double_t GetDz() const
Definition: TGeoArb8.h:90
Int_t GetNz() const
Definition: TGeoPcon.h:87
virtual Double_t GetRmax() const
Definition: TGeoTube.h:78
virtual Int_t GetNsegments() const
Returns number of segments on each mesh circle segment.
Definition: TGeoPgon.h:95
Double_t * GetVertices()
Definition: TGeoArb8.h:94
virtual Double_t GetB() const
Definition: TGeoEltu.h:55