Commit 65a1df20 authored by Amy Squillacote's avatar Amy Squillacote

ENH: adding vtkStructuredGridAlgorithm

parent 2449bb5e
......@@ -164,6 +164,7 @@ vtkSource.cxx
vtkSpline.cxx
vtkStreamingDemandDrivenPipeline.cxx
vtkStructuredGrid.cxx
vtkStructuredGridAlgorithm.cxx
vtkStructuredGridSource.cxx
vtkStructuredGridToPolyDataFilter.cxx
vtkStructuredGridToStructuredGridFilter.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkStructuredGridAlgorithm.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 "vtkStructuredGridAlgorithm.h"
#include "vtkCommand.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredGrid.h"
#include "vtkTrivialProducer.h"
vtkCxxRevisionMacro(vtkStructuredGridAlgorithm, "1.1");
vtkStandardNewMacro(vtkStructuredGridAlgorithm);
//----------------------------------------------------------------------------
vtkStructuredGridAlgorithm::vtkStructuredGridAlgorithm()
{
// by default assume filters have one input and one output
// subclasses that deviate should modify this setting
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
}
//----------------------------------------------------------------------------
vtkStructuredGridAlgorithm::~vtkStructuredGridAlgorithm()
{
}
//----------------------------------------------------------------------------
void vtkStructuredGridAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
vtkStructuredGrid* vtkStructuredGridAlgorithm::GetOutput()
{
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkStructuredGrid* vtkStructuredGridAlgorithm::GetOutput(int port)
{
return vtkStructuredGrid::SafeDownCast(this->GetOutputDataObject(port));
}
//----------------------------------------------------------------------------
void vtkStructuredGridAlgorithm::SetOutput(vtkDataObject* d)
{
this->GetExecutive()->SetOutputData(0, d);
}
//----------------------------------------------------------------------------
vtkDataObject* vtkStructuredGridAlgorithm::GetInput()
{
return this->GetInput(0);
}
//----------------------------------------------------------------------------
vtkDataObject* vtkStructuredGridAlgorithm::GetInput(int port)
{
if (this->GetNumberOfInputConnections(port) < 1)
{
return 0;
}
return this->GetExecutive()->GetInputData(port, 0);
}
//----------------------------------------------------------------------------
vtkStructuredGrid* vtkStructuredGridAlgorithm::GetStructuredGridInput(int port)
{
return vtkStructuredGrid::SafeDownCast(this->GetInput(port));
}
//----------------------------------------------------------------------------
int vtkStructuredGridAlgorithm::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// generate the data
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
return this->RequestData(request, inputVector, outputVector);
}
if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
return this->RequestUpdateExtent(request, inputVector, outputVector);
}
// execute information
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
{
return this->RequestInformation(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
int vtkStructuredGridAlgorithm::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
// now add our info
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkStructuredGrid");
return 1;
}
//----------------------------------------------------------------------------
int vtkStructuredGridAlgorithm::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkStructuredGrid");
return 1;
}
//----------------------------------------------------------------------------
int vtkStructuredGridAlgorithm::RequestInformation(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* vtkNotUsed(outputVector))
{
// do nothing let subclasses handle it
return 1;
}
//----------------------------------------------------------------------------
// This is the superclasses style of Execute method. Convert it into
// an imaging style Execute method.
int vtkStructuredGridAlgorithm::RequestData(
vtkInformation* request,
vtkInformationVector** vtkNotUsed( inputVector ),
vtkInformationVector* outputVector)
{
// the default implimentation is to do what the old pipeline did find what
// output is requesting the data, and pass that into ExecuteData
// which output port did the request come from
int outputPort =
request->Get(vtkDemandDrivenPipeline::FROM_OUTPUT_PORT());
// if output port is negative then that means this filter is calling the
// update directly, in that case just assume port 0
if (outputPort == -1)
{
outputPort = 0;
}
// get the data object
vtkInformation *outInfo =
outputVector->GetInformationObject(outputPort);
// call ExecuteData
this->ExecuteData( outInfo->Get(vtkDataObject::DATA_OBJECT()) );
return 1;
}
//----------------------------------------------------------------------------
// Assume that any source that implements ExecuteData
// can handle an empty extent.
void vtkStructuredGridAlgorithm::ExecuteData(vtkDataObject *output)
{
// I want to find out if the requested extent is empty.
if (output && this->UpdateExtentIsEmpty(output))
{
output->Initialize();
return;
}
this->Execute();
}
//----------------------------------------------------------------------------
void vtkStructuredGridAlgorithm::Execute()
{
vtkErrorMacro(<< "Definition of Execute() method should be in subclass and you should really use the ExecuteData(vtkInformation *request,...) signature instead");
}
//----------------------------------------------------------------------------
int vtkStructuredGridAlgorithm::UpdateExtentIsEmpty(vtkDataObject *output)
{
if (output == NULL)
{
return 1;
}
int *ext = output->GetUpdateExtent();
switch ( output->GetExtentType() )
{
case VTK_PIECES_EXTENT:
// Special way of asking for no input.
if ( output->GetUpdateNumberOfPieces() == 0 )
{
return 1;
}
break;
case VTK_3D_EXTENT:
// Special way of asking for no input. (zero volume)
if (ext[0] == (ext[1] + 1) ||
ext[2] == (ext[3] + 1) ||
ext[4] == (ext[5] + 1))
{
return 1;
}
break;
// We should never have this case occur
default:
vtkErrorMacro( << "Internal error - invalid extent type!" );
break;
}
return 0;
}
//----------------------------------------------------------------------------
void vtkStructuredGridAlgorithm::SetInput(vtkDataObject* input)
{
this->SetInput(0, input);
}
//----------------------------------------------------------------------------
void vtkStructuredGridAlgorithm::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 vtkStructuredGridAlgorithm::AddInput(vtkDataObject* input)
{
this->AddInput(0, input);
}
//----------------------------------------------------------------------------
void vtkStructuredGridAlgorithm::AddInput(int index, vtkDataObject* input)
{
if(input)
{
this->AddInputConnection(index, input->GetProducerPort());
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkStructuredGridAlgorithm.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 vtkStructuredGridAlgorithm - Superclass for algorithms that produce only structured grid as output
// .SECTION Description
// vtkStructuredGridAlgorithm 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
// constructor for the default. This class also provides a FillInputPortInfo
// method that by default says that all inputs will be StructuredGrid. 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
// ExecuteData and ExecuteInformation. For new algorithms you should
// implement RequestData( request, inputVec, outputVec) but for older filters
// there is a default implementation that calls the old ExecuteData(output)
// signature, for even older filters that don;t implement ExecuteData the
// default implementation calls the even older Execute() signature.
#ifndef __vtkStructuredGridAlgorithm_h
#define __vtkStructuredGridAlgorithm_h
#include "vtkAlgorithm.h"
#include "vtkStructuredGrid.h" // makes things a bit easier
class vtkDataSet;
class vtkStructuredGrid;
class VTK_FILTERING_EXPORT vtkStructuredGridAlgorithm : public vtkAlgorithm
{
public:
static vtkStructuredGridAlgorithm *New();
vtkTypeRevisionMacro(vtkStructuredGridAlgorithm,vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the output data object for a port on this algorithm.
vtkStructuredGrid* GetOutput();
vtkStructuredGrid* GetOutput(int);
virtual void SetOutput(vtkDataObject* d);
// Description:
// see vtkAlgorithm for details
virtual int ProcessRequest(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
// this method is not recommended for use, but lots of old style filters
// use it
vtkDataObject* GetInput();
vtkDataObject *GetInput(int port);
vtkStructuredGrid *GetStructuredGridInput(int port);
// Description:
// Set an input of this algorithm.
void SetInput(vtkDataObject *);
void SetInput(int, vtkDataObject*);
// Description:
// Add an input of this algorithm.
void AddInput(vtkDataObject *);
void AddInput(int, vtkDataObject*);
protected:
vtkStructuredGridAlgorithm();
~vtkStructuredGridAlgorithm();
// convinience method
virtual int RequestInformation(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
// This is called by the superclass.
// This is the method you should override.
virtual int RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
// This is called by the superclass.
// This is the method you should override.
virtual int RequestUpdateExtent(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*)
{
return 1;
};
// Description:
// This detects when the UpdateExtent will generate no data.
// This condition is satisfied when the UpdateExtent has
// zero volume (0,-1,...) or the UpdateNumberOfPieces is 0.
// The source uses this call to determine whether to call Execute.
int UpdateExtentIsEmpty(vtkDataObject *output);
// Description:
// This method is the old style execute method
virtual void ExecuteData(vtkDataObject *output);
virtual void Execute();
// see algorithm for more info
virtual int FillOutputPortInformation(int port, vtkInformation* info);
virtual int FillInputPortInformation(int port, vtkInformation* info);
private:
vtkStructuredGridAlgorithm(const vtkStructuredGridAlgorithm&); // Not implemented.
void operator=(const vtkStructuredGridAlgorithm&); // Not implemented.
};
#endif
# This file attempts to convert an old pipeline filter to a new pipeline
# filter. Run it with a -DCLASS=classname it will use that class name
# for processing
IF (NOT DEFINED CLASS)
MESSAGE ("You did not specify the class to process. Usage: cmake -DCLASS=vtkMyClass -P NewPipeConvertStructuredGrid" FATAL_ERROR)
ENDIF (NOT DEFINED CLASS)
FILE (GLOB H_FILE ${CLASS}.h)
FILE (GLOB CXX_FILE ${CLASS}.cxx)
# read in both files
FILE (READ ${H_FILE} H_CONTENTS)
FILE (READ ${CXX_FILE} CXX_CONTENTS)
#================================================================
# First do the H file
#================================================================
STRING (REGEX REPLACE
"vtkStructuredGridSource"
"vtkStructuredGridAlgorithm"
H_CONTENTS "${H_CONTENTS}")
STRING (REGEX REPLACE
"vtkStructuredGridToStructuredGridFilter"
"vtkStructuredGridAlgorithm"
H_CONTENTS "${H_CONTENTS}")
STRING (REGEX REPLACE
"void[ \t]+Execute[ \t]*\\([ \t]*\\)"
"int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)"
H_CONTENTS "${H_CONTENTS}")
STRING (REGEX REPLACE
"void[ \t]+ExecuteInformation[ \t]*\\([ \t]*\\)"
"int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)"
H_CONTENTS "${H_CONTENTS}")
STRING (REGEX REPLACE
"void[ \t]+ComputeInputUpdateExtents[ \t]*\\([ \t]*[^)]*\\)"
"int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *)"
H_CONTENTS "${H_CONTENTS}")
FILE (WRITE ${H_FILE} "${H_CONTENTS}")
#================================================================
# Now do the CXX files
#================================================================
STRING (REGEX REPLACE
"::Execute[ \t]*\\([^{]*{"
"::RequestData(\n vtkInformation *vtkNotUsed(request),\n vtkInformationVector **inputVector,\n vtkInformationVector *outputVector)\n{\n // get the info objects\n vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);\n vtkInformation *outInfo = outputVector->GetInformationObject(0);\n\n // get the input and ouptut\n vtkStructuredGrid *input = vtkStructuredGrid::SafeDownCast(\n inInfo->Get(vtkDataObject::DATA_OBJECT()));\n vtkStructuredGrid *output = vtkStructuredGrid::SafeDownCast(\n outInfo->Get(vtkDataObject::DATA_OBJECT()));\n"
CXX_CONTENTS "${CXX_CONTENTS}")
STRING (REGEX REPLACE
"::ExecuteInformation[ \t]*\\([^{]*{"
"::RequestInformation(\n vtkInformation *vtkNotUsed(request),\n vtkInformationVector **inputVector,\n vtkInformationVector *outputVector)\n{\n // get the info objects\n vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);\n vtkInformation *outInfo = outputVector->GetInformationObject(0);\n"
CXX_CONTENTS "${CXX_CONTENTS}")
STRING (REGEX REPLACE
"::ComputeInputUpdateExtents[ \t]*\\([^{]*{"
"::RequestUpdateExtent(\n vtkInformation *vtkNotUsed(request),\n vtkInformationVector **inputVector,\n vtkInformationVector *outputVector)\n{\n // get the info objects\n vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);\n vtkInformation *outInfo = outputVector->GetInformationObject(0);\n"
CXX_CONTENTS "${CXX_CONTENTS}")
# add some useful include files if needed
IF ("${CXX_CONTENTS}" MATCHES ".*vtkInformation.*")
# do not do these replacements multiple times
IF (NOT "${CXX_CONTENTS}" MATCHES ".*vtkInformation.h.*")
STRING (REGEX REPLACE
"vtkObjectFactory.h"
"vtkInformation.h\"\n#include \"vtkInformationVector.h\"\n#include \"vtkObjectFactory.h"
CXX_CONTENTS "${CXX_CONTENTS}")
ENDIF (NOT "${CXX_CONTENTS}" MATCHES ".*vtkInformation.h.*")
ENDIF ("${CXX_CONTENTS}" MATCHES ".*vtkInformation.*")
FILE (WRITE ${CXX_FILE} "${CXX_CONTENTS}")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment