]> Creatis software - creaVtk.git/commitdiff
#3476 Export Normal in PointPicker box
authorEduardo DAVILA <davila@creatis.insa-lyon.fr>
Wed, 22 Dec 2021 13:01:05 +0000 (14:01 +0100)
committerEduardo DAVILA <davila@creatis.insa-lyon.fr>
Wed, 22 Dec 2021 13:01:05 +0000 (14:01 +0100)
bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.h

index 69c4c02eb71c54d4044dbec818573c41f26b4271..df5424ab152ed95d99f140e8ea13792b1efb7d06 100644 (file)
@@ -8,6 +8,10 @@
 #include <vtkCellPicker.h>
 #include <vtkRenderWindow.h>
 #include <vtkRendererCollection.h>
+#include <vtkDataSet.h>
+#include <vtkPolyData.h>
+#include <vtkPointData.h>
+#include <vtkDataArray.h>
 
 namespace bbcreaVtk
 {
@@ -28,38 +32,57 @@ void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*
        {
                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() );
+                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
 
 /*
@@ -225,6 +248,11 @@ void PointPicker::bbUserSetDefaultValues()
        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)
index 7d3d8538615821c84da3a2e7cdaa58d5eab18394..d48c5607527c3e5b7c3451ee859f1e980a53d7c4 100644 (file)
@@ -57,6 +57,7 @@ class bbcreaVtk_EXPORT PointPicker
   BBTK_DECLARE_OUTPUT(Mesh,vtkProp3D*);
   BBTK_DECLARE_OUTPUT(PointId,longInt);
   BBTK_DECLARE_OUTPUT(CellId,longInt);
+  BBTK_DECLARE_OUTPUT(Normal,std::vector<double>);
   BBTK_PROCESS(Process);
   void Process();
 
@@ -79,10 +80,11 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(PointPicker,bbtk::AtomicBlackBox);
   BBTK_INPUT(PointPicker,Renderer,"vtk Renderer",vtkRenderer*,"");
   BBTK_INPUT(PointPicker,Prop3D,"vtkProp3D de reference. If this parameter is empty all actors in the render are used",vtkProp3D*,"");
 
-  BBTK_OUTPUT(PointPicker,Point,"Point (double)",std::vector<double>,"");
+  BBTK_OUTPUT(PointPicker,Point,"Point [x,y,z])",std::vector<double>,"");
   BBTK_OUTPUT(PointPicker,Mesh,"Mesh",vtkProp3D*,"");
   BBTK_OUTPUT(PointPicker,PointId,"Point Id in Mesh",longInt,"");
   BBTK_OUTPUT(PointPicker,CellId,"Cell Id in Mesh",longInt,"");
+  BBTK_OUTPUT(PointPicker,Normal,"Normal [nx,ny,nz]",std::vector<double>,"");
 
 BBTK_END_DESCRIBE_BLACK_BOX(PointPicker);
 //=====