ParaView-5.0.1: Added the source-tree to ThirdParty-dev and patched as described in the README file

Resolves bug-report http://bugs.openfoam.org/view.php?id=2098
This commit is contained in:
Henry Weller
2016-05-30 21:20:56 +01:00
parent 1cce60aa78
commit eba760a6d6
24640 changed files with 6366069 additions and 0 deletions

View File

@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 2.8.8)
project(CxxMappedDataArrayExample)
set(USE_CATALYST ON CACHE BOOL "Link the simulator with Catalyst")
if(USE_CATALYST)
find_package(ParaView 4.1 REQUIRED COMPONENTS vtkPVPythonCatalyst)
include("${PARAVIEW_USE_FILE}")
set(Adaptor_SRCS
FEAdaptor.cxx
)
add_library(CxxMappedDataArrayExampleAdaptor ${Adaptor_SRCS})
target_link_libraries(CxxMappedDataArrayExampleAdaptor vtkPVPythonCatalyst vtkParallelMPI)
add_definitions("-DUSE_CATALYST")
if(NOT PARAVIEW_USE_MPI)
message(SEND_ERROR "ParaView must be built with MPI enabled")
endif()
else()
find_package(MPI REQUIRED)
include_directories(${MPI_C_INCLUDE_PATH})
endif()
add_executable(CxxMappedDataArrayExample FEDriver.cxx FEDataStructures.cxx)
if(USE_CATALYST)
target_link_libraries(CxxMappedDataArrayExample LINK_PRIVATE CxxMappedDataArrayExampleAdaptor)
include(vtkModuleMacros)
include(vtkMPI)
vtk_mpi_link(CxxMappedDataArrayExample)
else()
target_link_libraries(CxxMappedDataArrayExample LINK_PRIVATE ${MPI_LIBRARIES})
endif()
option(BUILD_TESTING "Build Testing" OFF)
# Setup testing.
if (BUILD_TESTING)
include(CTest)
add_test(NAME CxxMappedDataArrayExampleTest COMMAND CxxMappedDataArrayExample ${CMAKE_CURRENT_SOURCE_DIR}/SampleScripts/feslicescript.py)
set_tests_properties(CxxMappedDataArrayExampleTest PROPERTIES LABELS "PARAVIEW;CATALYST")
endif()

View File

