VolumeDataAxisDescriptor.h 4.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/****************************************************************************
** Copyright 2019 The Open Group
** Copyright 2019 Bluware, Inc.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
****************************************************************************/

#ifndef VOLUMEDATAAXISDESCRIPTOR_H
#define VOLUMEDATAAXISDESCRIPTOR_H

21
#include <OpenVDS/Range.h>
22

23
#include <cmath>
24
#include <string>
25
26
27

namespace OpenVDS
{
28
29
30
/// <summary>
/// Describes the number of samples, name, unit and coordinates (annotation) of an axis (dimension) of the volume
/// </summary>
31
32
class VolumeDataAxisDescriptor
{
Jørgen Lind's avatar
Jørgen Lind committed
33
  int         m_numSamples;
34
35
  const char *m_name;
  const char *m_unit;
36
37
  float       m_coordinateMin;
  float       m_coordinateMax;
38
39

public:
40
41
42
43
  /// <summary>
  /// Default constructor
  /// </summary>
  VolumeDataAxisDescriptor() : m_numSamples(), m_name(), m_unit(), m_coordinateMin(), m_coordinateMax() {}
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  /// <summary>
  /// Constructor
  /// </summary>
  /// <param name="numSamples">
  /// The number of samples along this axis
  /// </param>
  /// <param name="name">
  /// The name of this axis
  /// </param>
  /// <param name="unit">
  /// The unit of the coordinates of this axis
  /// </param>
  /// <param name="coordinateMin">
  /// The coordinate of the first sample of this axis
  /// </param>
  /// <param name="coordinateMax">
  /// The coordinate of the last sample of this axis
  /// </param>
63
  VolumeDataAxisDescriptor(int numSamples, const char *name, const char *unit, float coordinateMin, float coordinateMax)
64
    : m_numSamples(numSamples), m_name(name), m_unit(unit), m_coordinateMin(coordinateMin), m_coordinateMax(coordinateMax) {}
65

66
67
68
69
70
71
  /// <summary>
  /// Get the number of samples along this axis
  /// </summary>
  /// <returns>
  /// The number of samples along this axis
  /// </returns>
72
  int GetNumSamples()    const { return m_numSamples; }
73
74
75
76
77
78
79

  /// <summary>
  /// Get the name of this axis
  /// </summary>
  /// <returns>
  /// The name of this axis
  /// </returns>
80
  const char *GetName()          const { return m_name; }
81
82
83
84
85
86
87

  /// <summary>
  /// Get the unit of the coordinates of this axis
  /// </summary>
  /// <returns>
  /// The unit of the coordinates of this axis
  /// </returns>
88
  const char *GetUnit()          const { return m_unit; }
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  /// <summary>
  /// Get the coordinate of the first sample of this axis
  /// </summary>
  /// <returns>
  /// The coordinate of the first sample of this axis
  /// </returns>
  float GetCoordinateMin() const { return m_coordinateMin; }

  /// <summary>
  /// Get the coordinate of the last sample of this axis
  /// </summary>
  /// <returns>
  /// The coordinate of the last sample of this axis
  /// </returns>
  float GetCoordinateMax() const { return m_coordinateMax; }

  /// <summary>
  /// Get the coordiante step size per sample
  /// </summary>
  /// <returns>
  /// The coordiante step size per sample
  /// </returns>
  float GetCoordinateStep() const { return (m_numSamples > 1) ? ((m_coordinateMax - m_coordinateMin) / (m_numSamples - 1)) : 0; }

  /// <summary>
  /// Convert a sample index on this axis to a coordinate 
  /// </summary>
  /// <param name="sampleIndex">
  /// The sample index get the coordinate of
  /// </param>
  /// <returns>
  /// The coordinate of the sample index
  /// </returns>
  float SampleIndexToCoordinate(int sampleIndex)  { return m_coordinateMin + sampleIndex * GetCoordinateStep(); }
124

125
  /// <summary>
126
  /// Convert a coordinate to a sample index (rounding to the closest index)
127
128
129
130
131
132
133
134
  /// </summary>
  /// <param name="coordinate">
  /// The coordinate to get the sample index of
  /// </param>
  /// <returns>
  /// The sample index of the coordinate
  /// </returns>
  int CoordinateToSampleIndex(float coordinate) { return (coordinate == m_coordinateMin) ? 0 : (int)floorf(((coordinate - m_coordinateMin) / (m_coordinateMax - m_coordinateMin)) * (m_numSamples - 1) + 0.5f); }
135
136
137
138
};
}
#endif //VOLUMEDATAAXISDESCRIPTOR_H