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

More updates to geometry for ray tracing/Monte Carlo framework, Re #1212.

Removed unused material fields from Object class, Re #1735
parent 0838697e
......@@ -312,7 +312,7 @@ void AbsorptionCorrection::calculateDistances(const Geometry::IDetector_const_sp
}
else // The normal situation
{
L2s[i] = outgoing.begin()->Dist;
L2s[i] = outgoing.begin()->distFromStart;
}
}
}
......
......@@ -108,7 +108,7 @@ void AnyShapeAbsorption::initialiseCachedDistances()
// the element in this case.
if ( m_sampleObject->interceptSurface(incoming) > 0 )
{
m_L1s.push_back(incoming.begin()->Dist);
m_L1s.push_back(incoming.begin()->distFromStart);
m_elementPositions.push_back(currentPosition);
// Also calculate element volume here
m_elementVolumes.push_back(XSliceThickness*YSliceThickness*ZSliceThickness);
......
......@@ -120,7 +120,7 @@ void CylinderAbsorption::initialiseCachedDistances()
Track incoming(m_elementPositions[counter], m_beamDirection*-1.0);
m_sampleObject->interceptSurface(incoming);
m_L1s[counter] = incoming.begin()->Dist;
m_L1s[counter] = incoming.begin()->distFromStart;
// Also calculate element volumes here
const double outerR = R + (m_deltaR / 2.0);
......
......@@ -350,7 +350,7 @@ double DetectorEfficiencyCor::distToSurface(const V3D start, const Object *shape
throw std::invalid_argument("Fatal error interpreting the shape of a detector");
}
// the first part of the track will be the part inside the shape, return its length
return track.begin()->Length;
return track.begin()->distInsideObject;
}
/** Calculates detector efficiency, copied from the fortran code in effic_3he_cylinder.for
......
......@@ -106,7 +106,7 @@ void FlatPlateAbsorption::initialiseCachedDistances()
// Create track for distance in sample before scattering point
Track incoming(m_elementPositions[counter], m_beamDirection*-1.0);
m_sampleObject->interceptSurface(incoming);
m_L1s[counter] = incoming.begin()->Dist;
m_L1s[counter] = incoming.begin()->distFromStart;
// Also calculate element volume here
m_elementVolumes[counter] = m_XSliceThickness*m_YSliceThickness*m_ZSliceThickness;
......
......@@ -320,7 +320,7 @@ double He3TubeEfficiency::distToSurface(const Geometry::V3D start,
}
// the first part of the track will be the part inside the shape,
// return its length
return track.begin()->Length;
return track.begin()->distInsideObject;
}
/**
......
......@@ -70,11 +70,15 @@ public:
/// Get a detector at given XY indices.
boost::shared_ptr<Detector> getAtXY(int X, int Y) const;
/// Return the number of pixels in the X direction
int xpixels() const;
/// Return the number of pixels in the Y direction
int ypixels() const;
// This should inherit the getBoundingBox implementation from CompAssembly but
// the multiple inheritance seems to confuse it so we'll explicityly tell it that here
using CompAssembly::getBoundingBox;
// ------------ IObjComponent methods ----------------
/// Does the point given lie within this object component?
......@@ -88,9 +92,7 @@ public:
/// Finds the approximate solid angle covered by the component when viewed from the point given
double solidAngle(const V3D& observer) const;
BoundingBox getBoundingBox() const;
/// Retrieve the cached bounding box
void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin) const;
///Try to find a point that lies within (or on) the object
......@@ -131,8 +133,6 @@ private:
/// Pointer to the shape of the pixels in this detector array.
boost::shared_ptr<Object> mShape;
};
DLLExport std::ostream& operator<<(std::ostream&, const RectangularDetector&);
......
#ifndef MATERIAL_H
#define MATERIAL_H
#ifndef MANTID_GEOMETRY_MATERIAL_H_
#define MANTID_GEOMETRY_MATERIAL_H_
#include "MantidKernel/System.h"
#include <string>
namespace Mantid
{
namespace Kernel
{
class Logger;
}
namespace Geometry
{
/*!
\class Material
\brief Nuetronic information on the material
\author S. Ansell
\version 1.0
\date July 2007
This can be extended so that more sophisticated material
components can be used.
\todo This class nees to have a base class.
Copyright &copy; 2007 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
namespace Geometry
{
/**
Simple class defining a material. It holds basic information:
<UL>
<LI>Temperature (Kelvin)</LI>
<LI>Pressure (KPa) </LI>
<LI>Density (kg/m^3)</LI>
<LI>Coherent scattering cross section</LI>
<LI>Incoherent scattering cross section</LI>
<LI>Absorption cross section</LI>
</UL>
Copyright &copy; 2007-2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
......@@ -44,57 +40,79 @@ namespace Geometry
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
*/
class DLLExport Material
{
private:
static Kernel::Logger& PLog; ///< The official logger
std::string Name; ///< Name
double density; ///< number density [atom/A^3]
double scoh; ///< scattering cross section
double sinc; ///< incoherrrent cross section
double sabs; ///< Absorption cross section
class DLLExport Material
{
public:
/// Constructor
explicit Material(const std::string & name, const double density,
const double temperature, const double pressure,
const double coherentXsec, const double incoherentXsec,
const double absorbXsec);
/**
* Returns the name
* @returns A string containing the name of the material
*/
inline const std::string& name() const { return m_name; }
/**
* Get the density
* @returns The density of the material
*/
inline double density() const { return m_density; }
/**
* Get the temperature
* @returns The temperature of the material
*/
inline double temperature() const { return m_temperature; }
/**
* Get the pressure
* @returns The pressure of the material
*/
inline double pressure() const { return m_pressure; }
/**
* Get the total cross section
* @returns The sum of the coherent and incoherent scattering cross section
*/
inline double totalCrossSection() const { return m_coherentXsec + m_incoherentXsec; }
/**
* Get the coherent cross section
* @returns The coherent scattering cross section
*/
inline double coherentCrossSection() const { return m_coherentXsec; }
/**
* Get the incoherent cross section
* @returns The incoherent scattering cross section
*/
inline double incoherentCrossSection() const { return m_incoherentXsec; }
/**
* Get the absorption cross section
* @returns The absorption scattering cross section
*/
inline double absorptionCrossSection() const { return m_absorbXsec; }
private:
/// Default constructor
Material();
Material(const std::string& N,const double D,
const double S,const double I,const double A);
Material(const double D,const double S,const double I,const double A);
Material(const Material&);
virtual Material* clone() const;
Material& operator=(const Material&);
virtual ~Material();
/// Set the name
void setName(const std::string& N) { Name=N; }
void setDensity(const double D);
void setScat(const double S,const double I,const double A);
/// Get the number density
double getAtomDensity() const { return density; }
/// Set the name
const std::string& getName() const { return Name; }
/// Get the total cross section
double getScat() const { return scoh+sinc; }
/// Get the scattering cross section
double getCoh() const { return scoh; }
/// Get the incoherent cross section
double getInc() const { return sinc; }
double getScatFrac(const double Wave) const;
double getAtten(const double Wave) const;
double getAttenAbs(const double Wave) const;
double calcAtten(const double Wave,const double Length) const;
};
private:
/// Material name
std::string m_name;
/// Density in kg/m^3
double m_density;
/// Temperature
double m_temperature;
/// Pressure
double m_pressure;
/// Coherent scattering cross section
double m_coherentXsec;
/// Incoherent scattering cross section
double m_incoherentXsec;
/// Absorption cross section
double m_absorbXsec;
};
} // NAMESPACE Geometry
} // NAMESPACE Mantid
}
}
#endif
#endif //MANTID_GEOMETRY_MATERIAL_H_
......@@ -41,8 +41,7 @@ namespace Mantid
\date July 2007
\author S. Ansell
An object is a collection of Rules and
surface object
An object is a collection of Rules and surface objects
Copyright &copy; 2007-2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
......@@ -66,86 +65,27 @@ namespace Mantid
*/
class DLLExport Object
{
private:
static Kernel::Logger& PLog; ///< The official logger
int ObjName; ///< Creation number
int MatN; ///< Material Number
double Tmp; ///< Temperature (K)
double density; ///< Density
Rule* TopRule; ///< Top rule [ Geometric scope of object]
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
AABBxMin, ///< xmin of Axis aligned bounding box cache
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;
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;
double CylinderSolidAngle(const V3D & observer, const Mantid::Geometry::V3D & centre,
const Mantid::Geometry::V3D & axis,
const double radius, const double height) const;
double ConeSolidAngle(const V3D & observer, const Mantid::Geometry::V3D & centre,
const Mantid::Geometry::V3D & axis,
const double radius, const double height) const;
/// Geometry Handle for rendering
boost::shared_ptr<GeometryHandler> handle;
friend class CacheGeometryHandler;
/// Is geometry caching enabled?
bool bGeometryCaching;
/// a pointer to a class for reading from the geometry cache
boost::shared_ptr<vtkGeometryCacheReader> vtkCacheReader;
/// a pointer to a class for writing to the geometry cache
boost::shared_ptr<vtkGeometryCacheWriter> vtkCacheWriter;
void updateGeometryHandler();
/// for solid angle from triangulation
int NumberOfTriangles() const;
int NumberOfPoints() const;
int* getTriangleFaces() const;
double* getTriangleVertices() const;
void GetObjectGeom(int& type, std::vector<Geometry::V3D>& vectors, double& myradius, double & myheight) const;
protected:
std::vector<const Surface*> SurList; ///< Full surfaces (make a map including complementary object ?)
public:
/// Default constructor
Object();
/// Copy constructor
Object(const Object&);
/// Assignment operator
Object& operator=(const Object&);
/// Destructor
virtual ~Object();
/// Return the top rule
const Rule* topRule() const { return TopRule; }
void setName(const int nx) { ObjName=nx; } ///< Set Name
void setTemp(const double A) { Tmp=A; } ///< Set temperature [Kelvin]
int getName() const { return ObjName; } ///< Get Name
int setObject(const int ON,const std::string& Ln);
int procString(const std::string& Line);
void setMaterial(const int MatIndex) { MatN=MatIndex; } ///< Set Material index
void setDensity(const double D) { density=D; } ///< Set Density [Atom/A^3]
int complementaryObject(const int Cnum,std::string& Ln); ///< Process a complementary object
int hasComplement() const;
int getName() const { return ObjName; } ///< Get Name
int getMat() const { return MatN; } ///< Get Material ID
double getTemp() const { return Tmp; } ///< Get Temperature [K]
double getDensity() const { return density; } ///< Get Density [Atom/A^3]
int populate(const std::map<int,Surface*>&);
int createSurfaceList(const int outFlag=0); ///< create Surface list
int addSurfString(const std::string&); ///< Not implemented
......@@ -212,6 +152,63 @@ namespace Mantid
void setVtkGeometryCacheWriter(boost::shared_ptr<vtkGeometryCacheWriter>);
///set vtkGeometryCache reader
void setVtkGeometryCacheReader(boost::shared_ptr<vtkGeometryCacheReader>);
private:
static Kernel::Logger& PLog; ///< The official logger
int ObjName; ///< Creation number
//int MatN; ///< Material Number
//double Tmp; ///< Temperature (K)
//double density; ///< Density
Rule* TopRule; ///< Top rule [ Geometric scope of object]
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
AABBxMin, ///< xmin of Axis aligned bounding box cache
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;
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;
double CylinderSolidAngle(const V3D & observer, const Mantid::Geometry::V3D & centre,
const Mantid::Geometry::V3D & axis,
const double radius, const double height) const;
double ConeSolidAngle(const V3D & observer, const Mantid::Geometry::V3D & centre,
const Mantid::Geometry::V3D & axis,
const double radius, const double height) const;
/// Geometry Handle for rendering
boost::shared_ptr<GeometryHandler> handle;
friend class CacheGeometryHandler;
/// Is geometry caching enabled?
bool bGeometryCaching;
/// a pointer to a class for reading from the geometry cache
boost::shared_ptr<vtkGeometryCacheReader> vtkCacheReader;
/// a pointer to a class for writing to the geometry cache
boost::shared_ptr<vtkGeometryCacheWriter> vtkCacheWriter;
void updateGeometryHandler();
/// for solid angle from triangulation
int NumberOfTriangles() const;
int NumberOfPoints() const;
int* getTriangleFaces() const;
double* getTriangleVertices() const;
void GetObjectGeom(int& type, std::vector<Geometry::V3D>& vectors, double& myradius, double & myheight) const;
protected:
std::vector<const Surface*> SurList; ///< Full surfaces (make a map including complementary object ?)
};
} // NAMESPACE Geometry
......
......@@ -6,20 +6,21 @@
//----------------------------------------------------------------------
#include "MantidKernel/System.h"
#include "MantidGeometry/V3D.h"
#include "MantidGeometry/Tolerance.h"
namespace Mantid
{
//----------------------------------------------------------------------
// Forward Declaration
//----------------------------------------------------------------------
namespace Kernel
{
//----------------------------------------------------------------------
// Forward Declaration
//----------------------------------------------------------------------
namespace Kernel
{
class Logger;
}
}
namespace Geometry
{
/*!
namespace Geometry
{
/*!
\struct TUnit
\version 1.0
\author S. Ansell
......@@ -45,91 +46,133 @@ 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>
*/
struct DLLExport TUnit
{
V3D PtA; ///< Init Point
V3D PtB; ///< Exit Point
double Dist; ///< Total distance from track begin
double Length; ///< Total distance Distance [at end]
int ObjID; ///< ObjectID
TUnit(const Geometry::V3D& A,const Geometry::V3D& B,const double D,const int ID);
struct DLLExport TUnit
{
/**
* 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
*/
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)
{}
/// Less than operator
int operator<(const TUnit& A) const
{ return Dist<A.Dist; }
inline bool operator<(const TUnit& other) const { return distFromStart < other.distFromStart; }
/// Less than operator
int operator<(const double& A) const
{ return Dist<A; }
};
/*!
Ordering for TPartial is special since we need
that when dist is close that the +/- flag is taken into
account.
inline bool operator<(const double& other) const { return distFromStart < other; }
/** @name Attributes. */
//@{
V3D entryPoint; ///< Entry point
V3D exitPoint; ///< Exit point
double distFromStart; ///< Total distance from track beginning
double distInsideObject; ///< Total distance covered inside object
int ObjID; ///< ObjectID
//@}
};
/**
* Stores a point of intersection along a track. The object intersected is linked using its
* ID.
*
* Ordering for TPartial is special since we need
* that when dist is close that the +/- flag is taken into
* account.
*/
struct TPartial
{
struct TPartial
{
/**
* 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 end The end point for this partial segment
* @param distFromStartOfTrack Total distance from start of track
*/
inline TPartial(const int ID,const int directionFlag, const Geometry::V3D& end,const double distFromStartOfTrack) :
ObjID(ID),direction(directionFlag),endPoint(end),distFromStart(distFromStartOfTrack)
{}
/**
* A TPartial 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
* @return True if the object is considered less than, otherwise false.
*/
inline bool operator<(const TPartial& other) const
{
const double diff = fabs(distFromStart - other.distFromStart);
return (diff > Tolerance) ? distFromStart < other.distFromStart : direction < other.direction;
}
/** @name Attributes. */
//@{
int ObjID; ///< ObjectID
int Direction; ///< Flag direction
V3D PtA; ///< Point
double Dist; ///< Total distance from track begin
TPartial(const int ID,const int flag,const Geometry::V3D& PVec,const double D);
int operator<(const TPartial& A) const;
};
/*!
\class Track
\version 1.0
\author S. Ansell
\brief Order List of track units.
int direction; ///< Directional flag
V3D endPoint; ///< Point
double distFromStart; ///< Total distance from track begin
//@}
};
/**
* Defines a track as a start point and a direction. Intersections are
* stored as ordered lists of links from the start point to the exit point.
*
* @author S. Ansell
*/
class DLLExport Track
{
class DLLExport Track