<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
Hi,<br />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):<br /><br />#ifndef MOUSEINTERACTORSTYLEPP_H<br />#define MOUSEINTERACTORSTYLEPP_H<br /><br />#include <vtkSmartPointer.h><br />#include <vtkRendererCollection.h><br />#include <vtkPointPicker.h><br />#include <vtkSphereSource.h><br />#include <vtkPolyDataMapper.h><br />#include <vtkRenderer.h><br />#include <vtkRenderWindow.h><br />#include <vtkRenderWindowInteractor.h><br />#include <vtkActor.h><br />#include <vtkInteractorStyleTrackballActor.h><br />#include <vtkObjectFactory.h><br />#include <vtkPointPicker.h><br />#include <vtkSelectionNode.h><br />#include <vtkSelection.h><br />#include <vtkExtractSelection.h><br />#include <vtkUnstructuredGrid.h><br />#include <vtkDataSetMapper.h><br />#include <vtkVertexGlyphFilter.h><br />#include <vtkCoordinate.h><br />#include <vtkCamera.h><br />#include "drawablemesh.h"<br /><br />class MouseInteractorStylePP : public vtkInteractorStyleTrackballActor{<br /><br />    public:<br />        vtkSmartPointer<vtkPolyData> Data;<br />        vtkSmartPointer<vtkDataSetMapper> selectedMapper;<br />        vtkSmartPointer<vtkActor> selectedActor;<br />        vtkPolyData* GlyphData;<br /><br />        vtkSmartPointer<vtkPolyDataMapper> MoveMapper;<br />        vtkSmartPointer<vtkActor> MoveActor;<br />        vtkSmartPointer<vtkPolyData> MovePolyData;<br />        vtkSmartPointer<vtkVertexGlyphFilter> MoveGlyphFilter;<br /><br />        vtkSmartPointer<vtkPointPicker> PointPicker;<br />        vtkSmartPointer<vtkAssembly> assembly;<br />        DrawableMesh* model;<br /><br /><br />        bool Move;<br />        vtkIdType SelectedPoint;<br /><br />    public:<br /><br />        static MouseInteractorStylePP* New();<br /><br />        MouseInteractorStylePP(){<br />            this->Move = false;<br />            this->PointPicker = vtkSmartPointer<vtkPointPicker>::New();<br /><br />            // Setup ghost glyph<br />            vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();<br />            points->InsertNextPoint(0,0,0);<br />            this->MovePolyData = vtkSmartPointer<vtkPolyData>::New();<br />            this->MovePolyData->SetPoints(points);<br />            this->MoveMapper = vtkSmartPointer<vtkPolyDataMapper>::New();<br />            this->MoveMapper->SetInputData(this->MovePolyData);<br />            this->MoveActor = vtkSmartPointer<vtkActor>::New();<br />            this->MoveActor->SetMapper(this->MoveMapper);<br />            this->MoveActor->VisibilityOff();<br />            this->MoveActor->GetProperty()->RenderPointsAsSpheresOn();<br />            this->MoveActor->GetProperty()->SetPointSize(10.0f);<br />            this->MoveActor->GetProperty()->SetColor(1,0,0);<br />        }<br /><br />        vtkTypeMacro(MouseInteractorStylePP, vtkInteractorStyleTrackballActor)<br /><br />        void OnMouseMove(){<br /><br />            if(this->Interactor->GetControlKey() && Move){<br /><br />                double* p = this->MoveActor->GetPosition();<br />                this->Data->GetPoints()->SetPoint(this->SelectedPoint, p);<br />                this->Data->Modified();<br />                this->model->setPointPosition(this->SelectedPoint, p);<br />                this->GetCurrentRenderer()->RemoveActor(assembly);<br />                this->model->draw(assembly);<br />                this->GetCurrentRenderer()->AddActor(assembly);<br />            }else if(Move){<br />                this->EndPan();<br />                this->Move = false;<br />                this->MoveActor->VisibilityOff();<br />                this->SelectedPoint = -1;<br />                this->assembly->RemovePart(this->MoveActor);<br />                this->InteractionProp = vtkSmartPointer<vtkProp3D>::NewInstance(this->InteractionProp);<br />                this->GetCurrentRenderer()->Render();<br />                this->GetCurrentRenderer()->GetRenderWindow()->Render();<br />            }<br /><br />            vtkInteractorStyleTrackballActor::OnMouseMove();<br />        }<br /><br />        void OnRightButtonUp(){<br /><br />            if(this->Interactor->GetControlKey() && Move==true){<br />                this->EndPan();<br />                this->Move = false;<br />                this->MoveActor->VisibilityOff();<br />                this->SelectedPoint = -1;<br />                this->assembly->RemovePart(this->MoveActor);<br />                this->InteractionProp = vtkSmartPointer<vtkProp3D>::NewInstance(this->InteractionProp);<br />                this->GetCurrentRenderer()->Render();<br />                this->GetCurrentRenderer()->GetRenderWindow()->Render();<br /><br />            }<br /><br />            vtkInteractorStyleTrackballActor::OnRightButtonUp();<br /><br />        }<br /><br />        virtual void OnRightButtonDown(){<br />            if(this->Interactor->GetControlKey()){<br />                double x, y,z;<br />                x = this->Interactor->GetEventPosition()[0];<br />                y = this->Interactor->GetEventPosition()[1];<br />                this->FindPokedRenderer(x, y);<br />                this->PointPicker->SetTolerance(0.01);<br />                this->PointPicker->Pick(x, y, 0, this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());<br />                std::cout << "Point id is: " << this->PointPicker->GetPointId() << std::endl;<br /><br />                if(this->PointPicker->GetPointId() != -1 && this->PointPicker->GetPointId() < Data->GetNumberOfPoints()){<br />                    this->StartPan();<br />                    this->MoveActor->VisibilityOn();<br />                    this->Move = true;<br />                    this->SelectedPoint = this->PointPicker->GetPointId();<br /><br />                    std::cout << "Dragging point " << this->SelectedPoint << std::endl;<br /><br />                    double p[3];<br />                    this->Data->GetPoint(this->SelectedPoint, p);<br />                    std::cout << "p: " << p[0] << " " << p[1] << " " << p[2] << std::endl;<br />                    this->MoveActor->SetPosition(p);<br /><br />                    assembly->AddPart(this->MoveActor);<br />                    this->GetCurrentRenderer()->AddActor(assembly);<br />                    this->InteractionProp = this->MoveActor;<br />                }<br />            }else<br />                vtkInteractorStyleTrackballActor::OnRightButtonDown();<br />        }<br /><br /><br />};<br />#endif // MOUSEINTERACTORSTYLEPP_H
</body></html>
<br><br/><br/>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! <a href='http://casa.tiscali.it/mobile/' target='_blank'>http://casa.tiscali.it/mobile/</a><br/><br/>