[vtkusers] Picking & vtkCallbackCommand SetClientData

yaolu at engineering.uiowa.edu yaolu at engineering.uiowa.edu
Wed Nov 2 12:25:34 EST 2005


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




More information about the vtkusers mailing list