[vtkusers] unhandled exception in program using MouseInteraction

David Doria daviddoria at gmail.com
Sun Sep 2 17:28:03 EDT 2012


On Sun, Sep 2, 2012 at 5:03 PM, cerina <cerine-baratelli at hotmail.fr> wrote:
>
> sorry, it was a mistake when I create the post for the first time ( it was in
> html format), and here is the code:
> #include <vtkObjectFactory.h>
> #include "vtkOctree.h"
> #include "RenderWindow.h"
> #include <vtkRenderWindowInteractor.h>
> #include <vtkInteractorStyleTrackballCamera.h>
> #include <vtkPointPicker.h>
> #include <vtkSmartPointer.h>
> #include <vtkUnstructuredGrid.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> // Catch mouse events
> class MouseInteractorStyle : public vtkInteractorStyleTrackballCamera
> {
>   public:
>   static MouseInteractorStyle* New();
>
>   vtkSurface* Mesh2;// here is the input Data
>   vtkIntArray *lesNodes;// this is the nodes of the octree
>
>     virtual void OnLeftButtonDown()
>     {
>
>       int* pos = this->GetInteractor()->GetEventPosition();
>   vtkSmartPointer<vtkPointPicker> picker =
>   vtkSmartPointer<vtkPointPicker>::New();
>   picker->Pick(pos[0], pos[1], pos[2], this->GetDefaultRenderer());
>   double* worldPosition = picker->GetPickPosition();
>   vtkIdType c=picker->GetPointId();
>   cout<<" the PointId is : "<<picker->GetPointId()<<endl;
>   cout&lt;&lt;&quot; point coordinates are:
> &quot;&lt;&lt;pos[0]&lt;&lt;&quot; &quot;&lt;&lt;pos[1]&lt;&lt;&quot;
> &quot;&lt;&lt;pos[2]&lt;&lt;endl;
>                Mesh2->GetPoint(c);
>         cout<<"nombre des sommets : "<< Mesh2->GetNumberOfPoints()<<endl;
>
> this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);
>       vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
>         };
> };
>
> vtkStandardNewMacro(MouseInteractorStyle);
>
> void vtkOctree::Decompose(vtkSurface *Mesh1)
> {
>         RenderWindow *Window=RenderWindow::New();
>         Window->SetInput(this->Input);
>         vtkIntArray *PointsNode=vtkIntArray::New();
>         PointsNode->SetNumberOfValues(this->Input->GetNumberOfPoints());
>                /***********************************/
>                 here , there is the long code that  subdivide the octree: i
> will not put it
>                /***********************************/
>
>                 // create polydata for visualization
>         cout<<NumberOfSplitNodes&lt;&lt;&quot; Nodes
> split&quot;&lt;&lt;endl;
>         Window->DisplayVerticesColors(PointsNode);
>         Window->Render();
>              //here i initialize the interaction
>              vtkRenderWindowInteractor
> *interactor=vtkRenderWindowInteractor::New();
>         interactor->SetRenderWindow(Window->GetvtkRenderWindow());
>         interactor->Initialize();
>         vtkSmartPointer<MouseInteractorStyle> style =
> vtkSmartPointer<MouseInteractorStyle>::New();
>         style->Mesh2=Mesh1;
>         style->lesNodes=PointsNode;
>         interactor->SetInteractorStyle(style);
>         Window->GetvtkRenderWindow()->SetInteractor(interactor);
>         interactor->Start();
>         Window->Interact();
>
>         Window->Delete();
>         PointsNode->Delete();
> }
>
> and this is the main  file:
>
> #include "vtkSurface.h"
> #include "RenderWindow.h"
> #include "vtkOctree.h"
>
>
> int main( int argc, char *argv[] )
> {
>          // Parse command line arguments
>   if(argc != 2)
>     {
>     std::cout << "Usage: " << argv[0] << " Filename(.ply)" << std::endl;
>     return EXIT_FAILURE;
>     }
>
>         vtkSurface *Mesh;
>
>         // Load the mesh and create the vtkSurface data structure
>         Mesh=vtkSurface::New();
>         cout <<"load : "<<argv[1]&lt;&lt;endl;
>         Mesh->CreateFromFile(argv[1]);
>         Mesh->DisplayMeshProperties();
>
>         vtkOctree *Octree=vtkOctree::New();
>         Octree->SetInput(Mesh);
>         Octree->Decompose(Mesh);
>
>         return (0);
> }
> Sorry again


The formatting (indention) is still weird, and has html characters
embedded, etc.

I'm also not sure what your octree method has anything to do with
picking a point on the mesh? In VTK you need to have a non-spatial
data structure representation (i.e. a normal vtkPolyData) of your mesh
to display it, so this problem should have nothing to do with that.
Have you seen the picking examples on the wiki?

David



More information about the vtkusers mailing list