Mantid
Loading...
Searching...
No Matches
MDDimensionExtents.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9/*
10 * MDDimensionExtents.h
11 *
12 * Created on: Jan 14, 2011
13 * Author: Janik Zikovsky
14 */
16#include <limits>
17#ifndef Q_MOC_RUN
18#include <boost/lexical_cast.hpp>
19#endif
20
21namespace Mantid {
22namespace Geometry {
23
24#pragma pack(push, 4) // Ensure the structure is no larger than it needs to
25
26// the statement to exclude using macro min(a,b) in visual C++ uder win
27#ifdef min
28#undef min
29#endif
30// the statement to exclude using macro max(a,b) in visual C++ uder win
31#ifdef max
32#undef max
33#endif
34
35//===============================================================================================
39template <typename T> class MDDimensionExtents {
40public:
43 // ---- Public members ----------
44 MDDimensionExtents() : min(1e30f), max(-1e30f), m_size(0.0f) {}
45 T getSize() const { return m_size; }
46 T getCentre() const { return static_cast<T>(0.5 * (max + min)); }
47 bool outside(T x) const { return ((x < min) || (x >= max)); }
48 bool isUndefined() const { return (min > max); }
49 //
50 std::string extentsStr() const {
51 return (boost::lexical_cast<std::string>(min) + "-" + boost::lexical_cast<std::string>(max));
52 }
53 T getMin() const { return min; }
54 T getMax() const { return max; }
56 T getGridVertex(const size_t ind) const { return min + m_size * static_cast<T>(ind); }
57
58 void scaleExtents(double scaling, double offset) {
59 min = static_cast<T>(min * scaling + offset);
60 max = static_cast<T>(max * scaling + offset);
61 m_size = static_cast<T>(m_size * scaling);
62 if (max < min) {
63 T tmp = max;
64 max = min;
65 min = tmp;
66 m_size = std::fabs(m_size);
67 }
68 }
69 // it looks like this loses accuracy?
71 double dMax = double(other.max);
72 if (max > dMax)
73 dMax = double(max);
74 double dMin = double(other.min);
75 if (min < dMin)
76 dMin = double(min);
77
78 other.max = static_cast<T>(dMax);
79 other.min = static_cast<T>(dMin);
80 other.m_size = static_cast<T>(dMax - dMin);
81 }
82
83 void setExtents(double dMin, double dMax) {
84 min = static_cast<T>(dMin);
85 max = static_cast<T>(dMax);
86 m_size = static_cast<T>(dMax - dMin);
87 }
88 // private:
89private:
91 T min;
93 T max;
98};
99
100#pragma pack(pop) // Return to default packing size
101
102} // namespace Geometry
103
104} // namespace Mantid
gsl_vector * tmp
Simple class that holds the extents (min/max) of a given dimension in a MD workspace or MDBox.
T max
Extent: maximum value in that dimension.
void scaleExtents(double scaling, double offset)
void setExtents(double dMin, double dMax)
MDDimensionExtents()
Empty constructor - reset everything.
T min
Extent: minimum value in that dimension.
void expand(MDDimensionExtents &other)
T getGridVertex(const size_t ind) const
return the vertice in the grid, based on this extent's size
T m_size
the box size; It is important to have box size defined from doubles to avoid accuracy loss when extra...
Helper class which provides the Collimation Length for SANS instruments.