How to only render one vtkRender in vtkRenderWindow with two vtkRenders

Hello everyone,
I want to draw a polygon on the volumn data in freehand drawing. When mouse move, the volumn data and the ploygon render together, so the screen will stutter.
So I split the two data into two renders, when mosue move, only render the vtkRender with polygon. The method works, but the drawing result is wrong, I want the polygon without triangles.

m_pClipRender = vtkRenderer::New();
 this->m_pClipRender->SetLayer(1);

vtkNew<vtkPoints> points1;
for (int i = 0; i < vecDisPts.size(); i++)
{
	points1->InsertNextPoint(vecDisPts[i].GetX(), vecDisPts[i].GetY(), 0.0);
}
 
 vtkNew<vtkCellArray> polys1;
 polys1->InsertNextCell(points1->GetNumberOfPoints() + 1);
 for (int i = 0; i < points1->GetNumberOfPoints(); i++)
 {
 	polys1->InsertCellPoint(i);
 }
 polys1->InsertCellPoint(0);

//Polyline
m_pClipPolylinePolyData->SetPoints(points1);
m_pClipPolylinePolyData->SetLines(polys1);

The code for creating the polyline seems fine. I wonder if you’re adding a new actor to the renderer (or a new renderer) each time the polyline is re-created.

I think you need to remove this line from your code:

You only only want to do that when the polygon is complete.

Also, you asked about “one vtkRenderWindow, two vtkRenderers”, maybe the following information is useful:

The color buffer and the depth buffer are owned by the window, not by the renderers. The renderers share the window’s color buffer and depth buffer. So when you render the polygon (in Layer 1), the rendered pixels stay in the buffer until the volume (in Layer 0) is re-rendered.

1 Like

If I remove this line, the result is a polyline, not a closed polygon.Like this:

 	vtkNew<vtkCellArray> polys1;
 	polys1->InsertNextCell(points1->GetNumberOfPoints()/* + 1*/);
 	for (int i = 0; i < points1->GetNumberOfPoints(); i++)
 	{
 		polys1->InsertCellPoint(i);
 	}
// 	polys1->InsertCellPoint(0);

When the left mouse button is pressed, I create vtkPolyData, vtkPolyDataMapper2D, and vtkActor2D; When the mouse moves, I just update the point information in vtkPolyData.

So you mean you that you want the polygon to be filled, not empty? You can use the vtkContourTriangulator filter for that.

Thanks for your kindly reply!
At first, I hope the polygon is filled, but during the drawing process, the problem of concave polygons and self-intersecting polygons can occur, which can lead to repeated drawing.Like this:


I want the result, like this:

Because this problem is not solved, I now want the polygon to be empty!

Maybe that’s the problem, is there a way to make the process of drawing polygons not jammed, in one vtkRenderWindow with one vtkRender?

I don’t know what you mean, what is “not jammed”?

Maybe after rendering the volume, you want to save the color buffer (the image in the window), and then re-use that image instead of re-rendering the volume every time? That would fix the stutter. But I don’t know a good way to do that with VTK.

I think the issue is something to do with the points themselves where the first point is being repeated somehow. Perhaps, share more of your code to provide more insight.

@Pisces2018 Hi there! It’s very inspiring! I am implementing this feature, too. I am curious that each time when activating the clip function, do you create a new renderer for the window and when finishing the clipping, you null it? And how to update polylines without influcing the volume(before I really need to delete something)? I tried to add widget instead of actor/mapper but it seems not correct.