[vtkusers] how to get the x, yand z location information when i click mouse at a particular point on the renderwindow
frency v
frencyvarghese at yahoo.com
Thu Apr 23 12:29:55 EDT 2009
Hello Everyone
I am trying to get the location of a point picked by clicking the mouse on the render window. I tried to write a code for it. but nothing is happening. where will the locations of the picked point be displayed?
Pls Help
Rgds
Frency
Here is my code:-
#include <iostream>
#include <fstream>
#include <string>
#include "vtkTextProperty.h"
#include "vtkTextMapper.h"
#include "vtkInteractorStyleTrackballCamera.h"
int MouseMotion;
#include "vtkCallbackCommand.h"
#include "vtkImageImport.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataNormals.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "vtkCommand.h"
#include "vtkCellPicker.h"
#include "vtkActor2D.h"
#include "vtkLabeledDataMapper.h"
vtkImageImport *Importer = vtkImageImport::New();
vtkContourFilter *skinExtractor = vtkContourFilter::New();
vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
vtkActor *skin = vtkActor::New();
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
vtkCellPicker *picker = vtkCellPicker::New();
vtkActor2D *textActor;
vtkTextMapper *textMapper;
vtkRenderWindowInteractor *iren;
class PickCommand : public vtkCommand
{
public:
static PickCommand *New() { return new PickCommand; }
void Delete() { delete this; }
virtual void Execute(vtkObject *caller, unsigned long l, void *callData)
{
cout<<"this is it"<< endl;
if (picker->GetCellId() < 0 )
{
textActor->VisibilityOff();
}
else
{
double selpt[3];
picker->GetSelectionPoint(selpt);
double x = selpt[0];
double y = selpt[1];
double pickPos[3];
picker->GetPickPosition( pickPos );
double xp = pickPos[0];
double yp = pickPos[1];
double zp = pickPos[2];
cout<<zp<<endl;
char text[120];
sprintf( text, "(%5.5f, %5.5f, %5.5f)", xp, yp, zp );
textMapper->SetInput( text );
textActor->SetPosition(10, 10);
textActor->VisibilityOn();
}
renWin->Render();
}
};
// No. of iterations to be done//
int x_max=54;
int y_max=47;
int z_max=63;
const int x_neigh=50000;
const int y_neigh=50000;
const int z_neigh=50000;
int count_vv;
//**reading image into an array**//
int x,y,z;
unsigned short* ImageArray= new unsigned short[x_max*y_max*z_max];
using namespace std;
//*****Main program starts****//
int main()
{
int x;
int y;
int z;
//**reading the .raw image into and array **//
ifstream inputFile;
inputFile.open("/home/owner/Desktop/iteration/15s.raw",ios::binary);
for(z=0; z<z_max; z++)
{
for(y=0; y<y_max; y++)
{
for(x=0; x<x_max; x++)
{
inputFile.read((char*) &(ImageArray[z*x_max*y_max+y*x_max+x]),2);
}
}
}
//** Create the renderer, the render window, and the interactor.**//
//** The renderer draws into the render window, the interactor keyboard-based interaction with the data within the render window.**//
//cout<<"this is it"<< endl;
renWin->AddRenderer(aRenderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
//**using image import class the inmage in the array is moved into the buffer**//
Importer->SetDataExtent(0, 53, 0, 46, 0, 62);
Importer->SetWholeExtent(0, 53, 0, 46, 0, 62);
Importer->SetDataSpacing(1.0,1.0,1.0);
Importer->SetNumberOfScalarComponents(1);
Importer->SetDataScalarTypeToUnsignedShort();
Importer->SetImportVoidPointer(ImageArray);
// An isosurface, or contour value of 100 is known to correspond to the
//inner surface. Once generated, a vtkPolyDataNormals filter is
// is used to create normals for smooth surface shading during rendering.
skinExtractor->SetInputConnection(Importer->GetOutputPort());
skinExtractor->SetValue(0,109);
vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
skinNormals->SetInputConnection(skinExtractor->GetOutputPort());
skinNormals->SetFeatureAngle(60);
skinMapper->SetInputConnection(skinNormals->GetOutputPort());
skinMapper->ScalarVisibilityOff();
skin->SetMapper(skinMapper);
vtkCallbackCommand *pickerCommand = vtkCallbackCommand::New();
PickCommand* pickObserver = PickCommand::New();
aRenderer->SetBackground(1.5, 1.5, 1.5);
vtkCamera *aCamera = vtkCamera::New();
aCamera->SetViewUp (0, 0, -1);
aCamera->SetPosition (0, 1, 0);
aCamera->SetFocalPoint (0, 0, 0);
aCamera->ComputeViewPlaneNormal();
aRenderer->AddActor(skin);
aRenderer->SetActiveCamera(aCamera);
aRenderer->ResetCamera ();
aCamera->Dolly(1.5);
//** defining the vtk windowinteractor**//
iren =vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renWin->Render();
renWin->SetSize(500, 500 );
iren->Initialize();
iren->Start();
//**delete all objects created previously to preventmemory leaks**//
picker->RemoveObserver( pickObserver );
picker->Delete();
textMapper->Delete();
textActor->Delete();
pickerCommand->Delete();
// style->Delete();
pickObserver->Delete();
inputFile.close();
//picker->Delete();
Importer->Delete();
skinExtractor->Delete();
skinMapper->Delete();
skin->Delete();
aCamera->Delete();
renWin->Delete();
aRenderer->Delete();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090423/06421099/attachment.htm>
More information about the vtkusers
mailing list