]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
#2809 creaMaracas Visu Feature New Normal - update UnitLayerPaint DrawAxisTree
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuDrawAxisTree3D.cxx
index 4c80882c463d011ece282b76e2c942879f823ca8..fec824099408a2b00eace62478298500b02845c7 100644 (file)
@@ -1,5 +1,39 @@
+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+#                        pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+#  This software is governed by the CeCILL-B license under French law and
+#  abiding by the rules of distribution of free software. You can  use,
+#  modify and/ or redistribute the software under the terms of the CeCILL-B
+#  license as circulated by CEA, CNRS and INRIA at the following URL
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability.
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
 #include "bbmaracasvisuDrawAxisTree3D.h"
 #include "bbcreaMaracasVisuPackage.h"
+#include "vtkLinearTransform.h"
+
+#include "vtkUnsignedCharArray.h"
+#include "vtkCellData.h"
+#include "vtkPolyLine.h"
+#include "vtkLine.h"
+
+
+
 namespace bbcreaMaracasVisu
 {
 
@@ -14,6 +48,7 @@ void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
        vtkPolyDataMapper       *polydatamapper = vtkPolyDataMapper::New();
        vtkActor                        *vtkactor               = vtkActor::New();
 
+//     polydatamapper->ScalarVisibilityOff();
        polydatamapper->SetInput(polydata);
        vtkactor->SetMapper(polydatamapper);
 
@@ -21,50 +56,124 @@ void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
        vecVtkPolyDataMaper.push_back( polydatamapper );
        vecVtkActors.push_back( vtkactor );
 
-//     vtkImageData* img = bbGetInputImage();  
+//     vtkImageData* img = bbGetInputImage();
        unsigned int i,size;
-       double spc[3];  
+       double spc[3];
 //     img->GetSpacing(spc);
        spc[0]=1;
        spc[1]=1;
        spc[2]=1;
 
-       if(!bbGetInputlstPointX().empty()){
+       int lstpointsXsize =bbGetInputlstPointX().size();
+
+       if( lstpointsXsize>0 ){
                vtkPoints* allPoints            = vtkPoints::New( );
+vtkPolyLine *polyline = vtkPolyLine::New();
                vtkCellArray* allTopology       = vtkCellArray::New( );
-               allTopology->InsertNextCell( numPoints );
+//             allTopology->InsertNextCell( numPoints );
 
                size=iGeneral+numPoints;
                for (i=iGeneral;i<size;i++)
                {
                        //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
-                       //hay parámetro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
-                       allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],  
-                                                                               bbGetInputlstPointY()[i]*spc[1], 
+                       //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
+                       allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
+                                                                               bbGetInputlstPointY()[i]*spc[1],
                                                                                bbGetInputlstPointZ()[i]*spc[2] );
-                       allTopology->InsertCellPoint( i-iGeneral );
+//                     printf("DrawAxisTree3D::DrawOneAxis point  %d -> %f, %f, %f \n", i,  bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
+
+polyline->GetPointIds()->InsertNextId(i-iGeneral);
+
+//                     allTopology->InsertCellPoint( i-iGeneral );
                } // rof
+  allTopology->InsertNextCell(polyline);
+
+ // create cell array for edges
+  vtkCellArray *edges = vtkCellArray::New();
+
+// connect edge's and vertexes point ids
+  for(vtkIdType i = iGeneral; i < size-1; i++)
+  {
+    vtkLine *edge = vtkLine::New();
+    edge->GetPointIds()->SetId(0, i-iGeneral);
+    edge->GetPointIds()->SetId(1, (i-iGeneral+1) );
+    edges->InsertNextCell(edge);
+    edge->Delete();
+//    vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
+//    vertex->GetPointIds()->SetId(0, i);
+//    vertexes->InsertNextCell(vertex);
+  }
+
                polydata->SetPoints( allPoints );
-               polydata->SetLines( allTopology );
+ polydata->SetLines(edges);
+//             polydata->SetLines( allTopology );
+
+
+ // polydata->SetPolys( allTopology );
+
+               edges->Delete();
                allPoints->Delete();
-               allTopology->Delete();  
+               allTopology->Delete();
        }
 
        // color
        double r,g,b;
 
-       if ( (iAxis*3+1) < bbGetInputColour().size() ){
+       if (bbGetInputColourLaw()==1)  // the same color for all 
+       {
+               r = bbGetInputColour()[0];
+               g = bbGetInputColour()[1];
+               b = bbGetInputColour()[2];
+               vtkactor->GetProperty()->SetColor( r,g,b );
+       } // Law 1  color for all
+
+       if (bbGetInputColourLaw()==2) // different colors for each segment
+       {
+               if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )   
+               {
                        r = bbGetInputColour()[0+iAxis*3];
-                       g = bbGetInputColour()[1+iAxis*3]; 
+                       g = bbGetInputColour()[1+iAxis*3];
                        b = bbGetInputColour()[2+iAxis*3];
                } else {
-                       r = bbGetInputColour()[0];
-                       g = bbGetInputColour()[1]; 
-                       b = bbGetInputColour()[2];
+                       r = (rand() % 100) / 100.0;
+                       g = (rand() % 100) / 100.0;
+                       b = (rand() % 100) / 100.0;
+               }
+               vtkactor->GetProperty()->SetColor( r,g,b );
+       }  // Law 2  color for each segment
+
+
+       if (bbGetInputColourLaw()==3)  // color for each point 
+       {
+               // Setup the colors array
+               vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
+               colors->SetNumberOfComponents(3);
+               colors->SetName("Colors");
+//             colors->SetName("vertex color");
+               int iPoint,pointSize=iGeneral+numPoints;
+
+
+               for (iPoint=iGeneral; iPoint<pointSize; iPoint++)
+               {
+                       r = bbGetInputColour()[0+iPoint*3]*255.0;
+                       g = bbGetInputColour()[1+iPoint*3]*255.0;
+                       b = bbGetInputColour()[2+iPoint*3]*255.0;
+                       //colors->SetTuple3(iPoint,r,g,b);
+                       colors->InsertNextTuple3(r,g,b);
                }
+               polydata->GetCellData()->SetScalars(colors);
+               polydata->Modified();
+       }  // Law 3 color for each point
+
+
+       vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
+       vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
 
