[vtkusers] vtkCutter doesn't return cells that are totally inside the cutting vtkPlane

Dan Asimov dan.asimov at gmail.com
Fri Sep 17 11:10:46 EDT 2010


Hi Bill,

Thanks again for the detailed reply! Unfortunately, none can help me in my
problem. I was sending a simplified version of my problem. My whole problem
is that I have multiple 2D contours in parallel to each others in one
vtkpolydata. I want to cut the contours with a plane. If the plane is
exactly the plane of one of these 2D contours, the cut should return this
exact 2D contour. Else, it should return the intersection points between the
plane and the lines that connects the 2D contours. I was hoping vtkCutter
will do the job and I won't need to divide the problem into two steps (one
for the in-plane and one for the intersection).


Also, I'm not expert, but I don't think it's the float imprecision problem
here! When I debug the code inside the vtk classes, it all stops in
vtkTriangle::Contour. The vtkpolydata points are evaluated with the Evalute
function of the plane (this works nicely as expected, with scalar value = 0
for the three points) then the points are passed to vtkTriangle::Contour.

The first thing this function does is to build a case table with the
following for loop

static int CASE_MASK[3] = {1,2,4};
// Build the case table
  for ( i=0, index = 0; i < 3; i++)
    {
    if (cellScalars->GetComponent(i,0) >= value)
      {
      index |= CASE_MASK[i];
      }
    }

Basically, if the index is 7 it ignore this cell at all. However, if the
three points are evaluated to be on the plane (i.e. value=0), index will be
essentially 7!! So, I believe this is done intentionally, maybe for reasons
related to contouring the intersected points.

what do you think?

Thanks!


On Fri, Sep 17, 2010 at 8:10 AM, Bill Lorensen <bill.lorensen at gmail.com>wrote:

> Dan,
>
> I misunderstood your question. The cutting plane is infinitesimally
> thin so it would be difficult to extract those points via clipping.
> Also, both clipping and cutting introduce new points. I can think of 3
> ways to do this (there may be more):
>
> 1) Define a thin hexahedral cell that contains the plane. Then use
> vtkSelectEnclosedPoints.
> 2) Use vtkPlaneSource to define the plane. Then loop through all of
> the points and use the quad's EvaluatePosition to determine
> inside/outside. This will probably be slow.
> 3) Loop over all points and compute the distance to the plane using
> the plane equation. Retain those points that are within a tolerance of
> 0.
>
>
> Bill
> .
> On Thu, Sep 16, 2010 at 4:47 PM, Dan Asimov <dan.asimov at gmail.com> wrote:
> > Hi Bill,
> >
> > Thanks for the reply!
> >
> > I already tried this but vtkClipPolydata will return all the points on
> one
> > side of the cutting plane. I need the points inside the cutting plane
> only.
> >
> > For ex: if I move the origin of the cutting plane to
> >
> > pPlane->SetOrigin(0,0,-0.1);
> >
> > then vtkClipPolydata will return five points (the two cutting points and
> the
> > three points in the x-y plane). However, vtkCutter will return only the
> two
> > cutting points.
> >
> > what do you think?
> >
> > Thanks!
> >
> >
> > On Thu, Sep 16, 2010 at 2:33 PM, Bill Lorensen <bill.lorensen at gmail.com>
> > wrote:
> >>
> >> You want vtkClipPolydata rather than vtkCutter.
> >>
> >> On Thu, Sep 16, 2010 at 11:29 AM, Dan Asimov <dan.asimov at gmail.com>
> wrote:
> >> > Hi,
> >> >
> >> > I'm new to vtk. So, forgive me for my simple question!
> >> >
> >> > I'm trying to use vtkCutter on a vtkPolydata to get all the points
> >> > inside a
> >> > specific plane. However, it seems vtkCutter doesn't return any cell
> that
> >> > lies completely inside the cutting plane!
> >> >
> >> > Here is a very simple example in C++:
> >> >
> >> > //Adding some points (3 of them in the x-y plane)
> >> > vtkPoints *pPoints = vtkPoints::New();
> >> > pPoints->InsertNextPoint(1,0,-0.5);
> >> > pPoints->InsertNextPoint(0,1,0);
> >> > pPoints->InsertNextPoint(-1,0,0);
> >> > pPoints->InsertNextPoint(0,-1,0);
> >> >
> >> > vtkPolyData *pPolydata = vtkPolyData::New();
> >> > pPolydata->SetPoints(pPoints);
> >> >
> >> > vtkPolygon *pPolygon = vtkPolygon::New();
> >> > pPolygon->GetPointIds()->SetNumberOfIds(4);
> >> > for (int i=0;i<4;i++)
> >> > {
> >> >     pPolygon->GetPointIds()->SetId(i,i);
> >> > }
> >> > pPolydata->Allocate(1,1);
> >> >
> >> >
> pPolydata->InsertNextCell(pPolygon->GetCellType(),pPolygon->GetPointIds());
> >> >
> >> > // The cutting plane is the x-y plane
> >> > vtkPlane *pPlane = vtkPlane::New();
> >> > pPlane->SetOrigin(0,0,0);
> >> > pPlane->SetNormal(0,0,1);
> >> >
> >> > // Cut
> >> > vtkCutter *pCutter = vtkCutter::New();
> >> > pCutter->SetCutFunction(pPlane);
> >> > pCutter->SetInput(pPolydata);
> >> > pCutter->Update();
> >> > vtkPolyData *pCutterOutput = pCutter->GetOutput();
> >> >
> >> > vtkPoints *Pts = pCutterOutput->GetPoints();
> >> > int nPts = Pts->GetNumberOfPoints();
> >> >
> >> > now, the pCutterOutput contains only two points (0,1,0) & (0,-1,0). I
> >> > was
> >> > expecting it will contain also (-1,0,0) since it's in the same plane
> >> > (x-y
> >> > plane). Am I missing something??
> >> >
> >> > Thanks for your help!
> >> >
> >> >
> >> > _______________________________________________
> >> > Powered by www.kitware.com
> >> >
> >> > Visit other Kitware open-source projects at
> >> > http://www.kitware.com/opensource/opensource.html
> >> >
> >> > Please keep messages on-topic and check the VTK FAQ at:
> >> > http://www.vtk.org/Wiki/VTK_FAQ
> >> >
> >> > Follow this link to subscribe/unsubscribe:
> >> > http://www.vtk.org/mailman/listinfo/vtkusers
> >> >
> >> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100917/e38702c8/attachment.htm>


More information about the vtkusers mailing list