@ -0,0 +1,151 @@
#include <iostream>
#include "FEAdaptor.h"
#include "FEDataStructures.h"
#include <vtkCellData.h>
#include <vtkCellType.h>
#include <vtkCPDataDescription.h>
#include <vtkCPInputDataDescription.h>
#include <vtkCPProcessor.h>
#include <vtkCPPythonScriptPipeline.h>
#include <vtkDoubleArray.h>
#include <vtkFloatArray.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPointData.h>
#include <vtkUnstructuredGrid.h>
#include "vtkCPMappedVectorArrayTemplate.h"
namespace
{
vtkCPProcessor* Processor = NULL;
vtkUnstructuredGrid* VTKGrid;
void BuildVTKGrid(Grid& grid)
{
// create the points information
vtkCPMappedVectorArrayTemplate<double>* pointArray =
vtkCPMappedVectorArrayTemplate<double>::New();
pointArray->SetVectorArray(grid.GetPointsArray(),static_cast<vtkIdType>(grid.GetNumberOfPoints()));
vtkNew<vtkPoints> points;
points->SetData(pointArray);
pointArray->Delete();
VTKGrid->SetPoints(points.GetPointer());
// create the cells
size_t numCells = grid.GetNumberOfCells();
VTKGrid->Allocate(static_cast<vtkIdType>(numCells*9));
for(size_t cell=0;cell<numCells;cell++)
{
unsigned int* cellPoints = grid.GetCellPoints(cell);
vtkIdType tmp[8] = {cellPoints[0], cellPoints[1], cellPoints[2], cellPoints[3],
cellPoints[4], cellPoints[5], cellPoints[6], cellPoints[7]};
VTKGrid->InsertNextCell(VTK_HEXAHEDRON, 8, tmp);
}
}
void UpdateVTKAttributes(Grid& grid, Attributes& attributes)
{
if(VTKGrid->GetPointData()->GetNumberOfArrays() == 0)
{
// velocity array
vtkCPMappedVectorArrayTemplate<double>* velocity =
vtkCPMappedVectorArrayTemplate<double>::New();
velocity->SetName("velocity");
VTKGrid->GetPointData()->AddArray(velocity);
velocity->Delete();
}
vtkCPMappedVectorArrayTemplate<double>* velocity =
vtkCPMappedVectorArrayTemplate<double>::SafeDownCast(
VTKGrid->GetPointData()->GetArray("velocity"));
velocity->SetVectorArray(attributes.GetVelocityArray(),
VTKGrid->GetNumberOfPoints());
if(VTKGrid->GetCellData()->GetNumberOfArrays() == 0)
{
// pressure array
vtkNew<vtkFloatArray> pressure;
pressure->SetName("pressure");
pressure->SetNumberOfComponents(1);
VTKGrid->GetCellData()->AddArray(pressure.GetPointer());
}
vtkFloatArray* pressure = vtkFloatArray::SafeDownCast(
VTKGrid->GetCellData()->GetArray("pressure"));
// The pressure array is a scalar array so we can reuse
// memory as long as we ordered the points properly.
float* pressureData = attributes.GetPressureArray();
pressure->SetArray(pressureData, static_cast<vtkIdType>(grid.GetNumberOfCells()), 1);
}
void BuildVTKDataStructures(Grid& grid, Attributes& attributes)
{
if(VTKGrid == NULL)
{
// The grid structure isn't changing so we only build it
// the first time it's needed. If we needed the memory
// we could delete it and rebuild as necessary.
VTKGrid = vtkUnstructuredGrid::New();
BuildVTKGrid(grid);
}
UpdateVTKAttributes(grid, attributes);
}
}
namespace FEAdaptor
{
void Initialize(int numScripts, char* scripts[])
{
if(Processor == NULL)
{
Processor = vtkCPProcessor::New();
Processor->Initialize();
}
else
{
Processor->RemoveAllPipelines();
}
for(int i=1;i<numScripts;i++)
{
vtkNew<vtkCPPythonScriptPipeline> pipeline;
pipeline->Initialize(scripts[i]);
Processor->AddPipeline(pipeline.GetPointer());
}
}
void Finalize()
{
if(Processor)
{
Processor->Delete();
Processor = NULL;
}
if(VTKGrid)
{
VTKGrid->Delete();
VTKGrid = NULL;
}
}
void CoProcess(Grid& grid, Attributes& attributes, double time,
unsigned int timeStep, bool lastTimeStep)
{
vtkNew<vtkCPDataDescription> dataDescription;
dataDescription->AddInput("input");
dataDescription->SetTimeData(time, timeStep);
if(lastTimeStep == true)
{
// assume that we want to all the pipelines to execute if it
// is the last time step.
dataDescription->ForceOutputOn();
}
if(Processor->RequestDataDescription(dataDescription.GetPointer()) != 0)
{
BuildVTKDataStructures(grid, attributes);
dataDescription->GetInputDescriptionByName("input")->SetGrid(VTKGrid);
Processor->CoProcess(dataDescription.GetPointer());
}
}
} // end of Catalyst namespace

View File

@ -0,0 +1,17 @@
#ifndef FEADAPTOR_HEADER
#define FEADAPTOR_HEADER
class Attributes;
class Grid;
namespace FEAdaptor
{
void Initialize(int numScripts, char* scripts[]);
void Finalize();
void CoProcess(Grid& grid, Attributes& attributes, double time,
unsigned int timeStep, bool lastTimeStep);
}
#endif

View File

