G4TessellatedSolid Class Reference

#include <G4TessellatedSolid.hh>

Inheritance diagram for G4TessellatedSolid:

G4VSolid G4ExtrudedSolid

Public Member Functions

 G4TessellatedSolid ()
virtual ~G4TessellatedSolid ()
 G4TessellatedSolid (const G4String &name)
 G4TessellatedSolid (__void__ &)
 G4TessellatedSolid (const G4TessellatedSolid &ts)
G4TessellatedSolid & operator= (const G4TessellatedSolid &right)
G4TessellatedSolid & operator+= (const G4TessellatedSolid &right)
G4bool AddFacet (G4VFacet *aFacet)
G4VFacet * GetFacet (G4int i) const
G4int GetNumberOfFacets () const
virtual EInside Inside (const G4ThreeVector &p) const
virtual G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
virtual G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
virtual G4double DistanceToIn (const G4ThreeVector &p) const
virtual G4double DistanceToOut (const G4ThreeVector &p) const
virtual G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm, G4bool *validNorm, G4ThreeVector *norm) const
virtual G4bool Normal (const G4ThreeVector &p, G4ThreeVector &n) const
virtual G4double SafetyFromOutside (const G4ThreeVector &p, G4bool aAccurate=false) const
virtual G4double SafetyFromInside (const G4ThreeVector &p, G4bool aAccurate=false) const
virtual G4GeometryType GetEntityType () const
virtual std::ostream & StreamInfo (std::ostream &os) const
virtual G4VSolid * Clone () const
virtual G4ThreeVector GetPointOnSurface () const
virtual G4double GetSurfaceArea ()
virtual G4double GetCubicVolume ()
void SetSolidClosed (const G4bool t)
G4bool GetSolidClosed () const
void SetMaxVoxels (G4int max)
G4SurfaceVoxelizer & GetVoxels ()
virtual G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
G4double GetMinXExtent () const
G4double GetMaxXExtent () const
G4double GetMinYExtent () const
G4double GetMaxYExtent () const
G4double GetMinZExtent () const
G4double GetMaxZExtent () const
G4ThreeVectorList * CreateRotatedVertices (const G4AffineTransform &pT) const
virtual G4Polyhedron * CreatePolyhedron () const
virtual G4Polyhedron * GetPolyhedron () const
virtual G4NURBS * CreateNURBS () const
virtual void DescribeYourselfTo (G4VGraphicsScene &scene) const
virtual G4VisExtent GetExtent () const
G4int AllocatedMemoryWithoutVoxels ()
G4int AllocatedMemory ()
void DisplayAllocatedMemory ()

Detailed Description

Definition at line 128 of file G4TessellatedSolid.hh.


Constructor & Destructor Documentation

G4TessellatedSolid::G4TessellatedSolid (  ) 

Definition at line 101 of file G4TessellatedSolid.cc.

Referenced by Clone().

00101                                         : G4VSolid("dummy")
00102 {
00103   Initialize();
00104 }

G4TessellatedSolid::~G4TessellatedSolid (  )  [virtual]

Definition at line 131 of file G4TessellatedSolid.cc.

00132 {
00133   DeleteObjects ();
00134 }

G4TessellatedSolid::G4TessellatedSolid ( const G4String &  name  ) 

Definition at line 111 of file G4TessellatedSolid.cc.

00112   : G4VSolid(name)
00113 {
00114   Initialize();
00115 }

G4TessellatedSolid::G4TessellatedSolid ( __void__ &   ) 

Definition at line 122 of file G4TessellatedSolid.cc.

00122                                                    : G4VSolid(a)
00123 {
00124   Initialize();
00125   fMinExtent.set(0,0,0);
00126   fMaxExtent.set(0,0,0);
00127 }

G4TessellatedSolid::G4TessellatedSolid ( const G4TessellatedSolid &  ts  ) 

Definition at line 140 of file G4TessellatedSolid.cc.

00141   : G4VSolid(ts), fpPolyhedron(0)
00142 {
00143   Initialize();
00144 
00145   CopyObjects(ts);
00146 }


Member Function Documentation

G4bool G4TessellatedSolid::AddFacet ( G4VFacet *  aFacet  ) 

Definition at line 220 of file G4TessellatedSolid.cc.

References G4cout, G4Exception(), G4VFacet::GetCircumcentre(), G4VertexInfo::id, G4VFacet::IsDefined(), JustWarning, G4VSolid::kCarTolerance, G4VertexInfo::mag2, and G4VFacet::StreamInfo().

