VIALAB : ITK Course : Source Code : Re: [vtkusers] error: invalid static_cast from type 'int' to type 'const itk::Image<unsigned char, 3u>*'

Luis Ibanez luis.ibanez at kitware.com
Mon Jan 16 10:08:59 EST 2006


Hi Amir,


Thanks for letting us know about the details of the
myITKGui application.


This is not officially an application distributed with
"InsightApplications", so we cannot continuously test it.


The myITKGui is an example app, used for a course at
the University of Pittsburgh and Carnegie Mellon, by
the group directed by Dr. George Stetten. Details of
this course (and other ITK courses at graduate level)
are described in a paper published recently in the
Medical Image Analysis journal:

http://www.elsevier.com/wps/find/journaldescription.cws_home/620983/description



If you take a look at the README.txt file that is
distributed with the application. You will find that it
was intended to be built with

                  ITK 1.8.1
                  FLTK 1.1.6
                  VTK  4.4
                  CMake 2.0


In order to build it with CMake 2.2, the CMakeLists.txt
file needs to be updated. In lines 70 and 71, the variables

     myITKgui_VTK_SRCS
     myITKgui_App_SRCS

must be surrounded by brackets and with the dollar sign,
just like:


     ${myITKgui_VTK_SRCS}
     ${myITKgui_App_SRCS}


after this...

The compilation problem that you are finding are related to
comparisons of the SmartPointers with the value "0".

The code in migAppBase.cxx uses lines such as

       if( m_InputImage != 0 )

and

       if( m_InputImage == 0 )

and

       if( m_OutputImage == 0 )


That the compiler is misinterpreting as comparisons
between an ITK SmartPointer and an integer.

These lines should be replaced with:


        if(   m_InputImage.IsNotNull()  )

        if(  m_InputImage.IsNull()   )


    (Note that IsNotNull() and IsNull() are methods
     of the SmartPointer class, not of the Image class,
     therefore you invoke them with the "." notation,
     instead of the "->" notation.).


You could also use the more direct notation:


        if(  m_InputImage )   // test for non NULL

        if( ! m_InputImage )  // test for NULL


although the one of (IsNotNull() and IsNull() ) is
the recommended one, because it is very clear,
explicit and self-documented.


Please make these changes in the code, and let us
know if you find any further problems.


    Thanks



      Luis



BTW: Note that the source code is copyrighted
by Damion Shelton, (who developed most of the
material). Before modifying the code and using
it, you should contact the copyright holders
and ask about the license that they are providing
for users (typical cases are GPL, BSD, MIT, ...
but it is really up to the copyright holder to
chose one).

Depending on the rules of the University, the
copyright may actually be held by the University
and not the be authors of the code. You will be
surprised of the things that you will learn if
you visit the Intellectual Property Office of
your university and ask a similar question.


Note also that the vtkFlRenderWindowInteractor
is distributed under a GPL license. Therefore
the source code of this app, is implicitly subject
to a GPL license too, and if you modify the code
or use it for your applications, then your code
is also subject to a GPL license.

For more details on Open Source Licensing, please
take a look at the Wiki page:

http://www.na-mic.org/Wiki/index.php/NAMIC_Wiki:Community_Licensing



=================================================================


-------------------------
charfeddine amir wrote:
> hi Luis
> thx for your smart answer,
> i downloaded the myITKgui package from 
> http://www.vialab.org/methods_course/myITKgui.zip
> when i posted my question, i thinked that this package was knowed by a 
> lot of people using ITK and VTK packages, that's why i didn't attach 
> line of code including the line where the error was produced.
> this a fragment of the file /usr/local/myITKgui/migAppBase.cxx from line 
> 240 :
> 
>  void migAppBase ::CreateInputImageVTKPipeline(vtkFlRenderWindowInteractor *flrwi) {   /// Abort if the user is being stupid/   *if*(m_InputImage==0) ///<-------line 246/     *return*;    /// create a rendering window and renderer/   m_InputRenderer = vtkRenderer::New();   m_InputRenderer->SetBackground(0.0, 0.0, 0.0);      m_InputRenderWindow = vtkRenderWindow::New();   m_InputRenderWindow->AddRenderer(m_InputRenderer);
>   ......
> 
> i find a message posted in the pipermail on this link
> http://public.kitware.com/pipermail/insight-users/2005-December/015838.html
> did we find the same error ?
> i'm ready for more details,
> thx again
> Amir.
> 
> 
> 
> */Luis Ibanez <luis.ibanez at kitware.com>/* a écrit :
> 
> 
>     Hi Amir,
> 
> 
>     We may need to look at the code that
>     you wrote in your file migAppBase.cxx :-)
> 
> 
> 
>     It seems that you are attempting to assign
>     an integer to a SmartPointer of an image.
> 
>     That will not work....
> 
> 
>     Please be nice to us and share with mailing
>     list the lines of code around line 246 of
>     your file
> 
> 
>     /usr/local/myITKgui/migAppBase.cxx
> 
> 
>     We already tried hard to use our divinatory
>     mental powers to guess what you may have
>     written in that file...
> 
>     but given that today is almost Full Moon, and
>     that we are too far from the Winter Solstice,
>     our divinatory skills didn't work quite well.
> 
> 
> 
>     Best regards,
> 
> 
>     ! Luis
> 
> 
> 
> 
>     ---------------------
>     charfeddine amir wrote:
>      > Hi All
>      >
>      > while trying to build myITKgui package, i get error during build
>     process :
>      >
>      > /usr/local/include/InsightToolkit/Common/itkSmartPointer.h:90:
>     error:
>      > invalid static_cast from type 'int' to type 'const itk::Image
>      > char, 3u>*'
>      > /usr/local/include/InsightToolkit/Common/itkSmartPointer.h: In
>     member
>      > function 'bool itk::SmartPointer::operator==(R) const [with
>      > R = int, TObjectType = itk::Image]':
>      > /usr/local/myITKgui/migAppBase.cxx:246: instantiated from here
>      > /usr/local/include/InsightToolkit/Common/itkSmartPointer.h:86:
>     error:
>      > invalid static_cast from type 'int' to type 'const itk::Image
>      > char, 3u>*'
>      > make[1]: *** [migAppBase.o] Erreur 1
>      > make: *** [default_target] Erreur 2
>      > [root at timhpux myITKguibin]! #
>      >
>      > thankx for any help or comment.
>      > Amir.
>      >
> 
> 
> ------------------------------------------------------------------------
> Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les 
> tarifs exceptionnels pour appeler la France et l'international. 
> Téléchargez 
> <http://us.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.beta.messenger.yahoo.com> 
> la version beta.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list