Commit 33f9fb50 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Add InstrumentRayTracer class. Also updated names of Geometry::Track related...

Add InstrumentRayTracer class. Also updated names of Geometry::Track related classes and members so that they are easier to read. A fair few changes but worth it for clarity. Re #1212
parent cb403fae
......@@ -276,7 +276,7 @@ double DetectorEfficiencyCor::calculateOneOverK(double loBinBound, double uppBin
*/
void DetectorEfficiencyCor::getDetectorGeometry(boost::shared_ptr<Geometry::IDetector> det, double & detRadius, V3D & detAxis)
{
boost::shared_ptr<const Object> shape_sptr = det->Shape();
boost::shared_ptr<const Object> shape_sptr = det->shape();
std::map<const Geometry::Object *, std::pair<double, Geometry::V3D> >::const_iterator it =
m_shapeCache.find(shape_sptr.get());
if( it == m_shapeCache.end() )
......
......@@ -228,7 +228,7 @@ void He3TubeEfficiency::getDetectorGeometry(\
boost::shared_ptr<Geometry::IDetector> det,
double & detRadius, Geometry::V3D & detAxis)
{
boost::shared_ptr<const Geometry::Object> shape_sptr = det->Shape();
boost::shared_ptr<const Geometry::Object> shape_sptr = det->shape();
std::map<const Geometry::Object *, std::pair<double, Geometry::V3D> >::const_iterator it =
this->shapeCache.find(shape_sptr.get());
if( it == this->shapeCache.end() )
......
......@@ -15,6 +15,7 @@
#include "MantidGeometry/Instrument/Instrument.h"
#include "Poco/Path.h"
using namespace Mantid::Geometry;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataHandling;
......
......@@ -175,7 +175,7 @@
<ClCompile Include="src\Math\Algebra.cpp" />
<ClCompile Include="src\Math\BnId.cpp" />
<ClCompile Include="src\Objects\BoundingBox.cpp" />
<ClCompile Include="src\RayTracer.cpp" />
<ClCompile Include="src\InstrumentRayTracer.cpp" />
<ClCompile Include="src\Rendering\BitmapGeometryHandler.cpp" />
<ClCompile Include="src\Rendering\CacheGeometryGenerator.cpp" />
<ClCompile Include="src\Rendering\CacheGeometryHandler.cpp" />
......@@ -262,7 +262,7 @@
<ClInclude Include="inc\MantidGeometry\IRectangularDetector.h" />
<ClInclude Include="inc\MantidGeometry\Math\Acomp.h" />
<ClInclude Include="inc\MantidGeometry\Objects\BoundingBox.h" />
<ClInclude Include="inc\MantidGeometry\Objects\RayTracer.h" />
<ClInclude Include="inc\MantidGeometry\Objects\InstrumentRayTracer.h" />
<ClInclude Include="inc\MantidGeometry\Rendering\BitmapGeometryHandler.h" />
<ClInclude Include="inc\MantidGeometry\Rendering\OpenCascadeConfig.h" />
<ClInclude Include="test\AcompTest.h" />
......@@ -343,7 +343,7 @@
<ClInclude Include="inc\MantidGeometry\Quat.h" />
<ClInclude Include="test\QuatTest.h" />
<ClInclude Include="inc\MantidGeometry\Math\RegexSupport.h" />
<ClInclude Include="test\RayTracerTest.h" />
<ClInclude Include="test\InstrumentRayTracerTest.h" />
<ClInclude Include="test\RegexSupportTest.h" />
<ClInclude Include="inc\MantidGeometry\Math\RotCounter.h" />
<ClInclude Include="auxinc\RotCounter.h" />
......
......@@ -213,10 +213,10 @@
<ClCompile Include="src\Instrument\ParInstrument.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\RayTracer.cpp">
<ClCompile Include="src\Instrument\ParRectangularDetector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Instrument\ParRectangularDetector.cpp">
<ClCompile Include="src\InstrumentRayTracer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
......@@ -557,16 +557,16 @@
<ClInclude Include="inc\MantidGeometry\Instrument\ParInstrument.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\MantidGeometry\Objects\RayTracer.h">
<ClInclude Include="inc\MantidGeometry\IRectangularDetector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\RayTracerTest.h">
<ClInclude Include="inc\MantidGeometry\Instrument\ParRectangularDetector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\MantidGeometry\IRectangularDetector.h">
<ClInclude Include="inc\MantidGeometry\Objects\InstrumentRayTracer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\MantidGeometry\Instrument\ParRectangularDetector.h">
<ClInclude Include="test\InstrumentRayTracerTest.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
......
......@@ -8,9 +8,9 @@
namespace Mantid
{
namespace Geometry
{
/** @class ICompAssembly
namespace Geometry
{
/** @class ICompAssembly
@brief Class for Assembly of geometric components.
@version A
@author Laurent C Chapon, ISIS RAL
......@@ -39,10 +39,10 @@ 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 DLLExport ICompAssembly : public virtual IComponent
{
public:
*/
class DLLExport ICompAssembly : public virtual IComponent
{
public:
///String description of the type of component
virtual std::string type() const { return "ICompAssembly";}
//ICompAssembly();
......@@ -70,16 +70,18 @@ public:
*/
virtual void printTree(std::ostream&) const = 0;
private:
private:
/// Private copy assignment operator
ICompAssembly& operator=(const ICompAssembly&);
};
};
//DLLExport std::ostream& operator<<(std::ostream&, const CompAssembly&);
/// Shared pointer to a ICompAssembly
typedef boost::shared_ptr<ICompAssembly> ICompAssembly_sptr;
/// Shared pointer to a const ICompAssembly
typedef boost::shared_ptr<const ICompAssembly> ICompAssembly_const_sptr;
} //Namespace Geometry
} //Namespace Geometry
} //Namespace Mantid
#endif
#ifndef MANTID_GEOMETRY_IComponent_H_
#define MANTID_GEOMETRY_IComponent_H_
#ifndef MANTID_GEOMETRY_ICOMPONENT_H_
#define MANTID_GEOMETRY_ICOMPONENT_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/System.h"
#include <string>
#include <vector>
#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
......@@ -20,7 +17,10 @@ namespace Mantid
//---------------------------------------------------------
// Forward declarations
//---------------------------------------------------------
class V3D;
class Quat;
class IComponent;
class BoundingBox;
/// Define a type for a unique component identifier.
typedef IComponent* ComponentID;
......@@ -160,4 +160,4 @@ namespace Mantid
} //Namespace Mantid
#endif /*MANTID_GEOMETRY_IComponent_H_*/
#endif // MANTID_GEOMETRY_ICOMPONENT_H_
......@@ -109,7 +109,7 @@ public:
virtual void initDraw() const = 0;
/// Returns the shape of the Object
virtual const boost::shared_ptr<const Object> Shape()const = 0;
virtual const boost::shared_ptr<const Object> shape()const = 0;
void setScaleFactor(double xFactor,double yFactor, double zFactor);
......
......@@ -14,6 +14,7 @@ namespace Mantid
{
namespace Geometry
{
/** @class CompAssembly
@brief Class for Assembly of geometric components.
@version A
......
......@@ -170,7 +170,7 @@ private:
void initDraw() const{};
/// Returns the shape of the Object
const boost::shared_ptr<const Object> Shape() const
const boost::shared_ptr<const Object> shape() const
{
return boost::shared_ptr<const Object>();
}
......
......@@ -93,6 +93,8 @@ namespace Mantid
/// returns a list containing detector ids of monitors
const std::vector<int> getMonitors()const ;
/// Get the bounding box for this component and store it in the given argument
void getBoundingBox(BoundingBox& boundingBox) const;
/// Get pointers to plottable components
plottables_const_sptr getPlottable() const;
......@@ -109,6 +111,9 @@ namespace Mantid
std::string getDefaultAxis() const {return m_defaultViewAxis;}
/// Retrieves from which side the instrument to be viewed from when the instrument viewer first starts, possiblities are "Z+, Z-, X+, ..."
void setDefaultViewAxis(const std::string &axis) {m_defaultViewAxis = axis;}
// Allow access by index
using CompAssembly::getChild;
private:
friend class ParInstrument;
......@@ -120,6 +125,7 @@ namespace Mantid
/// Static reference to the logger class
static Kernel::Logger& g_log;
/// Get a child by name
Geometry::IComponent* getChild(const std::string& name) const;
/// Add a plottable component
......@@ -147,6 +153,11 @@ namespace Mantid
std::string m_defaultViewAxis;
};
/// Shared pointer to an instrument object
typedef boost::shared_ptr<Instrument> Instrument_sptr;
/// Shared pointer to an const instrument object
typedef boost::shared_ptr<const Instrument> Instrument_const_sptr;
} // namespace Geometry
} //Namespace Mantid
#endif /*MANTID_APIINSTRUMENT_H_*/
......@@ -78,7 +78,7 @@ public:
void drawObject() const;
void initDraw() const;
///returns a shared pointer to the object class
const boost::shared_ptr<const Object> Shape()const{return shape;};
const boost::shared_ptr<const Object> shape()const{return m_shape;};
protected:
......@@ -95,7 +95,7 @@ private:
/// The phyical geometry representation
// Made a const pointer to a const object. Since this is a shared object we shouldn't be
// exposing non-const methods of Object through this class.
const boost::shared_ptr<const Object> shape;
const boost::shared_ptr<const Object> m_shape;
};
......
......@@ -74,6 +74,8 @@ namespace Mantid
/// return reference to detector cache
std::map<int, Geometry::IDetector_sptr> getDetectors() const;
/// Get the bounding box for this component and store it in the given argument
void getBoundingBox(BoundingBox& boundingBox) const;
/// Get pointers to plottable components
virtual plottables_const_sptr getPlottable() const;
......
......@@ -82,7 +82,7 @@ public:
protected:
ParObjComponent(const ParObjComponent&);
const boost::shared_ptr<const Object> Shape()const{return dynamic_cast<const ObjComponent*>(m_base)->Shape();}
const boost::shared_ptr<const Object> shape()const{return dynamic_cast<const ObjComponent*>(m_base)->shape();}
//GeometryHandler* Handle()const{return dynamic_cast<const ObjComponent*>(m_base)->Handle();}
const V3D factorOutComponentPosition(const V3D& point) const;
const V3D takeOutRotation(V3D point) const;
......
......@@ -90,7 +90,7 @@ public:
void initDraw() const;
/// Returns the shape of the Object
const boost::shared_ptr<const Object> Shape() const;
const boost::shared_ptr<const Object> shape() const;
// ------------ End of IObjComponent methods ----------------
......
......@@ -7,6 +7,7 @@
#include "MantidGeometry/Instrument/Parameter.h"
#include "MantidGeometry/Instrument/ParameterFactory.h"
#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Objects/BoundingBox.h"
#ifndef HAS_UNORDERED_MAP_H
#include <map>
......@@ -22,7 +23,10 @@ namespace Mantid
namespace Geometry
{
//class IComponent;
//---------------------------------------------------------------------------
// Forward declarations
//---------------------------------------------------------------------------
class BoundingBox;
/** @class ParameterMap ParameterMap.h
......
......@@ -110,7 +110,7 @@ public:
void initDraw() const;
/// Returns the shape of the Object
const boost::shared_ptr<const Object> Shape() const;
const boost::shared_ptr<const Object> shape() const;
// ------------ End of IObjComponent methods ----------------
......
......@@ -12,6 +12,11 @@ namespace Mantid
namespace Geometry
{
//-------------------------------------------------------------------------
// Forward declarations
//-------------------------------------------------------------------------
class Track;
/**
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.
......@@ -95,6 +100,8 @@ namespace Mantid
//@{
/// Is the given point within the bounding box?
bool isPointInside(const V3D & point) const;
/// Does a specified track intersect the bounding box
bool doesLineIntersect(const Track & track) 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
......
#ifndef MANTID_GEOMETRY_INSTRUMENTRAYTRACER_H_
#define MANTID_GEOMETRY_INSTRUMENTRAYTRACER_H_
//-------------------------------------------------------------
// Includes
//-------------------------------------------------------------
#include "MantidKernel/Logger.h"
#include "MantidGeometry/IInstrument.h"
#include <list>
#include <deque>
namespace Mantid
{
namespace Geometry
{
//-------------------------------------------------------------
// Forward declarations
//-------------------------------------------------------------
struct Link;
class Track;
class V3D;
/**
This class is responsible for tracking rays and accumulating a list of objects that are
intersected along the way.
@author Martyn Gigg, Tessella plc
@date 22/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 InstrumentRayTracer
{
public:
// Result type for trace tests
typedef std::list<Link> TraceResults;
/// Constructor taking an instrument
InstrumentRayTracer(IInstrument_sptr instrument);
/// Trace a given track from the instrument source in the given direction
/// and compile a list of results that this track intersects.
TraceResults trace(const V3D & ray) const;
private:
/// Default constructor
InstrumentRayTracer();
/// Fire the given track at the instrument
void fireRay(Track & testRay) const;
/// Test the physical intersection of a track and any component children
void testIntersectionWithChildren(Track & testRay, ICompAssembly_sptr assembly,
std::deque<IComponent_sptr> & searchQueue) const;
/// Pointer to the instrument
IInstrument_sptr m_instrument;
/// Logger
static Kernel::Logger & g_log;
};
}
}
#endif //MANTID_GEOMETRY_INSTRUMENTRAYTRACER_H_
\ No newline at end of file
......@@ -7,6 +7,7 @@
#include "MantidKernel/System.h"
#include "MantidGeometry/V3D.h"
#include "MantidGeometry/Tolerance.h"
#include "MantidGeometry/IComponent.h"
namespace Mantid
{
......@@ -20,10 +21,11 @@ namespace Mantid
namespace Geometry
{
/*!
\struct TUnit
\version 1.0
\struct Link
\author S. Ansell
\author M. Gigg, Tessella plc
\brief For a leg of a track
Copyright &copy; 2007 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
......@@ -46,20 +48,28 @@ namespace Mantid
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
struct DLLExport TUnit
struct DLLExport Link
{
/**
* Default constructor
*/
inline Link() : entryPoint(),exitPoint(),distFromStart(),
distInsideObject(), componentID(NULL)
{}
/**
* Constuctor
* @param entry V3D point to start
* @param exit V3D point to end track
* @param totalDistance Total distance from start of track
* @param ID ID number
* @param compID An optional component identifier for the physical object hit. (Default=NULL)
*/
inline TUnit(const Geometry::V3D& entry,const Geometry::V3D& exit, const double totalDistance,const int ID) :
entryPoint(entry),exitPoint(exit),distFromStart(totalDistance), distInsideObject(entryPoint.distance(exitPoint)),ObjID(ID)
inline Link(const V3D& entry,const V3D& exit, const double totalDistance, const ComponentID compID = NULL) :
entryPoint(entry),exitPoint(exit),distFromStart(totalDistance), distInsideObject(entryPoint.distance(exitPoint)),
componentID(compID)
{}
/// Less than operator
inline bool operator<(const TUnit& other) const { return distFromStart < other.distFromStart; }
inline bool operator<(const Link& other) const { return distFromStart < other.distFromStart; }
/// Less than operator
inline bool operator<(const double& other) const { return distFromStart < other; }
......@@ -69,51 +79,54 @@ namespace Mantid
V3D exitPoint; ///< Exit point
double distFromStart; ///< Total distance from track beginning
double distInsideObject; ///< Total distance covered inside object
int ObjID; ///< ObjectID
ComponentID componentID; ///< ComponentID of the intersected component
//@}
};
/**
* Stores a point of intersection along a track. The object intersected is linked using its
* ID.
* Stores a point of intersection along a track. The component intersected
* is linked using its ComponentID.
*
* Ordering for TPartial is special since we need
* that when dist is close that the +/- flag is taken into
* Ordering for IntersectionPoint is special since we need that when dist is close
* that the +/- flag is taken into
* account.
*/
struct TPartial
struct IntersectionPoint
{
/**
* Constuctor
* @param ID Object ID number
* @param flag Indicates the direction of travel of the track with respect to the object: +1 is entering, -1 is leaving.
* @param flag Indicates the direction of travel of the track with respect
* to the object: +1 is entering, -1 is leaving.
* @param end The end point for this partial segment
* @param distFromStartOfTrack Total distance from start of track
* @param compID An optional unique ID marking the component intersected. (Default=NULL)
*/
inline TPartial(const int ID,const int directionFlag, const Geometry::V3D& end,const double distFromStartOfTrack) :
ObjID(ID),direction(directionFlag),endPoint(end),distFromStart(distFromStartOfTrack)
inline IntersectionPoint(const int flag, const Geometry::V3D& end,
const double distFromStartOfTrack, const ComponentID compID = NULL) :
directionFlag(flag),endPoint(end),distFromStart(distFromStartOfTrack), componentID(compID)
{}
/**
* A TPartial is less-than another if either
* A IntersectionPoint is less-than another if either
* (a) the difference in distances is greater than the tolerance and this distance is less than the other or
* (b) the distance is less than the other and this point is defined as an exit point
*
* @param other TPartial object to compare
* @param other IntersectionPoint object to compare
* @return True if the object is considered less than, otherwise false.
*/
inline bool operator<(const TPartial& other) const
inline bool operator<(const IntersectionPoint& other) const
{
const double diff = fabs(distFromStart - other.distFromStart);
return (diff > Tolerance) ? distFromStart < other.distFromStart : direction < other.direction;
return (diff > Tolerance) ? distFromStart < other.distFromStart : directionFlag < other.directionFlag;
}
/** @name Attributes. */
//@{
int ObjID; ///< ObjectID
int direction; ///< Directional flag
int directionFlag; ///< Directional flag
V3D endPoint; ///< Point
double distFromStart; ///< Total distance from track begin
ComponentID componentID; ///< Unique component ID
//@}
};
......@@ -126,12 +139,12 @@ namespace Mantid
class DLLExport Track
{
public:
typedef std::vector<TUnit> LType; ///< Type for the Link storage
typedef std::vector<TPartial> PType; ///< Type for the partial
typedef std::vector<Link> LType; ///< Type for the Link storage
typedef std::vector<IntersectionPoint> PType; ///< Type for the partial
public:
/// Constructor
Track(const Geometry::V3D& StartPt,const Geometry::V3D& UV,const int initObj=0);
Track(const V3D& startPt, const V3D& unitVector);
/// Copy constructor
Track(const Track&);
/// Assignment operator
......@@ -139,37 +152,35 @@ namespace Mantid
/// Destructor
~Track();
/// Adds a point of intersection to the track
void addPoint(const int ID,const int Direct,const Geometry::V3D& Pt);
void addPoint(const int directionFlag, const V3D& endPoint, const ComponentID compID = NULL);
/// Adds a link to the track
int addTUnit(const int ID,const Geometry::V3D& Apt,const Geometry::V3D& Bpt,
const double D);
/// Remove touching TUnits that have identical components
void removeCoJoins();
int addLink(const V3D& firstPoint,const V3D& secondPoint,
const double distanceAlongTrack, const ComponentID compID = NULL);
/// Remove touching Links that have identical components
void removeCojoins();
/// Construct links between added points
void buildLink();
/// Reset the track
void setFirst(const Geometry::V3D& startPoint,const Geometry::V3D& direction);
void reset(const Geometry::V3D& startPoint,const Geometry::V3D& direction);
/// Returns the starting point
const Geometry::V3D& getInit() const { return iPt; }
/// Returns the direction
const Geometry::V3D& getUVec() const { return uVec; }