[vtkusers] Add ID to vtkImageActor

Mathieu Coursolle mcoursolle at rogue-research.com
Fri Mar 13 09:35:59 EDT 2009


Hi,

You may want to look at vtkImageMapToColors and
vtkLookupTable to convert your vtkImageData into
a RGBA image for example. You can then change the
vtkLookupTable tableRange and other properties to
change the brightness and contrast.

Thanks,

Mathieu

ps: I added the vtkusers list in Cc. so that other can benefit from  
this discussion.

____________________
Mathieu Coursolle, M.Ing.		
Rogue Research Inc.
www.rogue-research.com



On 13-Mar-09, at 9:02 AM, John Eke wrote:

> Thanks a lot! This worked and has completely taken care of my memory  
> leak problem.
>
> On another note, I was wondering if you could refer me to any vtk  
> image filters that can change image brightness and contrast
>
> Mathieu Coursolle wrote:
>>
>> If you have a fixed number of actors, I guess you could declare an  
>> array:
>>
>> vtkSmartPointer<vtkActor> myArray[20];
>>
>> You could then create your actors:
>>
>> vtkSmartPointer<vtkActor> newActor =  
>> vtkSmartPointer<vtkActor>::New();
>> myArray[idx] = newActor;
>>
>> There is no need to delete it, it is released when its out of scope.
>> Therefore, you should have a reference in your array.
>>
>> To avoid memory leaks, just remove it from your array.
>> myArray[idx] = NULL;
>>
>> Mathieu
>>
>>
>> On 6-Mar-09, at 2:07 PM, John Eke wrote:
>>
>>> I think i spoke too soon, I thought vtkSmartPointer was some sort  
>>> of map. Could you please give me a brief explanation if what I am  
>>> supposed to do.
>>>
>>> Are you saying I should store the IDs and the smart pointers in  
>>> the map, then I can delete the Image Actors?
>>>
>>> - John
>>>
>>> John Eke wrote:
>>>>
>>>> Thanks! I'll try that
>>>>
>>>> Mathieu Coursolle wrote:
>>>>>
>>>>> Have you tried using vtkSmartPointer ? The map will keep a  
>>>>> reference
>>>>> to it. You just need to remove it from the map to release the  
>>>>> reference.
>>>>>
>>>>> Mathieu
>>>>>
>>>>> On 6-Mar-09, at 1:42 PM, John Eke wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Another problem comes up. Here's a code snippet:
>>>>>>
>>>>>>     char images[20];
>>>>>>     //initialize array
>>>>>>     for (int i = 0; i < 20; i++)
>>>>>>     {
>>>>>>         if (image exists)
>>>>>>         {
>>>>>>             vtkPNGReader *pngReader = vtkPNGReader::New();
>>>>>>             vtkImageShiftScale *pShiftScaleFilter =  
>>>>>> vtkImageShiftScale::New();
>>>>>>             pngReader->SetFileName(images[i]);
>>>>>>             pngReader->Update();
>>>>>>
>>>>>>             //Image actor will only display 24bit RGBs
>>>>>>             //image shift scale filter will convert any image  
>>>>>> to this version
>>>>>>             pShiftScaleFilter->SetInputConnection(pngReader- 
>>>>>> >GetOutputPort());
>>>>>>             pShiftScaleFilter->Update();
>>>>>>             pShiftScaleFilter- 
>>>>>> >SetOutputScalarTypeToUnsignedChar();
>>>>>>
>>>>>>             vtkImageActor *pImageActor = vtkImageActor::New();
>>>>>>             m_KeyMap.insert (images[i], pImageActor);//insert  
>>>>>> image file name as its ID in a map, along with a pointer to the  
>>>>>> image actor
>>>>>>             pImageActor->SetInput(pShiftScaleFilter- 
>>>>>> >GetOutput());
>>>>>>
>>>>>>             m_pRenderer->AddActor(pImageActor);
>>>>>>
>>>>>>             //pImageActor->Delete();  //cannot delete since I  
>>>>>> am keeping a reference to it using an external map
>>>>>>             pShiftScaleFilter->Delete();
>>>>>>             pngReader->Delete();
>>>>>>         }
>>>>>>     }
>>>>>>
>>>>>> The problem is all 20 pShiftScaleFilter, and pngReader objects  
>>>>>> that are created inside the loop probably do not get deleted  
>>>>>> since pImageActor never gets deleted. So I get memory leaks
>>>>>>
>>>>>> Is there a better solution? Am I doing something wrong?
>>>>>>
>>>>>> - John
>>>>>>
>>>>>> John Eke wrote:
>>>>>>>
>>>>>>> Thanks a lot, I will try that
>>>>>>>
>>>>>>> Mathieu Coursolle wrote:
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> If I understand correctly, you are trying to easily retrieve  
>>>>>>>> a vtkActor instance based on some key.
>>>>>>>> I usually use a map where the key is a unique ID, and the  
>>>>>>>> value the actual vtkActor.
>>>>>>>> That way I can retrieve quickly the actor associated with a  
>>>>>>>> key. However, this has the inconvenient
>>>>>>>> of maintaining that map to make sure you remove actors which  
>>>>>>>> are deleted, and add newly created
>>>>>>>> actors.
>>>>>>>>
>>>>>>>> Hope this helps,
>>>>>>>>
>>>>>>>> Mathieu
>>>>>>>>
>>>>>>>> ____________________
>>>>>>>> Mathieu Coursolle, M.Ing.
>>>>>>>> Rogue Research Inc.
>>>>>>>> www.rogue-research.com
>>>>>>>>
>>>>>>>> On 6-Mar-09, at 11:02 AM, John Eke wrote:
>>>>>>>>
>>>>>>>>> What I am trying to do is add a string Id as a private  
>>>>>>>>> member to a vtkImageActor. I have a scenario where I am  
>>>>>>>>> inserting multiple vtkImageActors into a renderer... and I  
>>>>>>>>> want to selectively enable and disable them. The only way I  
>>>>>>>>> can forsee doing that is if each image actor had an ID. That  
>>>>>>>>> way I can iterate through the actors, find the one with the  
>>>>>>>>> ID I am looking for, then enable it.
>>>>>>>>>
>>>>>>>>> Is there a better way to do this? If not how can I add the  
>>>>>>>>> ID field to an image actor?
>>>>>>>>>
>>>>>>>>> I hope this clears things up
>>>>>>>>>
>>>>>>>>> - John
>>>>>>>>>
>>>>>>>>> Mathieu Malaterre wrote:
>>>>>>>>>>
>>>>>>>>>> On Fri, Mar 6, 2009 at 4:39 PM, John Eke  
>>>>>>>>>> <johne at annidis.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi Guys,
>>>>>>>>>>>
>>>>>>>>>>> Whats the easiest way to get a vtkImageActor with an ID  
>>>>>>>>>>> field? I tried
>>>>>>>>>>> inheritance, didn't work (maybe I didn't do it right). I  
>>>>>>>>>>> tried creating a
>>>>>>>>>>> replica of vtkImageActor, and renaming it to something  
>>>>>>>>>>> else. But with this,
>>>>>>>>>>> the New() method returns NULL
>>>>>>>>>>>
>>>>>>>>>> I did not quite followed what you are trying to do, but you  
>>>>>>>>>> understand
>>>>>>>>>> that vtkImageActor::New() returns a vtkOpenGLImageActor ?
>>>>>>>>>>
>>>>>>>>>> 2cts
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -- 
>>>>>>>>> INFORMAL COMMUNICATION - The statements within this email  
>>>>>>>>> and attachments if any, may be founded on partial knowledge,  
>>>>>>>>> incorrect information, or incomplete understanding of the  
>>>>>>>>> issues and should not be accorded the probity or status of a  
>>>>>>>>> formal evidentiary deposition.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> CONFIDENTIALITY STATEMENT - This e-mail and  attachments if  
>>>>>>>>> any, may contain confidential or privileged information. If  
>>>>>>>>> you are not the intended recipient, please delete it, notify  
>>>>>>>>> me immediately by reply e-mail, and be advised that you are  
>>>>>>>>> not permitted to read, use, disclose, copy, or distribute it  
>>>>>>>>> or its contents.
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> 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
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> -- 
>>>>>>> INFORMAL COMMUNICATION - The statements within this email and  
>>>>>>> attachments if any, may be founded on partial knowledge,  
>>>>>>> incorrect information, or incomplete understanding of the  
>>>>>>> issues and should not be accorded the probity or status of a  
>>>>>>> formal evidentiary deposition.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> CONFIDENTIALITY STATEMENT - This e-mail and  attachments if  
>>>>>>> any, may contain confidential or privileged information. If  
>>>>>>> you are not the intended recipient, please delete it, notify  
>>>>>>> me immediately by reply e-mail, and be advised that you are  
>>>>>>> not permitted to read, use, disclose, copy, or distribute it  
>>>>>>> or its contents.
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> 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
>>>>>>>
>>>>>>
>>>>>> -- 
>>>>>> INFORMAL COMMUNICATION - The statements within this email and  
>>>>>> attachments if any, may be founded on partial knowledge,  
>>>>>> incorrect information, or incomplete understanding of the  
>>>>>> issues and should not be accorded the probity or status of a  
>>>>>> formal evidentiary deposition.
>>>>>>
>>>>>>
>>>>>>
>>>>>> CONFIDENTIALITY STATEMENT - This e-mail and  attachments if  
>>>>>> any, may contain confidential or privileged information. If you  
>>>>>> are not the intended recipient, please delete it, notify me  
>>>>>> immediately by reply e-mail, and be advised that you are not  
>>>>>> permitted to read, use, disclose, copy, or distribute it or its  
>>>>>> contents.
>>>>>>
>>>>>
>>>>> ____________________
>>>>> Mathieu Coursolle, M.Ing.
>>>>> Rogue Research Inc.
>>>>> www.rogue-research.com
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> INFORMAL COMMUNICATION - The statements within this email and  
>>>> attachments if any, may be founded on partial knowledge,  
>>>> incorrect information, or incomplete understanding of the issues  
>>>> and should not be accorded the probity or status of a formal  
>>>> evidentiary deposition.
>>>>
>>>>
>>>>
>>>> CONFIDENTIALITY STATEMENT - This e-mail and  attachments if any,  
>>>> may contain confidential or privileged information. If you are  
>>>> not the intended recipient, please delete it, notify me  
>>>> immediately by reply e-mail, and be advised that you are not  
>>>> permitted to read, use, disclose, copy, or distribute it or its  
>>>> contents.
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>
>>> -- 
>>> INFORMAL COMMUNICATION - The statements within this email and  
>>> attachments if any, may be founded on partial knowledge, incorrect  
>>> information, or incomplete understanding of the issues and should  
>>> not be accorded the probity or status of a formal evidentiary  
>>> deposition.
>>>
>>>
>>>
>>> CONFIDENTIALITY STATEMENT - This e-mail and  attachments if any,  
>>> may contain confidential or privileged information. If you are not  
>>> the intended recipient, please delete it, notify me immediately by  
>>> reply e-mail, and be advised that you are not permitted to read,  
>>> use, disclose, copy, or distribute it or its contents.
>>>
>>
>> ____________________
>> Mathieu Coursolle, M.Ing.
>> Rogue Research Inc.
>> www.rogue-research.com
>>
>>
>>
>>
>>
>>
>>
>
> -- 
> INFORMAL COMMUNICATION - The statements within this email and  
> attachments if any, may be founded on partial knowledge, incorrect  
> information, or incomplete understanding of the issues and should  
> not be accorded the probity or status of a formal evidentiary  
> deposition.
>
>
>
> CONFIDENTIALITY STATEMENT - This e-mail and  attachments if any, may  
> contain confidential or privileged information. If you are not the  
> intended recipient, please delete it, notify me immediately by reply  
> e-mail, and be advised that you are not permitted to read, use,  
> disclose, copy, or distribute it or its contents.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090313/0bd954e1/attachment.htm>


More information about the vtkusers mailing list