File: SplittedABBox.cpp

package info (click to toggle)
vecgeom 1.2.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,016 kB
  • sloc: cpp: 88,803; ansic: 6,888; python: 1,035; sh: 582; sql: 538; makefile: 23
file content (75 lines) | stat: -rw-r--r-- 2,918 bytes parent folder | download
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
#include "VecGeom/volumes/utilities/VolumeUtilities.h"
#include "VecGeom/base/Global.h"
#include "VecGeom/base/Vector3D.h"
#include "VecGeom/base/Transformation3D.h"
#include "VecGeom/volumes/Box.h"
#include "VecGeomTest/Visualizer.h"
#include "VecGeom/volumes/Polycone.h"
#include "VecGeom/volumes/Cone.h"
#include "VecGeom/management/ABBoxManager.h"

using namespace vecgeom;

void Visualize(Visualizer *visualizer, VPlacedVolume const *pvol, std::vector<Vector3D<Precision>> lowerc_v,
               std::vector<Vector3D<Precision>> upperc_v);

int main()
{

  // Now trying to generate aligned bounding box for cone

  std::vector<Vector3D<Precision>> lowerc, upperc;

  int numOfSlices = 10;
  // UnplacedBox box(4,6,10);
  auto cone = GeoManager::MakeInstance<UnplacedCone>(0., 3., 0., 8., 30., 0., 2 * kPi);
  Transformation3D tr(0, 0, 0, 0, 30, 45);
  VPlacedVolume const *conePlaced = LogicalVolume("", cone).Place(&tr);
  ABBoxManager::Instance().ComputeSplittedABBox(conePlaced, lowerc, upperc, numOfSlices);

  Visualizer visualizer;
  Visualize(&visualizer, conePlaced, lowerc, upperc);
  visualizer.Show();

  return 0;
}

void Visualize(Visualizer *visualizer, VPlacedVolume const *pvol, std::vector<Vector3D<Precision>> lowerc_v,
               std::vector<Vector3D<Precision>> upperc_v)
{

  Transformation3D const *tr = pvol->GetTransformation();

  // Adding placedVolume to visualizer
  visualizer->AddVolume(*pvol, *tr);

  Vector3D<Precision> lowerc(0., 0., 0.), upperc(0., 0., 0.);
  pvol->Extent(lowerc, upperc);
  Vector3D<Precision> delta = (upperc - lowerc) / 2;
  UnplacedBox box(delta);
  VPlacedVolume const *boxPlaced = LogicalVolume("", &box).Place(tr);

  // Adding placedBoundingBox to visualizer
  visualizer->AddVolume(*boxPlaced, *tr);

  // Adding Global Aligned Box of the placed Volume
  Vector3D<Precision> lowerc_ABBox(0., 0., 0.), upperc_ABBox(0., 0., 0.);
  ABBoxManager::Instance().ComputeABBox(pvol, &lowerc_ABBox, &upperc_ABBox);
  delta                           = (upperc_ABBox - lowerc_ABBox) / 2;
  Vector3D<Precision> translation = (upperc_ABBox + lowerc_ABBox) / 2;
  Transformation3D trans(translation.x(), translation.y(), translation.z());
  UnplacedBox unplacedGlobalABBox(delta);
  VPlacedVolume const *placedGlobalABBox = LogicalVolume("", &unplacedGlobalABBox).Place(&trans);
  visualizer->AddVolume(*placedGlobalABBox, trans);

  // Adding SplittedABBoxes to visualizer
  for (auto itLower = lowerc_v.begin(), itUpper = upperc_v.begin(); itLower != lowerc_v.end(); itLower++, itUpper++) {
    delta       = (*itUpper - *itLower) / 2;
    translation = (*itUpper + *itLower) / 2;
    trans.SetTranslation(translation);
    trans.SetProperties();
    UnplacedBox unplacedSplittedABBox(delta);
    VPlacedVolume const *placedSplittedABBox = LogicalVolume("", &unplacedSplittedABBox).Place(&trans);
    visualizer->AddVolume(*placedSplittedABBox, trans);
  }
}