1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractDataOverTime.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 "vtkExtractDataOverTime.h"
#include "vtkPointSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkDoubleArray.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkExtractDataOverTime);
//----------------------------------------------------------------------------
vtkExtractDataOverTime::vtkExtractDataOverTime()
{
this->NumberOfTimeSteps = 0;
this->CurrentTimeIndex = 0;
this->PointIndex = 0;
}
//----------------------------------------------------------------------------
void vtkExtractDataOverTime::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Point Index: " << this->PointIndex << endl;
os << indent << "NumberOfTimeSteps: " << this->NumberOfTimeSteps << endl;
}
//----------------------------------------------------------------------------
int vtkExtractDataOverTime::RequestInformation(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
if ( inInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_STEPS()) )
{
this->NumberOfTimeSteps =
inInfo->Length( vtkStreamingDemandDrivenPipeline::TIME_STEPS() );
}
else
{
this->NumberOfTimeSteps = 0;
}
// The output of this filter does not contain a specific time, rather
// it contains a collection of time steps. Also, this filter does not
// respond to time requests. Therefore, we remove all time information
// from the output.
vtkInformation* outInfo = outputVector->GetInformationObject(0);
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_STEPS()))
{
outInfo->Remove(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
}
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_RANGE()))
{
outInfo->Remove(vtkStreamingDemandDrivenPipeline::TIME_RANGE());
}
return 1;
}
//----------------------------------------------------------------------------
int vtkExtractDataOverTime::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
{
return this->RequestInformation(request, inputVector, outputVector);
}
else if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
// get the requested update extent
double *inTimes = inputVector[0]->GetInformationObject(0)
->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
if (inTimes)
{
double timeReq = inTimes[this->CurrentTimeIndex];
inputVector[0]->GetInformationObject(0)->Set
( vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP(),
timeReq);
}
return 1;
}
// generate the data
else if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
if (this->NumberOfTimeSteps == 0)
{
vtkErrorMacro("No Time steps in input time data!");
return 0;
}
// get the output data object
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkPointSet *output =
vtkPointSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
// and input data object
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkPointSet *input =
vtkPointSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
// is this the first request
if (!this->CurrentTimeIndex)
{
// Tell the pipeline to start looping.
request->Set(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING(), 1);
this->AllocateOutputData(input, output);
}
// extract the actual data
output->GetPoints()->SetPoint( this->CurrentTimeIndex,
input->GetPoints()->GetPoint(this->PointIndex) );
output->GetPointData()->CopyData(input->GetPointData(), this->PointIndex,
this->CurrentTimeIndex);
if (input->GetPointData()->GetArray("Time"))
{
output->GetPointData()->GetArray("TimeData")->SetTuple1
(this->CurrentTimeIndex,
input->GetInformation()->Get(vtkDataObject::DATA_TIME_STEP()));
}
else
{
output->GetPointData()->GetArray("Time")->SetTuple1
(this->CurrentTimeIndex,
input->GetInformation()->Get(vtkDataObject::DATA_TIME_STEP()));
}
// increment the time index
this->CurrentTimeIndex++;
if (this->CurrentTimeIndex == this->NumberOfTimeSteps)
{
// Tell the pipeline to stop looping.
request->Remove(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING());
this->CurrentTimeIndex = 0;
}
return 1;
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
int vtkExtractDataOverTime::AllocateOutputData(vtkPointSet *input, vtkPointSet *output)
{
// by default vtkPointSetAlgorithm::RequestDataObject already
// created an output of the same type as the input
if (!output)
{
vtkErrorMacro("Output not created as expected!");
return 0;
}
// 1st the points
vtkPoints *points = output->GetPoints();
if (!points)
{
points = vtkPoints::New();
output->SetPoints( points );
points->Delete();
}
points->SetNumberOfPoints( this->NumberOfTimeSteps );
// now the point data
output->GetPointData()->CopyAllocate(input->GetPointData(), this->NumberOfTimeSteps);
// and finally add an array to hold the time at each step
vtkDoubleArray *timeArray = vtkDoubleArray::New();
timeArray->SetNumberOfComponents(1);
timeArray->SetNumberOfTuples(this->NumberOfTimeSteps);
if (input->GetPointData()->GetArray("Time"))
{
timeArray->SetName("TimeData");
}
else
{
timeArray->SetName("Time");
}
output->GetPointData()->AddArray(timeArray);
timeArray->Delete();
return 1;
}
|