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
82
83public:
92
96 explicit AnatomicalOrientation(QString threeLetterCode) {
97 setOrientation(threeLetterCode);
98 }
99
103 AnatomicalOrientation(QString minXLabel, QString maxXLabel, QString minYLabel, QString maxYLabel, QString minZLabel, QString maxZLabel) {
104 setOrientation(minXLabel, maxXLabel, minYLabel, maxYLabel, minZLabel, maxZLabel);
105 }
106
110 void setUnkown() {
111 known = false;
112 code = "";
113 minLabels.fill("");
114 maxLabels.fill("");
115 }
116
120 bool isUnknown() const {
121 return !known;
122 }
123
127 void setOrientation(QString threeLetterCode) {
128 if (this->set3LetterCode(threeLetterCode)) {
129 known = true;
130 }
131 else {
132 known = false;
133 }
134
135 }
136
140 void setOrientation(QString minXLabel, QString maxXLabel, QString minYLabel, QString maxYLabel, QString minZLabel, QString maxZLabel) {
141 code = "";
142 minLabels = {minXLabel, minYLabel, minZLabel};
143 maxLabels = {maxXLabel, maxYLabel, maxZLabel};
144 known = true;
145 }
146
150 void setMinLabel(int axis, QString minLabel) {
151 if (axis >= 0 && axis < 3) {
152 code = "";
153 minLabels[axis] = minLabel;
154 known = true;
155 }
156 }
157
161 void setMaxLabel(int axis, QString maxLabel) {
162 if (axis >= 0 && axis < 3) {
163 code = "";
164 maxLabels[axis] = maxLabel;
165 known = true;
166 }
167 }
168
174 void setLabels(int axis, QString minLabel, QString maxLabel) {
175 setMinLabel(axis, minLabel);
176 setMaxLabel(axis, maxLabel);
177 };
178
182 QString getMinLabel(int axis) const {
183 if (axis >= 0 && axis < 3) {
184 return minLabels[axis];
185 }
186 else {
187 return "";
188 }
189 }
190
194 QString getMaxLabel(int axis) const {
195 if (axis >= 0 && axis < 3) {
196 return maxLabels[axis];
197 }
198 else {
199 return "";
200 }
201 }
202
215 std::pair<int, bool> getAxisFromName(QString name) const {
216 for (unsigned int ax = 0; ax < 3; ++ax) {
217 if (minLabels[ax] == name) {
218 return {ax, true};
219 }
220 else if (maxLabels[ax] == name) {
221 return {ax, false};
222 }
223 }
224 return {-1, false};
225 }
226
231 static QString invert3LetterCode(const QString& code) {
232 QString invertedCode = code;
233 for (int i = 0; i < code.size(); ++i) {
234 if (code[i] == 'R') {
235 invertedCode[i] = 'L';
236 }
237 else if (code[i] == 'L') {
238 invertedCode[i] = 'R';
239 }
240 else if (code[i] == 'A') {
241 invertedCode[i] = 'P';
242 }
243 else if (code[i] == 'P') {
244 invertedCode[i] = 'A';
245 }
246 else if (code[i] == 'I') {
247 invertedCode[i] = 'S';
248 }
249 else if (code[i] == 'S') {
250 invertedCode[i] = 'I';
251 }
252 else if (code[i] == 'F') {
253 invertedCode[i] = 'H';
254 }
255 else if (code[i] == 'H') {
256 invertedCode[i] = 'F';
257 }
258 }
259 return invertedCode;
260 }
261
269 QString get3LetterCode(bool plus = false) const {
270 if (!known || code.isEmpty()) {
271 return "";
272 }
273 if (plus) { // Invert the axis letters and add a '+' at the end
274 QString plusCode = AnatomicalOrientation::invert3LetterCode(code);
275 plusCode.append('+');
276 return plusCode;
277 }
278 else {
279 return code;
280 }
281 }
282
289 QString getLabel(int axis, bool minDirection) const {
290 if (axis >= 0 && axis < 3) {
291 return minDirection ? minLabels[axis] : maxLabels[axis];
292 }
293 return "";
294 }
295
298
302 QVariant toVariant() const override {
303 if (known) {
304 return QVariantMap {
305 {"code", code},
306 {"minLabels", QVariantList{minLabels[0], minLabels[1], minLabels[2]}},
307 {"maxLabels", QVariantList{maxLabels[0], maxLabels[1], maxLabels[2]}},
308 };
309 }
310 else {
311 return QVariantMap();
312 }
313 }
314
318 void fromVariant(const QVariant& variant) override {
319 known = false;
320 code = "";
321 QVariantMap map = variant.toMap();
322 QVariantList list;
323 if (map.contains("code")) { // It is known
324 known = true;
325 code = map.value("code").toString();
326 }
327
328 if (map.contains("minLabels") && map.contains("maxLabels")) {
329 known = true;
330
331 list = map.value("minLabels").toList();
332 if (list.size() == 3) {
333 minLabels[0] = list[0].toString();
334 minLabels[1] = list[1].toString();
335 minLabels[2] = list[2].toString();
336 }
337 else {
338 minLabels.fill("");
339 }
340
341 list = map.value("maxLabels").toList();
342 if (list.size() == 3) {
343 maxLabels[0] = list[0].toString();
344 maxLabels[1] = list[1].toString();
345 maxLabels[2] = list[2].toString();
346 }
347 else {
348 maxLabels.fill("");
349 }
350 }
351 else { // Unknown
352 if (code.isEmpty()) {
353 minLabels.fill("");
354 maxLabels.fill("");
355 }
356 else {
357 set3LetterCode(code); // Ensure minLabels and maxLabels are filled from the code
358 }
359
360 }
361 }
362
367 bool setUuid(QUuid newid) override {
368 return false;
369 }
370
375 QUuid getUuid() const override {
376 return QUuid();
377 }
378
379
380private:
382 std::array<QString, 3> minLabels;
383
385 std::array<QString, 3> maxLabels;
386
388 bool known;
389
391 QString code;
392
404 bool set3LetterCode(QString code = "", bool forcePlus = false) {
405 if (code.size() < 3 || code.size() > 4) { // Minimum 3 letters, maximum 4 (in case there is a '+' at the end)
406 return false;
407 }
408 if ((code.size() > 3 && code[3] == '+') || forcePlus) {
410 }
411 else {
412 this->code = code;
413 }
414 this->code.truncate(3); // in case there is an unwanted trailing '+'
415 QString invertedCode = AnatomicalOrientation::invert3LetterCode(this->code);
416 minLabels[0] = code[0];
417 minLabels[1] = code[1];
418 minLabels[2] = code[2];
419 maxLabels[0] = invertedCode[0];
420 maxLabels[1] = invertedCode[1];
421 maxLabels[2] = invertedCode[2];
422 known = true;
423 return true;
424 }
425
426};
427
428} // namespace camitk
429
430#endif // ANATOMICALORIENTATION_H
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:103
void setMaxLabel(int axis, QString maxLabel)
Set the label of the corresponding axis positive direction.
Definition AnatomicalOrientation.h:161
bool setUuid(QUuid newid) override
SetUuid does nothing It does not store the uuid, but is needed to implement InterfacePersistence.
Definition AnatomicalOrientation.h:367
QString getMaxLabel(int axis) const
Get the label of the positive/maximum direction of the specified axis.
Definition AnatomicalOrientation.h:194
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:289
QString getMinLabel(int axis) const
Get the label of the negative/minimum direction of the specified axis.
Definition AnatomicalOrientation.h:182
void setOrientation(QString threeLetterCode)
Sets the orientation using the standard 3-letter code.
Definition AnatomicalOrientation.h:127
void setLabels(int axis, QString minLabel, QString maxLabel)
Set both negative and positive direction labels for an axis.
Definition AnatomicalOrientation.h:174
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:269
void setUnkown()
Reset anatomical information to unknown.
Definition AnatomicalOrientation.h:110
QVariant toVariant() const override
Convert all data from the object to a QVariantMap.
Definition AnatomicalOrientation.h:302
bool isUnknown() const
Check if anatomical information is unknown.
Definition AnatomicalOrientation.h:120
AnatomicalOrientation()
Default constructor.
Definition AnatomicalOrientation.h:89
AnatomicalOrientation(QString threeLetterCode)
Constructor from a 3-letter code (e.g.
Definition AnatomicalOrientation.h:96
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:140
void fromVariant(const QVariant &variant) override
Load data from a QVariant to initialize the current object.
Definition AnatomicalOrientation.h:318
QUuid getUuid() const override
Returns an invalid uuid because AnatomicalOrientation is part of a FrameOfReference which has its own...
Definition AnatomicalOrientation.h:375
static QString invert3LetterCode(const QString &code)
Returns the inverted 3-letter code (e.g.
Definition AnatomicalOrientation.h:231
void setMinLabel(int axis, QString minLabel)
Set the label of the corresponding axis negative direction.
Definition AnatomicalOrientation.h:150
std::pair< int, bool > getAxisFromName(QString name) const
Definition AnatomicalOrientation.h:215
Interface for all objects that should be serialized by the PersistenceManager.
Definition InterfacePersistence.h:38
Definition Action.cpp:40