Import Geant4 10.5.0.beta source tree
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4ExtrudedSolid.cc 108484 2018-02-15 14:38:03Z gcosmo $
|
||||
// $Id: G4ExtrudedSolid.cc 108078 2017-12-20 08:15:44Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
#include "G4ExtrudedSolid.hh"
|
||||
|
||||
//#if !defined(G4GEOM_USE_UEXTRUDEDSOLID)
|
||||
#if !defined(G4GEOM_USE_UEXTRUDEDSOLID)
|
||||
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
@@ -1564,4 +1564,4 @@ std::ostream& G4ExtrudedSolid::StreamInfo(std::ostream &os) const
|
||||
return os;
|
||||
}
|
||||
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4Hype.cc 106627 2017-10-17 06:23:58Z gcosmo $
|
||||
// $Id: G4Hype.cc 108078 2017-12-20 08:15:44Z gcosmo $
|
||||
// $Original: G4Hype.cc,v 1.0 1998/06/09 16:57:50 safai Exp $
|
||||
//
|
||||
//
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
#include "G4Hype.hh"
|
||||
|
||||
//#if !(defined(G4GEOM_USE_UHYPE) && defined(G4GEOM_USE_SYS_USOLIDS))
|
||||
#if !(defined(G4GEOM_USE_UHYPE) && defined(G4GEOM_USE_SYS_USOLIDS))
|
||||
|
||||
#include "G4VoxelLimits.hh"
|
||||
#include "G4AffineTransform.hh"
|
||||
@@ -1341,4 +1341,4 @@ G4double G4Hype::asinh(G4double arg)
|
||||
return std::log(arg+std::sqrt(sqr(arg)+1));
|
||||
}
|
||||
|
||||
//#endif // !defined(G4GEOM_USE_UHYPE) || !defined(G4GEOM_USE_SYS_USOLIDS)
|
||||
#endif // !defined(G4GEOM_USE_UHYPE) || !defined(G4GEOM_USE_SYS_USOLIDS)
|
||||
|
||||
@@ -36,7 +36,11 @@ namespace
|
||||
G4Mutex singletonMutexSWP = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4ThreadLocal G4SolidsWorkspace* G4SolidsWorkspacePool::fMyWorkspace=0;
|
||||
G4SolidsWorkspace*& G4SolidsWorkspacePool::fMyWorkspace()
|
||||
{
|
||||
G4ThreadLocalStatic G4SolidsWorkspace* _instance = nullptr;
|
||||
return _instance;
|
||||
}
|
||||
G4SolidsWorkspacePool* G4SolidsWorkspacePool::thePool=0;
|
||||
|
||||
G4SolidsWorkspacePool* G4SolidsWorkspacePool::GetInstance()
|
||||
@@ -51,7 +55,7 @@ G4SolidsWorkspacePool* G4SolidsWorkspacePool::GetInstance()
|
||||
G4SolidsWorkspace* G4SolidsWorkspacePool::CreateWorkspace()
|
||||
{
|
||||
G4SolidsWorkspace* geometryWrk=0;
|
||||
if( !fMyWorkspace )
|
||||
if( !fMyWorkspace() )
|
||||
{
|
||||
geometryWrk= new G4SolidsWorkspace();
|
||||
|
||||
@@ -63,7 +67,7 @@ G4SolidsWorkspace* G4SolidsWorkspacePool::CreateWorkspace()
|
||||
else
|
||||
{
|
||||
// geometryWrk->UseWorkspace(); // Do not assign it already.
|
||||
fMyWorkspace= geometryWrk;
|
||||
fMyWorkspace()= geometryWrk;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -71,7 +75,7 @@ G4SolidsWorkspace* G4SolidsWorkspacePool::CreateWorkspace()
|
||||
G4Exception("GeometryWorspacePool::CreateWorkspace", "Geom-003",
|
||||
FatalException,
|
||||
"Cannot create workspace twice for the same thread.");
|
||||
geometryWrk= fMyWorkspace;
|
||||
geometryWrk= fMyWorkspace();
|
||||
}
|
||||
|
||||
return geometryWrk;
|
||||
@@ -88,14 +92,14 @@ void G4SolidsWorkspacePool::CreateAndUseWorkspace()
|
||||
//
|
||||
G4SolidsWorkspace* G4SolidsWorkspacePool::FindOrCreateWorkspace()
|
||||
{
|
||||
G4SolidsWorkspace* geometryWrk= fMyWorkspace;
|
||||
G4SolidsWorkspace* geometryWrk= fMyWorkspace();
|
||||
if( !geometryWrk )
|
||||
{
|
||||
geometryWrk= this->CreateWorkspace();
|
||||
}
|
||||
geometryWrk->UseWorkspace();
|
||||
|
||||
fMyWorkspace= geometryWrk; // assign it for use by this thread.
|
||||
fMyWorkspace()= geometryWrk; // assign it for use by this thread.
|
||||
return geometryWrk;
|
||||
}
|
||||
|
||||
@@ -111,11 +115,11 @@ void G4SolidsWorkspacePool::Recycle( G4SolidsWorkspace *geometryWrk )
|
||||
|
||||
void G4SolidsWorkspacePool::CleanUpAndDestroyAllWorkspaces()
|
||||
{
|
||||
if (fMyWorkspace)
|
||||
if (fMyWorkspace())
|
||||
{
|
||||
fMyWorkspace->DestroyWorkspace();
|
||||
delete fMyWorkspace;
|
||||
fMyWorkspace=0;
|
||||
fMyWorkspace()->DestroyWorkspace();
|
||||
delete fMyWorkspace();
|
||||
fMyWorkspace()=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4TessellatedSolid.cc 106710 2017-10-20 09:22:51Z gcosmo $
|
||||
// $Id: G4TessellatedSolid.cc 108288 2018-01-31 09:36:41Z gcosmo $
|
||||
//
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//
|
||||
@@ -72,6 +72,10 @@
|
||||
//
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
#include "G4TessellatedSolid.hh"
|
||||
|
||||
#if !defined(G4GEOM_USE_UTESSELLATEDSOLID)
|
||||
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <iostream>
|
||||
@@ -80,8 +84,6 @@
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
|
||||
#include "G4TessellatedSolid.hh"
|
||||
|
||||
#include "geomdefs.hh"
|
||||
#include "Randomize.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
@@ -1785,14 +1787,14 @@ G4Polyhedron *G4TessellatedSolid::CreatePolyhedron () const
|
||||
G4int size = fFacets.size();
|
||||
for (G4int i = 0; i < size; ++i)
|
||||
{
|
||||
G4VFacet &facet = *fFacets[i];
|
||||
G4VFacet* facet = fFacets[i];
|
||||
G4int v[4];
|
||||
G4int n = facet.GetNumberOfVertices();
|
||||
G4int n = facet->GetNumberOfVertices();
|
||||
if (n > 4) n = 4;
|
||||
else if (n == 3) v[3] = 0;
|
||||
for (G4int j=0; j<n; ++j)
|
||||
{
|
||||
G4int k = facet.GetVertexIndex(j);
|
||||
G4int k = facet->GetVertexIndex(j);
|
||||
v[j] = k+1;
|
||||
}
|
||||
polyhedron->AddFacet(v[0],v[1],v[2],v[3]);
|
||||
@@ -2098,3 +2100,5 @@ G4int G4TessellatedSolid::AllocatedMemory()
|
||||
size += sizeInsides + sizeVoxels;
|
||||
return size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4ExtrudedSolid.hh"
|
||||
#if 0
|
||||
#include "G4UExtrudedSolid.hh"
|
||||
|
||||
#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
|
||||
@@ -49,22 +48,29 @@
|
||||
G4UExtrudedSolid::G4UExtrudedSolid(const G4String& name,
|
||||
std::vector<G4TwoVector> polygon,
|
||||
std::vector<ZSection> zsections)
|
||||
: G4USolid(name, new UExtrudedSolid())
|
||||
: Base_t(name) // General constructor
|
||||
{
|
||||
GetShape()->SetName(name);
|
||||
std::vector<UVector2> pvec;
|
||||
for (unsigned int i=0; i<polygon.size(); ++i)
|
||||
unsigned int nVertices = polygon.size();
|
||||
unsigned int nSections = zsections.size();
|
||||
|
||||
vecgeom::XtruVertex2* vertices = new vecgeom::XtruVertex2[nVertices];
|
||||
vecgeom::XtruSection* sections = new vecgeom::XtruSection[nSections];
|
||||
|
||||
for (unsigned int i = 0; i < nVertices; ++i)
|
||||
{
|
||||
pvec.push_back(UVector2(polygon[i].x(), polygon[i].y()));
|
||||
vertices[i].x = polygon[i].x();
|
||||
vertices[i].y = polygon[i].y();
|
||||
}
|
||||
std::vector<UExtrudedSolid::ZSection> svec;
|
||||
for (unsigned int i=0; i<zsections.size(); ++i)
|
||||
for (unsigned int i = 0; i < nSections; ++i)
|
||||
{
|
||||
ZSection sec = zsections[i];
|
||||
svec.push_back(UExtrudedSolid::ZSection(sec.fZ,
|
||||
UVector2(sec.fOffset.x(), sec.fOffset.y()), sec.fScale));
|
||||
sections[i].fOrigin.Set(zsections[i].fOffset.x(),
|
||||
zsections[i].fOffset.y(),
|
||||
zsections[i].fZ);
|
||||
sections[i].fScale = zsections[i].fScale;
|
||||
}
|
||||
GetShape()->Initialise(pvec, svec);
|
||||
Base_t::Initialize(nVertices, vertices, nSections, sections);
|
||||
delete[] vertices;
|
||||
delete[] sections;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,16 +79,26 @@ G4UExtrudedSolid::G4UExtrudedSolid(const G4String& name,
|
||||
G4double halfZ,
|
||||
G4TwoVector off1, G4double scale1,
|
||||
G4TwoVector off2, G4double scale2)
|
||||
: G4USolid(name, new UExtrudedSolid())
|
||||
{
|
||||
GetShape()->SetName(name);
|
||||
std::vector<UVector2> pvec;
|
||||
for (unsigned int i=0; i<polygon.size(); ++i)
|
||||
: Base_t(name) // Special constructor for 2 sections
|
||||
{
|
||||
unsigned int nVertices = polygon.size();
|
||||
unsigned int nSections = 2;
|
||||
|
||||
vecgeom::XtruVertex2* vertices = new vecgeom::XtruVertex2[nVertices];
|
||||
vecgeom::XtruSection* sections = new vecgeom::XtruSection[nSections];
|
||||
|
||||
for (unsigned int i = 0; i < nVertices; ++i)
|
||||
{
|
||||
pvec.push_back(UVector2(polygon[i].x(), polygon[i].y()));
|
||||
vertices[i].x = polygon[i].x();
|
||||
vertices[i].y = polygon[i].y();
|
||||
}
|
||||
GetShape()->Initialise(pvec, halfZ, UVector2(off1.x(), off1.y()), scale1,
|
||||
UVector2(off2.x(), off2.y()), scale2);
|
||||
sections[0].fOrigin.Set(off1.x(), off1.y(), -halfZ);
|
||||
sections[0].fScale = scale1;
|
||||
sections[1].fOrigin.Set(off2.x(), off2.y(), halfZ);
|
||||
sections[1].fScale = scale2;
|
||||
Base_t::Initialize(nVertices, vertices, nSections, sections);
|
||||
delete[] vertices;
|
||||
delete[] sections;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@@ -91,7 +107,7 @@ G4UExtrudedSolid::G4UExtrudedSolid(const G4String& name,
|
||||
// for usage restricted to object persistency.
|
||||
//
|
||||
G4UExtrudedSolid::G4UExtrudedSolid(__void__& a)
|
||||
: G4USolid(a)
|
||||
: Base_t(a)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -110,7 +126,7 @@ G4UExtrudedSolid::~G4UExtrudedSolid()
|
||||
// Copy constructor
|
||||
//
|
||||
G4UExtrudedSolid::G4UExtrudedSolid(const G4UExtrudedSolid &source)
|
||||
: G4USolid(source)
|
||||
: Base_t(source)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -124,7 +140,7 @@ G4UExtrudedSolid::operator=(const G4UExtrudedSolid &source)
|
||||
{
|
||||
if (this == &source) return *this;
|
||||
|
||||
G4USolid::operator=( source );
|
||||
Base_t::operator=( source );
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -136,40 +152,45 @@ G4UExtrudedSolid::operator=(const G4UExtrudedSolid &source)
|
||||
|
||||
G4int G4UExtrudedSolid::GetNofVertices() const
|
||||
{
|
||||
return GetShape()->GetNofVertices();
|
||||
return Base_t::GetNVertices();
|
||||
}
|
||||
G4TwoVector G4UExtrudedSolid::GetVertex(G4int i) const
|
||||
{
|
||||
UVector2 v = GetShape()->GetVertex(i);
|
||||
return G4TwoVector(v.x, v.y);
|
||||
G4double xx, yy;
|
||||
Base_t::GetVertex(i, xx, yy);
|
||||
return G4TwoVector(xx, yy);
|
||||
}
|
||||
std::vector<G4TwoVector> G4UExtrudedSolid::GetPolygon() const
|
||||
{
|
||||
std::vector<UVector2> pol = GetShape()->GetPolygon();
|
||||
std::vector<G4TwoVector> v;
|
||||
for (unsigned int i=0; i<pol.size(); ++i)
|
||||
std::vector<G4TwoVector> pol;
|
||||
for (unsigned int i = 0; i < Base_t::GetNVertices(); ++i)
|
||||
{
|
||||
v.push_back(G4TwoVector(pol[i].x, pol[i].y));
|
||||
pol.push_back(GetVertex(i));
|
||||
}
|
||||
return v;
|
||||
return pol;
|
||||
}
|
||||
G4int G4UExtrudedSolid::GetNofZSections() const
|
||||
{
|
||||
return GetShape()->GetNofZSections();
|
||||
return Base_t::GetNSections();
|
||||
}
|
||||
G4UExtrudedSolid::ZSection G4UExtrudedSolid::GetZSection(G4int i) const
|
||||
{
|
||||
return ZSection(GetShape()->GetZSection(i));
|
||||
vecgeom::XtruSection sect = Base_t::GetSection(i);
|
||||
return ZSection(sect.fOrigin[2],
|
||||
G4TwoVector(sect.fOrigin[0], sect.fOrigin[1]),
|
||||
sect.fScale);
|
||||
}
|
||||
std::vector<G4UExtrudedSolid::ZSection> G4UExtrudedSolid::GetZSections() const
|
||||
{
|
||||
std::vector<UExtrudedSolid::ZSection> sv = GetShape()->GetZSections();
|
||||
std::vector<G4UExtrudedSolid::ZSection> vec;
|
||||
for (unsigned int i=0; i<sv.size(); ++i)
|
||||
std::vector<G4UExtrudedSolid::ZSection> sections;
|
||||
for (unsigned int i = 0; i < Base_t::GetNSections(); ++i)
|
||||
{
|
||||
vec.push_back(ZSection(sv[i]));
|
||||
vecgeom::XtruSection sect = Base_t::GetSection(i);
|
||||
sections.push_back(ZSection(sect.fOrigin[2],
|
||||
G4TwoVector(sect.fOrigin[0], sect.fOrigin[1]),
|
||||
sect.fScale));
|
||||
}
|
||||
return vec;
|
||||
return sections;
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +258,7 @@ void G4UExtrudedSolid::BoundingLimits(G4ThreeVector& pMin,
|
||||
if (checkBBox)
|
||||
{
|
||||
UVector3 vmin, vmax;
|
||||
GetShape()->Extent(vmin,vmax);
|
||||
Base_t::Extent(vmin,vmax);
|
||||
if (std::abs(pMin.x()-vmin.x()) > kCarTolerance ||
|
||||
std::abs(pMin.y()-vmin.y()) > kCarTolerance ||
|
||||
std::abs(pMin.z()-vmin.z()) > kCarTolerance ||
|
||||
@@ -360,36 +381,22 @@ G4UExtrudedSolid::CalculateExtent(const EAxis pAxis,
|
||||
//
|
||||
G4Polyhedron* G4UExtrudedSolid::CreatePolyhedron () const
|
||||
{
|
||||
G4int nFacets = GetShape()->GetNumberOfFacets();
|
||||
G4int nVertices = 0;
|
||||
for (G4int l = 0; l<nFacets; ++l) // compute total number of vertices first
|
||||
{
|
||||
VUFacet* facet = GetShape()->GetFacet(l);
|
||||
G4int n = facet->GetNumberOfVertices();
|
||||
nVertices += n;
|
||||
}
|
||||
unsigned int nFacets = Base_t::GetStruct().fTslHelper.fFacets.size();
|
||||
unsigned int fVertices = 3*nFacets;
|
||||
|
||||
G4PolyhedronArbitrary *polyhedron =
|
||||
new G4PolyhedronArbitrary (nVertices,nFacets);
|
||||
new G4PolyhedronArbitrary (fVertices,nFacets);
|
||||
|
||||
for (G4int i = 0; i<nFacets; ++i)
|
||||
for (unsigned int i = 0; i < nFacets; ++i)
|
||||
{
|
||||
VUFacet* facet = GetShape()->GetFacet(i);
|
||||
G4int v[4];
|
||||
G4int n = facet->GetNumberOfVertices();
|
||||
for (G4int m = 0; m<n; ++m)
|
||||
G4int v[3]; // Facets are only triangular in VecGeom
|
||||
for (unsigned int j = 0; j < 3; ++j)
|
||||
{
|
||||
UVector3 vtx = facet->GetVertex(m);
|
||||
UVector3 vtx = Base_t::GetStruct().fTslHelper.fFacets[i]->fVertices[j];
|
||||
polyhedron->AddVertex(G4ThreeVector(vtx.x(), vtx.y(), vtx.z()));
|
||||
v[j] = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[j]+1;
|
||||
}
|
||||
if (n > 4) n = 4;
|
||||
else if (n == 3) v[3] = 0;
|
||||
for (G4int j=0; j<n; ++j)
|
||||
{
|
||||
G4int k = facet->GetVertexIndex(j);
|
||||
v[j] = k+1;
|
||||
}
|
||||
polyhedron->AddFacet(v[0],v[1],v[2],v[3]);
|
||||
polyhedron->AddFacet(v[0],v[1],v[2],0);
|
||||
}
|
||||
polyhedron->SetReferences();
|
||||
|
||||
@@ -397,4 +404,3 @@ G4Polyhedron* G4UExtrudedSolid::CreatePolyhedron () const
|
||||
}
|
||||
|
||||
#endif // G4GEOM_USE_USOLIDS
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4Hype.hh"
|
||||
#if 0
|
||||
|
||||
#include "G4UHype.hh"
|
||||
|
||||
#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
|
||||
@@ -240,5 +240,3 @@ G4Polyhedron* G4UHype::CreatePolyhedron() const
|
||||
}
|
||||
|
||||
#endif // G4GEOM_USE_USOLIDS
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,410 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id:$
|
||||
//
|
||||
//
|
||||
// Implementation of G4UTessellatedSolid wrapper class
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4TessellatedSolid.hh"
|
||||
#include "G4UTessellatedSolid.hh"
|
||||
|
||||
#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
|
||||
|
||||
#include "G4TriangularFacet.hh"
|
||||
#include "G4QuadrangularFacet.hh"
|
||||
|
||||
#include "G4GeomTools.hh"
|
||||
#include "G4AffineTransform.hh"
|
||||
#include "G4BoundingEnvelope.hh"
|
||||
|
||||
#include "G4PolyhedronArbitrary.hh"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
G4UTessellatedSolid::G4UTessellatedSolid()
|
||||
: Base_t("")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
G4UTessellatedSolid::G4UTessellatedSolid(const G4String& name)
|
||||
: Base_t(name)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Fake default constructor - sets only member data and allocates memory
|
||||
// for usage restricted to object persistency.
|
||||
//
|
||||
G4UTessellatedSolid::G4UTessellatedSolid(__void__& a)
|
||||
: Base_t(a)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
//
|
||||
G4UTessellatedSolid::~G4UTessellatedSolid()
|
||||
{
|
||||
G4int size = fFacets.size();
|
||||
for (G4int i = 0; i < size; ++i) { delete fFacets[i]; }
|
||||
fFacets.clear();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
//
|
||||
G4UTessellatedSolid::G4UTessellatedSolid(const G4UTessellatedSolid& source)
|
||||
: Base_t(source)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
//
|
||||
G4UTessellatedSolid&
|
||||
G4UTessellatedSolid::operator=(const G4UTessellatedSolid& source)
|
||||
{
|
||||
if (this == &source) return *this;
|
||||
|
||||
Base_t::operator=( source );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Accessors
|
||||
|
||||
G4bool G4UTessellatedSolid::AddFacet(G4VFacet* aFacet)
|
||||
{
|
||||
// Add a facet to the structure, checking validity.
|
||||
//
|
||||
if (GetSolidClosed())
|
||||
{
|
||||
G4Exception("G4UTessellatedSolid::AddFacet()", "GeomSolids1002",
|
||||
JustWarning, "Attempt to add facets when solid is closed.");
|
||||
return false;
|
||||
}
|
||||
if (!aFacet->IsDefined())
|
||||
{
|
||||
G4Exception("G4UTessellatedSolid::AddFacet()", "GeomSolids1002",
|
||||
JustWarning, "Attempt to add facet not properly defined.");
|
||||
aFacet->StreamInfo(G4cout);
|
||||
return false;
|
||||
}
|
||||
if (aFacet->GetNumberOfVertices() == 3)
|
||||
{
|
||||
G4TriangularFacet* a3Facet = dynamic_cast<G4TriangularFacet*>(aFacet);
|
||||
return Base_t::AddTriangularFacet(UVector3(a3Facet->GetVertex(0).x(),
|
||||
a3Facet->GetVertex(0).y(),
|
||||
a3Facet->GetVertex(0).z()),
|
||||
UVector3(a3Facet->GetVertex(1).x(),
|
||||
a3Facet->GetVertex(1).y(),
|
||||
a3Facet->GetVertex(1).z()),
|
||||
UVector3(a3Facet->GetVertex(2).x(),
|
||||
a3Facet->GetVertex(2).y(),
|
||||
a3Facet->GetVertex(2).z()),
|
||||
true);
|
||||
}
|
||||
else if (aFacet->GetNumberOfVertices() == 4)
|
||||
{
|
||||
G4QuadrangularFacet* a4Facet = dynamic_cast<G4QuadrangularFacet*>(aFacet);
|
||||
return Base_t::AddQuadrilateralFacet(UVector3(a4Facet->GetVertex(0).x(),
|
||||
a4Facet->GetVertex(0).y(),
|
||||
a4Facet->GetVertex(0).z()),
|
||||
UVector3(a4Facet->GetVertex(1).x(),
|
||||
a4Facet->GetVertex(1).y(),
|
||||
a4Facet->GetVertex(1).z()),
|
||||
UVector3(a4Facet->GetVertex(2).x(),
|
||||
a4Facet->GetVertex(2).y(),
|
||||
a4Facet->GetVertex(2).z()),
|
||||
UVector3(a4Facet->GetVertex(3).x(),
|
||||
a4Facet->GetVertex(3).y(),
|
||||
a4Facet->GetVertex(3).z()),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
G4Exception("G4UTessellatedSolid::AddFacet()", "GeomSolids1002",
|
||||
JustWarning, "Attempt to add facet not properly defined.");
|
||||
aFacet->StreamInfo(G4cout);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
G4VFacet* G4UTessellatedSolid::GetFacet(G4int i) const
|
||||
{
|
||||
return fFacets[i];
|
||||
}
|
||||
|
||||
G4int G4UTessellatedSolid::GetNumberOfFacets() const
|
||||
{
|
||||
return GetNFacets();
|
||||
}
|
||||
|
||||
void G4UTessellatedSolid::SetSolidClosed(const G4bool t)
|
||||
{
|
||||
if (t && !Base_t::IsClosed())
|
||||
{
|
||||
Base_t::Close();
|
||||
G4int nVertices = fTessellated.fVertices.size();
|
||||
G4int nFacets = fTessellated.fFacets.size();
|
||||
for (G4int j = 0; j < nVertices; ++j)
|
||||
{
|
||||
UVector3 vt = fTessellated.fVertices[j];
|
||||
fVertexList.push_back(G4ThreeVector(vt.x(), vt.y(), vt.z()));
|
||||
}
|
||||
for (G4int i = 0; i < nFacets; ++i)
|
||||
{
|
||||
vecgeom::TriangleFacet<G4double>* afacet = Base_t::GetFacet(i);
|
||||
std::vector<G4ThreeVector> v;
|
||||
for (G4int k=0; k<3; ++k)
|
||||
{
|
||||
v.push_back(G4ThreeVector(afacet->fVertices[k].x(),
|
||||
afacet->fVertices[k].y(),
|
||||
afacet->fVertices[k].z()));
|
||||
}
|
||||
G4VFacet* facet = new G4TriangularFacet(v[0], v[1], v[2],
|
||||
G4FacetVertexType::ABSOLUTE);
|
||||
facet->SetVertices(&fVertexList);
|
||||
for (G4int k=0; k<3; ++k)
|
||||
{
|
||||
facet->SetVertexIndex(k, afacet->fIndices[k]);
|
||||
}
|
||||
fFacets.push_back(facet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
G4bool G4UTessellatedSolid::GetSolidClosed() const
|
||||
{
|
||||
return Base_t::IsClosed();
|
||||
}
|
||||
|
||||
void G4UTessellatedSolid::SetMaxVoxels(G4int)
|
||||
{
|
||||
// Not yet implemented !
|
||||
}
|
||||
|
||||
G4double G4UTessellatedSolid::GetMinXExtent() const
|
||||
{
|
||||
UVector3 aMin, aMax;
|
||||
Base_t::Extent(aMin, aMax);
|
||||
return aMin.x();
|
||||
}
|
||||
G4double G4UTessellatedSolid::GetMaxXExtent() const
|
||||
{
|
||||
UVector3 aMin, aMax;
|
||||
Base_t::Extent(aMin, aMax);
|
||||
return aMax.x();
|
||||
}
|
||||
G4double G4UTessellatedSolid::GetMinYExtent() const
|
||||
{
|
||||
UVector3 aMin, aMax;
|
||||
Base_t::Extent(aMin, aMax);
|
||||
return aMin.y();
|
||||
}
|
||||
G4double G4UTessellatedSolid::GetMaxYExtent() const
|
||||
{
|
||||
UVector3 aMin, aMax;
|
||||
Base_t::Extent(aMin, aMax);
|
||||
return aMax.y();
|
||||
}
|
||||
G4double G4UTessellatedSolid::GetMinZExtent() const
|
||||
{
|
||||
UVector3 aMin, aMax;
|
||||
Base_t::Extent(aMin, aMax);
|
||||
return aMin.z();
|
||||
}
|
||||
G4double G4UTessellatedSolid::GetMaxZExtent() const
|
||||
{
|
||||
UVector3 aMin, aMax;
|
||||
Base_t::Extent(aMin, aMax);
|
||||
return aMax.z();
|
||||
}
|
||||
|
||||
G4int G4UTessellatedSolid::AllocatedMemoryWithoutVoxels()
|
||||
{
|
||||
G4int base = sizeof(*this);
|
||||
base += fVertexList.capacity() * sizeof(G4ThreeVector);
|
||||
|
||||
G4int limit = fFacets.size();
|
||||
for (G4int i = 0; i < limit; i++)
|
||||
{
|
||||
G4VFacet &facet = *fFacets[i];
|
||||
base += facet.AllocatedMemory();
|
||||
}
|
||||
return base;
|
||||
}
|
||||
G4int G4UTessellatedSolid::AllocatedMemory()
|
||||
{
|
||||
return AllocatedMemoryWithoutVoxels();
|
||||
}
|
||||
void G4UTessellatedSolid::DisplayAllocatedMemory()
|
||||
{
|
||||
G4int without = AllocatedMemoryWithoutVoxels();
|
||||
// G4int with = AllocatedMemory();
|
||||
// G4double ratio = (G4double) with / without;
|
||||
// G4cout << "G4TessellatedSolid - Allocated memory without voxel overhead "
|
||||
// << without << "; with " << with << "; ratio: " << ratio << G4endl;
|
||||
G4cout << "G4TessellatedSolid - Allocated memory without voxel overhead "
|
||||
<< without << G4endl;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get bounding box
|
||||
|
||||
void G4UTessellatedSolid::BoundingLimits(G4ThreeVector& pMin,
|
||||
G4ThreeVector& pMax) const
|
||||
{
|
||||
UVector3 aMin, aMax;
|
||||
Base_t::Extent(aMin, aMax);
|
||||
pMin = G4ThreeVector(aMin.x(), aMin.y(), aMin.z());
|
||||
pMax = G4ThreeVector(aMax.x(), aMax.y(), aMax.z());
|
||||
|
||||
// Check correctness of the bounding box
|
||||
//
|
||||
if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
|
||||
{
|
||||
std::ostringstream message;
|
||||
message << "Bad bounding box (min >= max) for solid: "
|
||||
<< GetName() << " !"
|
||||
<< "\npMin = " << pMin
|
||||
<< "\npMax = " << pMax;
|
||||
G4Exception("G4UTessellatedSolid::BoundingLimits()",
|
||||
"GeomMgt0001", JustWarning, message);
|
||||
StreamInfo(G4cout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Calculate extent under transform and specified limit
|
||||
|
||||
G4bool
|
||||
G4UTessellatedSolid::CalculateExtent(const EAxis pAxis,
|
||||
const G4VoxelLimits& pVoxelLimit,
|
||||
const G4AffineTransform& pTransform,
|
||||
G4double& pMin, G4double& pMax) const
|
||||
{
|
||||
G4ThreeVector bmin, bmax;
|
||||
G4bool exist;
|
||||
G4double kCarToleranceHalf = 0.5*kCarTolerance;
|
||||
|
||||
// Check bounding box (bbox)
|
||||
//
|
||||
BoundingLimits(bmin,bmax);
|
||||
G4BoundingEnvelope bbox(bmin,bmax);
|
||||
#ifdef G4BBOX_EXTENT
|
||||
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
#endif
|
||||
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
|
||||
{
|
||||
return exist = (pMin < pMax) ? true : false;
|
||||
}
|
||||
|
||||
// The extent is calculated as cumulative extent of the pyramids
|
||||
// formed by facets and the center of the bounding box.
|
||||
//
|
||||
G4double eminlim = pVoxelLimit.GetMinExtent(pAxis);
|
||||
G4double emaxlim = pVoxelLimit.GetMaxExtent(pAxis);
|
||||
|
||||
G4ThreeVectorList base;
|
||||
G4ThreeVectorList apex(1);
|
||||
std::vector<const G4ThreeVectorList *> pyramid(2);
|
||||
pyramid[0] = &base;
|
||||
pyramid[1] = &apex;
|
||||
apex[0] = (bmin+bmax)*0.5;
|
||||
|
||||
// main loop along facets
|
||||
pMin = kInfinity;
|
||||
pMax = -kInfinity;
|
||||
for (G4int i=0; i<GetNumberOfFacets(); ++i)
|
||||
{
|
||||
G4VFacet* facet = GetFacet(i);
|
||||
if (std::abs((facet->GetSurfaceNormal()).dot(facet->GetVertex(0)-apex[0]))
|
||||
< kCarToleranceHalf) continue;
|
||||
|
||||
base.resize(3);
|
||||
for (G4int k=0; k<3; ++k) { base[k] = facet->GetVertex(k); }
|
||||
G4double emin,emax;
|
||||
G4BoundingEnvelope benv(pyramid);
|
||||
if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax)) continue;
|
||||
if (emin < pMin) pMin = emin;
|
||||
if (emax > pMax) pMax = emax;
|
||||
if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
|
||||
}
|
||||
return (pMin < pMax);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CreatePolyhedron()
|
||||
//
|
||||
G4Polyhedron* G4UTessellatedSolid::CreatePolyhedron () const
|
||||
{
|
||||
G4int nVertices = fVertexList.size();
|
||||
G4int nFacets = fFacets.size();
|
||||
G4PolyhedronArbitrary *polyhedron = new G4PolyhedronArbitrary (nVertices,
|
||||
nFacets);
|
||||
for (G4int j = 0; j < nVertices; ++j)
|
||||
{
|
||||
polyhedron->AddVertex(fVertexList[j]);
|
||||
}
|
||||
|
||||
for (G4int i = 0; i < nFacets; ++i)
|
||||
{
|
||||
G4int v[3]; // Only facets with 3 vertices are defined in VecGeom
|
||||
G4VFacet* facet = GetFacet(i);
|
||||
for (G4int j=0; j<3; ++j) // Retrieve indexing directly from VecGeom
|
||||
{
|
||||
v[j] = facet->GetVertexIndex(j) + 1;
|
||||
}
|
||||
polyhedron->AddFacet(v[0],v[1],v[2]);
|
||||
}
|
||||
polyhedron->SetReferences();
|
||||
|
||||
return (G4Polyhedron*) polyhedron;
|
||||
}
|
||||
|
||||
#endif // G4GEOM_USE_USOLIDS
|
||||
Reference in New Issue
Block a user