[vtkusers] correct way of reusing filters in loop

c674 c674332 at web.de
Wed Jan 7 06:32:05 EST 2009


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!

-- 
View this message in context: http://www.nabble.com/correct-way-of-reusing-filters-in-loop-tp21329503p21329503.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list