]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx
#2516 creaMaracasVisu Feature New Normal - creaPanelButtonContainer ListPanel with...
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuTubeTreeFilter.cxx
index 8f2a3ce5b96a44cd26d1a401feb3b34d085db377..b58742c5c63e1d1db6fa6b147461e41be4570a88 100644 (file)
@@ -1,3 +1,28 @@
+/*# ---------------------------------------------------------------------
+#
+# 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.
+# ------------------------------------------------------------------------ */
+
 //=====
 // 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)
 //=====
 #include <vtkPolyData.h>
 #include <vtkPointData.h>
 #include <vtkTubeFilter.h>
-#include <vtkSphereSource.h>
+#include "vtkObjectFactory.h"
 
 
+       
+       vtkStandardNewMacro(vtkLookupTableEED);
+       
+       // Construct with range=(0,1); and hsv ranges set up for rainbow color table 
+       // (from red to blue).
+       vtkLookupTableEED::vtkLookupTableEED(int sze, int ext)
+       {
+               this->TableRange[0] = 0.0;
+               this->TableRange[1] = 1.0;
+       }
+       
+       //----------------------------------------------------------------------------
+       vtkLookupTableEED::~vtkLookupTableEED()
+       {
+       }
+       
+       
+       
+       unsigned char *vtkLookupTableEED::MapValue(double v)
+       {
+               
+               //int idx = this->GetIndex(v);
+               //return (this->Table->GetPointer(0) + 4*idx);
+               
+               return 0;
+       }
+       
+       void vtkLookupTableEED::GetColor(double v, double rgb[3])
+       {
+               //      unsigned char *rgb8 = this->MapValue(v);
+               //      rgb[0] = rgb8[0]/255.0;
+               //      rgb[1] = rgb8[1]/255.0;
+               //      rgb[2] = rgb8[2]/255.0;
+               
+               rgb[0] = 1;
+               rgb[1] = 1;
+               rgb[2] = 0;
+       }
+       
+       
+       void vtkLookupTableEED::SetTableRange(double r[2])
+       {
+               this->SetTableRange(r[0],r[1]);
+       }
+       
+       //----------------------------------------------------------------------------
+       // Set the minimum/maximum scalar values for scalar mapping. Scalar values
+       // less than minimum range value are clamped to minimum range value.
+       // Scalar values greater than maximum range value are clamped to maximum
+       // range value.
+       void vtkLookupTableEED::SetTableRange(double rmin, double rmax)
+       {
+               if (rmax < rmin)
+               {
+                       vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
+                       return;
+               }
+               
+               if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
+               {
+                       return;
+               }
+               
+               this->TableRange[0] = rmin;
+               this->TableRange[1] = rmax;
+               
+               this->Modified();
+       }
+       
+       
+       
+       //----------------------------------------------------------------------------
+       // Although this is a relatively expensive calculation,
+       // it is only done on the first render. Colors are cached
+       // for subsequent renders.
+       template<class T>
+       void vtkLookupTableMapDirVectorEED(vtkLookupTableEED *self, T *input, 
+                                                                          unsigned char *output, int length, 
+                                                                          int inIncr, int outFormat)
+       {
+               double tmp,sum;
+               //      double *mag;
+               int i, j;
+               double dirx,diry,dirz;
+               
+               
+               printf("EED length %d  %p\n", length,input);
+               //      mag = new double[length];
+               for (i = 0; i < length; ++i)
+               {
+                       dirx    = 0;
+                       diry    = 0;
+                       dirz    = 0;
+                       sum             = 0;
+                       for (j = 0; j < inIncr; ++j)
+                       {
+                               if (j==0) dirx= static_cast<double>(*input);  
+                               if (j==1) diry= static_cast<double>(*input);  
+                               if (j==2) dirz= static_cast<double>(*input);  
+                               tmp = static_cast<double>(*input);  
+                               sum += (tmp * tmp);
+                               ++input;
+                       }
+                       sum=sqrt(sum);
+                       *output++ = (unsigned char) abs( (255*dirx/sum) );
+                       *output++ = (unsigned char) abs( (255*diry/sum) );
+                       *output++ = (unsigned char) abs( (255*dirz/sum) );
+                       *output++ = 255;
+                       //              printf("%d %d %d   ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
+               }
+               
+               //      vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
+               
+               //      delete [] mag;
+       }
+       
+       
+       
+       //----------------------------------------------------------------------------
+       void vtkLookupTableEED::MapScalarsThroughTable2(void *input, 
+                                                                                                       unsigned char *output,
+                                                                                                       int inputDataType, 
+                                                                                                       int numberOfValues,
+                                                                                                       int inputIncrement,
+                                                                                                       int outputFormat)
+       {
+               
+               printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d   inputDataType=%d\n",inputIncrement,inputDataType);
+               
+               
+               //      if (this->UseMagnitude && inputIncrement > 1)
+               //  {
+               switch (inputDataType)
+               {
+                               vtkTemplateMacro(
+                                                                vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
+                                                                                                                          numberOfValues,inputIncrement,outputFormat);
+                                                                return
+                                                                );                             
+                       case VTK_BIT:
+                               vtkErrorMacro("Cannot comput magnitude of bit array.");
+                               break;
+                       default:
+                               vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
+               }
+               //  }
+               
+       }  
+       
+       
+       //----------------------------------------------------------------------------
+       void vtkLookupTableEED::PrintSelf(ostream& os, vtkIndent indent)
+       {
+               this->Superclass::PrintSelf(os,indent); 
+       }
+       
+       
+       
+       
+       //----------------------------------
+       //----------------------------------
+       //----------------------------------
+       //----------------------------------
+       //----------------------------------
+       
+       
+       
 namespace bbcreaMaracasVisu
 {
+       
+       
 
+       
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeTreeFilter)
 BBTK_BLACK_BOX_IMPLEMENTATION(TubeTreeFilter,bbtk::AtomicBlackBox);
 
 
