[vtkusers] sorry about the typo and please help me "trying to delete object with non zero reference count"

david michell davidmichell at rediffmail.com
Fri Jan 23 07:54:09 EST 2004


An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040123/a0f7b084/attachment.htm>
-------------- next part --------------
my pc on which i develop the code is isolated from all networks.
so i had to retype the code on my email client and send it.
so a mistake occured which Mr.West pointed out.
so iam resending the code after correcting the error.
please help me, if there are any typos please excuse.



//all the header files go here
class grids : public vtkInteractorObserer
{
BOOL m_mousedown;
vtkRenderer *m_renderer;
vtkLineSource *m_linesource;
vtkPolyDataMapper *m_datamapper;
vtkActor *m_actor;
float m_lastpickposition[4];

public:
grids(vtkRenderer *renderer)
{
	m_renderer=renderer;
	m_linesource=vtkLineSource::New();
	m_datamapper=vtkDataMapper::New();
	m_actor=vtkActor::New();
	m_picker=vtkCellPicker::New();
	m_linesource.Point1(0.0,0.0,0.0);
	m_linesource.Point1(0.0,10.0,0.0);
	m_datamapper->SetInput(linesource->GetOutput());
	m_actor->SetMapper(m_datamapper);
	m_picker->AddPickList(m_actor);
	m_render->Render();
	this->EventCallbackCommand->SetCallback(grids::ProcessEvents);

}

~grids()
{
//this->ReferenceCount--;  //if i uncomment this line the program terminates normally, without
                           //this line the program displays a window saying, trying to delete
                           //object with non zero reference count	

	m_actor->Delete();
	m_datamapper->Delete();
	m_linesource->Delete();
	m_picker->Delete();

}

static void ProcessEvents(vtkObject object,unsigned long event, void *clientdata,void *calldata)
{

grid *self=reinterpret_cast<grid *>(clientdata);

switch(event)
{
	case vtkCommand::LeftButtonPressEvent:
		self->OnLeftButtonDown();
	break;
			
	case vtkCommand::LeftButtonReleaseEvent:
		self->OnLeftButtonUp();
	break;
	
	case vtkCommand::MouseMoveEvent:
		self->OnMouseMove();
	break;
}
}

void SetEnabled(int enabling)
{
	if (!this->Interactor) return;
	
	if (enabling)
	{
		if (this->Enabled) return;
		this->Enabled=1;
		this->CurrentRenderer=m_renderer;
		
		vtkRenderWindowInteractor *i=this->Interactor;
		i->AddObserver(vtkCommand::MouseMoveEvent,
			this->EventCallbackCommand,this->priority);
		i->AddObserver(vtkCommand::LeftButtonPressEvent,
			this->EventCallbackCommand,this->priority);
		i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
			this->EventCallbackCommand,this->priority);
		
		this->InvokeEvent(vtkCommand::EnableEvent,NULL);
	}
	else
	{
		if (!this->Enabled) return;
		this->Enabled=0;
		this->CurrentRenderer=NULL;
		this->Interactor->RemoveObserver(this->EventCallbackCommand);
		this->InvokeEvent(vtkCommand::DisableEvent,NULL);
	}
	
	this->Interactor->Render();
}
		
	
	

void OnLeftButtonDown()
{
	int x=this->Interactor->GetEventPosition()[0];
	int y=this->Interactor->GetEventPosition()[1];
	
	vtkAssemblyPath *path;
	
	this->m_picker->Pick(x,y,0.0,this->m_renderer);
	path=this->m_picker->GetPath();
	
	if (path!=NULL)
	
	{
		m_picker->GetPickPosition(m_lastpickposition);
		m_mousedown=TRUE;
		this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
	}
	
	else 
		return;
		
	this->EventCallbackCommand->SetAbortFlag(1);
	this->StartInteraction();
	this->Interactor->Render();
}
	

void OnLeftButtonUp()
{
	if (m_mousedown) 	
	{
		m_mousedown=FALSE;
		this->EventCallbackCommand->SetAbortFlag(1);
		this->EndInteraction();
		this->InvlokeEvent(vtkCommand::EndInteractionEvent,NULL);
		this->Interactor->Render
	}
	
	
}
	



virtual void OnMouseMove()
{
	if (!m_mousedown) return;
	
	int x=this->Interactor->GetEventPosition()[0];
	int y=this->Interactor->GetEventPosition()[1];
	
	double focalpoint[4],pickpoint[4];
	
	double z;
	
	vtkCamera *camera =m_renderer->GetActiveCamera();
	
	if (!camera) return;
	
	this->ComputeWorldToDisplay(m_lastpickposition[0],
		m_lastpickposition[1],m_lastpickposition[2],focalpoint);
	
	this->ComputeDisplayToWorld(double(x),double(y),z,pickpoint);
	
	float e1[3],e2[3];
	
	m_linesource->GetPoint1(e1);
	m_linesource->GetPoint1(e2);
	
	e1[0]+=pickpoint[0];
	e1[1]+=pickpoint[1];
	e1[2]+=pickpoint[2];
	
	e2[0]+=pickpoint[0];
	e2[1]+=pickpoint[1];
	e2[2]+=pickpoint[2];
	
	m_linesource->SetPoint1(e1);
	m_linesource->SetPoint2(e2);
	m_linesource->Update();
	
	this->EventCallbackCommand->SetAbortFlag(1);
	this->InvlokeEvent(vtkCommand::InteractionEvent,NULL);
	this->Interactor->Render();
}
	


};




void main()
{
vtkrenderer *rn=vtkRenderer::New();
vtkRenderWindow *win=vtkRenderWindow::New();
vtkRenderWindowObserver *intr=vtkRenderWindowObserver::New();

win->AddRenderer(rn);
intr->SetRenderWindow(win);

grids *cg;

cg=new grids(rn);
intr->Initialize();
rn->Render();
intr->Start();

delete cg;

}



More information about the vtkusers mailing list