[vtkusers] VTK polylines using RGBA to set opacity does not work

David Gobbi david.gobbi at gmail.com
Mon Jan 10 09:31:58 EST 2011


Hi Iggy,

VTK often needs a hint before it will do transparent rendering.
Try something like this:

actor->GetProperty()->SetOpacity(0.995);

Setting the opacity to just below 1.0 will force VTK to use
the translucent rendering pass, which should allow things like
per-vertex opacity to work.

  David


On Mon, Jan 10, 2011 at 7:02 AM, Reicht Ignaz
<i.reicht at dkfz-heidelberg.de> wrote:
> Hi,
>
> on creating vtk polylines with RGBA-color information for each single point, no opacity has been processed/rendered. VTK-Literature says that opacity can be specified for an actor and also for an vertex, but somehow this does not work properly for vertex based settings. Attached you will find my code example where two polylines are given. coordinates represent polyline1 in front of polyline2. Color/opacity-information is given using RGBA tuple with 4 Components. I also tried this approach using vtkTubes but with the same disappointing result (see commented out parts).
>
> Does somebody know what is missing or what is implemented wrong?
> thanks in advise
> iggy
>
> ##############################
> int main() {
>
>
>
>   //Create points for polyline1.
>  double origin[3] = {0.0, 0.0, 0.0};
>  double p0[3] = {100.0, 0.0, 0.0};
>  double p1[3] = {150.0, 100.0, 0.0};
>  double p2[3] = {170.0, 200.0, 0.0};
>
>
>
>  //create points for polyline2
>  double p01[3] = {50.0, 50.0, 13.0};
>  double p11[3] = {200.0, 100.0, 13.0};
>
>  //insert points to vtkPointarray
>  vtkPoints *pnts = vtkPoints::New();
>  pnts->InsertPoint(0,origin);
>  pnts->InsertPoint(1,p0);
>  pnts->InsertPoint(2,p1);
>  pnts->InsertPoint(3,p2);
>  pnts->InsertPoint(4,p01);
>  pnts->InsertPoint(5,p11);
>
>
>
>  //generate and define polyline1
>  vtkPolyLine *polyLine = vtkPolyLine::New();
>  polyLine->GetPointIds()->SetNumberOfIds(4);
>  polyLine->GetPointIds()->SetId(0,0);
>  polyLine->GetPointIds()->SetId(1,1);
>  polyLine->GetPointIds()->SetId(2,2);
>  polyLine->GetPointIds()->SetId(3,3);
>
>
>
>  //generate and define polyline2
>  vtkPolyLine *polyLine2 = vtkPolyLine::New();
>  polyLine2->GetPointIds()->SetNumberOfIds(2);
>  polyLine2->GetPointIds()->SetId(0,4);
>  polyLine2->GetPointIds()->SetId(1,5);
>
>  //add lines to cellArray
>
>  vtkCellArray *lines = vtkCellArray::New();
>  lines->InsertNextCell(polyLine);
>  lines->InsertNextCell(polyLine2);
>
>
>
>  vtkPolyData *polyDataT = vtkPolyData::New();
>  polyDataT->SetPoints(pnts);
>  polyDataT->SetLines(lines);
>
>
>
>  //color and opacity handling
>  vtkUnsignedCharArray *colorT = vtkUnsignedCharArray::New();
>  colorT->SetName("Colors");
>  colorT->SetNumberOfComponents(4); //4 components cuz of RGBA
>
>
>
>  unsigned char red[4] =      {255, 0,    0,    0.5};
>  unsigned char green[4] =    {0,   255,  0,    0.5};
>  unsigned char blue[4] =     {0,   0,    255,  0.5};
>  unsigned char white[4] = {255, 255, 255,   0.5};
>
>  colorT->InsertNextTupleValue(red); //color for point0
>  colorT->InsertNextTupleValue(green); //color for point1
>  colorT->InsertNextTupleValue(blue);
>  colorT->InsertNextTupleValue(white);
>  colorT->InsertNextTupleValue(white);
>  colorT->InsertNextTupleValue(white); //color for point5
>
>
>
>  polyDataT->GetPointData()->AddArray(colorT);
>
>
>
>  //tube representation
>
>  //vtkTubeFilter *tube =  vtkTubeFilter::New();
>  //tube->SetInput(polyDataT);
>  //tube->SetNumberOfSides(8);
>  //tube->SetRadius(5);
>
>
>
>  vtkSmartPointer<vtkPolyDataMapper> mapper =
>  vtkSmartPointer<vtkPolyDataMapper>::New();
>  mapper->SetInput(polyDataT);
>  //mapper->SetInputConnection(tube->GetOutputPort()); //using for tube representation
>  mapper->ScalarVisibilityOn();
>  mapper->SetScalarModeToUsePointFieldData();
>  mapper->SelectColorArray("Colors");
>
>
>
>  vtkSmartPointer<vtkActor> actor =
>  vtkSmartPointer<vtkActor>::New();
>  actor->SetMapper(mapper);
>
>
>
>  //Rendering
>
>  vtkSmartPointer<vtkRenderer> renderer =
>  vtkSmartPointer<vtkRenderer>::New();
>  renderer->AddActor(actor);
>  renderer->SetBackground(.2, .3, .4);
>
>  renderer->ResetCamera();
>
>  vtkSmartPointer<vtkRenderWindow> renWin =
>  vtkSmartPointer<vtkRenderWindow>::New();
>  vtkSmartPointer<vtkRenderWindowInteractor>
>  iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
>  iren->SetRenderWindow(renWin);
>  renWin->AddRenderer(renderer);
>  renWin->SetSize(500, 500);
>  renWin->Render();
>  iren->Start();
>
> }//end main()
> #############################
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list