Is vtkprobefilter working correctly ? Here is an example to test…

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Is vtkprobefilter working correctly ? Here is an example to test…

foufara
Hi VTK devs !

First thing first, thank you for this amazing tool I'm using every day. :-)

For quite a long time I've been wondering if vtkprobefilter is working correctly in every case.

Here an example with an extraction of a 3D mesh that I want to probe with 2 points.
vtkprobefilter works on one of these points only.
I read in detail the source code of vtkprobefilter and tried to reproduce it in python without calling the filter itself but every object and method it uses.

But I don't get the same results !

On point 0, vtkprobefilter fails but I find a cell on the 12th walk
On point 1, vtkprobefilter does find a cell, but I don't, unless I go until the 27th walk

Normaly 12 is the max number of walks in vtk (hard coded). Can it change from one installation to another ? (I used pip)

So I really don't understand why I don't get the same results ?

Besides, even when it or I find a cell, you'll notice that the point in not necessarily in the cell per se because of the warp aspect of the cell. But let's say it does not matter for now (although if you know ho to find the cell that really contains the point, please tell me !)

Here is a link to my data (.vtk file, very light) and a python script which compares both methods.
The script outputs several data to vtk files that you can open in paraview.
Everything should be straightforward to understand.

https://drive.google.com/open?id=0B2Fplxt079XmenF5b1FGemg4VW8

Please can anyone have a look at it and help me understand what's wrong ?

If I'm not clear please tell me !

Thank you !

Raphaël
Reply | Threaded
Open this post in threaded view
|

Re: Is vtkprobefilter working correctly ? Here is an example to test…

foufara
H again,

I updated the script I was talking about in my last post with a test with vtkcelllocator.

vtkcelllocator works fine on this example.

But that somehow surprises me since it seems to me that my "homemade vtkprobefilter" version does exactly the same thing :
- a call vtkPointLocator to locate the closest point
- a call to data.GetPointCells to get all the cells using that point
- and then visiting these cells and their neighbors and calling evaluateposition each time to determine if my point lies inside the cell or to identify the best neighbor to visit. with a maximum walk number of 12.

