MCPcopy Create free account
hub / github.com/Kitware/VTK / Capture

Method Capture

Rendering/Parallel/vtkSynchronizedRenderers.cxx:790–846  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

788
789//------------------------------------------------------------------------------
790bool vtkSynchronizedRenderers::vtkRawImage::Capture(vtkRenderer* ren)
791{
792 double viewport[4];
793 ren->GetViewport(viewport);
794
795 int window_size[2];
796 window_size[0] = ren->GetVTKWindow()->GetActualSize()[0];
797 window_size[1] = ren->GetVTKWindow()->GetActualSize()[1];
798
799 int viewport_in_pixels[4];
800 viewport_in_pixels[0] = static_cast<int>(window_size[0] * viewport[0]);
801 viewport_in_pixels[1] = static_cast<int>(window_size[1] * viewport[1]);
802 viewport_in_pixels[2] = static_cast<int>(window_size[0] * viewport[2]) - 1;
803 viewport_in_pixels[3] = static_cast<int>(window_size[1] * viewport[3]) - 1;
804
805 // we need to ensure that the size computation is always done in pixels,
806 // otherwise we end up with rounding issues. In short, avoid doing
807 // additions/subtractions using normalized viewport coordinates. Those are
808 // better done in pixels.
809 int image_size[2];
810 image_size[0] = viewport_in_pixels[2] - viewport_in_pixels[0] + 1;
811 image_size[1] = viewport_in_pixels[3] - viewport_in_pixels[1] + 1;
812
813 // using RGBA always?
814 this->Resize(image_size[0], image_size[1], 4);
815
816 ren->GetRenderWindow()->GetRGBACharPixelData(viewport_in_pixels[0], viewport_in_pixels[1],
817 viewport_in_pixels[2], viewport_in_pixels[3], 0, this->GetRawPtr(),
818 /*right=*/ren->GetActiveCamera()->GetLeftEye() == 0);
819
820 // if selecting then pass the processed pixel buffer
821 vtkHardwareSelector* sel = ren->GetSelector();
822 if (sel)
823 {
824 unsigned char* passdata = sel->GetPixelBuffer(sel->GetCurrentPass());
825 unsigned char* destdata = this->GetRawPtr()->GetPointer(0);
826 if (passdata && destdata)
827 {
828 unsigned int* area = sel->GetArea();
829 unsigned int passwidth = area[2] - area[0] + 1;
830 for (int y = 0; y < image_size[1]; ++y)
831 {
832 for (int x = 0; x < image_size[0]; ++x)
833 {
834 unsigned char* pdptr = passdata + (y * passwidth + x) * 3;
835 destdata[0] = pdptr[0];
836 destdata[1] = pdptr[1];
837 destdata[2] = pdptr[2];
838 destdata += 4;
839 }
840 }
841 }
842 }
843
844 this->MarkValid();
845 return true;
846}
847

Callers 2

RenderMethod · 0.80

Calls 10

GetViewportMethod · 0.80
GetActualSizeMethod · 0.80
GetVTKWindowMethod · 0.80
GetActiveCameraMethod · 0.80
MarkValidMethod · 0.80
ResizeMethod · 0.45
GetRGBACharPixelDataMethod · 0.45
GetRenderWindowMethod · 0.45
GetSelectorMethod · 0.45
GetPointerMethod · 0.45

Tested by

no test coverage detected