open_iA 2025.6
Loading...
Searching...
No Matches
iAToolsVTK.cpp File Reference
#include "iAToolsVTK.h"
#include "iAConnector.h"
#include "iAITKIO.h"
#include "iALog.h"
#include "iAMathUtility.h"
#include "iAProgress.h"
#include "iATypedCallHelper.h"
#include "iAValueTypeVectorHelpers.h"
#include "iAVtkDraw.h"
#include <vtkBMPWriter.h>
#include <vtkCamera.h>
#include <vtkImageData.h>
#include <vtkImageWriter.h>
#include <vtkJPEGWriter.h>
#include <vtkObjectFactory.h>
#include <vtkPNGWriter.h>
#include <vtkTIFFWriter.h>
#include <vtkColorTransferFunction.h>
#include <vtkImageReader.h>
#include <vtkLookupTable.h>
#include <vtkPiecewiseFunction.h>
#include <QFileInfo>
#include <QRegularExpression>
#include <QStringList>

Functions

void addImages (vtkSmartPointer< vtkImageData > imgDst, vtkSmartPointer< vtkImageData > const imgToAdd, iAProgress *p)
 add values of one image to the values of another image
 
void adjustIndexAndSizeToImage (QVariantMap &params, vtkImageData *img)
 Given index and size parameters in a QVariantMap, adjust these parameters so that they specify a region of interest that lies completely within the given image.
 
vtkSmartPointer< iAvtkImageDataallocateiAImage (int vtkType, int const dimensions[3], double const spacing[3], int numComponents)
 allocate an iAvtkImageData image
 
vtkSmartPointer< vtkImageData > allocateImage (int vtkType, int const dimensions[3], double const spacing[3])
 Create a VTK image with the given properties.
 
vtkSmartPointer< vtkImageData > allocateImage (int vtkType, int const dimensions[3], double const spacing[3], int numComponents)
 Create a VTK image with the given properties.
 
vtkSmartPointer< vtkImageData > allocateImage (vtkSmartPointer< vtkImageData > img)
 Create a VTK image that has the same properties (type, size, spacing) as the given image.
 
void convertLUTToTF (vtkSmartPointer< vtkLookupTable > lut, vtkSmartPointer< vtkColorTransferFunction > ctf, vtkSmartPointer< vtkPiecewiseFunction > otf, double alphaOverride)
 
void convertTFToLUT (vtkSmartPointer< vtkLookupTable > lut, vtkSmartPointer< vtkScalarsToColors > ctf, vtkSmartPointer< vtkPiecewiseFunction > otf, int numCols, double const *lutRange, bool reverse)
 
void copyCameraParams (vtkCamera *dstCam, vtkCamera *srcCam)
 
void fillImage (vtkSmartPointer< vtkImageData > img, double const value, iAProgress *p)
 fill all pixels in the given image with the given value
 
bool isFlat (vtkImageData *img)
 Checks whether an image is flat.
 
bool isVtkIntegerImage (vtkImageData *img)
 Check whether the given image holds integer numbers.
 
int mapReadableDataTypeToVTKType (QString const &dataTypeName)
 Maps a given data type string to the corresponding VTK type identifier.
 
QString mapVTKTypeToReadableDataType (int vtkType)
 Maps a given VTK type to the corresponding readable data type.
 
size_t mapVTKTypeToSize (int vtkType)
 Returns the size (in bytes) of the given VTK type.
 
iAVec3i mapWorldCoordsToIndex (vtkImageData *img, double const *worldCoord)
 Translate from world coordinates to voxel indices for the given image.
 
void mapWorldToVoxelCoords (vtkImageData *img, double const *worldCoord, double *voxelCoord)
 Translate from world coordinates to voxel coordinates for the given image.
 
iAbase_API void multiplyImage (vtkSmartPointer< vtkImageData > img, double value, iAProgress *p)
 multiply all values of an image with the given value
 
QStringList const & readableDataTypeList (bool withLongLongTypes)
 Returns a human-readable list of available data types for a single pixel/voxel.
 
vtkSmartPointer< vtkImageData > readImage (QString const &filename)
 Read an image from disk into a VTK image.
 
void setCamPosition (vtkCamera *cam, iACameraPosition pos)
 Set given camera position to one of the predefined positions available in iACameraPosition.
 
