EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_autoenvelope_REMOTE_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  bool hasRhoScaling() override;
414 
415  void finishInitialization() override;
416 
417  virtual EGS_Float getVolume(int ireg);
418 
419  virtual EGS_Float getCorrectionRatio(int ireg);
420 
421  virtual const string &getType() const {
422  return type;
423  };
424 
425  void printInfo() const;
426 
427  void setRelativeRho(int start, int end, EGS_Float rho);
428  void setRelativeRho(EGS_Input *);
429 
430  EGS_Float getRelativeRho(int ireg) const;
431 
448  static vector<EGS_AffineTransform *> createTransforms(EGS_Input *inpt);
449 
450 
453  static bool allowedBaseGeomType(const string &geom_type);
454 
455 
456 protected:
457 
458  EGS_BaseGeometry *base_geom;
459  vector<EGS_BaseGeometry *> inscribed_geoms;
460  vector<EGS_AffineTransform *> transforms;
461  vector<volcor::VCOptions *> opts;
462  int nregbase;
463  int ninscribed;
464  int nreg_with_inscribed;
465 
466  bool debug_info;
467  string output_vc;
468  volcor::VCResults vc_results;
469 
470  // conversions from inscribed to global region numbers and vice versa
471  map<volcor::GeomRegPairT, int> local_to_global_reg;
472  map<int, volcor::GeomRegPairT> global_reg_to_local;
473 
474  //keep track of which geometries are present in which base geometry regions
475  vector<EGS_BaseGeometry *> *geoms_in_region;
476 
477  static string type;
478 
479  const static string allowed_base_geom_types[];
480 
487  void setMedia(EGS_Input *,int,const int *);
488 
489  double findRegionsInscribedIn(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
490  double loadFileVolumeCorrections(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
491 
493 
494  void writeVCToFile(ostream &);
495  void writeVolumeCorrection();
496 
497 private:
498 
499  void setPropertyError(const char *funcname) {
500  egsFatal("EGS_AEnvelope::%s: don't use this method\n Define "
501  "properties in the constituent geometries instead\n",
502  funcname);
503  };
504 
505  bool getHasRhoScaling();
506 
507 };
508 
561 class EGS_AENVELOPE_EXPORT EGS_ASwitchedEnvelope : public EGS_AEnvelope {
562 
563 private:
564 
565  vector<EGS_BaseGeometry *> active_inscribed;
566  int cur_ptr;
567 
568 protected:
569 
570  static string type;
571 
572  vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
573 
574 public:
575 
577  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
578 
579  const string &getType() const {
580  return type;
581  };
582 
585  void setActiveGeometries(vector<EGS_BaseGeometry *> geoms);
586 
589  void setActiveGeometries(vector<int> geom_indexes);
590 
592  bool hasActiveGeom(int ireg);
593 
595  bool hasInactiveGeom(int ireg);
596 
598  void setActiveByIndex(int inscribed_index);
599 
601  void activateByIndex(int inscribed_index);
602 
604  void deactivateByIndex(int inscribed_index);
605 
607  void cycleActive();
608 
609 };
610 
611 #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.