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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkInterpolateDataSetAttributes.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 "vtkInterpolateDataSetAttributes.h"
#include "vtkCellData.h"
#include "vtkDataSetCollection.h"
#include "vtkExecutive.h"
#include "vtkGarbageCollector.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkUnstructuredGrid.h"
vtkStandardNewMacro(vtkInterpolateDataSetAttributes);
// Create object with no input or output.
vtkInterpolateDataSetAttributes::vtkInterpolateDataSetAttributes()
{
this->InputList = vtkDataSetCollection::New();
this->T = 0.0;
}
vtkInterpolateDataSetAttributes::~vtkInterpolateDataSetAttributes()
{
if (this->InputList)
{
this->InputList->Delete();
this->InputList = NULL;
}
}
vtkDataSetCollection *vtkInterpolateDataSetAttributes::GetInputList()
{
int i;
this->InputList->RemoveAllItems();
for (i = 0; i < this->GetNumberOfInputConnections(0); i++)
{
this->InputList->AddItem(static_cast<vtkDataSet *>(this->GetExecutive()->GetInputData(0, i)));
}
return this->InputList;
}
// Interpolate the data
int vtkInterpolateDataSetAttributes::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info object
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the ouptut
vtkDataSet *output = vtkDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkIdType numPts, numCells, i;
int numInputs = this->GetNumberOfInputConnections(0);
int lowDS, highDS;
vtkDataSet *ds, *ds2;
vtkPointData *outputPD = output->GetPointData();
vtkCellData *outputCD = output->GetCellData();
vtkPointData *inputPD, *input2PD;
vtkCellData *inputCD, *input2CD;
double t;
if ( numInputs < 2 )
{
vtkErrorMacro(<< "Need at least two inputs to interpolate!");
return 1;
}
vtkDebugMacro(<<"Interpolating data...");
// Check input and determine between which data sets the interpolation
// is to occur.
if ( this->T > static_cast<double>(numInputs) )
{
vtkErrorMacro(<<"Bad interpolation parameter");
return 1;
}
lowDS = static_cast<int>(this->T);
if ( lowDS >= (numInputs-1) )
{
lowDS = numInputs - 2;
}
highDS = lowDS + 1;
t = this->T - static_cast<double>(lowDS);
if (t > 1.0)
{
t =1.0;
}
vtkInformation *dsInfo = inputVector[0]->GetInformationObject(lowDS);
vtkInformation *ds2Info = inputVector[0]->GetInformationObject(highDS);
ds = vtkDataSet::SafeDownCast(dsInfo->Get(vtkDataObject::DATA_OBJECT()));
ds2 = vtkDataSet::SafeDownCast(ds2Info->Get(vtkDataObject::DATA_OBJECT()));
numPts = ds->GetNumberOfPoints();
numCells = ds->GetNumberOfCells();
if ( numPts != ds2->GetNumberOfPoints() ||
numCells != ds2->GetNumberOfCells() )
{
vtkErrorMacro(<<"Data sets not consistent!");
return 1;
}
output->CopyStructure(ds);
inputPD = ds->GetPointData();
inputCD = ds->GetCellData();
input2PD = ds2->GetPointData();
input2CD = ds2->GetCellData();
// Allocate the data set attributes
outputPD->CopyAllOff();
if ( inputPD->GetScalars() && input2PD->GetScalars() )
{
outputPD->CopyScalarsOn();
}
if ( inputPD->GetVectors() && input2PD->GetVectors() )
{
outputPD->CopyVectorsOn();
}
if ( inputPD->GetNormals() && input2PD->GetNormals() )
{
outputPD->CopyNormalsOn();
}
if ( inputPD->GetTCoords() && input2PD->GetTCoords() )
{
outputPD->CopyTCoordsOn();
}
if ( inputPD->GetTensors() && input2PD->GetTensors() )
{
outputPD->CopyTensorsOn();
}
// *TODO* Fix
// if ( inputPD->GetFieldData() && input2PD->GetFieldData() )
//{
// outputPD->CopyFieldDataOn();
//}
outputPD->InterpolateAllocate(inputPD);
outputCD->CopyAllOff();
if ( inputCD->GetScalars() && input2CD->GetScalars() )
{
outputCD->CopyScalarsOn();
}
if ( inputCD->GetVectors() && input2CD->GetVectors() )
{
outputCD->CopyVectorsOn();
}
if ( inputCD->GetNormals() && input2CD->GetNormals() )
{
outputCD->CopyNormalsOn();
}
if ( inputCD->GetTCoords() && input2CD->GetTCoords() )
{
outputCD->CopyTCoordsOn();
}
if ( inputCD->GetTensors() && input2CD->GetTensors() )
{
outputCD->CopyTensorsOn();
}
// *TODO* Fix
//if ( inputCD->GetFieldData() && input2CD->GetFieldData() )
//{
// outputCD->CopyFieldDataOn();
// }
outputCD->InterpolateAllocate(inputCD);
// Interpolate point data. We'll assume that it takes 50% of the time
for ( i=0; i < numPts; i++ )
{
if ( ! (i % 10000) )
{
this->UpdateProgress(static_cast<double>(i)/numPts * 0.50);
if (this->GetAbortExecute())
{
break;
}
}
outputPD->InterpolateTime(inputPD, input2PD, i, t);
}
// Interpolate cell data. We'll assume that it takes 50% of the time
for ( i=0; i < numCells; i++ )
{
if ( ! (i % 10000) )
{
this->UpdateProgress (0.5 + static_cast<double>(i)/numCells * 0.50);
if (this->GetAbortExecute())
{
break;
}
}
outputCD->InterpolateTime(inputCD, input2CD, i, t);
}
return 1;
}
int vtkInterpolateDataSetAttributes::FillInputPortInformation(
int port, vtkInformation *info)
{
if (!this->Superclass::FillInputPortInformation(port, info))
{
return 0;
}
info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
return 1;
}
void vtkInterpolateDataSetAttributes::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "T: " << this->T << endl;
}
//----------------------------------------------------------------------------
void
vtkInterpolateDataSetAttributes
::ReportReferences(vtkGarbageCollector* collector)
{
this->Superclass::ReportReferences(collector);
vtkGarbageCollectorReport(collector, this->InputList, "InputList");
}
|