[vtkusers] correct way of reusing filters in loop

c674332 c674332 at web.de
Mon Jan 12 04:50:36 EST 2009


Thanks, John!

It works now:

vtkThreshold* threshold = vtkThreshold::New();
vtkGeometryFilter* gf = vtkGeometryFilter::New();
vtkAppendPolyData* append = vtkAppendPolyData::New();

threshold->SetInput(ug);
gf->SetInput(threshold->GetOutput());

for(...){
	threshold->ThresholdBetween(*it,*it);
	vtkPolyData* gfOut = vtkPolyData::New();
	gf->SetOutput( gfOut );
	gf->Update();
	gfOut->SetSource(0); // !!!
	append->SetInput(gf->GetOutput());
	
	... 
}
append->Update();




On Fri, 2009-01-09 at 23:51 +0000, John Platt wrote:
> Each time Update() is called within the loop, any previous output from
> the threshold + geometry filters will be cleared. At the end of the loop
> the append filter only has 1 input with data based on the threshold at
> the last iteration.
> 
> If you want to save the output from each iteration, try something like
> 
> for(...){
> 	threshold->ThresholdBetween(*it,*it);
> 	vtkPolyData* gfOut = vtkPolyData::New();
> 	gf->SetOutput( gfOut );
> 	gfOut->Delete();
> 	append->SetInput(gf->GetOutput());
> 	gf->Update();
> 	... 
> }
> 
> At the end of the loop the append filter should have multiple inputs
> with the data from each threshold change saved in all the new gfOut's
> that have been created.
> 
> HTH
> 
> John.
> 
> -----Original Message-----
> From: c674332 at web.de [mailto:c674332 at web.de] 
> Sent: 09 January 2009 18:17
> To: John Platt
> Subject: RE: [vtkusers] correct way of reusing filters in loop
> 
> Hi,
> 
> thanks for your reply! I liked your idea, but it seems that whenever
> creating the pipeline from outside of the loop only the data with the
> first *it will be appended. It seems to be a problem with the append
> filter, because I checked the number of cells in the output of the
> threshold filter and it changed in every loop, same applies to the
> geometry filter.
> 
> Anyway, I am glad you replied because it really helped me understanding
> the pipeline concept of vtk.
> 
> Best wishes

> 
> 
> On Wed, 2009-01-07 at 14:01 +0000, John Platt wrote:
> > Hi,
> > 
> > Try creating the pipeline once only, outside of the loop -
> > 
> > vtkThreshold* threshold = vtkThreshold::New();
> > threshold->SetInput(ug);
> > vtkGeometryFilter* gf = new vtkGeometryFilter::New();
> > gf->SetInput(threshold->GetOutput());
> > vtkAppendPolyData* append = vtkAppendPolyData::New();
> > append->SetInput(gf->GetOutput());
> > 
> > In your loop just change the filter parameters -
> > 
> > for(...){
> > 	threshold->ThresholdBetween(*it,*it);
> > 	append->Update();
> > 	... 
> > }
> > 
> > append->Delete();
> > gf->Delete();
> > threshold->Delete();
> > 
> > 
> > HTH
> > 
> > John.
> > 
> > -----Original Message-----
> > From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On
> > Behalf Of c674
> > Sent: 07 January 2009 11:32
> > To: vtkusers at vtk.org
> > Subject: [vtkusers] correct way of reusing filters in loop
> > 
> > 
> > Hi,
> > 
> > this works fine, but it is slow and messy, because I create new
> > vtkThreshold and vtkGeometryFilter every loop:
> > 
> > vtkAppendPolyData* append = vtkAppendPolyData::New();
> > for(...){
> > vtkThreshold* threshold = vtkThreshold::New();
> > threshold->SetInput(ug);
> > threshold->ThresholdBetween(*it,*it);
> > threshold->Update();
> > vtkGeometryFilter* gf = new vtkGeometryFilter::New();
> > gf->SetInput(threshold->GetOutput());
> > gf->Update();
> > append->SetInput(gf->GetOutput());
> > append->Update();
> > vtkUnstructuredGrid* tug = threshold->GetOutput();
> > if(tug->GetNumberOfCells() < 5) ...
> > ...
> > gf->Delete();
> > threshold->Delete();
> > }
> > 
> > Therefore I would rather do this:
> > 
> > vtkAppendPolyData* append = vtkAppendPolyData::New();
> > vtkThreshold* threshold = vtkThreshold::New();
> > vtkGeometryFilter* gf = vtkGeometryFilter::New();
> > threshold->SetReleaseFlagOn();
> > gf->SetReleaseFlagOn();
> > for(...){
> > threshold->SetInput(ug);
> > threshold->ThresholdBetween(*it,*it);
> > threshold->Update();
> > gf->SetInput(threshold->GetOutput());
> > gf->Update();
> > append->SetInput(gf->GetOutput());
> > append->Update();
> > vtkUnstructuredGrid* tug = threshold->GetOutput();
> > if(tug->GetNumberOfCells() < 5) ...
> > ...
> > tug->Register(0);
> > tug->SetSource(0);
> > tug->Delete();
> > }
> > threshold->Delete();
> > gf->Delete();
> > 
> > But this gives me errors:
> > ERROR: In /build/buildd/vtk-5.0.3/Filtering/vtkImageData.cxx, line
> 1450
> > vtkImageData (0xb52293c8): GetScalarPointer: Pixel (123, 0, 42) not in
> > memory.
> >  Current extent= (0, 49, 0, 49, 0, 49)
> > 
> > and if I only create the threshold every loop I don't get errors, but
> > the
> > results are strange.
> > My guess is, that the results from the former loop are not thrown
> away,
> > but
> > kept and the new results are only added to them or so. How do I reuse
> > these
> > filters correctly?
> > 
> > Thanks in advance!
> > 
> 
> 
> 




More information about the vtkusers mailing list