[Insight-users] ITK in Paraview Plugin

Christian Werner christian.werner at rwth-aachen.de
Sat Feb 27 05:23:30 EST 2010


Hmm, the vtkITKImageBox does contain instantiations for ALL pixel types. 
This is because I have to make sure that I create a correkt itk 
ImageType for each vtkImageData input (1-3 Scalar Components, 1-3 
Dimensions, 10 different Scalar Types). That image box is about 9 MB 
big, but it is a shared library anyway...

The filters who use this box however also include code that checks the 
vtkImageData and setup an appropriate ImageType. Then they instantiate a 
corresponding ImageBox<ImageType>. Maybe this way the compiler generates 
all different kind of class headers for the vtkITKImageBox, but I don't 
see how this could justify 7MB...

Since I am not a professional programmer I don't know much about "Modern 
C++ programming", or generic programming. I had problems with the linker 
telling me about not finding any reference to specific template 
functions, because the compiler did not instantiate them. So I just 
brutally "forced" the compiler to make all instantiations (actually 
instanitiate each class type and call all its methods explicitly in some 
dummy code). I think what I am missing here is some understanding about 
how to do that dynamically... ?
On the other hand I have to decide at runtime what ImageType I need for 
the ITK Filtering because I don't know what vtkImageData I get as input. 
So this verification has to be implemented in every single filter and 
the appropriate functions with the corresponding ImageType from the 
vtkITKImageBox have to exist at this point.

If you take a look at my code you will see what I mean. The good thing 
is that I can use Gaetans Labling/Analysis filtering right out of 
Paraview now for any kind of image data, and that is what I needed. I 
actually don't care if it is this big, though I really would have liked 
to create something more professional. But since this is only a very 
tiny little part of my work, which already took much more time then 
planned, I cannot sacrifice more time on that.

If you (or maybe somebody else) knows how to improve that, please tell 
me. I could dive into this again when I have made progress in my actual 
project and won back some of the time.


Best regards,
Christian




