G4SurfaceBoundary.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // ----------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // G4SurfaceBoundary.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4SurfaceBoundary.hh"
00037 #include "geomdefs.hh"
00038 #include "G4CompositeCurve.hh"
00039 
00040 
00041 G4SurfaceBoundary::G4SurfaceBoundary()
00042 {
00043 }
00044 
00045 G4SurfaceBoundary::~G4SurfaceBoundary()
00046 {
00047 }
00048 
00049 void G4SurfaceBoundary::Init(const G4CurveVector& bounds0)
00050 {
00051   bounds= bounds0;
00052   lastIntersection.Reset();
00053   
00054   const G4BoundingBox3D* b= bounds[0]->BBox();
00055   bBox.Init(b->GetBoxMin(), b->GetBoxMax());
00056   
00057   size_t i;
00058   for ( i=1; i<bounds.size(); i++) 
00059   {
00060     b= bounds[i]->BBox();
00061     bBox.Extend(b->GetBoxMin());
00062     bBox.Extend(b->GetBoxMax());
00063   }
00064 
00065   // the points array is probably unused, so the following code is useless
00066   G4int cnt= 0;
00067 
00068   size_t entr = bounds.size();
00069 
00070   for (i=0; i < entr; i++) 
00071   {
00072     G4Curve* c = bounds[i];
00073 
00074     if (c->GetEntityType() == "G4CompositeCurve") 
00075     {
00076       G4CompositeCurve* cc = (G4CompositeCurve*)c;
00077       const G4CurveVector& segments = cc->GetSegments();
00078       cnt+= segments.size();
00079     } 
00080     else 
00081       cnt++;
00082   }
00083 
00084   points.resize(cnt);
00085   
00086   G4int j= 0;
00087   
00088   for (i=0; i<bounds.size(); i++) 
00089   {
00090     G4Curve* c= bounds[i];
00091     if (c->GetEntityType() == "G4CompositeCurve") 
00092     {
00093       G4CompositeCurve* cc = (G4CompositeCurve*)c;
00094       const G4CurveVector& segments = cc->GetSegments();
00095      
00096       for (size_t k=0; k<segments.size(); k++) 
00097       {
00098         G4Curve* ccc = segments[k];
00099         G4Point3D p  = ccc->GetEnd();
00100         points[j]= p;
00101         j++;
00102       }
00103 
00104     } 
00105     else
00106     {
00107       G4Point3D p= c->GetEnd();
00108       points[j]= p;
00109       j++;
00110     }
00111   }
00112 }
00113 
00114 
00115 G4SurfaceBoundary* G4SurfaceBoundary::Project(const G4Transform3D& tr)
00116 {
00117   G4CurveVector newBounds;
00118   G4Curve* a = 0;
00119   G4Curve* c = 0;
00120   
00121   for (size_t i=0; i<bounds.size(); i++)
00122   {
00123     c= bounds[i]->Project(tr);
00124     
00125     if (c==0) 
00126     {
00127       // Remove newBounds and delete all its contents
00128       while (newBounds.size()>0)
00129       {
00130         a = newBounds.back();
00131         newBounds.pop_back();
00132         for (G4CurveVector::iterator it=newBounds.begin();
00133                                      it!=newBounds.end();)
00134         {
00135           if (*it==a)
00136           {
00137             it = newBounds.erase(it);
00138           }
00139           else
00140           {
00141             it--;
00142           }
00143         } 
00144         if ( a )  { delete a; }
00145       } 
00146       return 0;
00147     }
00148     // L. Broglia
00149     c->SetSameSense( bounds[i]->GetSameSense() );
00150 
00151     newBounds.push_back(c);
00152   }
00153   
00154   G4SurfaceBoundary* lof= new G4SurfaceBoundary;
00155   lof->Init(newBounds);
00156   return lof;
00157 }
00158 
00159 /*
00160 void G4SurfaceBoundary::IntersectRay2D(const G4Ray& ray,
00161                                        G4CurveRayIntersection& is)
00162 {
00163   is.Reset();
00164   G4int entr = bounds.entries();
00165   for (G4int i=0; i < entr; i++) 
00166   {
00167     G4Curve& c = *bounds.at(i);
00168     G4CurveRayIntersection isTmp(c, ray);
00169     c.IntersectRay2D(ray, isTmp);
00170     
00171     if (std::fabs(isTmp.GetDistance()) < std::fabs(is.GetDistance())) 
00172       is= isTmp;
00173   }
00174 
00175   lastIntersection= is;
00176 }
00177 */
00178 
00179 G4int G4SurfaceBoundary::IntersectRay2D(const G4Ray& ray)
00180 {
00181   G4int nbinter = 0;
00182   G4int temp = 0;
00183 
00184   for (size_t i=0; i < bounds.size(); i++) 
00185   {   
00186     G4Curve& c = *bounds[i];
00187     temp = c.IntersectRay2D(ray);
00188 
00189     // test if the point is on the boundary
00190     if ( temp == 999 )
00191       nbinter = 1;
00192     else
00193       nbinter += temp; 
00194   }
00195 
00196   return nbinter;
00197 }
00198 
00199 
00200 G4bool G4SurfaceBoundary::Tangent(G4CurvePoint&, G4Vector3D& v)
00201 {
00202   if (lastIntersection.GetDistance() == kInfinity) 
00203     return false;
00204   
00205   return lastIntersection.GetCurve().Tangent(lastIntersection, v);
00206   // should be true
00207   
00208   // cp is ignored for the moment
00209 }
00210 
00211 
00212 void G4SurfaceBoundary::SplitWithPlane(const G4Point3D&,
00213                                        const G4Vector3D&,
00214                                        G4SurfaceBoundary*&,
00215                                        G4SurfaceBoundary*&)
00216 {
00217   G4Exception("G4SurfaceBoundary::SplitWithPlane()", "GeomSolids0001",
00218               FatalException, "Sorry, not yet implemented.");
00219 }
00220 
00221 void G4SurfaceBoundary::SplitWithCylinder(const G4CylindricalSurface&,
00222                                           G4SurfaceBoundary*&, 
00223                                           G4SurfaceBoundary*&)
00224 {
00225   G4Exception("G4SurfaceBoundary::SplitWithCylinder()", "GeomSolids0001",
00226               FatalException, "Sorry, not yet implemented.");
00227 }

Generated on Mon May 27 17:49:56 2013 for Geant4 by  doxygen 1.4.7