25 m_volumeMaterial(nullptr),
27 m_confinedLayers(nullptr),
28 m_confinedVolumes(nullptr),
33 const std::shared_ptr<const TrackingVolumeArray>& containedVolumeArray,
34 const std::string& volumeName)
35 :
Volume(std::move(htrans), std::move(volbounds)),
36 m_volumeMaterial(nullptr),
38 m_confinedLayers(nullptr),
39 m_confinedVolumes(containedVolumeArray),
47 std::shared_ptr<const Transform3D> htrans,
VolumeBoundsPtr volumeBounds,
48 std::shared_ptr<const IVolumeMaterial> volumeMaterial,
49 std::unique_ptr<const LayerArray> staticLayerArray,
50 std::shared_ptr<const TrackingVolumeArray> containedVolumeArray,
52 const std::string& volumeName)
53 :
Volume(std::move(htrans), std::move(volumeBounds)),
54 m_volumeMaterial(std::move(volumeMaterial)),
55 m_confinedLayers(std::move(staticLayerArray)),
56 m_confinedVolumes(std::move(containedVolumeArray)),
57 m_confinedDenseVolumes({}),
59 createBoundarySurfaces();
61 connectDenseBoundarySurfaces(denseVolumeVector);
67 std::vector<std::unique_ptr<Volume::BoundingBox>> boxStore,
68 std::vector<std::unique_ptr<const Volume>> descendants,
70 std::shared_ptr<const IVolumeMaterial> volumeMaterial,
71 const std::string& volumeName)
72 :
Volume(std::move(htrans), std::move(volbounds)),
73 m_volumeMaterial(std::move(volumeMaterial)),
75 m_descendantVolumes(std::move(descendants)),
80 for (
auto& uptr : boxStore) {
82 std::unique_ptr<Volume::BoundingBox>(uptr.release()));
87 delete m_glueVolumeDescriptor;
92 const double tol)
const {
94 if (m_confinedVolumes) {
95 return (m_confinedVolumes->object(position).get());
99 if (!m_confinedDenseVolumes.empty())
100 for (
auto& denseVolume : m_confinedDenseVolumes)
101 if (denseVolume->inside(position, tol))
102 return denseVolume.get();
110 return (m_boundarySurfaces);
115 if (!confinedDenseVolumes.empty()) {
118 for (
auto& confDenseVol : confinedDenseVolumes) {
120 auto& boundSur = confDenseVol->boundarySurfaces();
121 for (
unsigned int i = 0; i < boundSur.size(); i++) {
124 if (boundSur.at(i) ==
nullptr) {
133 if (mutableBs->m_insideVolume !=
nullptr &&
134 mutableBs->m_outsideVolume ==
nullptr) {
136 mutableBs->attachVolume(
this, bo);
138 if (mutableBs->m_insideVolume ==
nullptr &&
139 mutableBs->m_outsideVolume !=
nullptr) {
141 mutableBs->attachVolume(
this, bo);
149 m_confinedDenseVolumes.push_back(std::move(confDenseVol));
156 std::vector<std::shared_ptr<const Surface>> surfaces =
161 size_t sfNumber = surfaces.size();
163 for (
auto& sf : surfaces) {
171 m_boundarySurfaces.push_back(
189 std::shared_ptr<const BoundarySurfaceT<TrackingVolume>> bSurfaceMine =
190 boundarySurfaces().at(bsfMine);
194 bSurfaceMine->surfaceRepresentation().normal(gctx, bPosition);
200 if ((m_glueVolumeDescriptor ==
nullptr) ||
201 m_glueVolumeDescriptor->glueVolumes(bsfMine) ==
nullptr) {
203 auto mutableBSurfaceMine =
205 mutableBSurfaceMine->
attachVolume(neighbor, bOrientation);
207 const Surface& neighborSurface =
210 const Surface& mySurface = bSurfaceMine->surfaceRepresentation();
213 if (myMaterial ==
nullptr and neighborMaterial !=
nullptr) {
224 const std::shared_ptr<TrackingVolumeArray>& neighbors,
228 std::shared_ptr<const TrackingVolume> nRefVolume =
229 neighbors->arrayObjects().at(0);
233 Vector3D(nRefVolume->binningPosition(gctx,
binR) - bPosition);
235 std::shared_ptr<const BoundarySurfaceT<TrackingVolume>> bSurfaceMine =
236 boundarySurfaces().at(bsfMine);
240 bSurfaceMine->surfaceRepresentation().normal(gctx, bPosition);
246 if ((m_glueVolumeDescriptor ==
nullptr) ||
247 !m_glueVolumeDescriptor->glueVolumes(bsfMine)) {
249 auto mutableBSurfaceMine =
253 for (
auto& nVolume : neighbors->arrayObjects()) {
255 (mutableNVolume->m_boundarySurfaces).
at(bsfNeighbor) = bSurfaceMine;
261 std::shared_ptr<const ISurfaceMaterial> surfaceMaterial,
263 auto bSurface = m_boundarySurfaces.at(bsFace);
271 bool checkmaterial) {
273 auto cMaterialPtr = m_boundarySurfaces.at(bsf)
274 ->surfaceRepresentation()
275 .surfaceMaterialSharedPtr();
276 auto bsMaterial = bs->surfaceRepresentation().surfaceMaterial();
277 if (cMaterialPtr !=
nullptr && bsMaterial ==
nullptr) {
282 m_boundarySurfaces.at(bsf) = std::move(bs);
287 delete m_glueVolumeDescriptor;
288 m_glueVolumeDescriptor = gvd;
292 if (m_glueVolumeDescriptor ==
nullptr) {
295 return (*m_glueVolumeDescriptor);
303 if (m_confinedLayers) {
307 for (
auto& clayIter : m_confinedLayers->arrayObjects()) {
322 if (m_confinedVolumes) {
326 for (
auto& cVolumesIter : m_confinedVolumes->arrayObjects()) {
327 cVolumesIter->synchronizeLayers(envelope);
333 if (m_confinedLayers) {
334 auto& layers = m_confinedLayers->arrayObjects();
338 const Layer* lastLayer =
nullptr;
339 for (
auto& layerPtr : layers) {
348 lastLayer = &mutableLayer;
352 for (
auto layerIter = layers.rbegin(); layerIter != layers.rend();
357 lastLayer = &mutableLayer;
364 std::map<std::string, const TrackingVolume*>& volumeMap,
size_t& vol) {
366 volumeMap[volumeName()] =
this;
375 if (materialDecorator !=
nullptr) {
376 materialDecorator->
decorate(*thisVolume);
378 if (thisVolume->volumeMaterial() ==
nullptr && thisVolume->motherVolume() &&
379 thisVolume->motherVolume()->volumeMaterial() !=
nullptr) {
381 thisVolume->motherVolume()->volumeMaterial());
382 if (protoMaterial ==
nullptr) {
383 thisVolume->assignVolumeMaterial(
384 thisVolume->motherVolume()->volumeMaterialSharedPtr());
388 this->assignGeoID(volumeID);
392 for (
auto& bSurfIter : boundarySurfaces()) {
394 auto& bSurface = bSurfIter->surfaceRepresentation();
398 auto& mutableBSurface = *(
const_cast<Surface*
>(&bSurface));
399 mutableBSurface.assignGeoID(boundaryID);
401 if (materialDecorator !=
nullptr) {
402 materialDecorator->
decorate(mutableBSurface);
407 if (!m_confinedVolumes) {
409 if (m_confinedLayers) {
412 for (
auto& layerPtr : m_confinedLayers->arrayObjects()) {
419 }
else if (m_bvhTop !=
nullptr) {
421 for (
const auto& descVol : m_descendantVolumes) {
425 if (avol !=
nullptr) {
427 for (
const auto& bnd : bndSrf) {
428 const auto& srf = bnd->surfaceRepresentation();
439 for (
auto& volumesIter : m_confinedVolumes->arrayObjects()) {
440 auto mutableVolumesIter =
443 mutableVolumesIter->closeGeometry(materialDecorator, volumeMap, vol);
447 if (!m_confinedDenseVolumes.empty()) {
448 for (
auto& volumesIter : m_confinedDenseVolumes) {
449 auto mutableVolumesIter =
452 mutableVolumesIter->closeGeometry(materialDecorator, volumeMap, vol);
459 if (!m_confinedVolumes) {
461 if (m_confinedLayers) {
462 for (
const auto&
layer : m_confinedLayers->arrayObjects()) {
463 if (
layer->surfaceArray() ==
nullptr) {
467 for (
const auto& srf :
layer->surfaceArray()->surfaces()) {
474 for (
const auto&
volume : m_confinedVolumes->arrayObjects()) {
475 volume->visitSurfaces(visitor);