[vtkusers] The usage of addObserve?
zfjgo
zfjgo at 126.com
Wed Nov 10 08:07:09 EST 2004
Hi,
The following is my C++ code converted from annotatePick.tcl. I know there are many bugs,expect you to correct them.
Thanks again
static void annotatePick(void *arg)
{ 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();
}
int main(int argc, char* argv[])
{ 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(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,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);
//iren AddObserver UserEvent {wm deiconify .vtkInteract}
renWin->Render();
iren->Start();
iren->Initialize();
//picker->Pick(85,126,0,ren1);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20041110/ed40e053/attachment.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testpick.cpp
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20041110/ed40e053/attachment.txt>
More information about the vtkusers
mailing list