[vtkusers] how to get the mouse position and scalar value on that position i

Dean Inglis dean.inglis at sympatico.ca
Tue Sep 5 17:37:24 EDT 2006


James,

with the test code below, I get no such error.

Dean


Hi, Dean,

  I tried the  vtkImageCoordinateWidget widget using following codes:

  coordWidget->SetViewProp((vtkProp*)(win->ImageViewer->GetImageActor()));
  coordWidget->SetInput(reader->GetOutput());
coordWidget->SetInteractor(win->ImageViewer->GetRenderWindow()->GetInteracto
r());
  coordWidget->DisplayTextOn();
  coordWidget->PlaceWidget();
  coordWidget->SetEnabled(1);

  where "ImageViewer" is an object of vtkImageViewer2. I can compile the
codes successfully, but during running the program, when the mouse  moves
over the imageviewer, the error appears. The error occurs in
"ProcessEvents" of vtkImageCoordinateWidget. Would you please give me  any
idea on how to solve this problem?

  Thanks a lot!

  James

//////////////////////////////////////////////////////////////
#include "vtkImageActor.h"
#include "vtkImageData.h"
#include "vtkImageCoordinateWidget.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkImageCoordinateWidget.h"
#include "vtkImageViewer2.h"


void main( void )
{
  char* fname =  "MY_PATH_TO_/VTKData/Data/headsq/quarter";

// Start by loading some data.
//
  vtkVolume16Reader* v16 = vtkVolume16Reader::New();
	v16->SetDataDimensions(64, 64);
	v16->SetDataByteOrderToLittleEndian();
	v16->SetImageRange(1, 93);
	v16->SetDataSpacing(3.2, 3.2, 1.5);
	v16->SetFilePrefix(fname);
	v16->ReleaseDataFlagOn();
	v16->SetDataMask(0x7fff);
	v16->Update();

  delete[] fname;

  vtkImageViewer2* viewer = vtkImageViewer2::New();
  vtkInteractorStyleImage* style = vtkInteractorStyleImage::New();
  vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
  iren->SetInteractorStyle(style);
  viewer->SetupInteractor(iren);
  viewer->SetInput(v16->GetOutput());
  viewer->SetSliceOrientationToXY();
  viewer->SetSlice(45);

  style->Delete();

// Set up the image coord widget
//
  vtkImageCoordinateWidget* widget = vtkImageCoordinateWidget::New();
	widget->SetDefaultRenderer(viewer->GetRenderer());
	widget->SetViewProp(viewer->GetImageActor());
	widget->SetInput(v16->GetOutput());
	widget->SetInteractor(iren);
	widget->DisplayTextOn();
	widget->On();

  viewer->Render();

  iren->Start();

  widget->Delete();
  v16->Delete();
  viewer->Delete();
  iren->Delete();
}




More information about the vtkusers mailing list