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,103 +59,104 @@ 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:
/// Returns a string representation of the IComponent type
virtual std::string type() const {return "LogicalIComponent";}
//! Return a clone to the current object
virtual IComponent* clone() const=0;
/// Destructor
virtual ~IComponent(){}
//! Returns the ComponentID - a unique identifier of the component.
virtual ComponentID getComponentID()const = 0;
//! Assign a parent IComponent. Previous parent link is lost
virtual void setParent(IComponent*)= 0;
//! Return a pointer to the current parent.
virtual boost::shared_ptr<const IComponent> getParent() const = 0;
//! Return an array of all ancestors, the nearest first
virtual std::vector<boost::shared_ptr<const IComponent> > getAncestors() const = 0;
//! Set the IComponent name
virtual void setName(const std::string&) = 0;
//! Get the IComponent name
virtual std::string getName() const = 0;
//! Set the IComponent position, x, y, z respective to parent (if present) otherwise absolute
virtual void setPos(double, double, double) = 0;
/*! Set the position of the component
* The position is with respect to the parent component
*/
virtual void setPos(const V3D&) = 0;
//! Set the orientation quaternion relative to parent (if present) otherwise absolute
virtual void setRot(const Quat&) = 0;
//! Copy the Rotation from another IComponent
virtual void copyRot(const IComponent&) = 0;
//! Translate the IComponent (vector form). This is relative to parent if present.
virtual void translate(const V3D&) = 0;
//! Translate the IComponent (x,y,z form). This is relative to parent if present.
virtual void translate(double, double, double) = 0;
//! Rotate the IComponent. This is relative to parent.
virtual void rotate(const Quat&) = 0;
//! Rotate the IComponent by an angle in degrees with respect to an axis.
virtual void rotate(double,const V3D&) = 0;
//! Get the position relative to the parent IComponent (absolute if no parent)
virtual V3D getRelativePos() const = 0;
//! Get the position of the IComponent. Tree structure is traverse through the parent chain
virtual V3D getPos() const = 0;
//! Get the relative Orientation
virtual const Quat& getRelativeRot() const = 0;
//! Get the absolute orientation of the IComponent
virtual const Quat getRotation() const = 0;
//! Get the distance to another IComponent
virtual double getDistance(const IComponent&) const = 0;
/** @name ParameterMap access */
//@{
/// Return the names of the parameters for this component
virtual std::set<std::string> getParameterNames(bool recursive = true) const = 0;
/// Returns a boolean indicating if the component has the named parameter
virtual bool hasParameter(const std::string & name, bool recursive = true) const = 0;
// 06/05/2010 MG: Templated virtual functions cannot be defined so we have to resort to
// one for each type, luckily there won't be too many
/// Get a parameter defined as a double
virtual std::vector<double> getNumberParameter(const std::string& pname, bool recursive = true) const = 0;
/// Get a parameter defined as a V3D
virtual std::vector<V3D> getPositionParameter(const std::string& pname, bool recursive = true) const = 0;
/// Get a parameter defined as a Quaternion
virtual std::vector<Quat> getRotationParameter(const std::string& pname, bool recursive = true) const = 0;
/// Get a parameter defined as a string
virtual std::vector<std::string> getStringParameter(const std::string& pname, bool recursive = true) const = 0;
//@}
/** Prints a text representation of itself
*/
virtual void printSelf(std::ostream&) const = 0;
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;
/** Prints a text representation
*/
DLLExport std::ostream& operator<<(std::ostream&, const IComponent&);
} //Namespace Geometry
/// 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*){}
};
*/
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
virtual IComponent* clone() const=0;
/// Destructor
virtual ~IComponent(){}
//! Returns the ComponentID - a unique identifier of the component.
virtual ComponentID getComponentID()const = 0;
//! Assign a parent IComponent. Previous parent link is lost
virtual void setParent(IComponent*)= 0;
//! Return a pointer to the current parent.
virtual boost::shared_ptr<const IComponent> getParent() const = 0;
//! Return an array of all ancestors, the nearest first
virtual std::vector<boost::shared_ptr<const IComponent> > getAncestors() const = 0;
//! Set the IComponent name
virtual void setName(const std::string&) = 0;
//! Get the IComponent name
virtual std::string getName() const = 0;
//! Set the IComponent position, x, y, z respective to parent (if present) otherwise absolute
virtual void setPos(double, double, double) = 0;
/*! Set the position of the component
* The position is with respect to the parent component
*/
virtual void setPos(const V3D&) = 0;
//! Set the orientation quaternion relative to parent (if present) otherwise absolute
virtual void setRot(const Quat&) = 0;
//! Copy the Rotation from another IComponent
virtual void copyRot(const IComponent&) = 0;
//! Translate the IComponent (vector form). This is relative to parent if present.
virtual void translate(const V3D&) = 0;
//! Translate the IComponent (x,y,z form). This is relative to parent if present.
virtual void translate(double, double, double) = 0;
//! Rotate the IComponent. This is relative to parent.
virtual void rotate(const Quat&) = 0;
//! Rotate the IComponent by an angle in degrees with respect to an axis.
virtual void rotate(double,const V3D&) = 0;
//! Get the position relative to the parent IComponent (absolute if no parent)
virtual V3D getRelativePos() const = 0;
//! Get the position of the IComponent. Tree structure is traverse through the parent chain
virtual V3D getPos() const = 0;
//! Get the relative Orientation
virtual const Quat& getRelativeRot() const = 0;
//! Get the absolute orientation of the IComponent
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
virtual std::set<std::string> getParameterNames(bool recursive = true) const = 0;
/// Returns a boolean indicating if the component has the named parameter
virtual bool hasParameter(const std::string & name, bool recursive = true) const = 0;
// 06/05/2010 MG: Templated virtual functions cannot be defined so we have to resort to
// one for each type, luckily there won't be too many
/// Get a parameter defined as a double
virtual std::vector<double> getNumberParameter(const std::string& pname, bool recursive = true) const = 0;
/// Get a parameter defined as a V3D
virtual std::vector<V3D> getPositionParameter(const std::string& pname, bool recursive = true) const = 0;
/// Get a parameter defined as a Quaternion
virtual std::vector<Quat> getRotationParameter(const std::string& pname, bool recursive = true) const = 0;
/// Get a parameter defined as a string
virtual std::vector<std::string> getStringParameter(const std::string& pname, bool recursive = true) const = 0;
//@}
/** Prints a text representation of itself
*/
virtual void printSelf(std::ostream&) const = 0;
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;
/** Prints a text representation
*/
DLLExport std::ostream& operator<<(std::ostream&, const IComponent&);
} //Namespace Geometry
/// 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
......
......@@ -88,7 +88,7 @@ public:
* @param zmin :: Minimum value for the bounding box in z direction
*/
virtual void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin) const = 0;
///Try to find a point that lies within (or on) the object
virtual int getPointInObject(V3D& point) const = 0;
......
......@@ -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)