00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "G4VisExtent.hh"
00035
00036 #include "G4ios.hh"
00037
00038 const G4VisExtent G4VisExtent::NullExtent;
00039
00040 G4VisExtent::G4VisExtent (G4double xmin, G4double xmax,
00041 G4double ymin, G4double ymax,
00042 G4double zmin, G4double zmax):
00043 fXmin(xmin), fXmax(xmax), fYmin(ymin), fYmax(ymax), fZmin(zmin), fZmax(zmax),
00044 fRadiusCached(false), fCentreCached(false), fRadius(0.)
00045 {}
00046
00047 G4VisExtent::G4VisExtent (const G4Point3D& centre, G4double radius):
00048 fRadiusCached(true), fCentreCached(true),
00049 fRadius(radius), fCentre(centre)
00050 {
00051
00052 G4double halfSide (radius / std::sqrt (3.));
00053 fXmin = centre.x () - halfSide;
00054 fXmax = centre.x () + halfSide;
00055 fYmin = centre.y () - halfSide;
00056 fYmax = centre.y () + halfSide;
00057 fZmin = centre.z () - halfSide;
00058 fZmax = centre.z () + halfSide;
00059 }
00060
00061 G4VisExtent::~G4VisExtent () {}
00062
00063 const G4Point3D& G4VisExtent::GetExtentCentre () const {
00064 if (!fCentreCached) {
00065 fCentre = G4Point3D (((fXmin + fXmax) / 2.),
00066 ((fYmin + fYmax) / 2.),
00067 ((fZmin + fZmax) / 2.));
00068 fCentreCached = true;
00069 }
00070 return fCentre;
00071 }
00072
00073 G4double G4VisExtent::GetExtentRadius () const {
00074 if (!fRadiusCached) {
00075 fRadius = std::sqrt (((fXmax - fXmin) * (fXmax - fXmin)) +
00076 ((fYmax - fYmin) * (fYmax - fYmin)) +
00077 ((fZmax - fZmin) * (fZmax - fZmin))) / 2.;
00078 fRadiusCached = true;
00079 }
00080 return fRadius;
00081 }
00082
00083 std::ostream& operator << (std::ostream& os, const G4VisExtent& e) {
00084 os << "G4VisExtent (bounding box):";
00085 os << "\n X limits: " << e.fXmin << ' ' << e.fXmax;
00086 os << "\n Y limits: " << e.fYmin << ' ' << e.fYmax;
00087 os << "\n Z limits: " << e.fZmin << ' ' << e.fZmax;
00088 return os;
00089 }
00090
00091 G4bool G4VisExtent::operator != (const G4VisExtent& e) const {
00092 return ((fXmin != e.fXmin) ||
00093 (fXmax != e.fXmax) ||
00094 (fYmin != e.fYmin) ||
00095 (fYmax != e.fYmax) ||
00096 (fZmin != e.fZmin) ||
00097 (fZmax != e.fZmax));
00098 }