]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
#3084 bbGEditor Bug New Normal - Color refresh for inputs and outputs
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGBoxView.cxx
index 02d194b772a3c283f2063a22a3513cda4c4d74ec..a8789d779f407038f2ff23a1107a7667307b8a75 100644 (file)
@@ -60,6 +60,8 @@ Version:   $Revision$
 
 
 #include "vtkGBoxView.h"
+#include "vtkUnsignedCharArray.h"
+#include "vtkCellData.h"
 
 namespace bbtk
 {
@@ -100,18 +102,12 @@ namespace bbtk
        void vtkGBoxView::createVtkInputOutputPorts()
        {
                ///************************* Inputs Fill (triangles) *************************
+               float rgb[3];
                GBoxModel* boxModel                     =(GBoxModel*)_model;
                int numberOfTriangles                   = boxModel->getNumInputPorts();
                _TrianglesInputsPts                             = vtkPoints::New();
                _TrianglesInputsPts->SetNumberOfPoints( 3*numberOfTriangles );
 
-//EED 2017-03-02
-//             if (numberOfTriangles>0)
-//             {
-//                     _TrianglesInputsPts->SetPoint(0, -1000, -1000, -1000 );
-//                     _TrianglesInputsPts->SetPoint(1, 1000, 1000, 1000 );
-//             }
-
                vtkCellArray *stripTrianglesInputs = vtkCellArray::New();
                vtkPolyData *pdTrianglesInputs  = vtkPolyData::New();
                _TrianglesInputsPolyMapper              = vtkPolyDataMapper::New();
@@ -124,11 +120,27 @@ namespace bbtk
                                stripTrianglesInputs->InsertCellPoint(i*3+1);
                                stripTrianglesInputs->InsertCellPoint(i*3+2);
                }
+
+               // Create cell data
+               _cellDataInputTriangles = vtkUnsignedCharArray::New();
+               _cellDataInputTriangles->SetNumberOfComponents(3);
+               _cellDataInputTriangles->SetNumberOfTuples(numberOfTriangles);
+               for (int i = 0; i < numberOfTriangles; i++)
+               {
+                       rgb[0] = 100;
+                       rgb[1] = 100;
+                       rgb[2] = 100;
+                       _cellDataInputTriangles->SetTuple(i, rgb);
+               } // for colors  
+               pdTrianglesInputs->GetCellData()->SetScalars( _cellDataInputTriangles );
+
                pdTrianglesInputs->SetPoints( _TrianglesInputsPts );
                pdTrianglesInputs->SetStrips( stripTrianglesInputs );
                _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
                _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
                _TrianglesInputsPolyMapper->Modified();
+
+
                ///************************* Inputs Fill (triangles) *************************
 
                ///************************* Outputs Fill (triangles) *************************
@@ -136,13 +148,6 @@ namespace bbtk
                _TrianglesOutputsPts                                    = vtkPoints::New();
                _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
 
-//EED 2017-03-02
-//             if (numberOfTriangles>0)
-//             {
-//                     _TrianglesOutputsPts->SetPoint(0, -1000, -1000, -1000 );
-//                     _TrianglesOutputsPts->SetPoint(1, 1000, 1000, 1000 );
-//             }
-
                vtkCellArray *stripTrianglesOutputs     = vtkCellArray::New();
                vtkPolyData *pdTrianglesOutputs                 = vtkPolyData::New();
                _TrianglesOutputsPolyMapper                             = vtkPolyDataMapper::New();
@@ -150,11 +155,23 @@ namespace bbtk
                // RaC In the actual version, zInic=zFin=GPOSITION_Z
                for (int i=0 ; i<numberOfTriangles; i++)
                {
-                               stripTrianglesOutputs->InsertNextCell( 3 );
-                               stripTrianglesOutputs->InsertCellPoint(i*3+0);
-                               stripTrianglesOutputs->InsertCellPoint(i*3+1);
-                               stripTrianglesOutputs->InsertCellPoint(i*3+2);
-               }
+                       stripTrianglesOutputs->InsertNextCell( 3 );
+                       stripTrianglesOutputs->InsertCellPoint(i*3+0);
+                       stripTrianglesOutputs->InsertCellPoint(i*3+1);
+                       stripTrianglesOutputs->InsertCellPoint(i*3+2);
+               } // for
+               // Create cell data
+               _cellDataOutputTriangles = vtkUnsignedCharArray::New();
+               _cellDataOutputTriangles->SetNumberOfComponents(3);
+               _cellDataOutputTriangles->SetNumberOfTuples(numberOfTriangles);
+               for (int i = 0; i < numberOfTriangles; i++)
+               {
+                       rgb[0] = 000;
+                       rgb[1] = 255;
+                       rgb[2] = 255;
+                       _cellDataOutputTriangles->SetTuple(i, rgb);
+               } // for colors  
+               pdTrianglesOutputs->GetCellData()->SetScalars( _cellDataOutputTriangles );
                pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
                pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
                _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