@ -0,0 +1,162 @@
#include "FEDataStructures.h"
#include <mpi.h>
#include <iostream>
Grid::Grid()
{}
void Grid::Initialize(const unsigned int numPoints[3], const double spacing[3] )
{
if(numPoints[0] == 0 || numPoints[1] == 0 || numPoints[2] == 0)
{
std::cerr << "Must have a non-zero amount of points in each direction.\n";
}
// in parallel, we do a simple partitioning in the x-direction.
int mpiSize = 1;
int mpiRank = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank);
MPI_Comm_size(MPI_COMM_WORLD, &mpiSize);
unsigned int startXPoint = mpiRank*numPoints[0]/mpiSize;
unsigned int endXPoint = (mpiRank+1)*numPoints[0]/mpiSize;
if(mpiSize != mpiRank+1)
{
endXPoint++;
}
// create the points -- slowest in the x and fastest in the z directions
// all of the x coordinates are stored first, then y coordinates and
// finally z coordinates (e.g. x[0], x[1], ..., x[n-1], y[0], y[1], ...,
// y[n-1], z[0], z[1], ..., z[n-1]) which is OPPOSITE of VTK's ordering.
size_t numTotalPoints = (endXPoint-startXPoint)*numPoints[1]*numPoints[2];
this->Points.resize(3*numTotalPoints);
size_t counter = 0;
for(unsigned int i=startXPoint;i<endXPoint;i++)
{
for(unsigned int j=0;j<numPoints[1];j++)
{
for(unsigned int k=0;k<numPoints[2];k++)
{
this->Points[counter] = i*spacing[0];
this->Points[numTotalPoints+counter] = j*spacing[1];
this->Points[2*numTotalPoints+counter] = k*spacing[2];
counter++;
}
}
}
// create the hex cells
unsigned int cellPoints[8];
unsigned int numXPoints = endXPoint - startXPoint;
for(unsigned int i=0;i<numXPoints-1;i++)
{
for(unsigned int j=0;j<numPoints[1]-1;j++)
{
for(unsigned int k=0;k<numPoints[2]-1;k++)
{
cellPoints[0] = i*numPoints[1]*numPoints[2] +
j*numPoints[2] + k;
cellPoints[1] = (i+1)*numPoints[1]*numPoints[2] +
j*numPoints[2] + k;
cellPoints[2] = (i+1)*numPoints[1]*numPoints[2] +
(j+1)*numPoints[2] + k;
cellPoints[3] = i*numPoints[1]*numPoints[2] +
(j+1)*numPoints[2] + k;
cellPoints[4] = i*numPoints[1]*numPoints[2] +
j*numPoints[2] + k+1;
cellPoints[5] = (i+1)*numPoints[1]*numPoints[2] +
j*numPoints[2] + k+1;
cellPoints[6] = (i+1)*numPoints[1]*numPoints[2] +
(j+1)*numPoints[2] + k+1;
cellPoints[7] = i*numPoints[1]*numPoints[2] +
(j+1)*numPoints[2] + k+1;
std::copy(cellPoints, cellPoints+8, std::back_inserter(this->Cells));
}
}
}
}
size_t Grid::GetNumberOfPoints()
{
return this->Points.size()/3;
}
size_t Grid::GetNumberOfCells()
{
return this->Cells.size()/8;
}
double* Grid::GetPointsArray()
{
if(this->Points.empty())
{
return NULL;
}
return &(this->Points[0]);
}
bool Grid::GetPoint(size_t pointId, double coord[3])
{
if(pointId >= this->Points.size()/3)
{
return false;
}
coord[0] = this->Points[pointId];
coord[1] = this->Points[pointId+this->GetNumberOfPoints()];
coord[2] = this->Points[pointId+2*this->GetNumberOfPoints()];
return true;
}
unsigned int* Grid::GetCellPoints(size_t cellId)
{
if(cellId >= this->Cells.size())
{
return NULL;
}
return &(this->Cells[cellId*8]);
}
Attributes::Attributes()
{
this->GridPtr = NULL;
}
void Attributes::Initialize(Grid* grid)
{
this->GridPtr = grid;
}
void Attributes::UpdateFields(double time)
{
size_t numPoints = this->GridPtr->GetNumberOfPoints();
this->Velocity.resize(numPoints*3);
double coord[3] = {0, 0, 0};
for(size_t pt=0;pt<numPoints;pt++)
{
this->GridPtr->GetPoint(pt, coord);
this->Velocity[pt] = coord[1]*time;
}
std::fill(this->Velocity.begin()+numPoints, this->Velocity.end(), 0.);
size_t numCells = this->GridPtr->GetNumberOfCells();
this->Pressure.resize(numCells);
std::fill(this->Pressure.begin(), this->Pressure.end(), 1.);
}
double* Attributes::GetVelocityArray()
{
if(this->Velocity.empty())
{
return NULL;
}
return &this->Velocity[0];
}
float* Attributes::GetPressureArray()
{
if(this->Pressure.empty())
{
return NULL;
}
return &this->Pressure[0];
}

