EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_autoenvelope_BASE_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 #
32 ###############################################################################
33 #
34 # egs_autoenvelope was developed for the Carleton Laboratory for
35 # Radiotherapy Physics.
36 #
37 ###############################################################################
38 */
39 
40 
46 #ifndef EGS_AENVELOPE_GEOMETRY_
47 #define EGS_AENVELOPE_GEOMETRY_
48 
49 #ifdef WIN32
50 
51  #ifdef BUILD_AENVELOPE_DLL
52  #define EGS_AENVELOPE_EXPORT __declspec(dllexport)
53  #else
54  #define EGS_AENVELOPE_EXPORT __declspec(dllimport)
55  #endif
56  #define EGS_AENVELOPE_LOCAL
57 
58 #else
59 
60  #ifdef HAVE_VISIBILITY
61  #define EGS_AENVELOPE_EXPORT __attribute__ ((visibility ("default")))
62  #define EGS_AENVELOPE_LOCAL __attribute__ ((visibility ("hidden")))
63  #else
64  #define EGS_AENVELOPE_EXPORT
65  #define EGS_AENVELOPE_LOCAL
66  #endif
67 
68 #endif
69 
70 
71 #include "egs_base_geometry.h"
72 #include "egs_functions.h"
73 #include "egs_transformations.h"
74 #include "egs_shapes.h"
75 #include "volcor.h"
76 
77 #include<vector>
78 #include<algorithm>
79 #include<map>
80 #include<set>
81 
82 
338 using std::vector;
339 using namespace volcor;
340 
341 
343 struct EGS_AENVELOPE_LOCAL AEnvelopeAux {
344  EGS_BaseGeometry *geom;
345  EGS_AffineTransform *transform;
346  volcor::VCOptions *vcopts;
347 
349  geom(geom), transform(transform), vcopts(vcopts) {};
350 };
351 
353 class EGS_AENVELOPE_EXPORT EGS_AEnvelope : public EGS_BaseGeometry {
354 
355 
356 public:
357 
358  EGS_AEnvelope(EGS_BaseGeometry *base_geom,
359  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
360 
361  ~EGS_AEnvelope();
362 
363  int getGlobalRegFromLocalReg(EGS_BaseGeometry *g, int local_reg);
364 
365  int getGlobalRegFromLocal(const volcor::GeomRegPairT local) const;
366 
367  volcor::GeomRegPairT getLocalFromGlobalReg(int ireg) const;
368 
369  int getNRegWithInscribed() const;
370 
371  bool isRealRegion(int ireg) const;
372 
373  bool isInside(const EGS_Vector &x);
374 
375  int isWhere(const EGS_Vector &x);
376 
377  int inside(const EGS_Vector &x);
378 
379  int medium(int ireg) const;
380 
381  virtual vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
382 
383  int computeIntersections(int ireg, int n, const EGS_Vector &X,
384  const EGS_Vector &u, EGS_GeometryIntersections *isections);
385 
386 
387  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u);
388 
389  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
390  EGS_Float &t, int *newmed = 0, EGS_Vector *normal = 0);
391 
392  EGS_Float hownear(int ireg, const EGS_Vector &x);
393 
394  bool hasBooleanProperty(int ireg, EGS_BPType prop) const;
395 
396  void setBooleanProperty(EGS_BPType);
397 
398  void addBooleanProperty(int);
399 
400  void setBooleanProperty(EGS_BPType,int,int,int step=1);
401 
402  void addBooleanProperty(int,int,int,int step=1);
403 
404  int getMaxStep() const;
405 
406  virtual EGS_Float getVolume(int ireg);
407 
408  virtual EGS_Float getCorrectionRatio(int ireg);
409 
410  virtual const string &getType() const {
411  return type;
412  };
413 
414  void printInfo() const;
415 
416  void setRelativeRho(int start, int end, EGS_Float rho);
417  void setRelativeRho(EGS_Input *);
418 
419  EGS_Float getRelativeRho(int ireg) const;
420 
437  static vector<EGS_AffineTransform *> createTransforms(EGS_Input *inpt);
438 
439 
442  static bool allowedBaseGeomType(const string &geom_type);
443 
444 
445 protected:
446 
447  EGS_BaseGeometry *base_geom;
448  vector<EGS_BaseGeometry *> inscribed_geoms;
449  vector<EGS_AffineTransform *> transforms;
450  vector<volcor::VCOptions *> opts;
451  int nregbase;
452  int ninscribed;
453  int nreg_with_inscribed;
454 
455  bool debug_info;
456  string output_vc;
457  volcor::VCResults vc_results;
458 
459  // conversions from inscribed to global region numbers and vice versa
460  map<volcor::GeomRegPairT, int> local_to_global_reg;
461  map<int, volcor::GeomRegPairT> global_reg_to_local;
462 
463  //keep track of which geometries are present in which base geometry regions
464  vector<EGS_BaseGeometry *> *geoms_in_region;
465 
466  static string type;
467 
468  const static string allowed_base_geom_types[];
469 
476  void setMedia(EGS_Input *,int,const int *);
477 
478  double findRegionsInscribedIn(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
479  double loadFileVolumeCorrections(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
480 
482 
483  void writeVCToFile(ostream &);
484  void writeVolumeCorrection();
485 
486 private:
487 
488  void setPropertyError(const char *funcname) {
489  egsFatal("EGS_AEnvelope::%s: don't use this method\n Define "
490  "properties in the constituent geometries instead\n",
491  funcname);
492  };
493 
494  bool getHasRhoScaling();
495 
496 };
497 
550 class EGS_AENVELOPE_EXPORT EGS_ASwitchedEnvelope : public EGS_AEnvelope {
551 
552 private:
553 
554  vector<EGS_BaseGeometry *> active_inscribed;
555  int cur_ptr;
556 
557 protected:
558 
559  static string type;
560 
561  vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
562 
563 public:
564 
566  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
567 
568  const string &getType() const {
569  return type;
570  };
571 
574  void setActiveGeometries(vector<EGS_BaseGeometry *> geoms);
575 
578  void setActiveGeometries(vector<int> geom_indexes);
579 
581  bool hasActiveGeom(int ireg);
582 
584  bool hasInactiveGeom(int ireg);
585 
587  void setActiveByIndex(int inscribed_index);
588 
590  void activateByIndex(int inscribed_index);
591 
593  void deactivateByIndex(int inscribed_index);
594 
596  void cycleActive();
597 
598 };
599 
600 #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
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.