[vtkusers] ReferenceCoordinate not used if coordinate system is View

xabi riobe xabivtk at gmail.com
Mon Jan 18 13:21:26 EST 2010


Hi,

I noticed that if we use a vtkCoordinate with the coordinate system set to
View, and we add a ReferenceCoordinate, this one is not used.
The problem is in method vtkCoordinate::GetComputedDoubleDisplayValue.

here is an example to demonstrate that:
run it once to see the correct result then set the boolean bOk (just before
main) to false to see the problem.

Is there a reason for that?


#include <vtk/vtkActor2D.h>
#include <vtk/vtkCamera.h>
#include <vtk/vtkInteractorStyleTrackballCamera.h>
#include <vtk/vtkLineSource.h>
#include <vtk/vtkPolyData.h>
#include <vtk/vtkPolyDataMapper2D.h>
#include <vtk/vtkProperty2D.h>
#include <vtk/vtkRenderer.h>
#include <vtk/vtkRenderWindow.h>
#include <vtk/vtkRenderWindowInteractor.h>
#include <vtk/vtkSphereSource.h>

#include <vtk/vtkSmartPointer.h>
#define MY_SMART(class, variable)\
   vtkSmartPointer<class> variable = vtkSmartPointer<class>::New();

const double cst_dSize = 0.1;
const bool bOk = true;

int main(int, char* [])
{
   MY_SMART(vtkRenderer, ren1);
   ren1->SetBackground(0.2, 0.2, 0.2);
   MY_SMART(vtkRenderWindow, renWin);
   renWin->SetSize( 800, 800 );
   renWin->AddRenderer(ren1);
   MY_SMART(vtkRenderWindowInteractor, iren);
   iren->SetRenderWindow(renWin);
   MY_SMART(vtkInteractorStyleTrackballCamera, vtk_style);
   iren->SetInteractorStyle(vtk_style);

   MY_SMART(vtkLineSource, line);
   line->SetPoint1(0.0, 0.0, 0.0);
   if(bOk)
      line->SetPoint2(cst_dSize, 0.0, 0.0);
   else
      line->SetPoint2(cst_dSize*2, 0.0, 0.0);

   MY_SMART(vtkSphereSource, sphere1);
   sphere1->SetCenter(0.0, 0.0, 0.0);
   sphere1->SetRadius(0.1);
   sphere1->SetThetaResolution(16);
   sphere1->SetPhiResolution(8);

   MY_SMART(vtkSphereSource, sphere2);
   sphere2->SetCenter(0.0, 0.0, 0.0);
   sphere2->SetRadius(5);
   sphere2->SetThetaResolution(16);
   sphere2->SetPhiResolution(8);

   MY_SMART(vtkSphereSource, sphere3);
   sphere3->SetCenter(0.0, 0.0, 0.0);
   sphere3->SetRadius(5);
   sphere3->SetThetaResolution(16);
   sphere3->SetPhiResolution(8);

   MY_SMART(vtkPolyDataMapper2D, Mapper);
   Mapper->SetInputConnection(line->GetOutputPort());
   MY_SMART(vtkPolyDataMapper2D, Mappers1);
   Mappers1->SetInputConnection(sphere1->GetOutputPort());
   MY_SMART(vtkPolyDataMapper2D, Mappers2);
   Mappers2->SetInputConnection(sphere2->GetOutputPort());
   MY_SMART(vtkPolyDataMapper2D, Mappers3);
   Mappers3->SetInputConnection(sphere3->GetOutputPort());

   MY_SMART(vtkActor2D, Act);
   Act->GetProperty()->SetColor(0.0, 1.0, 1.0);
   Act->GetProperty()->SetLineWidth(5);
   Act->SetMapper(Mapper);
   MY_SMART(vtkActor2D, Acts1);
   Acts1->GetProperty()->SetColor(1.0, 0.0, 0.0);
   Acts1->SetMapper(Mappers1);
   MY_SMART(vtkActor2D, Acts2);
   Acts2->GetProperty()->SetColor(0.0, 1.0, 0.0);
   Acts2->SetMapper(Mappers2);
   MY_SMART(vtkActor2D, Acts3);
   Acts3->GetProperty()->SetColor(0.0, 0.0, 1.0);
   Acts3->SetMapper(Mappers3);

   MY_SMART(vtkCoordinate, coord);
   coord->SetCoordinateSystemToWorld();
   Mappers1->SetTransformCoordinate(coord);

   Acts2->GetPositionCoordinate()->SetCoordinateSystemToWorld();
   Acts2->GetPositionCoordinate()->SetValue(0.0, 2.0, 0.0);


Acts3->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
   Acts3->GetPositionCoordinate()->SetValue(0.1, 0.0, 0.0);

   MY_SMART(vtkCoordinate, pCoord);
   pCoord->SetCoordinateSystemToWorld();
   pCoord->SetValue(0.0, 2.0, 0.0);
   Acts3->GetPositionCoordinate()->SetReferenceCoordinate(pCoord);

   MY_SMART(vtkCoordinate, coo);
   if(bOk)
      coo->SetCoordinateSystemToNormalizedViewport();
   else
      coo->SetCoordinateSystemToView();
   coo->SetReferenceCoordinate(pCoord);
   Mapper->SetTransformCoordinate(coo);

   ren1->AddActor2D(Act);
   ren1->AddActor2D(Acts1);
   ren1->AddActor2D(Acts2);
   ren1->AddActor2D(Acts3);

   ren1->ResetCamera();
   ren1->GetActiveCamera()->ParallelProjectionOn();
   ren1->GetActiveCamera()->Zoom(0.4);
   renWin->Render();
   iren->Start();

   return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100118/5f3f856f/attachment.htm>


More information about the vtkusers mailing list