<html>
<body>
<font face="Courier New, Courier">Hello vtkers,<br><br>
I need to test the visibility of objects to be rendered and I am using
zbuffering to test for visibility. I test the visibility of an annotation
anchor point to manually clip the annotation if it is not
visible.<br><br>
I am not sure if the zbuffering method I am using is correct because I
had to make some changes from version 4.2 to 4.5 and the zbuffering does
not always work (before I had some problem only on the laptop with the
ATI mobility radeon 9700 card, now also with the invidia card). Sometimes
it happens that I see the anchor point displayed but the test says it is
not visible.<br><br>
In past vtk msgs and in vtk code, I found two zbuffering methods are used
(see z and z2 in the code) but they give different values, I used z
because its value seems the closest to the display coordinates of the
point.<br><br>
Can somebody help me? Please check if I am making any mistake or <br>
show me a working method to calculate the zbuffering for visibility
test.<br><br>
Thanks a lot,<br>
Monica<br><br>
<br><br>
ViewManager * vm = ViewManager::GetInstance();<br>
vector<View *> * vs= vm->GetViews();<br>
vtkRenderer* ren=(*vs)[0]->GetRenderer();<br>
double this->Tolerance = 0.01;<br>
<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><br>
int* viewSize =ren->GetRenderWindow()->GetSize(); <br>
<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><br>
// calculate visible labels<br>
vector <AbstractDataSetRenderer *> * viewRenderers =
(*vs)[0]->GetListRenderer(); <br>
float* Zptr = ren->GetRenderWindow()->GetZbufferData(0,0,
(viewSize[0]-1), (viewSize[1]-1));<br>
double viewCoord[4];<br>
double z, z2, displayCoord[3];<br>
double worldCoord[4];<br>
vtkMatrix4x4* matrix= vtkMatrix4x4::New(); <br>
<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><br>
//aspect calculation<br>
int usize, vsize;<br>
ren->GetTiledSize(&usize,&vsize);<br>
double aspect[2];<br>
ren->ComputeAspect();<br>
ren->GetAspect(aspect);<br>
double aspect2[2];<br>
ren->vtkViewport::ComputeAspect();<br>
ren->vtkViewport::GetAspect(aspect2);<br>
double aspectModification =
aspect[0]*aspect2[1]/(aspect[1]*aspect2[0]);<br>
<br>
double finalAspect = 1.0;<br>
if(vsize && usize){<br>
<x-tab> </x-tab>finalAspect =
aspectModification*usize/vsize;<br>
}<br><br>
<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><br>
matrix->DeepCopy(ren->GetActiveCamera()->GetCompositePerspectiveTransformMatrix(finalAspect,0,1));<br>
worldCoord[3]=1.0;<br>
//viewRenderers is a vector containing the objects to be displayed and
annotations<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><br>
for(int k=0; k<(int) viewRenderers->size();
k++){<x-tab> </x-tab><br>
//get annotation data and check if it is visible <br>
if(!strcmp((*viewRenderers)[k]->GetId()->c_str(),
"DataSetRenderer.LabelDataSetRenderer")){<br>
//get label anchor world coordinates and transform into
display coordinates<br>
<x-tab> </x-tab>
((LabelDataSetRenderer*)(*viewRenderers)[k])->GetAnchor(worldCoord);
<br>
<x-tab> </x-tab>
matrix->MultiplyPoint(worldCoord, viewCoord);<br>
<x-tab> </x-tab>
ren->SetViewPoint(viewCoord[0]/viewCoord[3],
viewCoord[1]/viewCoord[3],viewCoord[2]/viewCoord[3]);<br>
<x-tab> </x-tab>
ren->ViewToDisplay();<br>
<x-tab> </x-tab>
ren->GetDisplayPoint(displayCoord);<br><br>
<x-tab> </x-tab>
//first method to calculate zbuffer<br>
<x-tab> </x-tab> z=
Zptr[(int) displayCoord[0] + (int)(displayCoord[1])*viewSize[0]];<br>
<x-tab> </x-tab>
//another method to calculate zbuffer <br>
<x-tab> </x-tab> z2=
ren->GetZ(
static_cast<int>(displayCoord[0]),static_cast<int>(displayCoord[1]));<br>
<x-tab> </x-tab>
cout<<" depth z: "<< z<< endl;<br>
<x-tab> </x-tab>
cout<<" depth z2: "<< z2<< endl;<br>
<x-tab> </x-tab>
cout<<" display coord depth: "<<
displayCoord[2]<< endl;<br><br>
<x-tab> </x-tab>
if(displayCoord[2]<(z + this->Tolerance)){<br>
<x-tab> </x-tab><x-tab>
</x-tab>
cout<<" visible "<<endl;<br>
<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><br>
<x-tab> </x-tab>
}<br>
<x-tab> </x-tab>
else{<br>
<x-tab> </x-tab>
cout<<" invisible "<< endl;<br>
<x-tab> </x-tab>
}<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><br>
}<br>
}<br><br>
<br>
</font><x-sigsep><p></x-sigsep>
<font face="Arial Baltic, Helvetica" size=2> Monica Gemo - Ph.D.
Student<br>
Communication and Remote Sensing Lab. (UCL/TELE)<br>
Belgium Lab. of Computer-Human Interaction (UCL/BCHI)<br>
Université catholique de Louvain<br>
Address : Stevin Building, room A.147<br>
Place du Levant, 2<br>
B-1348 Louvain-la-Neuve, BELGIUM<br>
Tel : + 32 10 47.41.05 - Fax : + 32 10 47.20.89<br>
E-mail : gemo@tele.ucl.ac.be<br>
<a href="http://www.tele.ucl.ac.be/view-people.php?id=54" eudora="autourl">
http://www.tele.ucl.ac.be/view-people.php?id=54<br>
</a></font></body>
</html>