]> Creatis software - creaVtk.git/blobdiff - bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx
#3478 PointPickerNearest
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkPointPicker.cxx
index 5bb82f5d54abba853cef4936adf50b61e39905dc..71fbe7ef000a4d14d5dc437c0d6a932bcadf4594 100644 (file)
@@ -8,53 +8,89 @@
 #include <vtkCellPicker.h>
 #include <vtkRenderWindow.h>
 #include <vtkRendererCollection.h>
+#include <vtkDataSet.h>
+#include <vtkPolyData.h>
+#include <vtkPointData.h>
+#include <vtkDataArray.h>
 
 namespace bbcreaVtk
 {
 
 creaVtkCallbackPointPicker::creaVtkCallbackPointPicker(void)
 {
-       boxPointPicker=NULL;
+       boxPointPicker = NULL;
 }
 
 void creaVtkCallbackPointPicker::setBox(PointPicker *box)
 {
-       boxPointPicker=box;
+       boxPointPicker = box;
 }
 
 void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*)
 {
+    printf("EED creaVtkCallbackPointPicker::Execute Start\n");
        if (boxPointPicker!=NULL)
        {
                if (boxPointPicker->bbGetInputActive()==true)
                {
-                       printf("creaVtkCallbackPointPicker EED Picker\n");
-                       vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
-                       int* pos = iren->GetEventPosition();
-                   vtkCellPicker *picker = vtkCellPicker::New();
+                       vtkRenderWindowInteractor   *iren   = static_cast<vtkRenderWindowInteractor*>(caller);
+                       int                         *pos    = iren->GetEventPosition();
+                   vtkCellPicker               *picker = vtkCellPicker::New();
                    picker->SetTolerance(0.0005);
+                   if (boxPointPicker->bbGetInputProp3D()!=NULL ) 
+                   {
+                       picker->AddPickList( boxPointPicker->bbGetInputProp3D() );
+                       picker->PickFromListOn();
+                       }
                    picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() );
                        double point[3];
-
                        if(picker->GetCellId() != -1)
                    {
-                               printf("creaVtkCallbackPointPicker EED picker OK\n");
                                picker->GetPickPosition(point);
                                std::vector<double> vecPoint;
                                vecPoint.push_back( point[0] );
                                vecPoint.push_back( point[1] );
                                vecPoint.push_back( point[2] );
-                                       boxPointPicker->bbSetOutputPoint( vecPoint );
-                                       boxPointPicker->bbSetOutputMesh( picker->GetProp3D() );
-                                       boxPointPicker->bbSetOutputPointId( picker->GetPointId() );
-                                       boxPointPicker->bbSetOutputCellId( picker->GetCellId() );
-                                       boxPointPicker->bbSignalOutputModification();
-                       } else {
-                               printf("creaVtkCallbackPointPicker EED picker --\n");
-                       } // if
-               }
+                boxPointPicker->bbSetOutputPoint( vecPoint );
+                boxPointPicker->bbSetOutputMesh( picker->GetProp3D() );
+                boxPointPicker->bbSetOutputPointId( picker->GetPointId() );
+                printf("EED creaVtkCallbackPointPicker::Execute PointId %ld\n", picker->GetPointId() );
+
+                boxPointPicker->bbSetOutputCellId( picker->GetCellId() );
+                vtkDataSet *dataset = picker->GetDataSet();
+                if (strcmp(dataset->GetClassName(),"vtkPolyData")==0)
+                {
+                    vtkPolyData     *polydata   = (vtkPolyData*)dataset;
+                    vtkPointData    *pointdata  = polydata->GetPointData();
+                    vtkDataArray    *dataarray;
+                    double          *pValue;
+                    /*
+                    int i,size=pointdata->GetNumberOfArrays();
+                    for(i=0;i<size;i++)
+                    {
+                        dataarray=pointdata->GetArray(i);
+                        printf("EED creaVtkCallbackPointPicker::Execute dataarray=%s  n=%ld p=%ld\n", dataarray->GetName(),dataarray->GetNumberOfValues() ,polydata->GetNumberOfPoints() );
+                    } // for i
+                    */
+                    dataarray   = pointdata->GetNormals();
+                    if (dataarray!=NULL)
+                    {
+                        pValue      = dataarray->GetTuple3( picker->GetPointId() );
+                        std::vector<double> lstNormal;
+                        lstNormal.push_back(pValue[0]);
+                        lstNormal.push_back(pValue[1]);
+                        lstNormal.push_back(pValue[2]);
+                        boxPointPicker->bbSetOutputNormal( lstNormal );
+                    } // if dataarray
+                } // if ClassName
+                boxPointPicker->bbSignalOutputModification();
+                       }  // if
+               } // if Active
        } // if boxPoiintPicker
 
+    printf("EED creaVtkCallbackPointPicker::Execute End\n");
+
+    
 /*
 {
  
@@ -115,8 +151,6 @@ void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*
         }
 */
 
-
-
 }
 
 
@@ -132,7 +166,7 @@ BBTK_BLACK_BOX_IMPLEMENTATION(PointPicker,bbtk::AtomicBlackBox);
 //===== 
 void PointPicker::Process()
 {
-
+    printf("EED PointPicker::Process Start \n");
 // THE MAIN PROCESSING METHOD BODY
 //   Here we simply set the input 'In' value to the output 'Out'
 //   And print out the output value
@@ -166,10 +200,8 @@ void PointPicker::Process()
                picker->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
                bbGetInputRenderer()->GetRenderWindow()->GetInteractor()->SetPicker(picker);
 */
-
                callPicker = creaVtkCallbackPointPicker::New();
                callPicker->setBox( this );
-
        } // if firsttime
 
 
@@ -199,9 +231,23 @@ void PointPicker::Process()
        } // if bbGetInputRenderer()
 
                
-
+//  std::vector<double> lstPoint;
+//  lstPoint.push_back(0);
+//  lstPoint.push_back(0);
+//  lstPoint.push_back(1);
+//  bbSetOutputPoint( lstPoint );
+    
+// BORRAME    bbSetOutputPoint( bbGetInputDefaultPoint() );
+    
+//  bbSetOutputMesh( NULL );
+// Borrame    bbSetOutputPointId( bbGetInputDefaultPointId() );
+//  bbSetOutputCellId( -1 );
+//  bbSetOutputNormal( lstPoint );
+    
+    printf("EED PointPicker::Process End \n");
 
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
@@ -212,38 +258,42 @@ void PointPicker::bbUserSetDefaultValues()
 //   bbSetInputIn(0);
        bbSetInputActive(true);
        bbSetInputTypeEvent(0);
+    bbSetInputDefaultPointId( -1 );
        bbSetOutputMesh(NULL);
        bbSetOutputPointId(-1);
        bbSetOutputCellId(-1);
        firsttime=true;
        callPicker=NULL;
+       bbSetInputProp3D(NULL);
+    std::vector<double> lstNormal;
+    lstNormal.push_back(0);
+    lstNormal.push_back(0);
+    lstNormal.push_back(1);
+    bbSetOutputNormal( lstNormal );
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void PointPicker::bbUserInitializeProcessing()
 {
-
 //  THE INITIALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should allocate the internal/output pointers 
-//    if any 
-
-  
+//    if any
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void PointPicker::bbUserFinalizeProcessing()
 {
-
 //  THE FINALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should desallocate the internal/output pointers 
 //    if any
-  
 }
-}
-// EO namespace bbcreaVtk
+
+}// EO namespace bbcreaVtk