View File

@ -0,0 +1,41 @@
#ifndef FEDATASTRUCTURES_HEADER
#define FEDATASTRUCTURES_HEADER
#include <cstddef>
#include <vector>
class Grid
{
public:
Grid();
void Initialize(const unsigned int numPoints[3], const double spacing[3]);
size_t GetNumberOfPoints();
size_t GetNumberOfCells();
double* GetPointsArray();
bool GetPoint(size_t pointId, double coord[3]);
unsigned int* GetCellPoints(size_t cellId);
private:
std::vector<double> Points;
std::vector<unsigned int> Cells;
};
class Attributes
{
// A class for generating and storing point and cell fields.
// Velocity is stored at the points and pressure is stored
// for the cells. The current velocity profile is for a
// shearing flow with U(y,t) = y*t, V = 0 and W = 0.
// Pressure is constant through the domain.
public:
Attributes();
void Initialize(Grid* grid);
void UpdateFields(double time);
double* GetVelocityArray();
float* GetPressureArray();
private:
std::vector<double> Velocity;
std::vector<float> Pressure;
Grid* GridPtr;
};
#endif

View File

@ -0,0 +1,51 @@
#include "FEDataStructures.h"
#include <mpi.h>
#ifdef USE_CATALYST
#include "FEAdaptor.h"
#endif
// Example of a C++ adaptor for a simulation code
// where the simulation code has a fixed topology
// grid. We treat the grid as an unstructured
// grid even though in the example provided it
// would be best described as a vtkImageData.
// Also, the points are stored in an inconsistent
// manner with respect to the velocity vector.
// This is purposefully done to demonstrate
// the different approaches for getting data
// into Catalyst. Note that through configuration
// that the driver can be run without linking
// to Catalyst.
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
Grid grid;
unsigned int numPoints[3] = {70, 60, 44};
double spacing[3] = {1, 1.1, 1.3};
grid.Initialize(numPoints, spacing);
Attributes attributes;
attributes.Initialize(&grid);
#ifdef USE_CATALYST
FEAdaptor::Initialize(argc, argv);
#endif
unsigned int numberOfTimeSteps = 100;
for(unsigned int timeStep=0;timeStep<numberOfTimeSteps;timeStep++)
{
// use a time step length of 0.1
double time = timeStep * 0.1;
attributes.UpdateFields(time);
#ifdef USE_CATALYST
FEAdaptor::CoProcess(grid, attributes, time, timeStep, timeStep == numberOfTimeSteps-1);
#endif
}
#ifdef USE_CATALYST
FEAdaptor::Finalize();
#endif
MPI_Finalize();
return 0;
}

View File

