Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkStepper.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkStepper.h"
14 
16  : m_Pos(0),
17  m_Steps(0),
18  m_AutoRepeat(false),
19  m_PingPong(false),
20  m_InverseDirection(false),
21  m_RangeMin(0.0),
22  m_RangeMax(-1.0),
23  m_RangeValid(false),
24  m_HasRange(false),
25  m_HasUnitName(false)
26 {
27 }
28 
30 {
31 }
32 
34 {
35  m_RangeMin = min;
36  m_RangeMax = max;
37  m_HasRange = true;
38  m_RangeValid = true;
39  this->Modified();
40 }
41 
43 {
44  m_HasRange = true;
45  m_RangeValid = false;
46  this->Modified();
47 }
48 
50 {
51  return m_RangeMin;
52 }
53 
55 {
56  return m_RangeMax;
57 }
58 
60 {
61  m_HasRange = false;
62  this->Modified();
63 }
64 
66 {
67  return (m_HasRange && m_RangeValid);
68 }
69 
71 {
72  return m_HasRange;
73 }
74 
75 void mitk::Stepper::SetUnitName(const char *unitName)
76 {
77  m_UnitName = std::string(unitName);
78  m_HasUnitName = true;
79  this->Modified();
80 }
81 
82 const char *mitk::Stepper::GetUnitName() const
83 {
84  return m_UnitName.c_str();
85 }
86 
88 {
89  m_HasUnitName = false;
90  this->Modified();
91 }
92 
94 {
95  return m_HasUnitName;
96 }
97 
99 {
100  if (this->GetPos() < this->GetSteps() - 1)
101  {
102  this->SetPos(this->GetPos() + 1);
103  }
104  else if (m_AutoRepeat)
105  {
106  if (!m_PingPong)
107  {
108  this->SetPos(0);
109  }
110  else
111  {
112  m_InverseDirection = true;
113  if (this->GetPos() > 0)
114  {
115  this->SetPos(this->GetPos() - 1);
116  }
117  }
118  }
119 }
120 
122 {
123  if (this->GetPos() > 0)
124  {
125  this->SetPos(this->GetPos() - 1);
126  }
127  else if (m_AutoRepeat)
128  {
129  if (!m_PingPong)
130  {
131  this->SetPos(this->GetSteps() - 1);
132  }
133  else
134  {
135  m_InverseDirection = false;
136  if (this->GetPos() < this->GetSteps() - 1)
137  {
138  this->SetPos(this->GetPos() + 1);
139  }
140  }
141  }
142 }
143 
145 {
146  if (!m_InverseDirection)
147  {
148  this->Increase();
149  }
150  else
151  {
152  this->Decrease();
153  }
154 }
155 
157 {
158  if (!m_InverseDirection)
159  {
160  this->Decrease();
161  }
162  else
163  {
164  this->Increase();
165  }
166 }
167 
168 void mitk::Stepper::MoveSlice(int sliceDelta)
169 {
170  int newPosition = this->GetPos() + sliceDelta;
171  // if auto repeat is on, increasing continues at the first slice if the last slice was reached and vice versa
172  int maxSlices = this->GetSteps();
173  if (m_AutoRepeat)
174  {
175  while (newPosition < 0)
176  {
177  newPosition += maxSlices;
178  }
179  while (newPosition >= maxSlices)
180  {
181  newPosition -= maxSlices;
182  }
183  }
184  else
185  {
186  // if the new slice is below 0 we still show slice 0
187  // due to the stepper using unsigned int we have to do this ourselves
188  if (newPosition < 1)
189  {
190  newPosition = 0;
191  }
192  }
193 
194  this->SetPos(newPosition);
195 }
196 
198 {
199  this->SetPos(0);
200 }
201 
203 {
204  this->SetPos(this->GetSteps() - 1);
205 }
const char * GetUnitName() const
Definition: mitkStepper.cpp:82
std::string m_UnitName
Definition: mitkStepper.h:138
void InvalidateRange()
Definition: mitkStepper.cpp:42
bool HasRange() const
Definition: mitkStepper.cpp:70
ScalarType m_RangeMax
Definition: mitkStepper.h:134
bool HasValidRange() const
Definition: mitkStepper.cpp:65
double ScalarType
void RemoveRange()
Definition: mitkStepper.cpp:59
void RemoveUnitName()
Definition: mitkStepper.cpp:87
ScalarType m_RangeMin
Definition: mitkStepper.h:133
virtual void First()
bool m_HasUnitName
Definition: mitkStepper.h:139
void SetRange(ScalarType min, ScalarType max)
Definition: mitkStepper.cpp:33
virtual void Previous()
bool m_InverseDirection
Definition: mitkStepper.h:131
virtual void MoveSlice(int sliceDelta)
virtual void SetPos(unsigned int pos)
Definition: mitkStepper.h:55
static T max(T x, T y)
Definition: svm.cpp:56
~Stepper() override
Definition: mitkStepper.cpp:29
void SetUnitName(const char *unitName)
Definition: mitkStepper.cpp:75
virtual void Last()
static T min(T x, T y)
Definition: svm.cpp:53
ScalarType GetRangeMin() const
Definition: mitkStepper.cpp:49
virtual unsigned int GetSteps() const
virtual unsigned int GetPos() const
ScalarType GetRangeMax() const
Definition: mitkStepper.cpp:54
virtual void Next()
bool HasUnitName() const
Definition: mitkStepper.cpp:93