void storeImage (vtkSmartPointer< vtkImageData > img, QString const &filename, bool useCompression, iAProgress const *progress)
 Stores an image on disk (typically in .mhd format).
 
 vtkStandardNewMacro (iAvtkImageData)
 
void writeSingleSliceImage (QString const &filename, vtkImageData *img, int compressionLevel)
 Write a single slice image to a common 2D picture format.
 

Function Documentation

◆ addImages()

void addImages ( vtkSmartPointer< vtkImageData > imgDst,
vtkSmartPointer< vtkImageData > const imgToAdd,
iAProgress * p = nullptr )

add values of one image to the values of another image

Parameters
imgDstdestination image (will be modified)
imgToAddimage with values to be added to imgDst (will not be modified)
pif given, used to report progress

◆ adjustIndexAndSizeToImage()

void adjustIndexAndSizeToImage ( QVariantMap & params,
vtkImageData * img )

Given index and size parameters in a QVariantMap, adjust these parameters so that they specify a region of interest that lies completely within the given image.

Parameters
paramsmap of parameters (which should contain values for "Index" and "Size", as iAValueType::Vector3i, i.e. QVector<int>)
imgthe image whose size determines the clamping of parameters

◆ allocateiAImage()

vtkSmartPointer< iAvtkImageData > allocateiAImage ( int vtkType,
int const dimensions[3],
double const spacing[3],
int numComponents )

allocate an iAvtkImageData image

◆ allocateImage() [1/3]

vtkSmartPointer< vtkImageData > allocateImage ( int vtkType,
int const dimensions[3],
double const spacing[3] )

Create a VTK image with the given properties.

Parameters
vtkTypethe VTK type identifier (VTK_INT, VTK_UNSIGNED_CHAR, ...) for the voxel data type to use in the new image
dimensionsthe size of the image in the 3 dimensions.
spacingthe spacing (distance of voxels) in each of the 3 dimension directions.
Returns
an image with a single component and the type, size and spacing as the given parameters, with allocated but uninitialized pixel data.

◆ allocateImage() [2/3]

vtkSmartPointer< vtkImageData > allocateImage ( int vtkType,
int const dimensions[3],
double const spacing[3],
int numComponents )

Create a VTK image with the given properties.

Parameters
vtkTypethe VTK type identifier (VTK_INT, VTK_UNSIGNED_CHAR, ...) for the voxel data type to use in the new image
dimensionsthe size of the image in the 3 dimensions.
spacingthe spacing (distance of voxels) in each of the 3 dimension directions.
numComponentsthe number of components in each voxel.
Returns
an image with the type, size, spacing and number of components as the given parameters, with allocated but uninitialized pixel data.

◆ allocateImage() [3/3]

vtkSmartPointer< vtkImageData > allocateImage ( vtkSmartPointer< vtkImageData > img)

Create a VTK image that has the same properties (type, size, spacing) as the given image.

Parameters
imgimage whose type, size and spacing will be used to create the result image; its data will not be copied over to the new image
Returns
an image that has the same type, size and spacing as the image given as parameter, with allocated but uninitialized pixel data.

◆ convertLUTToTF()

void convertLUTToTF ( vtkSmartPointer< vtkLookupTable > lut,
vtkSmartPointer< vtkColorTransferFunction > ctf,
vtkSmartPointer< vtkPiecewiseFunction > otf,
double alphaOverride )

◆ convertTFToLUT()

void convertTFToLUT ( vtkSmartPointer< vtkLookupTable > lut,
vtkSmartPointer< vtkScalarsToColors > ctf,
vtkSmartPointer< vtkPiecewiseFunction > otf,
int numCols,
double const * lutRange,
bool reverse )

◆ copyCameraParams()

void copyCameraParams ( vtkCamera * dstCam,
vtkCamera * srcCam )

◆ fillImage()

void fillImage ( vtkSmartPointer< vtkImageData > img,
double const value,
iAProgress * p = nullptr )

fill all pixels in the given image with the given value

Parameters
imgimage to be filled
valueused to fill each voxel in given image
pif given, used to report progress

◆ isFlat()

bool isFlat ( vtkImageData * img)

Checks whether an image is flat.

Parameters
imga VTK image
Returns
whether the image is flat in any direction, i.e. whether one side is only 1 pixel wide.

◆ isVtkIntegerImage()

bool isVtkIntegerImage ( vtkImageData * img)

