//===== // 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 "bbcreaMaracasVisuTubeFilter.h" #include "bbcreaMaracasVisuPackage.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace bbcreaMaracasVisu { MaracasTubeFilter::MaracasTubeFilter() { } void MaracasTubeFilter::SetvtkRenderer(vtkRenderer *render) { this->renderer = render; } void MaracasTubeFilter::SetlstPoints( std::vector lstPointX , std::vector lstPointY , std::vector lstPointZ ) { this->lstPointX=lstPointX; this->lstPointY=lstPointY; this->lstPointZ=lstPointZ; } void MaracasTubeFilter::SetlstRadius( std::vector lstRadius ) { this->lstRadius=lstRadius; } void MaracasTubeFilter::Run() { // Spiral tube // double vX, vY, vZ; // unsigned int nV = 256; // No. of vertices // unsigned int nCyc = 5; // No. of spiral cycles // double rT1 = 0.1, rT2 = 0.5;// Start/end tube radii // double rS = 2; // Spiral radius // double h = 10; // Height unsigned int nTv = 8; // No. of surface elements for each tube vertex unsigned int i; // Create points and cells vtkSmartPointer points = vtkSmartPointer::New(); for(i = 0; i < lstPointX.size(); i++) { points->InsertPoint(i, lstPointX[i], lstPointY[i], lstPointZ[i]); } vtkSmartPointer lines = vtkSmartPointer::New(); lines->InsertNextCell( lstPointX.size() ); for (i = 0; i < lstPointX.size(); i++) { lines->InsertCellPoint(i); } vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(points); polyData->SetLines(lines); // Varying tube radius using sine-function vtkSmartPointer tubeRadius = vtkSmartPointer::New(); tubeRadius->SetName("TubeRadius"); tubeRadius->SetNumberOfTuples( lstRadius.size() ); for (i=0 ;iSetTuple1(i, lstRadius[i] ); } polyData->GetPointData()->AddArray(tubeRadius); polyData->GetPointData()->SetActiveScalars("TubeRadius"); // RBG array (could add Alpha channel too I guess...) // Varying from blue to red vtkSmartPointer colors = vtkSmartPointer::New(); colors->SetName("Colors"); colors->SetNumberOfComponents(3); colors->SetNumberOfTuples( lstPointX.size() ); for (i = 0; i < lstPointX.size() ;i++) { colors->InsertTuple3(i, 255 , 0.0 , 0.0 ); } polyData->GetPointData()->AddArray(colors); vtkSmartPointer tube = vtkSmartPointer::New(); tube->SetInput(polyData); tube->SetNumberOfSides(nTv); tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar(); vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputConnection(tube->GetOutputPort()); mapper->ScalarVisibilityOn(); mapper->SetScalarModeToUsePointFieldData(); mapper->SelectColorArray("Colors"); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); renderer->AddActor(actor); } BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter) BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox); //===== // 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 TubeFilter::Process() { // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value // INPUT/OUTPUT ACCESSORS ARE OF THE FORM : // void bbSet{Input|Output}NAME(const TYPE&) // const TYPE& bbGet{Input|Output}NAME() const // Where : // * NAME is the name of the input/output // (the one provided in the attribute 'name' of the tag 'input') // * TYPE is the C++ type of the input/output // (the one provided in the attribute 'type' of the tag 'input') printf("EED TubeFilter::Process start \n"); tubefilter->SetvtkRenderer( bbGetInputRenderer() ); tubefilter->SetlstPoints( bbGetInputlstPointX(), bbGetInputlstPointY(), bbGetInputlstPointZ() ); tubefilter->SetlstRadius( bbGetInputlstRadio() ); tubefilter->Run(); bbSetOutputOutAxis( NULL ); printf("EED TubeFilter::Process end \n"); } //===== // 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 TubeFilter::bbUserSetDefaultValues() { // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 // bbSetInputIn(0); } //===== // 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 TubeFilter::bbUserInitializeProcessing() { // THE INITIALIZATION METHOD BODY : // Here does nothing // but this is where you should allocate the internal/output pointers // if any tubefilter = new MaracasTubeFilter(); } //===== // 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 TubeFilter::bbUserFinalizeProcessing() { // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers // if any } } // EO namespace bbcreaMaracasVisu