Luis Ibanez wrote:
> Hi Christian,
>
> Thanks for letting us know.
>
> The size of the filter seems to be large indeed.
>
> Does it include instantiations for several different pixel types ?
>
> As a reference, a typical executable example of ITK is about 300K.
> (when using a single pixel type).
>
> The VolviewPlugins, on the other hand range in size from
> 1Mb to 5.3Mb. (They include instantiation for 9 different pixel
> types).
>
> If you run them through "strip" they get about 25% to 30% smaller.
> (e.g. a pluging whose shared library was 2.7M gets down to 2.0Mb).
>
> --
>
> BTW: You mention some code, I seem to have missed your
> email with an attachment, or with instructions on how to download
> it.  If the code is available, I will be happy to give it a try.
>
>
>
>       Regards,
>
>
>              Luis
>
>
> ---------------------------------------------
> On Thu, Feb 25, 2010 at 4:36 PM, Christian Werner
> <christian.werner at rwth-aachen.de> wrote:
>   
>> It works now when I use TARGET_LINK_LIBRARIES, I just did not do it
>> correctly (I did not provide the lib that is actually build!). Strange
>> though that the compiler did not seem to care.
>>
>> There is one issue which is still somewhat annoying. Every Paraview-ITK
>> filter is now very big (like 7MB). I do not understand why, but that is
>> really huuuuge! I tried reducing this by moving all the exporter/importer
>> related code from the ImageBox header into the .cxx code, but that just made
>> a difference of a view hundred byte.! It didn't work this way either...
>>
>> This is really strange, I was so happy that I was able to make the
>> vtkITKImageBox a shared library and thought that would reduce the size of
>> the plugins to "normal" levels. In a VTK-only environment these filters get
>> as big, by the way.
>>
>> Maybe if you take a look at the code I sent you, you can make out the reason
>> for this? I am not sure if the commutiy is glad about being able to easily
>> use ITK Filters in Paraview-Plugins when they are this big...
>>
>>
>> Best regards,
>> Christian
>>
>>
>>
>> Luis Ibanez wrote:
>>     
>>> Hi Christian,
>>>
>>>    Thanks for sharing the good news.
>>>
>>> You are doing very interesting work,
>>> it will be really useful to see it described
>>> in a IJ paper, or a paper in "The Source"
>>> newsletter.
>>>
>>> ---
>>>
>>> Regarding LINK_LIBRARIES(): when you
>>> use this CMake command, you add a list of
>>> libraries to the link line of all the targets.
>>>
>>> If using LINK_LIBRARIES fixed the problem, then
>>> it might be that there was a target in your project
>>> for which the ITKCommon library was missing.
>>>
>>>
>>> It will be great to figure this out, because the
>>> command LINK_LIBRARIES was deprecated
>>> in CMake 2.6.4, and the recommended command
>>> to use is TARGET_LINK_LIBRARIES.
>>>
>>>
>>> ...a CMake Guru will be of great help here...
>>>
>>> You may want to post the question to the CMake
>>> users list.
>>>
>>>
>>>     Regards,
>>>
>>>
>>>            Luis
>>>
>>>
>>> ------------------------------------------------------------
>>> On Thu, Feb 25, 2010 at 4:57 AM, Christian Werner
>>> <christian.werner at rwth-aachen.de> wrote:
>>>
>>>       
>>>> Luis, you led me to the right direction. Good news, everything works
>>>> fine!
>>>> By chance I found some cmake related postings where there was some
>>>> problem
>>>> with the LINK_LIBRARIES variable. I was like "Gee, this variable looks
>>>> nice!
>>>> It could replace my TARGET_LINK_LIBRARIES which does not work anyway."
>>>> And
>>>> voila, everything goes. This is what I put into my CMakeList that made
>>>> Paraview execute my cool plugin (a itkFlipImageFilter :)
>>>>
>>>> LINK_LIBRARIES( vtkITKImageBox
>>>>  ITKCommon ITKIO ITKBasicFilters
>>>> )
>>>>
>>>> I know, diving a little bit more into CMake would have helped in the
>>>> first
>>>> place, but you just can't study everything before getting your work done.
>>>>
>>>> What's a bit strange is that the plugin is very big (7MB). I am afraid
>>>> that
>>>> the vtkITKImageBox (which is about that big), or even some ITK stuff is
>>>> cramped into the filter despite my efforts to link everything
>>>> dynamically. I
>>>> will try to find a solution to this.
>>>>
>>>>
>>>> Thanks for your help with everything Luis and best regards,
>>>> Christian
>>>>
>>>>
>>>>
>>>>
>>>> Christian Werner wrote:
>>>>
>>>>         
>>>>> I am afraid I did. My vtkITKImageBox was build as a shared library, too
>>>>> and this was only possible after rebuilding ITK with shared libraries.
>>>>>
>>>>> Somehow, if you put that
>>>>>
>>>>> ADD_PARAVIEW_PLUGIN(SampleImageFilter "1.0"
>>>>> SERVER_MANAGER_XML SampleImageFilter.xml
>>>>> #GUI_RESOURCE_FILES SampleImageFilterGUI.xml
>>>>> SERVER_MANAGER_SOURCES vtkITKSampleImageFilter.cxx
>>>>> )
>>>>>
>>>>> into your CMakeList, the compiler does not really seem to care about
>>>>> which
>>>>> libraries it has to compile against. It makes no difference for the
>>>>> compiling and linking process. I do not even have to mention my
>>>>> vtkITKImageBox library which is clearly needed by my filter.
>>>>>
>>>>> So these libraries oviously have to be available "globally" when
>>>>> paraview
>>>>> runs. I added the ITK library path to the LD_LIBRARY_PATH, which I think
>>>>> is
>>>>> the place where ParaView looks for shared libraries but that did not
>>>>> help.
>>>>>
>>>>> I asked the guys form ParaView too about that. If everything works fine
>>>>> and I have the time I could write a paper about my Paraview-ITK
>>>>> Filtering.
>>>>>
>>>>> Best regards,
>>>>> Christian
>>>>>
>>>>>
>>>>> Luis Ibanez wrote:
>>>>>
>>>>>           
>>>>>> Hi Christian,
>>>>>>
>>>>>>
>>>>>>  Did you build ITK as a Shared library ?
>>>>>>
>>>>>>
>>>>>> ---
>>>>>>
>>>>>> BTW: This  VERY interesting, you should
>>>>>> consider writing a paper for the Insight Journal   :-)
>>>>>>
>>>>>>          http://www.insight-journal.org
>>>>>>
>>>>>>
>>>>>>    Regards,
>>>>>>
>>>>>>
>>>>>>          Luis
>>>>>>
>>>>>>
>>>>>> -------------------------------------------------------
>>>>>> On Wed, Feb 24, 2010 at 1:38 PM, Christian Werner
>>>>>> <christian.werner at rwth-aachen.de> wrote:
>>>>>>
>>>>>>
>>>>>>             
>>>>>>> Hello!
>>>>>>>
>>>>>>> I wrote a nice VTK filter that incorporates ITK filters. It works fine
>>>>>>> in a
>>>>>>> VTK-only environment. I was able to compile it as a ParaView plugin
>>>>>>> but
>>>>>>> when
>>>>>>> I want to use it, I get an error messages which seems to indicate some
>>>>>>> missing ITK library or something:
>>>>>>>
>>>>>>> Attempting to load
>>>>>>> /home/christian/.paraview-plugins/libSampleImageFilter.so
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>>>>> Failed to load the shared library.
>>>>>>>> /home/christian/.paraview-plugins/libSampleImageFilter.so: undefined
>>>>>>>> symbol:
>>>>>>>> _ZN3itk11LightObject6DeleteEv
>>>>>>>>
>>>>>>>>
>>>>>>>>                 
>>>>>>> I attached my CMakeList.txt. There's no
>>>>>>>
>>>>>>> TARGET_LINK_LIBRARIES(
>>>>>>>  ITKCommon ITKIO
>>>>>>>  vtkCommon vtkIO
>>>>>>> )
>>>>>>>
>>>>>>> or such in my CMakeList, but that does not seem to be a problem
>>>>>>> anyway.
>>>>>>> Everthing is compiled and linked just fine.
>>>>>>>
>>>>>>> Anyway, I tried
>>>>>>>
>>>>>>> TARGET_LINK_LIBRARIES(   vtkITKImageBox   #my library
>>>>>>>  ITKBasicFilters
>>>>>>> )
>>>>>>>
>>>>>>> or similar. But that turned into a cmake error:
>>>>>>>
>>>>>>> CMake Error at CMakeLists.txt:16 (TARGET_LINK_LIBRARIES):
>>>>>>>  Cannot specify link libraries for target "vtkITKImageBox" which is
>>>>>>> not
>>>>>>>  built by this project.
>>>>>>>
>>>>>>> whereas ommitting one of the above libraries, e.g. writing:
>>>>>>>
>>>>>>> TARGET_LINK_LIBRARIES(   vtkITKImageBox
>>>>>>> )
>>>>>>>
>>>>>>> works just fine. On the other hand it seems to be totally unnecessary
>>>>>>> to
>>>>>>> do
>>>>>>> anything like that, because always everything compiles just fine, as
>>>>>>> long as
>>>>>>> cmake ran succesful. When I compile for VTK-only it won't compile if I
>>>>>>> do
>>>>>>> not add my library that I actually need for this filter...
>>>>>>>
>>>>>>> What do I have do write into my CMakeList??
>>>>>>>
>>>>>>>
>>>>>>> Best regards,
>>>>>>> Christian
>>>>>>>
>>>>>>>
>>>>>>> # create a paraview plugin containing server manager xml and the
>>>>>>> server
>>>>>>> # manager classes to build
>>>>>>> # this plugin can be loaded on the server side
>>>>>>>
>>>>>>> cmake_minimum_required(VERSION 2.4)
>>>>>>>
>>>>>>> PROJECT(vtkITKSampleImageFilter)
>>>>>>>
>>>>>>> INCLUDE("/home/christian/programming/pv-plugins/conf.cmake")
>>>>>>>
>>>>>>> #find and load ParaView settings
>>>>>>> FIND_PACKAGE(ParaView REQUIRED)
>>>>>>> INCLUDE(${PARAVIEW_USE_FILE})
>>>>>>>
>>>>>>> # Find ITK & VTK
>>>>>>> FIND_PACKAGE(ITK REQUIRED)
>>>>>>> INCLUDE(${ITK_USE_FILE})
>>>>>>>
>>>>>>>
>>>>>>> ADD_PARAVIEW_PLUGIN(SampleImageFilter "1.0"
>>>>>>>  SERVER_MANAGER_XML SampleImageFilter.xml
>>>>>>>  #GUI_RESOURCE_FILES SampleImageFilterGUI.xml
>>>>>>>  SERVER_MANAGER_SOURCES vtkITKSampleImageFilter.cxx
>>>>>>> )
>>>>>>>
>>>>>>> _____________________________________
>>>>>>> Powered by www.kitware.com
>>>>>>>
>>>>>>> Visit other Kitware open-source projects at
>>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>>
>>>>>>> Kitware offers ITK Training Courses, for more information visit:
>>>>>>> http://www.kitware.com/products/protraining.html
>>>>>>>
>>>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>>>
>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>> _____________________________________
>>>>> Powered by www.kitware.com
>>>>>
>>>>> Visit other Kitware open-source projects at
>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>
>>>>> Kitware offers ITK Training Courses, for more information visit:
>>>>> http://www.kitware.com/products/protraining.html
>>>>>
>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>
>>>>>           
>>>> _____________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Kitware offers ITK Training Courses, for more information visit:
>>>> http://www.kitware.com/products/protraining.html
>>>>
>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>
>>>>
>>>>         
>>     

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkITKImageBox.tar.gz
Type: application/gzip
Size: 3471 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100227/4d49929e/attachment.bin>


More information about the Insight-users mailing list