-       vtkactor->GetProperty()->SetColor( 1,0,0 );
-       vtkactor->GetProperty()->SetLineWidth( 3 );
+       if ( bbGetInputTransform()!=NULL )
+       {
+               vtkactor->SetUserTransform( bbGetInputTransform() );
+       }
 
      // Interface Update
      if  (bbGetInputRenderer()!=NULL )
@@ -76,39 +185,65 @@ void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
 
 void DrawAxisTree3D::Process()
 {
-        int iActor,sizeActors = vecVtkActors.size();
-        for (iActor=0 ; iActor<sizeActors; iActor++)
-        {
-               if (bbGetInputRenderer()!=NULL )
-               {
-                       bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
-                       vecVtkPolyData[iActor]->Delete();
-                       vecVtkPolyDataMaper[iActor]->Delete();
-                       vecVtkActors[iActor]->Delete();
-               }
-        }
-     vecVtkPolyData.clear();
-     vecVtkPolyDataMaper.clear();
-        vecVtkActors.clear();
-
+       printf("EED DrawAxisTree3D::Process start \n");
 
        int iGeneral=0;
        int iAxis,sizeLstAxis=bbGetInputlstIndexs().size();
+    int iActor,sizeActors = vecVtkActors.size();
        int numPoints;
-       for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
-       {
-               numPoints = bbGetInputlstIndexs()[iAxis];
-               DrawOneAxis(iGeneral,numPoints,iAxis);
-               iGeneral = iGeneral+numPoints;
-       }
 
+//    if (oldLstSize!=sizeLstAxis)
+//      {
+//        oldLstSize=sizeLstAxis;
+         for (iActor=0 ; iActor<sizeActors; iActor++)
+         {
+            if (bbGetInputRenderer()!=NULL )
+            {
+                bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
+                vecVtkPolyData[iActor]->Delete();
+                vecVtkPolyDataMaper[iActor]->Delete();
+                vecVtkActors[iActor]->Delete();
+            } // if
+         } // for iActor
+         vecVtkPolyData.clear();
+         vecVtkPolyDataMaper.clear();
+         vecVtkActors.clear();
+
+        for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
+        {
+            numPoints = bbGetInputlstIndexs()[iAxis];
+            DrawOneAxis(iGeneral,numPoints,iAxis);
+            iGeneral = iGeneral+numPoints;
+
+    //         if ((iAxis % 1)==0)
+    //         {
+    //                 printf("EED  DrawAxisTree3D::Process  %d/%d\n", iAxis,sizeLstAxis );
+    //         }
 
-       bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
+        } // for iAxis
+
+        if ( bbGetInputiAxis() < (int)(vecVtkActors.size()-1) )
+        {
+            bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
+        } else         {
+            printf("DrawAxisTree3D .ERROR. missing index vector...\n");
+        } // if 
+
+ //   } else {// if oldLstSize
+        for (iActor=0 ; iActor<sizeActors; iActor++)
+        {
+            vecVtkActors[iActor]->GetProperty()->SetOpacity( bbGetInputOpacity() );
+           vecVtkActors[iActor]->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
+        }
+//    } // if oldLstSize
+
+       printf("EED DrawAxisTree3D::Process end \n");
 
 }
 
-void DrawAxisTree3D::bbUserConstructor()
-{ 
+void DrawAxisTree3D::bbUserSetDefaultValues()
+{
+    oldLstSize=-1;
         bbSetInputiAxis(0);
      std::vector<double> colour;
         // 1- red
@@ -127,27 +262,35 @@ void DrawAxisTree3D::bbUserConstructor()
      colour.push_back(0.0);
      colour.push_back(1.0);
      colour.push_back(0.0);
-        // 5- 
+        // 5-
      colour.push_back(0.0);
      colour.push_back(1.0);
      colour.push_back(1.0);
 
-        // 6- 
+        // 6-
      colour.push_back(0.5);
      colour.push_back(0.5);
      colour.push_back(0.5);
 
      bbSetInputColour(colour);
+     bbSetInputOpacity(1);
+     bbSetInputLineWidth(0.5);
+     bbSetInputColourLaw(1);
 
 }
 
-void DrawAxisTree3D::bbUserCopyConstructor()
-{  
-}
 
-void DrawAxisTree3D::bbUserDestructor()
-{  
-}
+       //-----------------------------------------------------------------
+       void DrawAxisTree3D::bbUserInitializeProcessing()
+       {
+       }
+
+       //-----------------------------------------------------------------
+       void DrawAxisTree3D::bbUserFinalizeProcessing()
+       {
+       }
+
+       //-----------------------------------------------------------------
 
 }
 // EO namespace bbcreaMaracasVisu