]> Creatis software - creaMaracasVisu.git/commitdiff
2107 Bug Color Tube Axes visu in 3D
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Mon, 19 Aug 2013 13:37:37 +0000 (15:37 +0200)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Mon, 19 Aug 2013 13:37:37 +0000 (15:37 +0200)
bbtk/src/bbcreaMaracasVisuTubeFilter.cxx
bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx
bbtk/src/bbcreaMaracasVisuTubeTreeFilter.h
bbtk/src/bbmaracasvisuAxeVolume.cxx
bbtk/src/bbmaracasvisuDrawAxe3D.cxx
bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
bbtk/src/bbmaracasvisuDrawAxisTree3D.h

index a3b0184eca1c53e43df3037620e765e55a152e9d..c25e3e5bb8411b9c2b0be0849a7609223cf93bf2 100644 (file)
@@ -132,14 +132,23 @@ namespace bbcreaMaracasVisu
                polyData->SetPoints(points);
                polyData->SetLines(lines);
                
-
+               double radio;
                // Varying tube radius using sine-function
                vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
                tubeRadius->SetName("TubeRadius");
-               tubeRadius->SetNumberOfTuples( lstRadius.size() );
-               for (i=0 ;i<lstRadius.size() ; i++)
+               tubeRadius->SetNumberOfTuples( lstPointX.size() );
+               for (i=0 ;i<lstPointX.size() ; i++)
                {
-                       tubeRadius->SetTuple1(i, lstRadius[i] );
+                       if (lstRadius.size()==0)
+                       { 
+                          radio=1;
+                       } else if (i<lstRadius.size()) {
+                         radio = lstRadius[i];
+                       } else if (i>=lstRadius.size()) {
+                         radio= lstRadius[ lstRadius.size()-1 ];
+                       }   
+
+                       tubeRadius->SetTuple1(i, radio );
                }
                polyData->GetPointData()->AddArray(tubeRadius);
                polyData->GetPointData()->SetActiveScalars("TubeRadius");
@@ -276,6 +285,10 @@ void TubeFilter::bbUserSetDefaultValues()
        colour.push_back(0.0);
        colour.push_back(0.0);
        bbSetInputColour(colour);
+
+       std::vector<double> lstRadius;
+       lstRadius.push_back(1);
+        bbSetInputColour(lstRadius);
 }
        
 //===== 
index 94f13067779bf29f81ec55ec28cac04af869748f..80946c0447e0f488add37ffe035ea726d9929084 100644 (file)
@@ -215,6 +215,49 @@ 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)
 {
@@ -256,10 +299,9 @@ 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");
 
@@ -329,7 +371,10 @@ void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
 
 void TubeTreeFilter::SetGraphicProperties()
 {
-       int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
+    int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
+
+    int iGeneral=0;
+    int numPoints;
 
     vtkActor *actorTube;
     vtkActor *actorSpherEnd;
@@ -352,7 +397,7 @@ void TubeTreeFilter::SetGraphicProperties()
         actorSpherEnd->GetProperty()->SetOpacity( bbGetInputOpacity() );
         actorSpherStart->GetProperty()->SetOpacity( bbGetInputOpacity() );
 
-        //Set Colour
+       // Set Transform
         if ( bbGetInputTransform()!=NULL )
         {
             actorTube->SetUserTransform( bbGetInputTransform() );
@@ -360,6 +405,7 @@ void TubeTreeFilter::SetGraphicProperties()
             actorSpherStart->SetUserTransform( bbGetInputTransform() );
         }
 
+        //Set Colour
         if (bbGetInputColourLaw()==1)  // One solide colour
         {
             //
@@ -382,6 +428,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
 }
 
@@ -415,6 +468,7 @@ void TubeTreeFilter::Process()
     //EED      vecVtkPolyData.clear();
     //EED      vecVtkPolyDataMaper.clear();
         vecVtkActors.clear();
+       vecTubeRadiosArray.clear();
 
         for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
         {
@@ -429,7 +483,7 @@ void TubeTreeFilter::Process()
         } else         {
                 printf("TubeTreeFilter .ERROR. missing index vector...\n");
         }// vector Actor size
-    }
+    } // oldLstSize
     SetGraphicProperties();
 
        printf("EED TubeTreeFilter::Process end \n");
