File: boolminustest.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 (91 lines) | stat: -rw-r--r-- 3,648 bytes parent folder | download | duplicates (2)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * boolminustest.cpp
 *
 *  Created on: Aug 13, 2014
 *      Author: swenzel
 */

#include "VecGeom/volumes/TUnplacedBooleanMinusVolume.h"
#include "VecGeom/volumes/kernel/TBooleanMinusImplementation.h"
#include "VecGeom/volumes/Box.h"
#include "VecGeom/base/Transformation3D.h"
#include "VecGeom/base/Vector3D.h"
#include "VecGeom/volumes/PlacedVolume.h"
#include <iostream>

using namespace vecgeom;

// now create a specialized box by hand (instead of the factory)
// we know that it is only translated
typedef SpecializedBox<translation::kIdentity, rotation::kIdentity> OriginBox_t;
typedef SpecializedBox<translation::kGeneric, rotation::kIdentity> TranslatedBox_t;
// typedef TUnplacedBooleanMinusVolume<
//             OriginBox_t, TranslatedBox_t > BoxMinusBox_t;

// if we don't want to give all this information, we can also be very unprecise and construct something based on
// virtual functions
typedef TUnplacedBooleanMinusVolume<VPlacedVolume, VPlacedVolume> GenericSubtraction_t;

// let's try the vector interface
Real_v DistanceToOut(BoxMinusBox_t const &unplaced, Vector3D<Real_v> const &point, Vector3D<Real_v> const &dir)
{
  Real_v dist(0.);
  TBooleanMinusImplementation<translation::kIdentity, rotation::kIdentity>::DistanceToOut<BoxMinusBox_t, kVc>(
      unplaced, point, dir, kInfLength, dist);
  return dist;
}

double DistanceToOut(BoxMinusBox_t const &unplaced, Vector3D<Precision> const &point, Vector3D<Precision> const &dir)
{
  double dist(0.);
  TBooleanMinusImplementation<translation::kIdentity, rotation::kIdentity>::DistanceToOut<BoxMinusBox_t, kScalar>(
      unplaced, point, dir, kInfLength, dist);
  return dist;
}

double SafetyToOut(BoxMinusBox_t const &unplaced, Vector3D<Precision> const &point)
{
  double dist(0);
  TBooleanMinusImplementation<translation::kIdentity, rotation::kIdentity>::SafetyToOut<BoxMinusBox_t, kScalar>(
      unplaced, point, dist);
  return dist;
}
/*
double DistanceToOut2( GenericSubtraction_t const & unplaced, Vector3D<Precision> const & point, Vector3D<Precision>
const & dir)
{
    double dist(0);
    TBooleanMinusImplementation<translation::kIdentity,
rotation::kIdentity>::DistanceToOut<GenericSubtraction_t,kScalar>(
            unplaced, point, dir, kInfLength, dist);
    return dist;
}
*/

int main()
{
  UnplacedBox world(10., 10., 10.);
  UnplacedBox motherbox(5., 5., 5.);
  UnplacedBox subtractedbox(2., 2., 2);
  Transformation3D translation(-2.5, 0, 0);

  // now create a specialized box by hand (instead of the factory)
  // we know that it is only translated
  typedef SpecializedBox<translation::kIdentity, rotation::kIdentity> OriginBox_t;
  typedef SpecializedBox<translation::kGeneric, rotation::kIdentity> TranslatedBox_t;

  TranslatedBox_t const *placedsubtractedbox = new TranslatedBox_t(new LogicalVolume("", &subtractedbox), &translation);

  // now create a specialized box by hand (instead of the factory)
  // we know that it is only translated
  OriginBox_t const *placedmotherbox = new OriginBox_t(new LogicalVolume("", &motherbox), &Transformation3D::kIdentity);

  // now make the boolean solid
  BoxMinusBox_t complexsolid(placedmotherbox, placedsubtractedbox);

  // now calculate distance to out; here directly talking to the solid
  std::cerr << DistanceToOut(complexsolid, Vector3D<Precision>(0., 0., 0.), Vector3D<Precision>(0, 0, -1)) << "\n";
  std::cerr << DistanceToOut(complexsolid, Vector3D<Precision>(0., 0., 0.), Vector3D<Precision>(-1, 0, 0)) << "\n";
  std::cerr << SafetyToOut(complexsolid, Vector3D<Precision>(0., 0., 0.));
  std::cerr << DistanceToOut(complexsolid, Vector3D<Real_v>(0.), Vector3D<Real_v>(-1.));
}