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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/// \file UnplacedScaledShape.cpp
/// \author Mihaela Gheata (mihaela.gheata@cern.ch)
#include "VecGeom/volumes/UnplacedScaledShape.h"
#include "VecGeom/management/VolumeFactory.h"
#include "VecGeom/volumes/SpecializedScaledShape.h"
#ifndef VECCORE_CUDA
#include "VecGeom/base/RNG.h"
#endif
#include <stdio.h>
#ifdef VECGEOM_CUDA_INTERFACE
#include "VecGeom/management/CudaManager.h"
#endif
namespace vecgeom {
inline namespace VECGEOM_IMPL_NAMESPACE {
VECCORE_ATT_HOST_DEVICE
void UnplacedScaledShape::Print() const
{
printf("UnplacedScaledShape: scale:{%g, %g, %g} shape: ", fScaled.fScale.Scale()[0], fScaled.fScale.Scale()[1],
fScaled.fScale.Scale()[2]);
// UnscaledShape()->Print();
}
void UnplacedScaledShape::Print(std::ostream &os) const
{
os << "UnplacedScaledShape: " << fScaled.fScale.Scale() << *UnscaledShape();
}
//______________________________________________________________________________
VECCORE_ATT_HOST_DEVICE
bool UnplacedScaledShape::Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const
{
bool valid = false;
ScaledShapeImplementation::NormalKernel<Precision>(fScaled, point, normal, valid);
return valid;
}
//______________________________________________________________________________
VECCORE_ATT_HOST_DEVICE
void UnplacedScaledShape::Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const
{
// Returns the full 3D cartesian extent of the solid.
// First get the extent of the unscaled shape
fScaled.fPlaced->Extent(aMin, aMax);
// The center of the extent may not be in the origin
Vector3D<Precision> pos;
pos = 0.5 * (aMin + aMax);
Vector3D<Precision> center, semilengths;
fScaled.fScale.InverseTransform(pos, center);
// The lenghts are also scaled
pos = 0.5 * (aMax - aMin);
fScaled.fScale.InverseTransform(pos, semilengths);
aMin = center - semilengths;
aMax = center + semilengths;
}
//______________________________________________________________________________
Vector3D<Precision> UnplacedScaledShape::SamplePointOnSurface() const
{
// Sample the scaled shape
Vector3D<Precision> sampled;
fScaled.fScale.InverseTransform(fScaled.fPlaced->GetUnplacedVolume()->SamplePointOnSurface(), sampled);
return sampled;
}
//______________________________________________________________________________
template <TranslationCode trans_code, RotationCode rot_code>
VECCORE_ATT_DEVICE
VPlacedVolume *UnplacedScaledShape::Create(LogicalVolume const *const logical_volume,
Transformation3D const *const transformation,
#ifdef VECCORE_CUDA
const int id, const int copy_no, const int child_id,
#endif
VPlacedVolume *const placement)
{
if (placement) {
new (placement) SpecializedScaledShape<trans_code, rot_code>(logical_volume, transformation
#ifdef VECCORE_CUDA
,
id, copy_no, child_id
#endif
);
return placement;
}
return new SpecializedScaledShape<trans_code, rot_code>(logical_volume, transformation
#ifdef VECCORE_CUDA
,
id, copy_no, child_id
#endif
);
}
//______________________________________________________________________________
VECCORE_ATT_DEVICE
VPlacedVolume *UnplacedScaledShape::CreateSpecializedVolume(LogicalVolume const *const volume,
Transformation3D const *const transformation,
const TranslationCode trans_code,
const RotationCode rot_code,
#ifdef VECCORE_CUDA
const int id, const int copy_no, const int child_id,
#endif
VPlacedVolume *const placement)
{
return VolumeFactory::CreateByTransformation<UnplacedScaledShape>(volume, transformation, trans_code, rot_code,
#ifdef VECCORE_CUDA
id, copy_no, child_id,
#endif
placement);
}
#ifdef VECGEOM_CUDA_INTERFACE
//______________________________________________________________________________
DevicePtr<cuda::VUnplacedVolume> UnplacedScaledShape::CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const in_gpu_ptr) const
{
DevicePtr<cuda::VPlacedVolume> gpuptr = CudaManager::Instance().LookupPlaced(fScaled.fPlaced);
Vector3D<Precision> const &scl = fScaled.fScale.Scale();
return CopyToGpuImpl<UnplacedScaledShape>(in_gpu_ptr, gpuptr, scl[0], scl[1], scl[2], fGlobalConvexity);
}
//______________________________________________________________________________
DevicePtr<cuda::VUnplacedVolume> UnplacedScaledShape::CopyToGpu() const
{
return CopyToGpuImpl<UnplacedScaledShape>();
}
#endif // VECGEOM_CUDA_INTERFACE
} // namespace VECGEOM_IMPL_NAMESPACE
#ifdef VECCORE_CUDA
namespace cxx {
template size_t DevicePtr<cuda::UnplacedScaledShape>::SizeOf();
// template void DevicePtr<cuda::UnplacedScaledShape>::Construct(
// DevicePtr<cuda::VPlacedVolume> gpuptr, Scale3D const scale) const;
template void DevicePtr<cuda::UnplacedScaledShape>::Construct(DevicePtr<cuda::VPlacedVolume> gpuptr, Precision sx,
Precision sy, Precision sz, bool globalConvexity) const;
} // namespace cxx
#endif
} // namespace vecgeom
|