Skip to content

Commit

Permalink
refs #6271. Use boost optional where required.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 7, 2013
1 parent 1775fba commit 2996560
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace MantidQt
{
namespace SliceViewer
{
/// Alisas for a boost optional double.
typedef boost::optional<double> optional_double;

/**
@class Spherical peak drawing primitive information.
*/
Expand Down Expand Up @@ -45,29 +48,36 @@ namespace MantidQt
SphericalPeakPrimitives draw(const double& windowHeight, const double& windowWidth, const double& viewWidth, const double& viewHeight) const;

/**
Determine whether the physical peak is visible. This means that the intesecting plane penetrates the sphere somehow. If the absolute
Determine whether the physical peak is viewable. This means that the intesecting plane penetrates the sphere somehow. If the absolute
distance between the plane and the origin is greater than the peak radius, then the peak is not visible.
@return True if the peak is visible in the current configuration.
*/
inline bool isViewablePeak() const
{
return (m_peakRadiusAtDistance <= this->m_peakRadius);
if(m_peakRadiusAtDistance.is_initialized())
{
return (m_peakRadiusAtDistance.get() <= this->m_peakRadius);
}
return false;
}

/**
Determine whether the physical peak background is viewable. This means that the intesecting plane penetrates the sphere somehow. If the absolute
distance between the plane and the origin is greater than the peak radius, then the peak is not visible.
@return True if the peak is visible in the current configuration.
*/
inline bool isViewableBackground() const
{
if(m_showBackgroundRadius && m_backgroundOuterRadiusAtDistance.is_initialized())
{
return (m_backgroundOuterRadiusAtDistance <= this->m_backgroundOuterRadius);
return (m_backgroundOuterRadiusAtDistance.get() <= this->m_backgroundOuterRadius);
}
return false;
}

/// Setter to command whether the background radius should also be shown.
void showBackgroundRadius(const bool show);

bool showBackgroundRadius() const;

private:
/// Original origin x=h, y=k, z=l
const Mantid::Kernel::V3D m_originalOrigin;
Expand All @@ -86,23 +96,21 @@ namespace MantidQt
/// Cached opacity at the distance z from origin
double m_cachedOpacityAtDistance;
/// Cached radius at the distance z from origin
double m_peakRadiusAtDistance;
optional_double m_peakRadiusAtDistance;
/// Cached opacity gradient.
const double m_cachedOpacityGradient;
/// Cached radius squared.
const double m_peakRadiusSQ;
/// Cached background inner radius sq.
const double m_backgroundInnerRadiusSQ;
/// Cached background outer radius sq.
double m_backgroundOuterRadiusSQ;
const double m_backgroundOuterRadiusSQ;
/// Flag to indicate that the background radius should be drawn.
bool m_showBackgroundRadius;
/// Inner radius at distance.
double m_backgroundInnerRadiusAtDistance;
optional_double m_backgroundInnerRadiusAtDistance;
/// Outer radius at distance.
boost::optional<double> m_backgroundOuterRadiusAtDistance;
/// Current slicepoint.
double m_currentSlicePoint;
optional_double m_backgroundOuterRadiusAtDistance;

DISABLE_COPY_AND_ASSIGN(PhysicalSphericalPeak)
};
Expand Down
15 changes: 4 additions & 11 deletions Code/Mantid/MantidQt/SliceViewer/src/PhysicalSphericalPeak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace MantidQt
m_opacityMin(0.0),
m_cachedOpacityAtDistance(0.0),
m_peakRadiusAtDistance(peakRadius+1), // Initialize such that physical peak is not visible
m_backgroundInnerRadiusAtDistance(backgroundInnerRadius+1), // Initialize such that physical peak is not visible
m_backgroundOuterRadiusAtDistance(backgroundOuterRadius+1), // Initialize such that physical peak is not visible
m_cachedOpacityGradient((m_opacityMin - m_opacityMax)/m_peakRadius),
m_peakRadiusSQ(m_peakRadius*m_peakRadius),
m_backgroundInnerRadiusSQ(backgroundInnerRadius*backgroundInnerRadius),
Expand Down Expand Up @@ -106,15 +104,15 @@ namespace MantidQt
if(this->isViewablePeak())
{
// Create the return object.
drawingObjects.peakInnerRadiusX = scaleX * m_peakRadiusAtDistance;
drawingObjects.peakInnerRadiusY = scaleY * m_peakRadiusAtDistance;
drawingObjects.peakInnerRadiusX = scaleX * m_peakRadiusAtDistance.get();
drawingObjects.peakInnerRadiusY = scaleY * m_peakRadiusAtDistance.get();
}
if(this->isViewableBackground())
{
drawingObjects.backgroundOuterRadiusX = scaleX * m_backgroundOuterRadiusAtDistance.get();
drawingObjects.backgroundOuterRadiusY = scaleY * m_backgroundOuterRadiusAtDistance.get();
drawingObjects.backgroundInnerRadiusX = scaleX * m_backgroundInnerRadiusAtDistance;
drawingObjects.backgroundInnerRadiusY = scaleY * m_backgroundInnerRadiusAtDistance;
drawingObjects.backgroundInnerRadiusX = scaleX * m_backgroundInnerRadiusAtDistance.get();
drawingObjects.backgroundInnerRadiusY = scaleY * m_backgroundInnerRadiusAtDistance.get();
}
return drawingObjects;
}
Expand All @@ -123,10 +121,5 @@ namespace MantidQt
{
m_showBackgroundRadius = show;
}

bool PhysicalSphericalPeak::showBackgroundRadius() const
{
return m_showBackgroundRadius;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class PhysicalSphericalPeakTest : public CxxTest::TestSuite
const double slicePoint = radius + delta;
physicalPeak.setSlicePoint(slicePoint);

int i;
std::cin >> i;

TSM_ASSERT("Should NOT be viewable if a slice point > r is set.", !physicalPeak.isViewablePeak());
}

Expand Down

0 comments on commit 2996560

Please sign in to comment.