Commit 6adcad5a authored by Amy Squillacote's avatar Amy Squillacote

ENH: adding vtkUnstructuredGridAlgorithm

parent 40e07019
......@@ -185,6 +185,7 @@ vtkTriangleStrip.cxx
vtkTrivialProducer.cxx
vtkUniformGrid.cxx
vtkUnstructuredGrid.cxx
vtkUnstructuredGridAlgorithm.cxx
vtkUnstructuredGridSource.cxx
vtkUnstructuredGridToPolyDataAlgorithm.cxx
vtkUnstructuredGridToPolyDataFilter.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkUnstructuredGridAlgorithm.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 "vtkUnstructuredGridAlgorithm.h"
#include "vtkCommand.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkUnstructuredGrid.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkTrivialProducer.h"
vtkCxxRevisionMacro(vtkUnstructuredGridAlgorithm, "1.1");
vtkStandardNewMacro(vtkUnstructuredGridAlgorithm);
//----------------------------------------------------------------------------
vtkUnstructuredGridAlgorithm::vtkUnstructuredGridAlgorithm()
{
// by default assume filters have one input and one output
// subclasses that deviate should modify this setting
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
}
//----------------------------------------------------------------------------
vtkUnstructuredGridAlgorithm::~vtkUnstructuredGridAlgorithm()
{
}
//----------------------------------------------------------------------------
void vtkUnstructuredGridAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
vtkUnstructuredGrid* vtkUnstructuredGridAlgorithm::GetOutput()
{
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkUnstructuredGrid* vtkUnstructuredGridAlgorithm::GetOutput(int port)
{
return vtkUnstructuredGrid::SafeDownCast(this->GetOutputDataObject(port));
}
//----------------------------------------------------------------------------
void vtkUnstructuredGridAlgorithm::SetOutput(vtkDataObject* d)
{
this->GetExecutive()->SetOutputData(0, d);
}
//----------------------------------------------------------------------------
vtkDataObject* vtkUnstructuredGridAlgorithm::GetInput()
{
return this->GetInput(0);
}
//----------------------------------------------------------------------------
vtkDataObject* vtkUnstructuredGridAlgorithm::GetInput(int port)
{
if (this->GetNumberOfInputConnections(port) < 1)
{
return 0;
}
return this->GetExecutive()->GetInputData(port, 0);
}
//----------------------------------------------------------------------------
vtkUnstructuredGrid* vtkUnstructuredGridAlgorithm::GetUnstructuredGridInput(int port)
{
return vtkUnstructuredGrid::SafeDownCast(this->GetInput(port));
}
//----------------------------------------------------------------------------
int vtkUnstructuredGridAlgorithm::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 vtkUnstructuredGridAlgorithm::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
// now add our info
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
return 1;
}
//----------------------------------------------------------------------------
int vtkUnstructuredGridAlgorithm::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid");
return 1;
}
//----------------------------------------------------------------------------
int vtkUnstructuredGridAlgorithm::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 vtkUnstructuredGridAlgorithm::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 vtkUnstructuredGridAlgorithm::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 vtkUnstructuredGridAlgorithm::Execute()
{
vtkErrorMacro(<< "Definition of Execute() method should be in subclass and you should really use the ExecuteData(vtkInformation *request,...) signature instead");
}
//----------------------------------------------------------------------------
int vtkUnstructuredGridAlgorithm::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 vtkUnstructuredGridAlgorithm::SetInput(vtkDataObject* input)
{
this->SetInput(0, input);
}
//----------------------------------------------------------------------------
void vtkUnstructuredGridAlgorithm::SetInput(int index, vtkDataObject* input)
{
if(input)
{
this->SetInputConnection(index, input->GetProducerPort());
input->GetPipelineInformation()->Set(
vtkDataObject::DATA_TYPE_NAME(), input->GetClassName());
}
else
{
// Setting a NULL input removes the connection.
this->SetInputConnection(index, 0);
}
}
//----------------------------------------------------------------------------
void vtkUnstructuredGridAlgorithm::AddInput(vtkDataObject* input)
{
this->AddInput(0, input);
}
//----------------------------------------------------------------------------
void vtkUnstructuredGridAlgorithm::AddInput(int index, vtkDataObject* input)
{
if(input)
{
this->AddInputConnection(index, input->GetProducerPort());
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkUnstructuredGridAlgorithm.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 vtkUnstructuredGridAlgorithm - Superclass for algorithms that produce only unstructured grid as output
// .SECTION Description
// vtkUnstructuredGridAlgorithm 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 UnstructuredGrid. 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 __vtkUnstructuredGridAlgorithm_h
#define __vtkUnstructuredGridAlgorithm_h
#include "vtkAlgorithm.h"
#include "vtkUnstructuredGrid.h" // makes things a bit easier
class vtkDataSet;
class vtkUnstructuredGrid;
class VTK_FILTERING_EXPORT vtkUnstructuredGridAlgorithm : public vtkAlgorithm
{
public:
static vtkUnstructuredGridAlgorithm *New();
vtkTypeRevisionMacro(vtkUnstructuredGridAlgorithm,vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the output data object for a port on this algorithm.
vtkUnstructuredGrid* GetOutput();
vtkUnstructuredGrid* 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);
vtkUnstructuredGrid *GetUnstructuredGridInput(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:
vtkUnstructuredGridAlgorithm();
~vtkUnstructuredGridAlgorithm();
// 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:
vtkUnstructuredGridAlgorithm(const vtkUnstructuredGridAlgorithm&); // Not implemented.
void operator=(const vtkUnstructuredGridAlgorithm&); // 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 NewPipeConvertUnstructuredGrid" 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
"vtkUnstructuredGridSource"
"vtkUnstructuredGridAlgorithm"
H_CONTENTS "${H_CONTENTS}")
STRING (REGEX REPLACE
"vtkUnstructuredGridToUnstructuredGridFilter"
"vtkUnstructuredGridAlgorithm"
H_CONTENTS "${H_CONTENTS}")
STRING (REGEX REPLACE
"vtkDataSetToUnstructuredGridFilter"
"vtkDataSetToUnstructuredGridAlgorithm"
H_CONTENTS "${H_CONTENTS}")
STRING (REGEX REPLACE
"vtkStructuredPointsToUnstructuredGridFilter"
"vtkStructuredPointsToUnstructuredGridAlgorithm"
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 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(\n inInfo->Get(vtkDataObject::DATA_OBJECT()));\n vtkUnstructuredGrid *output = vtkUnstructuredGrid::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