[vtkusers] Help with Vtk when rendering millions of points

ikatz ikatzbilb at hotmail.com
Tue Aug 7 05:19:34 EDT 2012


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();
	}



--
View this message in context: http://vtk.1045678.n5.nabble.com/Help-with-Vtk-when-rendering-millions-of-points-tp5715120p5715137.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list