[vtkusers] vtkDICOMImageReader and vtkImageShiftScale

Nasos Iliopoulos nasos_i at hotmail.com
Wed Jun 24 11:53:03 EDT 2009


You have a couple of options,
(1) Like in the example in the
previous message, it is generally convenient that when you create an
object (i.e. vtkSphereSource), to keep a pointer (either encapsulated
in a class, or maybe as a global variable (bad!), so that you can just
modify it when you need to.

(2) Another way, but not as
convenient in terms of getting the handle of the objects is by using
getxxx methods. i.e. if you look in the vtkRenderer, there is a method
that returns the list of actors of this renderer:
http://www.vtk.org/doc/nightly/html/classvtkRenderer.html   (look at the method GetActors)
To
use it you have to go through the actors, in the vtkActorCollection and
use their getMapper method to get the mapper. The same thing with
mapper, by using their GetInput() method and so on till you get to the
source. But beyond that point it gets too complicated, because you then
need to be sure you do the correct type casting, so that you get the
object you want (unless of course your pipeline is simple and you can
control it). Another problem of this approach is that you must also
keep track of which actor is which (I am not sure if vtk has a standard
approach for that).

Also, when you call the method Delete(), the
object is NOT deleted, it still exists but it is referenced by another
object, like an actor is referenced from a renderer. When you call the
renderer's delete, it will invoke Delete on all it's actors, and that's
when the memory will be freed (assuming that no other renderer or
object is referencing it). Vtk is using what is called "reference
counting", see 
http://en.wikipedia.org/wiki/Reference_counting
and
http://en.wikipedia.org/wiki/Smart_pointer
so
when you call vtkObject->Delete(), the object's reference count is
decreased by one and the object is only deleted when the reference
count is 0 (i.e. when nothing is using it).

Instead of having to
deal with the delete statements it is highly recommended to use
vtkSmartPointer in combination with (1), that does all the memory
handling almost automatically.

Best
Nasos

> Date: Wed, 24 Jun 2009 11:23:37 -0400
> From: bill.lorensen at gmail.com
> To: alex.dutu at gmail.com
> CC: vtkusers at vtk.org
> Subject: Re: [vtkusers] vtkDICOMImageReader and vtkImageShiftScale
> 
> double range[1];
> should be
> double range[2];
> 
> On Wed, Jun 24, 2009 at 9:14 AM, Alex Duţu<alex.dutu at gmail.com> wrote:
> > Thank you Francois,
> >
> > I have one more problem at scale->SetInputConnection or scale->SetInput. My
> > code looks like this:
> >
> >     vtkDICOMImageReader *dicomReader = vtkDICOMImageReader::New();
> >     dicomReader->SetDirectoryName("D:/MANIX/CER-CT/AVEC I.V");
> >     dicomReader->SetDataScalarTypeToUnsignedShort();
> >     dicomReader->UpdateWholeExtent();
> >     double range[1];
> >     dicomReader->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
> >     //I could have used
> >     //dicomReader->GetOutput()->GetScalarRange(range);
> >
> >     vtkImageShiftScale *scale = vtkImageShiftScale::New();
> >     scale->SetInputConnection(dicomReader->GetOutputPort());
> >     //scale->SetInput(dicomReader->GetOutput());
> >     scale->SetShift(-range[0]);
> >     scale->SetScale(VTK_UNSIGNED_SHORT_MAX/(range[1]-range[0]));
> >     scale->SetOutputScalarTypeToUnsignedShort();
> >     scale->Update();
> >
> > I got this error:
> >
> > Unhandled exception at 0x00594c21 in RayCast.exe: 0xC0000005: Access
> > violation reading location 0x40a7fc34.
> >
> > at
> >
> > int vtkAlgorithm::GetNumberOfOutputPorts()
> > {
> >   return this->OutputPortInformation->GetNumberOfInformationObjects();
> > }
> >
> > and if I used scale->SetInput(dicomReader->GetOutput()); I got:
> >
> > Unhandled exception at 0x0058dae3 in RayCast.exe: 0xC0000005: Access
> > violation reading location 0x40a7fc2c.
> >
> > at
> >
> > int vtkAlgorithm::HasExecutive()
> > {
> >   return this->Executive ? 1 : 0;
> > }
> >
> > Any thoughts?
> >
> > Thanks,
> > Alex
> >
> > _______________________________________________
> > 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
> >
> >
> _______________________________________________
> 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

_________________________________________________________________
Microsoft brings you a new way to search the web.  Try  BingT now
http://www.bing.com?form=MFEHPG&publ=WLHMTAG&crea=TEXT_MFEHPG_Core_tagline_try_bing_1x1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090624/4f21353f/attachment.htm>


More information about the vtkusers mailing list