Commit 2931a936 authored by Ken Martin's avatar Ken Martin
Browse files

ENH: rearranged the code and fixed failing test

parent 4e62719c
......@@ -35,7 +35,7 @@
#include <vtkstd/set>
#include <vtkstd/vector>
vtkCxxRevisionMacro(vtkAlgorithm, "1.20");
vtkCxxRevisionMacro(vtkAlgorithm, "1.21");
vtkStandardNewMacro(vtkAlgorithm);
vtkCxxSetObjectMacro(vtkAlgorithm,Information,vtkInformation);
......@@ -440,12 +440,141 @@ void vtkAlgorithm::SetNumberOfOutputPorts(int n)
}
//----------------------------------------------------------------------------
vtkDataObject* vtkAlgorithm::GetOutputDataObject(int port)
vtkInformation* vtkAlgorithm::GetInputPortInformation(int port)
{
if(!this->InputPortIndexInRange(port, "get information object for"))
{
return 0;
}
// Get the input port information object.
vtkInformation* info =
this->InputPortInformation->GetInformationObject(port);
// Fill it if it has not yet been filled.
if(!info->Has(PORT_REQUIREMENTS_FILLED()))
{
if(this->FillInputPortInformation(port, info))
{
info->Set(PORT_REQUIREMENTS_FILLED(), 1);
}
else
{
info->Clear();
}
}
// Return ths information object.
return info;
}
//----------------------------------------------------------------------------
vtkInformation* vtkAlgorithm::GetOutputPortInformation(int port)
{
if(!this->OutputPortIndexInRange(port, "get information object for"))
{
return 0;
}
// Get the output port information object.
vtkInformation* info =
this->OutputPortInformation->GetInformationObject(port);
// Fill it if it has not yet been filled.
if(!info->Has(PORT_REQUIREMENTS_FILLED()))
{
if(this->FillOutputPortInformation(port, info))
{
info->Set(PORT_REQUIREMENTS_FILLED(), 1);
}
else
{
info->Clear();
}
}
// Return ths information object.
return info;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::FillInputPortInformation(int, vtkInformation*)
{
vtkErrorMacro("FillInputPortInformation is not implemented.");
return 0;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::FillOutputPortInformation(int, vtkInformation*)
{
vtkErrorMacro("FillOutputPortInformation is not implemented.");
return 0;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::InputPortIndexInRange(int index, const char* action)
{
// Make sure the index of the input port is in range.
if(index < 0 || index >= this->GetNumberOfInputPorts())
{
vtkErrorMacro("Attempt to " << (action?action:"access")
<< " input port index " << index
<< " for an algorithm with "
<< this->GetNumberOfInputPorts() << " input ports.");
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::OutputPortIndexInRange(int index, const char* action)
{
if(!this->OutputPortIndexInRange(port, "get the data object for"))
// Make sure the index of the output port is in range.
if(index < 0 || index >= this->GetNumberOfOutputPorts())
{
vtkErrorMacro("Attempt to " << (action?action:"access")
<< " output port index " << index
<< " for an algorithm with "
<< this->GetNumberOfOutputPorts() << " output ports.");
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
vtkExecutive* vtkAlgorithm::CreateDefaultExecutive()
{
return vtkStreamingDemandDrivenPipeline::New();
}
//----------------------------------------------------------------------------
void vtkAlgorithm::Register(vtkObjectBase* o)
{
this->RegisterInternal(o, 1);
}
//----------------------------------------------------------------------------
void vtkAlgorithm::UnRegister(vtkObjectBase* o)
{
this->UnRegisterInternal(o, 1);
}
//----------------------------------------------------------------------------
void vtkAlgorithm::ReportReferences(vtkGarbageCollector* collector)
{
this->Superclass::ReportReferences(collector);
vtkGarbageCollectorReport(collector, this->Executive, "Executive");
}
/// These are convenience methods to forward to the executive
//----------------------------------------------------------------------------
vtkDataObject* vtkAlgorithm::GetOutputDataObject(int port)
{
return this->GetExecutive()->GetOutputData(port);
}
......@@ -729,77 +858,6 @@ vtkAlgorithmOutput* vtkAlgorithm::GetOutputPort(int port)
return this->AlgorithmInternal->Outputs[port];
}
//----------------------------------------------------------------------------
vtkInformation* vtkAlgorithm::GetInputPortInformation(int port)
{
if(!this->InputPortIndexInRange(port, "get information object for"))
{
return 0;
}
// Get the input port information object.
vtkInformation* info =
this->InputPortInformation->GetInformationObject(port);
// Fill it if it has not yet been filled.
if(!info->Has(PORT_REQUIREMENTS_FILLED()))
{
if(this->FillInputPortInformation(port, info))
{
info->Set(PORT_REQUIREMENTS_FILLED(), 1);
}
else
{
info->Clear();
}
}
// Return ths information object.
return info;
}
//----------------------------------------------------------------------------
vtkInformation* vtkAlgorithm::GetOutputPortInformation(int port)
{
if(!this->OutputPortIndexInRange(port, "get information object for"))
{
return 0;
}
// Get the output port information object.
vtkInformation* info =
this->OutputPortInformation->GetInformationObject(port);
// Fill it if it has not yet been filled.
if(!info->Has(PORT_REQUIREMENTS_FILLED()))
{
if(this->FillOutputPortInformation(port, info))
{
info->Set(PORT_REQUIREMENTS_FILLED(), 1);
}
else
{
info->Clear();
}
}
// Return ths information object.
return info;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::FillInputPortInformation(int, vtkInformation*)
{
vtkErrorMacro("FillInputPortInformation is not implemented.");
return 0;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::FillOutputPortInformation(int, vtkInformation*)
{
vtkErrorMacro("FillOutputPortInformation is not implemented.");
return 0;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::GetNumberOfInputConnections(int port)
......@@ -853,36 +911,6 @@ vtkAlgorithmOutput* vtkAlgorithm::GetInputConnection(int port, int index)
return 0;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::InputPortIndexInRange(int index, const char* action)
{
// Make sure the index of the input port is in range.
if(index < 0 || index >= this->GetNumberOfInputPorts())
{
vtkErrorMacro("Attempt to " << (action?action:"access")
<< " input port index " << index
<< " for an algorithm with "
<< this->GetNumberOfInputPorts() << " input ports.");
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkAlgorithm::OutputPortIndexInRange(int index, const char* action)
{
// Make sure the index of the output port is in range.
if(index < 0 || index >= this->GetNumberOfOutputPorts())
{
vtkErrorMacro("Attempt to " << (action?action:"access")
<< " output port index " << index
<< " for an algorithm with "
<< this->GetNumberOfOutputPorts() << " output ports.");
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
void vtkAlgorithm::Update()
{
......@@ -915,30 +943,6 @@ void vtkAlgorithm::UpdateWholeExtent()
}
}
//----------------------------------------------------------------------------
vtkExecutive* vtkAlgorithm::CreateDefaultExecutive()
{
return vtkStreamingDemandDrivenPipeline::New();
}
//----------------------------------------------------------------------------
void vtkAlgorithm::Register(vtkObjectBase* o)
{
this->RegisterInternal(o, 1);
}
//----------------------------------------------------------------------------
void vtkAlgorithm::UnRegister(vtkObjectBase* o)
{
this->UnRegisterInternal(o, 1);
}
//----------------------------------------------------------------------------
void vtkAlgorithm::ReportReferences(vtkGarbageCollector* collector)
{
this->Superclass::ReportReferences(collector);
vtkGarbageCollectorReport(collector, this->Executive, "Executive");
}
//----------------------------------------------------------------------------
void vtkAlgorithm::ConvertTotalInputToPortConnection(
......
......@@ -108,6 +108,83 @@ public:
vtkGetObjectMacro(Information, vtkInformation);
virtual void SetInformation(vtkInformation*);
// Description:
// Get the number of input ports used by the algorithm.
int GetNumberOfInputPorts();
// Description:
// Get the number of output ports provided by the algorithm.
int GetNumberOfOutputPorts();
// Description:
// Participate in garbage collection.
virtual void Register(vtkObjectBase* o);
virtual void UnRegister(vtkObjectBase* o);
// Description:
// Set/Get the AbortExecute flag for the process object. Process objects
// may handle premature termination of execution in different ways.
vtkSetMacro(AbortExecute,int);
vtkGetMacro(AbortExecute,int);
vtkBooleanMacro(AbortExecute,int);
// Description:
// Set/Get the execution progress of a process object.
vtkSetClampMacro(Progress,double,0.0,1.0);
vtkGetMacro(Progress,double);
// Description:
// Update the progress of the process object. If a ProgressMethod exists,
// executes it. Then set the Progress ivar to amount. The parameter amount
// should range between (0,1).
void UpdateProgress(double amount);
// Description:
// Set the current text message associated with the progress state.
// This may be used by a calling process/GUI.
vtkSetStringMacro(ProgressText);
vtkGetStringMacro(ProgressText);
// Description:
// The error code contains a possible error that occured while
// reading or writing the file.
vtkGetMacro( ErrorCode, unsigned long );
// left public for performance since it is used in inner loops
int AbortExecute;
// Description:
// Keys used to specify input port requirements.
static vtkInformationIntegerKey* INPUT_IS_OPTIONAL();
static vtkInformationIntegerKey* INPUT_IS_REPEATABLE();
static vtkInformationInformationVectorKey* INPUT_REQUIRED_FIELDS();
static vtkInformationStringKey* INPUT_REQUIRED_DATA_TYPE();
static vtkInformationInformationVectorKey* INPUT_ARRAYS_TO_PROCESS();
static vtkInformationIntegerKey* INPUT_PORT();
static vtkInformationIntegerKey* INPUT_CONNECTION();
// Description:
// Set the input data arrays that this algorithm will process. Specifically
// the idx array that this algorithm will process (starting from 0) is the
// array on port, connection with the specified association and name or
// attribute type (such as SCALARS)
void SetInputArrayToProcess(int idx, int port, int connection,
int fieldAssociation,
const char *name);
void SetInputArrayToProcess(int idx, int port, int connection,
int fieldAssociation,
int fieldAttributeType);
void SetInputArrayToProcess(int idx, vtkInformation *info);
// Description:
// Get the info object for the specified input array to this algorithm
vtkInformation *GetInputArrayInformation(int idx);
// from here down are convenience methods that really ar executive methods
// Description:
// Remove all the input data.
void RemoveAllInputs();
......@@ -139,14 +216,6 @@ public:
vtkAlgorithmOutput* GetOutputPort() {
return this->GetOutputPort(0); }
// Description:
// Get the number of input ports used by the algorithm.
int GetNumberOfInputPorts();
// Description:
// Get the number of output ports provided by the algorithm.
int GetNumberOfOutputPorts();
// Description:
// Get the number of input currently connected to a port.
int GetNumberOfInputConnections(int port);
......@@ -171,53 +240,6 @@ public:
// Bring this algorithm's outputs up-to-date.
virtual void UpdateWholeExtent();
// Description:
// Participate in garbage collection.
virtual void Register(vtkObjectBase* o);
virtual void UnRegister(vtkObjectBase* o);
// Description:
// Set/Get the AbortExecute flag for the process object. Process objects
// may handle premature termination of execution in different ways.
vtkSetMacro(AbortExecute,int);
vtkGetMacro(AbortExecute,int);
vtkBooleanMacro(AbortExecute,int);
// Description:
// Set/Get the execution progress of a process object.
vtkSetClampMacro(Progress,double,0.0,1.0);
vtkGetMacro(Progress,double);
// Description:
// Update the progress of the process object. If a ProgressMethod exists,
// executes it. Then set the Progress ivar to amount. The parameter amount
// should range between (0,1).
void UpdateProgress(double amount);
// Description:
// Set the current text message associated with the progress state.
// This may be used by a calling process/GUI.
vtkSetStringMacro(ProgressText);
vtkGetStringMacro(ProgressText);
// Description:
// The error code contains a possible error that occured while
// reading or writing the file.
vtkGetMacro( ErrorCode, unsigned long );
// left public for performance since it is used in inner loops
int AbortExecute;
// Description:
// Keys used to specify input port requirements.
static vtkInformationIntegerKey* INPUT_IS_OPTIONAL();
static vtkInformationIntegerKey* INPUT_IS_REPEATABLE();
static vtkInformationInformationVectorKey* INPUT_REQUIRED_FIELDS();
static vtkInformationStringKey* INPUT_REQUIRED_DATA_TYPE();
static vtkInformationInformationVectorKey* INPUT_ARRAYS_TO_PROCESS();
static vtkInformationIntegerKey* INPUT_PORT();
static vtkInformationIntegerKey* INPUT_CONNECTION();
// Description:
// Conviniance routine to convert from a linrar ordering of input
// connections to a port, connecction pair
......@@ -237,23 +259,6 @@ public:
void ReleaseDataFlagOn();
void ReleaseDataFlagOff();
// Description:
// Set the input data arrays that this algorithm will process. Specifically
// the idx array that this algorithm will process (starting from 0) is the
// array on port, connection with the specified association and name or
// attribute type (such as SCALARS)
void SetInputArrayToProcess(int idx, int port, int connection,
int fieldAssociation,
const char *name);
void SetInputArrayToProcess(int idx, int port, int connection,
int fieldAssociation,
int fieldAttributeType);
void SetInputArrayToProcess(int idx, vtkInformation *info);
// Description:
// Get the info object for the specified input array to this algorithm
vtkInformation *GetInputArrayInformation(int idx);
//========================================================================
// Description:
......@@ -299,21 +304,6 @@ protected:
int InputPortIndexInRange(int index, const char* action);
int OutputPortIndexInRange(int index, const char* action);
// Description:
// Replace the Nth connection on the given input port. For use only
// by this class and subclasses. If this is used to store a NULL
// input then the subclass must be able to handle NULL inputs in its
// ProcessRequest method.
virtual void SetNthInputConnection(int port, int index,
vtkAlgorithmOutput* input);
// Description:
// Set the number of input connections on the given input port. For
// use only by this class and subclasses. If this is used to store
// a NULL input then the subclass must be able to handle NULL inputs
// in its ProcessRequest method.
virtual void SetNumberOfInputConnections(int port, int n);
// Description:
// Get the actual data array for the input array sepcified by idx, this is
// only reasonable during the REQUEST_DATA pass
......@@ -344,6 +334,24 @@ protected:
// Garbage collection support.
virtual void ReportReferences(vtkGarbageCollector*);
// executive methods below
// Description:
// Replace the Nth connection on the given input port. For use only
// by this class and subclasses. If this is used to store a NULL
// input then the subclass must be able to handle NULL inputs in its
// ProcessRequest method.
virtual void SetNthInputConnection(int port, int index,
vtkAlgorithmOutput* input);
// Description:
// Set the number of input connections on the given input port. For
// use only by this class and subclasses. If this is used to store
// a NULL input then the subclass must be able to handle NULL inputs
// in its ProcessRequest method.
virtual void SetNumberOfInputConnections(int port, int n);
private:
vtkExecutive* Executive;
vtkInformationVector* InputPortInformation;
......
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