We had introduced a way to keep a few special models awalys on the top layer in 3D scene. The relative post: https://www.weiy.city/2020/03/make-model-always-on-top/. But it will fail to shift polygons, lines, and points sometimes, eg. when we are in the WebAssembly environment (wasm) for web page.
Let’s use an another method to get the same result.
Add a top renderer and move the target actors to the renderer, then set the same status for the new renderer’s active camera and keep it.
The following commit adds a renderer to make sure the actors in the renderer awalys on the top layer in the VTK 3D scene.

diff --git a/gMyTester.cpp b/gMyTester.cpp
index 71e8ac3..54f1df6 100644
--- a/gMyTester.cpp
+++ b/gMyTester.cpp
@@ -237,6 +237,7 @@ void CMyTester::Play()
 void CMyTester::StartLoop()
 {
     m_Renderer->GetActiveCamera()->ParallelProjectionOn();  // avoid z-buffer value issue. eg. rotated object will become very big.
+    m_OperatorRenderer->SetActiveCamera( m_Renderer->GetActiveCamera() );
     m_Renderer->GetRenderWindow()->GetInteractor()->Start();

@@ -250,6 +251,10 @@ void CMyTester::Test(std::string path)

     m_Renderer = vSP<vtkRenderer>::New();
+    m_Renderer->SetLayer( 0 );
+    m_OperatorRenderer = vSP<vtkRenderer>::New();
+    m_OperatorRenderer->SetLayer( 1 );
+    m_OperatorRenderer->SetInteractive( 0 );


@@ -259,7 +264,9 @@ void CMyTester::Test(std::string path)
 #endif

        m_RenderWindow->SetSize(1000, 600);
-    m_RenderWindow->AddRenderer(m_Renderer);
+    m_RenderWindow->SetNumberOfLayers(2);
+    m_RenderWindow->AddRenderer( m_Renderer );
+    m_RenderWindow->AddRenderer( m_OperatorRenderer );
     m_Renderer->SetRenderWindow(m_RenderWindow);

diff --git a/gMyTester.h b/gMyTester.h
index e9e7ef3..a293de5 100644
--- a/gMyTester.h
+++ b/gMyTester.h
@@ -13,7 +13,7 @@

 class CMyModel;
@@ -119,6 +119,7 @@ public:
        vSP<vtkRenderer> m_Renderer;
+       vSP<vtkRenderer> m_OperatorRenderer;

After that, we can add actors such as buttons in the m_OperatorRenderer to make sure the users’ operations successful.

Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Yaren
Yaren
15 days ago

Hi, I am working with two actors in a 3D scene, where I need one actor (highlightActor) to always appear on top of another actor (currentActor), even when they are in close proximity or overlapping. Currently, I’m facing Z-fighting issues in certain views, where the two actors seem to compete for visibility, especially when viewed from different camera angles.
I have tried using the following approaches to resolve the issue:
mapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(-1, -100);
mapper->SetResolveCoincidentTopologyToPolygonOffset();
While this works in some views, it doesn’t entirely solve the problem as the highlightActor sometimes still appears behind the other actor, depending on the camera angle.
Like this:
comment image
I try 2 renderer but I have same problem like topology.
comment image

What I actually want to do is to make sure that the two actors do not interfere with each other:
comment image

I would like to know if there is a more reliable method in VTK to ensure that one actor always renders on top of another, regardless of camera angle or geometry.
Thank you for your help!

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
2
0
Would love your thoughts, please comment.x
()
x