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 "MantidKernel/System.h"
17#include <limits>
18#ifndef Q_MOC_RUN
19#include <boost/lexical_cast.hpp>
20#endif
21
22namespace Mantid {
23namespace Geometry {
24
25#pragma pack(push, 4) // Ensure the structure is no larger than it needs to
26
27// the statement to exclude using macro min(a,b) in visual C++ uder win
28#ifdef min
29#undef min
30#endif
31// the statement to exclude using macro max(a,b) in visual C++ uder win
32#ifdef max
33#undef max
34#endif
35
36//===============================================================================================
40template <typename T> class MDDimensionExtents {
41public:
44 // ---- Public members ----------
45 MDDimensionExtents() : min(1e30f), max(-1e30f), m_size(0.0f) {}
46 T getSize() const { return m_size; }
47 T getCentre() const { return static_cast<T>(0.5 * (max + min)); }
48 bool outside(T x) const { return ((x < min) || (x >= max)); }
49 bool isUndefined() const { return (min > max); }
50 //
51 std::string extentsStr() const {
52 return (boost::lexical_cast<std::string>(min) + "-" + boost::lexical_cast<std::string>(max));
53 }
54 T getMin() const { return min; }
55 T getMax() const { return max; }
57 T getGridVertex(const size_t ind) const { return min + m_size * static_cast<T>(ind); }
58
59 void scaleExtents(double scaling, double offset) {
60 min = static_cast<T>(min * scaling + offset);
61 max = static_cast<T>(max * scaling + offset);
62 m_size = static_cast<T>(m_size * scaling);
63 if (max < min) {
64 T tmp = max;
65 max = min;
66 min = tmp;
67 m_size = std::fabs(m_size);
68 }
69 }
70 // it looks like this loses accuracy?
72 double dMax = double(other.max);
73 if (max > dMax)
74 dMax = double(max);
75 double dMin = double(other.min);
76 if (min < dMin)
77 dMin = double(min);
78
79 other.max = static_cast<T>(dMax);
80 other.min = static_cast<T>(dMin);
81 other.m_size = static_cast<T>(dMax - dMin);
82 }
83
84 void setExtents(double dMin, double dMax) {
85 min = static_cast<T>(dMin);
86 max = static_cast<T>(dMax);
87 m_size = static_cast<T>(dMax - dMin);
88 }
89 // private:
90private:
92 T min;
94 T max;
99};
100
101#pragma pack(pop) // Return to default packing size
102
103} // namespace Geometry
104
105} // 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.