]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
2107 Bug Color Tube Axes visu in 3D
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuDrawAxisTree3D.cxx
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