Referenced by G4tgbVolume::FindOrConstructG4Solid(), operator+=(), and G4GDMLReadSolids::TessellatedRead().

00221 {
00222   // Add the facet to the vector.
00223   //
00224   if (fSolidClosed)
00225   {
00226     G4Exception("G4TessellatedSolid::AddFacet()", "GeomSolids1002",
00227                 JustWarning, "Attempt to add facets when solid is closed.");
00228     return false;
00229   }
00230   else if (aFacet->IsDefined())
00231   {
00232     set<G4VertexInfo,G4VertexComparator>::iterator begin
00233       = fFacetList.begin(), end = fFacetList.end(), pos, it;
00234     G4ThreeVector p = aFacet->GetCircumcentre();
00235     G4VertexInfo value;
00236     value.id = fFacetList.size();
00237     value.mag2 = p.x() + p.y() + p.z();
00238 
00239     G4bool found = false;
00240     if (!OutsideOfExtent(p, kCarTolerance))
00241     {
00242       G4double kCarTolerance3 = 3 * kCarTolerance;
00243       pos = fFacetList.lower_bound(value);
00244 
00245       it = pos;
00246       while (!found && it != end)
00247       {
00248         G4int id = (*it).id;
00249         G4VFacet *facet = fFacets[id];
00250         G4ThreeVector q = facet->GetCircumcentre();
00251         if ((found = (facet == aFacet))) break;
00252         G4double dif = q.x() + q.y() + q.z() - value.mag2;
00253         if (dif > kCarTolerance3) break;
00254         it++;
00255       }
00256 
00257       if (fFacets.size() > 1)
00258       {
00259         it = pos;
00260         while (!found && it != begin)
00261         {
00262           --it;
00263           G4int id = (*it).id;
00264           G4VFacet *facet = fFacets[id];          
00265           G4ThreeVector q = facet->GetCircumcentre();
00266           found = (facet == aFacet);
00267           if (found) break;
00268           G4double dif = value.mag2 - (q.x() + q.y() + q.z());
00269           if (dif > kCarTolerance3) break;
00270         }
00271       }
00272     }
00273 
00274     if (!found)
00275     {
00276       fFacets.push_back(aFacet);
00277       fFacetList.insert(value);
00278     }
00279 
00280     return true;
00281   }
00282   else
00283   {
00284     G4Exception("G4TessellatedSolid::AddFacet()", "GeomSolids1002",
00285                 JustWarning, "Attempt to add facet not properly defined.");    
00286     aFacet->StreamInfo(G4cout);
00287     return false;
00288   }
00289 }

G4int G4TessellatedSolid::AllocatedMemory (  ) 

Definition at line 2018 of file G4TessellatedSolid.cc.

References G4SurfaceVoxelizer::AllocatedMemory(), AllocatedMemoryWithoutVoxels(), and G4SurfBits::GetNbytes().

Referenced by DisplayAllocatedMemory().

02019 {
02020   G4int size = AllocatedMemoryWithoutVoxels();
02021   G4int sizeInsides = fInsides.GetNbytes();
02022   G4int sizeVoxels = fVoxels.AllocatedMemory();
02023   size += sizeInsides + sizeVoxels;
02024   return size;
02025 }

G4int G4TessellatedSolid::AllocatedMemoryWithoutVoxels (  ) 

Definition at line 1992 of file G4TessellatedSolid.cc.

References G4VFacet::AllocatedMemory().

Referenced by AllocatedMemory(), and DisplayAllocatedMemory().

01993 {
01994   G4int base = sizeof(*this);
01995   base += fVertexList.capacity() * sizeof(G4ThreeVector);
01996   base += fRandir.capacity() * sizeof(G4ThreeVector);
01997 
01998   G4int limit = fFacets.size();
01999   for (G4int i = 0; i < limit; i++)
02000   {
02001     G4VFacet &facet = *fFacets[i];
02002     base += facet.AllocatedMemory();
02003   }
02004 
02005   std::set<G4VFacet *>::const_iterator beg, end, it;
02006   beg = fExtremeFacets.begin();
02007   end = fExtremeFacets.end();
02008   for (it = beg; it != end; it++)
02009   {
02010     G4VFacet &facet = *(*it);
02011     base += facet.AllocatedMemory();
02012   }
02013   return base;
02014 }

