[vtkusers] vtkCellLocator - finding bracketing subids

Dean Inglis dean.inglis at camris.ca
Wed Mar 31 15:26:59 EDT 2010


its a 2D contour (z-coords of all points line in an image plane).
Here is what I have that should work.  I was hoping for an existing
API somewhere in VTK...

// a contour is defined
// get the point wpt nearest the vtkPolyData "contour" by picking or some 
other method
//
  double wpt[3];
  this->CellLocator->SetDataSet( contour );
  this->CellLocator->Update();
  vtkGenericCell* cell = vtkGenericCell::New();
  cell->SetCellTypeToLine();
  vtkIdType cellId = -1;
  int subId = -1;
  double closest[3];
  double dist2;
  this->CellLocator->FindClosestPoint( wpt, closest, cell, cellId, subId, 
dist2 );

if( cellId > -1 && subId > -1 )
{
  if( subId == 0 ) // then we are at the beginning
  {
    // start at the end of the contour, reverse copying points prior to 
subId
    // then add the closest point
    // then add the contour widget's contour
  }
  else if( subId == 
contour->GetLines()->GetNumberOfConnectivityEntries()-1 ) // at the end
  {
    // start at the beginning of the contour, copying points prior to subId
    // then add the closest point
    // then add the contour widget's contour
  }
  else
  {
    int prev = subId-1;
    int next = subId+1;
    int curr = subId;
    double p1[3];
    double p2[3];
    double p3[3];
    vtkPoints* pts = contour->GetPoints();
    pts->GetPoint(prev,p1);
    pts->GetPoint(curr,p2);
    pts->GetPoint(next,p3);

    double l = sqrt( vtkMath::Distance2BetweenPoints( closest, p2 ) );
    double u = l / sqrt( vtkMath::Distance2BetweenPoints( p1, p2 ) );
    double v = l / sqrt( vtkMath::Distance2BetweenPoints( p2, p3 ) );

    if( u < v ) // we are bracketed by prev and curr
    {
      // get the length of the contour going forward up to prev
      // add in the length to closest point
    }
    else // we are bracketed by curr and next
    {
      // get the length of the contour going in revere up to next
      // add in the length to closest point
    }

    // keep the longest length and define the new contour
}


Dean

----- Original Message ----- 
From: "Biddiscombe, John A." <biddisco at cscs.ch>
To: "Dean Inglis" <dean.inglis at camris.ca>; "vtkusers archive" 
<vtkusers at vtk.org>
Sent: Wednesday, March 31, 2010 3:12 PM
Subject: RE: [vtkusers] vtkCellLocator - finding bracketing subids


Dean

I think a picture would help. Is the contour 2D or 3D?

JB

> -----Original Message-----
> From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf
> Of Dean Inglis
> Sent: 31 March 2010 20:57
> To: vtkusers archive
> Subject: [vtkusers] vtkCellLocator - finding bracketing subids
>
> I have a vtkPolyData, a contour generated by vtkContourWidget,
> that I want to pick on and then clip such that the longest part of
> the contour is retained.  I am using vtkCellLocator to get the
> closest point on the contour (which is not necessarily an actual
> point defining the contour) and the cell's (a vtkLine) nearest subId. 
> What
> I want
> is to have the two subIds that define the segment of the contour 
> containing
> the closest point.  For example, an open contour could have 4 points and 
> the
> following cell array indices:
> 0, 1, 2, 3
> and if I pick a location between points 1 and 2, Ill get subId 1 or
> 2 depending on where along that part of the contour I pick, but not
> both.  Anyone know of a way to get the bracketing subIds?
>
> Dean
>
> _______________________________________________
> 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 




More information about the vtkusers mailing list