19 #include "itkByteSwapper.h"
20 #include "igtlImageMessage.h"
25 this->SetNumberOfRequiredOutputs(1);
26 this->SetNthOutput(0, output.GetPointer());
27 this->SetNumberOfRequiredInputs(1);
33 for (
unsigned int i = 0; i < this->GetNumberOfIndexedOutputs(); ++i)
43 MITK_INFO <<
"Sending image. Dimensions: " << dims <<
" Channels: " << chn <<
"\n";
47 MITK_ERROR <<
"Can not handle dimensionless images";
51 MITK_ERROR <<
"Can not handle more than three dimensions";
57 MITK_ERROR <<
"Can not handle anything but one channel. Image contained " << chn;
64 imgMsg->SetCoordinateSystem(igtl::ImageMessage::COORDINATE_RAS);
69 imgMsg->SetEndian(igtl::ImageMessage::ENDIAN_LITTLE);
78 case itk::ImageIOBase::CHAR:
79 imgMsg->SetScalarTypeToInt8();
81 case itk::ImageIOBase::UCHAR:
82 imgMsg->SetScalarTypeToUint8();
84 case itk::ImageIOBase::SHORT:
85 imgMsg->SetScalarTypeToInt16();
87 case itk::ImageIOBase::USHORT:
88 imgMsg->SetScalarTypeToUint16();
90 case itk::ImageIOBase::INT:
91 imgMsg->SetScalarTypeToInt32();
93 case itk::ImageIOBase::UINT:
94 imgMsg->SetScalarTypeToUint32();
96 case itk::ImageIOBase::LONG:
100 imgMsg->SetScalarType(8);
102 case itk::ImageIOBase::ULONG:
106 imgMsg->SetScalarType(9);
108 case itk::ImageIOBase::FLOAT:
110 imgMsg->SetScalarType(10);
112 case itk::ImageIOBase::DOUBLE:
114 imgMsg->SetScalarType(11);
117 MITK_ERROR <<
"Can not handle pixel component type "
126 for (
size_t i = 0; i < 4; ++i)
128 for (
size_t j = 0; j < 4; ++j)
130 matF[i][j] = matrix->GetElement(i, j);
133 imgMsg->SetMatrix(matF);
138 for (
int i = 0; i < 3; ++i)
139 spacing[i] = spacingImg[i];
141 imgMsg->SetSpacing(spacing);
145 for (
size_t j = 0; j < 3; ++j)
149 imgMsg->SetDimensions(sizes);
152 imgMsg->AllocatePack();
153 imgMsg->AllocateScalars();
155 size_t num_pixel = sizes[0] * sizes[1] * sizes[2];
156 void* out = imgMsg->GetScalarPointer();
160 const void*
in = readAccess.GetData();
162 memcpy(out, in, num_pixel * type.
GetSize());
172 case itk::ImageIOBase::CHAR:
173 case itk::ImageIOBase::UCHAR:
176 case itk::ImageIOBase::SHORT:
177 case itk::ImageIOBase::USHORT:
178 itk::ByteSwapper<short>::SwapRangeFromSystemToLittleEndian((
short*)out,
181 case itk::ImageIOBase::INT:
182 case itk::ImageIOBase::UINT:
183 itk::ByteSwapper<int>::SwapRangeFromSystemToLittleEndian((
int*)out,
186 case itk::ImageIOBase::LONG:
187 case itk::ImageIOBase::ULONG:
188 itk::ByteSwapper<long>::SwapRangeFromSystemToLittleEndian((
long*)out,
191 case itk::ImageIOBase::FLOAT:
192 itk::ByteSwapper<float>::SwapRangeFromSystemToLittleEndian((
float*)out,
195 case itk::ImageIOBase::DOUBLE:
196 itk::ByteSwapper<double>::SwapRangeFromSystemToLittleEndian(
197 (
double*)out, num_scalars);
209 this->ProcessObject::SetNthInput(0, const_cast<mitk::Image*>(img));
210 this->CreateOutputsForAllInputs();
216 this->ProcessObject::SetNthInput(idx, const_cast<mitk::Image*>(img));
217 this->CreateOutputsForAllInputs();
222 if (this->GetNumberOfInputs() < 1)
224 return static_cast<const mitk::Image*
>(this->ProcessObject::GetInput(0));
229 if (this->GetNumberOfInputs() < idx + 1)
233 return static_cast<const mitk::Image*
>(this->ProcessObject::GetInput(idx));
238 MITK_INFO <<
"Image source for this (" <<
this <<
") mitkImageToIGTLMessageFilter is " << upstream;
239 for (DataObjectPointerArraySizeType i = 0; i < upstream->GetNumberOfOutputs();
242 this->SetInput(i, upstream->GetOutput(i));
249 this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs());
251 for (
size_t idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx)
253 if (this->GetOutput(idx) == NULL)
255 this->SetNthOutput(idx, this->MakeOutput(idx));
Superclass of all classes generating Images (instances of class Image) as output. ...
ImageToIGTLMessageFilter()
itk::SmartPointer< Self > Pointer
virtual void ConnectTo(mitk::ImageSource *UpstreamFilter)
Connects the input of this filter to the outputs of the given ImageSource.
vtkMatrix4x4 * GetVtkMatrix()
void SetMessage(igtl::MessageBase::Pointer msg)
Sets the OpenIGTLink message.
const mitk::Image * GetInput()
Returns the input of this filter.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
virtual ImageDataItemPointer GetChannelData(int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
vcl_size_t GetSize() const
Get size of the PixelType in bytes.
A wrapper for the OpenIGTLink message type.
Image class for storing images.
virtual void GenerateData() override
filter execute method
virtual void CreateOutputsForAllInputs()
create output objects for all inputs
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
unsigned int GetNumberOfChannels() const
Get the number of channels.
virtual void SetInput(const mitk::Image *img)
Sets one input Image.
unsigned int GetDimension() const
Get dimension of the image.
ImageReadAccessor class to get locked read access for a particular image part.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Class for defining the data type of pixels.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.