G4bool G4TessellatedSolid::CalculateExtent ( const EAxis  pAxis,
const G4VoxelLimits &  pVoxelLimit,
const G4AffineTransform &  pTransform,
G4double &  pMin,
G4double &  pMax 
) const [virtual]

Implements G4VSolid.

Definition at line 1769 of file G4TessellatedSolid.cc.

References G4AffineTransform::ApplyPointTransform(), G4VoxelLimits::GetMaxExtent(), G4VoxelLimits::GetMinExtent(), G4VoxelLimits::IsLimited(), G4VSolid::kCarTolerance, kXAxis, kYAxis, and kZAxis.

Referenced by G4GenericTrap::CalculateExtent().

01773 {
01774   G4ThreeVectorList transVertexList(fVertexList);
01775   G4int size = fVertexList.size();
01776 
01777   // Put solid into transformed frame
01778   for (G4int i=0; i < size; ++i)
01779   {
01780     pTransform.ApplyPointTransform(transVertexList[i]);
01781   }
01782 
01783   // Find min and max extent in each dimension
01784   G4ThreeVector minExtent(kInfinity, kInfinity, kInfinity);
01785   G4ThreeVector maxExtent(-kInfinity, -kInfinity, -kInfinity);
01786 
01787   size = transVertexList.size();
01788   for (G4int i=0; i< size; ++i)
01789   {
01790     for (G4int axis=G4ThreeVector::X; axis < G4ThreeVector::SIZE; ++axis)
01791     {
01792       G4double coordinate = transVertexList[i][axis];
01793       if (coordinate < minExtent[axis])
01794       { minExtent[axis] = coordinate; }
01795       if (coordinate > maxExtent[axis])
01796       { maxExtent[axis] = coordinate; }
01797     }
01798   }
01799 
01800   // Check for containment and clamp to voxel boundaries
01801   for (G4int axis=G4ThreeVector::X; axis < G4ThreeVector::SIZE; ++axis)
01802   {
01803     EAxis geomAxis = kXAxis; // U geom classes use different index type
01804     switch(axis)
01805     {
01806     case G4ThreeVector::X: geomAxis = kXAxis; break;
01807     case G4ThreeVector::Y: geomAxis = kYAxis; break;
01808     case G4ThreeVector::Z: geomAxis = kZAxis; break;
01809     }
01810     G4bool isLimited = pVoxelLimit.IsLimited(geomAxis);
01811     G4double voxelMinExtent = pVoxelLimit.GetMinExtent(geomAxis);
01812     G4double voxelMaxExtent = pVoxelLimit.GetMaxExtent(geomAxis);
01813 
01814     if (isLimited)
01815     {
01816       if ( minExtent[axis] > voxelMaxExtent+kCarTolerance ||
01817         maxExtent[axis] < voxelMinExtent-kCarTolerance    )
01818       {
01819         return false ;
01820       }
01821       else
01822       {
01823         if (minExtent[axis] < voxelMinExtent)
01824         {
01825           minExtent[axis] = voxelMinExtent ;
01826         }
01827         if (maxExtent[axis] > voxelMaxExtent)
01828         {
01829           maxExtent[axis] = voxelMaxExtent;
01830         }
01831       }
01832     }
01833   }
01834 
01835   // Convert pAxis into G4ThreeVector index
01836   G4int vecAxis=0;
01837   switch(pAxis)
01838   {
01839   case kXAxis: vecAxis = G4ThreeVector::X; break;
01840   case kYAxis: vecAxis = G4ThreeVector::Y; break;
01841   case kZAxis: vecAxis = G4ThreeVector::Z; break;
01842   default: break;
01843   } 
01844 
01845   pMin = minExtent[vecAxis] - kCarTolerance;
01846   pMax = maxExtent[vecAxis] + kCarTolerance;
01847 
01848   return true;
01849 }

G4VSolid * G4TessellatedSolid::Clone (  )  const [virtual]

Reimplemented from G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1591 of file G4TessellatedSolid.cc.

References G4TessellatedSolid().

01592 {
01593   return new G4TessellatedSolid(*this);
01594 }

G4NURBS * G4TessellatedSolid::CreateNURBS (  )  const [virtual]

Reimplemented from G4VSolid.

Definition at line 1741 of file G4TessellatedSolid.cc.

Referenced by G4GenericTrap::CreateNURBS().

01742 {
01743   return 0;
01744 }

