source: trunk/source/geometry/solids/BREPS/src/G4ControlPoints.cc @ 1058

Last change on this file since 1058 was 1058, checked in by garnier, 15 years ago

file release beta

File size: 4.7 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4ControlPoints.cc,v 1.8 2006/06/29 18:42:00 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30// ----------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4ControlPoints.cc
34//
35// ----------------------------------------------------------------------
36
37#include "G4ControlPoints.hh"
38
39
40G4ControlPoints::G4ControlPoints()
41{
42  nr=nc=0;
43  data=(G4PointRat**)0;
44}
45
46
47G4ControlPoints::G4ControlPoints( G4int rows, G4int columns)
48{
49  nr=rows; 
50  nc=columns; 
51  data = (G4PointRat**) new G4PointRat *[nr*nc];
52 
53  for(G4int a =0; a<nr*nc;a++) 
54    data[a]=new G4PointRat;
55}
56
57
58G4ControlPoints::G4ControlPoints( G4int, G4int rows, G4int columns)
59{
60
61//     point_type is maintained only for compatibility
62//     G4ControlPoints is now a array of G4pointRat only
63
64      nr=rows;
65      nc=columns;
66      data = (G4PointRat**)new G4PointRat *[nr*nc];
67
68      for(G4int a = 0; a < nr*nc ; a++ )
69        data[a]=new G4PointRat;
70}
71
72
73G4ControlPoints::G4ControlPoints(const G4ControlPoints& old_points)
74{ 
75   // copy constructor
76 
77  for( G4int i = 0; i < nr*nc; i++)
78    delete data[i];
79  delete[] data;
80
81  nr   = old_points.nr;
82  nc   = old_points.nc;
83  data = (G4PointRat**)new G4PointRat *[nr*nc];
84 
85  G4int a, b;
86 
87  for (a = 0; a < nr*nc ; a++ )
88    data[a] = new G4PointRat;
89     
90  for ( a = 0; a < nr ; a++ )
91    for ( b = 0; b < nc ; b++ )
92      put( a, b, old_points.GetRat(a,b));
93}
94   
95
96G4ControlPoints::~G4ControlPoints()
97{
98  for( G4int a = 0; a < nr*nc; a++)
99    delete data[a];
100 
101  delete[] data;
102}
103
104
105G4ControlPoints& G4ControlPoints::operator=(const G4ControlPoints& c)
106{ 
107   // assignment operator
108
109  if (&c == this) return *this;
110
111  for( G4int i = 0; i < nr*nc; i++)
112    delete data[i];
113  delete[] data;
114
115  nr   = c.nr;
116  nc   = c.nc;
117  data = (G4PointRat**)new G4PointRat *[nr*nc];
118 
119  G4int a, b;
120 
121  for (a = 0; a < nr*nc ; a++ )
122    data[a] = new G4PointRat;
123     
124  for ( a = 0; a < nr ; a++ )
125    for ( b = 0; b < nc ; b++ )
126      put( a, b, c.GetRat(a,b));
127
128  return *this;
129}
130
131
132void G4ControlPoints::SetWeights(G4double* weights)
133{
134  for ( G4int a = 0; a < nr*nc; a++ )
135    (data[a])->setW(weights[a]);
136}
137
138
139void G4ControlPoints::CalcValues ( G4double k1, G4double param, 
140                                   G4PointRat& pts1, G4double k2, 
141                                   G4PointRat& pts2               )
142{
143  pts2.setX(Calc(k1,param,pts1.x(),k2,pts2.x()));
144  pts2.setY(Calc(k1,param,pts1.y(),k2,pts2.y()));
145  pts2.setZ(Calc(k1,param,pts1.z(),k2,pts2.z()));   
146  pts2.setW(Calc(k1,param,pts1.w(),k2,pts2.w()));
147}
148 
149 
150void G4ControlPoints::CalcValues(G4double k1, G4double param, G4Point3D& pts1,
151                                 G4double k2, G4Point3D& pts2)
152{               
153  pts2.setX(Calc(k1,param,pts1.x(),k2,pts2.x()));
154  pts2.setY(Calc(k1,param,pts1.y(),k2,pts2.y()));
155  pts2.setZ(Calc(k1,param,pts1.z(),k2,pts2.z()));
156}
157
158
159G4double G4ControlPoints::ClosestDistanceToPoint( const G4Point3D& Pt)
160{
161  // Square distance
162 
163  G4double  PointDist=1.e20; 
164  G4double  TmpDist;
165  G4Point3D Pt2;
166 
167  for(G4int a=0;a<nr;a++)
168    for(G4int b=0;b<nc;b++)
169    {
170      Pt2       = Get3D(a,b);
171      TmpDist   = Pt.distance2(Pt2);
172      PointDist = ( PointDist > TmpDist ) ? TmpDist : PointDist;
173    }
174 
175  return PointDist;
176}
Note: See TracBrowser for help on using the repository browser.