Hi everyone,
I am trying to use a vtkHardwareSelector with an OSMesa-based VTK distribution. And it does not work so far β¦ help !
Has anyone ever attempted this ?
I tried looking on the Paraview side, but nothing obivous jumped out when trying to get info on how PV does the selection offscreen with OSMesa.
Below are the CMake build & the piece of code that is relevant to the operation. Thank you very much in advance for your help !
The CMake build is done like this :
cmake \
-DCMAKE_C_COMPILER=${CC} \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_C_FLAGS="-Wno-incompatible-function-pointer-types" \
-DCMAKE_CXX_FLAGS="-Wno-incompatible-function-pointer-types" \
-DCMAKE_EXE_LINKER_FLAGS="-L${LLVM_ROOT}/lib/c++ -Wl,-rpath,${LLVM_ROOT}/lib/c++" \
-DVTK_USE_COCOA=OFF \
-DVTK_USE_X=OFF \
-DVTK_OPENGL_HAS_OSMESA=ON \
-DOSMESA_INCLUDE_DIR=${MESA_ROOT}/include \
-DOSMESA_LIBRARY=${MESA_ROOT}/lib/libOSMesa.${LIB_SUFFIX} \
-DOPENGL_INCLUDE_DIR=IGNORE \
-DOPENGL_gl_LIBRARY=IGNORE \
-DOPENGL_xmesa_INCLUDE_DIR=IGNORE \
-DVTK_DEFAULT_RENDER_WINDOW_OFFSCREEN=OFF \
-DVTK_USE_OFFSCREEN=OFF \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=${CODE_DIR}/${SUB_DIR}/vtk/build/install \
${@} \
-S .. -B .
And based on multiple examples in the documentation I am using this snippet:
_graphics_factory = vtkSmartPointer<vtkGraphicsFactory>::New();
_graphics_factory->SetOffScreenOnlyMode(1);
_graphics_factory->SetUseMesaClasses(1);
_renderer = vtkSmartPointer<vtkRenderer>::New();
_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
_mapper->SetInputData(const_cast<vtkPolyData*>(polydata));
_actor = vtkSmartPointer<vtkActor>::New();
_actor->SetMapper(_mapper);
Vertex focal_point = centroid;
Vertex position = (focal_point - (initial_sight_direction * _bounding_sphere_radius /
std::sin(0.5 * vtkMath::RadiansFromDegrees(_field_of_view))));
_camera = vtkSmartPointer<vtkCamera>::New();
_camera->SetPosition(position.x(), position.y(), position.z());
_camera->SetFocalPoint(focal_point.x(), focal_point.y(), focal_point.z());
_renderer->SetActiveCamera(_camera);
_render_window = vtkSmartPointer<vtkRenderWindow>::New();
_render_window->AddRenderer(_renderer);
_render_window->SetSize(_window_width, _window_height);
_render_window->OffScreenRenderingOn();
_renderer->AddActor(_actor);
_hardware_selector = vtkSmartPointer<vtkOpenGLHardwareSelector>::New();
_hardware_selector->SetRenderer(_renderer);
_hardware_selector->SetArea(0, 0, _window_width - 1, _window_height - 1);
_hardware_selector->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_CELLS);
_render_window->Render();
// Pick the visible cells
vtkSelection* selection = _hardware_selector->Select();
vtkSelectionNode* selection_node = selection->GetNode(0);
vtkIdTypeArray* selection_ids =
vtkIdTypeArray::SafeDownCast(selection_node->GetSelectionList());
std::vector<vtkIdType> visible_cells;
visible_cells.reserve(selection_ids->GetNumberOfTuples());
for (vtkIdType i = 0; i < selection_ids->GetNumberOfTuples(); ++i) {
visible_cells.push_back(selection_ids->GetValue(i));
}
return visible_cells;