Commit 0962a88f authored by Martin Kostelnik's avatar Martin Kostelnik
Browse files

Add bounding box tests to ctest

parent bb455751
......@@ -87,7 +87,7 @@ private:
PolyhedronStruct<Precision> fPoly; ///< Structure holding polyhedron data
public:
UnplacedPolyhedron() : fPoly() {}
UnplacedPolyhedron() : fPoly() { ComputeBBox(); }
/// \param sideCount Number of sides along phi in each Z-segment.
/// \param zPlaneCount Number of Z-planes to draw segments between. The number
/// of segments will always be this number minus one.
......
......@@ -281,9 +281,6 @@ public:
std::ostream &StreamInfo(std::ostream &os) const;
VECCORE_ATT_HOST_DEVICE
void ComputeBBox() const;
// VECCORE_ATT_HOST_DEVICE
// Precision sqr(Precision x) {return x*x;};
......
......@@ -64,7 +64,9 @@ public:
bool AddTriangularFacet(Vector3D<Precision> const &vt0, Vector3D<Precision> const &vt1,
Vector3D<Precision> const &vt2, bool absolute = true)
{
return fTessellated.AddTriangularFacet(vt0, vt1, vt2, absolute);
bool result = fTessellated.AddTriangularFacet(vt0, vt1, vt2, absolute);
ComputeBBox();
return result;
}
/// Method for adding a new quadrilateral facet, delegated to TessellatedStruct
......@@ -81,7 +83,9 @@ public:
bool AddQuadrilateralFacet(Vector3D<Precision> const &vt0, Vector3D<Precision> const &vt1,
Vector3D<Precision> const &vt2, Vector3D<Precision> const &vt3, bool absolute = true)
{
return fTessellated.AddQuadrilateralFacet(vt0, vt1, vt2, vt3, absolute);
bool result = fTessellated.AddQuadrilateralFacet(vt0, vt1, vt2, vt3, absolute);
ComputeBBox();
return result;
}
/// Getter for the number of facets.
......
......@@ -22,6 +22,7 @@ UnplacedPolyhedron::UnplacedPolyhedron(const int sideCount, const int zPlaneCoun
: UnplacedPolyhedron(0., kTwoPi, sideCount, zPlaneCount, zPlanes, rMin, rMax)
{
DetectConvexity();
ComputeBBox();
}
VECCORE_ATT_HOST_DEVICE
......@@ -31,6 +32,7 @@ UnplacedPolyhedron::UnplacedPolyhedron(Precision phiStart, Precision phiDelta, c
: fPoly(phiStart, phiDelta, sideCount, zPlaneCount, zPlanes, rMin, rMax)
{
DetectConvexity();
ComputeBBox();
}
UnplacedPolyhedron::UnplacedPolyhedron(Precision phiStart, Precision phiDelta, const int sideCount,
......@@ -41,6 +43,7 @@ UnplacedPolyhedron::UnplacedPolyhedron(Precision phiStart, Precision phiDelta, c
: fPoly(phiStart, phiDelta, sideCount, verticesCount, r, z)
{
DetectConvexity();
ComputeBBox();
}
VECCORE_ATT_HOST_DEVICE
......
......@@ -252,9 +252,6 @@ std::string UnplacedSphere::GetEntityType() const
#endif // !VECCORE_CUDA
VECCORE_ATT_HOST_DEVICE
void UnplacedSphere::ComputeBBox() const {}
/*UnplacedSphere *UnplacedSphere::Clone() const
{
return new UnplacedSphere(fSphere.fRmin, fSphere.fRmax, fSphere.fSPhi, fSphere.fDPhi, fSphere.fSTheta,
......
......@@ -2,6 +2,7 @@
#include "VecGeom/volumes/PlacedAssembly.h"
#include "VecGeom/navigation/NavigationState.h"
#include "VecGeom/volumes/Box.h"
#include "test/unit_tests/ApproxEqual.h"
// make sure that assert are included even in Release mode
#ifdef NDEBUG
......@@ -100,6 +101,14 @@ int main()
assert(emin == ass->GetLowerCorner());
assert(emax == ass->GetUpperCorner());
// test bounding box
Vector3D<Precision> minExtent, maxExtent;
Vector3D<Precision> minBBox, maxBBox;
ass->Extent(minExtent, maxExtent);
ass->GetBBox(minBBox, maxBBox);
assert(ApproxEqual<Precision>(minExtent, minBBox));
assert(ApproxEqual<Precision>(maxExtent, maxBBox));
// check Normal
// TBD
......
......@@ -55,6 +55,17 @@ int TestBooleans()
LogicalVolume lboxminusholes("CombinedBoolean", &boxminusholes);
auto placedcombinedboolean = lboxminusholes.Place();
// Check Extent and cached BBox
Vec3D_t minExtent, maxExtent, minBBox, maxBBox;
holes.Extent(minExtent, maxExtent);
holes.GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
boxminusholes.Extent(minExtent, maxExtent);
boxminusholes.GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
auto capacity = boxminusholes.Capacity();
assert(capacity > 0);
assert(std::fabs(capacity - (bv - 2. * tv)) / capacity < 1E-03);
......
......@@ -57,15 +57,22 @@ bool TestBox()
assert(b1.SurfaceArea() == 20800);
assert(b2.SurfaceArea() == 6 * 20 * 20);
// CalculateExtent
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
b1.Extent(minExtent, maxExtent);
b1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-20, -30, -40)));
assert(ApproxEqual(maxExtent, Vec_t(20, 30, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
b2.Extent(minExtent, maxExtent);
b2.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-10, -10, -10)));
assert(ApproxEqual(maxExtent, Vec_t(10, 10, 10)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
// Check Surface Normal
Vec_t normal;
......
......@@ -238,12 +238,16 @@ bool TestGenTrap()
}
// CalculateExtent
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
trap2.Extent(minExtent, maxExtent);
trap2.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-3, -3, -5)));
assert(ApproxEqual(maxExtent, Vec_t(3, 3, 5)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
return true;
}
......
......@@ -60,14 +60,19 @@ bool TestHype()
assert(!strcmp(b1.GetName(), "Solid VecGeomHype #1"));
assert(!strcmp(b2.GetName(), "Solid VecGeomHype #2"));
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
b1.Extent(minExtent, maxExtent);
b1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
double tSTout = std::tan(stOut);
double tSTin = std::tan(stIn);
double xy = std::sqrt(fRmax * fRmax + tSTout * tSTout * halfZ * halfZ);
assert(ApproxEqual(minExtent, Vec_t(-xy, -xy, -halfZ)));
assert(ApproxEqual(maxExtent, Vec_t(xy, xy, halfZ)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
// Check Surface Normal
Vec_t normal;
......
......@@ -62,13 +62,21 @@ bool TestOrb()
assert(ApproxEqual<Precision>(b1.SurfaceArea(), ((4 * kPi) * fR * fR)));
assert(ApproxEqual<Precision>(b2.SurfaceArea(), ((4 * kPi) * 6 * 6)));
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
b1.Extent(minExtent, maxExtent);
b1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-fR, -fR, -fR)));
assert(ApproxEqual(maxExtent, Vec_t(fR, fR, fR)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
b2.Extent(minExtent, maxExtent);
b2.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-6, -6, -6)));
assert(ApproxEqual(maxExtent, Vec_t(6, 6, 6)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
// Check Surface Normal
Vec_t normal;
......
......@@ -119,6 +119,14 @@ bool TestParaboloid()
valid = p1.Normal(pOutZ, normal);
assert(!valid && ApproxEqual(normal, Vec_t(0, 0, -1.)));
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
p1.Extent(minExtent, maxExtent);
p1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
return true;
}
......
......@@ -69,13 +69,15 @@ bool TestParallelepiped()
std::cout << " surf = " << surf << " mc_estimated = " << surfCheck << std::endl;
assert(std::abs(surf - surfCheck) < 0.01 * surf);
// Check Extent
// Check Extent and cached BBox
std::cout << "=== Check Extent()" << std::endl;
std::cout << "=== Check Extent() and cached BBox" << std::endl;
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
Vec_t minCheck(kInfLength, kInfLength, kInfLength);
Vec_t maxCheck(-kInfLength, -kInfLength, -kInfLength);
para.Extent(minExtent, maxExtent);
para.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
for (int i = 0; i < Npoints; ++i) {
Vec_t p = para.GetUnplacedVolume()->SamplePointOnSurface();
minCheck.Set(std::min(p.x(), minCheck.x()), std::min(p.y(), minCheck.y()), std::min(p.z(), minCheck.z()));
......@@ -90,6 +92,8 @@ bool TestParallelepiped()
assert(std::abs(maxExtent.x() - maxCheck.x()) < 0.001 * std::abs(maxExtent.x()));
assert(std::abs(maxExtent.y() - maxCheck.y()) < 0.001 * std::abs(maxExtent.y()));
assert(maxExtent.z() == maxCheck.z());
assert(ApproxEqual<Precision>(minExtent, minBBox));
assert(ApproxEqual<Precision>(maxExtent, maxBBox));
// Check Inside
......
......@@ -323,16 +323,23 @@ bool TestPolycone()
// std::cout <<"D2I unverified: Line "<< __LINE__ <<", p="<< pbigx <<", dir="<< vxy <<", dist="<<Dist<<"\n";
assert(ApproxEqual<Precision>(Dist, kInfLength));
// CalculateExtent
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
Simple.Extent(minExtent, maxExtent);
Simple.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
// std::cout<<" min="<<minExtent<<" max="<<maxExtent<<std::endl;
assert(ApproxEqual(minExtent, Vec_t(-80, -80, -10)));
assert(ApproxEqual(maxExtent, Vec_t(80, 80, 10)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
MyPCone->Extent(minExtent, maxExtent);
MyPCone->GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
// std::cout<<" min="<<minExtent<<" max="<<maxExtent<<std::endl;
// assert(ApproxEqual(minExtent, Vec_t(-80, -80, -20)));
// assert(ApproxEqual(maxExtent, Vec_t(80, 80, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
#ifdef SCAN_SOLID
......
......@@ -146,13 +146,17 @@ bool TestPolyhedra()
diry = Vec_t(0, 1, 0);
dirz = Vec_t(0, 0, 1);
// CalculateExtent
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
MyPGon->Extent(minExtent, maxExtent);
MyPGon->GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
std::cout << "polyhedra Extent(): min=" << minExtent << " max=" << maxExtent << std::endl;
// In VecGeom the extent is minimal
assert(ApproxEqual(minExtent, Vec_t(0, 0, -30)));
assert(ApproxEqual(maxExtent, Vec_t(80. / cos(halfdphi), 40. * sqrt(2.) / cos(halfdphi), 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
// Check Inside
std::cout << " EInside values: kInside=" << vecgeom::EInside::kInside << ", kSurface=" << vecgeom::EInside::kSurface
......
......@@ -58,13 +58,21 @@ bool TestSphere()
// std::cout<<std::setprecision(12)<<"SurfaceArea of B3 : "<< b3.SurfaceArea() << std::endl;
// std::cout<<"Not : "<< b1.SurfaceArea()/4 << std::endl;
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
b1.Extent(minExtent, maxExtent);
b1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-fR, -fR, -fR)));
assert(ApproxEqual(maxExtent, Vec_t(fR, fR, fR)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
b2.Extent(minExtent, maxExtent);
b2.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-1.5, 0, -3.)));
assert(ApproxEqual(maxExtent, Vec_t(2.59808, 3., 3.)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
// assert(ApproxEqual(minExtent,Vec_t(-6,-6,-6)));
// assert(ApproxEqual(maxExtent,Vec_t( 6, 6, 6)));
......
......@@ -346,16 +346,23 @@ bool TestTessellated()
// return-value = 2.4415531753644804e-15
// CalculateExtent
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
tsl1.Extent(minExtent, maxExtent);
tsl1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
// std::cout<<" min="<<minExtent<<" max="<<maxExtent<<std::endl;
assert(ApproxEqual(minExtent, Vec_t(-20, -30, -40)));
assert(ApproxEqual(maxExtent, Vec_t(20, 30, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
tsl2.Extent(minExtent, maxExtent);
tsl2.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
// std::cout<<" min="<<minExtent<<" max="<<maxExtent<<std::endl;
assert(ApproxEqual(minExtent, Vec_t(-30, -40, -40)));
assert(ApproxEqual(maxExtent, Vec_t(30, 40, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
return true;
}
......
......@@ -52,10 +52,14 @@ bool TestTet()
assert(ApproxEqual<Precision>(vol, 4. / 3.));
Vec_t bmin, bmax;
Vec_t minBBox, maxBBox;
tet.Extent(bmin, bmax);
tet.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
std::cout << "Extent : " << bmin << ", " << bmax << std::endl;
assert(bmin == Vec_t(0., 0., 0.));
assert(bmax == Vec_t(2., 2., 2.));
assert(ApproxEqual(bmin, minBBox));
assert(ApproxEqual(bmax, maxBBox));
// Check Inside()
//
......
......@@ -637,15 +637,22 @@ bool TestTrap()
dist = trap1.DistanceToIn(Vec_t(0, 0, 70), vymz);
assert(ApproxEqual<Precision>(dist, 30.0 * sqrt(2.0)));
// CalculateExtent
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
trap1.Extent(minExtent, maxExtent);
trap1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-20, -30, -40)));
assert(ApproxEqual(maxExtent, Vec_t(20, 30, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
trap2.Extent(minExtent, maxExtent);
trap2.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
assert(ApproxEqual(minExtent, Vec_t(-30, -40, -40)));
assert(ApproxEqual(maxExtent, Vec_t(30, 40, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
#ifndef VECGEOM_NO_SPECIALIZATION
Precision tdz = 5., ttheta = 0., tphi = 0., tdy1 = 4., tdx1 = 3., tdx2 = 3., tAlpha1 = 0., tdy2 = 4., tdx3 = 3.,
......
......@@ -399,16 +399,23 @@ bool TestTrd()
// return-value = 2.4415531753644804e-15
// CalculateExtent
// Check Extent and cached BBox
Vec_t minExtent, maxExtent;
Vec_t minBBox, maxBBox;
trd1.Extent(minExtent, maxExtent);
trd1.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
// std::cout<<" min="<<minExtent<<" max="<<maxExtent<<std::endl;
assert(ApproxEqual(minExtent, Vec_t(-20, -30, -40)));
assert(ApproxEqual(maxExtent, Vec_t(20, 30, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
trd2.Extent(minExtent, maxExtent);
trd2.GetUnplacedVolume()->GetBBox(minBBox, maxBBox);
// std::cout<<" min="<<minExtent<<" max="<<maxExtent<<std::endl;
assert(ApproxEqual(minExtent, Vec_t(-30, -40, -40)));
assert(ApproxEqual(maxExtent, Vec_t(30, 40, 40)));
assert(ApproxEqual(minExtent, minBBox));
assert(ApproxEqual(maxExtent, maxBBox));
// Simple Unit Tests for Factory of Trd.
// Trd_t trdBoxTrd1("Test Trd", 20, 20, 30, 40);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment