VTK继承问题 我现在尝试定制C++ Android原生示例,以便能够在使用平板电脑时改变与2个(或3个)手指交互时发生的行为。根据我对VTK管道的理解,因此我应该修改vtkAndroidRenderWindowInteractor的行为(如果我错了,请纠正我)。 这就是我到目前为止所做的:

VTK继承问题 我现在尝试定制C++ Android原生示例,以便能够在使用平板电脑时改变与2个(或3个)手指交互时发生的行为。根据我对VTK管道的理解,因此我应该修改vtkAndroidRenderWindowInteractor的行为(如果我错了,请纠正我)。 这就是我到目前为止所做的:,c++,inheritance,vtk,C++,Inheritance,Vtk,myRenderInteractor.h myRenderInteractor.cxx 最后是main.cxx 所以我想我应该检查build.make,它包含: # CMAKE generated file: DO NOT EDIT! # Generated by "Unix Makefiles" Generator, CMake Version 3.1 #=====================================================================

myRenderInteractor.h

myRenderInteractor.cxx

最后是main.cxx

所以我想我应该检查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,但现在看来我别无选择。

这看起来像是您在库中定义了myRenderInteractor,但后来忘记了通过target\u link\u库将可执行文件链接到该库


根据你问题中的错误输出,你从ld得到了一个“未定义引用”错误——这是一个链接器错误。你的代码编译得很好。您需要将包含myRenderInteractor的库添加到链接到最终可执行文件的库列表中。如果您没有使用CMake生成所涉及的makefiles,则需要将库名称添加到手工制作的Makefile中链接的内容列表中。

谢谢您的回答。我应该在Makefile中这样做吗?因为我在使用构建vtk时自动生成的Makefile,因为我自己直接获取示例时遇到了问题。在这之前,它不会给我带来问题吗?例如,当简单地尝试包括标题?作为我的答案的编辑回答。。。(是的,在Makefile中这样做,不,在此之前不会出现问题-如果包含头文件,则在编译时会定义它…但是如果不链接到它,则在链接时不会定义它…)感谢您的编辑。我现在完全理解了,但在实际编辑makefile时,我遇到了一些问题。如果你不介意的话,我可能需要一些帮助(见编辑)。事实上,当涉及到android示例时,我不能使用CMake而不犯这个错误。再次感谢您迄今为止提供的帮助
#include "myRenderInteractor.h"

vtkStandardNewMacro(myRenderInteractor);

myRenderInteractor::myRenderInteractor(){
    vtkAndroidRenderWindowInteractor();
}

~myRenderInteractor::myRenderInteractor(){
    ~vtkAndroidRenderWindowInteractor();
}

void myRenderInteractor::log(){
    // ...
}
#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();
}
# 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
# 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