20 #include <vtkLinearTransform.h> 21 #include <vtkPolyData.h> 22 #include <vtkSmartPointer.h> 23 #include <vtkTransform.h> 24 #include <vtkTransformPolyDataFilter.h> 26 #include <itkTriangleMeshToBinaryImageFilter.h> 29 : m_MakeOutputBinary(false), m_OverwriteBackground(false), m_BackgroundValue(0.0), m_ForegroundValue(1.0)
51 itkDebugMacro(<<
"GenerateOutputInformation()");
53 if (inputImage.IsNull() || (inputImage->IsInitialized() ==
false) || (inputImage->GetTimeGeometry() ==
nullptr))
57 outputImage->Initialize(mitk::MakeScalarPixelType<unsigned char>(), *inputImage->GetTimeGeometry());
59 outputImage->Initialize(inputImage->GetPixelType(), *inputImage->GetTimeGeometry());
61 outputImage->SetPropertyList(inputImage->GetPropertyList()->Clone());
73 if (inputImage.IsNull())
77 if (outputImage->IsInitialized() ==
false)
85 int tstart = outputRegion.GetIndex(3);
86 int tmax = tstart + outputRegion.GetSize(3);
91 for (t = tstart; t < tmax; ++t)
113 vtkPolyData *polydata =
m_Surface->GetVtkPolyData(surfaceTimeStep);
117 vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
118 transformFilter->SetInputData(polydata);
121 vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
124 transform->PostMultiply();
125 transform->Concatenate(geometry->GetVtkTransform()->GetMatrix());
129 transform->Concatenate(imageGeometry->GetVtkTransform()->GetLinearInverse());
130 transformFilter->SetTransform(transform);
131 transformFilter->Update();
133 polydata = transformFilter->GetOutput();
135 if (!polydata || !polydata->GetNumberOfPoints())
136 mitkThrow() <<
"Polydata retrieved from transformation is null or has no points.";
138 MeshType::Pointer mesh = MeshType::New();
139 mesh->SetCellsAllocationMethod(MeshType::CellsAllocatedDynamicallyCellByCell);
140 unsigned int numberOfPoints = polydata->GetNumberOfPoints();
141 mesh->GetPoints()->Reserve(numberOfPoints);
143 vtkPoints *points = polydata->GetPoints();
145 MeshType::PointType point;
146 for (
unsigned int i = 0; i < numberOfPoints; i++)
148 double *aux = points->GetPoint(i);
152 mesh->SetPoint(i, point);
156 typedef MeshType::CellAutoPointer CellAutoPointerType;
157 typedef MeshType::CellType CellType;
158 typedef itk::TriangleCell<CellType> TriangleCellType;
159 typedef MeshType::PointIdentifier PointIdentifierType;
160 typedef MeshType::CellIdentifier CellIdentifierType;
163 CellIdentifierType numberOfPolygons = 0;
164 numberOfPolygons = polydata->GetNumberOfPolys();
166 PointIdentifierType numberOfCellPoints = 3;
167 CellIdentifierType i = 0;
169 for (i = 0; i < numberOfPolygons; i++)
172 vtkCell *vcell = polydata->GetCell(i);
173 cellIds = vcell->GetPointIds();
175 CellAutoPointerType cell;
176 auto *triangleCell =
new TriangleCellType;
177 PointIdentifierType
k;
178 for (k = 0; k < numberOfCellPoints; k++)
180 triangleCell->SetPointId(k, cellIds->GetId(k));
183 cell.TakeOwnership(triangleCell);
184 mesh->SetCell(i, cell);
187 if (!mesh->GetNumberOfPoints())
188 mitkThrow() <<
"Generated itk mesh is empty.";
202 auto *inputImage = this->
GetInput();
206 typedef itk::Image<unsigned char, 3> BinaryImageType;
207 BinaryImageType::Pointer itkInputImage;
210 typedef itk::TriangleMeshToBinaryImageFilter<MeshType, BinaryImageType> FilterType;
212 FilterType::Pointer filter = FilterType::New();
213 filter->SetInput(mesh);
214 filter->SetInfoImage(itkInputImage);
215 filter->SetInsideValue(1);
216 filter->SetOutsideValue(0);
219 BinaryImageType::Pointer resultImage = filter->GetOutput();
220 resultImage->DisconnectPipeline();
225 template <
typename TPixel>
229 typedef itk::Image<unsigned char, 3> BinaryImageType;
231 typedef itk::TriangleMeshToBinaryImageFilter<mitk::SurfaceStampImageFilter::MeshType, BinaryImageType> FilterType;
233 BinaryImageType::Pointer binaryInput = BinaryImageType::New();
234 binaryInput->SetSpacing(input->GetSpacing());
235 binaryInput->SetOrigin(input->GetOrigin());
236 binaryInput->SetDirection(input->GetDirection());
237 binaryInput->SetRegions(input->GetLargestPossibleRegion());
238 binaryInput->Allocate();
239 binaryInput->FillBuffer(0);
241 FilterType::Pointer filter = FilterType::New();
242 filter->SetInput(mesh);
243 filter->SetInfoImage(binaryInput);
244 filter->SetInsideValue(1);
245 filter->SetOutsideValue(0);
248 BinaryImageType::Pointer resultImage = filter->GetOutput();
249 resultImage->DisconnectPipeline();
252 typename ImageType::Pointer itkOutputImage;
255 typedef itk::ImageRegionConstIterator<BinaryImageType> BinaryIteratorType;
256 typedef itk::ImageRegionConstIterator<ImageType> InputIteratorType;
257 typedef itk::ImageRegionIterator<ImageType> OutputIteratorType;
259 BinaryIteratorType sourceIter(resultImage, resultImage->GetLargestPossibleRegion());
260 sourceIter.GoToBegin();
262 InputIteratorType inputIter(input, input->GetLargestPossibleRegion());
263 inputIter.GoToBegin();
265 OutputIteratorType outputIter(itkOutputImage, itkOutputImage->GetLargestPossibleRegion());
266 outputIter.GoToBegin();
268 typename ImageType::PixelType inputValue;
269 unsigned char sourceValue;
274 while (!sourceIter.IsAtEnd())
276 sourceValue =
static_cast<unsigned char>(sourceIter.Get());
277 inputValue =
static_cast<typename ImageType::PixelType
>(inputIter.Get());
279 if (sourceValue != 0)
280 outputIter.Set(fgValue);
282 outputIter.Set(bgValue);
284 outputIter.Set(inputValue);
Class for storing surfaces (vtkPolyData).
void GenerateInputRequestedRegion() override
itk::Image< unsigned char, 3 > ImageType
SurfaceStampImageFilter()
void SurfaceStamp(int time=0)
mitk::Surface::Pointer m_Surface
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
void SetSurface(mitk::Surface *surface)
itk::ImageRegion< RegionDimension > RegionType
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
void SurfaceStampProcessing(itk::Image< TPixel, 3 > *input, MeshType *mesh)
Image class for storing images.
virtual TimePointType TimeStepToTimePoint(TimeStepType timeStep) const =0
Converts a time step to a time point.
void SurfaceStampBinaryOutputProcessing(MeshType *mesh)
bool m_OverwriteBackground
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
~SurfaceStampImageFilter() override
void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry, const TOutputRegion &outputRegion, const mitk::TimeGeometry *inputTimeGeometry, TInputRegion &inputRegion)
itk::QuadEdgeMesh< double, 3 > MeshType
InputImageType * GetInput(void)
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const =0
Returns the geometry which corresponds to the given time step.
OutputType * GetOutput()
Get the output data of this image source object.
void GenerateData() override
void GenerateOutputInformation() override