<div dir="ltr">I played with this for quite a while, but never could get it to work. In the end I made an application specific probe. The code, for others who have the same issue is:<div><br></div><div><div><font face="courier new, monospace">#include <vtkUnstructuredGridReader.h></font></div>
<div><font face="courier new, monospace">#include <vtkPolyData.h></font></div><div><font face="courier new, monospace">#include <vtkUnstructuredGrid.h></font></div><div><font face="courier new, monospace">#include <vtkXMLPolyDataReader.h></font></div>
<div><font face="courier new, monospace">#include <vtkXMLPolyDataWriter.h></font></div><div><font face="courier new, monospace">#include <vtkSmartPointer.h></font></div><div><font face="courier new, monospace">#include <vtkPointData.h></font></div>
<div><font face="courier new, monospace">#include <vtkDoubleArray.h></font></div><div><font face="courier new, monospace">#include <vtkCellLocator.h></font></div><div><font face="courier new, monospace">#include <vtkWedge.h></font></div>
<div><font face="courier new, monospace">#include <vtkCell.h></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">int main(int argc, char **argv)</font></div>
<div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace"> // Read the volume</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkUnstructuredGridReader> volumeReader =</font></div>
<div><font face="courier new, monospace"> vtkSmartPointer<vtkUnstructuredGridReader>::New();</font></div><div><font face="courier new, monospace"> volumeReader->SetFileName("/home/seth/Desktop/volume.vtk");</font></div>
<div><font face="courier new, monospace"> volumeReader->Update();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> // Read the surface</font></div><div>
<font face="courier new, monospace"> vtkSmartPointer<vtkXMLPolyDataReader> polyReader =</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkXMLPolyDataReader>::New();</font></div>
<div><font face="courier new, monospace"> polyReader->SetFileName("/home/seth/Desktop/aligned.vtp");</font></div><div><font face="courier new, monospace"> polyReader->Update();</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> // remove pre-existing array data</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkPolyData> inputSurface = polyReader->GetOutput();</font></div>
<div><font face="courier new, monospace"> unsigned int numberOfArrays = inputSurface->GetPointData()->GetNumberOfArrays();</font></div><div><font face="courier new, monospace"> for (unsigned int i = 0; i < numberOfArrays; ++i)</font></div>
<div><font face="courier new, monospace"> {</font></div><div><font face="courier new, monospace"> inputSurface->GetPointData()->RemoveArray(i);</font></div><div><font face="courier new, monospace"> }</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> std::cout<<"Images Read"<<std::endl;</font></div><div><font face="courier new, monospace"><br></font></div>
<div><font face="courier new, monospace"> // create a new array to hold the data</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkDoubleArray> newArray = vtkSmartPointer<vtkDoubleArray>::New();</font></div>
<div><font face="courier new, monospace"> newArray->SetNumberOfTuples(inputSurface->GetNumberOfPoints());</font></div><div><font face="courier new, monospace"> newArray->SetNumberOfComponents(1);</font></div>
<div><font face="courier new, monospace"> newArray->SetName("Extracted MinPStrain");</font></div><div><font face="courier new, monospace"> inputSurface->GetPointData()->AddArray(newArray);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> // create a cell locator to aid in finding the cells that points belong to</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkCellLocator> cellLocator =</font></div>
<div><font face="courier new, monospace"> vtkSmartPointer<vtkCellLocator>::New();</font></div><div><font face="courier new, monospace"> cellLocator->SetDataSet(volumeReader->GetOutput());</font></div>
<div><font face="courier new, monospace"> cellLocator->BuildLocator();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> // these will be used in the loop to hold data</font></div>
<div><font face="courier new, monospace"> double blankTuple = 0.0;</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkWedge> cCell;</font></div><div><font face="courier new, monospace"> double cPoint[3];</font></div>
<div><font face="courier new, monospace"> double closestPoint[3];</font></div><div><font face="courier new, monospace"> int subId;</font></div><div><font face="courier new, monospace"> double pcoords[3];</font></div>
<div><font face="courier new, monospace"> double dist2;</font></div><div><font face="courier new, monospace"> double weights[6];</font></div><div><font face="courier new, monospace"> double cellData[6];</font></div>
<div><font face="courier new, monospace"> double cValue;</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkIdList> cellPoints;</font></div><div><font face="courier new, monospace"><br></font></div>
<div><font face="courier new, monospace"> // loop through each point in the input surface</font></div><div><font face="courier new, monospace"> for (unsigned int i = 0; i < inputSurface->GetNumberOfPoints(); ++i)</font></div>
<div><font face="courier new, monospace"> {</font></div><div><font face="courier new, monospace"> // get the point location</font></div><div><font face="courier new, monospace"> inputSurface->GetPoint(i,cPoint);</font></div>
<div><font face="courier new, monospace"> // find the cell that contains the point</font></div><div><font face="courier new, monospace"> vtkIdType cCellNo = cellLocator->FindCell(cPoint);</font></div><div>
<font face="courier new, monospace"> if (cCellNo == -1) // if the point is outside of cells, enter a value of zero in the data array</font></div><div><font face="courier new, monospace"> {</font></div><div>
<font face="courier new, monospace"> inputSurface->GetPointData()->GetArray(0)->SetTuple(i,&blankTuple);</font></div><div><font face="courier new, monospace"> continue;</font></div><div>
<font face="courier new, monospace"> }</font></div><div><font face="courier new, monospace"> // get the point IDs that define the containing cell</font></div><div><font face="courier new, monospace"> cellPoints = volumeReader->GetOutput()->GetCell(cCellNo)->GetPointIds();</font></div>
<div><font face="courier new, monospace"> // get the strain values for each point in the containing cell</font></div><div><font face="courier new, monospace"> cellData[0] = *volumeReader->GetOutput()->GetPointData()->GetArray(0)->GetTuple(cellPoints->GetId(0));</font></div>
<div><font face="courier new, monospace"> cellData[1] = *volumeReader->GetOutput()->GetPointData()->GetArray(0)->GetTuple(cellPoints->GetId(1));</font></div><div><font face="courier new, monospace"> cellData[2] = *volumeReader->GetOutput()->GetPointData()->GetArray(0)->GetTuple(cellPoints->GetId(2));</font></div>
<div><font face="courier new, monospace"> cellData[3] = *volumeReader->GetOutput()->GetPointData()->GetArray(0)->GetTuple(cellPoints->GetId(3));</font></div><div><font face="courier new, monospace"> cellData[4] = *volumeReader->GetOutput()->GetPointData()->GetArray(0)->GetTuple(cellPoints->GetId(4));</font></div>
<div><font face="courier new, monospace"> cellData[5] = *volumeReader->GetOutput()->GetPointData()->GetArray(0)->GetTuple(cellPoints->GetId(5));</font></div><div><font face="courier new, monospace"> // use the EvaluatePosition method of the cell to get the interpolation function weight values. The rest of the data is not used</font></div>
<div><font face="courier new, monospace"> volumeReader->GetOutput()->GetCell(cCellNo)->EvaluatePosition(cPoint,closestPoint,subId,pcoords,dist2,weights);</font></div><div><font face="courier new, monospace"> // calculate the value at the point by multiplying each weight by the data</font></div>
<div><font face="courier new, monospace"> cValue = cellData[0]*weights[0] + cellData[1]*weights[1] + cellData[2]*weights[2] + cellData[3]*weights[3] + cellData[4]*weights[4] + cellData[5]*weights[5];</font></div><div>
<font face="courier new, monospace"> // set the data.</font></div><div><font face="courier new, monospace"> inputSurface->GetPointData()->GetArray(0)->SetTuple(i,&cValue);</font></div><div><font face="courier new, monospace"> }</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> // write the probed surface out</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkXMLPolyDataWriter> polyWirter =</font></div>
<div><font face="courier new, monospace"> vtkSmartPointer<vtkXMLPolyDataWriter>::New();</font></div><div><font face="courier new, monospace"> polyWirter->SetInput(inputSurface);</font></div><div><font face="courier new, monospace"> polyWirter->SetFileName("/home/seth/Desktop/testProbe.vtp");</font></div>
<div><font face="courier new, monospace"> polyWirter->Write();</font></div><div><font face="courier new, monospace">}</font></div></div></div><div class="gmail_extra"><br clear="all"><div><i>Seth Gilchrist, MASc, PhD Candidate<br>
<span style="font-family:courier new,monospace">+---------------------------------------+</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">Orthopaedic and Injury Biomechanics Group<br>
UBC Department of Mechanical Engineering</span><span style="font-family:courier new,monospace"></span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">6th Floor-2635 Laurel Street</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Vancouver, BC V5Z-1M9<br></span><span style="font-family:courier new,monospace">+---------------------------------------+<br><a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a><br>
Fax 604-675-2576</span></i><br></div>
<br><br><div class="gmail_quote">On Thu, May 23, 2013 at 12:08 PM, Seth Gilchrist <span dir="ltr"><<a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Hello all,</div><div>I'm having a problem with the vtkProbeFilter. I have a vtkUnstructuredGrid volume with one data field called MinPStrain and I am trying to probe it with a vtkPolyData surface. The output indicates that the two interact in only a very small portion of the surface, when in reality they almost completely overlap.</div>
<div><br></div><div>There are some screen shots at: <a href="https://plus.google.com/photos/101839812291734892344/albums/5881253191058882961?authkey=CIOdsYjQi8zKjQE" target="_blank">https://plus.google.com/photos/101839812291734892344/albums/5881253191058882961?authkey=CIOdsYjQi8zKjQE</a></div>
<div><br></div><div>On the left is the surface and volume in their actual positions. On the right is the output of the probe, translated so that it can be viewed.</div><div><br></div><div>Most recently I have tried using the vtkAppendFilter to convert the vtkPolyData to a vtkUnstructuredGrid, but to no avail. The latest code is:</div>
<div><br></div><div><div><font face="courier new, monospace">#include <vtkUnstructuredGridReader.h></font></div><div><font face="courier new, monospace">#include <vtkXMLUnstructuredGridWriter.h></font></div>
<div><font face="courier new, monospace">#include <vtkPolyData.h></font></div><div><font face="courier new, monospace">#include <vtkUnstructuredGrid.h></font></div><div><font face="courier new, monospace">#include <vtkXMLPolyDataReader.h></font></div>
<div><font face="courier new, monospace">#include <vtkXMLPolyDataWriter.h></font></div><div><font face="courier new, monospace">#include <vtkProbeFilter.h></font></div><div><font face="courier new, monospace">#include <vtkSmartPointer.h></font></div>
<div><font face="courier new, monospace">#include <vtkAppendFilter.h></font></div><div><font face="courier new, monospace">#include <vtkPointData.h></font></div><div><font face="courier new, monospace"><br></font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">int main(int argc, char **argv)</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace"> // Read the volume</font></div>
<div><font face="courier new, monospace"> vtkSmartPointer<vtkUnstructuredGridReader> volumeReader =</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkUnstructuredGridReader>::New();</font></div>
<div><font face="courier new, monospace"> volumeReader->SetFileName("/home/seth/Desktop/volume.vtk");</font></div><div><font face="courier new, monospace"> volumeReader->Update();</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"> // Read the surface</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkXMLPolyDataReader> polyReader =</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkXMLPolyDataReader>::New();</font></div>
<div><font face="courier new, monospace"> polyReader->SetFileName("/home/seth/Desktop/aligned.vtp");</font></div><div><font face="courier new, monospace"> polyReader->Update();</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"> // remove pre-existing array data</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkPolyData> inputSurface = polyReader->GetOutput();</font></div>
<div><font face="courier new, monospace"> unsigned int numberOfArrays = inputSurface->GetPointData()->GetNumberOfArrays();</font></div><div><font face="courier new, monospace"> for (unsigned int i = 0; i < numberOfArrays; ++i)</font></div>
<div><font face="courier new, monospace"> {</font></div><div><font face="courier new, monospace"> inputSurface->GetPointData()->RemoveArray(i);</font></div><div><font face="courier new, monospace"> }</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> std::cout<<"Images Read"<<std::endl;</font></div><div><font face="courier new, monospace"><br></font></div>
<div><font face="courier new, monospace"> // convert the surface from vtkPolyData to vtkUnstructuredGrid</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkAppendFilter> appender =</font></div>
<div><font face="courier new, monospace"> vtkSmartPointer<vtkAppendFilter>::New();</font></div><div><font face="courier new, monospace"> appender->SetInput(inputSurface);</font></div><div><font face="courier new, monospace"> appender->Update();</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> // probe the volume with the surface</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkProbeFilter> probe =</font></div>
<div><font face="courier new, monospace"> vtkSmartPointer<vtkProbeFilter>::New();</font></div><div><font face="courier new, monospace"> probe->SetInput(appender->GetOutput());</font></div><div><font face="courier new, monospace"> probe->SetSource(volumeReader->GetOutput());</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> // write the probed surface out</font></div><div><font face="courier new, monospace"> vtkSmartPointer<vtkXMLUnstructuredGridWriter> polyWirter =</font></div>
<div><font face="courier new, monospace"> vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();</font></div><div><font face="courier new, monospace"> polyWirter->SetInputConnection(probe->GetOutputPort());</font></div>
<div><font face="courier new, monospace"> polyWirter->SetFileName("/home/seth/Desktop/testProbe.vtu");</font></div><div><font face="courier new, monospace"> polyWirter->Write();</font></div><div><font face="courier new, monospace">}</font></div>
</div></div>
</blockquote></div><br></div>