Computer Assisted Medical Intervention Tool Kit version 6.0
 
Loading...
Searching...
No Matches
AnatomicalOrientation.h
Go to the documentation of this file.
1/*****************************************************************************
2 * $CAMITK_LICENCE_BEGIN$
3 *
4 * CamiTK - Computer Assisted Medical Intervention ToolKit
5 * (c) 2001-2025 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#ifndef ANATOMICALORIENTATION_H
27#define ANATOMICALORIENTATION_H
28
29#include <array>
30#include <QVariantList>
31#include <QVariantMap>
32#include <QVariant>
33#include <QString>
34#include <QUuid>
35
36
37namespace camitk {
38
39
84
85public:
94
98 explicit AnatomicalOrientation(QString threeLetterCode) {
99 setOrientation(threeLetterCode);
100 }
101
105 AnatomicalOrientation(QString minXLabel, QString maxXLabel, QString minYLabel, QString maxYLabel, QString minZLabel, QString maxZLabel) {
106 setOrientation(minXLabel, maxXLabel, minYLabel, maxYLabel, minZLabel, maxZLabel);
107 }
108
112 void setUnkown() {
113 known = false;
114 code = "";
115 minLabels.fill("");
116 maxLabels.fill("");
117 }
118
122 bool isUnknown() const {
123 return !known;
124 }
125
129 void setOrientation(QString threeLetterCode) {
130 if (this->set3LetterCode(threeLetterCode)) {
131 known = true;
132 }
133 else {
134 known = false;
135 }
136
137 }
138
142 void setOrientation(QString minXLabel, QString maxXLabel, QString minYLabel, QString maxYLabel, QString minZLabel, QString maxZLabel) {
143 code = "";
144 minLabels = {minXLabel, minYLabel, minZLabel};
145 maxLabels = {maxXLabel, maxYLabel, maxZLabel};
146 known = true;
147 }
148
152 void setMinLabel(int axis, QString minLabel) {
153 if (axis >= 0 && axis < 3) {
154 code = "";
155 minLabels[axis] = minLabel;
156 known = true;
157 }
158 }
159
163 void setMaxLabel(int axis, QString maxLabel) {
164 if (axis >= 0 && axis < 3) {
165 code = "";
166 maxLabels[axis] = maxLabel;
167 known = true;
168 }
169 }
170
176 void setLabels(int axis, QString minLabel, QString maxLabel) {
177 setMinLabel(axis, minLabel);
178 setMaxLabel(axis, maxLabel);
179 };
180
184 QString getMinLabel(int axis) const {
185 if (axis >= 0 && axis < 3) {
186 return minLabels[axis];
187 }
188 else {
189 return "";
190 }
191 }
192
196 QString getMaxLabel(int axis) const {
197 if (axis >= 0 && axis < 3) {
198 return maxLabels[axis];
199 }
200 else {
201 return "";
202 }
203 }
204
217 std::pair<int, bool> getAxisFromName(QString name) const {
218 for (unsigned int ax = 0; ax < 3; ++ax) {
219 if (minLabels[ax] == name) {
220 return {ax, true};
221 }
222 else if (maxLabels[ax] == name) {
223 return {ax, false};
224 }
225 }
226 return {-1, false};
227 }
228
233 static QString invert3LetterCode(const QString& code) {
234 QString invertedCode = code;
235 for (int i = 0; i < code.size(); ++i) {
236 if (code[i] == 'R') {
237 invertedCode[i] = 'L';
238 }
239 else if (code[i] == 'L') {
240 invertedCode[i] = 'R';
241 }
242 else if (code[i] == 'A') {
243 invertedCode[i] = 'P';
244 }
245 else if (code[i] == 'P') {
246 invertedCode[i] = 'A';
247 }
248 else if (code[i] == 'I') {
249 invertedCode[i] = 'S';
250 }
251 else if (code[i] == 'S') {
252 invertedCode[i] = 'I';
253 }
254 else if (code[i] == 'F') {
255 invertedCode[i] = 'H';
256 }
257 else if (code[i] == 'H') {
258 invertedCode[i] = 'F';
259 }
260 }
261 return invertedCode;
262 }
263
271 QString get3LetterCode(bool plus = false) const {
272 if (!known || code.isEmpty()) {
273 return "";
274 }
275 if (plus) { // Invert the axis letters and add a '+' at the end
276 QString plusCode = AnatomicalOrientation::invert3LetterCode(code);
277 plusCode.append('+');
278 return plusCode;
279 }
280 else {
281 return code;
282 }
283 }
284
291 QString getLabel(int axis, bool minDirection) const {
292 if (axis >= 0 && axis < 3) {
293 return minDirection ? minLabels[axis] : maxLabels[axis];
294 }
295 return "";
296 }
297
300
304 QVariant toVariant() const override {
305 if (known) {
306 return QVariantMap {
307 {"code", code},
308 {"minLabels", QVariantList{minLabels[0], minLabels[1], minLabels[2]}},
309 {"maxLabels", QVariantList{maxLabels[0], maxLabels[1], maxLabels[2]}},
310 };
311 }
312 else {
313 return QVariantMap();
314 }
315 }
316
320 void fromVariant(const QVariant& variant) override {
321 known = false;
322 code = "";
323 QVariantMap map = variant.toMap();
324 QVariantList list;
325 if (map.contains("code")) { // It is known
326 known = true;
327 code = map.value("code").toString();
328 }
329
330 if (map.contains("minLabels") && map.contains("maxLabels")) {
331 known = true;
332
333 list = map.value("minLabels").toList();
334 if (list.size() == 3) {
335 minLabels[0] = list[0].toString();
336 minLabels[1] = list[1].toString();
337 minLabels[2] = list[2].toString();
338 }
339 else {
340 minLabels.fill("");
341 }
342
343 list = map.value("maxLabels").toList();
344 if (list.size() == 3) {
345 maxLabels[0] = list[0].toString();
346 maxLabels[1] = list[1].toString();
347 maxLabels[2] = list[2].toString();
348 }
349 else {
350 maxLabels.fill("");
351 }
352 }
353 else { // Unknown
354 if (code.isEmpty()) {
355 minLabels.fill("");
356 maxLabels.fill("");
357 }
358 else {
359 set3LetterCode(code); // Ensure minLabels and maxLabels are filled from the code
360 }
361
362 }
363 }
364
369 bool setUuid(QUuid newid) override {
370 return false;
371 }
372
377 QUuid getUuid() const override {
378 return QUuid();
379 }
381
382private:
384 std::array<QString, 3> minLabels;
385
387 std::array<QString, 3> maxLabels;
388
390 bool known;
391
393 QString code;
394
406 bool set3LetterCode(QString code = "", bool forcePlus = false) {
407 if (code.size() < 3 || code.size() > 4) { // Minimum 3 letters, maximum 4 (in case there is a '+' at the end)
408 return false;
409 }
410 if ((code.size() > 3 && code[3] == '+') || forcePlus) {
412 }
413 else {
414 this->code = code;
415 }
416 this->code.truncate(3); // in case there is an unwanted trailing '+'
417 QString invertedCode = AnatomicalOrientation::invert3LetterCode(this->code);
418 minLabels[0] = code[0];
419 minLabels[1] = code[1];
420 minLabels[2] = code[2];
421 maxLabels[0] = invertedCode[0];
422 maxLabels[1] = invertedCode[1];
423 maxLabels[2] = invertedCode[2];
424 known = true;
425 return true;
426 }
427
428};
429
430} // namespace camitk
431
432#endif // ANATOMICALORIENTATION_H
AnatomicalOrientation describes the relationship between 3D axes of a FrameOfReference and medical im...
Definition AnatomicalOrientation.h:83
AnatomicalOrientation(QString minXLabel, QString maxXLabel, QString minYLabel, QString maxYLabel, QString minZLabel, QString maxZLabel)
Constructor setting a custom label for each axis negative and positive directions.
Definition AnatomicalOrientation.h:105
void setMaxLabel(int axis, QString maxLabel)
Set the label of the corresponding axis positive direction.
Definition AnatomicalOrientation.h:163
bool setUuid(QUuid newid) override
SetUuid does nothing It does not store the uuid, but is needed to implement InterfacePersistence.
Definition AnatomicalOrientation.h:369
QString getMaxLabel(int axis) const
Get the label of the positive/maximum direction of the specified axis.
Definition AnatomicalOrientation.h:196
QString getLabel(int axis, bool minDirection) const
Returns the label of the corresponding axis/direction (or empty string if there is no label)
Definition AnatomicalOrientation.h:291
QString getMinLabel(int axis) const
Get the label of the negative/minimum direction of the specified axis.
Definition AnatomicalOrientation.h:184
void setOrientation(QString threeLetterCode)
Sets the orientation using the standard 3-letter code.
Definition AnatomicalOrientation.h:129
void setLabels(int axis, QString minLabel, QString maxLabel)
Set both negative and positive direction labels for an axis.
Definition AnatomicalOrientation.h:176
QString get3LetterCode(bool plus=false) const
Return the current 3 letter code or an empty string if it is unknown or custom.
Definition AnatomicalOrientation.h:271
void setUnkown()
Reset anatomical information to unknown.
Definition AnatomicalOrientation.h:112
QVariant toVariant() const override
Convert all data from the object to a QVariantMap.
Definition AnatomicalOrientation.h:304
bool isUnknown() const
Check if anatomical information is unknown.
Definition AnatomicalOrientation.h:122
AnatomicalOrientation()
Default constructor.
Definition AnatomicalOrientation.h:91
AnatomicalOrientation(QString threeLetterCode)
Constructor from a 3-letter code (e.g.
Definition AnatomicalOrientation.h:98
void setOrientation(QString minXLabel, QString maxXLabel, QString minYLabel, QString maxYLabel, QString minZLabel, QString maxZLabel)
Set a custom label for the negative and positive directions of all axes.
Definition AnatomicalOrientation.h:142
void fromVariant(const QVariant &variant) override
Load data from a QVariant to initialize the current object.
Definition AnatomicalOrientation.h:320
QUuid getUuid() const override
Returns an invalid uuid because AnatomicalOrientation is part of a FrameOfReference which has its own...
Definition AnatomicalOrientation.h:377
static QString invert3LetterCode(const QString &code)
Returns the inverted 3-letter code (e.g.
Definition AnatomicalOrientation.h:233
void setMinLabel(int axis, QString minLabel)
Set the label of the corresponding axis negative direction.
Definition AnatomicalOrientation.h:152
std::pair< int, bool > getAxisFromName(QString name) const
Definition AnatomicalOrientation.h:217
Interface for all objects that should be serialized by the PersistenceManager.
Definition InterfacePersistence.h:38
Definition Action.cpp:40