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