<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> vtkTypeRevisionMacro(vtkPainter, vtkObject);<br> static MyPainter* New();<br>protected:<br> virtual void RenderInternal(vtkRenderer* renderer, vtkActor* actor, <br> 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> vtkPoints *points = vtkPoints::New();<br> points->InsertNextPoint(1.0, 6.0, 5.0);<br> points->InsertNextPoint(2.0, 3.0, 0.0);<br> points->InsertNextPoint(3.0, 4.5, 0.0);<br> points->InsertNextPoint(5.0, 5.5, 5.0);<br><br> vtkFloatArray *colorArray = vtkFloatArray::New();<br> colorArray->InsertNextValue(0);<br>
colorArray->InsertNextValue(1);<br> colorArray->SetName("colorArray");<br><br> vtkCellArray *cells = vtkCellArray::New();<br> int ptsTri[3];<br> ptsTri[0]=0;<br> ptsTri[1]=1;<br> ptsTri[2]=2;<br> cells->InsertNextCell(3, ptsTri);<br><br> ptsTri[0]=1;<br> ptsTri[1]=2;<br> ptsTri[2]=3;<br> cells->InsertNextCell(3, ptsTri);<br><br>vtkPolyData *polydata = vtkPolyData::New();<br> polydata->SetPoints(points);<br> polydata->SetPolys(cells);<br> polydata->GetCellData()->AddArray(colorArray);<br>
polydata->GetCellData()->SetActiveAttribute("colorArray",0);<br> <br>vtkLookupTable *lut = vtkLookupTable::New();<br> lut->SetNumberOfColors(2);<br> lut->Build();<br> lut->SetTableValue(0, 1.0,0.0,0.0,1.0);<br> lut->SetTableValue(1, 0.0,0.0,1.0,1.0);<br> lut->SetTableRange(0,1);<br><br>vtkPainterPolyDataMapper *mapper = vtkPainterPolyDataMapper::New();<br> mapper->SetInputConnection(polydata->GetProducerPort());<br> mapper->SetLookupTable(lut);<br> mapper->UseLookupTableScalarRangeOn();<br><br>MyPainter *transparentPainter = MyPainter::New();<br> transparentPainter->SetDelegatePainter(mapper->GetPainter());<br>
mapper->SetPainter(transparentPainter);<br><br>vtkActor *actor = vtkActor::New();<br> actor->SetMapper(mapper);<br> actor->GetProperty()->SetOpacity(0.9);<br> actor->RotateX(-72);<br><br>vtkRenderer *ren = vtkRenderer::New();<br> ren->AddActor(actor);<br> ren->SetBackground(1, 1, 1);<br>vtkRenderWindow *renWin = vtkRenderWindow::New();<br> renWin->AddRenderer(ren);<br> renWin->SetSize(600, 600);<br>vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br> iren->SetRenderWindow(renWin);<br>vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();<br> iren->SetInteractorStyle(style);<br><br>renWin->Render();<br>iren->Initialize();<br>iren->Start();<br>return 0;<br><br>}<br><br><br><br>--- On <b>Thu, 6/19/08,
clinton@elemtech.com <i><clinton@elemtech.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: clinton@elemtech.com <clinton@elemtech.com><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 & 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->Superclass::RenderInternal(renderer, actor, typeflags);<br>glEnable(GL_CULL_FACE);<br>glCullFace(GL_BACK);<br>this->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->SetDelegatePainter(mapper->GetPainter());<br>mapper->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>> Clint,<br>> <br>> I saw your message posted two years ago and tried to follow what you<br>> suggested to solve vtk transparency problem. I have not get success yet,<br>> and I think I must not be doing it right. I wonder if you could do me a<br>> favor and send me those code that you used to solve the problem? or if<br>you<br>> could make it more explict, e.g., how did you overload<br>> vtkRender::UpdataGeometry, where did you insert glCullFace(GL_BACK), etc.<br>?<br>> <br>> Thank you so much<br>> <br>>
Tracy<br>><br>><br>---------------------------------------------------------------------------<br>>--------------------------- One thing I do that really helps with scenes in<br>> VTK is to make two passes at rendering the transparent data.<br>><br>> I've overloaded vtk*Renderer::UpdateGeometry.<br>> I've also overloaded vtkOpenGLProperty::Render.<br>><br>> The UpdateGeometry function does a cheap z-depth sort at the actor level,<br>> instead of each polygon.<br>><br>> I turn enable culling..<br>> glEnable(GL_CULL_FACE)<br>><br>> Then draw each polygons with<br>> glCullFace(GL_FRONT)<br>><br>> then on the second pass, draw each polygon with<br>> glCullFace(GL_BACK)<br>><br>> For the types of things I'm drawing, this is a cheap way to get pretty<br>good<br>> results, but it isn't perfect. I've heard no complaints from any<br>of our<br>> users. I might see some minor artifacts when I
have terribly convoluted<br>> geometry or pieces of geometry tangled up with each other.<br>><br>> That might work for you.<br>><br>> Clint</pre></blockquote></td></tr></table><br>