@@ -481,6 +535,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)
index 2d5ec1292f81742de12b1df9c7336b40dde1c028..02911c812a5cbd5cb9e8e50b0448ba3dd1bc5f0c 100644 (file)
@@ -110,6 +110,7 @@ class bbcreaMaracasVisu_EXPORT TubeTreeFilter
        BBTK_DECLARE_INPUT(lstPointY    , std::vector<double>);
        BBTK_DECLARE_INPUT(lstPointZ    , std::vector<double>);
        BBTK_DECLARE_INPUT(lstRadio     , std::vector<double>);
+       BBTK_DECLARE_INPUT(lstRadioLaw  , int);
        BBTK_DECLARE_INPUT(Colour       , std::vector<double>);
        BBTK_DECLARE_INPUT(ColourLaw    , int);
        BBTK_DECLARE_INPUT(Transform    , vtkLinearTransform *);
@@ -121,8 +122,11 @@ class bbcreaMaracasVisu_EXPORT TubeTreeFilter
 
   private:
        std::vector<vtkActor*>          vecVtkActors;
+       std::vector< vtkDoubleArray* >  vecTubeRadiosArray;
+
        void DrawOneTube(int iGeneral,int numPoints, int iTube);
        void SetGraphicProperties();
+       void SetRadioTube(int iGeneral,int numPoints, int iTube);
     int oldLstSize;
 
 //=====
@@ -141,15 +145,15 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(TubeTreeFilter,bbtk::AtomicBlackBox);
        BBTK_INPUT(TubeTreeFilter,lstPointX,"lstPointX",std::vector<double>,"");
        BBTK_INPUT(TubeTreeFilter,lstPointY,"lstPointY",std::vector<double>,"");
        BBTK_INPUT(TubeTreeFilter,lstPointZ,"lstPointZ",std::vector<double>,"");
-       BBTK_INPUT(TubeTreeFilter,lstRadio,"lstRadio",std::vector<double>,"");
+       BBTK_INPUT(TubeTreeFilter,lstRadio,"lstRadio (default 1) ",std::vector<double>,"");
+       BBTK_INPUT(TubeTreeFilter,lstRadioLaw,"0(default) radio for all, 1 radio by segment, 2 radio by point",int,"");
        BBTK_INPUT(TubeTreeFilter,Colour,"Colour",std::vector<double>,"");
-    BBTK_INPUT(TubeTreeFilter,ColourLaw,"ColorLaw 1(default) solid color, 2 color by segment, 3 color for each point",int,"");
+       BBTK_INPUT(TubeTreeFilter,ColourLaw,"ColorLaw 1(default) solid color, 2 color by segment, 3 color for each point",int,"");
        BBTK_INPUT(TubeTreeFilter,Transform,"vtkTransform", vtkLinearTransform *,"");
        BBTK_INPUT(TubeTreeFilter,iTube,"iTube",int,"");
        BBTK_INPUT(TubeTreeFilter,Opacity,"Opacity",double,"");
-       BBTK_OUTPUT(TubeTreeFilter,OutTube,"Tube[iTube]",vtkProp3D *,"");
-
 
+       BBTK_OUTPUT(TubeTreeFilter,OutTube,"Tube[iTube]",vtkProp3D *,"");
 
 BBTK_END_DESCRIBE_BLACK_BOX(TubeTreeFilter);
 //=====
index 40abad8a9031d170c1f814bb4ad95f73cb5166b3..53c5d385544f9480f72a17e724c35ffcfce68719 100644 (file)
@@ -85,7 +85,7 @@ void AxeVolume::Process()
                p++;
        }
 
