[vtkusers] zbuffering for visibility test

Monica Gemo gemo at tele.ucl.ac.be
Thu Nov 10 09:00:51 EST 2005


Hello vtkers,

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.

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.

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.

Can somebody help me? Please check if I am making any mistake or
show me a working method to calculate the zbuffering for visibility test.

Thanks a lot,
Monica



ViewManager * vm = ViewManager::GetInstance();
vector<View *> * vs= vm->GetViews();
vtkRenderer* ren=(*vs)[0]->GetRenderer();
double this->Tolerance = 0.01;

int* viewSize =ren->GetRenderWindow()->GetSize();

// calculate visible labels
vector <AbstractDataSetRenderer *> * 
viewRenderers = (*vs)[0]->GetListRenderer();
float* Zptr = 
ren->GetRenderWindow()->GetZbufferData(0,0, (viewSize[0]-1), (viewSize[1]-1));
double viewCoord[4];
double z, z2, displayCoord[3];
double worldCoord[4];
vtkMatrix4x4* matrix= vtkMatrix4x4::New();

//aspect calculation
int usize, vsize;
ren->GetTiledSize(&usize,&vsize);
double aspect[2];
ren->ComputeAspect();
ren->GetAspect(aspect);
double aspect2[2];
ren->vtkViewport::ComputeAspect();
ren->vtkViewport::GetAspect(aspect2);
double aspectModification = aspect[0]*aspect2[1]/(aspect[1]*aspect2[0]);

double finalAspect = 1.0;
if(vsize && usize){
         finalAspect = aspectModification*usize/vsize;
  }


matrix->DeepCopy(ren->GetActiveCamera()->GetCompositePerspectiveTransformMatrix(finalAspect,0,1));
worldCoord[3]=1.0;
//viewRenderers is a vector containing the 
objects to be displayed and annotations
for(int k=0; k<(int) viewRenderers->size(); k++){
    //get annotation data and check if it is visible
    if(!strcmp((*viewRenderers)[k]->GetId()->c_str(), 
"DataSetRenderer.LabelDataSetRenderer")){
    //get label anchor world coordinates and transform into display coordinates
          ((LabelDataSetRenderer*)(*viewRenderers)[k])->GetAnchor(worldCoord);
           matrix->MultiplyPoint(worldCoord, viewCoord);
           ren->SetViewPoint(viewCoord[0]/viewCoord[3], 
viewCoord[1]/viewCoord[3],viewCoord[2]/viewCoord[3]);
           ren->ViewToDisplay();
           ren->GetDisplayPoint(displayCoord);

           //first method to calculate zbuffer
           z= Zptr[(int) displayCoord[0] + (int)(displayCoord[1])*viewSize[0]];
           //another method to calculate zbuffer
           z2= ren->GetZ( 
static_cast<int>(displayCoord[0]),static_cast<int>(displayCoord[1]));
           cout<<" depth z: "<< z<< endl;
           cout<<" depth z2: "<< z2<< endl;
           cout<<" display coord depth: "<< displayCoord[2]<< endl;

           if(displayCoord[2]<(z + this->Tolerance)){
                 cout<<" visible "<<endl;

           }
           else{
             cout<<" invisible "<< endl;
          }
     }
}



  Monica Gemo - Ph.D. Student
  Communication and Remote Sensing Lab. (UCL/TELE)
  Belgium Lab. of Computer-Human Interaction (UCL/BCHI)
  Université catholique de Louvain
  Address : Stevin Building, room A.147
                  Place du Levant, 2
                  B-1348 Louvain-la-Neuve, BELGIUM
  Tel : + 32 10 47.41.05  -  Fax : + 32 10 47.20.89
  E-mail : gemo at tele.ucl.ac.be
  http://www.tele.ucl.ac.be/view-people.php?id=54
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051110/189db447/attachment.htm>


More information about the vtkusers mailing list