简体   繁体   中英

how to subclass vtkActor?

I am trying to subclass the vtkActor class. But my class keeps getting the error "undefined reference to `vtkIntraLatticeObject::New()"

I found this link . I tried it but I get "undefined reference to vtkIntraLatticeObject::vtkIntraLatticeObject()". I am also not 100% convinced this is the way to go. I managed to get the following example to work . So I have difficulty understanding what's so different with my code.

So here's my code class.
vtkIntraLatticeObject.h

#ifndef VTKINTRALATTICEOBJECT_H
#define VTKINTRALATTICEOBJECT_H


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

class VTKRENDERINGCORE_EXPORT vtkIntraLatticeObject : public vtkActor
{
    public:

        vtkTypeMacro(vtkIntraLatticeObject, vtkActor);
        static vtkIntraLatticeObject* New();

        int assignID();

        std::string getObjectTypeName();


    protected:
        int ID;
        static int intralatticeActorCounter;

        vtkActor* Device;

        vtkIntraLatticeObject();
        ~vtkIntraLatticeObject();

};


#endif

vtkIntraLatticeObject.cc

#include "vtkIntraLatticeObject.h"

vtkStandardNewMacro(vtkIntraLatticeObject);

int vtkIntraLatticeObject::intralatticeActorCounter = 0;

vtkIntraLatticeObject::vtkIntraLatticeObject()
{
    int ID = -1;
    this -> Device = vtkActor::New();
}

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

int vtkIntraLatticeObject::assignID()
{
    ID = intralatticeActorCounter;
    intralatticeActorCounter++;
    return ID;
}

std::string vtkIntraLatticeObject::getObjectTypeName()
{
    return "generic intralattice Object";
}

turns out it was my cmake file, I wasn't doing a recursive glob. The file in question was located two layers below. So when the compiler ran, it couldn't locate the .cc file.
The only thing I would add is that vtkActor is an abstract class. So a couple of function are not actually implemented. So when I tried to display my vtkActor, it was invisible. This was solved by subclassing vtkOpenGlActor instead of vtkActor or implementing the missing function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM