# how to add an image to render window which had point cloud already

**URL:** https://discourse.vtk.org/t/how-to-add-an-image-to-render-window-which-had-point-cloud-already/13863
**Category:** Support
**Tags:** code
**Created:** [May 10, 2024, 6:14pm UTC](https://discourse.vtk.org/t/how-to-add-an-image-to-render-window-which-had-point-cloud-already/13863 "2024-05-10T18:14:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Yang\_Tianxi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yang_tianxi/32/8793_2.png) [@Yang\_Tianxi](https://discourse.vtk.org/u/Yang_Tianxi)
#### Post date: [May 10, 2024, 6:14pm UTC](https://discourse.vtk.org/t/how-to-add-an-image-to-render-window-which-had-point-cloud-already/13863/1 "2024-05-10T18:14:12Z")

</div>

I write following function to add an image to a rendered window which contained point cloud, it failed

```auto
void addImageToview(vtkRenderWindowInteractor* interactor, vtkSmartPointer<vtkRenderWindow> renderWindow, const std::string &imagePath, double &x, double &y, double &x_wide, double &y_wide, double &opaticy)
{
	   vtkSmartPointer<vtkJPEGReader> reader = vtkSmartPointer<vtkJPEGReader>::New();
	   reader->SetFileName(imagePath.c_str());/*no multiple coding format*/
	  reader->Update();

	   vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
        //vtkSmartPointer<vtkRenderWindow> renderWindow = 
        vtkSmartPointer<vtkRenderWindow>::New(); //** comment out this line, the passed renderWindow will be erased.
        renderWindow->AddRenderer(renderer);  

        // Create a vtkImageActor to display the image
        vtkSmartPointer<vtkImageActor> imageActor = vtkSmartPointer<vtkImageActor>::New();
        imageActor->SetInputData(reader->GetOutput());
	    imageActor->SetPosition(x, y,0);

        // Add the image actor to the renderer as an overlay
        renderer->AddActor2D(imageActor); // AddActor2D adds the actor as an overlay, keeping existing actors intact
		
}

```

where, vtkRenderWindowInteractor\* interactor, vtkSmartPointer renderWindow contained point cloud,see blow

 ![vtk_lidar](https://discourse.vtk.org/uploads/default/original/2X/8/89268651744199ed78a169922b2949c9f83d9e0d.png)

if I comment out this line marked by \*\*, the passed renderWindow of function parameter will be erased. only the image showed,

 ![VTK_IMG](https://discourse.vtk.org/uploads/default/original/2X/a/a0065732bdadfab209bebbeed5dd8a79676be3d0.jpeg)

I want to show both an image on the point cloud(put the image at given postion of the screen), like below,

![LC](https://discourse.vtk.org/uploads/default/original/2X/5/58f751fa8746132ed99bee905a0b06ba691d9bad.jpeg)

how to implemented this function?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [May 10, 2024, 9:06pm UTC](https://discourse.vtk.org/t/how-to-add-an-image-to-render-window-which-had-point-cloud-already/13863/2 "2024-05-10T21:06:05Z")

</div>

Hello,

Why are you trying to create another `vtkRenderWindow` inside the function? Aren’t you supposed to use the one passed as argument?

best,

PC

---

<div class="post-metadata">

### Author: ![Yang\_Tianxi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yang_tianxi/32/8793_2.png) [@Yang\_Tianxi](https://discourse.vtk.org/u/Yang_Tianxi)
#### Post date: [May 11, 2024, 6:18am UTC](https://discourse.vtk.org/t/how-to-add-an-image-to-render-window-which-had-point-cloud-already/13863/3 "2024-05-11T06:18:22Z")

</div>

I want to use the passed _renderWindow_ as argument. my winodow is

```auto
  renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
  renderWindow->AddRenderer(renderer_lidar);

```

when I try to add a image view,such as  
` renderWindow->AddRenderer(renderer_image);`  
than renderer\_lidar is erased by renderer\_image

If I addd an image(via vtkImageActor) to renderer\_lidar, it is ok, adding to main window failed

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [May 12, 2024, 9:20pm UTC](https://discourse.vtk.org/t/how-to-add-an-image-to-render-window-which-had-point-cloud-already/13863/4 "2024-05-12T21:20:54Z")

</div>

So don’t create one inside the function. Just remove `New()` call from inside `addImageToview()`.

---

<div class="post-metadata">

### Author: ![Yang\_Tianxi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yang_tianxi/32/8793_2.png) [@Yang\_Tianxi](https://discourse.vtk.org/u/Yang_Tianxi)
#### Post date: [May 15, 2024, 10:02am UTC](https://discourse.vtk.org/t/how-to-add-an-image-to-render-window-which-had-point-cloud-already/13863/5 "2024-05-15T10:02:07Z")

</div>

That’s the point here, when I add `addImageToview(),` the previous point cloud is erased by image, I want show them simutaneously, and image not ratoated with pointcloud
