G4ControlPoints.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 // G4ControlPoints.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4ControlPoints.hh"
00037 
00038 
00039 G4ControlPoints::G4ControlPoints()
00040 {
00041   nr=nc=0;
00042   data=(G4PointRat**)0;
00043 }
00044 
00045 
00046 G4ControlPoints::G4ControlPoints( G4int rows, G4int columns)
00047 {
00048   nr=rows; 
00049   nc=columns; 
00050   data = (G4PointRat**) new G4PointRat *[nr*nc];
00051   
00052   for(G4int a =0; a<nr*nc;a++) 
00053     data[a]=new G4PointRat;
00054 }
00055 
00056 
00057 G4ControlPoints::G4ControlPoints( G4int, G4int rows, G4int columns)
00058 {
00059 
00060 //     point_type is maintained only for compatibility 
00061 //     G4ControlPoints is now a array of G4pointRat only
00062 
00063       nr=rows;
00064       nc=columns;
00065       data = (G4PointRat**)new G4PointRat *[nr*nc];
00066 
00067       for(G4int a = 0; a < nr*nc ; a++ )
00068         data[a]=new G4PointRat;
00069 }
00070 
00071 
00072 G4ControlPoints::G4ControlPoints(const G4ControlPoints& old_points)
00073 { 
00074    // copy constructor
00075   
00076   for( G4int i = 0; i < nr*nc; i++)
00077     delete data[i];
00078   delete[] data;
00079 
00080   nr   = old_points.nr;
00081   nc   = old_points.nc;
00082   data = (G4PointRat**)new G4PointRat *[nr*nc];
00083   
00084   G4int a, b;
00085   
00086   for (a = 0; a < nr*nc ; a++ )
00087     data[a] = new G4PointRat;
00088       
00089   for ( a = 0; a < nr ; a++ )
00090     for ( b = 0; b < nc ; b++ )
00091       put( a, b, old_points.GetRat(a,b));
00092 }
00093     
00094 
00095 G4ControlPoints::~G4ControlPoints()
00096 {
00097   for( G4int a = 0; a < nr*nc; a++)
00098     delete data[a];
00099   
00100   delete[] data;
00101 }
00102 
00103 
00104 G4ControlPoints& G4ControlPoints::operator=(const G4ControlPoints& c)
00105 { 
00106    // assignment operator
00107 
00108   if (&c == this) return *this;
00109 
00110   for( G4int i = 0; i < nr*nc; i++)
00111     delete data[i];
00112   delete[] data;
00113 
00114   nr   = c.nr;
00115   nc   = c.nc;
00116   data = (G4PointRat**)new G4PointRat *[nr*nc];
00117   
00118   G4int a, b;
00119   
00120   for (a = 0; a < nr*nc ; a++ )
00121     data[a] = new G4PointRat;
00122       
00123   for ( a = 0; a < nr ; a++ )
00124     for ( b = 0; b < nc ; b++ )
00125       put( a, b, c.GetRat(a,b));
00126 
00127   return *this;
00128 }
00129 
00130 
00131 void G4ControlPoints::SetWeights(G4double* weights)
00132 {
00133   for ( G4int a = 0; a < nr*nc; a++ )
00134     (data[a])->setW(weights[a]);
00135 }
00136 
00137 
00138 void G4ControlPoints::CalcValues ( G4double k1, G4double param, 
00139                                    G4PointRat& pts1, G4double k2, 
00140                                    G4PointRat& pts2               )
00141 {
00142   pts2.setX(Calc(k1,param,pts1.x(),k2,pts2.x()));
00143   pts2.setY(Calc(k1,param,pts1.y(),k2,pts2.y()));
00144   pts2.setZ(Calc(k1,param,pts1.z(),k2,pts2.z()));   
00145   pts2.setW(Calc(k1,param,pts1.w(),k2,pts2.w()));
00146 }
00147  
00148  
00149 void G4ControlPoints::CalcValues(G4double k1, G4double param, G4Point3D& pts1,
00150                                  G4double k2, G4Point3D& pts2)
00151 {               
00152   pts2.setX(Calc(k1,param,pts1.x(),k2,pts2.x()));
00153   pts2.setY(Calc(k1,param,pts1.y(),k2,pts2.y()));
00154   pts2.setZ(Calc(k1,param,pts1.z(),k2,pts2.z()));
00155 }
00156 
00157 
00158 G4double G4ControlPoints::ClosestDistanceToPoint( const G4Point3D& Pt)
00159 {
00160   // Square distance 
00161   
00162   G4double  PointDist=1.e20; 
00163   G4double  TmpDist;
00164   G4Point3D Pt2;
00165   
00166   for(G4int a=0;a<nr;a++)
00167     for(G4int b=0;b<nc;b++)
00168     {
00169       Pt2       = Get3D(a,b);
00170       TmpDist   = Pt.distance2(Pt2);
00171       PointDist = ( PointDist > TmpDist ) ? TmpDist : PointDist;
00172     }
00173   
00174   return PointDist;
00175 }

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