JuliaPCL/PCL.jl

VTK IJulia integration

Closed this issue · 2 comments

r9y9 commented

TODO:

  • Off-screen rendering
  • Render to Julia array so that it can be encoded as base64 string in a notebook
  • Changing camera parameters
r9y9 commented

memo:

cv::Mat render_to_cvmat(vtkSmartPointer<vtkRenderWindow> &renderWindow) {
  renderWindow->Render();

  vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
      vtkSmartPointer<vtkWindowToImageFilter>::New();
  windowToImageFilter->SetInput(renderWindow);
  windowToImageFilter->Update();

  vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
  writer->SetWriteToMemory(1);
  writer->SetInputConnection(windowToImageFilter->GetOutputPort());
  writer->Write();

  auto rawPngBuffer = writer->GetResult();
  auto rawPointer = rawPngBuffer->GetPointer(0);
  auto total_size =
      rawPngBuffer->GetDataSize() * rawPngBuffer->GetDataTypeSize();
  std::vector<unsigned char> buffer(rawPointer, rawPointer + total_size;

  // Finally decode buffer to cv::Mat
  cv::Mat mat = cv::imdecode(buffer, 1);
  return mat;
}
r9y9 commented

https://gist.github.com/r9y9/6ed9a1d0b46993d374f5 demonstration notebook is here. Done