@ -0,0 +1,86 @@
try: paraview.simple
except: from paraview.simple import *
from paraview import coprocessing
#--------------------------------------------------------------
# Code generated from cpstate.py to create the CoProcessor.
# ----------------------- CoProcessor definition -----------------------
def CreateCoProcessor():
def _CreatePipeline(coprocessor, datadescription):
class Pipeline:
filename_3_pvtu = coprocessor.CreateProducer( datadescription, "input" )
Slice1 = Slice( guiName="Slice1", Crinkleslice=0, SliceOffsetValues=[0.0], Triangulatetheslice=1, SliceType="Plane" )
Slice1.SliceType.Offset = 0.0
Slice1.SliceType.Origin = [34.5, 32.45, 27.95]
Slice1.SliceType.Normal = [1.0, 0.0, 0.0]
ParallelPolyDataWriter1 = coprocessor.CreateWriter( XMLPPolyDataWriter, "slice_%t.pvtp", 10 )
SetActiveSource(filename_3_pvtu)
ParallelUnstructuredGridWriter1 = coprocessor.CreateWriter( XMLPUnstructuredGridWriter, "fullgrid_%t.pvtu", 100 )
return Pipeline()
class CoProcessor(coprocessing.CoProcessor):
def CreatePipeline(self, datadescription):
self.Pipeline = _CreatePipeline(self, datadescription)
coprocessor = CoProcessor()
freqs = {'input': [10, 100]}
coprocessor.SetUpdateFrequencies(freqs)
return coprocessor
#--------------------------------------------------------------
# Global variables that will hold the pipeline for each timestep
# Creating the CoProcessor object, doesn't actually create the ParaView pipeline.
# It will be automatically setup when coprocessor.UpdateProducers() is called the
# first time.
coprocessor = CreateCoProcessor()
#--------------------------------------------------------------
# Enable Live-Visualizaton with ParaView
coprocessor.EnableLiveVisualization(False)
# ---------------------- Data Selection method ----------------------
def RequestDataDescription(datadescription):
"Callback to populate the request for current timestep"
global coprocessor
if datadescription.GetForceOutput() == True:
# We are just going to request all fields and meshes from the simulation
# code/adaptor.
for i in range(datadescription.GetNumberOfInputDescriptions()):
datadescription.GetInputDescription(i).AllFieldsOn()
datadescription.GetInputDescription(i).GenerateMeshOn()
return
# setup requests for all inputs based on the requirements of the
# pipeline.
coprocessor.LoadRequestedData(datadescription)
# ------------------------ Processing method ------------------------
def DoCoProcessing(datadescription):
"Callback to do co-processing for current timestep"
global coprocessor
# Update the coprocessor by providing it the newly generated simulation data.
# If the pipeline hasn't been setup yet, this will setup the pipeline.
coprocessor.UpdateProducers(datadescription)
# Write output data, if appropriate.
coprocessor.WriteData(datadescription);
# Write image capture (Last arg: rescale lookup table), if appropriate.
coprocessor.WriteImages(datadescription, rescale_lookuptable=False)
# Live Visualization, if enabled.
coprocessor.DoLiveVisualization(datadescription, "localhost", 22222)

View File

