From: Eduardo DAVILA Date: Mon, 19 Aug 2013 13:37:37 +0000 (+0200) Subject: 2107 Bug Color Tube Axes visu in 3D X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=bb69ea7be3f8baa4122fb51d04b4ec6ce906c809;p=creaMaracasVisu.git 2107 Bug Color Tube Axes visu in 3D --- diff --git a/bbtk/src/bbcreaMaracasVisuTubeFilter.cxx b/bbtk/src/bbcreaMaracasVisuTubeFilter.cxx index a3b0184..c25e3e5 100644 --- a/bbtk/src/bbcreaMaracasVisuTubeFilter.cxx +++ b/bbtk/src/bbcreaMaracasVisuTubeFilter.cxx @@ -132,14 +132,23 @@ namespace bbcreaMaracasVisu polyData->SetPoints(points); polyData->SetLines(lines); - + double radio; // Varying tube radius using sine-function vtkSmartPointer tubeRadius = vtkSmartPointer::New(); tubeRadius->SetName("TubeRadius"); - tubeRadius->SetNumberOfTuples( lstRadius.size() ); - for (i=0 ;iSetNumberOfTuples( lstPointX.size() ); + for (i=0 ;iSetTuple1(i, lstRadius[i] ); + if (lstRadius.size()==0) + { + radio=1; + } 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 lstRadius; + lstRadius.push_back(1); + bbSetInputColour(lstRadius); } //===== diff --git a/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx b/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx index 94f1306..80946c0 100644 --- a/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx +++ b/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx @@ -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=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;iSetTuple1(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 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) diff --git a/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.h b/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.h index 2d5ec12..02911c8 100644 --- a/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.h +++ b/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.h @@ -110,6 +110,7 @@ class bbcreaMaracasVisu_EXPORT TubeTreeFilter BBTK_DECLARE_INPUT(lstPointY , std::vector); BBTK_DECLARE_INPUT(lstPointZ , std::vector); BBTK_DECLARE_INPUT(lstRadio , std::vector); + BBTK_DECLARE_INPUT(lstRadioLaw , int); BBTK_DECLARE_INPUT(Colour , std::vector); BBTK_DECLARE_INPUT(ColourLaw , int); BBTK_DECLARE_INPUT(Transform , vtkLinearTransform *); @@ -121,8 +122,11 @@ class bbcreaMaracasVisu_EXPORT TubeTreeFilter private: std::vector 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,""); BBTK_INPUT(TubeTreeFilter,lstPointY,"lstPointY",std::vector,""); BBTK_INPUT(TubeTreeFilter,lstPointZ,"lstPointZ",std::vector,""); - BBTK_INPUT(TubeTreeFilter,lstRadio,"lstRadio",std::vector,""); + BBTK_INPUT(TubeTreeFilter,lstRadio,"lstRadio (default 1) ",std::vector,""); + 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,""); - 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); //===== diff --git a/bbtk/src/bbmaracasvisuAxeVolume.cxx b/bbtk/src/bbmaracasvisuAxeVolume.cxx index 40abad8..53c5d38 100644 --- a/bbtk/src/bbmaracasvisuAxeVolume.cxx +++ b/bbtk/src/bbmaracasvisuAxeVolume.cxx @@ -85,7 +85,7 @@ void AxeVolume::Process() p++; } - for (iAxe=0 ; iAxe 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); } diff --git a/bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx b/bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx index cdabc92..e43b35b 100644 --- a/bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx +++ b/bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx @@ -27,6 +27,13 @@ #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 %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 vertex = vtkSmartPointer::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; iPointSetTuple3(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 diff --git a/bbtk/src/bbmaracasvisuDrawAxisTree3D.h b/bbtk/src/bbmaracasvisuDrawAxisTree3D.h index 301018f..fb3a67a 100644 --- a/bbtk/src/bbmaracasvisuDrawAxisTree3D.h +++ b/bbtk/src/bbmaracasvisuDrawAxisTree3D.h @@ -84,7 +84,7 @@ BBTK_CATEGORY("actor"); BBTK_INPUT(DrawAxisTree3D,lstPointZ,"lstPointZ",std::vector,""); BBTK_INPUT(DrawAxisTree3D,lstRadio,"lstRadio",std::vector,""); BBTK_INPUT(DrawAxisTree3D,Colour,"Colour R1 G1 B1 R2 G2 B2 ... range[0..1]",std::vector,""); - 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,"");