+void TubeTreeFilter::SetRadioTube(int iGeneral,int numPoints, int iTube)
+{
+       int i;
+       double radiotmp=1;
+       int size=iGeneral+numPoints;
+       vtkDoubleArray *tubeRadius = vecTubeRadiosArray[iTube];
+
+       if (bbGetInputlstRadio().size()>=1) 
+       {
+          if (bbGetInputlstRadioLaw()==0)  // for All
+          {
+               radiotmp=bbGetInputlstRadio()[0];
+          }  // Law 0  for All
+
+          if (bbGetInputlstRadioLaw()==1)  // by segment
+          {
+              if (bbGetInputlstRadio().size()>=iTube) 
+              {
+                  radiotmp=bbGetInputlstRadio()[iTube];
+              } else {
+                  radiotmp=bbGetInputlstRadio()[ bbGetInputlstRadio().size()-1 ];
+              }
+          }  // Law 1  by segment
+
+          for (i=iGeneral;i<size;i++)
+          {
+               if (bbGetInputlstRadioLaw()==2)  // by point
+               {
+                   if (bbGetInputlstRadio().size()>=i) 
+                   {
+                       radiotmp=bbGetInputlstRadio()[i];
+                   } else {
+                       radiotmp=bbGetInputlstRadio()[ bbGetInputlstRadio().size()-1 ]; 
+                   } 
+               } // Law 2  by points
+               tubeRadius->SetTuple1(i-iGeneral, radiotmp );
+          } // for
+       tubeRadius->Modified();
+        }  // bbGetInputlstRadio().size()>=1
+
+
+}
+
 
 void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
 {
@@ -60,81 +298,53 @@ void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
 //EED  vtkDoubleArray *tubeRadius = vtkDoubleArray::New();
        tubeRadius->SetName("TubeRadius");
        tubeRadius->SetNumberOfTuples( numPoints );
-       for (i=iGeneral;i<size;i++)
-       {
-               tubeRadius->SetTuple1(i-iGeneral, bbGetInputlstRadio()[i] );
-       }
+       vecTubeRadiosArray.push_back( tubeRadius );
+
+
        polyData->GetPointData()->AddArray(tubeRadius);
        polyData->GetPointData()->SetActiveScalars("TubeRadius");
 
 
 
-// Adding spheres at the start and end of the tube
-
-       // Sphere start
-       i=iGeneral;
-       vtkSphereSource *vtksphereStart         = vtkSphereSource::New();
-       vtksphereStart->SetThetaResolution (10);
-       vtksphereStart->SetPhiResolution (10);
-       vtksphereStart->SetRadius( bbGetInputlstRadio()[i]  );
-       vtkPolyDataMapper *sphereMapperStart    = vtkPolyDataMapper::New();
-       sphereMapperStart->SetInput( vtksphereStart->GetOutput() );
-       vtkActor *sphereActorStart      = vtkActor::New();
-       sphereActorStart->SetMapper(sphereMapperStart);
-       sphereActorStart->SetOrigin( 0,0,0 );
-       sphereActorStart->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
-
-       // Sphere end
-       i=size-1;
-       vtkSphereSource *vtksphereEnd           = vtkSphereSource::New();
-       vtksphereEnd->SetThetaResolution (10);
-       vtksphereEnd->SetPhiResolution (10);
-       vtksphereEnd->SetRadius( bbGetInputlstRadio()[i]  );
-       vtkPolyDataMapper *sphereMapperEnd      = vtkPolyDataMapper::New();
-       sphereMapperEnd->SetInput( vtksphereEnd->GetOutput() );
-       vtkActor *sphereActorEnd        = vtkActor::New();
-       sphereActorEnd->SetMapper(sphereMapperEnd);
-       sphereActorEnd->SetOrigin( 0,0,0 );
-       sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
-
        vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
-//EED  vtkTubeFilter *tube = vtkTubeFilter::New();
        tube->SetInput(polyData);
        tube->SetNumberOfSides(nTv);
        tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
+        tube->CappingOn();
+       
+       vtkLookupTableEED* vLutEED                               = vtkLookupTableEED::New();
 
        vtkSmartPointer<vtkPolyDataMapper> mapper =     vtkSmartPointer<vtkPolyDataMapper>::New();
-//EED  vtkPolyDataMapper *mapper =     vtkPolyDataMapper::New();
        mapper->SetInputConnection(tube->GetOutputPort());
        mapper->ScalarVisibilityOn();
-       mapper->SetScalarModeToUsePointFieldData();
-
+       
+// EED fev 02/ 20112   
+       mapper->SetScalarModeToUsePointFieldData();     
+       mapper->SetLookupTable( vLutEED );
+       mapper->SelectColorArray( "points_axe" );
+       
        //              vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
     vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
        actor->SetMapper(mapper);
 
     vecVtkActors.push_back( actor );
-    vecVtkActors.push_back( sphereActorEnd );
-    vecVtkActors.push_back( sphereActorStart );
 
        // Interface Update    // Interface Update
      if  (bbGetInputRenderer()!=NULL )
      {
            bbGetInputRenderer()->AddActor( actor );
-           bbGetInputRenderer()->AddActor( sphereActorStart );
-           bbGetInputRenderer()->AddActor( sphereActorEnd );
      }
 }
 
 
 void TubeTreeFilter::SetGraphicProperties()
 {
-       int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
+    int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
 
-    vtkActor *actorTube;
-    vtkActor *actorSpherEnd;
-    vtkActor *actorSpherStart;
+    int iGeneral=0;
+    int numPoints;
 
+    vtkActor *actorTube;
 
     double r,g,b;
     r = bbGetInputColour()[0];
@@ -143,23 +353,19 @@ void TubeTreeFilter::SetGraphicProperties()
     for (iTube=0 ; iTube<sizeLstAxis; iTube++)
     {
         // Get Actor
-        actorTube=vecVtkActors[0+iTube*3];
-        actorSpherEnd=vecVtkActors[1+iTube*3];
-        actorSpherStart=vecVtkActors[2+iTube*3];
+
+        actorTube=vecVtkActors[iTube];
 
         // Set Opacity
         actorTube->GetProperty()->SetOpacity( bbGetInputOpacity() );
-        actorSpherEnd->GetProperty()->SetOpacity( bbGetInputOpacity() );
-        actorSpherStart->GetProperty()->SetOpacity( bbGetInputOpacity() );
 
-        //Set Colour
+       // Set Transform
         if ( bbGetInputTransform()!=NULL )
         {
             actorTube->SetUserTransform( bbGetInputTransform() );
-            actorSpherEnd->SetUserTransform( bbGetInputTransform() );
-            actorSpherStart->SetUserTransform( bbGetInputTransform() );
         }
 
+        //Set Colour
         if (bbGetInputColourLaw()==1)  // One solide colour
         {
             //
@@ -180,8 +386,13 @@ void TubeTreeFilter::SetGraphicProperties()
         }
 
         actorTube->GetProperty()->SetColor( r,g,b );
-        actorSpherEnd->GetProperty()->SetColor( r,g,b );
-        actorSpherStart->GetProperty()->SetColor( r,g,b );
+
+
+// Setting radio
+        numPoints = bbGetInputlstIndexs()[iTube];
+        SetRadioTube(iGeneral,numPoints,iTube);
+        iGeneral = iGeneral+numPoints;
+
     } // for
 }
 
