MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlITKSpecialFieldsSupport.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#pragma once
14
16// Include dll-specific settings.
18
20#include "mlModuleIncludes.h"
21
23#include "mlMultiFields.h"
24
26#include "mlPointList.h"
27#include "mlVectorList.h"
28#include "mlXMarkerList.h"
30
31#include <itkPolyLineParametricPath.h>
32#include <itkFiniteDifferenceFunction.h>
33
35
36//---------------------------------------------------------------------------
45//---------------------------------------------------------------------------
46template <class POLYLINEPATHTYPE>
47typename POLYLINEPATHTYPE::Pointer ITKPolylineFromBasePointer(Base* baseVal, bool emptyDefaultToOneZeroVal = true)
48{
49 XMarkerListContainer* xmlc = nullptr;
50 XMarkerList* xml = nullptr;
51 PointList* pl = nullptr;
52 VectorList* vl = nullptr;
53
54 // Get base field.
55 if (baseVal) {
56 // Check for different base object types.
58 xmlc = static_cast<XMarkerListContainer*>(baseVal);
59 }
60 else if (ML_BASE_IS_A(baseVal, XMarkerList)) {
61 xml = static_cast<XMarkerList*>(baseVal);
62 }
63 else if (ML_BASE_IS_A(baseVal, PointList)) {
64 pl = static_cast<PointList*>(baseVal);
65 }
66 else if (ML_BASE_IS_A(baseVal, VectorList)) {
67 vl = static_cast<VectorList*>(baseVal);
68 }
69 else { /* No valid type in base field. That can happen. */
70 }
71 }
72
73 // Get number of points from list.
74 size_t numVals =
75 (xmlc ? xmlc->getList()->size()
76 : (xml ? xml->size()
77 : (pl ? static_cast<size_t>(pl->getNum()) : (vl ? static_cast<size_t>(vl->getNum()) : 0))));
78
79
80 // Determine maximum point dimension, clamp it to 6.
81 int maxDim = POLYLINEPATHTYPE::VertexType::IndexDimension;
82 if (maxDim > 6) {
83 maxDim = 6;
84 ML_PRINT_WARNING("ITKPolylineFromBasePointer", ML_BAD_DIMENSION,
85 "Too high dimension of itk Polyline. Only 6 dimensions will be converted.");
86 }
87
88 if (numVals > 0) {
89
90 // Create point set object.
91 typename POLYLINEPATHTYPE::Pointer outputPolyline = POLYLINEPATHTYPE::New();
92
93 // A point to be added.
94 typename POLYLINEPATHTYPE::VertexType point;
95
96 // Insert all list elements into the NodeContainer.
97 for (size_t c = 0; c < numVals; ++c) {
98 // Get point list value if we have such a list.
99 Vector6 plVal(0);
100 if (pl) {
101 float px = 0, py = 0, pz = 0;
102 pl->getValue(c, px, py, pz);
103 plVal[0] = px;
104 plVal[1] = py;
105 plVal[2] = pz;
106 }
107
108 // Get point list value if we have such a list.
109 Vector6 vlVal(0);
110 int vecType = 0;
111 if (vl) {
112 float px = 0, py = 0, pz = 0;
113 vl->getPoint(c, vecType, px, py, pz);
114 vlVal[0] = px;
115 vlVal[1] = py;
116 vlVal[2] = pz;
117 }
118
119 // get position from any of the lists.
121 (xmlc ? (static_cast<XMarker*>(xmlc->getList()->getItemAt(c)))->pos
122 : (xml ? (static_cast<XMarker*>(xml->getItemAt(c)))->pos : (pl ? plVal : (vl ? vlVal : Vector6(0))))));
123
124 // Copy point components.
125 for (int j = 0; j < maxDim; j++) {
126 point[j] = mlVec[j];
127 }
128 outputPolyline->AddVertex(point);
129 }
130
131 return outputPolyline;
132 }
133 else {
134 // Create and return default (empty) point set object.
135 typename POLYLINEPATHTYPE::Pointer outputPolyline = POLYLINEPATHTYPE::New();
137 // Add at least one point at coordinates (0,...,0).
138 typename POLYLINEPATHTYPE::VertexType point;
139 outputPolyline->AddVertex(point);
140 }
141 return outputPolyline;
142 }
143}
144
145
146//---------------------------------------------------------------------------
152//---------------------------------------------------------------------------
153template <class FINITE_DIFFERENCE_FUNCTION_TYPE>
154typename FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer ITKDifferenceFunctionFromBasePointer(Base* baseVal)
155{
156 // Return value to be validated with function from connection.
157 typename FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer defaultFunction = nullptr;
158
159 // Pointer to ITKFiniteDifferenceFunctionWrapper if there is one connected.
161 if (functionObject) {
163 functionObject->GetFiniteDifferenceFunction(static_cast<FINITE_DIFFERENCE_FUNCTION_TYPE*>(nullptr));
164 }
165 else {
166 // Create and return a default difference function.
167 // defaultFunction = FINITE_DIFFERENCE_FUNCTION_TYPE::New();
168 }
169
170 // Return the found or the default function.
171 return defaultFunction;
172}
173
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:63
Class to provide a number of get/set functions for often used templated objects, for example function...
Base object class PointList managing a list of points.
Definition mlPointList.h:30
Base object representing a list of vectors given as Vector4's.
Base object class XMarkerListContainer (derived from ListContainerTemplate) for XMarkerList objects.
Base object class XMarkerList (derived from BaseListTemplate) specialized for XMarker items.
Base object class XMarker (derived form baseItem) with 6D pos, 3D vec and type int.
#define ML_BASE_IS_A(base, type)
This file defines macros that are inserted in classes to declare and implement additional class membe...
#define ML_BAD_DIMENSION
The image or data structure has wrong extent or dimensions.
Definition mlTypeDefs.h:891
#define ML_PRINT_WARNING(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_WARNING_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
POLYLINEPATHTYPE::Pointer ITKPolylineFromBasePointer(Base *baseVal, bool emptyDefaultToOneZeroVal=true)
Reads a base field and looks for point like data structures (XMarkerLists, XMarkerListContainers,...
FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer ITKDifferenceFunctionFromBasePointer(Base *baseVal)
Checks a base input connector for a base object containing a ITKFiniteDifferenceFunctionWrapper.