[vtkusers] vtk actor inheritance

Luke Hua luke_qz at yahoo.com
Wed May 5 10:33:19 EDT 2004


I derived a class from vtkOpenGLActor, it works fine for me.
 
                                                            Luke

Wiebke Timm <wiebke.timm at uni-bielefeld.de> wrote:
Hi!

On 04.05.2004, at 16:19, Simon DROUIN wrote:

> I had the same problem.

Same for me... Trying to make an actor class which can hold an 
additional int for an ID. Seems like a lot of people need to do 
something like that and it's not covered in the book in detail... :( So 
maybe somebody who already did that and it worked could write a howto 
or something?
I wasn't sure if it was better to start a new thread for this but 
because it's basically the same problem I posted to this thread.


> There is probably a more elegant solution using factories, but I 
> haven't tried it.

Hm, I use vtk with qt and tried to derive a factory like it's described 
in the book. But my actors aren't shown either. I'm not sure if I have 
to derive from vtkActor or vtkOpenGLActor either...

I extended vtkFactory _and_ vtkActor because the book said so. That's 
a lot of code for adding an int to a class...


This is my code, maybe someone can say what I did wrong so maybe all of 
us could use it then...? It compiles but no actors are shown and at the 
end of exectution (when I quit the qt Application) it segfaults.


vtkMyFactory.h:

################################################################ Begin 
of file
#ifndef OBJF_H
#define OBJF_H
#include 
#endif

#include 


class vtkMyFactory : public vtkObjectFactory {

public:
vtkMyFactory();
virtual const char* GetVTKSourceVersion();
virtual const char* GetDescription();

};

################################################################ End of 
file



vtkMyFactory.cc:

################################################################ Begin 
of file
#include "vtkMyFactory.h"
#include "vtkVersion.h"

VTK_CREATE_CREATE_FUNCTION(vtkMyActor);

VTK_FACTORY_INTERFACE_IMPLEMENT(vtkMyFactory);

vtkStandardNewMacro(vtkMyFactory);


vtkMyFactory::vtkMyFactory() {

this->RegisterOverride("vtkActor", "vtkMyActor", "vtkActor with ID", 
1,
vtkObjectFactoryCreatevtkMyActor);

}

const char* vtkMyFactory::GetVTKSourceVersion() {
return VTK_SOURCE_VERSION;
}

const char* vtkMyFactory::GetDescription() {
return "Factory needed to extend vtkActor by and int ID...";
}

################################################################ End of 
file




vtkMyActor.h:

################################################################ Begin 
of file
#include 

class vtkMyActor : public vtkActor {
public:
vtkMyActor();
int GetID();
void SetID(int id);
static vtkMyActor* New();

private:
int id; // id of this glyph's actor

};

################################################################ End of 
file




vtkMyActor.cc:

################################################################ Begin 
of file
#include "vtkMyActor.h"

#ifndef OBJF_H
#define OBJF_H
#include 
#endif

#include "vtkSetGet.h"

vtkMyActor::vtkMyActor() {
this->id = -1;
}

int vtkMyActor::GetID() {
return this->id;
}

void vtkMyActor::SetID(int id) {
this->id = id;
}

vtkStandardNewMacro(vtkMyActor);
################################################################ End of 
file

vtkStandardNewMacro is defined in vtkSetGet.h...




GUI.cc (which is called by my main method because it's a QWidget- I 
omitted the includes and unrelevant stuff) holds

#######
GUI::GUI(QWidget* parent, const char* name) : QWidget(parent,name) {

vtkObjectFactory::RegisterFactory((vtkObjectFactory*)vtkMyFactory:: 
New());
vtkQtObjectFactory::RegisterObjectFactory();


...

# All Actors are added to the renderer with ren->AddActor(actor);

...

}

#######

That stuff already worked/showed Actors for the code I posted earlier 
on this mailing list, so the error is definitely in the definion of the 
vtkMyActors. Back then I inherited from vtkActor directly overwriting 
the New method and it _showed_ the actors.


I also ran valgrind ( a memory leak checker) on the program that held 
of the code above and it gave me this many times - I don't know what 
happens, but the int is not allocated I think:

