<table cellspacing='0' cellpadding='0' border='0' ><tr><td valign='top' style='font: inherit;'>Hi, Clint,<br><br>I wonder if you could briefly look at my code below? I implemented everything as you suggested. But in the resulted two triangles, blue one always appear in front of red one no matter how I rotate them. Did I do something incorrect? I'm using vtk5.3<br><br>Thanks a lot.<br>Tracy<br>-------------------------------------------------------------------------------------------------------------------------------<br>#ifndef MYPAINTER_H<br>#define MYPAINTER_H<br><br>#include "vtkPainter.h"<br><br>class MyPainter :public vtkPainter<br>{<br>public:<br>&nbsp;&nbsp;&nbsp; vtkTypeRevisionMacro(vtkPainter, vtkObject);<br>&nbsp;&nbsp;&nbsp; static MyPainter* New();<br>protected:<br>&nbsp;&nbsp;&nbsp; virtual void RenderInternal(vtkRenderer* renderer, vtkActor* actor, <br>&nbsp;&nbsp;&nbsp; unsigned long
 typeflags);<br>};<br>#endif<br><br>-------------------------------------------------------------------------------------------------------------------<br>#include "MyPainter.h"<br>#include "vtkObjectFactory.h"<br>#include "vtkOpenGL.h"<br><br>vtkStandardNewMacro(MyPainter);<br>vtkCxxRevisionMacro(MyPainter, "$Revision: 1.6 $");<br><br>void MyPainter::RenderInternal(vtkRenderer *renderer, vtkActor *actor, unsigned long typeflags)<br>{<br>glEnable(GL_CULL_FACE);<br>glCullFace(GL_FRONT);<br>vtkPainter::RenderInternal(renderer, actor, typeflags);<br>glEnable(GL_CULL_FACE);<br>glCullFace(GL_BACK);<br>vtkPainter::RenderInternal(renderer, actor, typeflags);<br>glDisable(GL_CULL_FACE);<br>}<br><br>--------------------------------------------------------------------------------------------------------------<br>#include "vtkActor.h"<br>#include "vtkRenderer.h"<br>#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include
 "vtkInteractorStyleTrackballCamera.h"<br>#include "vtkPoints.h"<br>#include "vtkFloatArray.h"<br>#include "vtkCellArray.h"<br>#include "vtkCellData.h"<br>#include "vtkLookupTable.h"<br>#include "MyPainter.h"<br>#include "vtkPainterPolyDataMapper.h"<br>#include "vtkPolyData.h"<br>#include "vtkProperty.h"<br><br>int main()<br>{<br><br>&nbsp;&nbsp;&nbsp; vtkPoints *points = vtkPoints::New();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(1.0, 6.0, 5.0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(2.0, 3.0, 0.0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(3.0, 4.5, 0.0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(5.0, 5.5, 5.0);<br><br>&nbsp;&nbsp;&nbsp; vtkFloatArray *colorArray = vtkFloatArray::New();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; colorArray-&gt;InsertNextValue(0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 colorArray-&gt;InsertNextValue(1);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; colorArray-&gt;SetName("colorArray");<br><br>&nbsp;&nbsp;&nbsp; vtkCellArray *cells = vtkCellArray::New();<br>&nbsp;&nbsp;&nbsp; int ptsTri[3];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ptsTri[0]=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ptsTri[1]=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ptsTri[2]=2;<br>&nbsp;&nbsp;&nbsp; cells-&gt;InsertNextCell(3, ptsTri);<br><br>&nbsp;&nbsp;&nbsp; ptsTri[0]=1;<br>&nbsp;&nbsp;&nbsp; ptsTri[1]=2;<br>&nbsp;&nbsp;&nbsp; ptsTri[2]=3;<br>&nbsp;&nbsp;&nbsp; cells-&gt;InsertNextCell(3, ptsTri);<br><br>vtkPolyData *polydata = vtkPolyData::New();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polydata-&gt;SetPoints(points);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polydata-&gt;SetPolys(cells);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polydata-&gt;GetCellData()-&gt;AddArray(colorArray);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 polydata-&gt;GetCellData()-&gt;SetActiveAttribute("colorArray",0);<br>&nbsp;<br>vtkLookupTable *lut = vtkLookupTable::New();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lut-&gt;SetNumberOfColors(2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lut-&gt;Build();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lut-&gt;SetTableValue(0, 1.0,0.0,0.0,1.0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lut-&gt;SetTableValue(1, 0.0,0.0,1.0,1.0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lut-&gt;SetTableRange(0,1);<br><br>vtkPainterPolyDataMapper *mapper = vtkPainterPolyDataMapper::New();<br>&nbsp;&nbsp;&nbsp; mapper-&gt;SetInputConnection(polydata-&gt;GetProducerPort());<br>&nbsp;&nbsp;&nbsp; mapper-&gt;SetLookupTable(lut);<br>&nbsp;&nbsp;&nbsp; mapper-&gt;UseLookupTableScalarRangeOn();<br><br>MyPainter *transparentPainter = MyPainter::New();<br>&nbsp;&nbsp;&nbsp; transparentPainter-&gt;SetDelegatePainter(mapper-&gt;GetPainter());<br>&nbsp;&nbsp;&nbsp;
 mapper-&gt;SetPainter(transparentPainter);<br><br>vtkActor *actor = vtkActor::New();<br>&nbsp;&nbsp;&nbsp; actor-&gt;SetMapper(mapper);<br>&nbsp;&nbsp;&nbsp; actor-&gt;GetProperty()-&gt;SetOpacity(0.9);<br>&nbsp;&nbsp;&nbsp; actor-&gt;RotateX(-72);<br><br>vtkRenderer *ren = vtkRenderer::New();<br>&nbsp;&nbsp;&nbsp; ren-&gt;AddActor(actor);<br>&nbsp;&nbsp;&nbsp; ren-&gt;SetBackground(1, 1, 1);<br>vtkRenderWindow *renWin = vtkRenderWindow::New();<br>&nbsp;&nbsp;&nbsp; renWin-&gt;AddRenderer(ren);<br>&nbsp;&nbsp;&nbsp; renWin-&gt;SetSize(600, 600);<br>vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br>&nbsp;&nbsp;&nbsp; iren-&gt;SetRenderWindow(renWin);<br>vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();<br>&nbsp;&nbsp;&nbsp; iren-&gt;SetInteractorStyle(style);<br><br>renWin-&gt;Render();<br>iren-&gt;Initialize();<br>iren-&gt;Start();<br>return 0;<br><br>}<br><br><br><br>--- On <b>Thu, 6/19/08,
 clinton@elemtech.com <i>&lt;clinton@elemtech.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: clinton@elemtech.com &lt;clinton@elemtech.com&gt;<br>Subject: Re: vtk transparency problem<br>To: tracy.hu@yahoo.com<br>Date: Thursday, June 19, 2008, 4:32 PM<br><br><pre>I use a subclass of vtkPainter &amp; VTK 5.2/CVS to do it now.<br><br>In the RenderInternal() of my vtkPainter subclass, I call <br>glEnable(GL_CULL_FACE);<br>glCullFace(GL_FRONT);<br>this-&gt;Superclass::RenderInternal(renderer, actor, typeflags);<br>glEnable(GL_CULL_FACE);<br>glCullFace(GL_BACK);<br>this-&gt;Superclass::RenderInternal(renderer, actor, typeflags);<br>glDisable(GL_CULL_FACE);<br><br>That might be all you need without modifying vtkRenderer or vtkProperty.<br>To use the painter, <br><br>vtkPainterPolyDataMapper* mapper = ...<br><br>MyPainter* transparentPainter =
 MyPainter::New();<br>transparentPainter-&gt;SetDelegatePainter(mapper-&gt;GetPainter());<br>mapper-&gt;SetPainter(transparentPainter);<br><br>I don't have a sample app, or the code isolated enough to send you cpp<br>files.<br><br>Clint<br><br>On Thursday 19 June 2008 10:57:25 am Tracy Hu wrote:<br>&gt; Clint,<br>&gt;  <br>&gt; I saw your message posted two years ago and tried to follow what  you<br>&gt; suggested to solve vtk transparency problem. I have not get success yet,<br>&gt; and I think I must not be doing it right. I wonder if  you could do me a<br>&gt; favor and send me those code that you used to solve the problem?  or if<br>you<br>&gt; could make it more explict, e.g., how did you overload<br>&gt; vtkRender::UpdataGeometry, where did you insert glCullFace(GL_BACK), etc.<br>?<br>&gt; <br>&gt; Thank you so much<br>&gt;  <br>&gt;
 Tracy<br>&gt;<br>&gt;<br>---------------------------------------------------------------------------<br>&gt;--------------------------- One thing I do that really helps with scenes in<br>&gt; VTK is to make two passes at rendering the transparent data.<br>&gt;<br>&gt; I've overloaded vtk*Renderer::UpdateGeometry.<br>&gt; I've also overloaded vtkOpenGLProperty::Render.<br>&gt;<br>&gt; The UpdateGeometry function does a cheap z-depth sort at the actor level,<br>&gt; instead of each polygon.<br>&gt;<br>&gt; I turn enable culling..<br>&gt; glEnable(GL_CULL_FACE)<br>&gt;<br>&gt; Then draw each polygons with<br>&gt; glCullFace(GL_FRONT)<br>&gt;<br>&gt; then on the second pass, draw each polygon with<br>&gt; glCullFace(GL_BACK)<br>&gt;<br>&gt; For the types of things I'm drawing, this is a cheap way to get pretty<br>good<br>&gt; results, but it isn't perfect.  I've heard no complaints from any<br>of our<br>&gt; users.  I might see some minor artifacts when I
 have terribly convoluted<br>&gt; geometry or pieces of geometry tangled up with each other.<br>&gt;<br>&gt; That might work for you.<br>&gt;<br>&gt; Clint</pre></blockquote></td></tr></table><br>