MeVisLab Toolbox Reference
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 else if (ML_BASE_IS_A(baseVal, XMarkerList)) { xml = static_cast<XMarkerList*>(baseVal); }
59 else if (ML_BASE_IS_A(baseVal, PointList)) { pl = static_cast<PointList*>(baseVal); }
60 else if (ML_BASE_IS_A(baseVal, VectorList)) { vl = static_cast<VectorList*>(baseVal); }
61 else{ /* No valid type in base field. That can happen. */ }
62 }
63
64 // Get number of points from list.
65 size_t numVals = (xmlc ? xmlc->getList()->size() :
66 (xml ? xml->size() :
67 (pl ? static_cast<size_t>(pl->getNum()) :
68 (vl ? static_cast<size_t>(vl->getNum()) : 0))));
69
70
71 // Determine maximum point dimension, clamp it to 6.
72 int maxDim = POLYLINEPATHTYPE::VertexType::IndexDimension;
73 if (maxDim > 6){
74 maxDim = 6;
75 ML_PRINT_WARNING("ITKPolylineFromBasePointer", ML_BAD_DIMENSION, "Too high dimension of itk Polyline. Only 6 dimensions will be converted.");
76 }
77
78 if (numVals > 0){
79
80 // Create point set object.
81 typename POLYLINEPATHTYPE::Pointer outputPolyline = POLYLINEPATHTYPE::New();
82
83 // A point to be added.
84 typename POLYLINEPATHTYPE::VertexType point;
85
86 // Insert all list elements into the NodeContainer.
87 for (size_t c=0; c < numVals; ++c){
88 // Get point list value if we have such a list.
89 Vector6 plVal(0);
90 if (pl){
91 float px=0, py=0, pz=0;
92 pl->getValue(c, px, py, pz);
93 plVal[0] = px;
94 plVal[1] = py;
95 plVal[2] = pz;
96 }
97
98 // Get point list value if we have such a list.
99 Vector6 vlVal(0);
100 int vecType=0;
101 if (vl){
102 float px=0, py=0, pz=0;
103 vl->getPoint(c, vecType, px, py, pz);
104 vlVal[0]=px;
105 vlVal[1]=py;
106 vlVal[2]=pz;
107 }
108
109 // get position from any of the lists.
110 Vector6 mlVec((xmlc ? (static_cast<XMarker*>(xmlc->getList()->getItemAt(c)))->pos :
111 (xml ? (static_cast<XMarker*>(xml->getItemAt(c)))->pos :
112 (pl ? plVal :
113 (vl ? vlVal : Vector6(0))))));
114
115 // Copy point components.
116 for (int j=0;j< maxDim ;j++){ point[j] = mlVec[j]; }
117 outputPolyline->AddVertex(point);
118 }
119
120 return outputPolyline;
121 }
122 else{
123 // Create and return default (empty) point set object.
124 typename POLYLINEPATHTYPE::Pointer outputPolyline = POLYLINEPATHTYPE::New();
126 // Add at least one point at coordinates (0,...,0).
127 typename POLYLINEPATHTYPE::VertexType point;
128 outputPolyline->AddVertex(point);
129 }
130 return outputPolyline;
131 }
132}
133
134
135//---------------------------------------------------------------------------
141//---------------------------------------------------------------------------
142template<class FINITE_DIFFERENCE_FUNCTION_TYPE>
143typename FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer ITKDifferenceFunctionFromBasePointer(Base *baseVal)
144{
145 // Return value to be validated with function from connection.
146 typename FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer defaultFunction = nullptr;
147
148 // Pointer to MultiBaseObject is there is one connected.
150
151 // Get base field.
152 if (baseVal){
153 // Check for different base object types.
155 multiBaseObject = static_cast<MultiBaseTypeWrapper*>(baseVal)->getWrappedOutputObject();
156 if (multiBaseObject){
158 }
159 }
160 }
161 else{
162 // Create and return a default difference function.
163 //defaultFunction = FINITE_DIFFERENCE_FUNCTION_TYPE::New();
164 }
165
166 // Return the found or the default function.
167 return defaultFunction;
168}
169
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:59
Class to provide a number of get/set functions for often used templated objects, for example function...
FiniteDifferenceFunctionImg2OfVoxInt8Type::Pointer GetFiniteDifferenceFunction(FiniteDifferenceFunctionImg2OfVoxInt8Type *)
Base object class PointList managing a list of points.
Definition mlPointList.h:29
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, which are inserted in classes to declare and implement additional class mem...
#define ML_BAD_DIMENSION
The image or data structure has wrong extent or dimensions.
Definition mlTypeDefs.h:835
#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 MultiBaseType.