Commit 0802e07a authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Added a BoundingBox class and implemented caching at the CompAssembly level....

Added a BoundingBox class and implemented caching at the CompAssembly level. Note that there are still several functions using the old getBoundingBox methods but this covers a lot of the needed code for the MC correction. Re #1212
parent 42aa385a
......@@ -158,6 +158,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\CreateSampleShape.cpp" />
<ClCompile Include="src\DefineGaugeVolume.cpp" />
<ClCompile Include="src\FindDetectorsInShape.cpp" />
<ClCompile Include="src\GetMaskedDetectors.cpp" />
<ClCompile Include="src\GroupDetectors.cpp" />
......@@ -216,6 +217,7 @@
<ClCompile Include="src\UpdateInstrumentFromRaw.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\MantidDataHandling\DefineGaugeVolume.h" />
<ClInclude Include="inc\mantiddatahandling\getmaskeddetectors.h" />
<ClInclude Include="inc\mantiddatahandling\isisdataarchive.h" />
<ClInclude Include="inc\mantiddatahandling\load.h" />
......
......@@ -186,6 +186,9 @@
<ClCompile Include="src\LoadSpec.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DefineGaugeVolume.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="test\AlignDetectorsTest.h">
......@@ -452,5 +455,8 @@
<ClInclude Include="inc\MantidDataHandling\LoadSpec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\MantidDataHandling\DefineGaugeVolume.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -72,6 +72,7 @@ namespace Mantid
int spectra_nbr = 0;
while(getline(file,str))
{
if (str.empty() ) continue;
if (str[0] == '#' && str[1] == 'L')
{
spectra_nbr++;
......
......@@ -168,6 +168,7 @@
<ClCompile Include="src\Math\Acomp.cpp" />
<ClCompile Include="src\Math\Algebra.cpp" />
<ClCompile Include="src\Math\BnId.cpp" />
<ClCompile Include="src\Objects\BoundingBox.cpp" />
<ClCompile Include="src\Rendering\CacheGeometryGenerator.cpp" />
<ClCompile Include="src\Rendering\CacheGeometryHandler.cpp" />
<ClCompile Include="src\Rendering\CacheGeometryRenderer.cpp" />
......@@ -245,6 +246,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\MantidGeometry\Math\Acomp.h" />
<ClInclude Include="inc\MantidGeometry\Objects\BoundingBox.h" />
<ClInclude Include="inc\MantidGeometry\Rendering\OpenCascadeConfig.h" />
<ClInclude Include="test\AcompTest.h" />
<ClInclude Include="inc\MantidGeometry\Math\Algebra.h" />
......@@ -257,6 +259,7 @@
<ClInclude Include="inc\MantidGeometry\Rendering\CacheGeometryHandler.h" />
<ClInclude Include="inc\MantidGeometry\Rendering\CacheGeometryRenderer.h" />
<ClInclude Include="inc\MantidGeometry\Instrument\CompAssembly.h" />
<ClInclude Include="test\BoundingBoxTest.h" />
<ClInclude Include="test\CompAssemblyTest.h" />
<ClInclude Include="inc\MantidGeometry\Instrument\Component.h" />
<ClInclude Include="test\ComponentTest.h" />
......@@ -369,6 +372,9 @@
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="test\ComponentCreationHelpers.hh" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
......
......@@ -192,6 +192,9 @@
<ClCompile Include="src\Rendering\vtkGeometryCacheWriter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Objects\BoundingBox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\MantidGeometry\Math\Acomp.h">
......@@ -548,5 +551,16 @@
<ClInclude Include="inc\MantidGeometry\Rendering\OpenCascadeConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\MantidGeometry\Objects\BoundingBox.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\BoundingBoxTest.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="test\ComponentCreationHelpers.hh">
<Filter>Header Files</Filter>
</None>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -8,15 +8,24 @@
#include <set>
#include "MantidGeometry/V3D.h"
#include "MantidGeometry/Quat.h"
#include "MantidGeometry/Objects/BoundingBox.h"
#include "MantidKernel/System.h"
#include <boost/shared_ptr.hpp>
namespace Mantid
{
namespace Geometry
{
/** @class IComponent
namespace Geometry
{
//---------------------------------------------------------
// Forward declarations
//---------------------------------------------------------
class IComponent;
/// Define a type for a unique component identifier.
typedef IComponent* ComponentID;
/** @class IComponent
@brief base class for Geometric IComponent
@version A
@author Laurent C Chapon, ISIS RAL
......@@ -50,14 +59,12 @@ namespace Geometry
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class IComponent;
/// Define a type for a unique component identifier.
typedef IComponent* ComponentID;
*/
class DLLExport IComponent
{
public:
class DLLExport IComponent
{
public:
/// Returns a string representation of the IComponent type
virtual std::string type() const {return "LogicalIComponent";}
//! Return a clone to the current object
......@@ -104,6 +111,9 @@ public:
virtual const Quat getRotation() const = 0;
//! Get the distance to another IComponent
virtual double getDistance(const IComponent&) const = 0;
/// Get the bounding box for this component and store it in the given argument
virtual void getBoundingBox(BoundingBox& boundingBox) const = 0;
/** @name ParameterMap access */
//@{
/// Return the names of the parameters for this component
......@@ -124,29 +134,29 @@ public:
/** Prints a text representation of itself
*/
virtual void printSelf(std::ostream&) const = 0;
private:
private:
/// Private, unimplemented copy assignment operator
IComponent& operator=(const IComponent&);
};
};
///Typedef of a shared pointer to a IComponent
typedef boost::shared_ptr<Mantid::Geometry::IComponent> IComponent_sptr;
///Typedef of a shared pointer to a IComponent
typedef boost::shared_ptr<Mantid::Geometry::IComponent> IComponent_sptr;
/** Prints a text representation
/** Prints a text representation
*/
DLLExport std::ostream& operator<<(std::ostream&, const IComponent&);
DLLExport std::ostream& operator<<(std::ostream&, const IComponent&);
} //Namespace Geometry
} //Namespace Geometry
/// An object for constructing a shared_ptr that won't ever delete its pointee
class NoDeleting
{
public:
/// An object for constructing a shared_ptr that won't ever delete its pointee
class NoDeleting
{
public:
/// Does nothing
void operator()(void*){}
/// Does nothing
void operator()(const void*){}
};
};
} //Namespace Mantid
......
......@@ -75,6 +75,8 @@ public:
/// Set the pixel size of the detector (optional)
virtual void setNumPixels(int num_xPixels, int num_yPixels);
/// Get the bounding box for this component and store it in the given argument
virtual void getBoundingBox(BoundingBox& boundingBox) const;
//! Print information about all children
void printChildren(std::ostream&) const;
void printTree(std::ostream&) const;
......@@ -83,13 +85,13 @@ private:
CompAssembly& operator=(const ICompAssembly&);
///the group of child components
std::vector< IComponent* > group;
std::vector< IComponent* > m_children;
/// The number of pixels in the X (horizontal) direction; optional; for area detectors
int xPixels;
/// The number of pixels in the Y (vertical) direction; optional; for area detectors
int yPixels;
/// A cached bounding box
mutable BoundingBox *m_cachedBoundingBox;
};
DLLExport std::ostream& operator<<(std::ostream&, const CompAssembly&);
......
......@@ -110,6 +110,9 @@ namespace Mantid
const Quat getRotation() const;
//! Get the distance to another component
double getDistance(const IComponent&) const;
/// Get the bounding box for this component and store it in the given argument
virtual void getBoundingBox(BoundingBox& boundingBox) const;
/** @name ParamaterMap access */
//@{
// 06/05/2010 MG: Templated virtual functions cannot be defined so we have to resort to
......
......@@ -67,6 +67,8 @@ public:
virtual bool isOnSide(const V3D& point) const;
///Try to find a point that lies within (or on) the object
int getPointInObject(V3D& point) const;
/// Get the bounding box for this component and store it in the given argument
virtual void getBoundingBox(BoundingBox& boundingBox) const;
/// What detectors are contained in the group?
std::vector<int> getDetectorIDs();
......
......@@ -71,6 +71,7 @@ public:
int interceptSurface(Track& track) const;
double solidAngle(const V3D& observer) const;
void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin) const;
void getBoundingBox(BoundingBox& absoluteBB) const;
int getPointInObject(V3D& point) const;
//Rendering member functions
void draw() const;
......
......@@ -66,6 +66,9 @@ public:
/// Set the pixel size of the detector (optional)
virtual void setNumPixels(int num_xPixels, int num_yPixels);
/// Get the bounding box for this assembly and store it in the given argument
virtual void getBoundingBox(BoundingBox& boundingBox) const;
//! Print information about all children
void printChildren(std::ostream&) const;
void printTree(std::ostream&) const;
......
......@@ -71,6 +71,8 @@ public:
int interceptSurface(Track& track) const;
double solidAngle(const V3D& observer) const;
void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin) const;
/// Get the bounding box for this component and store it in the given argument
virtual void getBoundingBox(BoundingBox& boundingBox) const;
int getPointInObject(V3D& point) const;
//Rendering member functions
void draw() const;
......
......@@ -277,19 +277,21 @@ public:
{
m_cacheLocMap.clear();
m_cacheRotMap.clear();
m_boundingBoxMap.clear();
}
///Sets a cached location on the location cache
void setCachedLocation(const IComponent* comp, V3D& location) const;
void setCachedLocation(const IComponent* comp, const V3D& location) const;
///Attempts to retreive a location from the location cache
bool getCachedLocation(const IComponent* comp, V3D& location) const;
///Sets a cached rotation on the rotation cache
void setCachedRotation(const IComponent* comp, Quat& rotation) const;
void setCachedRotation(const IComponent* comp, const Quat& rotation) const;
///Attempts to retreive a rotation from the rotation cache
bool getCachedRotation(const IComponent* comp, Quat& rotation) const;
///Sets a cached bounding box
void setCachedBoundingBox(const IComponent *comp, const BoundingBox & box) const;
///Attempts to retrieve a bounding box from the cache
bool getCachedBoundingBox(const IComponent *comp, BoundingBox & box) const;
private:
///Assignment operator
......@@ -303,7 +305,8 @@ private:
mutable Kernel::Cache<const ComponentID,V3D > m_cacheLocMap;
/// internal cache map instance for cached rotation values
mutable Kernel::Cache<const ComponentID,Quat > m_cacheRotMap;
///internal cache map for cached bounding boxes
mutable Kernel::Cache<const ComponentID,BoundingBox> m_boundingBoxMap;
/// Static reference to the logger class
static Kernel::Logger& g_log;
};
......
......@@ -116,6 +116,9 @@ namespace Mantid
//! Get the distance to another IComponent
double getDistance(const IComponent&) const;
/// Get the bounding box for this component and store it in the given argument
virtual void getBoundingBox(BoundingBox& boundingBox) const;
/** @name ParamaterMap access */
//@{
// 06/05/2010 MG: Templated virtual functions cannot be defined so we have to resort to
......
#ifndef MANTIDGEOMETRY_BOUNDINGBOX_H_
#define MANTIDGEOMETRY_BOUNDINGBOX_H_
#include "MantidKernel/Exception.h"
#include "MantidGeometry/Tolerance.h"
#include "MantidGeometry/V3D.h"
#include <boost/shared_ptr.hpp>
#include <sstream>
namespace Mantid
{
namespace Geometry
{
/**
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
It is a thin structure containing the 6 points that define the corners of the cuboid.
@author Martyn Gigg
@date 01/10/2010
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport BoundingBox
{
public:
/// Default constructor constructs a zero-sized box
BoundingBox() : m_maxPoint(), m_minPoint()
{
}
/** Constructor taking six points. If inconsistent points are defined, i.e. xmin > xmax, then an error is thrown
* @param xmax Value of maximum in X. It must be greater than xmin.
* @param ymax Value of maximum in Y. It must be greater than ymin.
* @param zmax Value of maximum in Z. It must be greater than zmin.
* @param xmin Value of minimum in X. It must be less than xmax.
* @param ymin Value of minimum in Y. It must be less than ymax.
* @param zmin Value of minimum in Z. It must be less than zmax.
*/
BoundingBox(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin)
: m_maxPoint(xmax, ymax, zmax), m_minPoint(xmin,ymin,zmin)
{
// Sanity check
if( xmax < xmin || ymax < ymin || zmax < zmin )
{
std::ostringstream error;
error << "Error creating bounding box, inconsistent values given:\n\t"
<< "xmin=" << xmin << ", xmax=" << xmax << "\n"
<< "ymin=" << ymin << ", ymax=" << ymax << "\n"
<< "zmin=" << zmin << ", zmax=" << zmax << "\n";
throw std::invalid_argument(error.str());
}
}
/** @name Point access */
//@{
/// Return the minimum value of X
inline const double & xMin() const { return m_minPoint.X(); }
/// Return the maximum value of X
inline const double & xMax() const { return m_maxPoint.X(); }
/// Return the minimum value of Y
inline const double & yMin() const { return m_minPoint.Y(); }
/// Return the maximum value of Y
inline const double & yMax() const { return m_maxPoint.Y(); }
/// Return the minimum value of Z
inline const double & zMin() const { return m_minPoint.Z(); }
/// Return the maximum value of Z
inline const double & zMax() const { return m_maxPoint.Z(); }
/// Returns the min point of the box
inline const V3D & minPoint() const { return m_minPoint; }
/// Returns the min point of the box
inline const V3D & maxPoint() const { return m_maxPoint; }
/// Returns the centre of the bounding box
inline V3D centrePoint() const { return Geometry::V3D(0.5*(xMax() + xMin()), 0.5*(yMax() + yMin()), 0.5*(zMax() + zMin())); }
//@}
/** @name Querying */
//@{
/// Is the given point within the bounding box?
bool isPointInside(const V3D & point) const;
/// Does a line intersect the bounding box
bool doesLineIntersect(const V3D & startPoint, const V3D & lineDir) const;
/// Calculate the angular half width from the given point
double angularWidth(const V3D & observer) const;
//@}
/** @name Box mutation functions*/
//@{
/// Return the minimum value of X (non-const)
inline double & xMin() { return m_minPoint[0]; }
/// Return the maximum value of X (non-const)
inline double & xMax() { return m_maxPoint[0]; }
/// Return the minimum value of Y (non-const)
inline double & yMin() { return m_minPoint[1]; }
/// Return the maximum value of Y (non-const)
inline double & yMax() { return m_maxPoint[1]; }
/// Return the minimum value of Z (non-const)
inline double & zMin() { return m_minPoint[2]; }
/// Return the maximum value of Z (non-const)
inline double & zMax() { return m_maxPoint[2]; }
/// Grow the bounding box so that it also encompasses the given box
void grow(const BoundingBox & other);
//@}
private:
/// The minimum point of the axis-aligned box
V3D m_minPoint;
/// The maximum point of the axis-aligned box
V3D m_maxPoint;
};
/// A shared pointer to a BoundingBox
typedef boost::shared_ptr<BoundingBox> BoundingBox_sptr;
/// A shared pointer to a const BoundingBox
typedef boost::shared_ptr<const BoundingBox> BoundingBox_const_sptr;
}
}
#endif //MANTIDGEOMETRY_BOUNDINGBOX_H_
\ No newline at end of file
......@@ -32,6 +32,7 @@ namespace Mantid
class CacheGeometryHandler;
class vtkGeometryCacheReader;
class vtkGeometryCacheWriter;
class BoundingBox;
/*!
\class Object
......@@ -78,6 +79,9 @@ namespace Mantid
int procPair(std::string& Ln,std::map<int,Rule*>& Rlist,int& compUnit) const;
CompGrp* procComp(Rule*) const;
int checkSurfaceValid(const Geometry::V3D&,const Geometry::V3D&) const;
boost::shared_ptr<BoundingBox> m_boundingBox;
// -- DEPRECATED --
mutable double AABBxMax, ///< xmax of Axis aligned bounding box cache
AABByMax, ///< ymax of Axis aligned bounding box cache
AABBzMax, ///< zmax of Axis aligned bounding box cache
......@@ -85,16 +89,9 @@ namespace Mantid
AABByMin, ///< xmin of Axis aligned bounding box cache
AABBzMin; ///< zmin of Axis Aligned Bounding Box Cache
mutable bool boolBounded; ///< flag true if a bounding box exists, either by getBoundingBox or defineBoundingBox
// -- --
int searchForObject(Geometry::V3D&) const;
int inBoundingBox(const Geometry::V3D&,
const double&, const double&, const double&,
const double&, const double&, const double& ) const;
int lineHitsBoundingBox(const Geometry::V3D&, const Geometry::V3D&,
const double&, const double&, const double&,
const double&, const double&, const double& ) const;
double bbAngularWidth(const Geometry::V3D&,
const double&, const double&, const double&,
const double&, const double&, const double& ) const;
double getTriangleSolidAngle(const V3D& a, const V3D& b, const V3D& c, const V3D& observer) const;
double CuboidSolidAngle(const V3D observer, const std::vector<Geometry::V3D> vectors) const;
double SphereSolidAngle(const V3D observer, const std::vector<Geometry::V3D> vectors, const double radius) const;
......@@ -160,9 +157,9 @@ namespace Mantid
virtual void print() const;
void printTree() const;
int isValid(const Geometry::V3D&) const; ///< Check if a point is valid
int isValid(const std::map<int,int>&) const; ///< Check if a set of surfaces are valid.
int isOnSide(const Geometry::V3D&) const;
bool isValid(const Geometry::V3D&) const; ///< Check if a point is valid
bool isValid(const std::map<int,int>&) const; ///< Check if a set of surfaces are valid.
bool isOnSide(const Geometry::V3D&) const;
int calcValidType(const Geometry::V3D& Pt,const Geometry::V3D& uVec) const;
std::vector<int> getSurfaceIndex() const;
......@@ -191,10 +188,12 @@ namespace Mantid
// solid angle via ray tracing
double rayTraceSolidAngle(const Geometry::V3D& observer) const;
// Calculate (or return cached value of) Axis Aligned Bounding box
/// Calculate (or return cached value of) Axis Aligned Bounding box (DEPRECATED)
void getBoundingBox(double& xmax,double& ymax,double& zmax,double& xmin,double& ymin,double& zmin) const;
// Define Axis Aligned Bounding box
/// Calculate (or return cached value of) axis-aligned bounding box
boost::shared_ptr<BoundingBox> Object::getBoundingBox() const;
/// Define axis-aligned bounding box
void defineBoundingBox(const double& xmax,const double& ymax,const double& zmax,const double& xmin,const double& ymin,const double& zmin);
// find internal point to object
......
......@@ -86,9 +86,9 @@ namespace Mantid
/// Abstract: The point is within the object
virtual int isValid(const Geometry::V3D&) const =0;
virtual bool isValid(const Geometry::V3D&) const = 0;
/// Abstract Validity based on surface true/false map
virtual int isValid(const std::map<int,int>&) const =0;
virtual bool isValid(const std::map<int,int>&) const = 0;
/// Abstract: Can the rule be simplified
virtual int simplify() =0;
......@@ -148,8 +148,8 @@ namespace Mantid
std::string display() const;
std::string displayAddress() const;
int isValid(const Geometry::V3D&) const;
int isValid(const std::map<int,int>&) const;
bool isValid(const Geometry::V3D&) const;
bool isValid(const std::map<int,int>&) const;
int simplify(); ///< apply general intersection simplification
void getBoundingBox(double &xmax,double &ymax,double &zmax,double &xmin,double &ymin,double &zmin); ///bounding box
};
......@@ -198,8 +198,8 @@ namespace Mantid
int type() const { return -1; } ///< effective name
int isValid(const Geometry::V3D&) const;
int isValid(const std::map<int,int>&) const;
bool isValid(const Geometry::V3D&) const;
bool isValid(const std::map<int,int>&) const;
std::string display() const;
std::string displayAddress() const;
int simplify(); ///< apply general intersection simplification
......@@ -247,8 +247,8 @@ namespace Mantid
void setKeyN(const int Ky); ///< set keyNumber
void setKey(Surface*);
int isValid(const Geometry::V3D&) const;
int isValid(const std::map<int,int>&) const;
bool isValid(const Geometry::V3D&) const;
bool isValid(const std::map<int,int>&) const;
int getSign() const { return sign; } ///< Get Sign
int getKeyN() const { return keyN; } ///< Get Key
int simplify();
......@@ -299,8 +299,8 @@ namespace Mantid
void setObjN(const int Ky); ///< set object Number
void setObj(Object*); ///< Set a Object state
int isValid(const Geometry::V3D&) const;
int isValid(const std::map<int,int>&) const;
bool isValid(const Geometry::V3D&) const;
bool isValid(const std::map<int,int>&) const;
/// Get object number of component
int getObjN() const { return objN; }
int simplify();
......@@ -351,8 +351,8 @@ namespace Mantid
int type() const { return 0; } ///< Is it a branched object
int isComplementary() const { return 1