So why would my version not give the same results ?
And why would vtkprobefilter fail in the first place ? (if I'm right, vtkprobefilter is essentially a wrapper around the same operations…)

Thank you in advance for your help !

Reply | Threaded
Open this post in threaded view
|

Re: Is vtkprobefilter working correctly ? Here is an example to test…

foufara
Hi it's me again ! :-)

No one can help me on that ?

Here is this time a Cxx example.

To sum it up, vtkprobefilter and vtkcelllocator do not give the same results on this example and that does not seem right to me…

I'll be debugging it to see what happens.
But if you already have the explanation, please et me know !

Thanks

Raphael


#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDataSet.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "vtkDataSetReader.h"
#include "vtkProbeFilter.h"
#include "vtkPointLocator.h"
#include "vtkCellLocator.h"
#include "vtkIdList.h"
#include "vtkPolyDataWriter.h"


int main()
{
   
    std::cout << "DEBUGRAPHA : Debug1" << "\n "<<std::endl;
   
   
   
    double point1[3] = {-312.,-1407.,37.};
    double point2[3] = {-312.,-1407.,57.};
   
    // 2 Points to probe with
    vtkPoints* points = vtkPoints::New();
    vtkIdType nextPoint1 = points->InsertNextPoint(point1);
    vtkIdType nextPoint2 = points->InsertNextPoint(point2);  
    vtkPolyData* polydata = vtkPolyData::New();
    polydata->SetPoints(points);

    std::cout << "Points" <<std::endl;
    std::cout << "Point 1 : " << point1[0] << " " << point1[1] << " " << point1[2] << std::endl;    
    std::cout << "Point 2 : " << point2[0] << " " << point2[1] << " " << point2[2] << std::endl;    
    std::cout << "\n" << std::endl;    
   
    //Writing the points to vtk file
    vtkPolyDataWriter* writer1 = vtkPolyDataWriter::New();
    writer1->SetInputData(polydata);
    writer1->SetFileName("polydata.vtk");
    writer1->Write();
   
    // 3D Data to probe
    vtkDataSetReader *reader = vtkDataSetReader::New();
    reader->SetFileName("extraction.vtk");
    reader->Update();
    vtkDataSet* data=reader->GetOutput();
   
    // Probing
    vtkProbeFilter* probe = vtkProbeFilter::New();
    probe->SetInputData(polydata);
    probe->SetSourceData(data);
    probe->Update();
    vtkDataSet* result=probe->GetOutput();
   
    // Results probing
    vtkPointData* pointData = result->GetPointData();
    vtkDataArray* valid = pointData->GetArray("vtkValidPointMask");
    vtkDataArray* cellid = pointData->GetArray("ID");    

    std::cout << "Probing" <<std::endl;
    std::cout << "Valid : " << valid->GetTuple1(0) << " " << valid->GetTuple1(1) << std::endl;        
    std::cout << "ID : " << cellid->GetTuple1(0) << " " << cellid->GetTuple1(1) << std::endl;            
    std::cout << "\n" << std::endl;


    // CellLocator
    vtkIdType cellids[2];
    vtkCellLocator* locator=vtkCellLocator::New();
    locator->SetDataSet(data);
    locator->BuildLocator();
    for (int i=0; i<polydata->GetNumberOfPoints(); i++)
    {
        cellids[i]=locator->FindCell(polydata->GetPoint(i));
    }
    std::cout << "CellLocator" <<std::endl;    
    std::cout << "ID : " << cellids[0] << " " << cellids[1] << std::endl;            

    return 0;
}


Reply | Threaded
Open this post in threaded view
|

Re: Is vtkprobefilter working correctly ? Here is an example to test…

Ken Martin
Unless I am missing something in your question, probing and locating cells are two different things. I would expect them to have different results. Probing interpolates, locators don't. From the documentation of the two classes...

vtkProbeFilter is a filter that computes point attributes (e.g., scalars,
 * vectors, etc.) at specified point positions. The filter has two inputs:
 * the Input and Source. The Input geometric structure is passed through the
 * filter. The point attributes are computed at the Input point positions
 * by interpolating into the source data. For example, we can compute data
 * values on a plane (plane specified as Input) from a volume (Source).
 * The cell data of the source data is copied to the output based on in
 * which source cell each input point is. If an array of the same name exists
 * both in source's point and cell data, only the one from the point data is
 * probed.
 *
 * This filter can be used to resample data, or convert one dataset form into
 * another. For example, an unstructured grid (vtkUnstructuredGrid) can be
 * probed with a volume (three-dimensional vtkImageData), and then volume
 * rendering techniques can be used to visualize the results. Another example:
 * a line or curve can be used to probe data to produce x-y plots along
 * that line or curve.

Versus

 * vtkCellLocator is a spatial search object to quickly locate cells in 3D.
 * vtkCellLocator uses a uniform-level octree subdivision, where each octant
 * (an octant is also referred to as a bucket) carries an indication of
 * whether it is empty or not, and each leaf octant carries a list of the
 * cells inside of it. (An octant is not empty if it has one or more cells
 * inside of it.)  Typical operations are intersection with a line to return
 * candidate cells, or intersection with another vtkCellLocator to return
 * candidate cells.



On Tue, May 9, 2017 at 2:48 AM, foufara via vtk-developers <[hidden email]> wrote:
Hi it's me again ! :-)

No one can help me on that ?

Here is this time a Cxx example.

To sum it up, vtkprobefilter and vtkcelllocator do not give the same results
on this example and that does not seem right to me…

I'll be debugging it to see what happens.
But if you already have the explanation, please et me know !

Thanks

Raphael


#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDataSet.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "vtkDataSetReader.h"
#include "vtkProbeFilter.h"
#include "vtkPointLocator.h"
#include "vtkCellLocator.h"
#include "vtkIdList.h"
#include "vtkPolyDataWriter.h"


int main()
{

    std::cout << "DEBUGRAPHA : Debug1" << "\n "<<std::endl;



    double point1[3] = {-312.,-1407.,37.};
    double point2[3] = {-312.,-1407.,57.};

    // 2 Points to probe with
    vtkPoints* points = vtkPoints::New();
    vtkIdType nextPoint1 = points->InsertNextPoint(point1);
    vtkIdType nextPoint2 = points->InsertNextPoint(point2);
    vtkPolyData* polydata = vtkPolyData::New();
    polydata->SetPoints(points);

    std::cout << "Points" <<std::endl;
    std::cout &lt;&lt; &quot;Point 1 : &quot; &lt;&lt; point1[0] &lt;&lt;
&quot; &quot; &lt;&lt; point1[1] &lt;&lt; &quot; &quot; &lt;&lt; point1[2]
&lt;&lt; std::endl;
    std::cout &lt;&lt; &quot;Point 2 : &quot; &lt;&lt; point2[0] &lt;&lt;
&quot; &quot; &lt;&lt; point2[1] &lt;&lt; &quot; &quot; &lt;&lt; point2[2]
&lt;&lt; std::endl;
    std::cout &lt;&lt; &quot;\n&quot; &lt;&lt; std::endl;

    //Writing the points to vtk file
    vtkPolyDataWriter* writer1 = vtkPolyDataWriter::New();
    writer1->SetInputData(polydata);
    writer1->SetFileName("polydata.vtk");
    writer1->Write();

    // 3D Data to probe
    vtkDataSetReader *reader = vtkDataSetReader::New();
    reader->SetFileName("extraction.vtk");
    reader->Update();
    vtkDataSet* data=reader->GetOutput();

    // Probing
    vtkProbeFilter* probe = vtkProbeFilter::New();
    probe->SetInputData(polydata);
    probe->SetSourceData(data);
    probe->Update();
    vtkDataSet* result=probe->GetOutput();

    // Results probing
    vtkPointData* pointData = result->GetPointData();
    vtkDataArray* valid = pointData->GetArray("vtkValidPointMask");
    vtkDataArray* cellid = pointData->GetArray("ID");

    std::cout << "Probing" <<std::endl;
    std::cout &lt;&lt; &quot;Valid : &quot; &lt;&lt; valid->GetTuple1(0) <<
" " << valid->GetTuple1(1) << std::endl;
    std::cout << "ID : " << cellid->GetTuple1(0) << " " <<
cellid->GetTuple1(1) << std::endl;
    std::cout << "\n" << std::endl;


    // CellLocator
    vtkIdType cellids[2];
    vtkCellLocator* locator=vtkCellLocator::New();
    locator->SetDataSet(data);
    locator->BuildLocator();
    for (int i=0; i<polydata->GetNumberOfPoints(); i++)
    {
        cellids[i]=locator->FindCell(polydata->GetPoint(i));
    }
    std::cout << "CellLocator" <<std::endl;
    std::cout << "ID : " << cellids[0] << " " << cellids[1] << std::endl;

    return 0;
}






--
View this message in context: http://vtk.1045678.n5.nabble.com/Is-vtkprobefilter-working-correctly-Here-is-an-example-to-test-tp5743104p5743147.html
Sent from the VTK - Dev mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




--
Ken Martin PhD
Distinguished Engineer
Kitware Inc.
28 Corporate Drive
Clifton Park NY 12065

This communication, including all attachments, contains confidential and legally privileged information, and it is intended only for the use of the addressee.  Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution or any action taken in reliance on it is prohibited and may be unlawful. If you received this communication in error please notify us immediately and destroy the original message.  Thank you.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: Is vtkprobefilter working correctly ? Here is an example to test…

foufara
Hi Ken,

thank you for your answer.
I'm really flattered to get an answer from one of the fathers of VTK (right ?) whose book lies on my desk ! :-)

I realize I could have been more clearer on what I intend to do.
I want indeed interpolate from one dataset to another, from the source point or cell data to the input points.
For that purpose vtkprobefilter seems perfect.
I also understand that the interpolation will be different whether the data are point or cell located on the source :
- for pointdata, it will be interpolation based on the parametric coordinates of the input points in the cells that contain them
- for celldata it will just be passing cell values to the input points contained in them…

Please correct me if I'm wrong so far…

However I notice that on some occasions vtkprobefilter fails while it should not (according to me)

So I though I can get the same celldata "interpolation" using vtkcellLocator to identify which cell contains each input point and then passing manually the right values from the source cells to the input points.

And doing that I realize that vtkcellLocator does find the "right" cells where vtkprobeFilter fails.
So I don't expect here to get the same results in terms of interpolated data (at least when we deal with point data, since cell data should be treated the same way here, right ?) but in terms of which cell is found to contain each input point.

The example I joined in a previous post (in python and then C++) shows that the cells identified are different (vtkprobefilter fails but vtkcelllocator don't). Check the prints.

What surprises me is that, by reading the vtk code, it seemed to me that about the same functions were called by each filter (vtkpointlocator to identify the closest point in the source, then FindCell and FindCellWalk for each cell using the points, etc.).

I'm trying to "debug" (I'm sure it's not really bugged") each filter to understand where the difference arises. But I'm not used to C++ (see my other post : "Best way to add a print in a distribution file ?").

Finaly, I wrote earlier "find the "right" cells" because in my example the source cells are "warp hexa" (built from warp quadrangles). So the cell found to contain a point by either vtkprobefilter (when it works) or vtkcellLocator is not necessarily the cell that physically contains the point. You'll see it if you run the python version of my example and check the outputs in paraview. But I don't know if I can do better.

Well I hope I'm clearer now, and not too long :-)

Thank you for you help on that.

Raphaël