@ -0,0 +1,120 @@
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCPMappedVectorArrayTemplate.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 vtkCPMappedVectorArrayTemplate - Map native data arrays into
// the vtkDataArray interface.
//
// .SECTION Description
// Map native simulation code data arrays into the vtkDataArray interface.
// This is based on the vtkCPExodusIIResultsArrayTemplate.h class in VTK.
#ifndef vtkCPMappedVectorArrayTemplate_h
#define vtkCPMappedVectorArrayTemplate_h
#include "vtkMappedDataArray.h"
#include "vtkTypeTemplate.h" // For templated vtkObject API
#include "vtkObjectFactory.h" // for vtkStandardNewMacro
template <class Scalar>
class vtkCPMappedVectorArrayTemplate:
public vtkTypeTemplate<vtkCPMappedVectorArrayTemplate<Scalar>,
vtkMappedDataArray<Scalar> >
{
public:
vtkMappedDataArrayNewInstanceMacro(
vtkCPMappedVectorArrayTemplate<Scalar>)
static vtkCPMappedVectorArrayTemplate *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Set the raw scalar arrays for the coordinate set. This class takes
// ownership of the arrays and deletes them with delete[].
void SetVectorArray(Scalar *array, vtkIdType numPoints);
// Reimplemented virtuals -- see superclasses for descriptions:
void Initialize();
void GetTuples(vtkIdList *ptIds, vtkAbstractArray *output);
void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output);
void Squeeze();
vtkArrayIterator *NewIterator();
vtkIdType LookupValue(vtkVariant value);
void LookupValue(vtkVariant value, vtkIdList *ids);
vtkVariant GetVariantValue(vtkIdType idx);
void ClearLookup();
double* GetTuple(vtkIdType i);
void GetTuple(vtkIdType i, double *tuple);
vtkIdType LookupTypedValue(Scalar value);
void LookupTypedValue(Scalar value, vtkIdList *ids);
Scalar GetValue(vtkIdType idx);
Scalar& GetValueReference(vtkIdType idx);
void GetTupleValue(vtkIdType idx, Scalar *t);
// Description:
// This container is read only -- this method does nothing but print a
// warning.
int Allocate(vtkIdType sz, vtkIdType ext);
int Resize(vtkIdType numTuples);
void SetNumberOfTuples(vtkIdType number);
void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source);
void SetTuple(vtkIdType i, const float *source);
void SetTuple(vtkIdType i, const double *source);
void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source);
void InsertTuple(vtkIdType i, const float *source);
void InsertTuple(vtkIdType i, const double *source);
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
vtkAbstractArray *source);
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
vtkAbstractArray* source);
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source);
vtkIdType InsertNextTuple(const float *source);
vtkIdType InsertNextTuple(const double *source);
void DeepCopy(vtkAbstractArray *aa);
void DeepCopy(vtkDataArray *da);
void InterpolateTuple(vtkIdType i, vtkIdList *ptIndices,
vtkAbstractArray* source, double* weights);
void InterpolateTuple(vtkIdType i, vtkIdType id1, vtkAbstractArray *source1,
vtkIdType id2, vtkAbstractArray *source2, double t);
void SetVariantValue(vtkIdType idx, vtkVariant value);
void InsertVariantValue(vtkIdType idx, vtkVariant value);
void RemoveTuple(vtkIdType id);
void RemoveFirstTuple();
void RemoveLastTuple();
void SetTupleValue(vtkIdType i, const Scalar *t);
void InsertTupleValue(vtkIdType i, const Scalar *t);
vtkIdType InsertNextTupleValue(const Scalar *t);
void SetValue(vtkIdType idx, Scalar value);
vtkIdType InsertNextValue(Scalar v);
void InsertValue(vtkIdType idx, Scalar v);
protected:
vtkCPMappedVectorArrayTemplate();
~vtkCPMappedVectorArrayTemplate();
Scalar *Array;
private:
vtkCPMappedVectorArrayTemplate(
const vtkCPMappedVectorArrayTemplate &); // Not implemented.
void operator=(
const vtkCPMappedVectorArrayTemplate &); // Not implemented.
vtkIdType Lookup(const Scalar &val, vtkIdType startIndex);
double TempDoubleArray[3];
};
#include "vtkCPMappedVectorArrayTemplate.txx"
#endif //vtkCPMappedVectorArrayTemplate_h

View File

