G4BSplineCurve.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 // G4BSplineCurve.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4BSplineCurve.hh"
00037 #include "G4ControlPoints.hh"
00038 #include "G4KnotVector.hh"
00039 
00040 G4BSplineCurve::G4BSplineCurve()
00041   : degree(0), controlPointsList(0), knots(0), weightsData(0)
00042 {
00043 }
00044 
00045 void G4BSplineCurve::Init(G4int degree0, G4Point3DVector* controlPointsList0,
00046                           std::vector<G4double>* knots0,
00047                           std::vector<G4double>* weightsData0)
00048 {
00049   degree= degree0;
00050    
00051   G4int nbpoints =  controlPointsList0->size();
00052   controlPointsList = new G4Point3DVector(nbpoints,G4Point3D(0,0,0));
00053 
00054   G4int a;  
00055   for(a = 0; a < nbpoints; a++)
00056   {
00057     (*controlPointsList)[a] = (*controlPointsList0)[a];
00058   }
00059  
00060   G4int nbknots = knots0->size();
00061   knots = new std::vector<G4double>(nbknots,0.);
00062   for(a = 0; a < nbknots; a++)
00063   {
00064     (*knots)[a] = (*knots0)[a];
00065   }
00066 
00067   G4int nbweights = weightsData0->size();
00068   weightsData  = new std::vector<G4double>(nbweights,0.);
00069   for(a = 0; a < nbweights; a++)
00070   {
00071     (*weightsData)[a] = (*weightsData0)[a];
00072   }
00073   
00074   SetBounds((*knots)[0], (*knots)[knots->size()-1]);
00075 }
00076 
00077 
00078 G4BSplineCurve::~G4BSplineCurve()
00079 {
00080   delete [] controlPointsList;
00081   delete [] knots;
00082   delete [] weightsData;
00083 }
00084 
00085 
00086 G4BSplineCurve::G4BSplineCurve(const G4BSplineCurve& right)
00087   : G4Curve()
00088 {
00089   delete [] controlPointsList;
00090   delete [] knots;
00091   delete [] weightsData;
00092   Init(right.degree, right.controlPointsList,
00093        right.knots, right.weightsData);
00094   bBox      = right.bBox;
00095   start     = right.start;
00096   end       = right.end;
00097   pStart    = right.pStart;
00098   pEnd      = right.pEnd;
00099   pRange    = right.pRange;
00100   bounded   = right.bounded;
00101   sameSense = right.sameSense;
00102 }
00103 
00104 G4BSplineCurve& G4BSplineCurve::operator=(const G4BSplineCurve& right)
00105 {
00106   if (&right == this)  { return *this; }
00107   delete [] controlPointsList;
00108   delete [] knots;
00109   delete [] weightsData;
00110   Init(right.degree, right.controlPointsList,
00111        right.knots, right.weightsData);
00112   bBox      = right.bBox;
00113   start     = right.start;
00114   end       = right.end;
00115   pStart    = right.pStart;
00116   pEnd      = right.pEnd;
00117   pRange    = right.pRange;
00118   bounded   = right.bounded;
00119   sameSense = right.sameSense;
00120 
00121   return *this;
00122 }
00123 
00124 // add by L. Broglia to pass linkage
00125 
00126 G4double G4BSplineCurve::GetPMax() const
00127 {
00128   return 0.0;
00129 }
00130 
00131 G4Point3D G4BSplineCurve::GetPoint(G4double) const
00132 {
00133   return G4Point3D(0, 0, 0);
00134 }
00135 
00136 G4double  G4BSplineCurve::GetPPoint(const G4Point3D&) const
00137 {
00138   return 0.0;
00139 }
00140 
00141 /*
00142 #include "G4CurveRayIntersection.hh"
00143 
00144 void G4BSplineCurve::IntersectRay2D(const G4Ray& ray,
00145                                     G4CurveRayIntersection& is)
00146 {
00147 }
00148 */
00149 
00150 G4int G4BSplineCurve::IntersectRay2D(const G4Ray&)
00151 {
00152   // L. Broglia
00153   G4Exception("G4BSplineCurve::IntersectRay2D()", "GeomSolids0001",
00154               FatalException, "Sorry, not yet implemented.");
00155   return 0;
00156 }
00157 
00158 /*
00159 void G4BSplineCurve::CalcCurvePlaneNormal()
00160 {
00161         //Calc Normal for surface which is used for the projection
00162     G4ThreeVec norm;
00163     G4Point3d Pt1 = ControlPointList->get(0,0);
00164     G4Point3d Pt2 = ControlPointList->get(0,1);
00165     G4Point3d Pt3 = ControlPointList->get(0,2);    
00166     G4Point3d a(Pt2.X()-Pt1.X(), Pt2.Y()-Pt1.Y(), Pt2.Z()-Pt1.Z());
00167     G4Point3d b(Pt3.X()-Pt1.X(), Pt3.Y()-Pt1.Y(), Pt3.Z()-Pt1.Z()); 
00168     norm.X((a.Y()*b.Z() - a.Z()*b.Y()));
00169     norm.Y((a.X()*b.Z() - a.Z()*b.X()));
00170     norm.Z((a.X()*b.Y() - a.Y()*b.X()));
00171 
00172 }
00173 */
00174 
00175 
00176 G4Curve* G4BSplineCurve::Project(const G4Transform3D& tr)
00177 {
00178   // just transform + project all control points
00179   // what about self intersections?
00180   
00181   G4int            n                    = controlPointsList->size();
00182   G4Point3DVector* newControlPointsList = new G4Point3DVector(n);
00183 
00184   for (G4int i=0; i<n; i++)
00185   {
00186     G4Point3D& p= (*newControlPointsList)[i];
00187     p= tr*(*controlPointsList)[i];
00188     p.setZ(0);
00189   }
00190 
00191   std::vector<G4double>* newKnots= new std::vector<G4double>(*knots);
00192   std::vector<G4double>* newWeightsData= 
00193     weightsData ? new std::vector<G4double>(*weightsData)
00194                 : new std::vector<G4double>(0);
00195 
00196   G4BSplineCurve* r= new G4BSplineCurve;
00197   r->Init(degree, newControlPointsList, newKnots, newWeightsData);
00198 
00199   delete newControlPointsList;
00200   delete newKnots;
00201   delete newWeightsData;
00202 
00203   if (IsBounded()) 
00204   {
00205     r->SetBounds(GetPStart(), GetPEnd());
00206   }
00207   return r;
00208 }
00209 
00210 
00211 /*
00212 void G4BSplineCurve::ProjectCurve(const G4Plane& Pl1, const G4Plane& Pl2)
00213 {
00214     int rows  = ControlPointList->GetRows();
00215     int cols  = ControlPointList->GetCols();
00216     int NumberOfPoints = cols * rows;
00217     ProjectedControlPoints = new G4Point2d*[NumberOfPoints];
00218     // Loop through points and do projection
00219     for(int a = 0; a<NumberOfPoints;a++)
00220     {
00221         // Create 2d-point
00222         ProjectedControlPoints[a] = new G4Point2d;
00223         // Project 3d points into 2d
00224         Project((*ProjectedControlPoints[a]), ControlPointList->get(0,a), Pl1, Pl2); 
00225     }
00226 }
00227 
00228 
00229 int G4BSplineCurve::Inside( const G4Point3d& Hit, const G4Ray& rayref)
00230 {
00231   const G4Plane& Pl1 = rayref.GetPlane(0);
00232   const G4Plane& Pl2 = rayref.GetPlane(1);    
00233   register G4double DistA1, DistA2, DistB1, DistB2;
00234   // Calc distance from Start point to ray planes
00235   DistA1 = Start.PlaneDistance(Pl1);
00236   // Calc distance from End point to ray planes    
00237   DistB1 = End.PlaneDistance(Pl1);
00238   if((DistA1<0 && DistB1>0)||(DistA1>0 && DistB1 <0))
00239     {
00240       DistA2 = Start.PlaneDistance(Pl2);    
00241       DistB2 = End.PlaneDistance(Pl2);          
00242       // This checks the line Start-End of the convex hull
00243         if(DistA2<0&&DistB2<0)
00244           return 1;
00245     }
00246   // Test for the other lines of the convex hull
00247   // If one of them is on a different side than the
00248   // previously checked line, the curve has to be evaluated
00249   // against the G4Plane.
00250   int Points = ControlPointList->GetCols();
00251 
00252   G4Point *CPoint1, *CPoint2;    
00253 
00254   register G4double CDistA1,CDistA2, CDistB1, CDistB2;
00255   int Flag=0;
00256   for(int a=0;a<Points-1;a++) 
00257     {
00258       CPoint1 = &ControlPointList->get(0,a);
00259       CPoint2 = &ControlPointList->get(0,a+1);
00260       CDistA1 = CPoint1->PlaneDistance(Pl1);
00261       CDistB1 = CPoint2->PlaneDistance(Pl1);
00262       if((CDistA1<0 && CDistB1>0)||(CDistA1>0 && CDistB1<0))
00263         {
00264           CDistA2 = CPoint1->PlaneDistance(Pl2);
00265           CDistB2 = CPoint2->PlaneDistance(Pl2);      
00266           if (!(CDistA2<0&&CDistB2<0))
00267           {
00268             Flag=1;
00269             break;
00270           }
00271         }
00272     }
00273         
00274 
00275   if(!Flag)
00276     return 1;  
00277   else
00278     {
00279       // Evaluate curve & Pl1 intersection, Calc the intersections distance
00280       // from Pl2 to check which side it lies on.
00281         G4Point3d IntPoint;
00282       //      G4cout << "\nG4B_SplineCurve.cc:Inside - Evaluation not yet implemented!!!\n";
00283       // IntPoint = ...
00284       G4double IntDist =  IntPoint.PlaneDistance(Pl2);
00285       if(IntDist<0)
00286         return 1;
00287     }
00288   return 0;
00289     
00290 }
00291 */
00292 
00293 
00294 void G4BSplineCurve::InitBounded()
00295 {
00296   // just like in the old functions
00297   G4int pointCount = controlPointsList->size();
00298   bBox.Init( (*controlPointsList)[0] );
00299   for (G4int i=1; i<pointCount; i++) 
00300   {
00301     bBox.Extend( (*controlPointsList)[i] );
00302   }
00303 }
00304 
00305 
00306 /*
00307 G4Point3d G4BSplineCurve::GetBoundMin()
00308 {
00309   G4Point3d Min = PINFINITY;
00310   int PointCount = ControlPointList->GetCols();
00311   G4Point3d Tmp;
00312   for(int a=0;a<PointCount;a++)
00313     {
00314         Tmp = ControlPointList->get(0,a);
00315         Min > Tmp;
00316     }
00317   return Min;
00318 }
00319 
00320 G4Point3d G4BSplineCurve::GetBoundMax()
00321 {
00322   G4Point3d Max = -PINFINITY;
00323   G4Point3d Tmp;
00324   int PointCount = ControlPointList->GetCols();
00325   for(int a=0;a<PointCount;a++)
00326     {
00327         Tmp = ControlPointList->get(0,a);
00328         Max > Tmp;
00329     }
00330   return Max;
00331 }
00332 */
00333 
00334 
00335 G4bool G4BSplineCurve::Tangent(G4CurvePoint&, G4Vector3D&)
00336 {
00337   G4Exception("G4BSplineCurve::Tangent()", "GeomSolids0001",
00338               FatalException, "Sorry, not implemented !");
00339   return false;
00340 }
00341 

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