[vtkusers] Picking & vtkCallbackCommand SetClientData

John Platt jcplatt at lineone.net
Wed Nov 2 18:26:24 EST 2005


Hi Jenny,

Looking at the docs, vtkCallbackCommand is used to specify a function
for your callback, rather than a base class for your own callback class.
Have you tried deriving your class from vtkCommand and passing your grid
in the New() method.

Alternatively, you could use vtkCallbackCommand

      vtkCBC = vtkCallbackCommand::New();
      vtkCBC->SetCallback(MyClass::MyFunc );
      vtkCBC->SetClientData(this);
	picker->AddObserver(vtkCommand::EndPickEvent, vtkCBC);

static void MyFunc(vtkObject* object, unsigned long eventId, void*
clientdata, void* calldata);

void MyClass::MyFunc( vtkObject* vtkNotUsed(object), 
                                      unsigned long eventId,
                                      void* clientdata, 
                                      void* vtkNotUsed(calldata) )
{
   MyClass* self = reinterpret_cast<MyClass*>( clientdata );
   self->sgrid->GetCell(44)->Print(std::cout);
}

HTH

John.


-----Original Message-----
From: vtkusers-bounces+jcplatt=lineone.net at vtk.org
[mailto:vtkusers-bounces+jcplatt=lineone.net at vtk.org] On Behalf Of
yaolu at engineering.uiowa.edu
Sent: 02 November 2005 17:26
To: vtkusers at vtk.org
Subject: [vtkusers] Picking & vtkCallbackCommand SetClientData

Dear all,

I have a question on Picking. I constructed a vtkStructuredGrid in
member func.
Test2. And I want to pass this grid to my pick callback func. But it
seems the
callback doesn't get it. Could you please tell me why?

Here are my codes:
In MyClass.h
	vtkStructuredGrid *sgrid;

In MyClass.cxx:

MyClass::MyClass(){
	sgrid = vtkStructuredGrid::New();
}

class vtkMyCallback : public vtkCallbackCommand
{
	public:
	static vtkMyCallback *New()
    	{ return new vtkMyCallback; }
	void Delete()
	{ delete this; }
	virtual void Execute(vtkObject *caller, unsigned long, void*
calldata)
    	{
		vtkCellPicker * picker =
vtkCellPicker::SafeDownCast(caller);
		vtkStructuredGrid *CSIGrid =
reinterpret_cast<vtkStructuredGrid *> (calldata);
		CSIGrid->GetCell(44)->Print(std::cout);		//I got
a break here,  Access
violation reading location?????????????????????

    	}
};

MyClass::Test(){

	vtkCellPicker	* picker = vtkCellPicker::New();
	vtkMyCallback * cb = vtkMyCallback::New();
	cb->SetClientData((void*)sgrid);
	picker->AddObserver(vtkCommand::EndPickEvent,cb);
	fltkRenderWindowInteractor->SetPicker(picker);
	sgrid->GetCell(44)->Print(std::cout);	///Here I can print it
out!

}

MyClass::Test2(){	//create the sgrid

	sgrid->SetDimensions(dimensions);
	sgrid->SetPoints(points);
	vtkPolyDataMapper
	vtkActor...

}

I just use "44" for example. Thanks a lot!

Jenny

_______________________________________________
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




More information about the vtkusers mailing list