[Insight-users] problems when I trying to integrate ITK with
VTK + MFC : min/max macros in VC++
Luis Ibanez
luis . ibanez at kitware . com
Fri, 19 Dec 2003 10:32:40 -0500
Hi Kurt,
The error that you get is unrelated to the CMake
configuration of your project.
It is simply due to the fact that VisualStudio
had the poor idea of providing the functions for
min
max
implemented as macros !
Macros, as you probably know, are managed by the
preprocessor and are exempted of C++ types and
scope checking since they are converted before
passing the code to the compiler. They are therefore
oportunities for LA's = "Language Abominations".
This lack of type and scope checking of the "min" and
"max" macros creates conflicts with decent implementation
of other min() and max() functions made in ITK and VXL.
In order to prevent such conflicts we undefined the "min"
and "max" macros in the file
Insight/Code/Common/itkNumericTraits.h
What happens in your code is that you probably are trying
to use the min() and max() functions in a .cxx file where
you already have included ITK headers and henceforth the
"evil" VC++ min/max macros have been removed.
So, your options are the following:
A) Instead of:
float scale = min(fx,fy);
write:
float scale = (fx > fy) ? fy : fx;
which, after all, is what the VC++ min() macro was
expanding for you.
B) Use the the min, max functions provided by VXL/VNL
#include <vnl_math.h>
float scale = vnl_math_min( fx, fy );
In this case the vnl_math_min is also expanded inline
to the expression shown in option (A).
Regards,
Luis
---------------------
#ZHAO ZHEEN# wrote:
> Hi,
>
> I am an entry level user.
> In my application, I need to use ITK VTK and MFC. The VTK and ITK are built on my PC. The sample programs which implement VTK+MFC and ITK+MFC work very well.
> However, when I try to add ITK to the sample application: \VTK4.2\Examples\GUI\Win32\vtkMFC\vtkSDI, I got trouble. The sample alone works well. When I add
> "FIND_PACKAGE(ITK)
> IF(ITK_FOUND)
> INCLUDE(${ITK_USE_FILE})
> ELSE(ITK_FOUND)
> MESSAGE(FATAL_ERROR
> "Cannot build without ITK. Please set ITK_DIR.")
> ENDIF(ITK_FOUND)"
> to its CMakeLists.txt, there is no problem in building and running. However, as long as I added "${ITK_LIBRARIES}" or other itk-lib to LINK_LIBRARIES, the compiler reported error that "E:\work\try\ivtkmfc\vtkSDIView.cpp(147) : error C2065: 'min' : undeclared identifier". This is the line "float scale = min(fx,fy); ".
>
> The OS is win2000; compiler: VC++6.0; CMake: 1.82; ITK: 1.4; VTK: 4.2;
>
> Would anybody help me?
>
> Best Regards
> Kurt
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>