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
34ML_START_NAMESPACE
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.
57 if (ML_BASE_IS_A(baseVal, XMarkerListContainer)){ xmlc = static_cast<XMarkerListContainer*>(baseVal); }
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();
125 if (emptyDefaultToOneZeroVal){
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 ITKFiniteDifferenceFunctionWrapper if there is one connected.
150 if (functionObject) {
151 defaultFunction = functionObject->GetFiniteDifferenceFunction(static_cast<FINITE_DIFFERENCE_FUNCTION_TYPE*>(nullptr));
152 }
153 else {
154 // Create and return a default difference function.
155 //defaultFunction = FINITE_DIFFERENCE_FUNCTION_TYPE::New();
156 }
157
158 // Return the found or the default function.
159 return defaultFunction;
160}
161
162ML_END_NAMESPACE
BaseItem * getItemAt(MLssize_t index) override
Definition mlListBase.h:693
FiniteDifferenceFunctionImg2OfVoxInt8Type::Pointer GetFiniteDifferenceFunction(FiniteDifferenceFunctionImg2OfVoxInt8Type *)
Base object class PointList managing a list of points.
Definition mlPointList.h:29
void getValue(MLssize_t index, Vector3 &vec) const
get point at given index
MLssize_t getNum() const
returns the number of contained points
Base object representing a list of vectors given as Vector4's.
void getPoint(MLssize_t index, int &type, float &x1, float &y1, float &z1) const
returns point of vectors at given point index (NOTE: (0,1 = first vector , 2,3 = second vector))
MLssize_t getNum() const
returns the number of contained points
#define ML_BASE_IS_A(base, type)
#define ML_BAD_DIMENSION
The image or data structure has wrong extent or dimensions.
Definition mlTypeDefs.h:834
#define ML_PRINT_WARNING(FUNC_NAME, REASON, HANDLING)
ToTypePtr mlbase_cast(ml::Base *from)
Template function to allow type-safe casting of a base object to a derived object.
Definition mlBase.h:176
POLYLINEPATHTYPE::Pointer ITKPolylineFromBasePointer(Base *baseVal, bool emptyDefaultToOneZeroVal=true)
Tvec6< MLdouble > Vector6
A vector with six components of type double.
Definition mlVector6.h:194
FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer ITKDifferenceFunctionFromBasePointer(Base *baseVal)