Commit ae3d4315 authored by Will Schroeder's avatar Will Schroeder

Preparation for reorganization

parent e5c4dd6d
Pipeline #7875 passed with stage
......@@ -23,6 +23,7 @@ vtk_add_test_python(
TestGridSynchronizedTemplates3D.py
TestMarchingSquares.py
TestPointInterpolator.py
TestPointInterpolator2.py
TestProbeFilterImageInput.py
TestRectilinearSynchronizedTemplates.py
TestScalarTrees.py
......
......@@ -70,7 +70,10 @@ outlineActor.SetMapper(outlineMapper)
# Gaussian kernel-------------------------------------------------------
gaussianKernel = vtk.vtkGaussianKernel()
#gaussianKernel = vtk.vtkEllipsoidalGaussianKernel()
gaussianKernel.SetSharpness(4);
#gaussianKernel.UseScalarsOn()
#gaussianKernel.UseNormalsOn()
gaussianKernel.SetSharpness(4)
gaussianKernel.SetRadius(0.25)
interpolator1 = vtk.vtkPointInterpolator()
interpolator1.SetInputConnection(plane.GetOutputPort())
......@@ -105,6 +108,7 @@ outlineActor1.SetMapper(outlineMapper1)
# Shepard kernel-------------------------------------------------------
shepardKernel = vtk.vtkShepardKernel()
shepardKernel.SetPowerParameter(2)
shepardKernel.SetRadius(0.25)
interpolator2 = vtk.vtkPointInterpolator()
interpolator2.SetInputConnection(plane.GetOutputPort())
......
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Interpolate onto a volume
# Parameters for debugging
res = 100
# create pipeline
#
pl3d = vtk.vtkMultiBlockPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()
output = pl3d.GetOutput().GetBlock(0)
# Create a probe volume
center = output.GetCenter()
bounds = output.GetBounds()
length = output.GetLength()
probe = vtk.vtkImageData()
probe.SetDimensions(res,res,res)
probe.SetOrigin(bounds[0],bounds[2],bounds[4])
probe.SetSpacing((bounds[1]-bounds[0])/(res-1),
(bounds[3]-bounds[2])/(res-1),
(bounds[5]-bounds[4])/(res-1))
# Reuse the locator
locator = vtk.vtkStaticPointLocator()
locator.SetDataSet(output)
locator.BuildLocator()
# Use a gaussian kernel------------------------------------------------
gaussianKernel = vtk.vtkGaussianKernel()
gaussianKernel.SetRadius(0.5)
gaussianKernel.SetSharpness(4)
print ("Radius: {0}".format(gaussianKernel.GetRadius()))
interpolator = vtk.vtkPointInterpolator()
interpolator.SetInputData(probe)
interpolator.SetSourceData(output)
interpolator.SetKernel(gaussianKernel)
interpolator.SetLocator(locator)
# Time execution
timer = vtk.vtkTimerLog()
timer.StartTimer()
interpolator.Update()
timer.StopTimer()
time = timer.GetElapsedTime()
print("Interpolate Points (Volume probe): {0}".format(time))
intMapper = vtk.vtkDataSetMapper()
intMapper.SetInputConnection(interpolator.GetOutputPort())
intActor = vtk.vtkActor()
intActor.SetMapper(intMapper)
# Create an outline
outline = vtk.vtkStructuredGridOutlineFilter()
outline.SetInputData(output)
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
# Create the RenderWindow, Renderer and both Actors
#
ren0 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren0)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the renderer, set the background and size
#
ren0.AddActor(intActor)
ren0.AddActor(outlineActor)
ren0.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(250,250)
cam = ren0.GetActiveCamera()
cam.SetClippingRange(3.95297, 50)
cam.SetFocalPoint(8.88908, 0.595038, 29.3342)
cam.SetPosition(-12.3332, 31.7479, 41.2387)
cam.SetViewUp(0.060772, -0.319905, 0.945498)
iren.Initialize()
# render the image
#
renWin.Render()
#iren.Start()
......@@ -32,6 +32,8 @@ vtkEllipsoidalGaussianKernel::vtkEllipsoidalGaussianKernel()
this->Normals = NULL;
this->Scalars = NULL;
this->UseNormals = true;
this->UseScalars = false;
this->F2 = this->Sharpness / this->Radius;
this->E2 = this->Eccentricity * this->Eccentricity;
......@@ -71,7 +73,8 @@ Initialize(vtkAbstractPointLocator *loc, vtkDataSet *ds, vtkPointData *pd)
this->Superclass::Initialize(loc, ds, pd);
this->Scalars = pd->GetScalars();
if ( this->Scalars && this->Scalars->GetNumberOfComponents() == 1 )
if ( this->UseScalars && this->Scalars &&
this->Scalars->GetNumberOfComponents() == 1 )
{
this->Scalars->Register(this);
}
......@@ -81,7 +84,7 @@ Initialize(vtkAbstractPointLocator *loc, vtkDataSet *ds, vtkPointData *pd)
}
this->Normals = pd->GetNormals();
if ( this->Normals )
if ( this->UseNormals && this->Normals )
{
this->Normals->Register(this);
}
......@@ -187,4 +190,8 @@ void vtkEllipsoidalGaussianKernel::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Radius: " << this->Radius << endl;
os << indent << "Sharpness: " << this->Sharpness << endl;
os << indent << "Eccentricity: " << this->Eccentricity << endl;
os << indent << "Use Normals: "
<< (this->UseNormals? "On" : " Off") << "\n";
os << indent << "Use Scalars: "
<< (this->UseScalars? "On" : " Off") << "\n";
}
......@@ -77,6 +77,20 @@ public:
virtual vtkIdType ComputeWeights(double x[3], vtkIdList *pIds,
vtkDoubleArray *weights);
// Description:
// Specify whether vector values should be used to affect the shape
// of the Gaussian distribution. By default this is on.
vtkSetMacro(UseNormals,bool);
vtkGetMacro(UseNormals,bool);
vtkBooleanMacro(UseNormals,bool);
// Description:
// Specify whether scalar values should be used to scale the weights.
// By default this is off.
vtkSetMacro(UseScalars,bool);
vtkGetMacro(UseScalars,bool);
vtkBooleanMacro(UseScalars,bool);
// Description:
// Specify the radius of the kernel. Points within this radius will be
// used for interpolation. If no point is found, then the closest point
......@@ -107,6 +121,9 @@ protected:
double Sharpness;
double Eccentricity;
bool UseNormals;
bool UseScalars;
vtkDataArray *Normals;
vtkDataArray *Scalars;
......
......@@ -20,7 +20,7 @@
//----------------------------------------------------------------------------
vtkInterpolationKernel::vtkInterpolationKernel()
{
this->RequiresInitialization = 1;
this->RequiresInitialization = true;
this->Locator = NULL;
this->DataSet = NULL;
......
......@@ -72,8 +72,9 @@ public:
// member is true, and using classes will invoke Initialize() on the
// kernel. However, if the user takes over initialization manually, then
// set RequiresInitialization to false (0).
vtkSetMacro(RequiresInitialization, int);
vtkGetMacro(RequiresInitialization, int);
vtkSetMacro(RequiresInitialization, bool);
vtkGetMacro(RequiresInitialization, bool);
vtkBooleanMacro(RequiresInitialization, bool);
// Description:
// Given a point x, compute interpolation weights associated with nearby
......@@ -88,7 +89,7 @@ protected:
vtkInterpolationKernel();
~vtkInterpolationKernel();
int RequiresInitialization;
bool RequiresInitialization;
vtkAbstractPointLocator *Locator;
vtkDataSet *DataSet;
vtkPointData *PointData;
......
......@@ -218,6 +218,32 @@ struct ProbePoints
weights->Allocate(128);
}
// When null point is encountered
void AssignNullPoint(const double x[3], vtkIdType numWeights,
vtkIdList *pIds, vtkDoubleArray *weights, vtkIdType ptId)
{
if ( this->Strategy == vtkPointInterpolator::MASK_POINTS)
{
this->Valid[ptId] = 0;
this->OutPD->NullPoint(ptId);
}
else if ( this->Strategy == vtkPointInterpolator::NULL_VALUE)
{
this->OutPD->NullPoint(ptId);
}
else //vtkPointInterpolator::CLOSEST_POINT:
{
numWeights = 1;
pIds->SetNumberOfIds(1);
vtkIdType pId = this->Locator->FindClosestPoint(x);
pIds->SetId(0,pId);
weights->SetNumberOfTuples(1);
weights->SetValue(0,1.0);
this->Arrays.Interpolate(numWeights, pIds->GetPointer(0),
weights->GetPointer(0), ptId);
}
}
// Threaded interpolation method
void operator() (vtkIdType ptId, vtkIdType endPtId)
{
......@@ -231,30 +257,17 @@ struct ProbePoints
this->Input->GetPoint(ptId,x);
numWeights = this->Kernel->ComputeWeights(x, pIds, weights);
if ( numWeights < 1)
if ( numWeights > 0)
{
switch ( this->Strategy )
{
case vtkPointInterpolator::MASK_POINTS:
this->Valid[ptId] = 0;
//purposely fall through to set null value
case vtkPointInterpolator::NULL_VALUE:
this->OutPD->NullPoint(ptId);
continue; //go to next point, jump to end of for loop
default: case vtkPointInterpolator::CLOSEST_POINT:
numWeights = 1;
pIds->SetNumberOfIds(1);
vtkIdType pId = this->Locator->FindClosestPoint(x);
pIds->SetId(0,pId);
weights->SetNumberOfTuples(1);
weights->SetValue(0,1.0);
//purposely fall through to Interpolate()
}
this->Arrays.Interpolate(numWeights, pIds->GetPointer(0),
weights->GetPointer(0), ptId);
}
else
{
this->AssignNullPoint(x, numWeights, pIds, weights, ptId);
}// null point
this->Arrays.Interpolate(numWeights, pIds->GetPointer(0),
weights->GetPointer(0), ptId);
}
}//for all dataset points
}
void Reduce()
......@@ -263,6 +276,72 @@ struct ProbePoints
}; //ProbePoints
// Probe points using an image. Uses a more efficient iteration scheme.
struct ImageProbePoints : public ProbePoints
{
int Dims[3];
double Origin[3];
double Spacing[3];
ImageProbePoints(vtkImageData *image, int dims[3], double origin[3],
double spacing[3], vtkInterpolationKernel *kernel,
vtkAbstractPointLocator *loc, vtkPointData *inPD,
vtkPointData *outPD, int strategy, char *valid) :
ProbePoints(image, kernel, loc, inPD, outPD, strategy, valid)
{
for (int i=0; i < 3; ++i)
{
this->Dims[i] = dims[i];
this->Origin[i] = origin[i];
this->Spacing[i] = spacing[i];
}
}
// Threaded interpolation method specialized to image traversal
void operator() (vtkIdType slice, vtkIdType sliceEnd)
{
double x[3];
vtkIdType numWeights;
double *origin=this->Origin;
double *spacing=this->Spacing;
int *dims=this->Dims;
vtkIdType ptId, jOffset, kOffset, sliceSize=dims[0]*dims[1];
vtkIdList*& pIds = this->PIds.Local();
vtkDoubleArray*& weights = this->Weights.Local();
for ( ; slice < sliceEnd; ++slice)
{
x[2] = origin[2] + slice*spacing[2];
kOffset = slice*sliceSize;
for ( int j=0; j < dims[1]; ++j)
{
x[1] = origin[1] + j*spacing[1];
jOffset = j*dims[0];
for ( int i=0; i < dims[0]; ++i)
{
x[0] = origin[0] + i*spacing[0];
ptId = i + jOffset + kOffset;
numWeights = this->Kernel->ComputeWeights(x, pIds, weights);
if ( numWeights > 0)
{
this->Arrays.Interpolate(numWeights, pIds->GetPointer(0),
weights->GetPointer(0), ptId);
}
else
{
this->AssignNullPoint(x, numWeights, pIds, weights, ptId);
}// null point
}//over i
}//over j
}//over slices
}
}; //ImageProbePoints
} //anonymous namespace
//================= Begin class proper =======================================
......@@ -281,9 +360,9 @@ vtkPointInterpolator::vtkPointInterpolator()
this->ValidPointsMaskArrayName = 0;
this->SetValidPointsMaskArrayName("vtkValidPointMask");
this->PassPointArrays = 1;
this->PassCellArrays = 1;
this->PassFieldArrays = 1;
this->PassPointArrays = true;
this->PassCellArrays = true;
this->PassFieldArrays = true;
}
//----------------------------------------------------------------------------
......@@ -316,10 +395,20 @@ vtkDataObject *vtkPointInterpolator::GetSource()
return this->GetExecutive()->GetInputData(1, 0);
}
//----------------------------------------------------------------------------
void vtkPointInterpolator::
ExtractImageDescription(vtkImageData *input, int dims[3], double origin[3],
double spacing[3])
{
input->GetDimensions(dims);
input->GetOrigin(origin);
input->GetSpacing(spacing);
}
//----------------------------------------------------------------------------
// The driver of the algorithm
void vtkPointInterpolator::Probe(vtkDataSet *input, vtkDataSet *source,
vtkDataSet *output)
void vtkPointInterpolator::
Probe(vtkDataSet *input, vtkDataSet *source, vtkDataSet *output)
{
// Make sure there is a kernel
if ( !this->Kernel )
......@@ -359,9 +448,24 @@ void vtkPointInterpolator::Probe(vtkDataSet *input, vtkDataSet *source,
this->Kernel->Initialize(this->Locator, source, inPD);
}
ProbePoints probe(input,this->Kernel,this->Locator,inPD,outPD,
this->NullPointsStrategy,mask);
vtkSMPTools::For(0, numPts, probe);
// If the input is image data then there is a faster path
vtkImageData *imgInput = vtkImageData::SafeDownCast(input);
if ( imgInput )
{
int dims[3];
double origin[3], spacing[3];
this->ExtractImageDescription(imgInput,dims,origin,spacing);
ImageProbePoints imageProbe(imgInput, dims, origin, spacing,
this->Kernel,this->Locator,inPD,outPD,
this->NullPointsStrategy,mask);
vtkSMPTools::For(0, dims[2], imageProbe);//over slices
}
else
{
ProbePoints probe(input,this->Kernel,this->Locator,inPD,outPD,
this->NullPointsStrategy,mask);
vtkSMPTools::For(0, numPts, probe);
}
// Clean up
if ( mask )
......
......@@ -146,23 +146,23 @@ public:
// Description:
// Shallow copy the input point data arrays to the output.
// On by default.
vtkSetMacro(PassPointArrays, int);
vtkBooleanMacro(PassPointArrays, int);
vtkGetMacro(PassPointArrays, int);
vtkSetMacro(PassPointArrays, bool);
vtkBooleanMacro(PassPointArrays, bool);
vtkGetMacro(PassPointArrays, bool);
// Description:
// Shallow copy the input cell data arrays to the output.
// On by default.
vtkSetMacro(PassCellArrays, int);
vtkBooleanMacro(PassCellArrays, int);
vtkGetMacro(PassCellArrays, int);
vtkSetMacro(PassCellArrays, bool);
vtkBooleanMacro(PassCellArrays, bool);
vtkGetMacro(PassCellArrays, bool);
// Description:
// Indicate whether to pass the field-data arrays from the input to the
// output. On by default.
vtkSetMacro(PassFieldArrays, int);
vtkBooleanMacro(PassFieldArrays, int);
vtkGetMacro(PassFieldArrays, int);
vtkSetMacro(PassFieldArrays, bool);
vtkBooleanMacro(PassFieldArrays, bool);
vtkGetMacro(PassFieldArrays, bool);
protected:
vtkPointInterpolator();
......@@ -175,9 +175,9 @@ protected:
char* ValidPointsMaskArrayName;
vtkCharArray *ValidPointsMask;
int PassCellArrays;
int PassPointArrays;
int PassFieldArrays;
bool PassCellArrays;
bool PassPointArrays;
bool PassFieldArrays;
virtual int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
......@@ -196,6 +196,11 @@ protected:
void PassAttributeData(
vtkDataSet* input, vtkDataObject* source, vtkDataSet* output);
// Description:
// Internal method to extract image metadata
void ExtractImageDescription(vtkImageData *input, int dims[3],
double origin[3], double spacing[3]);
private:
vtkPointInterpolator(const vtkPointInterpolator&); // Not implemented.
void operator=(const vtkPointInterpolator&); // Not implemented.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment