//===== // 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) //===== #include "bbcreaMaracasVisuTubeTreeFilter.h" #include "bbcreaMaracasVisuPackage.h" #include #include #include #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); void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube) { int i; unsigned int nTv = 8; // No. of surface elements for each tube vertex double spc[3]; // img->GetSpacing(spc); spc[0]=1; spc[1]=1; spc[2]=1; int size=iGeneral+numPoints; // Create points and cells vtkSmartPointer points = vtkSmartPointer::New(); //EED vtkPoints *points = vtkPoints::New(); vtkSmartPointer lines = vtkSmartPointer::New(); //EED vtkCellArray *lines = vtkCellArray::New(); lines->InsertNextCell( numPoints ); for (i=iGeneral;iInsertPoint(i-iGeneral, bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] ); lines->InsertCellPoint(i-iGeneral); } vtkSmartPointer polyData = vtkSmartPointer::New(); //EED vtkPolyData *polyData = vtkPolyData::New(); polyData->SetPoints(points); polyData->SetLines(lines); // Varying tube radius using sine-function vtkSmartPointer tubeRadius = vtkSmartPointer::New(); //EED vtkDoubleArray *tubeRadius = vtkDoubleArray::New(); tubeRadius->SetName("TubeRadius"); tubeRadius->SetNumberOfTuples( numPoints ); for (i=iGeneral;iSetTuple1(i-iGeneral, bbGetInputlstRadio()[i] ); } polyData->GetPointData()->AddArray(tubeRadius); polyData->GetPointData()->SetActiveScalars("TubeRadius"); // Adding spheres at the start and end of the tube // Sphere start i=iGeneral; vtkSphereSource *vtksphereStart = vtkSphereSource::New(); vtksphereStart->SetThetaResolution (10); vtksphereStart->SetPhiResolution (10); vtksphereStart->SetRadius( bbGetInputlstRadio()[i] ); vtkPolyDataMapper *sphereMapperStart = vtkPolyDataMapper::New(); sphereMapperStart->SetInput( vtksphereStart->GetOutput() ); vtkActor *sphereActorStart = vtkActor::New(); sphereActorStart->SetMapper(sphereMapperStart); sphereActorStart->SetOrigin( 0,0,0 ); sphereActorStart->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] ); // Sphere end i=size-1; vtkSphereSource *vtksphereEnd = vtkSphereSource::New(); vtksphereEnd->SetThetaResolution (10); vtksphereEnd->SetPhiResolution (10); vtksphereEnd->SetRadius( bbGetInputlstRadio()[i] ); vtkPolyDataMapper *sphereMapperEnd = vtkPolyDataMapper::New(); sphereMapperEnd->SetInput( vtksphereEnd->GetOutput() ); vtkActor *sphereActorEnd = vtkActor::New(); sphereActorEnd->SetMapper(sphereMapperEnd); sphereActorEnd->SetOrigin( 0,0,0 ); sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] ); vtkSmartPointer tube = vtkSmartPointer::New(); tube->SetInput(polyData); tube->SetNumberOfSides(nTv); tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar(); vtkLookupTableEED* vLutEED = vtkLookupTableEED::New(); vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputConnection(tube->GetOutputPort()); mapper->ScalarVisibilityOn(); // EED fev 02/ 20112 mapper->SetScalarModeToUsePointFieldData(); mapper->SetLookupTable( vLutEED ); mapper->SelectColorArray( "points_axe" ); // vtkSmartPointer actor =vtkSmartPointer::New(); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); vecVtkActors.push_back( actor ); vecVtkActors.push_back( sphereActorEnd ); vecVtkActors.push_back( sphereActorStart ); // Interface Update // Interface Update if (bbGetInputRenderer()!=NULL ) { bbGetInputRenderer()->AddActor( actor ); bbGetInputRenderer()->AddActor( sphereActorStart ); bbGetInputRenderer()->AddActor( sphereActorEnd ); } } void TubeTreeFilter::SetGraphicProperties() { int iTube,sizeLstAxis=bbGetInputlstIndexs().size(); vtkActor *actorTube; vtkActor *actorSpherEnd; vtkActor *actorSpherStart; double r,g,b; r = bbGetInputColour()[0]; g = bbGetInputColour()[1]; b = bbGetInputColour()[2]; for (iTube=0 ; iTubeGetProperty()->SetOpacity( bbGetInputOpacity() ); actorSpherEnd->GetProperty()->SetOpacity( bbGetInputOpacity() ); actorSpherStart->GetProperty()->SetOpacity( bbGetInputOpacity() ); //Set Colour if ( bbGetInputTransform()!=NULL ) { actorTube->SetUserTransform( bbGetInputTransform() ); actorSpherEnd->SetUserTransform( bbGetInputTransform() ); actorSpherStart->SetUserTransform( bbGetInputTransform() ); } if (bbGetInputColourLaw()==1) // One solide colour { // } if (bbGetInputColourLaw()==2) // color for differents tubes { if ( (iTube*3+1) < (int)(bbGetInputColour().size()) ) { r = bbGetInputColour()[0+iTube*3]; g = bbGetInputColour()[1+iTube*3]; b = bbGetInputColour()[2+iTube*3]; } else { r = (rand() % 100) / 100.0; g = (rand() % 100) / 100.0; b = (rand() % 100) / 100.0; } } actorTube->GetProperty()->SetColor( r,g,b ); actorSpherEnd->GetProperty()->SetColor( r,g,b ); actorSpherStart->GetProperty()->SetColor( r,g,b ); } // for } //===== // 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) //===== void TubeTreeFilter::Process() { printf("EED TubeTreeFilter::Process start \n"); int iGeneral=0; int iTube,sizeLstAxis=bbGetInputlstIndexs().size(); int iActor,sizeActors = vecVtkActors.size(); int numPoints; if (oldLstSize!=sizeLstAxis) { oldLstSize=sizeLstAxis; for (iActor=0 ; iActorRemoveActor( vecVtkActors[iActor] ); //EED vecVtkPolyData[iActor]->Delete(); //EED vecVtkPolyDataMaper[iActor]->Delete(); //EED vecVtkActors[iActor]->Delete(); } } //EED vecVtkPolyData.clear(); //EED vecVtkPolyDataMaper.clear(); vecVtkActors.clear(); for ( iTube=0 ; iTube colour; // 0- gray colour.push_back(0.5); colour.push_back(0.5); colour.push_back(0.5); // 1- red colour.push_back(1.0); colour.push_back(0.0); colour.push_back(0.0); // 2- blue colour.push_back(0.0); colour.push_back(0.0); colour.push_back(1.0); // 3- yellow colour.push_back(1.0); colour.push_back(1.0); colour.push_back(0.0); // 4- green colour.push_back(0.0); colour.push_back(1.0); colour.push_back(0.0); // 5- colour.push_back(0.0); colour.push_back(1.0); colour.push_back(1.0); // 6- colour.push_back(0.5); colour.push_back(0.5); colour.push_back(0.5); bbSetInputColour(colour); bbSetInputTransform(NULL); bbSetInputRenderer(NULL); bbSetInputColourLaw(1); bbSetInputOpacity(1); } //===== // 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) //===== void TubeTreeFilter::bbUserInitializeProcessing() { // THE INITIALIZATION METHOD BODY : // Here does nothing // but this is where you should allocate the internal/output pointers // if any } //===== // 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) //===== void TubeTreeFilter::bbUserFinalizeProcessing() { // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers // if any } } // EO namespace bbcreaMaracasVisu