G4Polyhedron * G4TessellatedSolid::CreatePolyhedron (  )  const [virtual]

Reimplemented from G4VSolid.

Definition at line 1707 of file G4TessellatedSolid.cc.

References G4PolyhedronArbitrary::AddFacet(), G4PolyhedronArbitrary::AddVertex(), G4VFacet::GetNumberOfVertices(), G4VFacet::GetVertexIndex(), and G4PolyhedronArbitrary::SetReferences().

Referenced by G4GenericTrap::CreatePolyhedron(), and GetPolyhedron().

01708 {
01709   G4int nVertices = fVertexList.size();
01710   G4int nFacets   = fFacets.size();
01711   G4PolyhedronArbitrary *polyhedron =
01712     new G4PolyhedronArbitrary (nVertices, nFacets);
01713   for (G4ThreeVectorList::const_iterator v= fVertexList.begin();
01714                                          v!=fVertexList.end(); ++v)
01715   {
01716     polyhedron->AddVertex(*v);
01717   }
01718 
01719   G4int size = fFacets.size();
01720   for (G4int i = 0; i < size; ++i)
01721   {
01722     G4VFacet &facet = *fFacets[i];
01723     G4int v[4];
01724     G4int n = facet.GetNumberOfVertices();
01725     if (n > 4) n = 4;
01726     else if (n == 3) v[3] = 0;
01727     for (G4int j=0; j<n; ++j)
01728     {
01729       G4int k = facet.GetVertexIndex(j);
01730       v[j] = k+1;
01731     }
01732     polyhedron->AddFacet(v[0],v[1],v[2],v[3]);
01733   }
01734   polyhedron->SetReferences();  
01735 
01736   return (G4Polyhedron*) polyhedron;
01737 }

G4ThreeVectorList* G4TessellatedSolid::CreateRotatedVertices ( const G4AffineTransform &  pT  )  const

void G4TessellatedSolid::DescribeYourselfTo ( G4VGraphicsScene &  scene  )  const [virtual]

Implements G4VSolid.

Definition at line 1700 of file G4TessellatedSolid.cc.

References G4VGraphicsScene::AddSolid().

Referenced by G4GenericTrap::DescribeYourselfTo().

01701 {
01702   scene.AddSolid (*this);
01703 }

void G4TessellatedSolid::DisplayAllocatedMemory (  ) 

Definition at line 567 of file G4TessellatedSolid.cc.

References AllocatedMemory(), AllocatedMemoryWithoutVoxels(), and G4cout.

Referenced by SetSolidClosed().

00568 {
00569   G4int without = AllocatedMemoryWithoutVoxels();
00570   G4int with = AllocatedMemory();
00571   G4double ratio = (G4double) with / without;
00572   G4cout << "G4TessellatedSolid - Allocated memory without voxel overhead "
00573          << without << "; with " << with << "; ratio: " << ratio << G4endl;      
00574 }

G4double G4TessellatedSolid::DistanceToIn ( const G4ThreeVector &  p  )  const [virtual]

Implements G4VSolid.

Definition at line 1637 of file G4TessellatedSolid.cc.

References SafetyFromOutside().

01638 {
01639   return SafetyFromOutside(p,false);
01640 }

G4double G4TessellatedSolid::DistanceToIn ( const G4ThreeVector &  p,
const G4ThreeVector &  v 
) const [virtual]

Implements G4VSolid.

Definition at line 1644 of file G4TessellatedSolid.cc.

Referenced by G4GenericTrap::DistanceToIn(), and SafetyFromInside().

01646 {
01647   return DistanceToInCore(p,v,kInfinity);
01648 }

G4double G4TessellatedSolid::DistanceToOut ( const G4ThreeVector &  p,
const G4ThreeVector &  v,
const G4bool  calcNorm,
G4bool *  validNorm,
G4ThreeVector *  norm 
) const [virtual]

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1680 of file G4TessellatedSolid.cc.

01685 {
01686   G4ThreeVector n;
01687   G4bool valid;
01688 
01689   G4double dist = DistanceToOutCore(p, v, n, valid);
01690   if (calcNorm)
01691   {
01692     *norm = n;
01693     *validNorm = valid;
01694   }
01695   return dist;
01696 }

G4double G4TessellatedSolid::DistanceToOut ( const G4ThreeVector &  p  )  const [virtual]

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1657 of file G4TessellatedSolid.cc.

