// #include "vtkalllibs.h"
// #include "vtkActor.h"
// #include "vtkPolyData.h"
// #include "vtkUnstructuredGrid.h"
// #include "vtkRenderWindow.h"
// #include "vtkRenderer.h"
// #include "vtkPointPicker.h"
// #include "vtkRenderWindowInteractor.h"
// #include "vtkPolyDataMapper.h"
// #include "vtkSphereSource.h"
// #include "vtkPolyDataReader.h"
// #include "vtkPolyDataMapper.h"
// #include "vtkShrinkFilter.h"
// #include "vtkDataSetMapper.h"
// #include "vtkRenderWindowInteractor.h"
// #include "vtkIdList.h"
// #include "vtkProperty.h"
// #include "vtkCamera.h"
//
// static void PickCells(void *);
// static vtkActor *sphereActor;
// static vtkPolyData *plateOutput;
// static vtkUnstructuredGrid *cells;
// static vtkRenderWindow *renWin;
// static vtkActor *cellsActor, *plateActor;
//
// //#include "SaveImage.h"
//
// void main( int argc, char *argv[] )
// {
// vtkRenderer *renderer = vtkRenderer::New();
// renWin = vtkRenderWindow::New();
// renWin->AddRenderer(renderer);
//
// vtkPointPicker *picker = vtkPointPicker::New();
// picker->SetTolerance(0.01);
//
// vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
// iren->SetRenderWindow(renWin);
// iren->SetPicker(picker);
//
// // read data file
// vtkPolyDataReader *plate = vtkPolyDataReader::New();
// plate->SetFileName("plate.vtk");
// //plate->DebugOn();
// plateOutput = plate->GetOutput();
// vtkPolyDataMapper *plateMapper = vtkPolyDataMapper::New();
// plateMapper->SetInput(plate->GetOutput());
// plateActor = vtkActor::New();
// plateActor->SetMapper(plateMapper);
// plateActor->GetProperty()->SetColor(0.5000,0.5400,0.5300);
//
// // create marker for pick
// vtkSphereSource *sphere = vtkSphereSource::New();
// sphere->SetThetaResolution(8); sphere->SetPhiResolution(8);
// sphere->SetRadius(0.01);
// vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
// sphereMapper->SetInput(sphere->GetOutput());
// sphereActor = vtkActor::New();
// sphereActor->SetMapper(sphereMapper);
// sphereActor->GetProperty()->SetColor(1,0,0);
// sphereActor->PickableOff();
//
// // create actor and mapper to display picked cells
// cells = vtkUnstructuredGrid::New();
// vtkShrinkFilter *shrink = vtkShrinkFilter::New();
// shrink->SetInput(cells);
// shrink->SetShrinkFactor(0.75);
// vtkDataSetMapper *cellsMapper = vtkDataSetMapper::New();
// cellsMapper->SetInput(shrink->GetOutput());
// cellsActor = vtkActor::New();
// cellsActor->SetMapper(cellsMapper);
// cellsActor->PickableOff();
// cellsActor->VisibilityOff();
// cellsActor->GetProperty()->SetColor(0.5000,0.5400,0.5300);
//
// renderer->AddActor(cellsActor);
// renderer->AddActor(plateActor);
// renderer->AddActor(sphereActor);
// renderer->SetBackground(1,1,1);
// renderer->GetActiveCamera()->Elevation(30.0);
// renderer->GetActiveCamera()->Azimuth(30.0);
// renderer->GetActiveCamera()->Zoom(0.75);
//
// renWin->SetSize(300,300);
//
// // interact with data
// renWin->Render();
//
// // SAVEIMAGE( renWin );
//
// iren->AddObserver( EndPickEvent, PickCells,(void *)iren);
// iren->Start();
//
// // Clean up
// renderer->Delete();
// renWin->Delete();
// picker->Delete();
// iren->Delete();
// plate->Delete();
// plateMapper->Delete();
// plateActor->Delete();
// sphere->Delete();
// sphereMapper->Delete();
// sphereActor->Delete();
// cells->Delete();
// shrink->Delete();
// cellsMapper->Delete();
// cellsActor->Delete();
// }
//
// static void PickCells(void *arg)
// {
// vtkRenderWindowInteractor *iren = (vtkRenderWindowInteractor *)arg;
// vtkPointPicker *picker = (vtkPointPicker *)iren->GetPicker();
// int i, cellId;
// vtkIdList *cellIds = vtkIdList::New(); cellIds->Allocate(12);
// vtkIdList *ptIds = vtkIdList::New(); ptIds->Allocate(12);
//
// sphereActor->SetPosition(picker->GetPickPosition());
//
// if ( picker->GetPointId() >= 0 )
// {
// cout << "Point id: " << picker->GetPointId() << "\n";
// cellsActor->VisibilityOn();
// plateActor->VisibilityOff();
//
// cells->Initialize();
// cells->Allocate(100);
// cells->SetPoints(plateOutput->GetPoints());
//
// plateOutput->GetPointCells(picker->GetPointId(), cellIds);
// for (i=0; i < cellIds->GetNumberOfIds(); i++)
// {
// cellId = cellIds->GetId(i);
// plateOutput->GetCellPoints(cellId, ptIds);
// cells->InsertNextCell(plateOutput->GetCellType(cellId), ptIds);
// }
// }
// else
// {
// cellsActor->VisibilityOff();
// plateActor->VisibilityOn();
// }
//
// renWin->Render();
// cellIds->Delete();
// ptIds->Delete();
// }
//#####################################################################
#include "vtkAllLibs.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkCommand.h"
#include "vtkPropPicker.h"
#include "vtkPointPicker.h"
#include "vtkSphereSource.h"
#include "vtkProperty.h"
#include "vtkInteractorStyleImage.h"
#include <stdio.h>
class vtkMyCallback : public vtkCommand
{
public:
vtkMyCallback::vtkMyCallback() { m_pvtkActorSelection = NULL; };
static vtkMyCallback *New() { return new vtkMyCallback; }
void PrintSelf(ostream&, vtkIndent) { }
void PrintTrailer(ostream&, vtkIndent) { }
void PrintHeader(ostream&, vtkIndent) { }
void CollectRevisions(ostream&) {}
void SetSelectionActor(vtkActor* pvtkActorSelection) { m_pvtkActorSelection = pvtkActorSelection; };
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderWindowInteractor *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller);
vtkPointPicker *picker = (vtkPointPicker *)iren->GetPicker();
cout << "PointId: " << picker->GetPointId() << "\n";
if (picker->GetPointId() != -1)
{
if (m_pvtkActorSelection)
m_pvtkActorSelection->SetPosition(picker->GetPickPosition());
iren->Render();
}
}
private:
vtkActor* m_pvtkActorSelection;
};
class vtkTransInteractorStyle : public vtkInteractorStyleImage
{
bool ctrldown;
double mx,my,mz,oldpos[3],pickpos[3];
public:
int MousePos[2];
vtkPropPicker * mPicker;
vtkRenderer * mRender;
static vtkTransInteractorStyle *New()
{
return new vtkTransInteractorStyle;
}
// virtual void OnLeftButtonDown();
// virtual void OnLeftButtonUp();
// virtual void OnRightButtonDown();
// virtual void OnRightButtonUp();
// virtual void OnMouseMove();
protected:
vtkTransInteractorStyle() { ctrldown = false;
mx = my = mz = 0;
};
~vtkTransInteractorStyle() {};
};
//void vtkTransInteractorStyle::OnLeftButtonDown()
//{
// int x,y;
// if (0)
// {
// mPicker->Pick(x,y,0,mRender);
// if (mPicker->PickProp(x,y,mRender) )
// {
// int r = mPicker->GetProp()->IsA("VtkImageActor");
// ctrldown = true;
// mx = x; my = y;
//
// mPicker->GetPickPosition(pickpos);
// mPicker->GetActor()->GetPosition(oldpos);
// pickpos[0] = pickpos[0] - oldpos[0];
// pickpos[1] = pickpos[1] - oldpos[1];
// mz = mRender->GetZ(mx,my);
// printf("Picked:%5.2f %5.2f %5.2f\0",oldpos[0],oldpos[1],oldpos[2]);
//
// }
// }
// else
// vtkInteractorStyleImage::OnLeftButtonDown();
//}
//voi