X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fvtk%2Fsrc%2FbbvtkSurfaceTexture.cxx;h=ef9d87ed0dcc7d076a21e568c6cb5301bb4755cd;hb=ab91e25f4ca81c10788da1fdd681a87f1f17641e;hp=d59b7a866d2afd13f222ed180b9447bbf3fc74e9;hpb=251e090bd2628040b8f49de9de5c4cb31281f192;p=bbtk.git diff --git a/packages/vtk/src/bbvtkSurfaceTexture.cxx b/packages/vtk/src/bbvtkSurfaceTexture.cxx index d59b7a8..ef9d87e 100644 --- a/packages/vtk/src/bbvtkSurfaceTexture.cxx +++ b/packages/vtk/src/bbvtkSurfaceTexture.cxx @@ -5,7 +5,7 @@ #include "bbvtkPackage.h" #include - +#include namespace bbvtk { @@ -17,7 +17,6 @@ BBTK_BLACK_BOX_IMPLEMENTATION(SurfaceTexture,bbtk::AtomicBlackBox); //===== void SurfaceTexture::Process() { - // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value @@ -33,86 +32,166 @@ void SurfaceTexture::Process() // bbSetOutputOut( bbGetInputIn() ); // std::cout << "Output value = " <GetSpacing(spc); - bbGetInputImage()->GetScalarRange(range); - bbGetInputImage()->GetWholeExtent(ext); - int maxX = ext[1]-ext[0]+1; - int maxY = ext[3]-ext[2]+1; - int maxZ = ext[5]-ext[4]+1; - - if (firsttime==true) + int i; + double spc[3]; + double range[2]; + int ext[6]; + if ((bbGetInputImage()!=NULL) && (bbGetInputMesh()!=NULL)) { - firsttime=false; - // Generate the colors for each point based on the color map - colors = vtkUnsignedCharArray::New(); - colors->SetNumberOfComponents(3); - colors->SetName("Colors"); + bbGetInputImage()->GetSpacing(spc); + bbGetInputImage()->GetScalarRange(range); + //EED 2017-01-01 Migration VTK7 + #if VTK_MAJOR_VERSION <= 5 + bbGetInputImage()->GetWholeExtent(ext); + #else + bbGetInputImage()->GetExtent(ext); + #endif + int maxX = ext[1]-ext[0]+1; + int maxY = ext[3]-ext[2]+1; + int maxZ = ext[5]-ext[4]+1; - // Create the color map - if (bbGetInputColorType()==1) + if (backColorType!=bbGetInputColorType() ) { - colorLookupTableWL = vtkWindowLevelLookupTable::New(); - colorLookupTable=colorLookupTableWL; - } else { - colorLookupTable = vtkLookupTable::New(); + backColorType = bbGetInputColorType(); + if (colors!=NULL) { colors->Delete(); } +// if (colorLookupTable!=NULL) { colorLookupTable->Delete(); } +// if (colorLookupTableWL!=NULL) { colorLookupTableWL->Delete(); } + + +// firsttime=false; + // Generate the colors for each point based on the color map + colors = vtkUnsignedCharArray::New(); + colors->SetNumberOfComponents(3); +// colors->SetName("ColorsEED"); + // Create the color map + if (bbGetInputColorType()==1) + { + colorLookupTableWL = vtkWindowLevelLookupTable::New(); + colorLookupTableWL->InverseVideoOn(); + colorLookupTable = colorLookupTableWL; + } else { + colorLookupTable = vtkLookupTable::New(); + } + colorLookupTable->SetTableRange(range[0],range[1]); + colorLookupTable->Build(); + double rgba1[4]; + double rgba2[4]; + for (int iLookTable = 0; iLookTable<128; iLookTable++) + { + colorLookupTable->GetTableValue( iLookTable, rgba1); + colorLookupTable->GetTableValue(256-1-iLookTable, rgba2); + colorLookupTable->SetTableValue(256-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]); + colorLookupTable->SetTableValue( iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]); + } // for iLookTable + + //EED 2018-06-8 ***********************ARDS Projet*********************************************** + if (bbGetInputColorType()==2) + { + int tableSize=256; + colorLookupTable = vtkLookupTable::New(); + // colorLookupTable->SetNumberOfTableValues(tableSize); + colorLookupTable->SetTableRange(range[0],range[1]); + // colorLookupTable->SetTableRange(0,11); + colorLookupTable->Build(); + + /* + for (unsigned int i = 0; i < tableSize; ++i) + { + colorLookupTable->SetTableValue(i, + vtkMath::Random(.25, 1.0), + vtkMath::Random(.25, 1.0), + vtkMath::Random(.25, 1.0), + 1.0); } - } - colorLookupTable->SetTableRange(range[0],range[1]); - colorLookupTable->Build(); - bbGetInputMesh()->GetPointData()->SetScalars(colors); - - if (bbGetInputColorType()==1) - { - colorLookupTableWL->SetLevel( bbGetInputColorLevel() ); - colorLookupTableWL->SetWindow( bbGetInputColorWindow() ); - } + */ + double rgba1[4]; + double rgba2[4]; + int i,j; + for (int iLookTable = 0; iLookTableGetTableValue(i, rgba1); + colorLookupTable->GetTableValue(j, rgba2); + + colorLookupTable->SetTableValue(j, rgba1[0],rgba1[1],rgba1[2],rgba1[3]); + colorLookupTable->SetTableValue(i, rgba2[0],rgba2[1],rgba2[2],rgba2[3]); + } // for iLookTable + } // type 2 + if (bbGetInputColorType()==3) + { + int tableSize=13; + colorLookupTable = vtkLookupTable::New(); + colorLookupTable->SetNumberOfTableValues(tableSize); + colorLookupTable->SetTableRange(6,range[1]); + colorLookupTable->Build(); + colorLookupTable->SetTableValue(0, 1 ,1 ,1 ,1); + colorLookupTable->SetTableValue(1, 1 ,0 ,0 ,1); + colorLookupTable->SetTableValue(2, 0 ,1 ,0 ,1); + colorLookupTable->SetTableValue(3, 0 ,0 ,1 ,1); + colorLookupTable->SetTableValue(4, 0 ,1 ,1 ,1); + colorLookupTable->SetTableValue(5, 1 ,1 ,0 ,1); + colorLookupTable->SetTableValue(6, 1 ,0 ,1 ,1); + colorLookupTable->SetTableValue(7, 0.5,1 ,1 ,1); + colorLookupTable->SetTableValue(8, 1 ,0.5,1 ,1); + colorLookupTable->SetTableValue(9, 1 ,1 ,0.5,1); + colorLookupTable->SetTableValue(10,1 ,0.5,0.5,1); + colorLookupTable->SetTableValue(11,0.5,0.5,1 ,1); + } // type 3 + } // firsttime - int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents(); - for(i = 0; i < missingpoints; i++) - { - colors->InsertNextTuple3(0,0,0); - } - - if (bbGetInputTransform()!=NULL) - { - bbGetInputTransform()->Update(); - } - - unsigned short gl; - double p1[3]; - double p2[3]; - double dcolor[3]; - for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++) - { - if (bbGetInputTransform()!=NULL) + + + bbGetInputMesh()->GetPointData()->SetScalars(colors); + if (bbGetInputColorType()==1) { - bbGetInputMesh()->GetPoint(i,p1); - bbGetInputTransform()->TransformPoint(p1,p2); + colorLookupTableWL->SetLevel( bbGetInputColorLevel() ); + colorLookupTableWL->SetWindow( bbGetInputColorWindow() ); + } + if (bbGetInputExternalLookupTable()!=NULL) + { + generalLookupTable = bbGetInputExternalLookupTable(); } else { - bbGetInputMesh()->GetPoint(i,p2); + generalLookupTable = colorLookupTable; } - p2[0] = p2[0]/spc[0]; - p2[1] = p2[1]/spc[1]; - p2[2] = p2[2]/spc[2]; - - if ( (p2[0]>=0) && (p2[0]=0) && (p2[1]=0) && (p2[2]GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents(); + for(i = 0; i < missingpoints; i++) { - gl = bbGetInputImage()->GetScalarComponentAsDouble(p2[0], p2[1], p2[2],0); - } else { - gl=0; + colors->InsertNextTuple3(0,0,0); + } + if (bbGetInputTransform()!=NULL) + { + bbGetInputTransform()->Update(); } - colorLookupTable->GetColor(gl, dcolor); - colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]); - } // for i - bbGetInputMesh()->Modified(); - + double gl; + double p1[3]; + double p2[3]; + double dcolor[3]; + for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++) + { + if (bbGetInputTransform()!=NULL) + { + bbGetInputMesh()->GetPoint(i,p1); + bbGetInputTransform()->TransformPoint(p1,p2); + } else { + bbGetInputMesh()->GetPoint(i,p2); + } + p2[0] = p2[0]/spc[0]; + p2[1] = p2[1]/spc[1]; + p2[2] = p2[2]/spc[2]; + if ( (p2[0]>=0) && (p2[0]=0) && (p2[1]=0) && (p2[2]GetScalarComponentAsDouble(round(p2[0]), round(p2[1]), round(p2[2]),0); + } else { + gl=0; + } + generalLookupTable->GetColor(gl, dcolor); + colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]); + } // for i + bbGetInputMesh()->Modified(); + } // if Image && Mesh } + //===== // 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) //===== @@ -127,11 +206,12 @@ void SurfaceTexture::bbUserSetDefaultValues() bbSetInputColorLevel(500); bbSetInputColorWindow(500); bbSetInputTransform(NULL); + bbSetInputExternalLookupTable(NULL); - firsttime = true; - colors = NULL; - colorLookupTable = NULL; - colorLookupTableWL = NULL; + backColorType = -999; + colors = NULL; + colorLookupTable = NULL; + colorLookupTableWL = NULL; } //===== // 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)