|
|
@@ -14,7 +14,7 @@
|
|
|
|
|
|
struct augment_renderer::impl {
|
|
|
const cv::cuda::GpuMat *bg_img = nullptr;
|
|
|
- GLuint bg_tex = 0, bg_pbo = 0;
|
|
|
+ GLuint bg_tex = 0, remap_tex = 0, bg_pbo = 0;
|
|
|
cudaGraphicsResource *bg_res = nullptr;
|
|
|
|
|
|
texture_renderer *tex_renderer = nullptr;
|
|
|
@@ -39,27 +39,35 @@ struct augment_renderer::impl {
|
|
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
|
|
|
|
|
// generate and allocate texture
|
|
|
- glGenTextures(1, &bg_tex);
|
|
|
+ static_assert(offsetof(impl, remap_tex) - offsetof(impl, bg_tex) == sizeof(GLuint));
|
|
|
+ glGenTextures(2, &bg_tex);
|
|
|
glBindTexture(GL_TEXTURE_2D, bg_tex);
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, image_width, image_height);
|
|
|
|
|
|
+ // config remap texture
|
|
|
+ glBindTexture(GL_TEXTURE_2D, remap_tex);
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, image_width, image_height, 0, GL_RG, GL_FLOAT, cam_info->remap_data);
|
|
|
+
|
|
|
// register background pbo
|
|
|
CUDA_API_CHECK(cudaGraphicsGLRegisterBuffer(&bg_res, bg_pbo,
|
|
|
cudaGraphicsRegisterFlagsWriteDiscard));
|
|
|
|
|
|
// setup vtk
|
|
|
vtk_render = vtkSmartPointer<vtkRenderer>::New();
|
|
|
-// vtk_render->SetBackground(0.4, 0.4, 0.4);
|
|
|
-// vtk_render->SetBackgroundAlpha(0.1);
|
|
|
vtk_window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
|
|
|
vtk_window->InitializeFromCurrentContext();
|
|
|
- vtk_window->SetSize(image_width, image_height);
|
|
|
+ vtk_window->SetSize(cam_info->width, cam_info->height);
|
|
|
vtk_window->SetAlphaBitPlanes(true);
|
|
|
vtk_window->SetOffScreenRendering(true);
|
|
|
+ vtk_window->FramebufferFlipYOn();
|
|
|
vtk_window->AddRenderer(vtk_render);
|
|
|
vtk_cam = vtkSmartPointer<vtkCamera>::New();
|
|
|
+ vtk_cam->SetViewAngle(cam_info->angle);
|
|
|
+ vtk_cam->SetClippingRange(default_len_focus, 2000);
|
|
|
vtk_render->SetActiveCamera(vtk_cam);
|
|
|
|
|
|
return true;
|
|
|
@@ -88,7 +96,8 @@ struct augment_renderer::impl {
|
|
|
assert(tex_renderer != nullptr);
|
|
|
assert(config != nullptr);
|
|
|
texture_renderer::render_config tex_config{
|
|
|
- .tex = bg_tex,
|
|
|
+ .image_tex = bg_tex,
|
|
|
+ .remap_tex = 0,
|
|
|
.x = config->x,
|
|
|
.y = config->y,
|
|
|
.width = config->width,
|
|
|
@@ -101,14 +110,11 @@ struct augment_renderer::impl {
|
|
|
|
|
|
void set_camera_pose(const Eigen::Isometry3d &cam_trans) {
|
|
|
auto trans_part = cam_trans.translation();
|
|
|
- auto focal_point = trans_part + cam_trans.rotation().col(2) * cam_info->focal_length;
|
|
|
- auto view_up = cam_trans.rotation().col(1);
|
|
|
+ auto focal_point = trans_part + cam_trans.rotation().col(2) * default_len_focus;
|
|
|
+ auto view_up = -cam_trans.rotation().col(1);
|
|
|
vtk_cam->SetPosition(trans_part.x(), trans_part.y(), trans_part.z());
|
|
|
vtk_cam->SetFocalPoint(focal_point.x(), focal_point.y(), focal_point.z());
|
|
|
vtk_cam->SetViewUp(view_up.x(), view_up.y(), view_up.z());
|
|
|
- vtk_cam->SetWindowCenter(cam_info->window_center.x, cam_info->window_center.y);
|
|
|
- vtk_cam->SetViewAngle(cam_info->view_angle);
|
|
|
- vtk_cam->SetClippingRange(cam_info->focal_length, 2000);
|
|
|
vtk_cam->Modified();
|
|
|
vtk_render->Modified();
|
|
|
}
|
|
|
@@ -119,10 +125,11 @@ struct augment_renderer::impl {
|
|
|
auto vtk_tex = vtk_window->GetDisplayFramebuffer()
|
|
|
->GetColorAttachmentAsTextureObject(0)->GetHandle();
|
|
|
texture_renderer::render_config tex_config{
|
|
|
- .tex = vtk_tex,
|
|
|
- .x = config->x + config->width,
|
|
|
+ .image_tex = vtk_tex,
|
|
|
+ .remap_tex = remap_tex,
|
|
|
+ .x = config->x,
|
|
|
.y = config->y,
|
|
|
- .width = -config->width,
|
|
|
+ .width = config->width,
|
|
|
.height = config->height
|
|
|
};
|
|
|
tex_renderer->render(&tex_config);
|