[vtkusers] I want to know the usage of addObserve ?

weiwei_zc weiwei_zc.student at sina.com
Fri Jul 1 01:44:25 EDT 2005


hi, all!
My plateform is window xp.I use c++ to finish thie code.look at the code below first ,please!the result of the code is wrong ,I think this line :
picker->AddObserver(vtkCommand::EndPickEvent,(vtkCommand *)annotatePick);is wrong,please tell me why?thanks.I want to know the usage of addObserve of vtkcellpicker.in urgent need!thanks!!!

void annotatePick()  
{  vtkCellPicker *picker=vtkCellPicker::New();
    vtkTextMapper *textMapper=vtkTextMapper::New();
    vtkActor2D *textActor=vtkActor2D::New();
    vtkRenderWindow *renWin=vtkRenderWindow::New();
    if (picker->GetCellId()< 0 ) 
	{
		textActor->VisibilityOff();
		
    } else 
	{
		float *selPt; 
		float *pickpos;
		int xp,yp,zp;
		int X,Y;
		
		selPt=picker->GetSelectionPoint();   //得到窗口象素坐标
        //cout<<\"Screen location:\"<<selPt[0]<<\" \"<<selPt[1]<<\"\\n\";
		X=selPt[0];
		Y=selPt[1];
		pickpos = picker->GetPickPosition();  //得到在物体上选择的点坐标
		//cout<<\"Point location:\"<<pickpos[0]<<\" \"<<pickpos[1]<<\" \"<<pickpos[2]<<\"\\n\";
		xp=pickpos[0];
		yp=pickpos[1];
		zp=pickpos[2];
		
		textMapper->SetInput(\"($xp, $yp, $zp)\");
		textActor->SetPosition(X,Y);
		textActor->VisibilityOn();
	}
	
	renWin->Render();                                                         
}
void CVtkDlg::Onaddobserve() 
{
  vtkSphereSource *sphere=vtkSphereSource::New();
 vtkPolyDataMapper *sphereMapper=vtkPolyDataMapper::New();
sphereMapper->SetInput(sphere->GetOutput());
sphereMapper->GlobalImmediateModeRenderingOn();
vtkLODActor *sphereActor=vtkLODActor::New();
sphereActor->SetMapper(sphereMapper);

vtkConeSource *cone=vtkConeSource::New();
vtkGlyph3D *glyph=vtkGlyph3D::New();
glyph->SetInput((vtkDataSet *)sphere->GetOutput());
glyph->SetSource(cone->GetOutput());
glyph->SetVectorModeToUseNormal();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.25);
vtkPolyDataMapper *spikeMapper=vtkPolyDataMapper::New();
spikeMapper->SetInput(glyph->GetOutput());
vtkLODActor *spikeActor=vtkLODActor::New();
spikeActor->SetMapper(spikeMapper);
vtkCellPicker *picker=vtkCellPicker::New();
picker->AddObserver(vtkCommand::EndPickEvent,(vtkCommand *)annotatePick);//@@@@@@@@@
vtkTextMapper *textMapper=vtkTextMapper::New();
vtkActor2D *textActor=vtkActor2D::New();
textActor->VisibilityOff();
textActor->SetMapper(textMapper);
vtkRenderer *ren1=vtkRenderer::New();
vtkRenderWindow *renWin=vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetPicker(picker);
ren1->AddActor2D(textActor);
ren1->AddActor(sphereActor);
ren1->AddActor(spikeActor);
ren1->SetBackground(1,1,1);
renWin->SetSize(300,300);
vtkCamera *cam1=vtkCamera::New();
cam1=ren1->GetActiveCamera();
cam1->Zoom(1.4);
renWin->Render();
iren->Start();
iren->Initialize();
picker->Pick(85,126,0,ren1);
ren1->Delete();
renWin->Delete();
iren->Delete();
picker->Delete();
textMapper->Delete();
textActor->Delete();
sphereMapper->Delete();
sphereActor->Delete();
cam1->Delete();
spikeActor->Delete();
spikeMapper->Delete();
sphere->Delete();
cone->Delete();
glyph->Delete();
picker->Pick(85,126,0,ren1);

}


注册新浪2G免费邮箱( http://mail.sina.com.cn/chooseMode.html )

===================================================================



More information about the vtkusers mailing list