When I want to use vtkInteractorStyleImage to overide the mousewheel event,
#1 New();
#2 vtkTypeMacro( ,);
are show “doesn’t find the function definition”
How can I do to solve it?
use
VTK 9.2.0rc2
VTK-DICOM
QT 5.14.2
Thanks!
class myVtkInteractorStyleImage : public vtkInteractorStyleImage
{
public:
static myVtkInteractorStyleImage* New();//#1
vtkTypeMacro(myVtkInteractorStyleImage, vtkInteractorStyleImage);//#2
};
vtkStandardNewMacro(myVtkInteractorStyleImage);
Hello,
Please, make sure you’ve #include
d vtkObjectFactory.h
.
regards,
Paulo
OK, I will tried it.
Thanks Paulo
It’s still not defined !~
I think it’s my fault that if there has “not define” in the code, still can run!! ( Maybe because it’s a “macro” ?)
Sorry about that, maybe before rewrite the code, some other mistake occured.
Make sure you put this:
#include <vtkObjectFactory.h>
In the myVtkInteractorStyleImage.h
file or whatever header file you’re defining the myVtkInteractorStyleImage
class.
Also, you are probably running old code. C++ compilers quit with undefined symbols errors.
I am sure that I include this header file, myVtkViewer.h
with the code below.
#include <vtkActor.h>
#include <vtkNamedColors.h>
#include <vtkColor.h>
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkActor2D.h>
#include <vtkDICOMImageReader.h>
#include <vtkImageViewer2.h>
#include <vtkInteractorStyleImage.h>
#include <vtkTextMapper.h>
#include <vtkTextProperty.h>
#include <vtkNamedColors.h>
#include <sstream>
namespace
{
// Define own interaction style
class myVtkInteractorStyleImage : public vtkInteractorStyleImage
{
public:
static myVtkInteractorStyleImage* New(); //not define
vtkTypeMacro(myVtkInteractorStyleImage, vtkInteractorStyleImage);//not define
...
};
vtkStandardNewMacro(myVtkInteractorStyleImage);//defined!!
} // namespace
So, please, copy and paste the error message as it is here.
I used Chineese version, sorry about that.
That’s the definition of the vtkTypeMacro macro. We need the text of the error message output by the compiler.
Why I said “not define” is base on what I seem the green waveline in this code(now still has), the error message hasn’t show any error now (after I rewrite it).
The earlier code I am sure that I had include the header file #include <vtkObjectFactory.h>
, but I cleared the old one.
Please, try to compile the program anyway. The compiler will surely issue an error message. Then copy and paste it here.
Like this? I can’t get the point
It run correctly and also build a *.exe
Yes, that’s one of the many errors. Now it’s necessary to translate the messages to English.
Error (active) E2512 the argument to a feature-test macro must be a simple identifier
maybe is like this
all the error is E2512
It seems to be an incompatiblity between the Qt version and VS version you are using. In your case, I’d recommend to either:
a) Use Qt Creator IDE to develop your program (VS IDE is bloatware, anyway);
b) Follow this: Problem with new Visual Studio update 2017 Version 15.8.0 and Qt 5.9.5 | Qt Forum .
1 Like
OKay, thank for your help
Maybe I’ll try another compiler. Because I have no idea to put the VTK library or others into QT creator~ , I choose to use VS (which used by my class teacher)
Hello,
You don’t need to throw away the VS IDE if you don’t feel comfortable. I don’t enjoy much any of Microsoft products, but I support freedom of tool choice. I just suggested using Qt’s IDE because it’ll do the job more efficiently, IMO.
You can still use VS tool chain (its compiler is called cl.exe
, its Makefile processor is called nmake
and so on) but you can use a better IDE IMO .
Adding libraries is not that difficult using alternatives. If you’d like how to setup libraries in qmake
, you can do something like this in the .pro
file:
#========== The VTK include and lib paths and libraries==================
_VTK_INCLUDE = $$(VTK_INCLUDE)
isEmpty(_VTK_INCLUDE){
error(VTK_INCLUDE environment variable not defined.)
}
_VTK_LIB = $$(VTK_LIB)
isEmpty(_VTK_LIB){
error(VTK_LIB environment variable not defined.)
}
_VTK_VERSION_SUFFIX = $$(VTK_VERSION_SUFFIX)
isEmpty(_VTK_VERSION_SUFFIX){
warning(VTK_VERSION_SUFFIX environment variable not defined or empty.)
}
gcc:QMAKE_CXXFLAGS += -isystem $$_VTK_INCLUDE #This is to suppress the countless compiler warnings from VTK headers
clang:QMAKE_CXXFLAGS += -isystem $$_VTK_INCLUDE #This is to suppress the countless compiler warnings from VTK headers
mingw:QMAKE_CXXFLAGS += -isystem $$_VTK_INCLUDE #This is to suppress the countless compiler warnings from VTK headers
msvc:QMAKE_CXXFLAGS += /external:I $$_VTK_INCLUDE #This is to suppress the countless compiler warnings from VTK headers
INCLUDEPATH += $$_VTK_INCLUDE
LIBPATH += $$_VTK_LIB
LIBS += -lvtkGUISupportQt$$_VTK_VERSION_SUFFIX \
-lvtkCommonCore$$_VTK_VERSION_SUFFIX \
-lvtkFiltersSources$$_VTK_VERSION_SUFFIX \
-lvtkRenderingCore$$_VTK_VERSION_SUFFIX \
-lvtkCommonExecutionModel$$_VTK_VERSION_SUFFIX \
-lvtkInteractionStyle$$_VTK_VERSION_SUFFIX \
-lvtkRenderingOpenGL2$$_VTK_VERSION_SUFFIX \
-lvtkRenderingAnnotation$$_VTK_VERSION_SUFFIX \
-lvtkRenderingFreeType$$_VTK_VERSION_SUFFIX \
-lvtkInteractionWidgets$$_VTK_VERSION_SUFFIX \
-lvtkCommonDataModel$$_VTK_VERSION_SUFFIX \
-lvtkFiltersGeneral$$_VTK_VERSION_SUFFIX \
-lvtkCommonTransforms$$_VTK_VERSION_SUFFIX \
-lvtkImagingSources$$_VTK_VERSION_SUFFIX \
-lvtkImagingCore$$_VTK_VERSION_SUFFIX \
-lvtkFiltersCore$$_VTK_VERSION_SUFFIX \
-lvtkFiltersExtraction$$_VTK_VERSION_SUFFIX \
-lvtkImagingFourier$$_VTK_VERSION_SUFFIX \
-lvtkCommonMisc$$_VTK_VERSION_SUFFIX \
-lvtkCommonComputationalGeometry$$_VTK_VERSION_SUFFIX \
-lvtkCommonMath$$_VTK_VERSION_SUFFIX \
-lvtksys$$_VTK_VERSION_SUFFIX \
-lvtkFiltersGeometry$$_VTK_VERSION_SUFFIX \
-lvtkCommonColor$$_VTK_VERSION_SUFFIX \
-lvtkCommonSystem$$_VTK_VERSION_SUFFIX \
-lvtkglew$$_VTK_VERSION_SUFFIX \
-lvtkfreetype$$_VTK_VERSION_SUFFIX \
-lvtkzlib$$_VTK_VERSION_SUFFIX \
-lvtkFiltersHybrid$$_VTK_VERSION_SUFFIX \
-lvtkFiltersModeling$$_VTK_VERSION_SUFFIX \
-lvtkImagingGeneral$$_VTK_VERSION_SUFFIX \
-lvtkRenderingVolume$$_VTK_VERSION_SUFFIX \
-lvtkFiltersStatistics$$_VTK_VERSION_SUFFIX \
-lvtkImagingStencil$$_VTK_VERSION_SUFFIX \
-lvtkImagingHybrid$$_VTK_VERSION_SUFFIX \
-lvtkRenderingContext2D$$_VTK_VERSION_SUFFIX \
-lvtkChartsCore$$_VTK_VERSION_SUFFIX \
-lvtkRenderingContextOpenGL2$$_VTK_VERSION_SUFFIX \
-lvtkRenderingVolumeOpenGL2$$_VTK_VERSION_SUFFIX
#=============================================================================
If you choose to organize and configure your project with CMake instead of Qt’s qmake
or VS’s nmake
, please, take a look at this: https://vtk.org/Wiki/VTK/Tutorials/CMakeListsFile.