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 ...@@ -276,7 +276,7 @@ double DetectorEfficiencyCor::calculateOneOverK(double loBinBound, double uppBin
*/ */
void DetectorEfficiencyCor::getDetectorGeometry(boost::shared_ptr<Geometry::IDetector> det, double & detRadius, V3D & detAxis) 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 = std::map<const Geometry::Object *, std::pair<double, Geometry::V3D> >::const_iterator it =
m_shapeCache.find(shape_sptr.get()); m_shapeCache.find(shape_sptr.get());
if( it == m_shapeCache.end() ) if( it == m_shapeCache.end() )
......
...@@ -228,7 +228,7 @@ void He3TubeEfficiency::getDetectorGeometry(\ ...@@ -228,7 +228,7 @@ void He3TubeEfficiency::getDetectorGeometry(\
boost::shared_ptr<Geometry::IDetector> det, boost::shared_ptr<Geometry::IDetector> det,
double & detRadius, Geometry::V3D & detAxis) 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 = std::map<const Geometry::Object *, std::pair<double, Geometry::V3D> >::const_iterator it =
this->shapeCache.find(shape_sptr.get()); this->shapeCache.find(shape_sptr.get());
if( it == this->shapeCache.end() ) if( it == this->shapeCache.end() )
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "MantidGeometry/Instrument/Instrument.h" #include "MantidGeometry/Instrument/Instrument.h"
#include "Poco/Path.h" #include "Poco/Path.h"
using namespace Mantid::Geometry;
using namespace Mantid::API; using namespace Mantid::API;
using namespace Mantid::Kernel; using namespace Mantid::Kernel;
using namespace Mantid::DataHandling; using namespace Mantid::DataHandling;
......
...@@ -175,7 +175,7 @@ ...@@ -175,7 +175,7 @@
<ClCompile Include="src\Math\Algebra.cpp" /> <ClCompile Include="src\Math\Algebra.cpp" />
<ClCompile Include="src\Math\BnId.cpp" /> <ClCompile Include="src\Math\BnId.cpp" />
<ClCompile Include="src\Objects\BoundingBox.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\BitmapGeometryHandler.cpp" />
<ClCompile Include="src\Rendering\CacheGeometryGenerator.cpp" /> <ClCompile Include="src\Rendering\CacheGeometryGenerator.cpp" />
<ClCompile Include="src\Rendering\CacheGeometryHandler.cpp" /> <ClCompile Include="src\Rendering\CacheGeometryHandler.cpp" />
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
<ClInclude Include="inc\MantidGeometry\IRectangularDetector.h" /> <ClInclude Include="inc\MantidGeometry\IRectangularDetector.h" />
<ClInclude Include="inc\MantidGeometry\Math\Acomp.h" /> <ClInclude Include="inc\MantidGeometry\Math\Acomp.h" />
<ClInclude Include="inc\MantidGeometry\Objects\BoundingBox.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\BitmapGeometryHandler.h" />
<ClInclude Include="inc\MantidGeometry\Rendering\OpenCascadeConfig.h" /> <ClInclude Include="inc\MantidGeometry\Rendering\OpenCascadeConfig.h" />
<ClInclude Include="test\AcompTest.h" /> <ClInclude Include="test\AcompTest.h" />
...@@ -343,7 +343,7 @@ ...@@ -343,7 +343,7 @@
<ClInclude Include="inc\MantidGeometry\Quat.h" /> <ClInclude Include="inc\MantidGeometry\Quat.h" />
<ClInclude Include="test\QuatTest.h" /> <ClInclude Include="test\QuatTest.h" />
<ClInclude Include="inc\MantidGeometry\Math\RegexSupport.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="test\RegexSupportTest.h" />
<ClInclude Include="inc\MantidGeometry\Math\RotCounter.h" /> <ClInclude Include="inc\MantidGeometry\Math\RotCounter.h" />
<ClInclude Include="auxinc\RotCounter.h" /> <ClInclude Include="auxinc\RotCounter.h" />
......
...@@ -213,10 +213,10 @@ ...@@ -213,10 +213,10 @@
<ClCompile Include="src\Instrument\ParInstrument.cpp"> <ClCompile Include="src\Instrument\ParInstrument.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\RayTracer.cpp"> <ClCompile Include="src\Instrument\ParRectangularDetector.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Instrument\ParRectangularDetector.cpp"> <ClCompile Include="src\InstrumentRayTracer.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
...@@ -557,16 +557,16 @@ ...@@ -557,16 +557,16 @@
<ClInclude Include="inc\MantidGeometry\Instrument\ParInstrument.h"> <ClInclude Include="inc\MantidGeometry\Instrument\ParInstrument.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="inc\MantidGeometry\Objects\RayTracer.h"> <ClInclude Include="inc\MantidGeometry\IRectangularDetector.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="test\RayTracerTest.h"> <ClInclude Include="inc\MantidGeometry\Instrument\ParRectangularDetector.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="inc\MantidGeometry\IRectangularDetector.h"> <ClInclude Include="inc\MantidGeometry\Objects\InstrumentRayTracer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="inc\MantidGeometry\Instrument\ParRectangularDetector.h"> <ClInclude Include="test\InstrumentRayTracerTest.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
namespace Mantid namespace Mantid
{ {
namespace Geometry namespace Geometry
{ {
/** @class ICompAssembly /** @class ICompAssembly
@brief Class for Assembly of geometric components. @brief Class for Assembly of geometric components.
@version A @version A
@author Laurent C Chapon, ISIS RAL @author Laurent C Chapon, ISIS RAL
...@@ -39,47 +39,49 @@ namespace Geometry ...@@ -39,47 +39,49 @@ namespace Geometry
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org> Code Documentation is available at: <http://doxygen.mantidproject.org>
*/ */
class DLLExport ICompAssembly : public virtual IComponent class DLLExport ICompAssembly : public virtual IComponent
{ {
public: public:
///String description of the type of component ///String description of the type of component
virtual std::string type() const { return "ICompAssembly";} virtual std::string type() const { return "ICompAssembly";}
//ICompAssembly(); //ICompAssembly();
virtual ~ICompAssembly(){}
//! Make a clone of the present component
virtual IComponent* clone() const = 0;
//! Return the number of elements in the assembly
virtual int nelements() const = 0;
//! Add a component to the assembly
virtual int add(IComponent*) = 0;
//! Add a copy (clone) of a component
virtual int addCopy(IComponent*) = 0;
//! Add a copy (clone) of a component and rename it
virtual int addCopy(IComponent*, const std::string&) = 0;
//! Get a pointer to the ith component within the assembly. Easier to use than [] when you have a pointer
virtual boost::shared_ptr<IComponent> getChild(const int i) const = 0;
//! Overloaded index operator. Get a pointer to the ith component in the assembly
virtual boost::shared_ptr<IComponent> operator[](int i) const = 0;
//! Print information about all children
virtual void printChildren(std::ostream&) const = 0;
/*! Print information about all the elements in the tree to a stream
* Loops through all components in the tree
* and call printSelf(os).
*/
virtual void printTree(std::ostream&) const = 0;
private: virtual ~ICompAssembly(){}
/// Private copy assignment operator //! Make a clone of the present component
ICompAssembly& operator=(const ICompAssembly&); virtual IComponent* clone() const = 0;
//! Return the number of elements in the assembly
virtual int nelements() const = 0;
//! Add a component to the assembly
virtual int add(IComponent*) = 0;
//! Add a copy (clone) of a component
virtual int addCopy(IComponent*) = 0;
//! Add a copy (clone) of a component and rename it
virtual int addCopy(IComponent*, const std::string&) = 0;
//! Get a pointer to the ith component within the assembly. Easier to use than [] when you have a pointer
virtual boost::shared_ptr<IComponent> getChild(const int i) const = 0;
//! Overloaded index operator. Get a pointer to the ith component in the assembly
virtual boost::shared_ptr<IComponent> operator[](int i) const = 0;
//! Print information about all children
virtual void printChildren(std::ostream&) const = 0;
/*! Print information about all the elements in the tree to a stream
* Loops through all components in the tree
* and call printSelf(os).
*/
virtual void printTree(std::ostream&) const = 0;
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 } //Namespace Mantid
#endif #endif
#ifndef MANTID_GEOMETRY_IComponent_H_ #ifndef MANTID_GEOMETRY_ICOMPONENT_H_
#define MANTID_GEOMETRY_IComponent_H_ #define MANTID_GEOMETRY_ICOMPONENT_H_
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Includes // Includes
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#include "MantidKernel/System.h"
#include <string> #include <string>
#include <vector>
#include <set> #include <set>
#include "MantidGeometry/V3D.h"
#include "MantidGeometry/Quat.h"
#include "MantidGeometry/Objects/BoundingBox.h"
#include "MantidKernel/System.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
namespace Mantid namespace Mantid
...@@ -20,7 +17,10 @@ namespace Mantid ...@@ -20,7 +17,10 @@ namespace Mantid
//--------------------------------------------------------- //---------------------------------------------------------
// Forward declarations // Forward declarations
//--------------------------------------------------------- //---------------------------------------------------------
class V3D;
class Quat;
class IComponent; class IComponent;
class BoundingBox;
/// Define a type for a unique component identifier. /// Define a type for a unique component identifier.
typedef IComponent* ComponentID; typedef IComponent* ComponentID;
...@@ -160,4 +160,4 @@ namespace Mantid ...@@ -160,4 +160,4 @@ namespace Mantid
} //Namespace Mantid } //Namespace Mantid
#endif /*MANTID_GEOMETRY_IComponent_H_*/ #endif // MANTID_GEOMETRY_ICOMPONENT_H_
...@@ -109,7 +109,7 @@ public: ...@@ -109,7 +109,7 @@ public:
virtual void initDraw() const = 0; virtual void initDraw() const = 0;
/// Returns the shape of the Object /// 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); void setScaleFactor(double xFactor,double yFactor, double zFactor);
......
...@@ -14,6 +14,7 @@ namespace Mantid ...@@ -14,6 +14,7 @@ namespace Mantid
{ {
namespace Geometry namespace Geometry
{ {
/** @class CompAssembly /** @class CompAssembly
@brief Class for Assembly of geometric components. @brief Class for Assembly of geometric components.
@version A @version A
......
...@@ -170,7 +170,7 @@ private: ...@@ -170,7 +170,7 @@ private:
void initDraw() const{}; void initDraw() const{};
/// Returns the shape of the Object /// 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>(); return boost::shared_ptr<const Object>();
} }
......
...@@ -93,6 +93,8 @@ namespace Mantid ...@@ -93,6 +93,8 @@ namespace Mantid
/// returns a list containing detector ids of monitors /// returns a list containing detector ids of monitors
const std::vector<int> getMonitors()const ; 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 /// Get pointers to plottable components
plottables_const_sptr getPlottable() const; plottables_const_sptr getPlottable() const;
...@@ -109,6 +111,9 @@ namespace Mantid ...@@ -109,6 +111,9 @@ namespace Mantid
std::string getDefaultAxis() const {return m_defaultViewAxis;} 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+, ..." /// 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;} void setDefaultViewAxis(const std::string &axis) {m_defaultViewAxis = axis;}
// Allow access by index
using CompAssembly::getChild;
private: private:
friend class ParInstrument; friend class ParInstrument;
...@@ -120,6 +125,7 @@ namespace Mantid ...@@ -120,6 +125,7 @@ namespace Mantid
/// Static reference to the logger class /// Static reference to the logger class
static Kernel::Logger& g_log; static Kernel::Logger& g_log;
/// Get a child by name
Geometry::IComponent* getChild(const std::string& name) const; Geometry::IComponent* getChild(const std::string& name) const;
/// Add a plottable component /// Add a plottable component
...@@ -147,6 +153,11 @@ namespace Mantid ...@@ -147,6 +153,11 @@ namespace Mantid
std::string m_defaultViewAxis; 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 Geometry
} //Namespace Mantid } //Namespace Mantid
#endif /*MANTID_APIINSTRUMENT_H_*/ #endif /*MANTID_APIINSTRUMENT_H_*/
...@@ -78,7 +78,7 @@ public: ...@@ -78,7 +78,7 @@ public:
void drawObject() const; void drawObject() const;
void initDraw() const; void initDraw() const;
///returns a shared pointer to the object class ///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: protected:
...@@ -95,7 +95,7 @@ private: ...@@ -95,7 +95,7 @@ private:
/// The phyical geometry representation /// The phyical geometry representation
// Made a const pointer to a const object. Since this is a shared object we shouldn't be // 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. // 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 ...@@ -74,6 +74,8 @@ namespace Mantid
/// return reference to detector cache /// return reference to detector cache
std::map<int, Geometry::IDetector_sptr> getDetectors() const; 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 /// Get pointers to plottable components
virtual plottables_const_sptr getPlottable() const; virtual plottables_const_sptr getPlottable() const;
......
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
protected: protected:
ParObjComponent(const ParObjComponent&); 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();} //GeometryHandler* Handle()const{return dynamic_cast<const ObjComponent*>(m_base)->Handle();}
const V3D factorOutComponentPosition(const V3D& point) const; const V3D factorOutComponentPosition(const V3D& point) const;
const V3D takeOutRotation(V3D point) const; const V3D takeOutRotation(V3D point) const;
......
...@@ -90,7 +90,7 @@ public: ...@@ -90,7 +90,7 @@ public:
void initDraw() const; void initDraw() const;
/// Returns the shape of the Object /// 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 ---------------- // ------------ End of IObjComponent methods ----------------
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "MantidGeometry/Instrument/Parameter.h" #include "MantidGeometry/Instrument/Parameter.h"
#include "MantidGeometry/Instrument/ParameterFactory.h" #include "MantidGeometry/Instrument/ParameterFactory.h"
#include "MantidGeometry/IComponent.h" #include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Objects/BoundingBox.h"
#ifndef HAS_UNORDERED_MAP_H #ifndef HAS_UNORDERED_MAP_H
#include <map> #include <map>
...@@ -22,7 +23,10 @@ namespace Mantid ...@@ -22,7 +23,10 @@ namespace Mantid
namespace Geometry namespace Geometry
{ {
//class IComponent; //---------------------------------------------------------------------------
// Forward declarations
//---------------------------------------------------------------------------
class BoundingBox;
/** @class ParameterMap ParameterMap.h /** @class ParameterMap ParameterMap.h
......
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
void initDraw() const; void initDraw() const;
/// Returns the shape of the Object /// 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 ---------------- // ------------ End of IObjComponent methods ----------------
......
...@@ -12,6 +12,11 @@ namespace Mantid ...@@ -12,6 +12,11 @@ namespace Mantid
namespace Geometry namespace Geometry
{ {
//-------------------------------------------------------------------------
// Forward declarations
//-------------------------------------------------------------------------
class Track;
/** /**
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object. 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. It is a thin structure containing the 6 points that define the corners of the cuboid.
...@@ -95,6 +100,8 @@ namespace Mantid ...@@ -95,6 +100,8 @@ namespace Mantid
//@{ //@{
/// Is the given point within the bounding box? /// Is the given point within the bounding box?
bool isPointInside(const V3D & point) const; 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 /// Does a line intersect the bounding box
bool doesLineIntersect(const V3D & startPoint, const V3D & lineDir) const; bool doesLineIntersect(const V3D & startPoint, const V3D & lineDir) const;
/// Calculate the angular half width from the given point /// 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>