@ -0,0 +1,499 @@
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCPMappedVectorArrayTemplate.txx
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 "vtkCPMappedVectorArrayTemplate.h"
#include "vtkIdList.h"
#include "vtkObjectFactory.h"
#include "vtkVariant.h"
#include "vtkVariantCast.h"
//------------------------------------------------------------------------------
// Can't use vtkStandardNewMacro with a template.
template <class Scalar> vtkCPMappedVectorArrayTemplate<Scalar> *
vtkCPMappedVectorArrayTemplate<Scalar>::New()
{
VTK_STANDARD_NEW_BODY(vtkCPMappedVectorArrayTemplate<Scalar>)
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::PrintSelf(ostream &os, vtkIndent indent)
{
this->vtkCPMappedVectorArrayTemplate<Scalar>::Superclass::PrintSelf(
os, indent);
os << indent << "Array: " << this->Array << std::endl;
os << indent << "TempDoubleArray: " << this->TempDoubleArray << std::endl;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::Initialize()
{
this->Array = NULL;
this->MaxId = -1;
this->Size = 0;
this->NumberOfComponents = 3;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::GetTuples(vtkIdList *ptIds, vtkAbstractArray *output)
{
vtkDataArray *outArray = vtkDataArray::FastDownCast(output);
if (!outArray)
{
vtkWarningMacro(<<"Input is not a vtkDataArray");
return;
}
vtkIdType numTuples = ptIds->GetNumberOfIds();
outArray->SetNumberOfComponents(this->NumberOfComponents);
outArray->SetNumberOfTuples(numTuples);
const vtkIdType numPoints = ptIds->GetNumberOfIds();
for (vtkIdType i = 0; i < numPoints; ++i)
{
outArray->SetTuple(i, this->GetTuple(ptIds->GetId(i)));
}
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output)
{
vtkDataArray *da = vtkDataArray::FastDownCast(output);
if (!da)
{
vtkErrorMacro(<<"Input is not a vtkDataArray");
return;
}
if (da->GetNumberOfComponents() != this->GetNumberOfComponents())
{
vtkErrorMacro(<<"Incorrect number of components in input array.");
return;
}
for (vtkIdType daTupleId = 0; p1 <= p2; ++p1)
{
da->SetTuple(daTupleId++, this->GetTuple(p1));
}
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::Squeeze()
{
// noop
}
//------------------------------------------------------------------------------
template <class Scalar> vtkArrayIterator*
vtkCPMappedVectorArrayTemplate<Scalar>::NewIterator()
{
vtkErrorMacro(<<"Not implemented.");
return NULL;
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::LookupValue(vtkVariant value)
{
bool valid = true;
Scalar val = vtkVariantCast<Scalar>(value, &valid);
if (valid)
{
return this->Lookup(val, 0);
}
return -1;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::LookupValue(vtkVariant value, vtkIdList *ids)
{
bool valid = true;
Scalar val = vtkVariantCast<Scalar>(value, &valid);
ids->Reset();
if (valid)
{
vtkIdType index = 0;
while ((index = this->Lookup(val, index)) >= 0)
{
ids->InsertNextId(index++);
}
}
}
//------------------------------------------------------------------------------
template <class Scalar> vtkVariant vtkCPMappedVectorArrayTemplate<Scalar>
::GetVariantValue(vtkIdType idx)
{
return vtkVariant(this->GetValueReference(idx));
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::ClearLookup()
{
// no-op, no fast lookup implemented.
}
//------------------------------------------------------------------------------
template <class Scalar> double* vtkCPMappedVectorArrayTemplate<Scalar>
::GetTuple(vtkIdType i)
{
this->GetTuple(i, this->TempDoubleArray);
return this->TempDoubleArray;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::GetTuple(vtkIdType i, double *tuple)
{
tuple[0] = static_cast<double>(this->Array[i]);
tuple[1] = static_cast<double>(this->Array[i+this->GetNumberOfTuples()]);
tuple[2] = static_cast<double>(this->Array[i+2*this->GetNumberOfTuples()]);
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::LookupTypedValue(Scalar value)
{
return this->Lookup(value, 0);
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::LookupTypedValue(Scalar value, vtkIdList *ids)
{
ids->Reset();
vtkIdType index = 0;
while ((index = this->Lookup(value, index)) >= 0)
{
ids->InsertNextId(index++);
}
}
//------------------------------------------------------------------------------
template <class Scalar> Scalar vtkCPMappedVectorArrayTemplate<Scalar>
::GetValue(vtkIdType idx)
{
return this->GetValueReference(idx);
}
//------------------------------------------------------------------------------
template <class Scalar> Scalar& vtkCPMappedVectorArrayTemplate<Scalar>
::GetValueReference(vtkIdType idx)
{
const vtkIdType tuple = idx / this->NumberOfComponents;
const vtkIdType comp = idx % this->NumberOfComponents;
switch (comp)
{
case 0:
return this->Array[tuple];
case 1:
return this->Array[tuple+this->GetNumberOfTuples()];
case 2:
return this->Array[tuple+2*this->GetNumberOfTuples()];
default:
vtkErrorMacro(<< "Invalid number of components.");
static Scalar dummy(0);
return dummy;
}
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::GetTupleValue(vtkIdType tupleId, Scalar *tuple)
{
tuple[0] = this->Array[tupleId];
tuple[1] = this->Array[tupleId+this->GetNumberOfTuples()];
tuple[2] = this->Array[tupleId+2*this->GetNumberOfTuples()];
}
//------------------------------------------------------------------------------
template <class Scalar> int vtkCPMappedVectorArrayTemplate<Scalar>
::Allocate(vtkIdType, vtkIdType)
{
vtkErrorMacro("Read only container.")
return 0;
}
//------------------------------------------------------------------------------
template <class Scalar> int vtkCPMappedVectorArrayTemplate<Scalar>
::Resize(vtkIdType)
{
vtkErrorMacro("Read only container.")
return 0;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetNumberOfTuples(vtkIdType)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetTuple(vtkIdType, vtkIdType, vtkAbstractArray *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetTuple(vtkIdType, const float *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetTuple(vtkIdType, const double *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertTuple(vtkIdType, vtkIdType, vtkAbstractArray *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertTuple(vtkIdType, const float *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertTuple(vtkIdType, const double *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertTuples(vtkIdList *, vtkIdList *, vtkAbstractArray *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertTuples(vtkIdType, vtkIdType, vtkIdType, vtkAbstractArray *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::InsertNextTuple(vtkIdType, vtkAbstractArray *)
{
vtkErrorMacro("Read only container.")
return -1;
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::InsertNextTuple(const float *)
{
vtkErrorMacro("Read only container.")
return -1;
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::InsertNextTuple(const double *)
{
vtkErrorMacro("Read only container.")
return -1;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::DeepCopy(vtkAbstractArray *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::DeepCopy(vtkDataArray *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InterpolateTuple(vtkIdType, vtkIdList *, vtkAbstractArray *, double *)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InterpolateTuple(vtkIdType, vtkIdType, vtkAbstractArray*, vtkIdType,
vtkAbstractArray*, double)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetVariantValue(vtkIdType, vtkVariant)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertVariantValue(vtkIdType, vtkVariant)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::RemoveTuple(vtkIdType)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::RemoveFirstTuple()
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::RemoveLastTuple()
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetTupleValue(vtkIdType, const Scalar*)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertTupleValue(vtkIdType, const Scalar*)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::InsertNextTupleValue(const Scalar *)
{
vtkErrorMacro("Read only container.")
return -1;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetValue(vtkIdType, Scalar)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::InsertNextValue(Scalar)
{
vtkErrorMacro("Read only container.")
return -1;
}
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::InsertValue(vtkIdType, Scalar)
{
vtkErrorMacro("Read only container.")
return;
}
//------------------------------------------------------------------------------
template <class Scalar> vtkCPMappedVectorArrayTemplate<Scalar>
::vtkCPMappedVectorArrayTemplate()
: Array(NULL)
{
}
//------------------------------------------------------------------------------
template <class Scalar> vtkCPMappedVectorArrayTemplate<Scalar>
::~vtkCPMappedVectorArrayTemplate()
{ }
//------------------------------------------------------------------------------
template <class Scalar> void vtkCPMappedVectorArrayTemplate<Scalar>
::SetVectorArray(Scalar *array, vtkIdType numPoints)
{
Initialize();
this->Array = array;
this->NumberOfComponents = 3;
this->Size = this->NumberOfComponents * numPoints;
this->MaxId = this->Size - 1;
this->Modified();
}
//------------------------------------------------------------------------------
template <class Scalar> vtkIdType vtkCPMappedVectorArrayTemplate<Scalar>
::Lookup(const Scalar &val, vtkIdType index)
{
while (index <= this->MaxId)
{
if (this->GetValueReference(index++) == val)
{
return index;
}
}
return -1;
}