[vtkusers] Drawing a simple line graph (CONTINUES...)

Amy Squillacote amy.squillacote at kitware.com
Mon Jul 23 08:51:09 EDT 2007


Hi Isidro,

Have you tried setting your second point to 0.5, 0.5, 0 instead of 1.0, 
1.0, 1.0?

- Amy

Isidro Moreno wrote:
>  
> Hi! I think this method _definitely doesn't work_: 
> vtkActor2D->GetPosition2Coordinate->SetValue(x,y,z).
>  
> This is my code (a simple straight line):
>  
> /*This should draw a diagonal in the left-bottom quarter of the 
> window, but the diagonal crosses the whole screen. If the commented 
> lines below are enabled, the behaviour it's the same*/
>  
> #include "vtkActor2D.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkPolyDataMapper2D.h"
> #include "vtkProperty2D.h"
> #include "vtkPolyData.h"
> #include "vtkPoints.h"
> #include "vtkCellArray.h"
> #include "vtkCamera.h"
>  
> int main(int argc, char *argv[]){
>  
>     vtkPolyData *linea=vtkPolyData::New();
>     vtkPoints *puntos=vtkPoints::New();
>     vtkCellArray *lineas=vtkCellArray::New();
>  
>     vtkPolyDataMapper2D *mapper=vtkPolyDataMapper2D::New();
>     vtkActor2D *actor=vtkActor2D::New();
>     vtkRenderer *render=vtkRenderer::New();
>     vtkRenderWindow *ventana=vtkRenderWindow::New();
>     vtkRenderWindowInteractor *interac=vtkRenderWindowInteractor::New();
>     vtkCoordinate *coor=vtkCoordinate::New();
>  
>     lineas->InsertNextCell(2);
>     lineas->InsertCellPoint(0);
>     lineas->InsertCellPoint(1);
>  
>     puntos->InsertPoint(0,0.0,0.0,0.0);
>     puntos->InsertPoint(1,1.0,1.0,0.0);
>  
>     linea->SetPoints(puntos);
>     linea->SetLines(lineas);
>  
>     coor->SetCoordinateSystemToNormalizedViewport();
>  
>     mapper->SetInput(linea);
>     mapper->SetTransformCoordinate(coor);
>  
>     actor->SetMapper(mapper);
>     actor->GetProperty()->SetColor(1.0,0.0,0.0);
>     
> actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
>     
> actor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
>     //actor->GetPosition2Coordinate()->SetReferenceCoordinate(NULL);
>    
>     actor->GetPositionCoordinate()->SetValue(0.0,0.0,0.0);
>     *actor->GetPosition2Coordinate()->SetValue(0.5,0.5,0.0); // 
> ¡¡¡Here!!!*
>  
>  render->AddActor2D(actor);
>     render->SetBackground(0.1,0.2,0.4);
> //    render->ResetCamera();
> //    render->ResetCameraClippingRange();
>  
>     ventana->AddRenderer(render);
>  
>     interac->SetRenderWindow(ventana);
>  
>     ventana->Render();
>     interac->Start();
>  
>     linea->Delete();
>     puntos->Delete();
>     lineas->Delete();
>  
>     mapper->Delete();
>     actor->Delete();
>     render->Delete();
>     ventana->Delete();
>     interac->Delete();
>     coor->Delete();
>  
>     return 0;}
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   

-- 
Amy Squillacote
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
Phone: (518) 371-3971 x106




More information about the vtkusers mailing list