I am building a simple tool for manipulating point clouds. I want to be able to do do a polygonal selection on mouse move. I am working with VTK 5.10 and QVTKWidget in Ubuntu 12.04.
To do this, I built a polygonalSelector class by modifying the test file : TestPolygonSelection.cxx at https://github.com/Kitware/VTK/blob/master/Rendering/Core/Testing/Cxx/TestPolygonSelection.cxx The modifications are those needed to use VTK 5.10 instead of vtk 6 as described here : (note that I need to use the old version) http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput
In the code, a polygonal shape is drawn and then a vtkHardwareSelector object vtkNew<vtkHardwareSelector> hardSel;
is used for its method of GeneratePolygonSelection:
The problem I am running into is when the next condition is tested :
if (hardSel->CaptureBuffers())
Internally, CaptureBuffers() contains code that does this:
vtkRenderWindow *rwin = this->Renderer->GetRenderWindow();
int rgba[4];
rwin->GetColorBufferSizes(rgba);
if (rgba[0] < 8 || rgba[1] < 8 || rgba[2] < 8)
{
vtkErrorMacro("Color buffer depth must be atleast 8 bit. "
"Currently: " << rgba[0] << ", " << rgba[1] << ", " <<rgba[2]);
return false;
}
I never get past this point because it always returns false. I have no clue how to set the ColorBufferSizes and I have not been able to find info online to clear this point. This is the error output:
vtkHardwareSelector (0x168dcd0): Color buffer depth must be atleast 8 bit. Currently: 17727456, 0, 23649488
On debugging, the rgba int is never changed (it stays the same before and after the call to rwin->GetColorBufferSizes(rgba)
).
On the Documentation for vtkRenderWindow it states that :
virtual int vtkRenderWindow::GetColorBufferSizes ( int * rgba )
Get the size of the color buffer. Returns 0 if not able to determine otherwise sets R G B and A into buffer.
Implemented in vtkOpenGLRenderWindow, and vtkOpenGLRenderWindow.
Do I need to use vtkOpenGLRenderWindow? On its Class reference it states that "Application programmers should normally use vtkRenderWindow instead of the OpenGL specific version."
Any ideas?
EDIT
I believe the problem stems from the VTK 5.10 vs VTK 6 differences.
I did manage to implement the polygonal selection using a different approach. If anyone intends to implement some kind of polygonal selection in the future, they might find these steps useful:
I sub-classed vtkInteractorStyleDrawPolygon and implemented the following steps inside the OnLeftButtonUp() method:
Get points on button release:
std::vector<vtkVector2i> points = this->GetPolygonPoints();
Insert points to vtkDoubleArray
Insert the vtkDoubleArray into a vtkPolygon
Get the polygon's numPoints, normal and bounds.
Get pointer to the double array inside the polygon data pts.
pts = static_cast<double*>(polygon->GetPoints()->GetData()->GetVoidPointer(0);
For each point P in the vtkPolyData, do :
inside = polygon->PointInPolygon(P,numPoints, pts, bounds,normal)
Add points to a vtkSelection when inside == 1