[Insight-users] Bad crop with mouse click
Cary lorey
developement.unity at gmail.com
Wed May 22 19:28:37 EDT 2013
Hello,
I am trying to retrieve the values of a pixel from a mouse clicks and I
pass the x and y parameters to the crop function , but when I click on the
image , the application crashes. here is my code:
class MouseInteractorStyle3 : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStyle3* New();
virtual void OnLeftButtonDown()
{
typedef itk::Image<unsigned short,2> ImageType;
std::cout << "Pressed left mouse button." << std::endl;
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
vtkSmartPointer<vtkCoordinate> coordinate =
vtkSmartPointer<vtkCoordinate>::New();
coordinate->SetCoordinateSystemToDisplay();
coordinate->SetValue(x,y,0);
// This doesn't produce the right value if the sphere is zoomed in???
double* world =
coordinate->GetComputedWorldValue(this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
std::cout << "World coordinate: " << world[0] << ", " << world[1] <<
", " << world[2] << std::endl;
Crop(x,y);
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
void Crop(int x, int y){
typedef itk::Image<unsigned short,2> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
ReaderType::Pointer reader= ReaderType::New();
ConnectorType::Pointer Connector= ConnectorType::New();
ImageType::Pointer image = ImageType::New();
ImageType::SizeType cropSize;
reader->SetFileName("C:/Test.jpg");
reader->Update();
image = reader->GetOutput();
cropSize[0] = x;
cropSize[1] = y;
typedef itk::CropImageFilter <ImageType, ImageType>
CropImageFilterType;
CropImageFilterType::Pointer cropFilter
= CropImageFilterType::New();
cropFilter->SetInput(image);
cropFilter->SetBoundaryCropSize(cropSize);
cropFilter->Update();
typedef itk::FlipImageFilter< ImageType > FlipImageFilterType;
FlipImageFilterType::Pointer flipFilter = FlipImageFilterType::New ();
// flipFilter->SetInput( reader->GetOutput() );
flipFilter->SetInput( cropFilter->GetOutput() );
bool flipAxes[3] = { false, true, false };
flipFilter->SetFlipAxes(flipAxes);
flipFilter->Update();
Connector->SetInput( flipFilter->GetOutput() );
vtkImageViewer* viewer= vtkImageViewer::New();
vtkRenderWindowInteractor* renderWindowInteractor =
vtkRenderWindowInteractor::New();
viewer->SetupInteractor( renderWindowInteractor);
viewer->SetInput( Connector->GetOutput() );
viewer->Render();
viewer->SetColorWindow( 255);
viewer->SetColorLevel(128);
renderWindowInteractor->Start();
}
};
vtkStandardNewMacro(MouseInteractorStyle3);
I spent a lot temp to seek a solution to a crop with mouse manipulation, I
tried to find a solution that unfortunately contains a bug, I count on you
to help me, I really need your help.
Please answer me!!
thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130523/b3ad46ce/attachment.htm>
More information about the Insight-users
mailing list