EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_autoenvelope.h
Go to the documentation of this file.
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 #
31 ###############################################################################
32 #
33 # egs_autoenvelope was developed for the Carleton Laboratory for
34 # Radiotherapy Physics.
35 #
36 ###############################################################################
37 */
38 
39 
45 #ifndef EGS_AENVELOPE_GEOMETRY_
46 #define EGS_AENVELOPE_GEOMETRY_
47 
48 #ifdef WIN32
49 
50  #ifdef BUILD_AENVELOPE_DLL
51  #define EGS_AENVELOPE_EXPORT __declspec(dllexport)
52  #else
53  #define EGS_AENVELOPE_EXPORT __declspec(dllimport)
54  #endif
55  #define EGS_AENVELOPE_LOCAL
56 
57 #else
58 
59  #ifdef HAVE_VISIBILITY
60  #define EGS_AENVELOPE_EXPORT __attribute__ ((visibility ("default")))
61  #define EGS_AENVELOPE_LOCAL __attribute__ ((visibility ("hidden")))
62  #else
63  #define EGS_AENVELOPE_EXPORT
64  #define EGS_AENVELOPE_LOCAL
65  #endif
66 
67 #endif
68 
69 
70 #include "egs_base_geometry.h"
71 #include "egs_functions.h"
72 #include "egs_transformations.h"
73 #include "egs_shapes.h"
74 #include "volcor.h"
75 
76 #include<vector>
77 #include<algorithm>
78 #include<map>
79 #include<set>
80 
81 
337 using std::vector;
338 using namespace volcor;
339 
340 
342 struct EGS_AENVELOPE_LOCAL AEnvelopeAux {
343  EGS_BaseGeometry *geom;
344  EGS_AffineTransform *transform;
345  volcor::VCOptions *vcopts;
346 
348  geom(geom), transform(transform), vcopts(vcopts) {};
349 };
350 
352 class EGS_AENVELOPE_EXPORT EGS_AEnvelope : public EGS_BaseGeometry {
353 
354 
355 public:
356 
357  EGS_AEnvelope(EGS_BaseGeometry *base_geom,
358  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
359 
360  ~EGS_AEnvelope();
361 
362  int getGlobalRegFromLocalReg(EGS_BaseGeometry *g, int local_reg);
363 
364  int getGlobalRegFromLocal(const volcor::GeomRegPairT local) const;
365 
366  volcor::GeomRegPairT getLocalFromGlobalReg(int ireg) const;
367 
368  int getNRegWithInscribed() const;
369 
370  bool isRealRegion(int ireg) const;
371 
372  bool isInside(const EGS_Vector &x);
373 
374  int isWhere(const EGS_Vector &x);
375 
376  int inside(const EGS_Vector &x);
377 
378  int medium(int ireg) const;
379 
380  virtual vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
381 
382  int computeIntersections(int ireg, int n, const EGS_Vector &X,
383  const EGS_Vector &u, EGS_GeometryIntersections *isections);
384 
385 
386  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u);
387 
388  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
389  EGS_Float &t, int *newmed = 0, EGS_Vector *normal = 0);
390 
391  EGS_Float hownear(int ireg, const EGS_Vector &x);
392 
393  bool hasBooleanProperty(int ireg, EGS_BPType prop) const;
394 
395  void setBooleanProperty(EGS_BPType);
396 
397  void addBooleanProperty(int);
398 
399  void setBooleanProperty(EGS_BPType,int,int,int step=1);
400 
401  void addBooleanProperty(int,int,int,int step=1);
402 
403  int getMaxStep() const;
404 
405  virtual EGS_Float getVolume(int ireg);
406 
407  virtual EGS_Float getCorrectionRatio(int ireg);
408 
409  virtual const string &getType() const {
410  return type;
411  };
412 
413  void printInfo() const;
414 
415  void setRelativeRho(int start, int end, EGS_Float rho);
416  void setRelativeRho(EGS_Input *);
417 
418  EGS_Float getRelativeRho(int ireg) const;
419 
436  static vector<EGS_AffineTransform *> createTransforms(EGS_Input *inpt);
437 
438 
441  static bool allowedBaseGeomType(const string &geom_type);
442 
443 
444 protected:
445 
447  vector<EGS_BaseGeometry *> inscribed_geoms;
448  vector<EGS_AffineTransform *> transforms;
449  vector<volcor::VCOptions *> opts;
450  int nregbase;
452  int nreg_with_inscribed;
453 
454  bool debug_info;
455  string output_vc;
456  volcor::VCResults vc_results;
457 
458  // conversions from inscribed to global region numbers and vice versa
459  map<volcor::GeomRegPairT, int> local_to_global_reg;
460  map<int, volcor::GeomRegPairT> global_reg_to_local;
461 
462  //keep track of which geometries are present in which base geometry regions
463  vector<EGS_BaseGeometry *> *geoms_in_region;
464 
465  static string type;
466 
467  const static string allowed_base_geom_types[];
468 
475  void setMedia(EGS_Input *,int,const int *);
476 
477  double findRegionsInscribedIn(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
478  double loadFileVolumeCorrections(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
479 
481 
482  void writeVCToFile(ostream &);
483  void writeVolumeCorrection();
484 
485 private:
486 
487  void setPropertyError(const char *funcname) {
488  egsFatal("EGS_AEnvelope::%s: don't use this method\n Define "
489  "properties in the constituent geometries instead\n",
490  funcname);
491  };
492 
493  bool getHasRhoScaling();
494 
495 };
496 
549 class EGS_AENVELOPE_EXPORT EGS_ASwitchedEnvelope : public EGS_AEnvelope {
550 
551 private:
552 
553  vector<EGS_BaseGeometry *> active_inscribed;
554  int cur_ptr;
555 
556 protected:
557 
558  static string type;
559 
560  vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
561 
562 public:
563 
565  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
566 
567  const string &getType() const {
568  return type;
569  };
570 
573  void setActiveGeometries(vector<EGS_BaseGeometry *> geoms);
574 
577  void setActiveGeometries(vector<int> geom_indexes);
578 
580  bool hasActiveGeom(int ireg);
581 
583  bool hasInactiveGeom(int ireg);
584 
586  void setActiveByIndex(int inscribed_index);
587 
589  void activateByIndex(int inscribed_index);
590 
592  void deactivateByIndex(int inscribed_index);
593 
595  void cycleActive();
596 
597 };
598 
599 #endif
A fast envelope geometry with automatic region detection.
A helper class for initializing auto envelopes.
This geometry type allows you to activate and deactivate inscribed geometries in custom egspp user co...
std::map< int, EGS_I64 > HitCounterT
Definition: volcor.h:93
A class providing affine transformations.
Region discovery/volume correction functionality for EGS_AEnvelope geometries.
A class representing 3D vectors.
Definition: egs_vector.h:56
pair< EGS_BaseGeometry *, int > GeomRegPairT
Definition: volcor.h:88
int nregbase
Number of regions in the base geometry.
Global egspp functions header file.
vector< EGS_BaseGeometry * > inscribed_geoms
The inscribed geometries.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
vector< EGS_AffineTransform * > transforms
The inscribed geometries.
vector< EGS_Float > applyVolumeCorrections(VCOptions *opts, HitCounterT hit_counter, vector< EGS_Float > uncorrected)
Apply volume corrections to base regions.
Definition: volcor.h:502
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
vector< volcor::VCOptions * > opts
The inscribed geometries.
EGS_BaseShape and shape classes header file.
EGS_BaseGeometry * base_geom
The envelope geometry.
EGS_AffineTransform and EGS_RotationMatrix class header file.
Struct used to collect and output results about a volume correction run.
Definition: volcor.h:424
static string type
Geometry type.
Volume correction initialization helper class.
Definition: volcor.h:241
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
EGS_BaseGeometry class header file.
int ninscribed
Number of regions in the base geometry.
static string type
Geometry type.