[vtkusers] sort translucent actors along view direction
Tracy Hu
tracy.hu at yahoo.com
Thu Jun 26 11:39:08 EDT 2008
I'm able to use vtkDepthSortPolyData to render a single translucent sphere correctly. but in the following code where I try to render two translucent sphere, their rendering order is incorrect. Grey sphere always appear in front of red sphere even when it is actually behind of red sphere. Is there a way to sort actors along view direction or some other way to get around this problem?
Thank you very much!
Tracy
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkLight.h"
#include "vtkLightCollection.h"
#include "vtkAppendPolyData.h"
#include "vtkDepthSortPolyData.h"
#include "vtkCamera.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkPoints.h"
#include "vtkFloatArray.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkLookupTable.h"
#include "vtkPolyDataToPolyDataFilter.h"
#include "vtkAppendPolyData.h"
#include "vtkAssembly.h"
#include "vtkSphereSource.h"
int main()
{
vtkSphereSource *sphere = vtkSphereSource::New();
vtkDepthSortPolyData *depthSort = vtkDepthSortPolyData::New();
depthSort->SetInputConnection(sphere->GetOutputPort());
depthSort->SortScalarsOff();
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(depthSort->GetOutputPort());
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetOpacity(0.9);
actor->RotateX(-32);
depthSort->SetProp3D(actor);
vtkRenderer *ren = vtkRenderer::New();
depthSort->SetCamera(ren->GetActiveCamera());
//*************************
vtkSphereSource *sphere2 = vtkSphereSource::New();
vtkDepthSortPolyData *depthSort2 = vtkDepthSortPolyData::New();
depthSort2->SetInputConnection(sphere2->GetOutputPort());
depthSort2->SortScalarsOff();
vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
mapper2->SetInputConnection(depthSort2->GetOutputPort());
vtkActor *actor2 = vtkActor::New();
actor2->SetMapper(mapper2);
actor2->GetProperty()->SetOpacity(0.9);
actor2->GetProperty()->SetColor(1, 0, 0);
actor2->SetPosition(1.5, 0.0,0.0);
actor2->RotateX(-32);
depthSort2->SetProp3D(actor2);
depthSort2->SetCamera(ren->GetActiveCamera());
//**************************
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
ren->AddActor(actor2);
ren->AddActor(actor);
ren->SetBackground(1, 1, 1);
renWin->SetSize(600, 600);
ren->ResetCamera();
renWin->Render();
iren->Initialize();
iren->Start();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080626/e6b9eced/attachment.htm>
More information about the vtkusers
mailing list