[vtkusers] Exception on vtkImageCacheFilter after modifying the pipeline

Mathieu Malaterre mathieu.malaterre at kitware.com
Fri Apr 23 10:27:23 EDT 2004


Emiliano,

	Thank you for your very detailed bug report. I wish all were just like 
yours :)

	Your suggested changes has been merged in the CVS, and a bug entry has 
been added:

http://vtk.org/Bug/bug.php?op=show&bugid=787

Thank you for your bug report,
Mathieu


Emiliano Beronich wrote:
> Hi all,
> 
> I have a pipeline formed by a vtkImageReader2, a vtkImageResample, a
> vtkMapToColors and a vtkImageCache, connected in this order to show the
> slices of a 3D image.
> This code works well while I change the ZSlice parameter of the
> vtkImageMapper. But when I modify the pipeline, an exception is thrown.
> 
> Reviewing the code of method UpdateData of vtkImageCache, I found that
> the algorithm verifies if the pipeline is still valid. If not, it
> deletes every image generated previous to the time of pipeline. The
> images are deleted but the array Data[i] is not assigned NULL. After
> that an exception is thrown in line 148.
>       ext = this->Data[i]->GetExtent();
> 
> I found a solution to my problem adding the following line to 
> vtkImageCacheFilter.cxx version 1.19
> 
> 136:    if (this->Data[i] && this->Times[i] < pmt)
> 137:      {
> 138:      this->Data[i]->Delete();
> 139:      this->Times[i] = 0;
> 140:      this->Data[i] = NULL;        // added line
> 141:      }
> 
> Is this a bug? am I doing something wrong o missing something? is it a
> known issue?
> I made a simple test program to show the exception.
> 
> Thanks,
> Emiliano
> 
> 
> 
> //--------------------------------------------------------------------------- 
> 
> 
> 
> #include "vtkImageReader2.h"
> #include "vtkImageResample.h"
> #include "vtkImageMapToColors.h"
> #include "vtkImageMapper.h"
> #include "vtkActor2D.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkLookupTable.h"
> #include "vtkImageData.h"
> #include "vtkImageCacheFilter.h"
> #include "vtkPointData.h"
> #include "vtkRenderWindowInteractor.h"
> 
> int main(int argc, char* argv[])
> {
> 
>   vtkImageReader2 * reader = vtkImageReader2::New();
>     reader->ReleaseDataFlagOff();
>     reader->SetDataByteOrderToLittleEndian();
>     reader->SetDataExtent(0, 63, 0, 63, 1, 93);
>     reader->SetDataSpacing(3.2, 3.2, 1.5);
>     char VtkDataRoot[256];
>     strcpy(VtkDataRoot, getenv("VTK_DATA_ROOT"));
>     strcat(VtkDataRoot, "\\Data\\headsq\\quarter");
>     reader->SetFilePrefix(VtkDataRoot);
>     reader->SetNumberOfScalarComponents(1);
>     reader->Update();
> 
>   int Zoom = 4;
>   vtkImageResample * reslice = vtkImageResample::New();
>     reslice->SetInput(reader->GetOutput());
>     reslice->SetAxisMagnificationFactor(0,Zoom);
>     reslice->SetAxisMagnificationFactor(1,Zoom);
> 
>   float range[2];
>   reader->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
>   vtkLookupTable *lut = vtkLookupTable::New();
>     lut->SetTableRange(range[0], range[1]);
>     lut->SetHueRange(0.6667, 0.0);
>     lut->Build();
> 
>   vtkImageMapToColors *color = vtkImageMapToColors::New();
>     color->SetInput(reslice->GetOutput());
>     color->SetOutputFormatToRGB();
>     color->SetLookupTable(lut);
> 
>   vtkImageCacheFilter *cache = vtkImageCacheFilter::New();
>     cache->SetCacheSize(90);
>     cache->SetInput(color->GetOutput());
> 
>   vtkImageMapper *mapper = vtkImageMapper::New();
>     mapper->SetInput(cache->GetOutput());
>     mapper->SetZSlice(12);
>     mapper->SetColorWindow(255);
>     mapper->SetColorLevel(127.5);
> 
>   vtkActor2D *actor = vtkActor2D::New();
>     actor->SetMapper(mapper);
> 
>   vtkRenderer *renderer = vtkRenderer::New();
>     renderer->AddActor(actor);
> 
>   vtkRenderWindow *renderwindow = vtkRenderWindow::New();
>     renderwindow->AddRenderer(renderer);
>     renderwindow->SetSize(64*Zoom, 64*Zoom);
> 
>   renderwindow->Render();
>   for(int j=0; j<5; j++){
>     for(int i=0; i<90; i++){
>       mapper->SetZSlice(i);
>       renderwindow->Render();
>     }
>     //Modify the pipeline after loading images in cache
>     reslice->SetAxisMagnificationFactor(0,Zoom-1);
>     reslice->SetAxisMagnificationFactor(1,Zoom-1);
>     // Next call to UpdateData() of cache will throw an exception
>   }
> 
>   vtkRenderWindowInteractor *interactor =
> vtkRenderWindowInteractor::New();
>   renderwindow->SetInteractor(interactor);
>   interactor->Initialize();
>   interactor->Start();
> 
>   interactor->Delete();
>   renderwindow->Delete();
>   renderer->Delete();
>   lut->Delete();
>   actor->Delete();
>   mapper->Delete();
>   cache->Delete();
>   color->Delete();
>   reslice->Delete();
>   reader->Delete();
>   return 0;
> }
> //--------------------------------------------------------------------------- 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> This is the private VTK discussion list. Please keep messages on-topic. 
> Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 






More information about the vtkusers mailing list