18 #include <igtlImageMessage.h>
19 #include <itkByteSwapper.h>
30 img = m_previousImage;
35 igtl::ImageMessage* imgMsg = (igtl::ImageMessage*)(msgBase.GetPointer());
37 bool big_endian = (imgMsg->GetEndian() == igtl::ImageMessage::ENDIAN_BIG);
39 if (imgMsg->GetCoordinateSystem() != igtl::ImageMessage::COORDINATE_RAS)
42 mitkThrow() <<
"Can not handle messages with LPS coordinate system";
45 switch (imgMsg->GetScalarType())
47 case igtl::ImageMessage::TYPE_UINT8:
48 Initiate<unsigned char>(img, imgMsg, big_endian);
50 case igtl::ImageMessage::TYPE_INT8:
51 Initiate<char>(img, imgMsg, big_endian);
53 case igtl::ImageMessage::TYPE_UINT16:
54 Initiate<unsigned short>(img, imgMsg, big_endian);
56 case igtl::ImageMessage::TYPE_INT16:
57 Initiate<short>(img, imgMsg, big_endian);
59 case igtl::ImageMessage::TYPE_UINT32:
60 Initiate<unsigned int>(img, imgMsg, big_endian);
62 case igtl::ImageMessage::TYPE_INT32:
63 Initiate<int>(img, imgMsg, big_endian);
65 case igtl::ImageMessage::TYPE_FLOAT32:
66 Initiate<float>(img, imgMsg, big_endian);
68 case igtl::ImageMessage::TYPE_FLOAT64:
69 Initiate<double>(img, imgMsg, big_endian);
72 mitkThrow() <<
"Incompatible PixelType " << imgMsg;
76 template <
typename TPixel>
78 igtl::ImageMessage* msg,
84 typename ImageType::RegionType region;
85 typename ImageType::RegionType::SizeType size;
86 typename ImageType::RegionType::IndexType index;
87 typename ImageType::SpacingType spacing;
92 msg->GetDimensions(dims);
94 for (
size_t i = 0; i < 3; i++)
102 int sdims[3], offs[3];
103 msg->GetSubVolume(sdims, offs);
104 for (
size_t i = 0; i < 3; i++)
106 if (offs[i] != 0 || sdims[i] != dims[i])
109 throw(
"Can not handle message with smaller subvolume than whole image");
116 msg->GetMatrix(matF);
119 for (
size_t i = 0; i < 4; ++i)
120 for (
size_t j = 0; j < 4; ++j)
121 vtkMatrix->SetElement(i, j, matF[i][j]);
125 msg->GetSpacing(spacingMsg);
127 for (
int i = 0; i < 3; ++i)
128 spacing[i] = spacingMsg[i];
130 region.SetSize(size);
131 region.SetIndex(index);
132 output->SetRegions(region);
133 output->SetSpacing(spacing);
136 TPixel*
in = (TPixel*)msg->GetScalarPointer();
137 TPixel* out = (TPixel*)output->GetBufferPointer();
138 memcpy(out, in, num_pixel *
sizeof(TPixel));
144 itk::ByteSwapper<TPixel>::SwapRangeFromSystemToBigEndian(out, num_pixel);
148 itk::ByteSwapper<TPixel>::SwapRangeFromSystemToLittleEndian(out, num_pixel);
152 img->InitializeByItk(output.GetPointer());
153 img->SetVolume(output->GetBufferPointer());
155 m_previousImage = img;
159 msg->GetOrigin(iorigin);
160 for (
size_t i = 0; i < 3; i++)
162 origin[i] = iorigin[i];
164 output->SetOrigin(origin);
168 : m_upstream(nullptr)
170 MITK_DEBUG <<
"Instantiated this (" <<
this <<
") mitkIGTMessageToUSImageFilter\n";
174 unsigned int numOutputs)
178 throw(
"Can only have 1 output for IGTLMessageToUSImageFilter.");
185 MITK_DEBUG <<
"Connected this (" <<
this <<
") mitkIGTLMessageToUSImageFilter to MessageSource (" << UpstreamFilter <<
")\n";
186 m_upstream = UpstreamFilter;
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual igtl::MessageBase::Pointer GetMessage() const
returns the OpenIGTLink message
void ConnectTo(mitk::IGTLMessageSource *UpstreamFilter)
Connects the input of this filter to the outputs of the given IGTLMessageSource.
itk::SmartPointer< Self > Pointer
const char * GetIGTLMessageType() const
IGTLMessageToUSImageFilter()
map::core::discrete::Elements< 3 >::InternalImageType ImageType
void SetNumberOfExpectedOutputs(unsigned int numOutputs)
Sets the number of expected outputs.
IGTLMessage * GetOutput(void)
return the output (output with id 0) of the filter
A wrapper for the OpenIGTLink message type.
OpenIGTLink message source.
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
virtual void GetNextRawImage(mitk::Image::Pointer &img)
Copies the data from the next OIGTL message to an mitk::Image.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.