[vtkusers] pick & drag a point in 3D

andreasscalas at tiscali.it andreasscalas at tiscali.it
Thu Mar 2 10:55:41 EST 2017


  Hi,
I am new to VTK and I was trying to create a tool for picking a
point in the 3D space and dragging it. I have written some code and, if
I pick and drag a point without rotating the scene all works well, but
if I rotate the scene the dragging doesn't follow the mouse, but works
as if I haven't rotated the scene at all. Any help? This is the
interactorStyle (drawablemesh.h is a class that I defined to draw a mesh
stored in a particular data struture, it doesn't influence the
interaction, or at least I suppose it):

#ifndef
MOUSEINTERACTORSTYLEPP_H
#define MOUSEINTERACTORSTYLEPP_H

#include

#include 
#include 
#include 
#include 
#include 
#include 
#include

#include 
#include 
#include 
#include 
#include 
#include 
#include

#include 
#include 
#include 
#include 
#include 
#include
"drawablemesh.h"

class MouseInteractorStylePP : public
vtkInteractorStyleTrackballActor{

 public:
 vtkSmartPointer Data;

vtkSmartPointer selectedMapper;
 vtkSmartPointer selectedActor;

vtkPolyData* GlyphData;

 vtkSmartPointer MoveMapper;
 vtkSmartPointer
MoveActor;
 vtkSmartPointer MovePolyData;
 vtkSmartPointer
MoveGlyphFilter;

 vtkSmartPointer PointPicker;
 vtkSmartPointer
assembly;
 DrawableMesh* model;

 bool Move;
 vtkIdType SelectedPoint;


public:

 static MouseInteractorStylePP* New();


MouseInteractorStylePP(){
 this->Move = false;
 this->PointPicker =
vtkSmartPointer::New();

 // Setup ghost glyph
 vtkSmartPointer points =
vtkSmartPointer::New();
 points->InsertNextPoint(0,0,0);

this->MovePolyData = vtkSmartPointer::New();

this->MovePolyData->SetPoints(points);
 this->MoveMapper =
vtkSmartPointer::New();

this->MoveMapper->SetInputData(this->MovePolyData);
 this->MoveActor =
vtkSmartPointer::New();
 this->MoveActor->SetMapper(this->MoveMapper);

this->MoveActor->VisibilityOff();

this->MoveActor->GetProperty()->RenderPointsAsSpheresOn();

this->MoveActor->GetProperty()->SetPointSize(10.0f);

this->MoveActor->GetProperty()->SetColor(1,0,0);
 }


vtkTypeMacro(MouseInteractorStylePP, vtkInteractorStyleTrackballActor)


void OnMouseMove(){

 if(this->Interactor->GetControlKey() && Move){


double* p = this->MoveActor->GetPosition();

this->Data->GetPoints()->SetPoint(this->SelectedPoint, p);

this->Data->Modified();

this->model->setPointPosition(this->SelectedPoint, p);

this->GetCurrentRenderer()->RemoveActor(assembly);

this->model->draw(assembly);

this->GetCurrentRenderer()->AddActor(assembly);
 }else if(Move){

this->EndPan();
 this->Move = false;
 this->MoveActor->VisibilityOff();

this->SelectedPoint = -1;
 this->assembly->RemovePart(this->MoveActor);

this->InteractionProp =
vtkSmartPointer::NewInstance(this->InteractionProp);

this->GetCurrentRenderer()->Render();

this->GetCurrentRenderer()->GetRenderWindow()->Render();
 }


vtkInteractorStyleTrackballActor::OnMouseMove();
 }

 void
OnRightButtonUp(){

 if(this->Interactor->GetControlKey() &&
Move==true){
 this->EndPan();
 this->Move = false;

this->MoveActor->VisibilityOff();
 this->SelectedPoint = -1;

this->assembly->RemovePart(this->MoveActor);
 this->InteractionProp =
vtkSmartPointer::NewInstance(this->InteractionProp);

this->GetCurrentRenderer()->Render();

this->GetCurrentRenderer()->GetRenderWindow()->Render();

 }


vtkInteractorStyleTrackballActor::OnRightButtonUp();

 }

 virtual void
OnRightButtonDown(){
 if(this->Interactor->GetControlKey()){
 double x,
y,z;
 x = this->Interactor->GetEventPosition()[0];
 y =
this->Interactor->GetEventPosition()[1];
 this->FindPokedRenderer(x,
y);
 this->PointPicker->SetTolerance(0.01);
 this->PointPicker->Pick(x,
y, 0,
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());

std::cout GetPointId() PointPicker->GetPointId() != -1 &&
this->PointPicker->GetPointId() < Data->GetNumberOfPoints()){

this->StartPan();
 this->MoveActor->VisibilityOn();
 this->Move = true;

this->SelectedPoint = this->PointPicker->GetPointId();

 std::cout
GetPoint(this->SelectedPoint, p);
 std::cout InteractionProp =
this->MoveActor;
 }
 }else

vtkInteractorStyleTrackballActor::OnRightButtonDown();
 }

};
#endif //
MOUSEINTERACTORSTYLEPP_H  


Con Open 4 Giga a 9 euro/4 sett navighi veloce, chiami e invii SMS dal tuo smartphone verso tutti i fissi e mobili in Italia. Passa a Tiscali Mobile! http://casa.tiscali.it/mobile/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170302/ab0c0dd8/attachment.html>


More information about the vtkusers mailing list