[Insight-users] Problem in obtaining world position with vtkSeedWidget
Xiaopeng Yang
yxp233 at postech.ac.kr
Wed Jan 12 03:42:39 EST 2011
I am trying to visualize a series of 2D DICOM images. After I change the vtkPointHandleRepresentation from 2D to 3D, no matter whether I move to another slice of image and select one seed point, the z value did not change.
The following is my code in main part:
imageViewer21->SetInput(reader->GetOutput());
this->ui->qvtkWidget->SetRenderWindow(imageViewer21->GetRenderWindow());
imageViewer21->SetupInteractor(iren);
imageViewer21->SetColorLevel(127);
imageViewer21->SetColorWindow(255);
vtkSliderRepresentation2D *SliderRepres = vtkSliderRepresentation2D::New();
int min = imageViewer21->GetSliceMin();
int max = imageViewer21->GetSliceMax();
SliderRepres->SetMinimumValue(min);
SliderRepres->SetMaximumValue(max);
SliderRepres->SetValue(static_cast<int>((min + max) / 2));
SliderRepres->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedDisplay();
SliderRepres->GetPoint1Coordinate()->SetValue(0.95, 0.9);
SliderRepres->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedDisplay();
SliderRepres->GetPoint2Coordinate()->SetValue(0.95, 0.1);
SliderRepres->SetSliderLength(0.02);
SliderRepres->SetSliderWidth(0.03);
SliderRepres->SetEndCapLength(0.01);
SliderRepres->SetEndCapWidth(0.03);
SliderRepres->SetTubeWidth(0.005);
SliderRepres->SetLabelFormat("%3.0lf");
SliderRepres->SetTitleHeight(0.05);
SliderRepres->SetLabelHeight(0.055);
vtkSliderWidget *SliderWidget = vtkSliderWidget::New();
SliderWidget->SetInteractor(iren);
SliderWidget->SetRepresentation(SliderRepres);
SliderWidget->KeyPressActivationOff();
SliderWidget->SetAnimationModeToAnimate();
SliderWidget->SetEnabled(true);
vtkSliderCallback2 *SliderCb = vtkSliderCallback2::New();
SliderCb->SetImageViewer(imageViewer21);
SliderWidget->AddObserver(vtkCommand::InteractionEvent, SliderCb);
imageViewer21->SetSlice(static_cast<int>(SliderRepres->GetValue()));
imageViewer21->SetSliceOrientationToXY();
// Create the representation
vtkSmartPointer<vtkPointHandleRepresentation3D> handle =
vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
handle->GetProperty()->SetColor(0,0,0);
handle->GetProperty()->SetOpacity(0);
vtkSmartPointer<vtkSeedRepresentation> rep =
vtkSmartPointer<vtkSeedRepresentation>::New();
rep->SetHandleRepresentation(handle);
// Seed widget
vtkSmartPointer<vtkSeedWidget> seedWidget =
vtkSmartPointer<vtkSeedWidget>::New();
seedWidget->SetInteractor(iren);
seedWidget->SetRepresentation(rep);
vtkSmartPointer<vtkSeedCallback> seedCallback =
vtkSmartPointer<vtkSeedCallback>::New();
seedCallback->SetRepresentation(rep);
seedWidget->AddObserver(vtkCommand::PlacePointEvent,seedCallback);
seedWidget->AddObserver(vtkCommand::InteractionEvent,seedCallback);
seedWidget->On();
imageViewer21->Render();
imageViewer21->GetRenderer()->ResetCamera();
-----邮件原件-----
发件人: Karthik Krishnan [mailto:karthik.krishnan at kitware.com]
发送时间: 2011년 1월 12일 수요일 오후 3:04
收件人: Xiaopeng Yang
抄送: vtk; insight-users at itk.org
主题: Re: [Insight-users] Problem in obtaining world position with vtkSeedWidget
The default representation for the individual handles created by
vtkSeedRepresentation is a 2D rep (vtkPointHandleRepresentation2D). It
does not have a notion of Z coordinate since its rendered on the
overlay plane. If you want 3D seeds, change the default handle
representation to an instance of vtkPointHandleRepresentation3Dvia :
vtkSeedRepresentation::SetHandleRepresentation
On 1/11/11, Xiaopeng Yang <yxp233 at postech.ac.kr> wrote:
> Dear Users,
>
>
>
> I am trying to get world position by
> SeedRepresentation->GetSeedWorldPosition(I, pos). But comparing with other
> software, I got the wrong value in z coordinate. The values of x and y
> coordinates are correct. I would appreciate if anyone can point me in the
> right direction.
>
>
>
> Thanks,
>
> Yang
>
>
>
> class vtkSeedCallback : public vtkCommand
>
> {
>
> public:
>
> static vtkSeedCallback *New()
>
> {
>
> return new vtkSeedCallback;
>
> }
>
> vtkSeedCallback() {}
>
> virtual void Execute(vtkObject*, unsigned long event, void *calldata)
>
> {
>
> if(event == vtkCommand::PlacePointEvent)
>
> {
>
> std::cout << "Point placed, total of: "
>
> << this->SeedRepresentation->GetNumberOfSeeds() << std::endl;
>
> }
>
> if(event == vtkCommand::InteractionEvent)
>
> {
>
> if(calldata)
>
> {
>
> std::cout << "Interacting with seed : "
>
> << *(static_cast< int * >(calldata)) << std::endl;
>
> }
>
> }
>
>
>
> std::cout << "List of seeds (Display coordinates):" << std::endl;
>
>
>
> for(vtkIdType i = 0; i < this->SeedRepresentation->GetNumberOfSeeds();
> i++)
>
> {
>
> double pos[3];
>
> this->SeedRepresentation->GetSeedWorldPosition(i, pos);
>
> std::cout << "(" << pos[0] << " " << pos[1] << " " << pos[2] << ")"
> << std::endl;
>
> }
>
>
>
> }
>
>
>
> void SetRepresentation(vtkSmartPointer<vtkSeedRepresentation> rep)
> {this->SeedRepresentation = rep;}
>
> private:
>
> vtkSmartPointer<vtkSeedRepresentation> SeedRepresentation;
>
> };
>
>
More information about the Insight-users
mailing list