3

当我选择一个vtkActor. 从vtkActor持有我的数据结构的 ptr 派生的类似乎是最简单的方法。

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

所以,这是我的课:

//.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一切都按预期显示,挑选作品等......

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

但是,如果我使用我的Actor班级,则不会添加任何演员

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

代码中没有其他任何变化。有什么想法吗?

4

1 回答 1

2

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

我在下面粘贴了现在对我有用的示例。它主要来自 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)
于 2014-01-10T03:47:30.080 回答