My MouseInteractorStyle:对`vtkInteractorStyleZoom :: New()'的未定义引用

时间:2017-07-11 08:40:49

标签: c++ qt cmake vtk

我在vtk项目上 我想编写自己的鼠标交互器样式 我写了这个课程

vtkInteractorStyleZoom.h

// I DON'T RECOMMEND THIS APPROACH
(function() {
    function removeHash(url) {
        var u = String(url || "");
        var x = u.lastIndexOf("#");
        return x == -1 ? u : u.substring(0, x);
    }
    var originalReplaceState = history.replaceState;
    history.replaceState = function(state, title, url) {
        url = removeHash(url);
        return originalReplaceState.call(history, state, title, url);
    };
    var originalPushState = history.pushState;
    history.pushState = function(state, title, url) {
        url = removeHash(url);
        return originalPushState.call(history, state, title, url);
    };
})();

vtkInteractorStyleZoom.cpp

#include <vtkSmartPointer.h>
#include <vtkInteractorStyleTrackballCamera.h>

class vtkInteractorStyleZoom: public vtkInteractorStyleTrackballCamera
{
public:
  static vtkInteractorStyleZoom* New();
  vtkTypeMacro(vtkInteractorStyleZoom , vtkInteractorStyleTrackballCamera);

  virtual void OnLeftButtonDown();

};

这就是我使用这个类的函数

#include "vtkInteractorStyleZoom.h"


vtkStandardNewMacro(vtkInteractorStyleZoom);

void vtkInteractorStyleZoom::OnLeftButtonDown()
{
    this->StartDolly();
}

当我用cmake编译我的项目时,我遇到了这个问题

CMakeFiles \ ReadDICOMSeriesQt.dir / objects.a(ReadDICOMSeriesQt.cxx.obj):在函数void ReadDICOMSeriesQt::on_ZoomButton_clicked() { vtkSmartPointer<vtkInteractorStyleZoom> Style = vtkSmartPointer<vtkInteractorStyleZoom>::New(); ui->qvtkWidget->GetRenderWindow()->GetInteractor()- >SetInteractorStyle(Style); } vtkInteractorStyleZoom :: New()'

我不知道cmake是否有任何问题(也许我必须更改我的CMakeLists.txt中的某些内容)

有谁可以帮助我?

1 个答案:

答案 0 :(得分:1)

您缺少的是构造函数定义。构造函数必须不带参数,以便对象工厂机制起作用。将其设为私有,因为没有人应该直接调用它。 您还应该禁用类的复制语义。即。

class vtkInteractorStyleZoom : public vtkInteractorStyleTrackballCamera
{
  public:
    static vtkInteractorStyleZoom* New();
    vtkTypeMacro(vtkInteractorStyleZoom, vtkInteractorStyleTrackballCamera);

    virtual void OnLeftButtonDown();

 private:
   vtkInteractorStyleZoom() { /* definition, if any */ }

   vtkInteractorStyleZoom(const vtkInteractorStyleZoom&) = delete;
   void operator =(const vtkInteractorStyleZoom&) = delete;
};

此外,你应该在.cpp文件中#include <vtkObjectFactory.h> - 这就是定义vtkStandardNewMacro()的地方。

然后确保调用程序模块(ReadDICOMSeriesQt)链接到vtkInteractorStyleZoom所属的库。