[vtkusers] Memory problem (coloring >44000 tetrahedrons objects)

David E DeMarle dave.demarle at kitware.com
Fri Mar 24 14:38:18 EST 2006


Hi  Paul,

You do not need separate actors/mappers and properties for each 
tetrahedron. Stick with one UnstructuredGrid and add 1, 44000 tuple by 3 
uchar, array to the UGrid's vtkCellData. Then set the ColorMode in the 
UGrid's mapper to Color by that CellData array. The simplest way to do 
all of this is to make your color array be the cell scalars.

hth,
Dave DeMarle


> On Fri, 24 Mar 2006 ksm-pb at ipt.rwth-aachen.de wrote:
>
>>
>> Hello vtkusers mailing list,
>>
>> i ve a problem with the memory usage of my VTK application. I create 
>> more
>> than 44000 tetrahedron objects which each have to have a different color
>> and i hope someone can help here.
>>
>> The 44000 vtkTetra objects are no problem as long as i put all of 
>> them into
>> the same vtkUnstructuredGrid object and using the same color for each
>> tetrahedron like this:
>>
>> // iCons contains the indexes for the tetrahedron point connectivities
>> int * const * iCons = GetCons();
>> int iNumofPoints = GetNumOfPoints();
>>
>> vtkUnstructuredGrid * pUnsGrid = vtkUnstructuredGrid::New();
>> vtkPoints * pPoints = vtkPoints::New();
>>
>> ... // Feeding pPoints from an external data format (10327 coords in my
>> app)
>>
>> pUnsGrid->Allocate(iNumOfPoints, iNumOfPoints);
>> pUnsGrid->SetPoints(pPoints);
>>
>> for (int i = 0; i < iNumOfTetra; ++i) {
>>      vtkTetra * pTetra = vtkTetra::New();
>>      vtkIdList * pTetraIdList = pTetra->GetPointIds();
>>
>>      for (int j = 0; j < 4; ++j)
>>            pTetraIdList->SetId(j, iCons[j][i]-1); // iCons knows 
>> which IDs
>> to set for each tetrahedron!
>>
>>      pUnsGrid->InsertNextCell(pTetra->GetCellType(), pTetraIdList);
>> }
>>
>> vtkOpenGLActor * pActor = vtkOpenGLActor::New();
>> vtkDataSetMapper * pMapper = vtkDataSetMapper::New();
>> pActor->SetMapper(pMapper);
>> pActor->GetProperty()->SetColor(1,0,0);
>> pActor->SetScale(.1,.1,.1);
>> pMapper->SetInput(pUnsGrid);
>>
>> This solution works okay with about 30MB of RAM usage, but each 
>> tetrahedron
>> has the same color (1,0,0) now. BUT however if i want each 
>> tetrahedron to
>> have a different color i would have to create for each 44000 
>> tetrahedrons
>> its own vtkUnstructuredGrid, vtkOpenGLActor and vtkDataSetMapper 
>> objects.
>> So i got at least 44000 * 3 = 132000 more objects in the memory. This 
>> way
>> the app would consume more than 2GB of RAM (and its swapping about 
>> 100MB)!
>> Also the display speed with the vtkOpenGLRenderer gets very very 
>> slow! The
>> code is like this:
>>
>> int i NumOfTetras = GetNumOfTetras();
>> std::vector< vtkOpenGLActor* > vecActors;
>> vecActors.resize(iNumOfTetras);
>>
>> for (int t = 0; t < iNumOfTetras; ++t )
>>      vtkPoints * pPoints = GetTetraPoints(t);
>>      vtkUnstructuredGrid * pUnsGrid = vtkUnstructuredGrid::New();
>>
>>      pUnsGrid->Allocate(4, 4);
>>      pUnsGrid->SetPoints(pPoints);
>>
>>      vtkTetra * pTetra = vtkTetra::New();
>>      vtkIdList * pTetraIdList = pTetra->GetPointIds();
>>
>>      for (int j = 0; j < 4; ++j)
>>            pTetraIdList->SetId(j, j);
>>
>>      pUnsGrid->InsertNextCell(pTetra->GetCellType(), pTetraIdList);
>>
>>      vtkOpenGLActor * pActor = vtkOpenGLActor::New();
>>      vtkDataSetMapper * pMapper = vtkDataSetMapper::New();
>>      pActor->SetMapper(pMapper);
>>      pActor->GetProperty()->SetColor(GetTetraColor(t));
>>      pActor->SetScale(.1,.1,.1);
>>      pMapper->SetInput(pUnsGrid);
>>      vecActors[t] = pActor;
>> }
>>
>> // Using vecActors to display all the tetrahedrons with different colors
>> each!
>>
>> I have to find another way to enable different colors for each 
>> tetrahedron
>> because its very importent to this application. The colors have to
>> visualize the mesh's temperatures of a drilling simulation demo.
>>
>> Thanks for reading my problem, I am looking forward for some ideas 
>> how to
>> solve this problem!
>>
>> Cheers,
>>
>> Paul Bütow
>>
>>
>> -----------------------------------------------------------------
>> Paul C. Buetow
>> Fraunhofer Institut für
>> Produktionstechnologie IPT
>> Virtual Reality Labor
>> Steinbachstraße 17
>> 52074 Aachen
>>
>> E-Mail: paul.buetow at ipt.fraunhofer.de
>> Internet: www.ipt.fraunhofer.de
>>
>> _______________________________________________
>> 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
>>
>>
>------------------------------------------------------------------------
>
>_______________________________________________
>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
>  
>




More information about the vtkusers mailing list