source: trunk/source/geometry/solids/BREPS/src/G4BSplineCurve.cc@ 1350

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

tag geant4.9.4 beta 1 + modifs locales

File size: 9.1 KB
RevLine 
[831]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: G4BSplineCurve.cc,v 1.12 2006/06/29 18:41:36 gunter Exp $
[1337]28// GEANT4 tag $Name: geant4-09-04-beta-01 $
[831]29//
30// ----------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4BSplineCurve.cc
34//
35// ----------------------------------------------------------------------
36
37#include "G4BSplineCurve.hh"
38#include "G4ControlPoints.hh"
39#include "G4KnotVector.hh"
40
41G4BSplineCurve::G4BSplineCurve()
42 : degree(0), controlPointsList(0), knots(0), weightsData(0)
43{
44}
45
46void G4BSplineCurve::Init(G4int degree0, G4Point3DVector* controlPointsList0,
47 G4doubleVector* knots0,
48 G4doubleVector* weightsData0)
49{
50 degree= degree0;
51
52 G4int nbpoints = controlPointsList0->size();
53 controlPointsList = new G4Point3DVector(nbpoints,G4Point3D(0,0,0));
54
55 G4int a;
56 for(a = 0; a < nbpoints; a++)
57 {
58 (*controlPointsList)[a] = (*controlPointsList0)[a];
59 }
60
61 G4int nbknots = knots0->size();
62 knots = new G4doubleVector(nbknots,0.);
63 for(a = 0; a < nbknots; a++)
64 {
65 (*knots)[a] = (*knots0)[a];
66 }
67
68 G4int nbweights = weightsData0->size();
69 weightsData = new G4doubleVector(nbweights,0.);
70 for(a = 0; a < nbweights; a++)
71 {
72 (*weightsData)[a] = (*weightsData0)[a];
73 }
74
75 SetBounds((*knots)[0], (*knots)[knots->size()-1]);
76}
77
78
79G4BSplineCurve::~G4BSplineCurve()
80{
81 delete [] controlPointsList;
82 delete [] knots;
83 delete [] weightsData;
84}
85
86
87G4BSplineCurve::G4BSplineCurve(const G4BSplineCurve& right)
88 : G4Curve()
89{
90 delete [] controlPointsList;
91 delete [] knots;
92 delete [] weightsData;
93 Init(right.degree, right.controlPointsList,
94 right.knots, right.weightsData);
95 bBox = right.bBox;
96 start = right.start;
97 end = right.end;
98 pStart = right.pStart;
99 pEnd = right.pEnd;
100 pRange = right.pRange;
101 bounded = right.bounded;
102 sameSense = right.sameSense;
103}
104
105G4BSplineCurve& G4BSplineCurve::operator=(const G4BSplineCurve& right)
106{
107 if (&right == this) return *this;
108 delete [] controlPointsList;
109 delete [] knots;
110 delete [] weightsData;
111 Init(right.degree, right.controlPointsList,
112 right.knots, right.weightsData);
113 bBox = right.bBox;
114 start = right.start;
115 end = right.end;
116 pStart = right.pStart;
117 pEnd = right.pEnd;
118 pRange = right.pRange;
119 bounded = right.bounded;
120 sameSense = right.sameSense;
121
122 return *this;
123}
124
125// add by L. Broglia to pass linkage
126
127G4double G4BSplineCurve::GetPMax() const
128{
129 return 0.0;
130}
131
132G4Point3D G4BSplineCurve::GetPoint(G4double) const
133{
134 return G4Point3D(0, 0, 0);
135}
136
137G4double G4BSplineCurve::GetPPoint(const G4Point3D&) const
138{
139 return 0.0;
140}
141
142/*
143#include "G4CurveRayIntersection.hh"
144
145void G4BSplineCurve::IntersectRay2D(const G4Ray& ray,
146 G4CurveRayIntersection& is)
147{
148}
149*/
150
151G4int G4BSplineCurve::IntersectRay2D(const G4Ray&)
152{
153 // L. Broglia
154 G4cout<<"\nWarning ! G4BSplineCurve::IntersectRay2D is empty.";
155 return 0;
156}
157
158/*
159void G4BSplineCurve::CalcCurvePlaneNormal()
160{
161 //Calc Normal for surface which is used for the projection
162 G4ThreeVec norm;
163 G4Point3d Pt1 = ControlPointList->get(0,0);
164 G4Point3d Pt2 = ControlPointList->get(0,1);
165 G4Point3d Pt3 = ControlPointList->get(0,2);
166 G4Point3d a(Pt2.X()-Pt1.X(), Pt2.Y()-Pt1.Y(), Pt2.Z()-Pt1.Z());
167 G4Point3d b(Pt3.X()-Pt1.X(), Pt3.Y()-Pt1.Y(), Pt3.Z()-Pt1.Z());
168 norm.X((a.Y()*b.Z() - a.Z()*b.Y()));
169 norm.Y((a.X()*b.Z() - a.Z()*b.X()));
170 norm.Z((a.X()*b.Y() - a.Y()*b.X()));
171
172}
173*/
174
175
176G4Curve* G4BSplineCurve::Project(const G4Transform3D& tr)
177{
178 // just transform + project all control points
179 // what about self intersections?
180
181 G4int n = controlPointsList->size();
182 G4Point3DVector* newControlPointsList = new G4Point3DVector(n);
183
184 for (G4int i=0; i<n; i++)
185 {
186 G4Point3D& p= (*newControlPointsList)[i];
187 p= tr*(*controlPointsList)[i];
188 p.setZ(0);
189 }
190
191 G4doubleVector* newKnots= new G4doubleVector(*knots);
192 G4doubleVector* newWeightsData=
193 weightsData ? new G4doubleVector(*weightsData) : 0;
194
195 G4BSplineCurve* r= new G4BSplineCurve;
196 r->Init(degree, newControlPointsList, newKnots, newWeightsData);
197
198 if (IsBounded())
199 {
200 r->SetBounds(GetPStart(), GetPEnd());
201 }
202 return r;
203}
204
205
206/*
207void G4BSplineCurve::ProjectCurve(const G4Plane& Pl1, const G4Plane& Pl2)
208{
209 int rows = ControlPointList->GetRows();
210 int cols = ControlPointList->GetCols();
211 int NumberOfPoints = cols * rows;
212 ProjectedControlPoints = new G4Point2d*[NumberOfPoints];
213 // Loop through points and do projection
214 for(int a = 0; a<NumberOfPoints;a++)
215 {
216 // Create 2d-point
217 ProjectedControlPoints[a] = new G4Point2d;
218 // Project 3d points into 2d
219 Project((*ProjectedControlPoints[a]), ControlPointList->get(0,a), Pl1, Pl2);
220 }
221}
222
223
224int G4BSplineCurve::Inside( const G4Point3d& Hit, const G4Ray& rayref)
225{
226 const G4Plane& Pl1 = rayref.GetPlane(0);
227 const G4Plane& Pl2 = rayref.GetPlane(1);
228 register G4double DistA1, DistA2, DistB1, DistB2;
229 // Calc distance from Start point to ray planes
230 DistA1 = Start.PlaneDistance(Pl1);
231 // Calc distance from End point to ray planes
232 DistB1 = End.PlaneDistance(Pl1);
233 if((DistA1<0 && DistB1>0)||(DistA1>0 && DistB1 <0))
234 {
235 DistA2 = Start.PlaneDistance(Pl2);
236 DistB2 = End.PlaneDistance(Pl2);
237 // This checks the line Start-End of the convex hull
238 if(DistA2<0&&DistB2<0)
239 return 1;
240 }
241 // Test for the other lines of the convex hull
242 // If one of them is on a different side than the
243 // previously checked line, the curve has to be evaluated
244 // against the G4Plane.
245 int Points = ControlPointList->GetCols();
246
247 G4Point *CPoint1, *CPoint2;
248
249 register G4double CDistA1,CDistA2, CDistB1, CDistB2;
250 int Flag=0;
251 for(int a=0;a<Points-1;a++)
252 {
253 CPoint1 = &ControlPointList->get(0,a);
254 CPoint2 = &ControlPointList->get(0,a+1);
255 CDistA1 = CPoint1->PlaneDistance(Pl1);
256 CDistB1 = CPoint2->PlaneDistance(Pl1);
257 if((CDistA1<0 && CDistB1>0)||(CDistA1>0 && CDistB1<0))
258 {
259 CDistA2 = CPoint1->PlaneDistance(Pl2);
260 CDistB2 = CPoint2->PlaneDistance(Pl2);
261 if (!(CDistA2<0&&CDistB2<0))
262 {
263 Flag=1;
264 break;
265 }
266 }
267 }
268
269
270 if(!Flag)
271 return 1;
272 else
273 {
274 // Evaluate curve & Pl1 intersection, Calc the intersections distance
275 // from Pl2 to check which side it lies on.
276 G4Point3d IntPoint;
277 // G4cout << "\nG4B_SplineCurve.cc:Inside - Evaluation not yet implemented!!!\n";
278 // IntPoint = ...
279 G4double IntDist = IntPoint.PlaneDistance(Pl2);
280 if(IntDist<0)
281 return 1;
282 }
283 return 0;
284
285}
286*/
287
288
289void G4BSplineCurve::InitBounded()
290{
291 // just like in the old functions
292 G4int pointCount = controlPointsList->size();
293 bBox.Init( (*controlPointsList)[0] );
294 for (G4int i=1; i<pointCount; i++)
295 {
296 bBox.Extend( (*controlPointsList)[i] );
297 }
298}
299
300
301/*
302G4Point3d G4BSplineCurve::GetBoundMin()
303{
304 G4Point3d Min = PINFINITY;
305 int PointCount = ControlPointList->GetCols();
306 G4Point3d Tmp;
307 for(int a=0;a<PointCount;a++)
308 {
309 Tmp = ControlPointList->get(0,a);
310 Min > Tmp;
311 }
312 return Min;
313}
314
315G4Point3d G4BSplineCurve::GetBoundMax()
316{
317 G4Point3d Max = -PINFINITY;
318 G4Point3d Tmp;
319 int PointCount = ControlPointList->GetCols();
320 for(int a=0;a<PointCount;a++)
321 {
322 Tmp = ControlPointList->get(0,a);
323 Max > Tmp;
324 }
325 return Max;
326}
327*/
328
329
330G4bool G4BSplineCurve::Tangent(G4CurvePoint&, G4Vector3D&)
331{
332 G4Exception("G4BSplineCurve::Tangent()", "NotImplemented",
333 FatalException, "Sorry, not implemented !");
334 return false;
335}
336
Note: See TracBrowser for help on using the repository browser.