==521== Invalid read of size 4
==521== at 0x40AD5FD7: 
vtkObjectFactory::RegisterFactory(vtkObjectFactory*) (in /usr/lib/libvt
==521== by 0x805D312: GUI::GUI(QWidget*, char const*) (in 
/home/goya/glyphview/Tests/GlyphWrap
==521== by 0x805EA98: main (in 
/home/goya/glyphview/Tests/GlyphWrapper-Test/GUI)
==521== Address 0x450FAFF0 is not stack'd, malloc'd or free'd


...and this:

==521== Invalid read of size 4
==521== at 0x40AD4E92: vtkObjectBase::PrintHeader(std::ostream&, 
vtkIndent) (in /usr/lib/libvt
==521== by 0x405A2DCC: vtkRenderer::Render() (in 
/usr/lib/libvtkRendering.so.4.2.4)
==521== by 0x405AA521: vtkRendererCollection::Render() (in 
/usr/lib/libvtkRendering.so.4.2.4)
==521== by 0x4059875D: vtkRenderWindow::DoStereoRender() (in 
/usr/lib/libvtkRendering.so.4.2.4

==521== Invalid read of size 4
==521== at 0x40AAB4B2: operator<<(std::ostream&, vtkIndent const&) 
(in /usr/lib/libvtkCommon.s
==521== by 0x40AD4EB7: vtkObjectBase::PrintHeader(std::ostream&, 
vtkIndent) (in /usr/lib/libvt
==521== by 0x405A2DCC: vtkRenderer::Render() (in 
/usr/lib/libvtkRendering.so.4.2.4)
==521== by 0x405AA521: vtkRendererCollection::Render() (in 
/usr/lib/libvtkRendering.so.4.2.4)
==521== Address 0x4 is not stack'd, malloc'd or free'd

==521== Process terminating with default action of signal 11 (SIGSEGV): 
dumping core
==521== Address not mapped to object at address 0x4
==521== at 0x40AAB4B2: operator<<(std::ostream&, vtkIndent const&) 
(in /usr/lib/libvtkCommon.s
==521== by 0x40AD4EB7: vtkObjectBase::PrintHeader(std::ostream&, 
vtkIndent) (in /usr/lib/libvt
==521== by 0x405A2DCC: vtkRenderer::Render() (in 
/usr/lib/libvtkRendering.so.4.2.4)
==521== by 0x405AA521: vtkRendererCollection::Render() (in 
/usr/lib/libvtkRendering.so.4.2.4)


...and in the leak summary:

==521== 24 bytes in 1 blocks are definitely lost in loss record 137 of 
449
==521== at 0x4002F202: operator new(unsigned) 
(vg_replace_malloc.c:162)
==521== by 0x40AD2E45: vtkObject::New() (in 
/usr/lib/libvtkCommon.so.4.2.4)
==521== by 0x805D30A: GUI::GUI(QWidget*, char const*) (in 
/home/goya/glyphview/Tests/GlyphWrap
==521== by 0x805EA98: main (in 
/home/goya/glyphview/Tests/GlyphWrapper-Test/GUI)
==521==
==521==
==521== 48 bytes in 1 blocks are definitely lost in loss record 207 of 
449
==521== at 0x4002F202: operator new(unsigned) 
(vg_replace_malloc.c:162)
==521== by 0x412BAD0C: (within /usr/lib/libqt-mt.so.3.2.3)
==521== by 0x412BD26A: QGLWidget::setContext(QGLContext*, QGLContext 
const*, bool) (in /usr/li
==521== by 0x412BCED5: QGLWidget::init(QGLContext*, QGLWidget 
const*) (in /usr/lib/libqt-mt.so



I didn't post everything from the valgrind output because it would make 
this post even bigger, but I hope I got the important parts of it.

Does anyone have an idea what's wrong? Maybe someone with knowledge of 
the things that vtk does internally...
I would be really really thankful and maybe it helps others out there 
too if we manage to get a working derivation of a vtkActor...


Ciao!
Wiebke

_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: 
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
		
---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040505/ab6e0d37/attachment.htm>


More information about the vtkusers mailing list