Commit 24b9f16f authored by Timothy M. Shead's avatar Timothy M. Shead

ENH: Merge vtkFactoredArrayData into vtkArrayData - making a distinction...

ENH: Merge vtkFactoredArrayData into vtkArrayData - making a distinction between the two has become a liability rather than an asset.
parent 7ee559ef
......@@ -327,8 +327,6 @@ IF(VTK_USE_N_WAY_ARRAYS)
${Kit_SRCS}
vtkArrayData.cxx
vtkArrayDataAlgorithm.cxx
vtkFactoredArrayData.cxx
vtkFactoredArrayDataAlgorithm.cxx
)
ENDIF(VTK_USE_N_WAY_ARRAYS)
......
......@@ -25,31 +25,47 @@
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkArrayData, "1.3");
#include <vtksys/stl/algorithm>
#include <vtksys/stl/vector>
//
// Standard functions
//
vtkCxxRevisionMacro(vtkArrayData, "1.4");
vtkStandardNewMacro(vtkArrayData);
vtkCxxSetObjectMacro(vtkArrayData, Array, vtkArray);
class vtkArrayData::implementation
{
public:
vtkstd::vector<vtkArray*> Arrays;
};
//----------------------------------------------------------------------------
vtkArrayData::vtkArrayData() :
Array(0)
Implementation(new implementation())
{
}
//----------------------------------------------------------------------------
vtkArrayData::~vtkArrayData()
{
if(this->Array)
{
this->Array->Delete();
}
this->ClearArrays();
delete this->Implementation;
}
//----------------------------------------------------------------------------
void vtkArrayData::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Array: " << (this->Array ? "" : "(none)") << endl;
if(this->Array)
for(unsigned int i = 0; i != this->Implementation->Arrays.size(); ++i)
{
this->Array->PrintSelf(os, indent.GetNextIndent());
os << indent << "Array: " << this->Implementation->Arrays[i] << endl;
this->Implementation->Arrays[i]->PrintSelf(os, indent.GetNextIndent());
}
}
......@@ -63,3 +79,39 @@ vtkArrayData* vtkArrayData::GetData(vtkInformationVector* v, int i)
return vtkArrayData::GetData(v->GetInformationObject(i));
}
void vtkArrayData::AddArray(vtkArray* array)
{
if(!array)
{
vtkErrorMacro(<< "vtkArrayData::AddArray() - cannot add NULL array");
return;
}
if(vtkstd::count(this->Implementation->Arrays.begin(), this->Implementation->Arrays.end(), array))
{
vtkErrorMacro(<< "vtkArrayData::AddArray() - cannot add array twice");
return;
}
this->Implementation->Arrays.push_back(array);
array->Register(0);
}
void vtkArrayData::ClearArrays()
{
for(unsigned int i = 0; i != this->Implementation->Arrays.size(); ++i)
this->Implementation->Arrays[i]->Delete();
this->Implementation->Arrays.clear();
}
vtkIdType vtkArrayData::GetNumberOfArrays()
{
return this->Implementation->Arrays.size();
}
vtkArray* vtkArrayData::GetArray(vtkIdType index)
{
return this->Implementation->Arrays[index];
}
......@@ -26,12 +26,19 @@
#include "vtkDataObject.h"
class vtkArray;
class vtkInformation;
class vtkInformationVector;
// .NAME vtkArrayData - Pipeline data object that acts as a container
// for a single vtkArray
// .NAME vtkArrayData - Pipeline data object that contains multiple vtkArray objects.
//
// .SECTION Description
// Because vtkArray cannot be stored as attributes of data objects (yet), a "carrier"
// object is needed to pass vtkArray through the pipeline. vtkArrayData acts as a
// container of zero-to-many vtkArray instances, which can be retrieved via a zero-based
// index. Note that a collection of arrays stored in vtkArrayData may-or-may-not have related
// types, dimensions, or extents.
//
// .SECTION See Also
// vtkArrayDataAlgorithm, vtkArray
//
// .SECTION Thanks
// Developed by Timothy M. Shead (tshead@sandia.gov) at Sandia National Laboratories.
......@@ -46,22 +53,33 @@ public:
static vtkArrayData* GetData(vtkInformationVector* v, int i = 0);
// Description:
// Sets the vtkArray instance contained by this object
virtual void SetArray(vtkArray*);
// Adds a vtkArray to the collection
void AddArray(vtkArray*);
// Description:
// Clears the contents of the collection
void ClearArrays();
// Description:
// Returns the vtkArray instance (if any) contained by this object
vtkGetObjectMacro(Array, vtkArray);
// Returns the number of vtkArray instances in the collection
vtkIdType GetNumberOfArrays();
// Description:
// Returns the n-th vtkArray in the collection
vtkArray* GetArray(vtkIdType index);
protected:
vtkArrayData();
~vtkArrayData();
vtkArray* Array;
private:
vtkArrayData(const vtkArrayData&); // Not implemented
void operator=(const vtkArrayData&); // Not implemented
//BTX
class implementation;
implementation* const Implementation;
//ETX
};
#endif
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFactoredArrayData.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
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 "vtkArray.h"
#include "vtkFactoredArrayData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include <vtksys/stl/algorithm>
#include <vtksys/stl/vector>
//
// Standard functions
//
vtkCxxRevisionMacro(vtkFactoredArrayData, "1.3");
vtkStandardNewMacro(vtkFactoredArrayData);
class vtkFactoredArrayData::implementation
{
public:
vtkstd::vector<vtkArray*> Arrays;
};
//----------------------------------------------------------------------------
vtkFactoredArrayData::vtkFactoredArrayData() :
Implementation(new implementation())
{
}
//----------------------------------------------------------------------------
vtkFactoredArrayData::~vtkFactoredArrayData()
{
this->ClearArrays();
delete this->Implementation;
}
//----------------------------------------------------------------------------
void vtkFactoredArrayData::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
for(unsigned int i = 0; i != this->Implementation->Arrays.size(); ++i)
{
os << indent << "Array: " << this->Implementation->Arrays[i] << endl;
this->Implementation->Arrays[i]->PrintSelf(os, indent.GetNextIndent());
}
}
vtkFactoredArrayData* vtkFactoredArrayData::GetData(vtkInformation* info)
{
return info? vtkFactoredArrayData::SafeDownCast(info->Get(DATA_OBJECT())) : 0;
}
vtkFactoredArrayData* vtkFactoredArrayData::GetData(vtkInformationVector* v, int i)
{
return vtkFactoredArrayData::GetData(v->GetInformationObject(i));
}
void vtkFactoredArrayData::AddArray(vtkArray* array)
{
if(!array)
{
vtkErrorMacro(<< "vtkFactoredArrayData::AddArray() - cannot add NULL array");
return;
}
if(vtkstd::count(this->Implementation->Arrays.begin(), this->Implementation->Arrays.end(), array))
{
vtkErrorMacro(<< "vtkFactoredArrayData::AddArray() - cannot add array twice");
return;
}
this->Implementation->Arrays.push_back(array);
array->Register(0);
}
void vtkFactoredArrayData::ClearArrays()
{
for(unsigned int i = 0; i != this->Implementation->Arrays.size(); ++i)
this->Implementation->Arrays[i]->Delete();
this->Implementation->Arrays.clear();
}
vtkIdType vtkFactoredArrayData::GetNumberOfArrays()
{
return this->Implementation->Arrays.size();
}
vtkArray* vtkFactoredArrayData::GetArray(vtkIdType index)
{
return this->Implementation->Arrays[index];
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFactoredArrayData.h
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
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.
=========================================================================*/
#ifndef __vtkFactoredArrayData_h
#define __vtkFactoredArrayData_h
#include "vtkArray.h"
#include "vtkDataObject.h"
class vtkArray;
// .NAME vtkFactoredArrayData - Pipeline data object that contains a
// collection of vtkArray instances. Used to store the "factored"
// representation of a larger array.
// .SECTION Thanks
// Developed by Timothy M. Shead (tshead@sandia.gov) at Sandia National Laboratories.
class VTK_FILTERING_EXPORT vtkFactoredArrayData : public vtkDataObject
{
public:
static vtkFactoredArrayData* New();
vtkTypeRevisionMacro(vtkFactoredArrayData, vtkDataObject);
void PrintSelf(ostream &os, vtkIndent indent);
static vtkFactoredArrayData* GetData(vtkInformation* info);
static vtkFactoredArrayData* GetData(vtkInformationVector* v, int i = 0);
// Description:
// Adds a vtkArray to the collection
void AddArray(vtkArray*);
// Description:
// Clears the contents of the collection
void ClearArrays();
// Description:
// Returns the number of vtkArray instances in the collection
vtkIdType GetNumberOfArrays();
// Description:
// Returns the n-th vtkArray in the collection
vtkArray* GetArray(vtkIdType index);
protected:
vtkFactoredArrayData();
~vtkFactoredArrayData();
private:
vtkFactoredArrayData(const vtkFactoredArrayData&); // Not implemented
void operator=(const vtkFactoredArrayData&); // Not implemented
//BTX
class implementation;
implementation* const Implementation;
//ETX
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFactoredArrayDataAlgorithm.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
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 "vtkFactoredArrayData.h"
#include "vtkFactoredArrayDataAlgorithm.h"
#include "vtkCommand.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkTrivialProducer.h"
vtkCxxRevisionMacro(vtkFactoredArrayDataAlgorithm, "1.1");
vtkStandardNewMacro(vtkFactoredArrayDataAlgorithm);
//----------------------------------------------------------------------------
vtkFactoredArrayDataAlgorithm::vtkFactoredArrayDataAlgorithm()
{
// by default assume filters have one input and one output
// subclasses that deviate should modify this setting
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
}
//----------------------------------------------------------------------------
vtkFactoredArrayDataAlgorithm::~vtkFactoredArrayDataAlgorithm()
{
}
//----------------------------------------------------------------------------
void vtkFactoredArrayDataAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
int vtkFactoredArrayDataAlgorithm::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 vtkFactoredArrayDataAlgorithm::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
// now add our info
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkFactoredArrayData");
return 1;
}
//----------------------------------------------------------------------------
int vtkFactoredArrayDataAlgorithm::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkFactoredArrayData");
return 1;
}
//----------------------------------------------------------------------------
vtkFactoredArrayData* vtkFactoredArrayDataAlgorithm::GetOutput(int index)
{
return vtkFactoredArrayData::SafeDownCast(this->GetOutputDataObject(index));
}
//----------------------------------------------------------------------------
void vtkFactoredArrayDataAlgorithm::SetInput(int index, vtkDataObject* input)
{
if (input)
{
this->SetInputConnection(index, input->GetProducerPort());
}
else
{
// Setting a NULL input removes the connection.
this->SetInputConnection(index, 0);
}
}
//----------------------------------------------------------------------------
int vtkFactoredArrayDataAlgorithm::RequestInformation(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* vtkNotUsed(outputVector))
{
// do nothing let subclasses handle it
return 1;
}
//----------------------------------------------------------------------------
int vtkFactoredArrayDataAlgorithm::RequestUpdateExtent(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* vtkNotUsed(outputVector))
{
int numInputPorts = this->GetNumberOfInputPorts();
for (int i=0; i<numInputPorts; i++)
{
int numInputConnections = this->GetNumberOfInputConnections(i);
for (int j=0; j<numInputConnections; j++)
{
vtkInformation* inputInfo = inputVector[i]->GetInformationObject(j);
inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1);
}
}
return 1;
}
//----------------------------------------------------------------------------
// This is the superclasses style of Execute method. Convert it into
// an imaging style Execute method.
int vtkFactoredArrayDataAlgorithm::RequestData(
vtkInformation* vtkNotUsed( request ),
vtkInformationVector** vtkNotUsed( inputVector ),
vtkInformationVector* vtkNotUsed( outputVector ) )
{
return 0;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFactoredArrayDataAlgorithm.h
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
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 vtkFactoredArrayDataAlgorithm - Superclass for algorithms that
// produce vtkFactoredArrayData as output
//
// .SECTION Description
// vtkFactoredArrayDataAlgorithm is a convenience class to make writing algorithms
// easier. It is also designed to help transition old algorithms to the new
// pipeline architecture. There 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 class
// constructor for the default. This class also provides a FillInputPortInfo
// method that by default says that all inputs will be vtkFactoredArrayData. If that
// isn't the case then please override this method in your subclass. This
// class breaks out the downstream requests into separate 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.
// .SECTION Thanks
// Developed by Timothy M. Shead (tshead@sandia.gov) at Sandia National Laboratories.
#ifndef __vtkFactoredArrayDataAlgorithm_h
#define __vtkFactoredArrayDataAlgorithm_h
#include "vtkAlgorithm.h"
#include "vtkFactoredArrayData.h"
class vtkDataSet;
class VTK_FILTERING_EXPORT vtkFactoredArrayDataAlgorithm : public vtkAlgorithm
{
public:
static vtkFactoredArrayDataAlgorithm *New();
vtkTypeRevisionMacro(vtkFactoredArrayDataAlgorithm,vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// see vtkAlgorithm for details
virtual int ProcessRequest(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
// Description:
// Get the output data object for a port on this algorithm.
vtkFactoredArrayData* GetOutput() { return this->GetOutput(0); }
vtkFactoredArrayData* GetOutput(int index);
// Description:
// Set an input of this algorithm. You should not override these
// methods because they are not the only way to connect a pipeline.
// Note that these methods support old-style pipeline connections.
// When writing new code you should use the more general
// vtkAlgorithm::SetInputConnection(). These methods transform the
// input index to the input port index, not an index of a connection
// within a single port.
void SetInput(vtkDataObject * obj) { this->SetInput(0, obj); }
void SetInput(int index, vtkDataObject* obj);
protected:
vtkFactoredArrayDataAlgorithm();
~vtkFactoredArrayDataAlgorithm();