[vtkusers] Problems with setting color properties to vtkPolyData actor

Alejandro Frangi afrangi at posta.unizar.es
Wed Jan 30 08:02:12 EST 2002


Hi all,

 Does anybody have any clue of why the code below does not produce a colored
actor? I mean, the opacity property is used in the rendering but the color
property is not applied and instead a green actor is shown when rendering
the output of the MarchingCubes. Any idea of what I am doing wrong here?

 Alex

PS: I´m working with vtk3.2 in a Linux platform.

//------------------------------------------------------------------
#include <vtkMarchingCubes.h>
#include <vtkStructuredPointsReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataNormals.h>
#include <vtkActor.h>
#include <vtkImageThreshold.h>
#include <vtkImageToStructuredPoints.h>
#include <vtkDepthSortPolyData.h>
#include <vtkDecimate.h>
#include <vtkProperty.h>


vtkRenderer *aRenderer;
vtkRenderWindow *renWin;
vtkRenderWindowInteractor *iren;

int main( int argc, char *argv[] )
{

  if ((argc!=2)){
    cout << " usage: example binary_image.vtk \n";
    return 1;
  }

  // Rendering
  aRenderer = vtkRenderer::New();
  renWin = vtkRenderWindow::New();
  renWin->AddRenderer(aRenderer);
  iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);


  // Read image
  vtkStructuredPointsReader* readerImage =
    vtkStructuredPointsReader::New();
  vtkMarchingCubes *mcubesEndo =
    vtkMarchingCubes::New();
  readerImage->SetFileName(argv[1]);
  readerImage->Update();

  // Threshold
  vtkImageThreshold *endo =
    vtkImageThreshold::New();

  endo->SetInput(readerImage->GetOutput());
  endo->ThresholdBetween(.5,1.5);
  endo->SetInValue(1);
  endo->SetOutValue(0);
  endo->SetReplaceIn(1);
  endo->SetReplaceOut(1);
  endo->Update();

  // Generate boundary surface of binary image
  mcubesEndo->SetInput(endo->GetOutput());
  mcubesEndo->SetValue(0,.5);
  mcubesEndo->Update();

  vtkPolyDataMapper*  triangleMapperEndo     = vtkPolyDataMapper::New();
  vtkActor*           triangleActorEndo      = vtkActor::New();
  vtkDepthSortPolyData* sortPolyDataEndo     = vtkDepthSortPolyData::New();
  vtkDecimate* decimatorEndo                 = vtkDecimate::New();

  vtkProperty *PropEndo = vtkProperty::New();
     PropEndo->SetColor(.2, .2, .2);
     PropEndo->SetDiffuseColor(1, .3882, .2784);
     PropEndo->SetSpecular(.3);
     PropEndo->SetSpecularPower(20);
     PropEndo->SetOpacity(0.95);


  decimatorEndo->SetInput(mcubesEndo->GetOutput());
  decimatorEndo->SetMaximumError(1);
  decimatorEndo->SetTargetReduction(0.95);

  sortPolyDataEndo->SetCamera(aRenderer->GetActiveCamera());
  sortPolyDataEndo->SortScalarsOn();
  sortPolyDataEndo->SetDirectionToBackToFront();

  triangleMapperEndo->SetInput(decimatorEndo->GetOutput());
  triangleActorEndo->SetMapper(triangleMapperEndo);
  triangleActorEndo->SetProperty(PropEndo);
  triangleActorEndo->ApplyProperties();

  aRenderer->AddActor(triangleActorEndo);
  aRenderer->GetActiveCamera()->SetPosition(247.338,-63.41,15.1383);
  aRenderer->GetActiveCamera()->SetPosition(247.338,-63.41,15.1383);
  aRenderer->GetActiveCamera()->SetFocalPoint(-8.3,-16.8,5.3);
  aRenderer->GetActiveCamera()->SetViewUp(0,0,1);
  aRenderer->ResetCamera();
  aRenderer->SetBackground(1,1,1);

  renWin->SetSize(500,500);

  iren->Start();
}





More information about the vtkusers mailing list