G4CompositeCurve.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 // G4CircularCurve.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4CompositeCurve.hh"
00037 #include "G4Line.hh"
00038 
00039 
00040 G4CompositeCurve::G4CompositeCurve(){}
00041 
00042 G4CompositeCurve::G4CompositeCurve(const G4Point3DVector& vertices)
00043 {
00044   G4CurveVector cv;
00045   for (size_t i=0; i<vertices.size(); i++) 
00046   {
00047     G4Point3D p1= vertices[i];
00048     G4Point3D p2= vertices[(i+1) % vertices.size()];
00049     
00050     G4Line* l= new G4Line;
00051     l->Init(p1, p2-p1);
00052     l->SetBounds(p1, p2);
00053     cv.push_back(l);
00054   }
00055   
00056   Init(cv);
00057 }
00058 
00059 G4CompositeCurve::~G4CompositeCurve()
00060 {
00061   // Remove segments and delete all its contents
00062 
00063   G4Curve* a = 0;
00064   while (segments.size()>0)
00065   {
00066     a = segments.back();
00067     segments.pop_back();
00068     for (G4CurveVector::iterator i=segments.begin(); i!=segments.end();)
00069     {
00070       if (*i==a)
00071       {
00072         i = segments.erase(i);
00073       }
00074       else
00075       {
00076         ++i;
00077       }
00078     } 
00079     delete a;    
00080   } 
00081 }
00082 
00083 G4String G4CompositeCurve::GetEntityType() const 
00084 {
00085   return G4String("G4CompositeCurve");
00086 }
00087 
00088 G4Curve* G4CompositeCurve::Project(const G4Transform3D& tr)
00089 {
00090   G4CurveVector newSegments;
00091   G4Curve* a = 0;
00092   G4Curve* c = 0;
00093   
00094   for (size_t i=0; i<segments.size(); i++) 
00095   {
00096     c = segments[i]->Project(tr);
00097     if (c==0) 
00098     {
00099       // Remove newSegments and delete all its contents
00100       while (newSegments.size()>0)
00101       {
00102         a = newSegments.back();
00103         newSegments.pop_back();
00104         for (G4CurveVector::iterator it=newSegments.begin();
00105                                      it!=newSegments.end();)
00106         {
00107           if (*it==a)
00108           {
00109             it = newSegments.erase(it);
00110           }
00111           else
00112           {
00113             ++it;
00114           }
00115         } 
00116         delete a;
00117       } 
00118       return 0;
00119     }
00120     newSegments.push_back(c);
00121   }
00122   
00123   G4CompositeCurve* r= new G4CompositeCurve;
00124   r->Init(newSegments);
00125   return r;
00126 }
00127 
00129 
00130 G4double G4CompositeCurve::GetPMax() const
00131 {
00132   G4Exception("G4CompositeCurve::GetPMax()", "GeomSolids0002",
00133               FatalException, "Not applicable to base class.");
00134   return 0;
00135 }
00136 
00137 G4Point3D G4CompositeCurve::GetPoint(G4double) const
00138 {
00139   G4Exception("G4CompositeCurve::GetPoint()", "GeomSolids0002",
00140               FatalException, "Not applicable to base class.");
00141   // Fake return value
00142   return G4Point3D();
00143 }
00144 
00145 G4double G4CompositeCurve::GetPPoint(const G4Point3D&) const
00146 {
00147   G4Exception("G4CompositeCurve::GetPPoint()", "GeomSolids0002",
00148               FatalException, "Not applicable to base class.");
00149   return 0;
00150 }
00151 
00153 
00154 /*
00155 void G4CompositeCurve::IntersectRay2D(const G4Ray& ray,
00156                                       G4CurveRayIntersection& is)
00157 {
00158   is.Reset();
00159  
00160   for (G4int i=0; i<segments.entries(); i++) 
00161   {
00162     G4Curve& c= *(segments(i));
00163     G4CurveRayIntersection isTmp(c, ray);
00164     c.IntersectRay2D(ray, isTmp);
00165     if (isTmp.GetDistance() < is.GetDistance()) 
00166       is= isTmp;  
00167   }
00168   
00169   lastIntersection= is;
00170 }
00171 */
00172 
00173 G4int G4CompositeCurve::IntersectRay2D(const G4Ray& ray)
00174 {
00175   G4int nbinter = 0;
00176   G4int temp = 0;
00177  
00178   for (size_t i=0; i<segments.size(); i++) 
00179   {
00180     G4Curve& c= *(segments[i]);
00181     temp = c.IntersectRay2D(ray);
00182 
00183     // test if the point is on the composite curve
00184     if( temp == 999 )
00185        return 999;
00186      else
00187        nbinter+= temp; 
00188   }
00189  
00190   return nbinter;
00191 }
00192 
00193 G4bool G4CompositeCurve::Tangent(G4CurvePoint&, G4Vector3D& v)
00194 {
00195   if (lastIntersection.GetDistance() == kInfinity) 
00196     return false;
00197   
00198   return lastIntersection.GetCurve().Tangent(lastIntersection, v);
00199   // should be true 
00200   // cp is ignored for the moment
00201 }
00202 
00203 
00204 void G4CompositeCurve::InitBounded()
00205 {
00206   const G4BoundingBox3D* b= segments[0]->BBox();
00207   bBox.Init(b->GetBoxMin(), b->GetBoxMax());
00208   
00209   for (size_t i=1; i<segments.size(); i++) 
00210   {
00211     b= segments[i]->BBox();
00212     bBox.Extend(b->GetBoxMin());
00213     bBox.Extend(b->GetBoxMax());
00214   }
00215   
00216   // init for efficient parameter <-> 3D point conversions
00217 }

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