X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=bbtk%2Fsrc%2FbbcreaMaracasVisuTubeTreeFilter.cxx;h=f431595c9a0219e8dfaa7f353ec610c69b953359;hb=0cc1383dff9255c9929097bbe9f44a6f4f31c97a;hp=8f2a3ce5b96a44cd26d1a401feb3b34d085db377;hpb=11899b8f7418abb4b95b70cd574d2de1c7f353ca;p=creaMaracasVisu.git diff --git a/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx b/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx index 8f2a3ce..f431595 100644 --- a/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx +++ b/bbtk/src/bbcreaMaracasVisuTubeTreeFilter.cxx @@ -10,11 +10,182 @@ #include #include #include +#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: ["<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 + 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(*input); + if (j==1) diry= static_cast(*input); + if (j==2) dirz= static_cast(*input); + tmp = static_cast(*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(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); @@ -98,17 +269,21 @@ void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube) sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] ); vtkSmartPointer tube = vtkSmartPointer::New(); -//EED vtkTubeFilter *tube = vtkTubeFilter::New(); tube->SetInput(polyData); tube->SetNumberOfSides(nTv); tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar(); + + vtkLookupTableEED* vLutEED = vtkLookupTableEED::New(); vtkSmartPointer mapper = vtkSmartPointer::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 actor =vtkSmartPointer::New(); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper);