[vtkusers] Read data from Callback function

Massinissa Bandou Massinissa.Bandou at USherbrooke.ca
Thu May 23 14:45:41 EDT 2013


Hello David! Thank you for your reply!

Sorry, I symplified my problem and I tried to display the the components of
the matrix with QTableWidget but it shows nothing! I'm pretty sure that my
Qt code is good but I still don't know how I can get the matrix values from
the callback function? I'm not sure of defining an object of my main class
in my vtkMyLandmark is a good idea. 

Thank you so much for your help!

I just want to fill the SourceLandmark matrix of picked positions.

#include "qtablewidget.h"
#include "QVTKWidget.h"
some others 

class ImageRegistration : public QMainWindow
{
	Q_OBJECT
public:
        ImageRegistration(QWidget *parent = 0, Qt::WFlags flags = 0);
void ReadPolyData(){
        /*
        *  some code to read a polydata (.obj file)
        */
	vtkPointPicker *picker = vtkPointPicker::New();
	picker->SetTolerance(0.01);
	
	vtkMyLandmark *callback = vtkMyLandmark::New();
	callback->SetSelectionActor(sphereActor);  sphere created to display during
point selection

	QVTKWidget->GetInteractor()->AddObserver(vtkMyLandmark::EndPickEvent,
callback);
	QVTKWidget->GetInteractor()->SetPicker(picker);
}
           
void TableOfLandmark(std::vector<std::vector&lt;double>> p){

           this->widget.tableWidget->setRowCount(p.size());
	   this->widget.tableWidget->setColumnCount(p[0].size());
           this->SourceLandmark = p;   the problem is here

	   for(unsigned int row=0;row<p.size();row++){
		        for(unsigned int column=0;column&lt;p[0].size();column++){
			QTableWidgetItem* newItem = new QTableWidgetItem();
			newItem->setText(QString::number(p[row][column]));
			this->widget.tableWidget->setItem(row,column,newItem);}}
}
          
	
private:
        std::vector<vector&lt;double>> SourceLandmark;
	Ui::ImageRegistration widget;
};


class vtkMyLandmark : public vtkCommand 
{ 
public: 
        ImageRegistration obj; // object of ImageRegistration class

        vtkMyLandmark::vtkMyLandmark(){SelectedActor = NULL;} 
        static vtkMyLandmark *New(){return new vtkMyLandmark;} 

        void SetSelectionActor(vtkActor* pvtkActorSelection) { 
                SelectedActor = pvtkActorSelection; 
                }; 
	void SetMatrix(std::vector<std::vector&lt;double>> a){
		obj.TableOfLandmark(a); fill a matrix of another class 	
	}

        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); seems not working!

                                iren->Render(); 
                        }	
                } 
        } 
private: 
        std::vector<double> row; 
        std::vector<std::vector&lt;double>> matrix; 
        vtkActor* SelectedActor; 

};




--
View this message in context: http://vtk.1045678.n5.nabble.com/Read-data-from-Callback-function-tp5720847p5720946.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list