[vtkusers] problem visualizing simple grid
Marcel Schiffel
marcelschiffel at googlemail.com
Thu Nov 13 17:05:36 EST 2008
Hi,
this one is probably pretty trivial: as a first test I'm trying to
visualize a really simple grid, but keep getting an empty render
window. What am I doing wrong?
Many Thanks
#include "vtkDataSetMapper.h"
#include "vtkRenderWindow.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkStructuredGrid.h"
#include "vtkPoints.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkHedgeHog.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
int main()
{
double p1[3] = {0,0,0};
double p2[3] = {1,0,0};
double p3[3] = {0,1,0};
double p4[3] = {1,1,0};
vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
vtkPoints *points = vtkPoints::New();
points->Allocate(4);
points->InsertPoint(0,p1);
points->InsertPoint(1,p2);
points->InsertPoint(2,p3);
points->InsertPoint(3,p4);
sgrid->SetPoints(points);
points->Delete();
vtkDataSetMapper *sgridMapper = vtkDataSetMapper::New();
sgridMapper->SetInput(sgrid);
vtkActor *sgridActor = vtkActor::New();
sgridActor->SetMapper(sgridMapper);
sgridActor->GetProperty()->SetColor(0,0,0);
vtkCamera *camera = vtkCamera::New();
camera->SetPosition(0,0,1);
camera->SetFocalPoint(0,0,0);
vtkRenderer *ren1= vtkRenderer::New();
ren1->AddActor( sgridActor );
ren1->SetActiveCamera(camera);
ren1->ResetCamera();
ren1->SetBackground(.5,.5,.5);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( ren1 );
renWin->SetSize( 800, 600 );
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renWin->Render();
iren->Start();
sgrid->Delete();
sgridMapper->Delete();
sgridActor->Delete();
ren1->Delete();
renWin->Delete();
return 0;
}
More information about the vtkusers
mailing list