0

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";
}
Marc Wang
  • 171
  • 2
  • 12
  • Your code compiles fine with VTK 7.0, with the only change being changing vtkRevisionTypeMacro -> vtkTypeMacro - it has been renamed in vtk 6.0, but the implementation of that particular macro is probably the same, so it's probably not the source of the problem. However, since you are using that, I assume you are on some old version of VTK. Since your error is about New(), I would look at the implementation of the vtkStandardNew macro in your VTK and compare it to the current 7.0 implementation to see what's missing. Or look for some old tutorials. – tomj Sep 05 '17 at 14:04
  • Hi thanks for the feedback @tomj . Indeed, I was compiling using vtk 6.2. Since there's no particular reason why I am using this version. I will try to migrate to vtk 7.0 – Marc Wang Sep 05 '17 at 16:36
  • hi @tomj , I compiled using vtk 8.0 but I still got the same error. Maybe something is funcky with my installation or cmake file. Do you by any chance have the cmake file you used? – Marc Wang Sep 05 '17 at 20:03
  • My cmake file uses just the default options + qt support, but that should not matter here. I just looked again at your error message and it suggest that you are trying to directly call the constructor of vtkIntraLatticeObject somewhere, which is not allowed (hence it is protected), instead a new instance should be created through vtkIntraLatticeObject::New(). In the code you posted this could be invoked only if there was something wrong with the vtkStandardNewMacro, but that's unlikely. Aren't you getting the error on some line that you did not show in your post? – tomj Sep 05 '17 at 21:39
  • `In function vtkSmartPointer::New()': /usr/local/include/vtk-8.0/vtkSmartPointer.h:137: undefined reference to vtkIntraLatticeObject::New()'` – Marc Wang Sep 06 '17 at 18:16
  • hi @tomj, as you can see I am calling the function New from instantiating a smartPointer. – Marc Wang Sep 06 '17 at 18:17
  • Okay , I had a breakthrough. When I put all the code in the header file the code compiles. This means that the compiler has a problem finding the .cc file. Since the file in question are two folder deep inside my project, this might point to an issue in my cmake or how I gather all my c++ file using glob. – Marc Wang Sep 06 '17 at 19:20

1 Answers1

0

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.

Marc Wang
  • 171
  • 2
  • 12