Computer Assited Medical Intervention Tool Kit  version 5.0
Direction.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 
27 #ifndef DIRECTION_H
28 #define DIRECTION_H
29 
30 #include <iostream>
31 
39 class Direction {
40 
41 public:
43  Direction() {};
45  Direction(const unsigned int toward) {
46  setToward(toward);
47  };
49  Direction(double x0, double y0, double z0) {
50  setX(x0);
51  setY(y0);
52  setZ(z0);
53  };
55  Direction(const Direction& d) {
56  x = d.x;
57  xState = d.xState;
58  y = d.y;
59  yState = d.yState;
60  z = d.z;
61  zState = d.zState;
63  };
64 
65  Direction& operator=(const Direction& d) {
66  x = d.x;
67  xState = d.xState;
68  y = d.y;
69  yState = d.yState;
70  z = d.z;
71  zState = d.zState;
73  return *this;
74  }
75 
77  void xmlPrint(std::ostream& o) const {
78  o << "\t<direction ";
79  if (isToward()) {
80  o << "toward=\"" << towardIndex << "\"";
81  }
82  else {
83  switch (xState) {
84  case NOT_SPECIFIED:
85  break;
86  case NULL_DIR:
87  o << "x=\"NULL\" ";
88  break;
89  case SPECIFIED:
90  o << "x=\"" << x << "\" ";
91  break;
92  default:
93  break;
94  }
95  switch (yState) {
96  case NOT_SPECIFIED:
97  break;
98  case NULL_DIR:
99  o << "y=\"NULL\" ";
100  break;
101  case SPECIFIED:
102  o << "y=\"" << y << "\" ";
103  break;
104  default:
105  break;
106  }
107  switch (zState) {
108  case NOT_SPECIFIED:
109  break;
110  case NULL_DIR:
111  o << "z=\"NULL\"";
112  break;
113  case SPECIFIED:
114  o << "z=\"" << z << "\"";
115  break;
116  default:
117  break;
118  }
119  }
120  o << "/>" << std::endl;
121  };
122 
124  void set(const double x, const double y, const double z) {
125  setX(x);
126  setY(y);
127  setZ(z);
128  };
129 
131  int getToward() const {
132  return towardIndex;
133  };
134 
136  void setToward(const unsigned int toward) {
137  towardIndex = toward;
138  xState = yState = zState = TOWARD;
139  };
140 
142  bool isToward() const {
143  return (towardIndex >= 0 && xState == TOWARD && yState == TOWARD && zState == TOWARD);
144  };
145 
147 
148 
150  double getX() const {
151  return x;
152  };
153 
155  bool isXNull() const {
156  return (xState == NULL_DIR);
157  };
158 
160  bool isXSpecified() const {
161  return (xState == SPECIFIED);
162  };
163 
165  void setNullX() {
166  x = 0.0;
167  xState = NULL_DIR;
168  };
169 
171  void setX(const double x) {
172  this->x = x;
174  };
176 
178 
179  double getY() const {
181  return y;
182  };
183 
185  bool isYNull() const {
186  return (yState == NULL_DIR);
187  };
188 
190  bool isYSpecified() const {
191  return (yState == SPECIFIED);
192  };
193 
195  void setNullY() {
196  y = 0.0;
197  yState = NULL_DIR;
198  };
199 
201  void setY(const double y) {
202  this->y = y;
204  };
205 
207 
209 
210  double getZ() const {
212  return z;
213  };
214 
216  bool isZNull() const {
217  return (zState == NULL_DIR);
218  };
219 
221  bool isZSpecified() const {
222  return (zState == SPECIFIED);
223  };
224 
226  void setNullZ() {
227  z = 0.0;
228  zState = NULL_DIR;
229  };
230 
232  void setZ(const double z) {
233  this->z = z;
235  };
236 
238 
239 private:
241  enum DirState {
242  NOT_SPECIFIED,
243  NULL_DIR,
245  TOWARD
246  };
247 
249  double x{0.0};
251  double y{0.0};
253  double z{0.0};
261  int towardIndex{-1};
262 };
263 
264 #endif //DIRECTION_H
Direction::TOWARD
@ TOWARD
the direction is set dynamically depending on the "toward" position
Definition: Direction.h:268
Direction::NOT_SPECIFIED
@ NOT_SPECIFIED
the direction has never been specified: it is absolutly free
Definition: Direction.h:265
Direction::isToward
bool isToward() const
true only if the direction is set by a toward atom
Definition: Direction.h:165
Direction::xState
DirState xState
state for the x coordinates
Definition: Direction.h:278
Direction::setNullY
void setNullY()
set the y coordinate as NULL
Definition: Direction.h:218
Direction::setToward
void setToward(const unsigned int toward)
set the toward index
Definition: Direction.h:159
Direction::isZSpecified
bool isZSpecified() const
is the z coordinate specified
Definition: Direction.h:244
Direction::getY
double getY() const
get the y coordinate
Definition: Direction.h:203
Direction::z
double z
z coordinates
Definition: Direction.h:276
Direction::getToward
int getToward() const
get the toward index
Definition: Direction.h:154
Direction::operator=
Direction & operator=(const Direction &d)
Definition: Direction.h:88
Direction::setX
void setX(const double x)
set the x coordinate
Definition: Direction.h:194
Direction::getZ
double getZ() const
get the z coordinate
Definition: Direction.h:234
Direction
Class that defines the direction of the Load with x, y and z.
Definition: Direction.h:39
Direction::isZNull
bool isZNull() const
is the z coordinate NULL ?
Definition: Direction.h:239
Direction::DirState
DirState
state of the x,y and z
Definition: Direction.h:264
Direction::y
double y
y coordinates
Definition: Direction.h:274
Direction::isXSpecified
bool isXSpecified() const
is the x coordinate specified
Definition: Direction.h:183
Direction::xmlPrint
void xmlPrint(std::ostream &o) const
print to an ostream
Definition: Direction.h:100
Direction::towardIndex
int towardIndex
toward atom index
Definition: Direction.h:284
Direction::SPECIFIED
@ SPECIFIED
the direction has been specified to be something imposed but not null (even 0.0 is possible!...
Definition: Direction.h:267
Direction::NULL_DIR
@ NULL_DIR
the direction has been specified to be always null
Definition: Direction.h:266
Direction::set
void set(const double x, const double y, const double z)
set the direction
Definition: Direction.h:147
Direction::yState
DirState yState
state for the y coordinates
Definition: Direction.h:280
Direction::Direction
Direction()
default constructor: nothing is specified
Definition: Direction.h:66
Direction::isXNull
bool isXNull() const
is the x coordinate NULL ?
Definition: Direction.h:178
Direction::setNullZ
void setNullZ()
set the z coordinate as NULL
Definition: Direction.h:249
Direction::x
double x
x coordinates
Definition: Direction.h:272
Direction::isYSpecified
bool isYSpecified() const
is the y coordinate specified
Definition: Direction.h:213
Direction::isYNull
bool isYNull() const
is the y coordinate NULL ?
Definition: Direction.h:208
Direction::setZ
void setZ(const double z)
set the z coordinate
Definition: Direction.h:255
Direction::getX
double getX() const
get the x coordinate
Definition: Direction.h:173
Direction::setY
void setY(const double y)
set the y coordinate
Definition: Direction.h:224
Direction::setNullX
void setNullX()
set the x coordinate as NULL
Definition: Direction.h:188
Direction::zState
DirState zState
state for the z coordinates
Definition: Direction.h:282