References SafetyFromInside().

Referenced by G4GenericTrap::DistanceToOut(), G4ExtrudedSolid::DistanceToOut(), and SafetyFromOutside().

01658 {
01659   return SafetyFromInside(p,false);
01660 }

G4double G4TessellatedSolid::GetCubicVolume (  )  [virtual]

Reimplemented from G4VSolid.

Definition at line 1902 of file G4TessellatedSolid.cc.

References G4VSolid::GetCubicVolume().

01903 {
01904   if(fCubicVolume != 0.) {;}
01905   else   { fCubicVolume = G4VSolid::GetCubicVolume(); }
01906   return fCubicVolume;
01907 }

G4GeometryType G4TessellatedSolid::GetEntityType (  )  const [virtual]

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1562 of file G4TessellatedSolid.cc.

01563 {
01564   return fGeometryType;
01565 }

G4VisExtent G4TessellatedSolid::GetExtent (  )  const [virtual]

Reimplemented from G4VSolid.

Definition at line 1895 of file G4TessellatedSolid.cc.

Referenced by G4GenericTrap::GetExtent().

01896 {
01897   return G4VisExtent (fMinExtent.x(), fMaxExtent.x(), fMinExtent.y(), fMaxExtent.y(), fMinExtent.z(), fMaxExtent.z());
01898 }

G4VFacet * G4TessellatedSolid::GetFacet ( G4int  i  )  const [inline]

Definition at line 303 of file G4TessellatedSolid.hh.

Referenced by operator+=(), and G4GDMLWriteSolids::TessellatedWrite().

00304 {
00305   return fFacets[i];
00306 }

G4double G4TessellatedSolid::GetMaxXExtent (  )  const

Definition at line 1860 of file G4TessellatedSolid.cc.

Referenced by G4ExtrudedSolid::Inside().

01861 {
01862   return fMaxExtent.x();
01863 }

G4double G4TessellatedSolid::GetMaxYExtent (  )  const

Definition at line 1874 of file G4TessellatedSolid.cc.

Referenced by G4ExtrudedSolid::Inside().

01875 {
01876   return fMaxExtent.y();
01877 }

G4double G4TessellatedSolid::GetMaxZExtent (  )  const

Definition at line 1888 of file G4TessellatedSolid.cc.

Referenced by G4ExtrudedSolid::Inside().

01889 {
01890   return fMaxExtent.z();
01891 }

G4double G4TessellatedSolid::GetMinXExtent (  )  const

Definition at line 1853 of file G4TessellatedSolid.cc.

Referenced by G4ExtrudedSolid::Inside().

01854 {
01855   return fMinExtent.x();
01856 }

G4double G4TessellatedSolid::GetMinYExtent (  )  const

Definition at line 1867 of file G4TessellatedSolid.cc.

Referenced by G4ExtrudedSolid::Inside().

01868 {
01869   return fMinExtent.y();
01870 }

G4double G4TessellatedSolid::GetMinZExtent (  )  const

Definition at line 1881 of file G4TessellatedSolid.cc.

Referenced by G4ExtrudedSolid::Inside().

01882 {
01883   return fMinExtent.z();
01884 }

G4int G4TessellatedSolid::GetNumberOfFacets (  )  const

Definition at line 639 of file G4TessellatedSolid.cc.

Referenced by operator+=(), and G4GDMLWriteSolids::TessellatedWrite().

00640 {
00641   return fFacets.size();
00642 }

G4ThreeVector G4TessellatedSolid::GetPointOnSurface (  )  const [virtual]

Reimplemented from G4VSolid.

Definition at line 1926 of file G4TessellatedSolid.cc.

Referenced by G4GenericTrap::GetPointOnSurface().

01927 {
01928   // Select randomly a facet and return a random point on it
01929 
01930   G4int i = (G4int) G4RandFlat::shoot(0., fFacets.size());
01931   return fFacets[i]->GetPointOnFace();
01932 }

G4Polyhedron * G4TessellatedSolid::GetPolyhedron (  )  const [virtual]

Reimplemented from G4VSolid.

Definition at line 1750 of file G4TessellatedSolid.cc.

References CreatePolyhedron(), and G4Polyhedron::GetNumberOfRotationStepsAtTimeOfCreation().

Referenced by G4GenericTrap::GetPolyhedron().