@@ -215,6 +426,7 @@ void TubeTreeFilter::Process()
     //EED      vecVtkPolyData.clear();
     //EED      vecVtkPolyDataMaper.clear();
         vecVtkActors.clear();
+       vecTubeRadiosArray.clear();
 
         for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
         {
@@ -223,13 +435,14 @@ void TubeTreeFilter::Process()
             iGeneral = iGeneral+numPoints;
         }
 
-        if ( bbGetInputiTube()*3 <= (int)(vecVtkActors.size()-1) )
+        if ( bbGetInputiTube() <= (int)(vecVtkActors.size()-1) )
         {
-            bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube()*3 ] );
+            bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube() ] );
         } else         {
                 printf("TubeTreeFilter .ERROR. missing index vector...\n");
         }// vector Actor size
-    }
+
+    } // oldLstSize
     SetGraphicProperties();
 
        printf("EED TubeTreeFilter::Process end \n");
@@ -281,6 +494,11 @@ void TubeTreeFilter::bbUserSetDefaultValues()
     bbSetInputColourLaw(1);
     bbSetInputOpacity(1);
 
+   std::vector<double> radio;
+       radio.push_back(1);
+       bbSetInputlstRadio( radio );
+       bbSetInputlstRadioLaw( 0 );  // for all
+
 }
 //=====
 // 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)