[vtkusers] Read data from Callback function
Massinissa Bandou
Massinissa.Bandou at USherbrooke.ca
Thu May 23 16:59:44 EDT 2013
Hi David,
This code is compiling if you run it you can see that it doesn't fill the
matrix well while picking with "P".
Is there any norme how to display code on vtkmaillist?
thx for your advice and help!!
the test.h file
#include "vtkSmartPointer.h"
#include "vtkCommand.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPointPicker.h"
#include "vtkSphereSource.h"
#include <vtkPolyData.h>
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include <vector>
using namespace std;
class ImgRegistration
{
public:
ImgRegistration(){};
void ReadPolyData();
void TableOfLandmark(std::vector<std::vector<double>>);
private:
std::vector<vector<double>> SourceLandmark;
};
class vtkMyCallback : public vtkCommand
{
public:
ImgRegistration obj;
vtkMyCallback::vtkMyCallback(){SelectedActor = NULL;}
static vtkMyCallback *New(){return new vtkMyCallback;}
void SetSelectionActor(vtkActor* pvtkActorSelection) {
SelectedActor = pvtkActorSelection;
};
void SetMatrix(std::vector<std::vector<double>> a){
obj.TableOfLandmark(a);
}
virtual void Execute(vtkObject *caller, unsigned long, void*){
vtkRenderWindowInteractor *iren =
reinterpret_cast<vtkRenderWindowInteractor*>(caller);
vtkPointPicker *picker = (vtkPointPicker
*)iren->GetPicker();
double picked[3];
picker->GetPickPosition(picked);
if (picker->GetPointId() != -1) {
if(SelectedActor){
SelectedActor->SetPosition(picker->GetPickPosition());
for(unsigned int i=0;i<3;i++){
this->row.push_back(picked[i]);
}
this->matrix.push_back(row);
this->SetMatrix(matrix);
iren->Render();
}
}
}
private:
std::vector<double> row;
std::vector<std::vector<double>> matrix;
vtkActor* SelectedActor;
};
and the cpp file
#include "test.h"
int main(int,char*[]){
ImgRegistration w;
w.ReadPolyData();
return EXIT_SUCCESS;
}
void ImgRegistration::ReadPolyData(){
vtkSmartPointer<vtkSphereSource> sphere =
vtkSmartPointer<vtkSphereSource>::New();
sphere->SetRadius(8);
sphere->SetCenter(0.0, 0.0, 0.0);
vtkSmartPointer<vtkSphereSource> sphere2 =
vtkSmartPointer<vtkSphereSource>::New();
sphere2->SetRadius(1);
vtkSmartPointer<vtkPolyDataMapper> sphere2Mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphere2Mapper->SetInput(sphere2->GetOutput());
vtkSmartPointer<vtkActor> sphere2Actor = vtkSmartPointer<vtkActor>::New();
sphere2Actor->SetMapper(sphere2Mapper);
sphere2Actor->PickableOff();
sphere2Actor->GetProperty()->SetColor(1,0,0);
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInput(sphere->GetOutput());
vtkSmartPointer<vtkActor> sphereActor =
vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
renderer->AddActor(sphereActor);
renderer->AddActor(sphere2Actor);
vtkPointPicker *picker = vtkPointPicker::New();
picker->SetTolerance(0.01);
vtkMyCallback *callback = vtkMyCallback::New();
callback->SetSelectionActor(sphere2Actor);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->AddObserver(vtkMyCallback::EndPickEvent, callback);
renderWindowInteractor->SetPicker(picker);
renderWindow->Render();
renderWindowInteractor->Start();
}
void ImgRegistration::TableOfLandmark(std::vector<std::vector<double>>
p){
this->SourceLandmark = p;
for(unsigned int row=0;row<p.size();row++){
for(unsigned int column=0;column<p[0].size();column++){
std::cout<<"Pos :
"<<this->SourceLandmark[row][column]<<std::endl;
}
}
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/Read-data-from-Callback-function-tp5720847p5720962.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list