[vtkusers] Fit to frame problem. How to solve?

rakesh patil prakeshofficial at gmail.com
Tue Sep 21 04:16:16 EDT 2010


Hello,

Here is a small piece of code. This is a very simple code to display a
triangular grid:

unsigned int numPts = x.size();

vtkSmarPointer<vtkPoints> pnts = vtkSmartPointer<vtkPoints>::New();
pnts->SetNumberOfPoints(numPts);

vtkSmartPointer<vtkFloatArray> scalar =
vtkSmartPointer<vtkFloatArray>::New();
scalar->SetNumberOfTuples(numPts);

for ( unsigned int i = 0; i < numPts; i++ )
{
*   pnts->InertPoint(i, x(i), y(i), z(i));*
   scalar->InsertTuple1(i, z(i));
}

unsigned int numCells = elems.rows();
vtkSmartPointer<vtkCellArray> cellArray =
vtkSmartPointer<vtkCellArray>::New();
for( unsigned int i = 0; i < numCells; i++ )
{
   cellArray->InsertNextCell(3);
   cellArray->InsertCellPoint( elem(i,0) );
   cellArray->InsertCellPoint( elem(i,1) );
   cellArray->InsertCellPoint( elem(i,2) );
}

unGrid = vtkUnstructuredGrid::New();
unGrid->Allocate(numCells, numCells);
unGrid->SetCells(cellArray);
unGrid->SetPoints(pnts);

vtkSmartPointer<vtkDataSetMapper> dsmapper =
vtkSmartPointer<vtkDataSetMapper>::New();
dsmapper->SetInput(unGrid);

gridActor = vtkActor::New();
gridActor->SetMapper(dsmapper);
gridActor->GetProperty()->SetColor(0, 0, 0);
gridActor->GetProperty()->SetRepresentationToWireframe();

pRenderer->AddActor(gridActor);
pRenderer->ResetCamera();

This code works very well. But with a small variation. The statement marked
on bold letters is the one causing this behavior.

If I replace the last argument z(i), by 0, then the grid fits directly into
the frame(window), but with the same code as it is above, it is displayed
very small. And i need to zoom it to bring it to the bigger form.

What should i do to resolve this? When i load a dataset, it should
automatically, fit to the window size.

Thanks

Regards
Rakesh Patil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100921/c6a48b68/attachment.htm>


More information about the vtkusers mailing list