[vtkusers] Semi-transparent sphere

Wu Ruoyun MRYWu at ntu.edu.sg
Fri Jun 10 04:40:38 EDT 2005


Dear All,

I encounter a problem on displaying semi-transparent surface. It is
surprising to see that the problem is repeatable on a simple
semi-transparent sphere. The codes are attached below. A screenshot is
also attached for your reference. In case this mail list does not allow
attachment, please compile the codes below to see the results. The blue
half sphere is not displayed properly.

Any suggestion will be appreciated.

Best Wishes!
Ruoyun

ATTACHED CODES

#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkStripper.h"
#include "vtkPolyDataNormals.h"

void main ()
{

  // create sphere geometry
  vtkSphereSource *sphere = vtkSphereSource::New();
  sphere->SetRadius(1.0);
  sphere->SetThetaResolution(18);
  sphere->SetPhiResolution(18);
  sphere->SetEndTheta( 180 );

  vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
    normals->SetInput(sphere->GetOutput());
	normals->FlipNormalsOn();
	normals->AutoOrientNormalsOn();
    normals->SetFeatureAngle(60.0);
  vtkStripper *stripper = vtkStripper::New();
    stripper->SetInput(normals->GetOutput());

  // map to graphics library
  vtkPolyDataMapper *map = vtkPolyDataMapper::New();
  map->SetInput(stripper->GetOutput());

  // actor coordinates geometry, properties, transformation
  vtkActor *aSphere = vtkActor::New();
  aSphere->SetMapper(map);
  aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue
  aSphere->GetProperty()->SetOpacity(0.5);
  //aSphere->GetProperty()->BackfaceCullingOn();

  // create sphere2 geometry
  vtkSphereSource *sphere2 = vtkSphereSource::New();
  sphere2->SetRadius(0.5);
  sphere2->SetThetaResolution(18);
  sphere2->SetPhiResolution(18);

  vtkPolyDataNormals *normals2 = vtkPolyDataNormals::New();
    normals2->SetInput(sphere2->GetOutput());
    normals2->SetFeatureAngle(60.0);
  vtkStripper *stripper2 = vtkStripper::New();
    stripper2->SetInput(normals2->GetOutput());

  // map2 to graphics library
  vtkPolyDataMapper *map2 = vtkPolyDataMapper::New();
  map2->SetInput(stripper2->GetOutput());

  // actor coordinates geometry, properties, transformation
  vtkActor *aSphere2 = vtkActor::New();
  aSphere2->SetMapper(map2);
  aSphere2->GetProperty()->SetColor(1,0,0); // sphere2 color red
  //aSphere2->GetProperty()->SetOpacity(0.5);
  //aSphere2->GetProperty()->BackfaceCullingOn();

  // a renderer and render window
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

  // an interactor
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  // add the actor to the scene
  ren1->AddActor(aSphere);
  ren1->AddActor(aSphere2);
  ren1->SetBackground(1,1,1); // Background color white

  // render an image (lights and cameras are created automatically)
  renWin->Render();

  // begin mouse interaction
  iren->Start();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk_opacity_artifact.jpg
Type: image/jpeg
Size: 52762 bytes
Desc: vtk_opacity_artifact.jpg
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050610/665524e7/attachment.jpg>


More information about the vtkusers mailing list