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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkInterpolatedVelocityField.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 "vtkInterpolatedVelocityField.h"
#include "vtkDataSet.h"
#include "vtkGenericCell.h"
#include "vtkObjectFactory.h"
//----------------------------------------------------------------------------
vtkStandardNewMacro( vtkInterpolatedVelocityField );
//----------------------------------------------------------------------------
void vtkInterpolatedVelocityField::AddDataSet( vtkDataSet * dataset )
{
if ( !dataset )
{
return;
}
// insert the dataset (do NOT register the dataset to 'this')
this->DataSets->push_back( dataset );
int size = dataset->GetMaxCellSize();
if ( size > this->WeightsSize )
{
this->WeightsSize = size;
delete[] this->Weights;
this->Weights = new double[size];
}
}
//----------------------------------------------------------------------------
void vtkInterpolatedVelocityField::SetLastCellId( vtkIdType c, int dataindex )
{
this->LastCellId = c;
this->LastDataSet = ( *this->DataSets )[dataindex];
// if the dataset changes, then the cached cell is invalidated
// we might as well prefetch the cached cell either way
if ( this->LastCellId != -1 )
{
this->LastDataSet->GetCell( this->LastCellId, this->GenCell );
}
this->LastDataSetIndex = dataindex;
}
//----------------------------------------------------------------------------
int vtkInterpolatedVelocityField::FunctionValues( double * x, double * f )
{
vtkDataSet * ds;
if(!this->LastDataSet && !this->DataSets->empty())
{
ds = ( *this->DataSets )[0];
this->LastDataSet = ds;
this->LastDataSetIndex = 0;
}
else
{
ds = this->LastDataSet;
}
int retVal = this->FunctionValues( ds, x, f );
if ( !retVal )
{
for( this->LastDataSetIndex = 0;
this->LastDataSetIndex < static_cast<int>( this->DataSets->size() );
this->LastDataSetIndex ++ )
{
ds = this->DataSets->operator[]( this->LastDataSetIndex );
if( ds && ds != this->LastDataSet )
{
this->ClearLastCellId();
retVal = this->FunctionValues( ds, x, f );
if ( retVal )
{
this->LastDataSet = ds;
return retVal;
}
}
}
this->LastCellId = -1;
this->LastDataSetIndex = 0;
this->LastDataSet = (*this->DataSets)[0];
return 0;
}
return retVal;
}
//----------------------------------------------------------------------------
int vtkInterpolatedVelocityField::SnapPointOnCell(double* pOrigin, double* pSnap)
{
if (this->LastDataSet == NULL)
{
return 0;
}
if (!this->FindAndUpdateCell(this->LastDataSet, pOrigin))
{
return 0;
}
double dist2;
this->GenCell->EvaluatePosition
(pOrigin, pSnap, this->LastSubId, this->LastPCoords, dist2, this->Weights);
return 1;
}
//----------------------------------------------------------------------------
void vtkInterpolatedVelocityField::PrintSelf( ostream & os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
}
|