Check whether the given image holds integer numbers.

Parameters
imga VTK image
Returns
true if the values in the given VTK image are integer numbers, false if it holds floating point numbers

◆ mapReadableDataTypeToVTKType()

int mapReadableDataTypeToVTKType ( QString const & dataTypeName)

Maps a given data type string to the corresponding VTK type identifier.

Reverse of mapVTKTypeToReadableDataType

Parameters
dataTypeNamean entry from the list of readable data types (see readableDataTypeList())
Returns
the VTK type identifier (VTK_INT, VTK_UNSIGNED_CHAR, ...) for the given readable data type name, or -1 if the given name is not on the list

◆ mapVTKTypeToReadableDataType()

QString mapVTKTypeToReadableDataType ( int vtkType)

Maps a given VTK type to the corresponding readable data type.

Reverse of mapReadableDataTypeToVTKType

Parameters
vtkTypethe VTK type identifier (VTK_INT, VTK_UNSIGNED_CHAR, ...)
Returns
the name (in the list as returned by readableDataTypeList()) of the given VTK type identifier, or -1 if the given VTK type identifier is unknown

◆ mapVTKTypeToSize()

size_t mapVTKTypeToSize ( int vtkType)

Returns the size (in bytes) of the given VTK type.

Parameters
vtkTypea VTK type identifier (VTK_INT, VTK_UNSIGNED_CHAR, ...)
Returns
the size in bytes of the given type (VTK_SIGNED_CHAR/VTK_UNSIGNED_CHAR -> 1, ...), or 0 if it's an unknown type

◆ mapWorldCoordsToIndex()

iAVec3i mapWorldCoordsToIndex ( vtkImageData * img,
double const * worldCoord )

Translate from world coordinates to voxel indices for the given image.

Parameters
imga VTK image
worldCoordworld (=scene) coordinates (3 components: x, y, z)
Returns
voxel indices, the coordinates in img for the given world coordinates (clamped)

◆ mapWorldToVoxelCoords()

void mapWorldToVoxelCoords ( vtkImageData * img,
double const * worldCoord,
double * voxelCoord )

Translate from world coordinates to voxel coordinates for the given image.

Parameters
imga VTK image
worldCoordworld (=scene) coordinates (3 components: x, y, z)
voxelCoordplace for storing 3 components of voxel coordinates in img for the given world coordinates (clamped)

◆ multiplyImage()

iAbase_API void multiplyImage ( vtkSmartPointer< vtkImageData > imgDst,
double value,
iAProgress * p = nullptr )

multiply all values of an image with the given value

Parameters
imgDstthe image to be multiplied
valuemultiplier used for each voxel
pif given, used to report progress

◆ readableDataTypeList()

QStringList const & readableDataTypeList ( bool withLongLongTypes)

Returns a human-readable list of available data types for a single pixel/voxel.

Parameters
withLongLongTypeswhether to include 64 bit signed/unsigned integer types

◆ readImage()

vtkSmartPointer< vtkImageData > readImage ( QString const & filename)

Read an image from disk into a VTK image.

Parameters
filenamethe name of the file to read.

◆ setCamPosition()

void setCamPosition ( vtkCamera * cam,
iACameraPosition pos )

Set given camera position to one of the predefined positions available in iACameraPosition.

◆ storeImage()

void storeImage ( vtkSmartPointer< vtkImageData > img,
QString const & filename,
bool useCompression = true,
iAProgress const * progress = nullptr )

Stores an image on disk (typically in .mhd format).

Parameters
imgthe image to store
filenamethe name of the file to write to.
useCompressionwhether the file should be compressed (.zraw) or not (.raw) in case we are storing .mhd files
progressan optional progress link; if != null, the file writer will trigger its progress signal

◆ vtkStandardNewMacro()

vtkStandardNewMacro ( iAvtkImageData )

◆ writeSingleSliceImage()

void writeSingleSliceImage ( QString const & filename,
vtkImageData * img,
int compressionLevel = 5 )

Write a single slice image to a common 2D picture format.

Parameters
filenamethe name of the file to write to; this is expected to have an extension of tif, png, jpg or bmp; the type of the file written will be chosen according to this extension
imgthe image to write; this already needs to be a 2D image (i.e., size in Z dimension = 1)
compressionLevelif output is in .png format, the compression level (0.. no compression, 9.. highest compression)