29#include <itkImportImageFilter.h>
31#include <itkPointSet.h>
33#include <itkFixedArray.h>
51 const std::string &handling=
"");
79template<
typename SIZE_TYPE>
83 if (
sizeObj.GetSizeDimension() >
static_cast<unsigned int>(vec.
dim())){
86 "Too high ITK dimension. The ML can handle only 6 dimensions.");
89 for (
unsigned int i=0;
i<
sizeObj.GetSizeDimension();
i++){
107template<
typename INDEX_TYPE>
111 if (
sizeObj.GetIndexDimension() >
static_cast<unsigned int>(vec.
dim())){
114 "Too high ITK dimension. The ML can handle only 6 dimensions.");
117 for (
unsigned int i=0;
i<
sizeObj.GetIndexDimension();
i++){
134template<
typename INDEX_TYPE>
139 unsigned int vecDim =
static_cast<unsigned int>(vec.
dim());
161template<
typename INDEX_TYPE>
166 unsigned int vecDim =
static_cast<unsigned int>(vec.
dim());
189template<
typename VECTOR_TYPE>
193 for (
unsigned int i=0;
i<
sizeObj.GetVectorDimension();
i++){
212template<
typename VECTOR_TYPE>
216 for (
unsigned int i=0;
i<
sizeObj.GetVectorDimension();
i++){
235template<
typename POINT_TYPE>
239 for (
unsigned int i=0;
i<
sizeObj.GetPointDimension();
i++){
258template<
typename POINT_TYPE>
262 for (
unsigned int i=0;
i<
sizeObj.GetPointDimension();
i++){
280template<
typename REGION_PARENT_TYPE>
283 typename REGION_PARENT_TYPE::RegionType
region;
302template<
typename REGION_PARENT_TYPE>
323template<
typename ARRAY_TYPE,
typename STL_VECTOR>
336template<
typename VERSOR_TYPE>
347template<
typename ARR_TYP,
unsigned int ARR_SIZE>
356template<
typename ITK_ARRAY_TYPE>
367template<
typename STL_CONTAINER,
typename ITK_ARRAY_TYPE>
381template<
typename ITK_VERSOR_TYPE>
401template<
typename INDEX_TYPE>
405 if (
sizeObj.GetIndexDimension() > 6){
422template<
class FilterType>
454 (
vl ?
vl->getNum() : 0))));
459 typename FilterType::NodeContainer::Pointer
nc = FilterType::NodeContainer::New();
491 typename FilterType::NodeType
pnt;
494 nc->InsertElement(c,
pnt);
518template<
typename DTYPE,
unsigned int ROW_DIM,
unsigned int COL_DIM>
522 itk::Matrix<DTYPE, ROW_DIM, COL_DIM>
retMat;
530 "Too high row dimension of ITK matrix. Only 4 dimensions will be converted.");
536 "Too high col dimension of ITK matrix. Only 4 dimensions will be converted.");
540 for (
unsigned int row=0; row <
maxRowDim; ++row){
560template<
typename DTYPE,
unsigned int ROW_DIM,
unsigned int COL_DIM>
572 "Too high row dimension of ITK matrix. Only 4 dimensions will be converted.");
581 "Too high col dimension of ITK matrix. Only 4 dimensions will be converted.");
588 for (
unsigned int row=0; row <
maxRowDim; ++row){
604template<
class POINTSETTYPE>
626 (
vl ?
vl->getNum() : 0))));
630 int maxDim = POINTSETTYPE::PointDimension;
635 "Too high dimension of ITK PointSet. Only 6 dimensions will be converted.");
641 typename POINTSETTYPE::Pointer
outputPointSet = POINTSETTYPE::New();
643 typedef typename POINTSETTYPE::PointDataContainer
DataContainer;
648 typename POINTSETTYPE::PointIdentifier
pointId = 0;
649 typename POINTSETTYPE::PointType
point;
689 typename POINTSETTYPE::Pointer
outputPointSet = POINTSETTYPE::New();
699template <
typename ITK_IMPORT_IMAGE_FILTER_TYPE>
701 ITK_IMPORT_IMAGE_FILTER_TYPE::OutputImageType::ImageDimension>*
importImageFilter,
712template <
typename ITK_IMAGE_TYPE>
714 ITK_IMAGE_TYPE::ImageDimension>* image,
740template <
typename ITK_CLASS_TYPE>
745 if (!image){
return; }
792 ITK_CLASS_TYPE::DirectionType::RowDimensions,
793 ITK_CLASS_TYPE::DirectionType::ColumnDimensions>(
mat);
824template <
typename ITK_CLASS_TYPE>
830 if (!image){
return; }
831 if (ITK_CLASS_TYPE::ImageDimension < 2){
834 "1 D itk world matrix conversion is not supported; "
835 "using identity as return value.");
840 const typename ITK_CLASS_TYPE::SpacingType spacing = image->GetSpacing();
841 const typename ITK_CLASS_TYPE::PointType origin = image->GetOrigin();
842 const typename ITK_CLASS_TYPE::DirectionType direction = image->GetDirection();
846 ITK_CLASS_TYPE::ImageDimension,
864 const double spacing2 = (ITK_CLASS_TYPE::ImageDimension > 2) ? spacing[2] : 1;
870 mat[0][3] = origin[0];
871 mat[1][3] = origin[1];
872 mat[2][3] = (ITK_CLASS_TYPE::ImageDimension > 2) ? origin[2] : 0;
905template <
typename ITK_INDATATYPE,
unsigned int DIM>
926 static_cast<itk::SizeValueType
>(
inSubImgBox.getNumVoxels()),
952 template <
typename RETURN_TYPE_PTR,
typename FILTER_TYPE,
typename VOXEL_TYPE>
983 typename FILTER_TYPE::Pointer
importer = FILTER_TYPE::New();
1000 ML_PRINT_ERROR(
"mlITKSupportToolFunctions::getInputAsItkImportImageAndSubImg()",
1002 "Failed to request input image data, probably subsequent operations will fail");
Field to encapsulate a pointer to an ML base object.
Class representing general ML objects that support import/export via strings (setPersistentState() an...
This class encapsulates basic medical image properties:
Vector3 getVoxelSize() const
Returns the voxel size.
void setVoxelToWorldMatrix(const Matrix4 &matrix)
Sets the matrix which transforms voxel to world coordinates to matrix.
void translateVoxelToWorldMatrix(const Vector3 &offsetVector)
Translates the voxelToWorld matrix by the offsetVector.
const Matrix4 & getVoxelToWorldMatrix() const
Returns the voxelToWorld matrix.
Base class for an image processing module of the ML.
Class which represents an image, which manages properties of an image and image data which is located...
Base object class PointList managing a list of points.
Class to handle Rotations (internally the rotation is stored as a unit quaternion)
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
static MLint dim()
Returns the dimension the ML calculates with.
VectorType v1
Corner v1 of the subimage region (included in region).
VectorType v2
Corner v2 of the subimage region (also included in region!).
This template class manages/represents a rectangular 6d image region in memory which is organized lin...
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...
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0, otherwise false.
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm;...
#define ML_BAD_DIMENSION
The image or data structure has wrong extent or dimensions.
MLint32 MLErrorCode
Type of an ML Error code.
#define ML_RESULT_OK
No error. Everything seems to be okay.
#define ML_PRINT_FATAL_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_FATAL_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be du...
#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...
#define ML_PRINT_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped.
#define MLITK_SUPPORT_EXPORT
When included by other libraries MLITK_SUPPORT_EXPORT is compiled as import symbol.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
@ ML_FATAL_MEMORY_ERROR
On allocation failure a fatal error print is done and NULL is returned.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
SSIZE_T MLssize_t
The signed ML size type which is a signed 32 bit size_t on 32 bit platforms and 64 bit one on 64 bit ...
MLMessageType
Message types handled by the ErrorOutput class.
ImageVector MLVectorFromITKSize(const INDEX_TYPE &sizeObj, MLint defaultVal)
Assign and cast values from an ITK size object to an ML ImageVector.
void setITKWorldFromMedicalImageProperty(MedicalImageProperties props, ITK_CLASS_TYPE *image, bool correctSVS=true)
Takes the world transformation of ML MedicalImageProperties and sets spacing, origin and direction co...
const STL_CONTAINER STLVectorFromITKArray(const ITK_ARRAY_TYPE &itkArray)
Returns an STL container object of type STL_CONTAINER which contains cast copies of all elements of t...
MLITK_SUPPORT_EXPORT void setAllowedTypesForITKNodeContainer(BaseField *field)
Set the allowed types for input Base fields that are converted to ITK NodeContainer objects.
FilterType::NodeContainer::Pointer ITKNodeContainerFromBasePointer(Base *baseVal)
Reads a base field and looks for point like data structures (XMarkerLists, XMarkerListContainers,...
REGION_PARENT_TYPE::RegionType ITKRegionFromMLSubImgBox(const SubImageBox &subImgBox)
Assign and cast values from an ITK region to an ML SubImageBox object.
POINT_TYPE ITKPointFromMLVec3(const Vector3 &vec, MLdouble defaultComp)
Assign and cast values from an ML Vector3 to an ITK point object; all itk components with index > 3 a...
Matrix4 MLMatrixFromITKMatrix(const ITKML_TYPENAME itk::Matrix< DTYPE, ROW_DIM, COL_DIM > &mat, bool fillWithID=false, bool suppressDimensionWarning=false)
Converts itk::Matrix mat of type itk::Matrix<DTYPE, ROW_DIM, COL_DIM> to the returned ML 4x4 matrix o...
POINTSETTYPE::Pointer ITKPointSetFromBasePointer(Base *baseVal)
Reads the passed baseVal objects and looks for point like data structures (XMarkerLists,...
const ml::Vector4 MLVectorFromITKVersor(const ITK_VERSOR_TYPE &itkVersor)
Returns an STL container object of type STL_CONTAINER which contains cast copies of all elements of t...
void ITKSetOriginFromVec3(itk::ImportImageFilter< typename ITK_IMPORT_IMAGE_FILTER_TYPE::OutputImagePixelType, ITK_IMPORT_IMAGE_FILTER_TYPE::OutputImageType::ImageDimension > *importImageFilter, const Vector3 &orig)
On the given ITK_IMPORT_IMAGE_FILTER_TYPE the origin orig is set with the SetOrigin method from an or...
VECTOR_TYPE ITKVectorFromMLVec4(const Vector4 &vec, MLdouble defaultComp)
Assign and cast values from an ML Vector4 to an ITK size object; all itk components with index > 3 ar...
POINT_TYPE ITKPointFromMLVec4(const Vector4 &vec, MLdouble defaultComp)
Assign and cast values from an ML Vector4 to an ITK object of type POINT_TYPE; all itk components wit...
size_t GetSizeOfAnITKArray(const itk::FixedArray< ARR_TYP, ARR_SIZE > &itkArray)
Returns the size of an itk::FixedArray.
MLITK_SUPPORT_EXPORT void copyITKDataBufferToMLSubImg(void *itkData, size_t itkDataTypeSize, const SubImageBox &itkBox, SubImage &outSubImg)
Unpack ITK data buffer to an ML subimage and convert data formats if necessary.
SIZE_TYPE ITKSizeFromMLVector(const ImageVector &vec)
Assign and cast values from an ML ImageVector to an ITK size object.
RETURN_TYPE_PTR getInputAsItkImportImageAndSubImg(Module &op, int inIdx, TSubImage< VOXEL_TYPE > &dataSubImg, bool correctSVS=true)
Reads and updates an input image from the input number inIdx of Module op and sets up the referenced ...
itk::Matrix< DTYPE, ROW_DIM, COL_DIM > ITKMatrixFromMLMatrix(const Matrix4 &mat)
Converts the ML 4x4 matrix mat function argument to the returned itk::Matrix of type itk::Matrix<DTYP...
VERSOR_TYPE ITKVersorFromMLVector(const ml::Vector4 &mlVec)
Returns an object of an ITK array type ARRAY_TYPE which contains cast copies of all elements of stlVe...
SubImageBox MLSubImgBoxFromITKRegion(const typename REGION_PARENT_TYPE::RegionType ®ion)
Assign and cast values from an ITK region to an ML SubImageBox object.
ImageVector MLVectorFromITKIndex(const INDEX_TYPE &indexObj, MLint defaultVal)
Assign and cast values from an ITK index object to an ML ImageVector.
INDEX_TYPE ITKIndexFromMLVector(const ImageVector &vec)
Assign and cast values from an ML ImageVector to an ITK size object.
INDEX_TYPE ITKIndexFromMLVec6(const Vector6 &vec)
Assign and cast values from an ML Vector6 to an ITK index object of type INDEX_TYPE.
void setMLWorldFromITKScaleOriginAndOrientation(const ITK_CLASS_TYPE *image, MedicalImageProperties &props, bool correctSVS=true, bool suppressDimensionWarning=false)
Sets the world transformation of the ML MedicalImageProperties props from the spacing,...
ARRAY_TYPE ITKArrayFromSTLVector(const STL_VECTOR &stlVec)
Returns an object of an ITK array type ARRAY_TYPE which contains cast copies of all elements of stlVe...
itk::ImportImageFilter< ITK_INDATATYPE, DIM >::Pointer getITKImportImageFromSubImg(const SubImage &inSubImg, const MedicalImageProperties &props, bool correctSVS=true)
Takes a SubImage and returns an object of an itk::ImportImageFilter managing the inSubImg as ITK obje...
MLITK_SUPPORT_EXPORT void postITKException(const itk::ExceptionObject &e, const Module *module, MLMessageType messageType, const std::string &handling="")
Sends all available information from the ITKException itkException to the ML error handler.
VECTOR_TYPE ITKVectorFromMLVec3(const Vector3 &vec, MLdouble defaultComp)
Assign and cast values from an ML Vector3 to an ITK size object; all itk components with index > 2 ar...