[vtkusers] Help with Vtk when rendering millions of points

David E DeMarle dave.demarle at kitware.com
Tue Aug 7 07:58:17 EDT 2012


10 million points seems like a lot. I suspect that OpenGL/GPU is the
bottleneck.

Once you get down to a self contained small example like David says,
first use vtkTimerLog to see what class specifically is taking so much
time.

If it turns out to be rendering, try calling
vtkPolyDataMapper::ImmediateModeRenderingOn/Off() to turn display
lists off/on. That can make a significant difference for larger
meshes. If that doesn't work, I don't see how having different
RenderWindow layers will help you. However I have heard of people
getting good results when they break up the whole mesh into many small
meshes. Twenty mappers each with half a million points might do in
your case. As I recall though, that performance result turned out to
be card and driver dependent so it may have no effect at all or may
slow things down.

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909


On Tue, Aug 7, 2012 at 7:02 AM, David Doria <daviddoria at gmail.com> wrote:
> On Tue, Aug 7, 2012 at 5:19 AM, ikatz <ikatzbilb at hotmail.com> wrote:
>>
>> I can't provide a self-contained example because the code is quite complex
>> and uses another libraries for other purposes, it would be impossible to
>> compile everything. Anyway, I will try to explain as best as possible.
>> We are using what we call gfxPointClouds, an structure that holds all the
>> poins of the point cloud, and after getting the number of points we use
>> vtkPolyData structures to manage all the points. This point cloud element
>> is
>> treated as other elements like spheres or lines in our vtkRenderWindow,
>> the
>> problem is that when we want to "refresh" the whole Viewport (working with
>> >10 million point clouds) it takes a lot of time (sometimes 1 minute) or
>> does not even load the point cloud and the program fails. I don't know if
>> there is another way of managing this point clouds structures in VTK other
>> than vtkPolyData or if it's normal to last so match...
>>
>> Here is the code:
>>
>> const gfxPointCloud3* cop = dynamic_cast<const
>> gfxPointCloud3*>(pointCloud);
>>         unsigned int iNumPoints = cop->GetNumElements();
>>
>>         //Reset to an empty state and free any memory.
>>         m_PolyData->Initialize();
>>
>>         //No points, no work.
>>         if( iNumPoints > 0 )
>>         {
>>                 vtkPoints* pointSet = vtkPoints::New();
>>                 pointSet->Allocate(iNumPoints);
>>                 vtkCellArray* cellSet = vtkCellArray::New();
>>                 vtkBitArray* selectSet = vtkBitArray::New();
>>                 vtkFloatArray* scalarSet = vtkFloatArray::New();
>>
>>                 pointSet->SetNumberOfPoints( iNumPoints );
>>                 selectSet->SetNumberOfValues( iNumPoints );
>>
>>                 switch( cop->GetAttributeSize() )
>>                 {
>>                         case 1: //char (8 bits)
>>                         case 2: //short (16 bits)
>>                         case 4: //int (32 bits)
>>                         case 8: //double (64 bits)
>>                                 m_AttributeSize = cop->GetAttributeSize();
>>                                 scalarSet->SetNumberOfValues( iNumPoints
>> );
>>                                 bAttribute = true;
>>                                 break;
>>                         default: //invalid size: disable the color map.
>>                                 m_AttributeSize = 0;
>>                                 m_Map->ScalarVisibilityOff();
>>                 }
>>
>>                 gfxPoint3 point;
>>                 for( unsigned int i=0; i<iNumPoints; i++ )
>>                 {
>>                         //Add the point to the point list.
>>                         point = cop->GetElement(i);
>>                         pointSet->SetPoint(     i, point.x(), point.y(),
>> point.z() );
>>
>>                         //Create a new cell and add the new point to it.
>>                         cellSet->InsertNextCell( 1 );
>>                         cellSet->InsertCellPoint( i );
>>
>>                         //Mark the new point as not selected.
>>                         selectSet->SetValue( i, 0 );
>>
>>                         //IF{} just to speed-up when there is no attribute
>> in the point cloud.
>>                         if( bAttribute )
>>                         {
>>                                 switch( m_AttributeSize )
>>                                 {
>>                                         //All types are converted to
>> float.
>>                                         case 1: //char (8 bits)
>>                                                 scalarSet->SetValue( i,
>> *((char*)(cop->GetAttribute(i))) );
>>                                                 break;
>>                                         case 2: //short (16 bits)
>>                                                 scalarSet->SetValue( i,
>> *((short*)(cop->GetAttribute(i))) );
>>                                                 break;
>>                                         case 4: //int (32 bits)
>>                                                 scalarSet->SetValue( i,
>> *((int*)(cop->GetAttribute(i))) );
>>                                                 break;
>>                                         case 8: //double (64 bits)
>>                                                 scalarSet->SetValue( i,
>> *((double*)(cop->GetAttribute(i))) );
>>                                                 break;
>>                                 }
>>                         }
>>                 }
>>
>>                 m_PolyData->SetPoints( pointSet );
>>                 m_PolyData->SetVerts( cellSet );
>>
>>                 //Associate the selection scalar with the cells.
>>                 m_PolyData->GetCellData()->SetScalars( selectSet );
>>
>>                 //Associate the attribute scalar with the points.
>>                 if( bAttribute )
>>                         m_PolyData->GetPointData()->SetScalars( scalarSet
>> );
>>
>>                 m_PolyData->Modified();
>>
>>                 m_Map->SetInput( m_PolyData );
>>                 m_SelectionMap->SetInput( m_PolyData );
>>
>>                 scalarSet->Delete();
>>                 selectSet->Delete();
>>                 cellSet->Delete();
>>                 pointSet->Delete();
>>          }
>
>
> You should be able to turn that into a working demo without much trouble. It
> looks like you can just replace your custom data type with a  vtkPointSource
> (http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PointSource ) to produce
> some random data. Of course you'll also have to make the member variables
> defined in this demo scope, etc.
>
> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK 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