gpt4 book ai didi

c++ - 如何继承 vtkActor

转载 作者:太空狗 更新时间:2023-10-29 21:44:09 30 4
gpt4 key购买 nike

当我选择一个 vtkActor 时,我希望能够访问我的底层数据结构。从 vtkActor 派生的类持有我的数据结构的 ptr 似乎是最简单的方法。

我让子类编译得很好,但 Actor 似乎没有被添加到渲染器中。

所以,这是我的类(class):

//.h
#include <vtkActor.h>
#include <vtkObjectFactory.h>

class Node;

struct Actor : public vtkActor {
static Actor* New();
vtkTypeMacro(Actor, vtkActor)

Node* holding_node;
};

//.cpp
#include "actor.h"
vtkStandardNewMacro(Actor)

在我的渲染步骤中:如果我用 vtkActor 实例化 Actor ,一切都会按预期显示,挑选作品等......

vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New();

但是如果我使用我的 Actor 类,则不会添加任何 Actor

vtkSmartPointer<Actor>    sphereActor = vtkSmartPointer<Actor>::New();

代码中没有其他变化。有什么问题吗?

最佳答案

所以,事实证明,有一堆函数需要重载和一些宏魔法才能让它工作。

我在下面粘贴了现在为我工作的示例。它主要来自 vtkFollower 代码(vtkActor 的派生类)。希望这对您有所帮助!

    #include <vtkSmartPointer.h>
#include <vtkRenderer.h>
#include <vtkObjectFactory.h>
#include <vtkRenderingCoreModule.h>
#include <vtkProperty.h>


class Node;

class VTKRENDERINGCORE_EXPORT NodeActor : public vtkActor {
public:
vtkTypeMacro(NodeActor, vtkActor);

static NodeActor *New();

virtual void ReleaseGraphicsResources(vtkWindow *window) {
this->Device->ReleaseGraphicsResources(window);
this->Superclass::ReleaseGraphicsResources(window);
}

virtual int RenderOpaqueGeometry(vtkViewport *viewport){
if ( ! this->Mapper ) {
return 0;
}
if (!this->Property) {
this->GetProperty();
}
if (this->GetIsOpaque()) {
vtkRenderer *ren = static_cast<vtkRenderer *>(viewport);
this->Render(ren);
return 1;
}
return 0;
}

virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport){
if ( ! this->Mapper ) {
return 0;
}
if (!this->Property) {
this->GetProperty();
}
if (!this->GetIsOpaque()) {
vtkRenderer *ren = static_cast<vtkRenderer *>(viewport);
this->Render(ren);
return 1;
}
return 0;
}

virtual void Render(vtkRenderer *ren){
this->Property->Render(this, ren);
this->Device->SetProperty (this->Property);
this->Property->Render(this, ren);
if (this->BackfaceProperty) {
this->BackfaceProperty->BackfaceRender(this, ren);
this->Device->SetBackfaceProperty(this->BackfaceProperty);
}
if (this->Texture) {
this->Texture->Render(ren);
}
this->ComputeMatrix();
this->Device->SetUserMatrix(this->Matrix);
this->Device->Render(ren,this->Mapper);
}

void ShallowCopy(vtkProp *prop) {
NodeActor *f = NodeActor::SafeDownCast(prop);
this->vtkActor::ShallowCopy(prop);
}

//****************************************//
// my member
//****************************************//
Node* node_i_represent{nullptr};

protected:
vtkActor* Device;

NodeActor() {
this -> Device = vtkActor::New();
}

~NodeActor() {
this -> Device -> Delete();
}
private:
};

vtkStandardNewMacro(NodeActor)

关于c++ - 如何继承 vtkActor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20945017/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com