00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4SurfaceBoundary.hh"
00037 #include "geomdefs.hh"
00038 #include "G4CompositeCurve.hh"
00039
00040
00041 G4SurfaceBoundary::G4SurfaceBoundary()
00042 {
00043 }
00044
00045 G4SurfaceBoundary::~G4SurfaceBoundary()
00046 {
00047 }
00048
00049 void G4SurfaceBoundary::Init(const G4CurveVector& bounds0)
00050 {
00051 bounds= bounds0;
00052 lastIntersection.Reset();
00053
00054 const G4BoundingBox3D* b= bounds[0]->BBox();
00055 bBox.Init(b->GetBoxMin(), b->GetBoxMax());
00056
00057 size_t i;
00058 for ( i=1; i<bounds.size(); i++)
00059 {
00060 b= bounds[i]->BBox();
00061 bBox.Extend(b->GetBoxMin());
00062 bBox.Extend(b->GetBoxMax());
00063 }
00064
00065
00066 G4int cnt= 0;
00067
00068 size_t entr = bounds.size();
00069
00070 for (i=0; i < entr; i++)
00071 {
00072 G4Curve* c = bounds[i];
00073
00074 if (c->GetEntityType() == "G4CompositeCurve")
00075 {
00076 G4CompositeCurve* cc = (G4CompositeCurve*)c;
00077 const G4CurveVector& segments = cc->GetSegments();
00078 cnt+= segments.size();
00079 }
00080 else
00081 cnt++;
00082 }
00083
00084 points.resize(cnt);
00085
00086 G4int j= 0;
00087
00088 for (i=0; i<bounds.size(); i++)
00089 {
00090 G4Curve* c= bounds[i];
00091 if (c->GetEntityType() == "G4CompositeCurve")
00092 {
00093 G4CompositeCurve* cc = (G4CompositeCurve*)c;
00094 const G4CurveVector& segments = cc->GetSegments();
00095
00096 for (size_t k=0; k<segments.size(); k++)
00097 {
00098 G4Curve* ccc = segments[k];
00099 G4Point3D p = ccc->GetEnd();
00100 points[j]= p;
00101 j++;
00102 }
00103
00104 }
00105 else
00106 {
00107 G4Point3D p= c->GetEnd();
00108 points[j]= p;
00109 j++;
00110 }
00111 }
00112 }
00113
00114
00115 G4SurfaceBoundary* G4SurfaceBoundary::Project(const G4Transform3D& tr)
00116 {
00117 G4CurveVector newBounds;
00118 G4Curve* a = 0;
00119 G4Curve* c = 0;
00120
00121 for (size_t i=0; i<bounds.size(); i++)
00122 {
00123 c= bounds[i]->Project(tr);
00124
00125 if (c==0)
00126 {
00127
00128 while (newBounds.size()>0)
00129 {
00130 a = newBounds.back();
00131 newBounds.pop_back();
00132 for (G4CurveVector::iterator it=newBounds.begin();
00133 it!=newBounds.end();)
00134 {
00135 if (*it==a)
00136 {
00137 it = newBounds.erase(it);
00138 }
00139 else
00140 {
00141 it--;
00142 }
00143 }
00144 if ( a ) { delete a; }
00145 }
00146 return 0;
00147 }
00148
00149 c->SetSameSense( bounds[i]->GetSameSense() );
00150
00151 newBounds.push_back(c);
00152 }
00153
00154 G4SurfaceBoundary* lof= new G4SurfaceBoundary;
00155 lof->Init(newBounds);
00156 return lof;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 G4int G4SurfaceBoundary::IntersectRay2D(const G4Ray& ray)
00180 {
00181 G4int nbinter = 0;
00182 G4int temp = 0;
00183
00184 for (size_t i=0; i < bounds.size(); i++)
00185 {
00186 G4Curve& c = *bounds[i];
00187 temp = c.IntersectRay2D(ray);
00188
00189
00190 if ( temp == 999 )
00191 nbinter = 1;
00192 else
00193 nbinter += temp;
00194 }
00195
00196 return nbinter;
00197 }
00198
00199
00200 G4bool G4SurfaceBoundary::Tangent(G4CurvePoint&, G4Vector3D& v)
00201 {
00202 if (lastIntersection.GetDistance() == kInfinity)
00203 return false;
00204
00205 return lastIntersection.GetCurve().Tangent(lastIntersection, v);
00206
00207
00208
00209 }
00210
00211
00212 void G4SurfaceBoundary::SplitWithPlane(const G4Point3D&,
00213 const G4Vector3D&,
00214 G4SurfaceBoundary*&,
00215 G4SurfaceBoundary*&)
00216 {
00217 G4Exception("G4SurfaceBoundary::SplitWithPlane()", "GeomSolids0001",
00218 FatalException, "Sorry, not yet implemented.");
00219 }
00220
00221 void G4SurfaceBoundary::SplitWithCylinder(const G4CylindricalSurface&,
00222 G4SurfaceBoundary*&,
00223 G4SurfaceBoundary*&)
00224 {
00225 G4Exception("G4SurfaceBoundary::SplitWithCylinder()", "GeomSolids0001",
00226 FatalException, "Sorry, not yet implemented.");
00227 }