Computer Assited Medical Intervention Tool Kit  version 4.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-2016 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:
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  } else {
71  switch (xState) {
72  case NOT_SPECIFIED:
73  break;
74  case NULL_DIR:
75  o << "x=\"NULL\" ";
76  break;
77  case SPECIFIED:
78  o << "x=\"" << x << "\" ";
79  break;
80  default:
81  break;
82  }
83  switch (yState) {
84  case NOT_SPECIFIED:
85  break;
86  case NULL_DIR:
87  o << "y=\"NULL\" ";
88  break;
89  case SPECIFIED:
90  o << "y=\"" << y << "\" ";
91  break;
92  default:
93  break;
94  }
95  switch (zState) {
96  case NOT_SPECIFIED:
97  break;
98  case NULL_DIR:
99  o << "z=\"NULL\"";
100  break;
101  case SPECIFIED:
102  o << "z=\"" << z << "\"";
103  break;
104  default:
105  break;
106  }
107  }
108  o << "/>" << std::endl;
109  };
110 
112  void set(const double x, const double y, const double z) {
113  setX(x);
114  setY(y);
115  setZ(z);
116  };
117 
119  int getToward() const {
120  return towardIndex;
121  };
122 
124  void setToward(const unsigned int toward) {
125  towardIndex=toward;
126  xState = yState = zState = TOWARD;
127  };
128 
130  bool isToward() const {
131  return (towardIndex>=0 && xState==TOWARD && yState==TOWARD && zState==TOWARD);
132  };
133 
135 
136 
138  double getX() const {
139  return x;
140  };
141 
143  bool isXNull() const {
144  return (xState==NULL_DIR);
145  };
146 
148  bool isXSpecified() const {
149  return (xState==SPECIFIED);
150  };
151 
153  void setNullX() {
154  x=0.0;
155  xState = NULL_DIR;
156  };
157 
159  void setX(const double x) {
160  this->x = x;
161  xState = SPECIFIED;
162  };
164 
166 
167  double getY() const {
169  return y;
170  };
171 
173  bool isYNull() const {
174  return (yState==NULL_DIR);
175  };
176 
178  bool isYSpecified() const {
179  return (yState==SPECIFIED);
180  };
181 
183  void setNullY() {
184  y=0.0;
185  yState = NULL_DIR;
186  };
187 
189  void setY(const double y) {
190  this->y = y;
191  yState = SPECIFIED;
192  };
193 
195 
197 
198  double getZ() const {
200  return z;
201  };
202 
204  bool isZNull() const {
205  return (zState==NULL_DIR);
206  };
207 
209  bool isZSpecified() const {
210  return (zState==SPECIFIED);
211  };
212 
214  void setNullZ() {
215  z=0.0;
216  zState = NULL_DIR;
217  };
218 
220  void setZ(const double z) {
221  this->z = z;
222  zState = SPECIFIED;
223  };
224 
226 
227 private:
229  enum DirState {
234  };
235 
237  double x;
239  double y;
241  double z;
250 };
251 
252 #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:130
bool isZNull() const
is the z coordinate NULL ?
Definition: Direction.h:204
the direction is set dynamically depending on the "toward" position
Definition: Direction.h:233
DirState yState
state for the y coordinates
Definition: Direction.h:245
double getY() const
get the y coordinate
Definition: Direction.h:168
void setX(const double x)
set the x coordinate
Definition: Direction.h:159
bool isXNull() const
is the x coordinate NULL ?
Definition: Direction.h:143
int towardIndex
toward atom index
Definition: Direction.h:249
void setNullZ()
set the z coordinate as NULL
Definition: Direction.h:214
double y
y coordinates
Definition: Direction.h:239
void setNullX()
set the x coordinate as NULL
Definition: Direction.h:153
double z
z coordinates
Definition: Direction.h:241
Direction()
default constructor: nothing is specified
Definition: Direction.h:43
bool isXSpecified() const
is the x coordinate specified
Definition: Direction.h:148
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:209
the direction has been specified to be always null
Definition: Direction.h:231
void setToward(const unsigned int toward)
set the toward index
Definition: Direction.h:124
int getToward() const
get the toward index
Definition: Direction.h:119
double getX() const
get the x coordinate
Definition: Direction.h:138
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:189
the direction has never been specified: it is absolutly free
Definition: Direction.h:230
double x
x coordinates
Definition: Direction.h:237
bool isYSpecified() const
is the y coordinate specified
Definition: Direction.h:178
the direction has been specified to be something imposed but not null (even 0.0 is possible!) ...
Definition: Direction.h:232
double getZ() const
get the z coordinate
Definition: Direction.h:199
void setZ(const double z)
set the z coordinate
Definition: Direction.h:220
void setNullY()
set the y coordinate as NULL
Definition: Direction.h:183
DirState xState
state for the x coordinates
Definition: Direction.h:243
DirState
state of the x,y and z
Definition: Direction.h:229
DirState zState
state for the z coordinates
Definition: Direction.h:247
bool isYNull() const
is the y coordinate NULL ?
Definition: Direction.h:173