Commit 8d4b9a06 authored by Amy Squillacote's avatar Amy Squillacote

ENH: converting vtkPointSetToPointSetFilters to use the new pipeline

parent c5134897
......@@ -132,6 +132,7 @@ vtkPixel.cxx
vtkPointData.cxx
vtkPointLocator.cxx
vtkPointSet.cxx
vtkPointSetAlgorithm.cxx
vtkPointSetSource.cxx
vtkPointSetToPolyDataAlgorithm.cxx
vtkPointSetToPointSetFilter.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointSetAlgorithm.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPointSetAlgorithm.h"
#include "vtkCommand.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredGrid.h"
#include "vtkUnstructuredGrid.h"
vtkCxxRevisionMacro(vtkPointSetAlgorithm, "1.1");
vtkStandardNewMacro(vtkPointSetAlgorithm);
//----------------------------------------------------------------------------
// Instantiate object so that cell data is not passed to output.
vtkPointSetAlgorithm::vtkPointSetAlgorithm()
{
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
}
//----------------------------------------------------------------------------
vtkPointSet* vtkPointSetAlgorithm::GetOutput()
{
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkPointSet* vtkPointSetAlgorithm::GetOutput(int port)
{
return vtkPointSet::SafeDownCast(this->GetOutputDataObject(port));
}
//----------------------------------------------------------------------------
// Get the output as vtkPolyData.
vtkPolyData *vtkPointSetAlgorithm::GetPolyDataOutput()
{
return vtkPolyData::SafeDownCast(this->GetOutput());
}
//----------------------------------------------------------------------------
// Get the output as vtkStructuredGrid.
vtkStructuredGrid *vtkPointSetAlgorithm::GetStructuredGridOutput()
{
return vtkStructuredGrid::SafeDownCast(this->GetOutput());
}
//----------------------------------------------------------------------------
// Get the output as vtkUnstructuredGrid.
vtkUnstructuredGrid *vtkPointSetAlgorithm::GetUnstructuredGridOutput()
{
return vtkUnstructuredGrid::SafeDownCast(this->GetOutput());
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::SetInput(vtkDataObject* input)
{
this->SetInput(0, input);
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::SetInput(int index, vtkDataObject* input)
{
if(input)
{
this->SetInputConnection(index, input->GetProducerPort());
}
else
{
// Setting a NULL input removes the connection.
this->SetInputConnection(index, 0);
}
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::SetInput(vtkPointSet* input)
{
this->SetInput(0, static_cast<vtkDataObject*>(input));
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::SetInput(int index, vtkPointSet* input)
{
this->SetInput(index, static_cast<vtkDataObject*>(input));
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::AddInput(vtkDataObject* input)
{
this->AddInput(0, input);
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::AddInput(int index, vtkDataObject* input)
{
if(input)
{
this->AddInputConnection(index, input->GetProducerPort());
}
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::AddInput(vtkPointSet* input)
{
this->AddInput(0, static_cast<vtkDataObject*>(input));
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::AddInput(int index, vtkPointSet* input)
{
this->AddInput(index, static_cast<vtkDataObject*>(input));
}
//----------------------------------------------------------------------------
vtkDataObject* vtkPointSetAlgorithm::GetInput(int port)
{
return this->GetExecutive()->GetInputData(port, 0);
}
//----------------------------------------------------------------------------
int vtkPointSetAlgorithm::ProcessRequest(
vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// generate the data
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
return this->RequestData(request, inputVector, outputVector);
}
// create the output
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT()))
{
return this->CreateOutput(request, inputVector, outputVector);
}
// execute information
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
{
return this->ExecuteInformation(request, inputVector, outputVector);
}
// set update extent
if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
return this->ComputeInputUpdateExtent(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
int vtkPointSetAlgorithm::CreateOutput(
vtkInformation*,
vtkInformationVector** inputVector ,
vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
if (!inInfo)
{
return 0;
}
vtkPointSet *input = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
if (input)
{
vtkInformation* info = outputVector->GetInformationObject(0);
vtkPointSet *output = vtkPointSet::SafeDownCast(
info->Get(vtkDataObject::DATA_OBJECT()));
if (!output || !output->IsA(input->GetClassName()))
{
output = input->NewInstance();
output->SetPipelineInformation(info);
output->Delete();
this->GetOutputPortInformation(0)->Set(
vtkDataObject::DATA_EXTENT_TYPE(), output->GetExtentType());
}
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
int vtkPointSetAlgorithm::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
// now add our info
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPointSet");
return 1;
}
//----------------------------------------------------------------------------
int vtkPointSetAlgorithm::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPointSet");
return 1;
}
//----------------------------------------------------------------------------
void vtkPointSetAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointSetAlgorithm.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPointSetAlgorithm - Superclass for algorithms that produce output of the same type as input
// .SECTION Description
// vtkPointSetAlgorithm is a convenience class to make writing algorithms
// easier. It is also designed to help transition old algorithms to the new
// pipeline architecture. Ther are some assumptions and defaults made by this
// class you should be aware of. This class defaults such that your filter
// will have one input port and one output port. If that is not the case
// simply change it with SetNumberOfInputPorts etc. See this classes
// contstructor for the default. This class also provides a FillInputPortInfo
// method that by default says that all inputs will be PointSet. If that
// isn't the case then please override this method in your subclass. This
// class breaks out the downstream requests into seperate functions such as
// CreateOutput RequestData and ExecuteInformation. The default implementation
// of CreateOutput will create an output data of the same type as the input.
#ifndef __vtkPointSetAlgorithm_h
#define __vtkPointSetAlgorithm_h
#include "vtkAlgorithm.h"
class vtkPointSet;
class vtkPolyData;
class vtkStructuredGrid;
class vtkUnstructuredGrid;
class VTK_FILTERING_EXPORT vtkPointSetAlgorithm : public vtkAlgorithm
{
public:
static vtkPointSetAlgorithm *New();
vtkTypeRevisionMacro(vtkPointSetAlgorithm,vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the output data object for a port on this algorithm.
vtkPointSet* GetOutput();
vtkPointSet* GetOutput(int);
// Description:
// Get the output as vtkPolyData.
vtkPolyData *GetPolyDataOutput();
// Description:
// Get the output as vtkStructuredGrid.
vtkStructuredGrid *GetStructuredGridOutput();
// Description:
// Get the output as vtkUnstructuredGrid.
vtkUnstructuredGrid *GetUnstructuredGridOutput();
// Description:
// Set an input of this algorithm.
void SetInput(vtkDataObject*);
void SetInput(int, vtkDataObject*);
void SetInput(vtkPointSet*);
void SetInput(int, vtkPointSet*);
// Description:
// Add an input of this algorithm.
void AddInput(vtkDataObject *);
void AddInput(vtkPointSet*);
void AddInput(int, vtkPointSet*);
void AddInput(int, vtkDataObject*);
// Description:
// see vtkAlgorithm for details
virtual int ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
protected:
vtkPointSetAlgorithm();
~vtkPointSetAlgorithm() {};
// This is called by the superclass.
// This is the method you should override.
virtual int CreateOutput(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
// This is called by the superclass.
// This is the method you should override.
virtual int ExecuteInformation(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*) {return 1;};
// This is called by the superclass.
// This is the method you should override.
virtual int RequestData(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*) {return 1;};
// This is called by the superclass.
// This is the method you should override.
virtual int ComputeInputUpdateExtent(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*)
{
return 1;
};
// see algorithm for more info
virtual int FillOutputPortInformation(int port, vtkInformation* info);
virtual int FillInputPortInformation(int port, vtkInformation* info);
vtkDataObject *GetInput(int port);
private:
vtkPointSetAlgorithm(const vtkPointSetAlgorithm&); // Not implemented.
void operator=(const vtkPointSetAlgorithm&); // Not implemented.
};
#endif
......@@ -16,12 +16,14 @@
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkLinearTransform.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPointSet.h"
vtkCxxRevisionMacro(vtkTransformFilter, "1.44");
vtkCxxRevisionMacro(vtkTransformFilter, "1.45");
vtkStandardNewMacro(vtkTransformFilter);
vtkCxxSetObjectMacro(vtkTransformFilter,Transform,vtkAbstractTransform);
......@@ -35,8 +37,21 @@ vtkTransformFilter::~vtkTransformFilter()
this->SetTransform(NULL);
}
void vtkTransformFilter::Execute()
int vtkTransformFilter::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 ouptut
vtkPointSet *input = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPointSet *output = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPoints *inPts;
vtkPoints *newPts;
vtkDataArray *inVectors, *inCellVectors;;
......@@ -44,8 +59,6 @@ void vtkTransformFilter::Execute()
vtkDataArray *inNormals, *inCellNormals;
vtkFloatArray *newNormals=NULL, *newCellNormals=NULL;
vtkIdType numPts, numCells;
vtkPointSet *input = this->GetInput();
vtkPointSet *output = this->GetOutput();
vtkPointData *pd=input->GetPointData(), *outPD=output->GetPointData();
vtkCellData *cd=input->GetCellData(), *outCD=output->GetCellData();
......@@ -59,7 +72,7 @@ void vtkTransformFilter::Execute()
if ( this->Transform == NULL )
{
vtkErrorMacro(<<"No transform defined!");
return;
return 1;
}
inPts = input->GetPoints();
......@@ -71,7 +84,7 @@ void vtkTransformFilter::Execute()
if ( !inPts )
{
vtkErrorMacro(<<"No input data");
return;
return 1;
}
numPts = inPts->GetNumberOfPoints();
......@@ -184,6 +197,8 @@ void vtkTransformFilter::Execute()
}
outFD->PassData(inFD);
}
return 1;
}
unsigned long vtkTransformFilter::GetMTime()
......
......@@ -32,15 +32,15 @@
#ifndef __vtkTransformFilter_h
#define __vtkTransformFilter_h
#include "vtkPointSetToPointSetFilter.h"
#include "vtkPointSetAlgorithm.h"
class vtkAbstractTransform;
class VTK_GRAPHICS_EXPORT vtkTransformFilter : public vtkPointSetToPointSetFilter
class VTK_GRAPHICS_EXPORT vtkTransformFilter : public vtkPointSetAlgorithm
{
public:
static vtkTransformFilter *New();
vtkTypeRevisionMacro(vtkTransformFilter,vtkPointSetToPointSetFilter);
vtkTypeRevisionMacro(vtkTransformFilter,vtkPointSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -56,7 +56,7 @@ protected:
vtkTransformFilter();
~vtkTransformFilter();
void Execute();
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
vtkAbstractTransform *Transform;
private:
vtkTransformFilter(const vtkTransformFilter&); // Not implemented.
......
......@@ -14,13 +14,15 @@
=========================================================================*/
#include "vtkWarpLens.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPointSet.h"
#include "vtkPoints.h"
vtkCxxRevisionMacro(vtkWarpLens, "1.28");
vtkCxxRevisionMacro(vtkWarpLens, "1.29");
vtkStandardNewMacro(vtkWarpLens);
//
......@@ -65,14 +67,25 @@ vtkWarpLens::vtkWarpLens()
this->ImageHeight = 1;
}
void vtkWarpLens::Execute()
int vtkWarpLens::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 ouptut
vtkPointSet *input = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPointSet *output = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPoints *inPts;
vtkPoints *newPts;
vtkIdType ptId, numPts;
double pixel[3], newPixel[3];
vtkPointSet *input = this->GetInput();
vtkPointSet *output = this->GetOutput();
double x;
double y;
double newX;
......@@ -88,7 +101,7 @@ void vtkWarpLens::Execute()
if (!inPts )
{
vtkErrorMacro(<<"No input data");
return;
return 1;
}
numPts = inPts->GetNumberOfPoints();
......@@ -146,6 +159,8 @@ void vtkWarpLens::Execute()
output->SetPoints(newPts);
newPts->Delete();
return 1;
}
void vtkWarpLens::PrintSelf(ostream& os, vtkIndent indent)
......
......@@ -20,13 +20,13 @@
#ifndef __vtkWarpLens_h
#define __vtkWarpLens_h
#include "vtkPointSetToPointSetFilter.h"
#include "vtkPointSetAlgorithm.h"
class VTK_GRAPHICS_EXPORT vtkWarpLens : public vtkPointSetToPointSetFilter
class VTK_GRAPHICS_EXPORT vtkWarpLens : public vtkPointSetAlgorithm
{
public:
static vtkWarpLens *New();
vtkTypeRevisionMacro(vtkWarpLens,vtkPointSetToPointSetFilter);
vtkTypeRevisionMacro(vtkWarpLens,vtkPointSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -74,12 +74,11 @@ public:
vtkSetMacro(ImageHeight,int);
vtkGetMacro(ImageHeight,int);
protected:
vtkWarpLens();
~vtkWarpLens() {};
void Execute();
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
double PrincipalPoint[2]; // The calibrated principal point of camera/lens in mm
double K1; // Symmetric radial distortion parameters
......
......@@ -16,12 +16,14 @@
#include "vtkCellData.h"
#include "vtkDataArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPointSet.h"
#include "vtkPoints.h"
vtkCxxRevisionMacro(vtkWarpScalar, "1.47");
vtkCxxRevisionMacro(vtkWarpScalar, "1.48");
vtkStandardNewMacro(vtkWarpScalar);
vtkWarpScalar::vtkWarpScalar()
......@@ -60,8 +62,21 @@ double *vtkWarpScalar::ZNormal(vtkIdType vtkNotUsed(id),
return zNormal;
}
void vtkWarpScalar::Execute()
int vtkWarpScalar::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 ouptut
vtkPointSet *input = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPointSet *output = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPoints *inPts;
vtkDataArray *inNormals;
vtkDataArray *inScalars;
......@@ -70,8 +85,6 @@ void vtkWarpScalar::Execute()
int i;
vtkIdType ptId, numPts;
double x[3], *n, s, newX[3];
vtkPointSet *input = this->GetInput();
vtkPointSet *output = this->GetOutput();
vtkDebugMacro(<<"Warping data with scalars");
......@@ -86,7 +99,7 @@ void vtkWarpScalar::Execute()
if ( !inPts || !inScalars )
{
vtkDebugMacro(<<"No data to warp");
return;
return 1;
}
numPts = inPts->GetNumberOfPoints();
......@@ -149,6 +162,8 @@ void vtkWarpScalar::Execute()
output->SetPoints(newPts);
newPts->Delete();
return 1;
}
void vtkWarpScalar::PrintSelf(ostream& os, vtkIndent indent)
......
......@@ -36,15 +36,15 @@
#ifndef __vtkWarpScalar_h
#define __vtkWarpScalar_h
#include "vtkPointSetToPointSetFilter.h"
#include "vtkPointSetAlgorithm.h"
class vtkDataArray;
class VTK_GRAPHICS_EXPORT vtkWarpScalar : public vtkPointSetToPointSetFilter
class VTK_GRAPHICS_EXPORT vtkWarpScalar : public vtkPointSetAlgorithm
{
public:
static vtkWarpScalar *New();
vtkTypeRevisionMacro(vtkWarpScalar,vtkPointSetToPointSetFilter);
vtkTypeRevisionMacro(vtkWarpScalar,vtkPointSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -84,7 +84,7 @@ protected:
vtkWarpScalar();
~vtkWarpScalar();
void Execute();
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
double ScaleFactor;
int UseNormal;
......
......@@ -14,13 +14,15 @@
=========================================================================*/
#include "vtkWarpTo.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPointSet.h"
#include "vtkPoints.h"
vtkCxxRevisionMacro(vtkWarpTo, "1.41");
vtkCxxRevisionMacro(vtkWarpTo, "1.42");
vtkStandardNewMacro(vtkWarpTo);
vtkWarpTo::vtkWarpTo()
......@@ -30,15 +32,26 @@ vtkWarpTo::vtkWarpTo()
this->Position[0] = this->Position[1] = this->Position[2] = 0.0;
}
void vtkWarpTo::Execute()
int vtkWarpTo::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 ouptut
vtkPointSet *input = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPointSet *output = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPoints *inPts;
vtkPoints *newPts;
vtkIdType ptId, numPts;
int i;
double x[3], newX[3];
vtkPointSet *input = this->GetInput();
vtkPointSet *output = this->GetOutput();
double mag;
double minMag = 0;
......@@ -52,7 +65,7 @@ void vtkWarpTo::Execute()
if (!inPts )
{
vtkErrorMacro(<<"No input data");
return;
return 1;
}
numPts = inPts->GetNumberOfPoints();
......@@ -106,6 +119,8 @@ void vtkWarpTo::Execute()
output->SetPoints(newPts);
newPts->Delete();
return 1;
}
void vtkWarpTo::PrintSelf(ostream& os, vtkIndent indent)
......
......@@ -20,13 +20,13 @@
#ifndef __vtkWarpTo_h
#define __vtkWarpTo_h
#include "vtkPointSetToPointSetFilter.h"
#include "vtkPointSetAlgorithm.h"
class VTK_GRAPHICS_EXPORT vtkWarpTo : public vtkPointSetToPointSetFilter
class VTK_GRAPHICS_EXPORT vtkWarpTo : public vtkPointSetAlgorithm
{
public:
static vtkWarpTo *New();
vtkTypeRevisionMacro(vtkWarpTo,vtkPointSetToPointSetFilter);
vtkTypeRevisionMacro(vtkWarpTo,vtkPointSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -50,7 +50,7 @@ protected:
vtkWarpTo();