[vtk-developers] [vtkusers] Loss of precision vtkCutter with vtkPlanes with vtk 5.10.1 - Reposting

David Gobbi david.gobbi at gmail.com
Thu Feb 14 15:29:26 EST 2013


Hi Remy,

So you have a half-sphere, and you have a vtkPlane that is _exactly_
lined up with the face of the sphere, and you want a vtkCutter to
return that face of the sphere to you?  You cannot expect this to work
robustly.  You should _always_ include a tolerance for numerical
errors.

In VTK 5.10 and earlier versions of VTK, nearly all VTK polydata filters
and nearly all VTK polydata sources will only generate single-precision
floats as output, regardless of the precision of the input (the situation
has improved somewhat in the code that will become VTK 6.0.)
That is why the precision is less than you expected.  However, for
your code to work you would need the results to be _exact_.  Even
double precision cannot provide that.  Always allow for a small amount
of error.

 - David


On Thu, Feb 14, 2013 at 10:08 AM, Rémy Trichet
<remy.trichet at zimmercas.com> wrote:
> I tried to post on vtkusers but had no success yet, so I am trying on
> vtk-developers.
>
>
>
> Remy
>
>
>
> From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf
> Of Rémy Trichet
> Sent: Wednesday, February 13, 2013 11:44 AM
> To: vtkusers at vtk.org
> Subject: [vtkusers] Loss of precision vtkCutter with vtkPlanes with vtk
> 5.10.1
>
>
>
> Hi,
>
>
>
> I am trying to use a vtkCutter with vtkPlanes as CutFunction, and then get
> the output.
>
> I set a vtkPlane with a normal (0.0, 0.0, 1.0) and an origin of (-1.0, -1.0,
> 0.5).
>
> My source is half a sphere centered on (-1.0,-1.0,0.5) and with z > 0.5.
>
> When I do the cut, and try to get the output, this is empty.
>
> I try to cut the entire sphere instead of only a half with the same vtkPlane
> and get the output (with vtkPolyData::GetPoint(i)) and
>
> I see that the resulting points have a z = 0.49999999046325684 instead of
> 0.5, which explains that the output is empty when I use half the sphere.
>
> I am only using doubles and the vtk methods I am calling return also
> doubles, so I am wondering why this happens, and if I am doing something
> wrong?
>
>
>
> Here is the sample  :
>
>
>
>    vtkSmartPointer<vtkPlane> plane3 = vtkSmartPointer<vtkPlane>::New();
>
>    plane3->SetNormal(0.0,0.0,1.0);
>
>    plane3->SetOrigin(-1.0,-1.0, 0.5);
>
>    vtkSmartPointer<vtkSTLReader> roiModelReader =
>
>       vtkSmartPointer<vtkSTLReader>::New();
>
>    roiModelReader->SetFileName("HalfSphere.stl");
>
>    roiModelReader->Update();
>
>    vtkSmartPointer<vtkCutter> cutterForROI =
>
>       vtkSmartPointer<vtkCutter>::New();
>
>    cutterForROI->SetInputConnection(roiModelReader->GetOutputPort());
>
>
>
>    cutterForROI->SetCutFunction(plane3);
>
>    cutterForROI->Update();
>
>    vtkPointSet* dataSet = cutterForROI->GetOutput();
>
>    int nbrPoints = dataSet->GetNumberOfPoints(); // = 0 with half the sphere
>
>    double* point;
>
>    for(int i = 0; i<nbrPoints; ++i)
>
>       {
>
>          point = dataSet->GetPoint(i); // point[2] = 0. 0.49999999046325684
> when using the whole sphere
>
>       }
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Remy Trichet



More information about the vtk-developers mailing list