[vtkusers] Semi-transparent sphere

Amy Squillacote amy.squillacote at kitware.com
Fri Jun 10 09:31:53 EDT 2005


Hi Ruoyun,

You are seeing this problem because your polygons are not 
depth-sorted.  They need to be in back-to-front order for transparency to 
work properly.  There are two mechanisms in VTK to handle this:
1) vtkDepthSortPolyData - a filter for ordering polygons; it you have more 
than one vtkPolyData overlapping in your scene, you would need to combine 
them into a single data set (using vtkAppendPolyData) before running this 
algorithm on them.
2) Use a vtkFrustumCoverageCuller to sort the polygons.  Add the culler to 
your renderer.  This method works with overlapping data sets.

- Amy

At 04:40 AM 6/10/2005, Wu Ruoyun wrote:
>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();
>}
>
>
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the 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