01751 {
01752   if (!fpPolyhedron ||
01753     fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
01754     fpPolyhedron->GetNumberOfRotationSteps())
01755   {
01756     delete fpPolyhedron;
01757     fpPolyhedron = CreatePolyhedron();
01758   }
01759   return fpPolyhedron;
01760 }

G4bool G4TessellatedSolid::GetSolidClosed (  )  const

Definition at line 611 of file G4TessellatedSolid.cc.

00612 {
00613   return fSolidClosed;
00614 }

G4double G4TessellatedSolid::GetSurfaceArea (  )  [virtual]

Reimplemented from G4VSolid.

Definition at line 1911 of file G4TessellatedSolid.cc.

References G4VFacet::GetArea().

01912 {
01913   if (fSurfaceArea != 0.) return fSurfaceArea;
01914 
01915   G4int size = fFacets.size();
01916   for (G4int i = 0; i < size; ++i)
01917   {
01918     G4VFacet &facet = *fFacets[i];
01919     fSurfaceArea += facet.GetArea();
01920   }
01921   return fSurfaceArea;
01922 }

G4SurfaceVoxelizer & G4TessellatedSolid::GetVoxels (  )  [inline]

Definition at line 313 of file G4TessellatedSolid.hh.

00314 {
00315   return fVoxels;
00316 }

EInside G4TessellatedSolid::Inside ( const G4ThreeVector &  p  )  const [virtual]

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1606 of file G4TessellatedSolid.cc.

References G4SurfaceVoxelizer::GetCountOfVoxels().

Referenced by G4GenericTrap::Inside(), SafetyFromInside(), and SafetyFromOutside().

01607 {
01608   EInside location;
01609 
01610   if (fVoxels.GetCountOfVoxels() > 1)
01611   {
01612     location = InsideVoxels(aPoint);
01613   }
01614   else
01615   {
01616     location = InsideNoVoxels(aPoint);
01617   }
01618   return location;
01619 }

G4bool G4TessellatedSolid::Normal ( const G4ThreeVector &  p,
G4ThreeVector &  n 
) const [virtual]

Definition at line 983 of file G4TessellatedSolid.cc.

References G4VFacet::Distance(), G4Exception(), G4SurfaceVoxelizer::GetCandidates(), G4SurfaceVoxelizer::GetCountOfVoxels(), G4VFacet::GetSurfaceNormal(), G4SurfaceVoxelizer::GetVoxel(), and JustWarning.

Referenced by SurfaceNormal().

00985 {
00986   G4double minDist;
00987   G4VFacet *facet = 0;
00988 
00989   if (fVoxels.GetCountOfVoxels() > 1)
00990   {
00991     vector<G4int> curVoxel(3);
00992     fVoxels.GetVoxel(curVoxel, p);
00993     const vector<G4int> &candidates = fVoxels.GetCandidates(curVoxel);
00994     // fVoxels.GetCandidatesVoxelArray(p, candidates, 0);
00995 
00996     if (G4int limit = candidates.size())
00997     {
00998       minDist = kInfinity;
00999       for(G4int i = 0 ; i < limit ; ++i)
01000       {      
01001         G4int candidate = candidates[i];
01002         G4VFacet &fct = *fFacets[candidate];
01003         G4double dist = fct.Distance(p,minDist);
01004         if (dist < minDist) minDist = dist;
01005         if (dist <= kCarToleranceHalf)
01006         {
01007           aNormal = fct.GetSurfaceNormal();
01008           return true;
01009         }
01010       }
01011     }
01012     minDist = MinDistanceFacet(p, true, facet);
01013   }
01014   else
01015   {
01016     minDist = kInfinity;
01017     G4int size = fFacets.size();
01018     for (G4int i = 0; i < size; ++i)
01019     {
01020       G4VFacet &f = *fFacets[i];
01021       G4double dist = f.Distance(p, minDist);
01022       if (dist < minDist)
01023       {
01024         minDist  = dist;
01025         facet = &f;
01026       }
01027     }
01028   }
01029 
01030   if (minDist != kInfinity)
01031   {
01032     if (facet)  { aNormal = facet->GetSurfaceNormal(); }
01033     return minDist <= kCarToleranceHalf;
01034   }
01035   else
01036   {
01037 #ifdef G4VERBOSE
01038     std::ostringstream message;
01039     message << "Point p is not on surface !?" << G4endl
01040       << "          No facets found for point: " << p << " !" << G4endl
01041       << "          Returning approximated value for normal.";
01042 
01043     G4Exception("G4TessellatedSolid::SurfaceNormal(p)",
01044                 "GeomSolids1002", JustWarning, message );
01045 #endif
01046     aNormal = (p.z() > 0 ? G4ThreeVector(0,0,1) : G4ThreeVector(0,0,-1));
01047     return false;
01048   }
01049 }

