[vtkusers] why vtk is consuming so much memory? 1000 vtkActors * 300 vtkLines
higherone
38332115 at qq.com
Thu May 21 06:18:43 EDT 2009
I have 1000 vtkActors, and in each vtkActor there are 300 vtkLines.when this
little sample runs, it consumes about 150 Mb Memory .Is this a normal
thing?If not, please tell me what is wrong, or any way to improve the
performance . Thanks.
my code is below.
// drawlines.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkSphereSource.h"
#include "vtkPoints.h"
#include "vtkPolyVertex.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDataSetMapper.h"
#include "vtkCamera.h"
#include "vtkLine.h"
#include "vtkAxes.h"
#include "vtkTubeFilter.h"
#include "vtkDoubleArray.h"
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkLookupTable.h"
int _tmain(int argc, char* argv[])
{
vtkRenderer *ren=vtkRenderer::New();
for (int m=0; m<1000; m++)
{
vtkPoints * points = vtkPoints::New();
points->InsertPoint(0,0,0,0);
points->InsertPoint(1,10,0,0);
//points->InsertPoint(2,0,10,0);
//points->InsertPoint(3,10,10,0);
//points->InsertPoint(4,0,0,0);
vtkUnstructuredGrid * grid=vtkUnstructuredGrid::New();
grid->SetPoints(points);
points->Delete();
int nLineNum(300);
for(int i=0;i<nLineNum;i++)
{
vtkLine *aline = vtkLine::New();
aline->GetPointIds()->SetNumberOfIds(2);
//aline->GetPointIds()->SetId(0,i);
//aline->GetPointIds()->SetId(1,i+1);
aline->GetPointIds()->SetId(0,0);
aline->GetPointIds()->SetId(1,1);
grid->InsertNextCell(aline->GetCellType(), aline->GetPointIds());
aline->Delete();
}
/*//set the color lookup table
vtkLookupTable *pLookup = vtkLookupTable::New();
pLookup->SetTableRange(0, 2);
pLookup->SetTableValue(0, 1, 1, 0);
pLookup->SetTableValue(1, 0, 1, 1);
pLookup->SetTableValue(2, 1, 0, 1);
pLookup->SetNumberOfTableValues(3);
//set color index for every line
vtkCellData *cellData = grid->GetCellData();
vtkIntArray *colourPts = vtkIntArray::New();
for(int i=0; i <nLineNum; i++)
{
colourPts->InsertNextValue(0);
}
cellData->SetScalars(colourPts);*/
vtkDataSetMapper *map1 = vtkDataSetMapper::New();
map1->SetInput(grid);
grid->Delete();
//map1->SetLookupTable(pLookup);
//map1->SetScalarRange(0, 2);
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(map1);
actor1->GetProperty()->SetColor(0.0,0.0, 1);
map1->Delete();
ren->AddActor(actor1);
actor1->Delete();
}
ren->SetBackground(1, 1, 1);
vtkRenderWindow* win=vtkRenderWindow::New();
win->AddRenderer(ren);
win->SetSize(400,400);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(win);
win->Render();
iren->Start();
//iren->Initialize();
ren->Delete();
win->Delete();
iren->Delete();
return 0;
}
More information about the vtkusers
mailing list