EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_autoenvelope_LOCAL_785542.h
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ auto envelope geometry headers
5 # Copyright (C) 2016 Randle E. P. Taylor, Rowan M. Thomson,
6 # Marc J. P. Chamberland, D. W. O. Rogers
7 #
8 # This file is part of EGSnrc.
9 #
10 # EGSnrc is free software: you can redistribute it and/or modify it under
11 # the terms of the GNU Affero General Public License as published by the
12 # Free Software Foundation, either version 3 of the License, or (at your
13 # option) any later version.
14 #
15 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
18 # more details.
19 #
20 # You should have received a copy of the GNU Affero General Public License
21 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
22 #
23 ###############################################################################
24 #
25 # Author: Randle Taylor, 2016
26 #
27 # Contributors: Marc Chamberland
28 # Rowan Thomson
29 # Dave Rogers
30 # Martin Martinov
31 # Alexandre Demelo
32 #
33 ###############################################################################
34 #
35 # egs_autoenvelope was developed for the Carleton Laboratory for
36 # Radiotherapy Physics.
37 #
38 ###############################################################################
39 */
40 
41 
47 #ifndef EGS_AENVELOPE_GEOMETRY_
48 #define EGS_AENVELOPE_GEOMETRY_
49 
50 #ifdef WIN32
51 
52  #ifdef BUILD_AENVELOPE_DLL
53  #define EGS_AENVELOPE_EXPORT __declspec(dllexport)
54  #else
55  #define EGS_AENVELOPE_EXPORT __declspec(dllimport)
56  #endif
57  #define EGS_AENVELOPE_LOCAL
58 
59 #else
60 
61  #ifdef HAVE_VISIBILITY
62  #define EGS_AENVELOPE_EXPORT __attribute__ ((visibility ("default")))
63  #define EGS_AENVELOPE_LOCAL __attribute__ ((visibility ("hidden")))
64  #else
65  #define EGS_AENVELOPE_EXPORT
66  #define EGS_AENVELOPE_LOCAL
67  #endif
68 
69 #endif
70 
71 
72 #include "egs_base_geometry.h"
73 #include "egs_functions.h"
74 #include "egs_transformations.h"
75 #include "egs_shapes.h"
76 #include "volcor.h"
77 
78 #include<vector>
79 #include<algorithm>
80 #include<map>
81 #include<set>
82 
83 
339 using std::vector;
340 using namespace volcor;
341 
342 
344 struct EGS_AENVELOPE_LOCAL AEnvelopeAux {
345  EGS_BaseGeometry *geom;
346  EGS_AffineTransform *transform;
347  volcor::VCOptions *vcopts;
348 
350  geom(geom), transform(transform), vcopts(vcopts) {};
351 };
352 
354 class EGS_AENVELOPE_EXPORT EGS_AEnvelope : public EGS_BaseGeometry {
355 
356 
357 public:
358 
359  EGS_AEnvelope(EGS_BaseGeometry *base_geom,
360  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
361 
362  ~EGS_AEnvelope();
363 
364  int getGlobalRegFromLocalReg(EGS_BaseGeometry *g, int local_reg);
365 
366  int getGlobalRegFromLocal(const volcor::GeomRegPairT local) const;
367 
368  volcor::GeomRegPairT getLocalFromGlobalReg(int ireg) const;
369 
370  int getNRegWithInscribed() const;
371 
372  bool isRealRegion(int ireg) const;
373 
374  bool isInside(const EGS_Vector &x);
375 
376  int isWhere(const EGS_Vector &x);
377 
378  int inside(const EGS_Vector &x);
379 
380  int medium(int ireg) const;
381 
382  virtual vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
383 
384  int computeIntersections(int ireg, int n, const EGS_Vector &X,
385  const EGS_Vector &u, EGS_GeometryIntersections *isections);
386 
387 
388  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u);
389 
390  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
391  EGS_Float &t, int *newmed = 0, EGS_Vector *normal = 0);
392 
393  EGS_Float hownear(int ireg, const EGS_Vector &x);
394 
395  bool hasBooleanProperty(int ireg, EGS_BPType prop) const;
396 
397  void setBooleanProperty(EGS_BPType);
398 
399  void addBooleanProperty(int);
400 
401  void setBooleanProperty(EGS_BPType,int,int,int step=1);
402 
403  void addBooleanProperty(int,int,int,int step=1);
404 
405  int getMaxStep() const;
406 
407  void getNextGeom(EGS_RandomGenerator *rndm);
408 
409  void updatePosition(EGS_Float time);
410 
411  void containsDynamic(bool &hasdynamic);
412 
413  virtual EGS_Float getVolume(int ireg);
414 
415  virtual EGS_Float getCorrectionRatio(int ireg);
416 
417  virtual const string &getType() const {
418  return type;
419  };
420 
421  void printInfo() const;
422 
423  void setRelativeRho(int start, int end, EGS_Float rho);
424  void setRelativeRho(EGS_Input *);
425 
426  EGS_Float getRelativeRho(int ireg) const;
427 
444  static vector<EGS_AffineTransform *> createTransforms(EGS_Input *inpt);
445 
446 
449  static bool allowedBaseGeomType(const string &geom_type);
450 
451 
452 protected:
453 
454  EGS_BaseGeometry *base_geom;
455  vector<EGS_BaseGeometry *> inscribed_geoms;
456  vector<EGS_AffineTransform *> transforms;
457  vector<volcor::VCOptions *> opts;
458  int nregbase;
459  int ninscribed;
460  int nreg_with_inscribed;
461 
462  bool debug_info;
463  string output_vc;
464  volcor::VCResults vc_results;
465 
466  // conversions from inscribed to global region numbers and vice versa
467  map<volcor::GeomRegPairT, int> local_to_global_reg;
468  map<int, volcor::GeomRegPairT> global_reg_to_local;
469 
470  //keep track of which geometries are present in which base geometry regions
471  vector<EGS_BaseGeometry *> *geoms_in_region;
472 
473  static string type;
474 
475  const static string allowed_base_geom_types[];
476 
483  void setMedia(EGS_Input *,int,const int *);
484 
485  double findRegionsInscribedIn(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
486  double loadFileVolumeCorrections(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
487 
489 
490  void writeVCToFile(ostream &);
491  void writeVolumeCorrection();
492 
493 private:
494 
495  void setPropertyError(const char *funcname) {
496  egsFatal("EGS_AEnvelope::%s: don't use this method\n Define "
497  "properties in the constituent geometries instead\n",
498  funcname);
499  };
500 
501  bool getHasRhoScaling();
502 
503 };
504 
557 class EGS_AENVELOPE_EXPORT EGS_ASwitchedEnvelope : public EGS_AEnvelope {
558 
559 private:
560 
561  vector<EGS_BaseGeometry *> active_inscribed;
562  int cur_ptr;
563 
564 protected:
565 
566  static string type;
567 
568  vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
569 
570 public:
571 
573  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
574 
575  const string &getType() const {
576  return type;
577  };
578 
581  void setActiveGeometries(vector<EGS_BaseGeometry *> geoms);
582 
585  void setActiveGeometries(vector<int> geom_indexes);
586 
588  bool hasActiveGeom(int ireg);
589 
591  bool hasInactiveGeom(int ireg);
592 
594  void setActiveByIndex(int inscribed_index);
595 
597  void activateByIndex(int inscribed_index);
598 
600  void deactivateByIndex(int inscribed_index);
601 
603  void cycleActive();
604 
605 };
606 
607 #endif
A fast envelope geometry with automatic region detection.
static vector< EGS_AffineTransform * > createTransforms(EGS_Input *inpt)
Take a block of transformations and return vector of EGS_AffineTransforms.
static bool allowedBaseGeomType(const string &geom_type)
function for checking whether a given geometry type is allowed to be used as a base geometry
void setMedia(EGS_Input *, int, const int *)
Don't set media for an envelope geometry.
This geometry type allows you to activate and deactivate inscribed geometries in custom egspp user co...
void deactivateByIndex(int inscribed_index)
bool hasInactiveGeom(int ireg)
void activateByIndex(int inscribed_index)
void setActiveGeometries(vector< EGS_BaseGeometry * > geoms)
void setActiveByIndex(int inscribed_index)
void setActiveGeometries(vector< int > geom_indexes)
bool hasActiveGeom(int ireg)
A class providing affine transformations.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
Base random number generator class. All random number generators should be derived from this class.
Definition: egs_rndm.h:90
A class representing 3D vectors.
Definition: egs_vector.h:57
Volume correction initialization helper class.
Definition: volcor.h:242
EGS_BaseGeometry class header file.
Global egspp functions header file.
EGS_BaseShape and shape classes header file.
EGS_AffineTransform and EGS_RotationMatrix class header file.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
Region discovery/volume correction for auto envelope geometries.
Definition: volcor.h:78
std::map< int, EGS_I64 > HitCounterT
Definition: volcor.h:94
pair< EGS_BaseGeometry *, int > GeomRegPairT
Definition: volcor.h:89
vector< EGS_Float > applyVolumeCorrections(VCOptions *opts, HitCounterT hit_counter, vector< EGS_Float > uncorrected)
Apply volume corrections to base regions.
Definition: volcor.h:503
A helper class for initializing auto envelopes.
Struct used to collect and output results about a volume correction run.
Definition: volcor.h:425
Region discovery/volume correction functionality for EGS_AEnvelope geometries.