[vtkusers] Problem with extending of vtkActor class under Win32

Yianis Nikolaou yianisn at gmail.com
Thu Apr 21 09:38:55 EDT 2005


Ηι alexey,

I wanted to subclass vtkActor too, and while looking into the
archives I came across several usefull posts.. I believe the 
following methodology to be more-or-less correct, althought not very simple.

First of all, when you create a vtkActor the object-factory
methodology actually creates a vtkOpenGLActor or a vtkMesaActor, 
depending on your configuration.

In order to create a custom Actor that contains some 
application-specific properties and methods, 
create first a subclass of vtkOpenGLActor (vtkMyOpenGLActor)

Then subclass from vtkObjectFactory, 
override the method virtual vtkObject *CreateObject(const char* 
vtkclassname);
so that when VTK request a vtkOpenGLActor object you can return a 
vtkMyOpenGLActor.
(I also tried the RegisterFactory(...) method without sucess so far, but you 
can experiment on that)

You have to register the new factory before you actually start creating 
actors
by calling

vtkMyOpenGLActorFactory *myOpenGLActorFactory = vtkMyOpenGLActorFactory 
::New();
vtkObjectFactory::RegisterFacto ry(myOpenGLActorFactory ); 
myOpenGLActorFactory->Delete();
(I placed this code in the constructor of my application)

the definition of these two classes follows...

hope this helps,
yianis nikolaou


class vtkMyOpenGLActor : public vtkOpenGLActor
{
private:
vtkMyOpenGLActor() { SetActorID(-1); SetPicked(false); }
~vtkMyOpenGLActor() { }
protected:
vtkMyOpenGLActor (const vtkMyOpenGLActor&) { }
operator=(const vtkMyOpenGLActor&) { }

public:
vtkTypeMacro(vtkMyOpenGLActor, vtkOpenGLActor);
static vtkMyOpenGLActor *New();

//custom members
protected:
int ActorID;
bool picked;
public:
void SetActorID(int i) { ActorID=i; }
int GetActorID() { return ActorID; }

void SetPicked(bool enable) { picked=enable; }
bool IsPicked() {return picked; }
};


class vtkMyOpenGLActorFactory : public vtkObjectFactory
{
private:
vtkMyOpenGLActorFactory() { }
~vtkMyOpenGLActorFactory() { }
protected:
vtkMyOpenGLActorFactory (const vtkMyOpenGLActor&) { }
operator=(const vtkMyOpenGLActorFactory&) { }

virtual vtkObject *CreateObject(const char* vtkclassname);
public:
vtkTypeMacro(vtkMyOpenGLActorFactory, vtkObjectFactory);

static vtkMyOpenGLActorFactory *New();
virtual const char* GetVTKSourceVersion();
virtual const char* GetDescription();
};


On 4/21/05, PETROV Alexey <alexey.petrov at opencascade.com> wrote:
> 
> Dear vtkusers,
> 
> I have problem with extending of vtkActor class under Win32.
> I have defined a descendant of vtkActor class, something like -
> 
> class MyActor: public vtkActor
> {
> ...
> }
> 
> But I can not render my actor.
> Is there any limitation?
> 
> Please help
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: 
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050421/20f0d1e7/attachment-0001.htm>


More information about the vtkusers mailing list