【问题标题】:VTK inheritance IssueVTK 继承问题
【发布时间】:2015-10-20 12:14:43
【问题描述】:

我目前正在尝试自定义 c++ android 本机示例,以便能够更改使用平板电脑时与 2 个(或 3 个)手指交互时发生的行为。因此,根据我对 VTK 管道的理解,我应该修改 vtkAndroidRenderWindowInteractor 的行为(如果我错了,请纠正我)。 这就是我目前所拥有的:

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:错误: 未定义对“myRenderInteractor::New()”的引用 collect2:错误:ld 返回 1 个退出状态 make[3]: ***

[示例/Android/NativeVTK/libs/armeabi-v7a/libNativeVTK.so] 错误 1 制作[2]: ***

[示例/Android/NativeVTK/jni/CMakeFiles/NativeVTK.dir/all] 错误 2 制作[1]: ***

[示例/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule] 错误 2:***

[示例/Android/NativeVTK/CMakeFiles/NativeVTK-apk-release.dir/rule] 错误 2

希望得到一些帮助。

提前致谢

编辑:在我的示例/Android/NativeVTK/ 的 Makefile 中,我有:

# 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

那是我需要更改的文件吗?坦率地说,我完全迷失了,我很想获得更多关于整个过程的文档,因为由于某种原因我不能使用 cmake。当然,我宁愿不必直接修改makefile,但我现在似乎别无选择。

【问题讨论】:

    标签: c++ inheritance vtk


    【解决方案1】:

    这看起来您已经在库中定义了 myRenderInteractor,但后来忘记通过 target_link_libraries 将您的可执行文件链接到该库。

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

    【讨论】:

    • 感谢您的回答。我应该在 Makefile 中这样做吗?因为我在构建 vtk 时使用了自动生成的 Makefile,因为我自己直接 ccmake-ing 示例时遇到问题
    • 在此之前不会给我带来麻烦吗?就像简单地尝试包含标题一样?
    • 回答为对我的回答的编辑...(是的,在 Makefile 中执行此操作,不,在此之前您不会遇到问题 - 如果您包含头文件,那么它定义为您正在编译...但是如果您不链接到它,那么在您链接时它没有定义...)
    • 感谢您的编辑。我现在完全理解了,但是在实际编辑 makefile 时我遇到了一些问题。如果您不介意,我可以使用一些帮助(请参阅编辑)。事实上,当涉及到 android 示例stackoverflow.com/questions/33099009/vtk-for-android 时,我无法使用 CMake 而不会遇到此错误
    • 编辑完成。再次感谢您迄今为止提供的帮助
    猜你喜欢
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 2021-07-24
    • 2012-05-11
    相关资源
    最近更新 更多