我正在尝试自定义C++ android本机示例,以便能够更改使用平板电脑时与2(或3)手指进行交互时发生的情况的行为。根据我对VTK管道的了解,我应该修改vtkAndroidRenderWindowInteractor的行为(如果我错了,请纠正我)。 所以这是我到目前为止有:VTK继承问题
myRenderInteractor.h
#include "vtkAndroidRenderWindowInteractor.h"
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkRenderWindowInteractor.h"
#ifndef LOGI
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "NativeVTK", __VA_ARGS__))
#endif
#ifndef LOGW
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "NativeVTK", __VA_ARGS__))
#endif
class myRenderInteractor : public vtkAndroidRenderWindowInteractor {
public:
static myRenderInteractor *New();
vtkTypeMacro(myRenderInteractor, vtkAndroidRenderWindowInteractor);
void PrintSelf(ostream& os, vtkIndent indent);
void log();
protected:
myRenderInteractor();
~myRenderInteractor();
};
myRenderInteractor.cxx
#include "myRenderInteractor.h"
vtkStandardNewMacro(myRenderInteractor);
myRenderInteractor::myRenderInteractor(){
vtkAndroidRenderWindowInteractor();
}
~myRenderInteractor::myRenderInteractor(){
~vtkAndroidRenderWindowInteractor();
}
void myRenderInteractor::log(){
// ...
}
终于在main.cxx
#include "vtkNew.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkConeSource.h"
#include "vtkDebugLeaks.h"
#include "vtkGlyph3D.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "myRenderInteractor.h"
#include "vtkAndroidRenderWindowInteractor.h"
#include <android/log.h>
#include <android_native_app_glue.h>
#ifndef LOGI
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "NativeVTK", __VA_ARGS__))
#endif
#ifndef LOGW
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "NativeVTK", __VA_ARGS__))
#endif
/**
* This is the main entry point of a native application that is using
* android_native_app_glue. It runs in its own thread, with its own
* event loop for receiving input events and doing other things.
*/
void android_main(struct android_app* state)
{
// Make sure glue isn't stripped.
app_dummy();
vtkNew<vtkRenderWindow> renWin;
vtkNew<vtkRenderer> renderer;
vtkNew<myRenderInteractor> iren;
// this line is key, it provides the android
// state to VTK
iren->SetAndroidApplication(state);
renWin->AddRenderer(renderer.Get());
iren->SetRenderWindow(renWin.Get());
vtkNew<vtkSphereSource> sphere;
sphere->SetThetaResolution(8);
sphere->SetPhiResolution(8);
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphere->GetOutputPort());
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper.Get());
vtkNew<vtkConeSource> cone;
cone->SetResolution(6);
vtkNew<vtkGlyph3D> glyph;
glyph->SetInputConnection(sphere->GetOutputPort());
glyph->SetSourceConnection(cone->GetOutputPort());
glyph->SetVectorModeToUseNormal();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.25);
vtkNew<vtkPolyDataMapper> spikeMapper;
spikeMapper->SetInputConnection(glyph->GetOutputPort());
vtkNew<vtkActor> spikeActor;
spikeActor->SetMapper(spikeMapper.Get());
renderer->AddActor(sphereActor.Get());
renderer->AddActor(spikeActor.Get());
renderer->SetBackground(0.4,0.5,0.6);
vtkNew<vtkTextActor> ta;
ta->SetInput("Droids Rock");
ta->GetTextProperty()->SetColor(0.5, 1.0, 0.0);
ta->SetDisplayPosition(50,50);
ta->GetTextProperty()->SetFontSize(32);
renderer->AddActor(ta.Get());
renWin->Render();
iren->Start();
}
我面临的问题是我有以下错误。所以也许我只是愚蠢地忘记了一件非常简单的事情,但我无法找到为什么我会得到它。
/Users/.../Desktop/VTKNew/Common/Core/vtkNew.h:66: error: undefined reference to 'myRenderInteractor::New()' collect2: error: ld returned 1 exit status make[3]: ***
[Examples/Android/NativeVTK/libs/armeabi-v7a/libNativeVTK.so] Error 1 make[2]: ***
[Examples/Android/NativeVTK/jni/CMakeFiles/NativeVTK.dir/all] Error 2 make[1]: ***
[Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule] Error 2 make: ***
[Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule] Error 2
想得到一些帮助。
在此先感谢
编辑:在我的Makefile的例子/安卓/ NativeVTK /我:
# Convenience name for target.
Examples/Android/NativeVTK/CMakeFiles/NativeVTK-ant-configure.dir/rule:
cd /Users/lonnibesancon/Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android && $(MAKE) -f CMakeFiles/Makefile2 Examples/Android/NativeVTK/CMakeFiles/NativeVTK-ant-configure.dir/rule
.PHONY : Examples/Android/NativeVTK/CMakeFiles/NativeVTK-ant-configure.dir/rule
# Convenience name for target.
NativeVTK-ant-configure: Examples/Android/NativeVTK/CMakeFiles/NativeVTK-ant-configure.dir/rule
.PHONY : NativeVTK-ant-configure
# fast build rule for target.
NativeVTK-ant-configure/fast:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android && $(MAKE) -f Examples/Android/NativeVTK/CMakeFiles/NativeVTK-ant-configure.dir/build.make Examples/Android/NativeVTK/CMakeFiles/NativeVTK-ant-configure.dir/build
.PHONY : NativeVTK-ant-configure/fast
# Convenience name for target.
Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/rule:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android && $(MAKE) -f CMakeFiles/Makefile2 Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/rule
.PHONY : Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/rule
# Convenience name for target.
NativeVTK-apk-debug: Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/rule
.PHONY : NativeVTK-apk-debug
# fast build rule for target.
NativeVTK-apk-debug/fast:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android && $(MAKE) -f Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/build.make Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/build
.PHONY : NativeVTK-apk-debug/fast
# Convenience name for target.
Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android && $(MAKE) -f CMakeFiles/Makefile2 Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule
.PHONY : Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule
# Convenience name for target.
NativeVTK-apk-release: Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule
.PHONY : NativeVTK-apk-release
# fast build rule for target.
NativeVTK-apk-release/fast:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android && $(MAKE) -f Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/build.make Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/build
.PHONY : NativeVTK-apk-release/fast
所以我想我应该检查哪些包含build.make:
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.1
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/local/Cellar/cmake/3.1.2/bin/cmake
# The command to remove a file.
RM = /usr/local/Cellar/cmake/3.1.2/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /Users/.../Desktop/VTKNew
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android
# Utility rule file for NativeVTK-apk-debug.
# Include the progress variables for this target.
include Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/progress.make
Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android/Examples/Android/NativeVTK && /usr/local/bin/ant -file /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android/Examples/Android/NativeVTK/build.xml debug
NativeVTK-apk-debug: Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug
NativeVTK-apk-debug: Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/build.make
.PHONY : NativeVTK-apk-debug
# Rule to build all files generated by this target.
Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/build: NativeVTK-apk-debug
.PHONY : Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/build
Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/clean:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android/Examples/Android/NativeVTK && $(CMAKE_COMMAND) -P CMakeFiles/NativeVTK-apk-debug.dir/cmake_clean.cmake
.PHONY : Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/clean
Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/depend:
cd /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /Users/.../Desktop/VTKNew /Users/.../Desktop/VTKNew/Examples/Android/NativeVTK /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android/.../Android/NativeVTK /Users/.../Desktop/VTKNew/vtkbin/CMakeExternals/Build/vtk-android/.../Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/DependInfo.cmake --color=$(COLOR)
.PHONY : Examples/Android/NativeVTK/CMakeFiles/NativeVTK-apk-debug.dir/depend
是我需要改变的文件。坦率地说,我完全失去了,并希望获得更多关于整个过程的文档,因为由于某种原因我无法使用cmake。当然,我不希望直接修改makefile,但现在看来我没有选择。
感谢您的回答。我应该在Makefile中做到这一点吗?原因我使用生成vtk时自动生成的Makefile,因为我有问题直接自己制作示例 – LBes
即使在这之前它不会让我感到困难吗?就像简单地试图包含标题一样? – LBes
作为编辑回答我的答案......(是的,在Makefile中做这个,不,在这之前你不会遇到任何问题 - 如果包含头文件,那么它在编译时定义...但如果你没有链接到它,那么它没有被定义,当你连接...) – DLRdave