Computer Assited Medical Intervention Tool Kit  version 4.1
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-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
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 
66  void xmlPrint(std::ostream& o) const {
67  o << "\t<direction ";
68  if (isToward()) {
69  o << "toward=\"" << towardIndex << "\"";
70  }
71  else {
72  switch (xState) {
73  case NOT_SPECIFIED:
74  break;
75  case NULL_DIR:
76  o << "x=\"NULL\" ";
77  break;
78  case SPECIFIED:
79  o << "x=\"" << x << "\" ";
80  break;
81  default:
82  break;
83  }
84  switch (yState) {
85  case NOT_SPECIFIED:
86  break;
87  case NULL_DIR:
88  o << "y=\"NULL\" ";
89  break;
90  case SPECIFIED:
91  o << "y=\"" << y << "\" ";
92  break;
93  default:
94  break;
95  }
96  switch (zState) {
97  case NOT_SPECIFIED:
98  break;
99  case NULL_DIR:
100  o << "z=\"NULL\"";
101  break;
102  case SPECIFIED:
103  o << "z=\"" << z << "\"";
104  break;
105  default:
106  break;
107  }
108  }
109  o << "/>" << std::endl;
110  };
111 
113  void set(const double x, const double y, const double z) {
114  setX(x);
115  setY(y);
116  setZ(z);
117  };
118 
120  int getToward() const {
121  return towardIndex;
122  };
123 
125  void setToward(const unsigned int toward) {
126  towardIndex = toward;
127  xState = yState = zState = TOWARD;
128  };
129 
131  bool isToward() const {
132  return (towardIndex >= 0 && xState == TOWARD && yState == TOWARD && zState == TOWARD);
133  };
134 
136 
137 
139  double getX() const {
140  return x;
141  };
142 
144  bool isXNull() const {
145  return (xState == NULL_DIR);
146  };
147 
149  bool isXSpecified() const {
150  return (xState == SPECIFIED);
151  };
152 
154  void setNullX() {
155  x = 0.0;
156  xState = NULL_DIR;
157  };
158 
160  void setX(const double x) {
161  this->x = x;
162  xState = SPECIFIED;
163  };
165 
167 
168  double getY() const {
170  return y;
171  };
172 
174  bool isYNull() const {
175  return (yState == NULL_DIR);
176  };
177 
179  bool isYSpecified() const {
180  return (yState == SPECIFIED);
181  };
182 
184  void setNullY() {
185  y = 0.0;
186  yState = NULL_DIR;
187  };
188 
190  void setY(const double y) {
191  this->y = y;
192  yState = SPECIFIED;
193  };
194 
196 
198 
199  double getZ() const {
201  return z;
202  };
203 
205  bool isZNull() const {
206  return (zState == NULL_DIR);
207  };
208 
210  bool isZSpecified() const {
211  return (zState == SPECIFIED);
212  };
213 
215  void setNullZ() {
216  z = 0.0;
217  zState = NULL_DIR;
218  };
219 
221  void setZ(const double z) {
222  this->z = z;
223  zState = SPECIFIED;
224  };
225 
227 
228 private:
230  enum DirState {
235  };
236 
238  double x{0.0};
240  double y{0.0};
242  double z{0.0};
250  int towardIndex{-1};
251 };
252 
253 #endif //DIRECTION_H
Direction(const Direction &d)
copy constructor
Definition: Direction.h:55
void xmlPrint(std::ostream &o) const
print to an ostream
Definition: Direction.h:66
bool isToward() const
true only if the direction is set by a toward atom
Definition: Direction.h:131
bool isZNull() const
is the z coordinate NULL ?
Definition: Direction.h:205
the direction is set dynamically depending on the "toward" position
Definition: Direction.h:234
DirState yState
state for the y coordinates
Definition: Direction.h:246
double getY() const
get the y coordinate
Definition: Direction.h:169
void setX(const double x)
set the x coordinate
Definition: Direction.h:160
bool isXNull() const
is the x coordinate NULL ?
Definition: Direction.h:144
int towardIndex
toward atom index
Definition: Direction.h:250
void setNullZ()
set the z coordinate as NULL
Definition: Direction.h:215
double y
y coordinates
Definition: Direction.h:240
void setNullX()
set the x coordinate as NULL
Definition: Direction.h:154
double z
z coordinates
Definition: Direction.h:242
Direction()
default constructor: nothing is specified
Definition: Direction.h:43
bool isXSpecified() const
is the x coordinate specified
Definition: Direction.h:149
Direction(double x0, double y0, double z0)
constructor with initialization of the 3 directions
Definition: Direction.h:49
Class that defines the direction of the Load with x, y and z.
Definition: Direction.h:39
bool isZSpecified() const
is the z coordinate specified
Definition: Direction.h:210
the direction has been specified to be always null
Definition: Direction.h:232
void setToward(const unsigned int toward)
set the toward index
Definition: Direction.h:125
int getToward() const
get the toward index
Definition: Direction.h:120
double getX() const
get the x coordinate
Definition: Direction.h:139
Direction(const unsigned int toward)
constructor with initialization of the toward
Definition: Direction.h:45
void setY(const double y)
set the y coordinate
Definition: Direction.h:190
the direction has never been specified: it is absolutly free
Definition: Direction.h:231
double x
x coordinates
Definition: Direction.h:238
bool isYSpecified() const
is the y coordinate specified
Definition: Direction.h:179
the direction has been specified to be something imposed but not null (even 0.0 is possible!) ...
Definition: Direction.h:233
double getZ() const
get the z coordinate
Definition: Direction.h:200
void setZ(const double z)
set the z coordinate
Definition: Direction.h:221
void setNullY()
set the y coordinate as NULL
Definition: Direction.h:184
DirState xState
state for the x coordinates
Definition: Direction.h:244
DirState
state of the x,y and z
Definition: Direction.h:230
DirState zState
state for the z coordinates
Definition: Direction.h:248
bool isYNull() const
is the y coordinate NULL ?
Definition: Direction.h:174