G4TessellatedSolid & G4TessellatedSolid::operator+= ( const G4TessellatedSolid &  right  ) 

Definition at line 626 of file G4TessellatedSolid.cc.

References AddFacet(), G4VFacet::GetClone(), GetFacet(), and GetNumberOfFacets().

00627 {
00628   G4int size = right.GetNumberOfFacets();
00629   for (G4int i = 0; i < size; ++i)
00630     AddFacet(right.GetFacet(i)->GetClone());
00631 
00632   return *this;
00633 }

G4TessellatedSolid & G4TessellatedSolid::operator= ( const G4TessellatedSolid &  right  ) 

Definition at line 153 of file G4TessellatedSolid.cc.

References G4VSolid::operator=().

Referenced by G4ExtrudedSolid::operator=().

00154 {
00155   if (&ts == this) return *this;
00156 
00157   // Copy base class data
00158   G4VSolid::operator=(ts);
00159 
00160   DeleteObjects ();
00161 
00162   Initialize();
00163 
00164   CopyObjects (ts);
00165 
00166   return *this;
00167 }

G4double G4TessellatedSolid::SafetyFromInside ( const G4ThreeVector &  p,
G4bool  aAccurate = false 
) const [virtual]

Definition at line 1513 of file G4TessellatedSolid.cc.

References G4VFacet::Distance(), DistanceToIn(), G4Exception(), G4SurfaceVoxelizer::GetCountOfVoxels(), Inside(), JustWarning, G4VSolid::kCarTolerance, and kOutside.

Referenced by DistanceToOut().

01514 {  
01515 #if G4SPECSDEBUG
01516   if ( Inside(p) == kOutside )
01517   {
01518     std::ostringstream message;
01519     G4int oldprc = message.precision(16) ;
01520     message << "Point p is already outside!?" << G4endl
01521       << "Position:"  << G4endl << G4endl
01522       << "p.x() = "   << p.x()/mm << " mm" << G4endl
01523       << "p.y() = "   << p.y()/mm << " mm" << G4endl
01524       << "p.z() = "   << p.z()/mm << " mm" << G4endl
01525       << "DistanceToIn(p) == " << DistanceToIn(p);
01526     message.precision(oldprc) ;
01527     G4Exception("G4TriangularFacet::DistanceToOut(p)",
01528                 "GeomSolids1002", JustWarning, message);
01529   }
01530 #endif
01531 
01532   G4double minDist;
01533 
01534   if (OutsideOfExtent(p, kCarTolerance)) return 0.0;
01535 
01536   if (fVoxels.GetCountOfVoxels() > 1)
01537   {
01538     G4VFacet *facet;
01539     minDist = MinDistanceFacet(p, true, facet);
01540   }
01541   else
01542   {
01543     minDist = kInfinity;
01544     G4double dist = 0.0;
01545     G4int size = fFacets.size();
01546     for (G4int i = 0; i < size; ++i)
01547     {
01548       G4VFacet &facet = *fFacets[i];
01549       dist = facet.Distance(p,minDist);
01550       if (dist < minDist) minDist  = dist;
01551     }
01552   }
01553   return minDist;
01554 }

G4double G4TessellatedSolid::SafetyFromOutside ( const G4ThreeVector &  p,
G4bool  aAccurate = false 
) const [virtual]

Definition at line 1454 of file G4TessellatedSolid.cc.

References G4VFacet::Distance(), G4SurfaceVoxelizer::DistanceToBoundingBox(), DistanceToOut(), G4Exception(), G4SurfaceVoxelizer::GetCandidates(), G4SurfaceVoxelizer::GetCountOfVoxels(), G4SurfBits::GetNbits(), G4SurfaceVoxelizer::GetPointIndex(), G4SurfaceVoxelizer::GetVoxel(), Inside(), JustWarning, G4VSolid::kCarTolerance, and kInside.

Referenced by DistanceToIn().