-       for (iAxe=0 ; iAxe<sizeAxe-1; iAxe++)
+       for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
         {
                if (sizeLstPointR<iAxe)
                {
index 9d65ade80712dd580a5db61edbd0472ae07bd1a9..6a369f3aa6c6e7404127f4ff9db4bd35231315cf 100644 (file)
@@ -40,10 +40,13 @@ BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,DrawAxe3D)
 BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxe3D,bbtk::AtomicBlackBox);
 void DrawAxe3D::Process()
 {
+printf("EED DrawAxe3D::Process Start\n");
        std::vector< double > vectx = bbGetInputlstPointX();
        std::vector< double > vecty = bbGetInputlstPointY();
        std::vector< double > vectz = bbGetInputlstPointZ();    
 
+printf("EED DrawAxe3D::Process size vector %d %d %d\n",vectx.size(),vecty.size(),vectz.size() );
+
 //     vtkImageData* img = bbGetInputImage();  
        unsigned int i;
        double spc[3];  
@@ -52,43 +55,57 @@ void DrawAxe3D::Process()
        spc[1]=1;
        spc[2]=1;
 
-       if(!vectx.empty()&&!vecty.empty()&&!vectz.empty()){
+       if(!vectx.empty()&&!vecty.empty()&&!vectz.empty())
+        {
+printf("EED DrawAxe3D::Process 1\n");
                vtkPoints* allPoints = vtkPoints::New( );
                vtkCellArray* allTopology = vtkCellArray::New( );
                allTopology->InsertNextCell( vectx.size() );
+printf("EED DrawAxe3D::Process 2\n");
 
                for( i = 0; i < vectx.size( ); i++) {   
                        //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
                        //hay parametro dicom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
                        allPoints->InsertNextPoint( vectx[i]*spc[0],  vecty[i]*spc[1], vectz[i]*spc[2] );
                        allTopology->InsertCellPoint( i );
+printf("EED DrawAxe3D::Process 3\n");
                } // rof
                mallData->SetPoints( allPoints );
                mallData->SetLines( allTopology );
+printf("EED DrawAxe3D::Process 4\n");
                allPoints->Delete();
                allTopology->Delete();  
+printf("EED DrawAxe3D::Process 5\n");
        }
 
        mvtkactor->GetProperty()->SetColor( bbGetInputColour()[0],  
                                bbGetInputColour()[1], 
                                bbGetInputColour()[2] );
+printf("EED DrawAxe3D::Process 6\n");
        //EC Axe Opacity property added
        ///Default Values
        double opacity=bbGetInputOpacity();
        mvtkactor->GetProperty()->SetOpacity( opacity );
+printf("EED DrawAxe3D::Process 7\n");
        if ( bbGetInputTransform()!=NULL )
        {
+printf("EED DrawAxe3D::Process 8\n");
                mvtkactor->SetUserTransform( bbGetInputTransform() );
        }
 
      // Interface Update
      if ((firsttime==true) && (bbGetInputRenderer()!=NULL ))
      {
+printf("EED DrawAxe3D::Process 9\n");
                firsttime=false;
            bbGetInputRenderer()->AddActor( mvtkactor );
      }
+printf("EED DrawAxe3D::Process End\n");
 }
 
+
+
+
 void DrawAxe3D::bbUserSetDefaultValues()
 {
        firsttime        = true;
@@ -102,6 +119,8 @@ void DrawAxe3D::bbUserSetDefaultValues()
     colour.push_back(0.0);
     bbSetInputColour(colour);
     bbSetInputOpacity(1.0);
+    bbSetInputRenderer(NULL);
+    bbSetInputTransform(NULL);
 }
 
 
index cdabc926eb9d63c2f1f361366b2e452b1a8d9350..e43b35b960c6ee3e22875114510ef69d1c524038 100644 (file)
 #include "bbcreaMaracasVisuPackage.h"
 #include "vtkLinearTransform.h"
 
+#include "vtkUnsignedCharArray.h"
+#include "vtkCellData.h"
+#include "vtkPolyLine.h"
+#include "vtkLine.h"
+
+
+
 namespace bbcreaMaracasVisu
 {
 
@@ -37,10 +44,12 @@ BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxisTree3D,bbtk::AtomicBlackBox);
 
 void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
 {
+printf("EED DrawAxisTree3D::DrawOneAxis Start \n");
        vtkPolyData                     *polydata               = vtkPolyData::New( );
        vtkPolyDataMapper       *polydatamapper = vtkPolyDataMapper::New();
        vtkActor                        *vtkactor               = vtkActor::New();
 
+//     polydatamapper->ScalarVisibilityOff();
        polydatamapper->SetInput(polydata);
        vtkactor->SetMapper(polydatamapper);
 
@@ -60,8 +69,9 @@ void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
 
        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++)
@@ -72,10 +82,37 @@ void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
                                                                                bbGetInputlstPointY()[i]*spc[1],
                                                                                bbGetInputlstPointZ()[i]*spc[2] );
 //                     printf("DrawAxisTree3D::DrawOneAxis point  %d -> %f, %f, %f \n", i,  bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
