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
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestvtkAMRInterpolatedVelocityField.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 <vtkAMRInterpolatedVelocityField.h>
#include <vtkAMRGaussianPulseSource.h>
#include <vtkNew.h>
#include <vtkGradientFilter.h>
#include <vtkOverlappingAMR.h>
#include <vtkMath.h>
#include <vtkCompositeDataPipeline.h>
#include "vtkUniformGrid.h"
#define RETURNONFALSE(b)\
if(!(b)) \
{\
vtkAlgorithm::SetDefaultExecutivePrototype(NULL);\
return EXIT_FAILURE;\
}
int TestAMRInterpolatedVelocityField(int, char*[])
{
vtkNew<vtkCompositeDataPipeline> cexec;
vtkAlgorithm::SetDefaultExecutivePrototype(cexec.GetPointer());
char name[100] = "Gaussian-Pulse";
vtkNew<vtkAMRGaussianPulseSource> imageSource;
vtkNew<vtkGradientFilter> gradientFilter;
gradientFilter->SetInputConnection(imageSource->GetOutputPort());
gradientFilter->SetInputScalars( vtkDataObject::FIELD_ASSOCIATION_CELLS,name);
gradientFilter->SetResultArrayName("Gradient");
gradientFilter->Update();
vtkOverlappingAMR* amrGrad = vtkOverlappingAMR::SafeDownCast(gradientFilter->GetOutputDataObject(0));
amrGrad->GenerateParentChildInformation();
for(unsigned int datasetLevel =0; datasetLevel<amrGrad->GetNumberOfLevels(); datasetLevel++)
{
for(unsigned int id=0; id < amrGrad->GetNumberOfDataSets(datasetLevel); id++)
{
vtkUniformGrid* grid = amrGrad->GetDataSet(datasetLevel,id);
int numBlankedCells(0);
for(int i=0; i<grid->GetNumberOfCells();i++)
{
numBlankedCells += grid->IsCellVisible(i)? 0 : 1;
}
cout<<numBlankedCells<<" ";
}
}
cout<<endl;
vtkNew<vtkAMRInterpolatedVelocityField> func;
func->SetAMRData(amrGrad);
func->SelectVectors(vtkDataObject::FIELD_ASSOCIATION_CELLS,"Gradient");
double Points[4][3] =
{{-2.1,-0.51,1},
{-1.9,-0.51,1},
{-0.9,-0.51,1},
{-0.1,-0.51,1}
};
double v[3];
bool res;
unsigned int level, id;
res = func->FunctionValues(Points[0],v)!=0;
RETURNONFALSE(!res);
res = func->FunctionValues(Points[1],v)!=0;
RETURNONFALSE(res);
func->GetLastDataSetLocation(level,id);
RETURNONFALSE(level==1)
res = func->FunctionValues(Points[2],v)!=0;
RETURNONFALSE(res);
func->GetLastDataSetLocation(level,id);
RETURNONFALSE(level==0)
res = func->FunctionValues(Points[3],v)!=0;
RETURNONFALSE(res);
func->GetLastDataSetLocation(level,id);
RETURNONFALSE(level==1)
vtkAlgorithm::SetDefaultExecutivePrototype(NULL);
return EXIT_SUCCESS;
}
|