01456 {
01457 #if G4SPECSDEBUG
01458   if ( Inside(p) == kInside )
01459   {
01460     std::ostringstream message;
01461     G4int oldprc = message.precision(16) ;
01462     message << "Point p is already inside!?" << G4endl
01463       << "Position:"  << G4endl << G4endl
01464       << "p.x() = "   << p.x()/mm << " mm" << G4endl
01465       << "p.y() = "   << p.y()/mm << " mm" << G4endl
01466       << "p.z() = "   << p.z()/mm << " mm" << G4endl
01467       << "DistanceToOut(p) == " << DistanceToOut(p);
01468     message.precision(oldprc) ;
01469     G4Exception("G4TriangularFacet::DistanceToIn(p)",
01470                 "GeomSolids1002", JustWarning, message);
01471   }
01472 #endif
01473 
01474   G4double minDist;
01475 
01476   if (fVoxels.GetCountOfVoxels() > 1)
01477   {
01478     if (!aAccurate)
01479       return fVoxels.DistanceToBoundingBox(p);
01480 
01481     if (!OutsideOfExtent(p, kCarTolerance))
01482     {
01483       vector<G4int> startingVoxel(3);
01484       fVoxels.GetVoxel(startingVoxel, p);
01485       const vector<G4int> &candidates = fVoxels.GetCandidates(startingVoxel);
01486       if (candidates.size() == 0 && fInsides.GetNbits())
01487       {
01488         G4int index = fVoxels.GetPointIndex(p);
01489         if (fInsides[index]) return 0.;
01490       }
01491     }
01492 
01493     G4VFacet *facet;
01494     minDist = MinDistanceFacet(p, true, facet);
01495   }
01496   else
01497   {
01498     minDist = kInfinity;
01499     G4int size = fFacets.size();
01500     for (G4int i = 0; i < size; ++i)
01501     {
01502       G4VFacet &facet = *fFacets[i];
01503       G4double dist = facet.Distance(p,minDist);
01504       if (dist < minDist) minDist  = dist;
01505     }
01506   }
01507   return minDist;
01508 }

void G4TessellatedSolid::SetMaxVoxels ( G4int  max  )  [inline]

Definition at line 308 of file G4TessellatedSolid.hh.

References G4SurfaceVoxelizer::SetMaxVoxels().

00309 {
00310   fVoxels.SetMaxVoxels(max);
00311 }

void G4TessellatedSolid::SetSolidClosed ( const G4bool  t  ) 

Definition at line 578 of file G4TessellatedSolid.cc.

References DisplayAllocatedMemory(), and G4cout.

Referenced by G4GDMLReadSolids::TessellatedRead().

00579 {
00580   if (t)
00581   {
00582 #ifdef G4SPECSDEBUG    
00583     G4cout << "Creating vertex list..." << G4endl;
00584 #endif
00585     CreateVertexList();
00586 
00587 #ifdef G4SPECSDEBUG    
00588     G4cout << "Setting extreme facets..." << G4endl;
00589 #endif
00590     SetExtremeFacets();
00591     
00592 #ifdef G4SPECSDEBUG    
00593     G4cout << "Voxelizing..." << G4endl;
00594 #endif
00595     Voxelize();
00596 
00597 #ifdef G4SPECSDEBUG
00598     DisplayAllocatedMemory();
00599 #endif
00600 
00601   }  
00602   fSolidClosed = t;
00603 }

std::ostream & G4TessellatedSolid::StreamInfo ( std::ostream &  os  )  const [virtual]

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1569 of file G4TessellatedSolid.cc.

References G4VFacet::StreamInfo().

01570 {
01571   os << G4endl;
01572   os << "Geometry Type    = " << fGeometryType  << G4endl;
01573   os << "Number of facets = " << fFacets.size() << G4endl;
01574 
01575   G4int size = fFacets.size();
01576   for (G4int i = 0; i < size; ++i)
01577   {
01578     os << "FACET #          = " << i + 1 << G4endl;
01579     G4VFacet &facet = *fFacets[i];
01580     facet.StreamInfo(os);
01581   }
01582   os << G4endl;
01583 
01584   return os;
01585 }

G4ThreeVector G4TessellatedSolid::SurfaceNormal ( const G4ThreeVector &  p  )  const [virtual]

Implements G4VSolid.

Definition at line 1623 of file G4TessellatedSolid.cc.

References Normal().

Referenced by G4GenericTrap::SurfaceNormal().

01624 {
01625   G4ThreeVector n;
01626   Normal(p, n);
01627   return n;
01628 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:28 2013 for Geant4 by  doxygen 1.4.7