Computer Assisted Medical Intervention Tool Kit  version 5.2
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-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, 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;
62  towardIndex = d.towardIndex;
63  };
64 
66  x = d.x;
67  xState = d.xState;
68  y = d.y;
69  yState = d.yState;
70  z = d.z;
71  zState = d.zState;
72  towardIndex = d.towardIndex;
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;
173  xState = SPECIFIED;
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;
203  yState = SPECIFIED;
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;
234  zState = SPECIFIED;
235  };
236 
238 
239 private:
241  enum DirState {
242  NOT_SPECIFIED,
243  NULL_DIR,
244  SPECIFIED,
245  TOWARD
246  };
247 
249  double x{0.0};
251  double y{0.0};
253  double z{0.0};
255  DirState xState{NOT_SPECIFIED};
257  DirState yState{NOT_SPECIFIED};
259  DirState zState{NOT_SPECIFIED};
261  int towardIndex{-1};
262 };
263 
264 #endif //DIRECTION_H
Class that defines the direction of the Load with x, y and z.
Definition: Direction.h:39
double getY() const
get the y coordinate
Definition: Direction.h:180
Direction(const Direction &d)
copy constructor
Definition: Direction.h:55
void setNullY()
set the y coordinate as NULL
Definition: Direction.h:195
void setY(const double y)
set the y coordinate
Definition: Direction.h:201
Direction(const unsigned int toward)
constructor with initialization of the toward
Definition: Direction.h:45
void setX(const double x)
set the x coordinate
Definition: Direction.h:171
Direction(double x0, double y0, double z0)
constructor with initialization of the 3 directions
Definition: Direction.h:49
bool isXSpecified() const
is the x coordinate specified
Definition: Direction.h:160
double getX() const
get the x coordinate
Definition: Direction.h:150
double getZ() const
get the z coordinate
Definition: Direction.h:211
void setNullX()
set the x coordinate as NULL
Definition: Direction.h:165
void setToward(const unsigned int toward)
set the toward index
Definition: Direction.h:136
bool isXNull() const
is the x coordinate NULL ?
Definition: Direction.h:155
bool isZNull() const
is the z coordinate NULL ?
Definition: Direction.h:216
bool isYNull() const
is the y coordinate NULL ?
Definition: Direction.h:185
void setNullZ()
set the z coordinate as NULL
Definition: Direction.h:226
bool isZSpecified() const
is the z coordinate specified
Definition: Direction.h:221
Direction()
default constructor: nothing is specified
Definition: Direction.h:43
void setZ(const double z)
set the z coordinate
Definition: Direction.h:232
int getToward() const
get the toward index
Definition: Direction.h:131
Direction & operator=(const Direction &d)
Definition: Direction.h:65
void set(const double x, const double y, const double z)
set the direction
Definition: Direction.h:124
bool isYSpecified() const
is the y coordinate specified
Definition: Direction.h:190
void xmlPrint(std::ostream &o) const
print to an ostream
Definition: Direction.h:77
bool isToward() const
true only if the direction is set by a toward atom
Definition: Direction.h:142