#include "surfacerenderingimagestencilexport.h"
-#include "vtkObjectFactory.h"
#include "vtkMetaImageWriter.h"
#include "math.h"
+
vtkStandardNewMacro(SurfaceRenderingImageStencilExport)
SurfaceRenderingImageStencilExport::SurfaceRenderingImageStencilExport()
ImageOutput = 0;
}
-SurfaceRenderingImageStencilExport::~SurfaceRenderingImageStencilExport(){
+SurfaceRenderingImageStencilExport::~SurfaceRenderingImageStencilExport()
+{
- if(ImageOutput){
+ if(ImageOutput)
+ {
ImageOutput->Delete();
}
}
-void SurfaceRenderingImageStencilExport::Update(){
- this->Execute(0);
-}
-void SurfaceRenderingImageStencilExport::Execute(vtkImageData *data){
-
- vtkSmartPointer<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
//EED 2017-01-01 Migration VTK7
#if VTK_MAJOR_VERSION <= 5
+
+ void SurfaceRenderingImageStencilExport::Update(){
+ this->Execute(0);
+ }
+
+
+ // This method is much too long, and has to be broken up!
+ // Furthermore we are loosing the normals !!!
+ void SurfaceRenderingImageStencilExport::Execute(vtkImageData *data){
+ {
+
+ vtkSmartPointer<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
+
vtkPolyData* polydata = (vtkPolyData*)this->GetInput();
polytostencil->SetInput(polydata);
-#else
- vtkPolyData* polydata = (vtkPolyData*)this->GetInput();
- polytostencil->SetInputData(polydata);
-#endif
polytostencil->Update();
double *bounds = polydata->GetBounds();
vtkSmartPointer<vtkImageData> imagein = vtkSmartPointer<vtkImageData>::New();
imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1);
-//EED 2017-01-01 Migration VTK7
-#if VTK_MAJOR_VERSION <= 5
imagein->SetScalarTypeToUnsignedShort();
imagein->AllocateScalars();
-#else
- imagein->AllocateScalars(VTK_UNSIGNED_SHORT,1);
-#endif
-
int* extent = imagein->GetExtent();
- for (int x = extent[0]; x <= extent[1]; x++){
- for (int y = extent[2]; y <= extent[3]; y++){
- for (int z =extent[4]; z <= extent[5]; z++){
+ int x, y, z;
+ for (x = extent[0]; x <= extent[1]; x++){
+ for (y = extent[2]; y <= extent[3]; y++){
+ for (z =extent[4]; z <= extent[5]; z++){
unsigned short* pixel = static_cast<unsigned short*>(imagein->GetScalarPointer(x,y,z));
*pixel = 0;
- }
- }
- }
+ } // for x
+ } // for y
+ } // for z
vtkSmartPointer<vtkImageStencil> stencil = vtkSmartPointer<vtkImageStencil>::New();
-//EED 2017-01-01 Migration VTK7
-#if VTK_MAJOR_VERSION <= 5
stencil->SetInput(imagein);
stencil->SetStencil(polytostencil->GetOutput());
+
+ stencil->ReverseStencilOn();
+ stencil->SetBackgroundValue(128);
+ stencil->Update();
+
+ if(ImageOutput)
+ {
+ ImageOutput->Delete();
+ }
+ ImageOutput = vtkImageData::New();
+ ImageOutput->DeepCopy(stencil->GetOutput());
+
+ }
+
#else
+
+int SurfaceRenderingImageStencilExport::RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector)
+{
+
+ // get the info objects
+ vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
+ vtkInformation *outInfo = outputVector->GetInformationObject(0);
+
+ // get the input and output
+ vtkPolyData *input = vtkPolyData::SafeDownCast( inInfo->Get(vtkDataObject::DATA_OBJECT()));
+ vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT()));
+
+
+ vtkSmartPointer<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
+
+// vtkPolyData* polydata = (vtkPolyData*)this->GetInput();
+ vtkPolyData* polydata = input;
+ polytostencil->SetInputData(polydata);
+ polytostencil->Update();
+
+ double *bounds = polydata->GetBounds();
+ vtkSmartPointer<vtkImageData> imagein = vtkSmartPointer<vtkImageData>::New();
+
+ imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1);
+ imagein->AllocateScalars(VTK_UNSIGNED_SHORT,1);
+
+
+ int* extent = imagein->GetExtent();
+
+ int x,y,z;
+ for (x = extent[0]; x <= extent[1]; x++){
+ for (y = extent[2]; y <= extent[3]; y++){
+ for (z =extent[4]; z <= extent[5]; z++){
+ unsigned short* pixel = static_cast<unsigned short*>(imagein->GetScalarPointer(x,y,z));
+ *pixel = 0;
+ } // for z
+ } // for y
+ } // for z
+
+ vtkSmartPointer<vtkImageStencil> stencil = vtkSmartPointer<vtkImageStencil>::New();
+
stencil->SetInputData(imagein);
stencil->SetStencilData(polytostencil->GetOutput());
-#endif
stencil->ReverseStencilOn();
stencil->SetBackgroundValue(128);
stencil->Update();
- if(ImageOutput){
+ if(ImageOutput)
+ {
ImageOutput->Delete();
}
ImageOutput = vtkImageData::New();
ImageOutput->DeepCopy(stencil->GetOutput());
+ return 1;
}
-vtkImageData* SurfaceRenderingImageStencilExport::GetOutput(){
+#endif
+
+
+
+
+
+
+
+//-------------------------------------------------------------------------------------------
+
+vtkImageData* SurfaceRenderingImageStencilExport::GetOutputData()
+{
return ImageOutput;
}
#ifndef SURFACERENDERINGIMAGESTENCILEXPORT_H
#define SURFACERENDERINGIMAGESTENCILEXPORT_H
+#include "vtkObjectFactory.h"
-#include <vtkImageData.h>
//EED 2017-01-01 Migration VTK7
#if VTK_MAJOR_VERSION <= 5
#include <vtkDataSetToImageFilter.h>
#else
- // ..
+ #include "vtkPolyDataAlgorithm.h"
+ #include "vtkDataObject.h"
+ #include "vtkInformation.h"
+ #include "vtkDemandDrivenPipeline.h"
+ #include "vtkInformationVector.h"
#endif
#include <vtkSmartPointer.h>
#include <vtkPolyDataToImageStencil.h>
#include <vtkImageStencil.h>
+#include <vtkImageData.h>
#include <vtkPolyData.h>
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
class SurfaceRenderingImageStencilExport : public vtkDataSetToImageFilter
+#else
+class SurfaceRenderingImageStencilExport : public vtkPolyDataAlgorithm
+#endif
{
public:
static SurfaceRenderingImageStencilExport *New();
- vtkTypeMacro(SurfaceRenderingImageStencilExport,vtkDataSetToImageFilter)
+ vtkTypeMacro(SurfaceRenderingImageStencilExport,vtkPolyDataAlgorithm)
+#if VTK_MAJOR_VERSION <= 5
virtual void Update();
- vtkImageData* GetOutput();
+#else
+ // ..
+#endif
+
+
+ virtual vtkImageData* GetOutputData();
protected:
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ // Usual data generation method
virtual void Execute(vtkImageData *data);
+#else
+ virtual int RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector);
+#endif
private: