source: trunk/source/geometry/solids/BREPS/src/G4CompositeCurve.cc @ 1202

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

file release beta

File size: 5.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: G4CompositeCurve.cc,v 1.13 2006/06/29 18:41:54 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30// ----------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4CircularCurve.cc
34//
35// ----------------------------------------------------------------------
36
37#include "G4CompositeCurve.hh"
38#include "G4Line.hh"
39
40
41G4CompositeCurve::G4CompositeCurve(){}
42
43G4CompositeCurve::G4CompositeCurve(const G4Point3DVector& vertices)
44{
45  G4CurveVector cv;
46  for (size_t i=0; i<vertices.size(); i++) 
47  {
48    G4Point3D p1= vertices[i];
49    G4Point3D p2= vertices[(i+1) % vertices.size()];
50   
51    G4Line* l= new G4Line;
52    l->Init(p1, p2-p1);
53    l->SetBounds(p1, p2);
54    cv.push_back(l);
55  }
56 
57  Init(cv);
58}
59
60G4CompositeCurve::~G4CompositeCurve()
61{
62  // Remove segments and delete all its contents
63  G4Curve* a = 0;
64  while (segments.size()>0)
65  {
66    a = segments.back();
67    segments.pop_back();
68    for (G4CurveVector::iterator i=segments.begin(); i!=segments.end(); i++)
69    {
70      if (*i==a)
71      {
72        segments.erase(i);
73        i--;
74      }
75    } 
76    if ( a )  delete a;   
77  } 
78}
79
80G4String G4CompositeCurve::GetEntityType() const 
81{
82  return G4String("G4CompositeCurve");
83}
84
85G4Curve* G4CompositeCurve::Project(const G4Transform3D& tr)
86{
87  G4CurveVector newSegments;
88  G4Curve* a = 0;
89  G4Curve* c = 0;
90 
91  for (size_t i=0; i<segments.size(); i++) 
92  {
93    c = segments[i]->Project(tr);
94    if (c==0) 
95    {
96      // Remove newSegments and delete all its contents
97      while (newSegments.size()>0)
98      {
99        a = newSegments.back();
100        newSegments.pop_back();
101        for (G4CurveVector::iterator i=newSegments.begin();
102                                     i!=newSegments.end(); i++)
103        {
104          if (*i==a)
105          {
106            newSegments.erase(i);
107            i--;
108          }
109        } 
110        if ( a )  delete a;   
111      } 
112      return 0;
113    }
114
115    newSegments.push_back(c);
116  }
117 
118  G4CompositeCurve* r= new G4CompositeCurve;
119  r->Init(newSegments);
120  return r;
121}
122
123/////////////////////////////////////////////////////////////////////////////
124
125G4double G4CompositeCurve::GetPMax() const
126{
127  G4Exception("G4CompositeCurve::GetPMax()", "NotApplicable",
128              FatalException, "Not applicable to base class.");
129  return 0;
130}
131
132G4Point3D G4CompositeCurve::GetPoint(G4double) const
133{
134  G4Exception("G4CompositeCurve::GetPoint()", "NotApplicable",
135              FatalException, "Not applicable to base class.");
136  // Fake return value
137  return G4Point3D();
138}
139
140G4double G4CompositeCurve::GetPPoint(const G4Point3D&) const
141{
142  G4Exception("G4CompositeCurve::GetPPoint()", "NotApplicable",
143              FatalException, "Not applicable to base class.");
144  return 0;
145}
146
147////////////////////////////////////////////////////////////////////////////
148
149/*
150void G4CompositeCurve::IntersectRay2D(const G4Ray& ray,
151                                      G4CurveRayIntersection& is)
152{
153  is.Reset();
154 
155  for (G4int i=0; i<segments.entries(); i++)
156  {
157    G4Curve& c= *(segments(i));
158    G4CurveRayIntersection isTmp(c, ray);
159    c.IntersectRay2D(ray, isTmp);
160    if (isTmp.GetDistance() < is.GetDistance())
161      is= isTmp; 
162  }
163 
164  lastIntersection= is;
165}
166*/
167
168G4int G4CompositeCurve::IntersectRay2D(const G4Ray& ray)
169{
170  G4int nbinter = 0;
171  G4int temp = 0;
172 
173  for (size_t i=0; i<segments.size(); i++) 
174  {
175    G4Curve& c= *(segments[i]);
176    temp = c.IntersectRay2D(ray);
177
178    // test if the point is on the composite curve
179    if( temp == 999 )
180       return 999;
181     else
182       nbinter+= temp; 
183  }
184 
185  return nbinter;
186}
187
188G4bool G4CompositeCurve::Tangent(G4CurvePoint&, G4Vector3D& v)
189{
190  if (lastIntersection.GetDistance() == kInfinity) 
191    return false;
192 
193  return lastIntersection.GetCurve().Tangent(lastIntersection, v);
194  // should be true
195  // cp is ignored for the moment
196}
197
198
199void G4CompositeCurve::InitBounded()
200{
201  const G4BoundingBox3D* b= segments[0]->BBox();
202  bBox.Init(b->GetBoxMin(), b->GetBoxMax());
203 
204  for (size_t i=1; i<segments.size(); i++) 
205  {
206    b= segments[i]->BBox();
207    bBox.Extend(b->GetBoxMin());
208    bBox.Extend(b->GetBoxMax());
209  }
210 
211  // init for efficient parameter <-> 3D point conversions
212}
Note: See TracBrowser for help on using the repository browser.