24 #include <vtkLinearTransform.h>
25 #include <vtkPolyData.h>
26 #include <vtkSmartPointer.h>
27 #include <vtkTransform.h>
28 #include <vtkTransformPolyDataFilter.h>
30 #include <itkTriangleMeshToBinaryImageFilter.h>
33 : m_MakeOutputBinary(false), m_OverwriteBackground(false), m_ForegroundValue(1.0), m_BackgroundValue(0.0)
55 itkDebugMacro(<<
"GenerateOutputInformation()");
57 if (inputImage.IsNull() || (inputImage->IsInitialized() ==
false) || (inputImage->GetTimeGeometry() == NULL))
60 if (m_MakeOutputBinary)
61 outputImage->Initialize(mitk::MakeScalarPixelType<unsigned char>(), *inputImage->GetTimeGeometry());
63 outputImage->Initialize(inputImage->GetPixelType(), *inputImage->GetTimeGeometry());
65 outputImage->SetPropertyList(inputImage->GetPropertyList()->Clone());
77 if (inputImage.IsNull())
81 if (outputImage->IsInitialized() ==
false)
84 if (m_Surface.IsNull())
89 int tstart = outputRegion.GetIndex(3);
90 int tmax = tstart + outputRegion.GetSize(3);
95 for (t = tstart; t < tmax; ++t)
97 this->SurfaceStamp(t);
102 this->SurfaceStamp(0);
117 vtkPolyData *polydata = m_Surface->GetVtkPolyData(surfaceTimeStep);
122 transformFilter->SetInputData(polydata);
128 transform->PostMultiply();
129 transform->Concatenate(geometry->GetVtkTransform()->GetMatrix());
133 transform->Concatenate(imageGeometry->GetVtkTransform()->GetLinearInverse());
134 transformFilter->SetTransform(transform);
135 transformFilter->Update();
137 polydata = transformFilter->GetOutput();
139 if (!polydata || !polydata->GetNumberOfPoints())
140 mitkThrow() <<
"Polydata retrieved from transformation is null or has no points.";
143 mesh->SetCellsAllocationMethod(MeshType::CellsAllocatedDynamicallyCellByCell);
144 unsigned int numberOfPoints = polydata->GetNumberOfPoints();
145 mesh->GetPoints()->Reserve(numberOfPoints);
147 vtkPoints *points = polydata->GetPoints();
150 for (
int i = 0; i < numberOfPoints; i++)
152 double *aux = points->GetPoint(i);
156 mesh->SetPoint(i, point);
160 typedef MeshType::CellAutoPointer CellAutoPointerType;
161 typedef MeshType::CellType CellType;
162 typedef itk::TriangleCell<CellType> TriangleCellType;
163 typedef MeshType::PointIdentifier PointIdentifierType;
164 typedef MeshType::CellIdentifier CellIdentifierType;
167 CellIdentifierType numberOfPolygons = 0;
168 numberOfPolygons = polydata->GetNumberOfPolys();
169 vtkCellArray *polys = polydata->GetPolys();
171 PointIdentifierType numberOfCellPoints = 3;
172 CellIdentifierType i = 0;
174 for (i = 0; i < numberOfPolygons; i++)
177 vtkCell *vcell = polydata->GetCell(i);
178 cellIds = vcell->GetPointIds();
180 CellAutoPointerType cell;
181 TriangleCellType *triangleCell =
new TriangleCellType;
182 PointIdentifierType k;
183 for (k = 0; k < numberOfCellPoints; k++)
185 triangleCell->SetPointId(k, cellIds->GetId(k));
188 cell.TakeOwnership(triangleCell);
189 mesh->SetCell(i, cell);
192 if (!mesh->GetNumberOfPoints())
193 mitkThrow() <<
"Generated itk mesh is empty.";
195 if (m_MakeOutputBinary)
197 this->SurfaceStampBinaryOutputProcessing(mesh);
215 typedef itk::TriangleMeshToBinaryImageFilter<MeshType, BinaryImageType> FilterType;
218 filter->SetInput(mesh);
219 filter->SetInfoImage(itkInputImage);
220 filter->SetInsideValue(1);
221 filter->SetOutsideValue(0);
225 resultImage->DisconnectPipeline();
230 template <
typename TPixel>
236 typedef itk::TriangleMeshToBinaryImageFilter<mitk::SurfaceStampImageFilter::MeshType, BinaryImageType> FilterType;
239 binaryInput->SetSpacing(input->GetSpacing());
240 binaryInput->SetOrigin(input->GetOrigin());
241 binaryInput->SetDirection(input->GetDirection());
242 binaryInput->SetRegions(input->GetLargestPossibleRegion());
243 binaryInput->Allocate();
244 binaryInput->FillBuffer(0);
247 filter->SetInput(mesh);
248 filter->SetInfoImage(binaryInput);
249 filter->SetInsideValue(1);
250 filter->SetOutsideValue(0);
254 resultImage->DisconnectPipeline();
260 typedef itk::ImageRegionConstIterator<BinaryImageType> BinaryIteratorType;
261 typedef itk::ImageRegionConstIterator<ImageType> InputIteratorType;
262 typedef itk::ImageRegionIterator<ImageType> OutputIteratorType;
264 BinaryIteratorType sourceIter(resultImage, resultImage->GetLargestPossibleRegion());
265 sourceIter.GoToBegin();
267 InputIteratorType inputIter(input, input->GetLargestPossibleRegion());
268 inputIter.GoToBegin();
270 OutputIteratorType outputIter(itkOutputImage, itkOutputImage->GetLargestPossibleRegion());
271 outputIter.GoToBegin();
274 unsigned char sourceValue;
279 while (!sourceIter.IsAtEnd())
281 sourceValue =
static_cast<unsigned char>(sourceIter.Get());
284 if (sourceValue != 0)
285 outputIter.Set(fgValue);
286 else if (m_OverwriteBackground)
287 outputIter.Set(bgValue);
289 outputIter.Set(inputValue);
Class for storing surfaces (vtkPolyData).
itk::SmartPointer< Self > Pointer
virtual void GenerateData()
A version of GenerateData() specific for image processing filters.
SurfaceStampImageFilter()
virtual ~SurfaceStampImageFilter()
virtual void GenerateInputRequestedRegion()
void SurfaceStamp(int time=0)
map::core::discrete::Elements< 3 >::InternalImageType ImageType
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.
virtual void GenerateOutputInformation()
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.
itk::Image< unsigned char, 3 > BinaryImageType
void SurfaceStampBinaryOutputProcessing(MeshType *mesh)
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry, const TOutputRegion &outputRegion, const mitk::TimeGeometry *inputTimeGeometry, TInputRegion &inputRegion)
itk::QuadEdgeMesh< double, 3 > MeshType
#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 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...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.