15 #include "itkByteSwapper.h" 16 #include "igtlImageMessage.h" 21 this->SetNumberOfRequiredOutputs(1);
22 this->SetNthOutput(0, output.GetPointer());
23 this->SetNumberOfRequiredInputs(1);
29 for (
unsigned int i = 0; i < this->GetNumberOfIndexedOutputs(); ++i)
41 MITK_ERROR <<
"Can not handle dimensionless images";
45 MITK_ERROR <<
"Can not handle more than three dimensions";
51 MITK_ERROR <<
"Can not handle anything but one channel. Image contained " << chn;
55 igtl::ImageMessage::Pointer imgMsg = igtl::ImageMessage::New();
58 imgMsg->SetCoordinateSystem(igtl::ImageMessage::COORDINATE_RAS);
63 imgMsg->SetEndian(igtl::ImageMessage::ENDIAN_LITTLE);
72 case itk::ImageIOBase::CHAR:
73 imgMsg->SetScalarTypeToInt8();
75 case itk::ImageIOBase::UCHAR:
76 imgMsg->SetScalarTypeToUint8();
78 case itk::ImageIOBase::SHORT:
79 imgMsg->SetScalarTypeToInt16();
81 case itk::ImageIOBase::USHORT:
82 imgMsg->SetScalarTypeToUint16();
84 case itk::ImageIOBase::INT:
85 imgMsg->SetScalarTypeToInt32();
87 case itk::ImageIOBase::UINT:
88 imgMsg->SetScalarTypeToUint32();
90 case itk::ImageIOBase::LONG:
94 imgMsg->SetScalarType(8);
96 case itk::ImageIOBase::ULONG:
100 imgMsg->SetScalarType(9);
102 case itk::ImageIOBase::FLOAT:
104 imgMsg->SetScalarType(10);
106 case itk::ImageIOBase::DOUBLE:
108 imgMsg->SetScalarType(11);
111 MITK_ERROR <<
"Can not handle pixel component type " 120 for (
size_t i = 0; i < 4; ++i)
122 for (
size_t j = 0; j < 4; ++j)
124 matF[i][j] = matrix->GetElement(i, j);
127 imgMsg->SetMatrix(matF);
132 for (
int i = 0; i < 3; ++i)
133 spacing[i] = spacingImg[i];
135 imgMsg->SetSpacing(spacing);
139 for (
size_t j = 0; j < 3; ++j)
143 imgMsg->SetDimensions(sizes);
146 imgMsg->AllocatePack();
147 imgMsg->AllocateScalars();
149 size_t num_pixel = sizes[0] * sizes[1] * sizes[2];
150 void* out = imgMsg->GetScalarPointer();
154 const void*
in = readAccess.GetData();
156 memcpy(out, in, num_pixel * type.
GetSize());
166 case itk::ImageIOBase::CHAR:
167 case itk::ImageIOBase::UCHAR:
170 case itk::ImageIOBase::SHORT:
171 case itk::ImageIOBase::USHORT:
172 itk::ByteSwapper<short>::SwapRangeFromSystemToLittleEndian((
short*)out,
175 case itk::ImageIOBase::INT:
176 case itk::ImageIOBase::UINT:
177 itk::ByteSwapper<int>::SwapRangeFromSystemToLittleEndian((
int*)out,
180 case itk::ImageIOBase::LONG:
181 case itk::ImageIOBase::ULONG:
182 itk::ByteSwapper<long>::SwapRangeFromSystemToLittleEndian((
long*)out,
185 case itk::ImageIOBase::FLOAT:
186 itk::ByteSwapper<float>::SwapRangeFromSystemToLittleEndian((
float*)out,
189 case itk::ImageIOBase::DOUBLE:
190 itk::ByteSwapper<double>::SwapRangeFromSystemToLittleEndian(
191 (
double*)out, num_scalars);
196 igtl::TimeStamp::Pointer timestamp = igtl::TimeStamp::New();
198 imgMsg->SetTimeStamp(timestamp);
208 this->ProcessObject::SetNthInput(0, const_cast<mitk::Image*>(img));
215 this->ProcessObject::SetNthInput(idx, const_cast<mitk::Image*>(img));
221 if (this->GetNumberOfInputs() < 1)
223 return static_cast<const mitk::Image*
>(this->ProcessObject::GetInput(0));
228 if (this->GetNumberOfInputs() < idx + 1)
232 return static_cast<const mitk::Image*
>(this->ProcessObject::GetInput(idx));
237 MITK_INFO <<
"Image source for this (" <<
this <<
") mitkImageToIGTLMessageFilter is " << upstream;
238 for (DataObjectPointerArraySizeType i = 0; i < upstream->GetNumberOfOutputs();
241 this->
SetInput(i, upstream->GetOutput(i));
248 this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs());
250 for (
size_t idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx)
254 this->SetNthOutput(idx, this->
MakeOutput(idx));
Superclass of all classes generating Images (instances of class Image) as output. ...
ImageToIGTLMessageFilter()
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::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
const mitk::Image * GetInput()
Returns the input of this filter.
virtual ImageDataItemPointer GetChannelData(int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
IGTLMessage * GetOutput(void)
return the output (output with id 0) of the filter
unsigned int GetNumberOfChannels() const
Get the number of channels.
unsigned int GetDimension() const
Get dimension of the image.
A wrapper for the OpenIGTLink message type.
Image class for storing images.
void GenerateData() override
filter execute method
virtual void CreateOutputsForAllInputs()
create output objects for all inputs
unsigned long GetMTime() const override
Get the modified time of the last change of the contents this data object or its geometry.
vcl_size_t GetSize() const
Get size of the PixelType in bytes.
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
virtual void SetInput(const mitk::Image *img)
Sets one input 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.