[vtkusers] question about vtkPolyDataConnectivityFilter

Anja Ende anja.ende at googlemail.com
Sat Apr 5 12:06:31 EDT 2008


Hi Mike,

Thanks for your reply.

I am actually working on writing a plugin for Osirix where I convert a
mask to a Osirix region of Interest.

So,what I need to do is iterate through each of the points for each of
the regions that is returned using the vtkContourFilter and the
vtkPolyDataConnectivityFilter.

So, the code is as follows:

// Contour filter
vtkContourFilter * contourFilter = vtkContourFilter::New();
contourFilter->SetInput(vtkDicomReader->GetOutput());
contourFilter->SetValue(0, 255);

// Pipe output to the polydata filter	
vtkPolyDataConnectivityFilter * polyDataFilter =
vtkPolyDataConnectivityFilter::New();
polyDataFilter->SetInput(contourFilter->GetOutput());
polyDataFilter->SetScalarRange(255.0, 255.0);
polyDataFilter->SetExtractionModeToAllRegions();
polyDataFilter->Update();
polyDataFilter->InitializeSpecifiedRegionList();

// Now I try to iterate over the points and regions
int regions = polyDataFilter->GetNumberOfExtractedRegions();
	
for (int i = 0; i < regions; ++i)
{
	polyDataFilter->AddSpecifiedRegion(i);
	polyDataFilter->Update();		
	// Now we can get the polygons
	vtkPolyData *polyData = polyDataFilter->GetOutput();
	polyData->GetLines()->InitTraversal();
		
	
	int npts, *pts;
	int numCells = polyData->GetLines()->GetNumberOfCells();
	
	while (polyData->GetLines()->GetNextCell(npts,pts))
	{

	}		
}

So, what I want to do in the last loop is to iterate over all the
points in the current cell. However, I do not know how to access it.

I am assuming that the GetNextCell() call somehow sets a pointer to
the next cell. Now, what I want to do is access the vtkPoints contents
for this cell. However, I am not getting anywhere with it.

So, my plan is as follows (in pseudocode):

loop through all the regions
    create the region of interest object
    loop through all the cells
         loop through all the points
                add the points to the region of interest
         end
    end
end


Hope that clarifies a bit.

Anja

On 05/04/2008, Mike Jackson <imikejackson at gmail.com> wrote:
> I am not fully understanding what you are trying to accomplish. If you
>  could post some more details regarding the code you are trying to
>  write and what you would like that code to output the vtk list might
>  be more helpful.
>
>  Mike
>
>
>  On Sat, Apr 5, 2008 at 9:19 AM, Anja Ende <anja.ende at googlemail.com> wrote:
>  > Hi Mike,
>  >
>  >  Thanks for your reply! I did as you had suggested but am having
>  >  problems as follows:
>  >
>  >  int npts, *pts;
>  >  int numCells = polyData->GetLines()->GetNumberOfCells();
>  >  while (polyData->GetLines()->GetNextCell(npts,pts) )
>  >  {
>  >         for (int j = 0; j < npts; ++j)
>  >         {
>  >                 vtkCell * cell = ....
>  >         }
>  >  }
>  >
>  >  How can I now access the current cell. I ran this through the debugger
>  >  and I can see that the number of points returned by GetNextCell() is
>  >  2. However, I am not sure how I can now access these coordinates! Any
>  >  ideas?
>  >
>  >  Thanks,
>  >
>  >  Anja
>  >
>  >
>  >
>  >  On 05/04/2008, Mike Jackson <imikejackson at gmail.com> wrote:
>  >  > You also want to add:
>  >  >
>  >  >  polyDataFilter->SetExtractionModeToAllRegions();
>  >  >
>  >  >  After you run the filter the first time then you will run it in a loop,
>  >  > each time through the loop you set:
>  >  >  for (int i = 0; i < numRegions; ++i)
>  >  >  {
>  >  >  polyDataFilter->InitializeSpecifiedRegionList ()
>  >  >  polyDataFilter->AddSpecifiedRegion (i);
>  >  >  polyDataFilter->SetInput(contourFilter->GetOutput());
>  >  >  polyDataFilter->SetScalarRange(255.0, 255.0);
>  >  >  polyDataFilter->Update();
>  >  >  vtkPolyData* polyData = polYDataFilter->getOUtput();
>  >  >  }
>  >  >
>  >  >  That is only one way and it has been a while since I have had to do
>  >  > something like this. There may be newer/faster ways.
>  >  >
>  >  >  The way we solved it was to re-write the vtkPolYDataConnectivityFilter to
>  >  > actually extract all the regions and store them in a vtkPolyDataCollection.
>  >  > This proved the fastest for us.
>  >  >
>  >  >  Our code can be found here:
>  >  > http://titanium.imts.us/viewvc/Task_4/Mesher/DNAPolyDataConnectivityFilter.cpp?view=log
>  >  > http://titanium.imts.us/viewvc/Task_4/Mesher/DNAPolyDataConnectivityFilter.h?view=log
>  >  >
>  >  >  They may need to be updated for vtk 5.x but you are welcome to use the
>  >  > code.
>  >  >
>  >  >  --
>  >  >  Mike Jackson   Senior Research Engineer
>  >  >  Innovative Management & Technology Services
>  >  >
>  >  >
>  >  >
>  >  >  On Apr 5, 2008, at 7:27 AM, Anja Ende wrote:
>  >  >
>  >  > >
>  >  > > Hi everyone,
>  >  > >
>  >  > > I am using vtkPolyDataConnectivityFilter as follows:
>  >  > >
>  >  > > vtkContourFilter * contourFilter = vtkContourFilter::New();
>  >  > > contourFilter->SetInput(vtkDicomReader->GetOutput());
>  >  > > contourFilter->SetValue(0, 255);
>  >  > >
>  >  > > vtkPolyDataConnectivityFilter * polyDataFilter =
>  >  > > vtkPolyDataConnectivityFilter::New();
>  >  > > polyDataFilter->SetInput(contourFilter->GetOutput());
>  >  > > polyDataFilter->SetScalarRange(255.0, 255.0);
>  >  > > polyDataFilter->Update();
>  >  > >
>  >  > > int regions =
>  >  > polyDataFilter->GetNumberOfExtractedRegions();
>  >  > >
>  >  > > Now what I want to do is iterate through all the regions and each of
>  >  > > the points in the region. However, I cannot figure out how to do this.
>  >  > > Anyone has any idea on how I can iterate through the regions and the
>  >  > > points?
>  >  > >
>  >  > > Cheers,
>  >  > >
>  >  > > Anja
>  >
>  >
>
> >  --
>  >  Cheers,
>  >
>  >  Anja
>  >
>


-- 
Cheers,

Anja



More information about the vtkusers mailing list