MeVisLabToolboxReference
FMEwork/ITK/Sources/ITK/MLITK/ITKSupport/mlITKSpecialFieldsSupport.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00008 //----------------------------------------------------------------------------------
00009 
00010 #ifndef __mlITKSpecialFieldsSupport_H
00011 #define __mlITKSpecialFieldsSupport_H
00012 
00014 // Include dll-specific settings.
00015 #include "mlInitSystemITKSupport.h"
00016 
00018 #ifndef __mlModuleIncludes_H
00019 #include "mlModuleIncludes.h"
00020 #endif
00021 
00023 #ifndef __mlMultiFields_H
00024 #include "mlMultiFields.h"
00025 #endif
00026 
00028 #ifndef __mlPointList_H
00029 #include "mlPointList.h"
00030 #endif
00031 #ifndef __mlVectorList_H
00032 #include "mlVectorList.h"
00033 #endif
00034 #ifndef __mlXMarkerList_H
00035 #include "mlXMarkerList.h"
00036 #endif
00037 #ifndef __mlITKMultiBaseConnect_H
00038 #include "mlITKMultiBaseConnect.h"
00039 #endif
00040 
00041 #include <itkPolyLineParametricPath.h>
00042 #include <itkFiniteDifferenceFunction.h>
00043 
00044 ML_START_NAMESPACE
00045 
00046 //---------------------------------------------------------------------------
00055 //---------------------------------------------------------------------------
00056 template<class POLYLINEPATHTYPE>
00057 typename POLYLINEPATHTYPE::Pointer ITKPolylineFromBasePointer(Base *baseVal, bool emptyDefaultToOneZeroVal=true)
00058 {
00059   ML_TRACE_IN("ITKPointSetFromBasePointer()");
00060 
00061   XMarkerListContainer *xmlc = NULL;
00062   XMarkerList          *xml  = NULL;
00063   PointList            *pl   = NULL;
00064   VectorList           *vl   = NULL;
00065 
00066   // Get base field.
00067   if (baseVal){
00068     // Check for different base object types.
00069     if (ML_BASE_IS_A(baseVal, XMarkerListContainer)){ xmlc = static_cast<XMarkerListContainer*>(baseVal); }
00070     else if (ML_BASE_IS_A(baseVal, XMarkerList))    { xml  = static_cast<XMarkerList*>(baseVal);          }
00071     else if (ML_BASE_IS_A(baseVal, PointList))      { pl   = static_cast<PointList*>(baseVal);            }
00072     else if (ML_BASE_IS_A(baseVal, VectorList))     { vl   = static_cast<VectorList*>(baseVal);           }
00073     else{ /* No valid type in base field. That can happen. */ }
00074   }
00075 
00076   // Get number of points from list.
00077   size_t numVals = (xmlc ? xmlc->getList()->size() : 
00078                    (xml  ? xml->size()            : 
00079                    (pl   ? static_cast<size_t>(pl->getNum()) : 
00080                    (vl   ? static_cast<size_t>(vl->getNum()) : 0))));
00081 
00082 
00083   // Determine maximum point dimension, clamp it to 6.
00084   int maxDim = POLYLINEPATHTYPE::VertexType::IndexDimension;
00085   if (maxDim > 6){
00086     maxDim = 6;
00087     ML_PRINT_WARNING("ITKPolylineFromBasePointer", ML_BAD_DIMENSION, "Too high dimension of itk Polyline. Only 6 dimensions will be converted.");
00088   }
00089 
00090   if (numVals > 0){
00091 
00092     // Create point set object.
00093     typename POLYLINEPATHTYPE::Pointer outputPolyline = POLYLINEPATHTYPE::New();                                             
00094 
00095     // A point to be added.
00096     typename POLYLINEPATHTYPE::VertexType point;
00097 
00098     // Insert all list elements into the NodeContainer.
00099     for (size_t c=0; c < numVals; ++c){
00100       // Get point list value if we have such a list.
00101       Vector6 plVal(0);
00102       if (pl){
00103         float px=0, py=0, pz=0; 
00104         pl->getValue(c, px, py, pz); 
00105         plVal[0] = px;
00106         plVal[1] = py;
00107         plVal[2] = pz;
00108       }
00109 
00110       // Get point list value if we have such a list.
00111       Vector6 vlVal(0);
00112       int vecType=0;
00113       if (vl){
00114         float px=0, py=0, pz=0; 
00115         vl->getPoint(c, vecType, px, py, pz);
00116         vlVal[0]=px;
00117         vlVal[1]=py;
00118         vlVal[2]=pz;
00119       }
00120 
00121       // get position from any of the lists.
00122       Vector6 mlVec((xmlc ? (static_cast<XMarker*>(xmlc->getList()->getItemAt(c)))->pos :
00123                     (xml  ? (static_cast<XMarker*>(xml->getItemAt(c)))->pos             :
00124                     (pl   ? plVal                                            :
00125                     (vl   ? vlVal                                            : Vector6(0))))));
00126 
00127       // Copy point components.
00128       for (int j=0;j< maxDim ;j++){ point[j] = mlVec[j]; }
00129       outputPolyline->AddVertex(point);
00130     }
00131 
00132     return outputPolyline;
00133   }
00134   else{
00135     // Create and return default (empty) point set object.
00136     typename POLYLINEPATHTYPE::Pointer outputPolyline = POLYLINEPATHTYPE::New();
00137     if (emptyDefaultToOneZeroVal){
00138       // Add at least one point at coordinates (0,...,0).
00139       typename POLYLINEPATHTYPE::VertexType point;
00140       outputPolyline->AddVertex(point);
00141     }
00142     return outputPolyline;
00143   }
00144 }
00145 
00146 
00147 //---------------------------------------------------------------------------
00153 //---------------------------------------------------------------------------
00154 template<class FINITE_DIFFERENCE_FUNCTION_TYPE>
00155 typename FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer ITKDifferenceFunctionFromBasePointer(Base *baseVal)
00156 {
00157   ML_TRACE_IN("ITKDifferenceFunctionFromBasePointer()");
00158 
00159   // Return value to be validated with function from connection.
00160   typename FINITE_DIFFERENCE_FUNCTION_TYPE::Pointer defaultFunction = NULL;
00161 
00162   // Pointer to MultiBaseObject is there is one connected.
00163   MultiBaseType *multiBaseObject=NULL;
00164 
00165   // Get base field.
00166   if (baseVal){
00167     // Check for different base object types.
00168     if (ML_BASE_IS_A(baseVal, MultiBaseTypeWrapper)){
00169       multiBaseObject = static_cast<MultiBaseTypeWrapper*>(baseVal)->getWrappedOutputObject();
00170       if (multiBaseObject){
00171         defaultFunction = multiBaseObject->GetFiniteDifferenceFunction((FINITE_DIFFERENCE_FUNCTION_TYPE*)NULL);
00172       }
00173     }
00174   }
00175   else{
00176     // Create and return a default difference function.
00177     //defaultFunction = FINITE_DIFFERENCE_FUNCTION_TYPE::New();                                             
00178   }
00179 
00180   // Return the found or the default function.
00181   return defaultFunction;
00182 }
00183 
00184 ML_END_NAMESPACE
00185 
00186 #endif // __mlITKSpecialFieldsSupport_H
00187