22 #include <vtkImageData.h>
23 #include <vtkImageStencil.h>
24 #include <vtkPointData.h>
25 #include <vtkPolyData.h>
26 #include <vtkPolyDataNormals.h>
27 #include <vtkPolyDataToImageStencil.h>
28 #include <vtkSmartPointer.h>
29 #include <vtkTransform.h>
30 #include <vtkTransformPolyDataFilter.h>
33 : m_MakeOutputBinary(false), m_UShortBinaryPixelType(false), m_BackgroundValue(-10000)
55 itkDebugMacro(<<
"GenerateOutputInformation()");
60 if (m_MakeOutputBinary)
62 if (m_UShortBinaryPixelType)
64 output->Initialize(mitk::MakeScalarPixelType<unsigned short>(), *inputImage->
GetTimeGeometry());
68 output->Initialize(mitk::MakeScalarPixelType<unsigned char>(), *inputImage->
GetTimeGeometry());
84 if (inputImage.IsNull())
87 if (output->IsInitialized() ==
false)
92 int tstart = outputRegion.GetIndex(3);
93 int tmax = tstart + outputRegion.GetSize(3);
98 for (t = tstart; t < tmax; ++t)
114 unsigned int size =
sizeof(
unsigned char);
115 if (m_MakeOutputBinary)
117 if (m_UShortBinaryPixelType)
119 binaryImage->Initialize(mitk::MakeScalarPixelType<unsigned short>(), *this->GetImage()->GetTimeGeometry(), 1, 1);
120 size =
sizeof(
unsigned short);
124 binaryImage->Initialize(mitk::MakeScalarPixelType<unsigned char>(), *this->GetImage()->GetTimeGeometry(), 1, 1);
129 binaryImage->Initialize(this->GetImage()->
GetPixelType(), *this->GetImage()->GetTimeGeometry(), 1, 1);
130 size = this->GetImage()->GetPixelType().GetSize();
133 for (
unsigned int i = 0; i < binaryImage->GetDimension(); ++i)
135 size *= binaryImage->GetDimension(i);
139 memset(accessor.
GetData(), 1, size);
146 mitk::TimeStepType surfaceTimeStep = surfaceTimeGeometry->TimePointToTimeStep(matchingTimePoint);
148 vtkPolyData *polydata = ((
mitk::Surface *)GetInput())->GetVtkPolyData(surfaceTimeStep);
152 move->SetInputData(polydata);
153 move->ReleaseDataFlagOn();
156 BaseGeometry *geometry = surfaceTimeGeometry->GetGeometryForTimeStep(surfaceTimeStep);
159 geometry = GetInput()->GetGeometry();
161 transform->PostMultiply();
165 transform->Concatenate(imageGeometry->
GetVtkTransform()->GetLinearInverse());
166 move->SetTransform(transform);
169 normalsFilter->SetFeatureAngle(50);
170 normalsFilter->SetConsistency(1);
171 normalsFilter->SetSplitting(1);
172 normalsFilter->SetFlipNormals(0);
173 normalsFilter->ReleaseDataFlagOn();
175 normalsFilter->SetInputConnection(move->GetOutputPort());
178 surfaceConverter->SetTolerance(0.0);
179 surfaceConverter->ReleaseDataFlagOn();
181 surfaceConverter->SetInputConnection(normalsFilter->GetOutputPort());
183 vtkImageData *image = m_MakeOutputBinary ? binaryImage->GetVtkImageData() :
184 const_cast<mitk::Image *
>(this->GetImage())->GetVtkImageData(time);
187 unsigned char inval = 1;
188 vtkIdType count = image->GetNumberOfPoints();
189 for (vtkIdType i = 0; i < count; ++i)
191 image->GetPointData()->GetScalars()->SetTuple1(i, inval);
196 stencil->SetInputData(image);
197 stencil->ReverseStencilOff();
198 stencil->ReleaseDataFlagOn();
199 stencil->SetStencilConnection(surfaceConverter->GetOutputPort());
201 stencil->SetBackgroundValue(m_MakeOutputBinary ? 0 : m_BackgroundValue);
204 output->SetVolume(stencil->GetOutput()->GetScalarPointer(), time);
205 MITK_INFO <<
"stencil ref count: " << stencil->GetReferenceCount() << std::endl;
209 memset(accessor.
GetData(), 0, size);
210 output->SetVolume(accessor.
GetData(), time);
216 if (this->GetNumberOfInputs() < 1)
221 return static_cast<const mitk::Surface *
>(this->ProcessObject::GetInput(0));
227 this->ProcessObject::SetNthInput(0, const_cast<mitk::Surface *>(input));
232 this->ProcessObject::SetNthInput(1, const_cast<mitk::Image *>(source));
237 return static_cast<const mitk::Image *
>(this->ProcessObject::GetInput(1));
virtual void GenerateInputRequestedRegion() override
Class for storing surfaces (vtkPolyData).
virtual ~SurfaceToImageFilter()
const mitk::Surface * GetInput(void)
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
const mitk::Image * GetImage(void)
void * GetData()
Gives full data access.
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
void SetImage(const mitk::Image *source)
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
mitk::PropertyList::Pointer GetPropertyList() const
Get the data's property list.
virtual TimePointType TimeStepToTimePoint(TimeStepType timeStep) const =0
Converts a time step to a time point.
void Stencil3DImage(int time=0)
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry, const TOutputRegion &outputRegion, const mitk::TimeGeometry *inputTimeGeometry, TInputRegion &inputRegion)
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const =0
Returns the geometry which corresponds to the given time step.
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
ImageWriteAccessor class to get locked write-access for a particular image part.
virtual void GenerateOutputInformation() override
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
BaseGeometry Describes the geometry of a data object.
virtual void SetInput(const mitk::Surface *surface)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.