EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_autoenvelope_BACKUP_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 <<<<<<< HEAD
408  void getNextGeom(EGS_RandomGenerator *rndm);
409 
410  void updatePosition(EGS_Float time);
411 
412  void containsDynamic(bool &hasdynamic);
413 
414 ||||||| 5980abb0
415 =======
416  void getNextGeom(EGS_RandomGenerator *rndm);
417 
418  void updatePosition(EGS_Float time);
419 
420  void containsDynamic(bool &hasdynamic);
421 
422  bool hasRhoScaling() override;
423 
424  void finishInitialization() override;
425 
426 >>>>>>> develop
427  virtual EGS_Float getVolume(int ireg);
428 
429  virtual EGS_Float getCorrectionRatio(int ireg);
430 
431  virtual const string &getType() const {
432  return type;
433  };
434 
435  void printInfo() const;
436 
437  void setRelativeRho(int start, int end, EGS_Float rho);
438  void setRelativeRho(EGS_Input *);
439 
440  EGS_Float getRelativeRho(int ireg) const;
441 
458  static vector<EGS_AffineTransform *> createTransforms(EGS_Input *inpt);
459 
460 
463  static bool allowedBaseGeomType(const string &geom_type);
464 
465 
466 protected:
467 
468  EGS_BaseGeometry *base_geom;
469  vector<EGS_BaseGeometry *> inscribed_geoms;
470  vector<EGS_AffineTransform *> transforms;
471  vector<volcor::VCOptions *> opts;
472  int nregbase;
473  int ninscribed;
474  int nreg_with_inscribed;
475 
476  bool debug_info;
477  string output_vc;
478  volcor::VCResults vc_results;
479 
480  // conversions from inscribed to global region numbers and vice versa
481  map<volcor::GeomRegPairT, int> local_to_global_reg;
482  map<int, volcor::GeomRegPairT> global_reg_to_local;
483 
484  //keep track of which geometries are present in which base geometry regions
485  vector<EGS_BaseGeometry *> *geoms_in_region;
486 
487  static string type;
488 
489  const static string allowed_base_geom_types[];
490 
497  void setMedia(EGS_Input *,int,const int *);
498 
499  double findRegionsInscribedIn(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
500  double loadFileVolumeCorrections(vector<EGS_BaseGeometry *>, vector<EGS_AffineTransform *>, volcor::VCOptions *);
501 
503 
504  void writeVCToFile(ostream &);
505  void writeVolumeCorrection();
506 
507 private:
508 
509  void setPropertyError(const char *funcname) {
510  egsFatal("EGS_AEnvelope::%s: don't use this method\n Define "
511  "properties in the constituent geometries instead\n",
512  funcname);
513  };
514 
515  bool getHasRhoScaling();
516 
517 };
518 
571 class EGS_AENVELOPE_EXPORT EGS_ASwitchedEnvelope : public EGS_AEnvelope {
572 
573 private:
574 
575  vector<EGS_BaseGeometry *> active_inscribed;
576  int cur_ptr;
577 
578 protected:
579 
580  static string type;
581 
582  vector<EGS_BaseGeometry *> getGeomsInRegion(int ireg);
583 
584 public:
585 
587  const vector<AEnvelopeAux> inscribed, const string &Name = "", bool debug=false, string output_vc_file="no");
588 
589  const string &getType() const {
590  return type;
591  };
592 
595  void setActiveGeometries(vector<EGS_BaseGeometry *> geoms);
596 
599  void setActiveGeometries(vector<int> geom_indexes);
600 
602  bool hasActiveGeom(int ireg);
603 
605  bool hasInactiveGeom(int ireg);
606 
608  void setActiveByIndex(int inscribed_index);
609 
611  void activateByIndex(int inscribed_index);
612 
614  void deactivateByIndex(int inscribed_index);
615 
617  void cycleActive();
618 
619 };
620 
621 #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.