@@ -257,6 +274,7 @@ namespace bbtk
 
        void vtkGBoxView::updateColors()
        {
+               printf("EED vtkGBoxView::updateColors\n");
                _fillObjectActor->GetProperty()->SetAmbient(0.6);
 
                if(_state==NOTHING_HAPPENS)
@@ -283,24 +301,57 @@ namespace bbtk
 //                     _borderObjectActor->GetProperty()->SetLineWidth(2);
 //                     _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
                        _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
-               }
+               } // if state box
+
+               updateColorsPorts();
        }
 
+
        //=========================================================================
+       void vtkGBoxView::updateColorsPorts()
+       {
+               // Input ports
+               float rgb[3];
+               vtkGPortView    *portView;
+               GBoxModel               *boxModel       = (GBoxModel*)_model;
+               int numberOfTriangles           = boxModel->getNumInputPorts();
+               for (int i=0 ; i<numberOfTriangles; i++)
+               {
+                       portView = _inputsG[i];
+                       portView->getColors(rgb);
+                       rgb[0]=rgb[0]*255;
+                       rgb[1]=rgb[1]*255;
+                       rgb[2]=rgb[2]*255;
+                       _cellDataInputTriangles->SetTuple(i, rgb);
+               } // for
+
+               numberOfTriangles               = boxModel->getNumOutputPorts();
+               for (int i=0 ; i<numberOfTriangles; i++)
+               {
+                       portView = _outputsG[i];
+                       portView->getColors(rgb);
+                       rgb[0]=rgb[0]*255;
+                       rgb[1]=rgb[1]*255;
+                       rgb[2]=rgb[2]*255;
+                       _cellDataOutputTriangles->SetTuple(i, rgb);
+               } // for
+       }
+
 
+       //=========================================================================
        void vtkGBoxView::updatePorts()
        {
                double xInic, yInic,zInic,xFin, yFin,zFin;
 
-               GBoxModel* boxModel =(GBoxModel*)_model;
+               GBoxModel* boxModel = (GBoxModel*)_model;
                boxModel->updatePorts();
 
 // update position for one Actor that represents all InputPorts
-               GPortModel      *portModel;
+               GPortModel              *portModel;
                int numberOfTriangles                   = boxModel->getNumInputPorts();
                for (int i=0;i<numberOfTriangles;i++)
                {
-                       portModel= boxModel->getInputPort(i);
+                       portModel = boxModel->getInputPort(i);
                portModel->getInicPoint( xInic , yInic , zInic ) ;
                portModel->getFinalPoint( xFin , yFin , zFin ) ;
                // RaC In the actual version, zInic=zFin=GPOSITION_Z
@@ -331,6 +382,17 @@ namespace bbtk
        }
 
        //=========================================================================
+       void vtkGBoxView::addInputPort(vtkGPortView *inputport)
+       {
+               _inputsG.push_back(inputport);
+       }
+
+       //=========================================================================
+       void vtkGBoxView::addOutputPort(vtkGPortView *outputport)
+       {
+               _outputsG.push_back(outputport);
+       }
+
 
 }  // EO namespace bbtk