EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicCadWizardPlane.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicCadWizardPlane.cxx
1 
2 #include <assert.h>
3 
4 #include <gp_Pln.hxx>
5 
6 #include <TopoDS_Face.hxx>
7 #include <TopoDS_Shape.hxx>
8 
9 #include <BRepBuilderAPI_MakeFace.hxx>
10 #include <BRepPrimAPI_MakeHalfSpace.hxx>
11 
12 #include <TGeoHalfSpace.h>
13 
14 #include <EicCadWizardPlane.h>
15 
16 // =======================================================================================
17 
18 
20 {
21  gp_Pnt pnt = plane.Location();
22  gp_Dir dir = plane.Axis().Direction();
23 
24  // Prefer to avoid issues with identical plane cuts of different orientation;
25  // convert any direction vector to a "first non-zero coordinate positive" case;
26  if (dir.X()) {
27  if (dir.X() < 0.0) {
28  dir.SetX(-dir.X()); dir.SetY(-dir.Y()); dir.SetZ(-dir.Z());
29  } //if
30  } else if (dir.Y()) {
31  if (dir.Y() < 0.0) {
32  dir.SetX(-dir.X()); dir.SetY(-dir.Y()); dir.SetZ(-dir.Z());
33  } //if
34  } else {
35  if (dir.Z() < 0.0) {
36  dir.SetX(-dir.X()); dir.SetY(-dir.Y()); dir.SetZ(-dir.Z());
37  } //if
38  } //if
39  //printf("@@@ %f %f %f\n", dir.X(), dir.Y(), dir.Z());
40 
41  TopoDS_Face aFace = BRepBuilderAPI_MakeFace(gp_Pln(pnt, dir));//plane);
42 
43  // Whatever non-zero number;
44  double t = 0.1;
45  // NB: put "-" sign here, because dir[] is an outer normal in ROOT halfspace volume;
46  gp_Pnt x0(plane.Location()), pt(x0.X() - t*dir.X(), x0.Y() - t*dir.Y(), x0.Z() - t*dir.Z());
47 
48  mSolid = new TopoDS_Shape(BRepPrimAPI_MakeHalfSpace(aFace, pt).Solid());
49  mPlane = new gp_Pln(x0, dir);
50  assert(dir.IsEqual(gp_Pln(x0, dir).Axis().Direction(), _ANGULAR_TOLERANCE_));
51 } // EicCadWizardPlane::EicCadWizardPlane()
52 
53 // ---------------------------------------------------------------------------------------
54 
56 {
57  // Check object type first;
58  const EicCadWizardPlane *other = dynamic_cast<const EicCadWizardPlane*>(cut);
59  if (!other) return false;
60 
61  const gp_Pln *pll = mPlane, *plr = other->mPlane;
62 
63  if (pll->Axis().Direction().IsParallel(plr->Axis().Direction(), _ANGULAR_TOLERANCE_)) {
64  if (pll->Distance(plr->Location()) > _SPATIAL_TOLERANCE_) return false;
65 
66  // Ok, do it better later; should not happen;
67  //assert(lh.first == rh.first);
68 
69  return true;
70  } else {
71 #if _THINK_
72  // Try anti-parallel option; gp_Dir does not have easy reflection methods, sorry;
73  gp_Dir anti(-plr->Axis().Direction().X(),
74  -plr->Axis().Direction().Y(),
75  -plr->Axis().Direction().Z());
76 
77  if (pll->Axis().Direction().IsParallel(anti, _ANGULAR_TOLERANCE_)) {
78  if (pll->Distance(plr->Location()) > _SPATIAL_TOLERANCE_) return false;
79 
80  // Ok, do it better later; should not happen;
81  //assert(lh.first != rh.first);
82 
83  // FIXME: check that can work with both orientations (flip the flag
84  // at respective assignment in EicCadWizard::FaceGuidedSplit() method);
85  assert(0);
86  return true;
87  }
88  else
89 #endif
90  return false;
91  } //if
92 } // EicCadWizardPlane::IsEqual()
93 
94 // ---------------------------------------------------------------------------------------
95 
96 TGeoCombiTrans *EicCadWizardPlane::BuildRootVolume(const char *vname, const char *tname)
97 {
98  double x0[3] = {mPlane->Location().X(), mPlane->Location().Y(), mPlane->Location().Z()};
99  double n0[3] = {mPlane->Axis().Direction().X(), mPlane->Axis().Direction().Y(), mPlane->Axis().Direction().Z()};
100 
101  //printf("PL (%s) -> x0[]: %7.2f %7.2f %7.2f; n0[]: %7.2f %7.2f %7.2f\n",
102  // facets[fc].first ? "-" : "*", x0[0], x0[1], x0[2], n0[0], n0[1], n0[2]);
103 
104  new TGeoHalfSpace(vname, x0, n0);
105 
106  return 0;
107 } // EicCadWizardPlane::BuildRootVolume()
108 
109 // =======================================================================================