-                       allTopology->InsertCellPoint( i-iGeneral );
+
+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();
        }
@@ -83,18 +120,54 @@ void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
        // color
        double r,g,b;
 
-       if ( (iAxis*3+1) < (int)(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];
                        b = bbGetInputColour()[2+iAxis*3];
-       } else {
+               } else {
                        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);
+printf("EED DrawAxisTree3D::DrawOneAxis iPoint=%d    size=%d  rgb=%f% f% f \n", iPoint , bbGetInputColour().size() , r,g,b);
+                       colors->InsertNextTuple3(r,g,b);
+               }
+               polydata->GetCellData()->SetScalars(colors);
+               polydata->Modified();
+       }  // Law 3 color for each point
 
-       vtkactor->GetProperty()->SetColor( r,g,b );
        vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
        vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
 
@@ -108,6 +181,7 @@ void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
      {
            bbGetInputRenderer()->AddActor( vtkactor );
      }
+printf("EED DrawAxisTree3D::DrawOneAxis End \n");
 }
 
 
@@ -154,7 +228,7 @@ void DrawAxisTree3D::Process()
         {
             bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
         } else         {
-            printf("TubeTreeFilter .ERROR. missing index vector...\n");
+            printf("DrawAxisTree3D .ERROR. missing index vector...\n");
         }
 
     } else {// if oldLstSize
index 301018f937dd93cd91426a8d401af28165a7459f..fb3a67aee766fd2d32cd5d29e3e699ebf2c30843 100644 (file)
@@ -84,7 +84,7 @@ BBTK_CATEGORY("actor");
   BBTK_INPUT(DrawAxisTree3D,lstPointZ,"lstPointZ",std::vector<double>,"");
   BBTK_INPUT(DrawAxisTree3D,lstRadio,"lstRadio",std::vector<double>,"");
   BBTK_INPUT(DrawAxisTree3D,Colour,"Colour  R1 G1 B1 R2 G2 B2 ...  range[0..1]",std::vector<double>,"");
-  BBTK_INPUT(DrawAxisTree3D,ColourLaw,"ColorLaw 1(default) solid color, 2 color by segment, 3 color for each point",int,"");
+  BBTK_INPUT(DrawAxisTree3D,ColourLaw,"ColorLaw 1(default) solid color, 2 color by segment (random if is necessary) , 3 color for each point",int,"");
   BBTK_INPUT(DrawAxisTree3D,Transform,"vtkTransform", vtkLinearTransform *,"");
   BBTK_INPUT(DrawAxisTree3D,Opacity,"Opacity",double,"");
   BBTK_INPUT(DrawAxisTree3D,LineWidth,"LineWidth (default 0.5)",double,"");