From 7023daa1cc0a6a3ac03d57cd7f576c368eac1eec Mon Sep 17 00:00:00 2001
From: Mathias Paulin <mathias.paulin@irit.fr>
Date: Tue, 22 Feb 2022 20:09:43 +0100
Subject: [PATCH] [librender] small improvements

---
 src/libRender/CMakeLists.txt                  |  3 +-
 .../Gui/NodeEditor/src/FlowScene.cpp          |  2 +-
 .../RadiumNBR/Gui/NodeEditor/src/Node.cpp     |  4 +--
 .../RadiumNBR/Gui/NodeGraphControllerGui.cpp  |  5 ++-
 .../ConnectionStatusData.hpp                  |  4 +--
 src/libRender/RadiumNBR/NodeBasedRenderer.cpp | 32 +++++++++----------
 .../RadiumNBR/NodeGraph/RenderGraph.cpp       | 30 +++++++++--------
 .../RadiumNBR/NodeGraph/RenderGraph.hpp       |  5 ++-
 8 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/src/libRender/CMakeLists.txt b/src/libRender/CMakeLists.txt
index d43a3c5..0eb4180 100644
--- a/src/libRender/CMakeLists.txt
+++ b/src/libRender/CMakeLists.txt
@@ -276,10 +276,11 @@ set(gui_sources
     RadiumNBR/Gui/HoverPoints.cpp
     RadiumNBR/Gui/TransferEditor.cpp
 
-    RadiumNBR/Gui/RenderGraphEditor/RenderGraphEditorView.cpp
+
     RadiumNBR/Gui/RenderGraphEditor/WidgetFactory.cpp
     RadiumNBR/Gui/RenderGraphEditor/ColorSlider.cpp
     RadiumNBR/Gui/RenderGraphEditor/NodeAdapterModel.cpp
+    RadiumNBR/Gui/RenderGraphEditor/RenderGraphEditorView.cpp
     RadiumNBR/VolumeVisualization/Gui/VolumeVisualizationGui.cpp
     RadiumNBR/Gui/MultiPassControllerGui.cpp
     RadiumNBR/Gui/NodeGraphControllerGui.cpp
diff --git a/src/libRender/RadiumNBR/Gui/NodeEditor/src/FlowScene.cpp b/src/libRender/RadiumNBR/Gui/NodeEditor/src/FlowScene.cpp
index 65d779e..7f9f722 100644
--- a/src/libRender/RadiumNBR/Gui/NodeEditor/src/FlowScene.cpp
+++ b/src/libRender/RadiumNBR/Gui/NodeEditor/src/FlowScene.cpp
@@ -209,7 +209,7 @@ createNode(std::unique_ptr<NodeDataModel> && dataModel)
   return *nodePtr;
 }
 
-
+// TODO MTHS -- Add a method that takes a datamodel and only create the node.
 Node&
 FlowScene::
 restoreNode(QJsonObject const& nodeJson)
diff --git a/src/libRender/RadiumNBR/Gui/NodeEditor/src/Node.cpp b/src/libRender/RadiumNBR/Gui/NodeEditor/src/Node.cpp
index 5ef599d..7a859f3 100644
--- a/src/libRender/RadiumNBR/Gui/NodeEditor/src/Node.cpp
+++ b/src/libRender/RadiumNBR/Gui/NodeEditor/src/Node.cpp
@@ -23,6 +23,7 @@ using QtNodes::NodeGraphicsObject;
 using QtNodes::PortIndex;
 using QtNodes::PortType;
 
+// TODO MTHS -- get uuid from datamodel instead of generating one
 Node::
 Node(std::unique_ptr<NodeDataModel> && dataModel)
   : _uid(QUuid::createUuid())
@@ -86,8 +87,7 @@ restore(QJsonObject const& json)
   _nodeDataModel->restore(json);
   // This prevent to have different instances (aliases) of the same node in the graph
   _uid = QUuid(_nodeDataModel->uuid());
-  // TODO : remove the following when aliases are OK
-  _uid = QUuid(json["id"].toString());
+  // TODO : Find a way to make Node aliasing available
 
   QJsonObject positionJson = json["position"].toObject();
   QPointF     point(positionJson["x"].toDouble(),
diff --git a/src/libRender/RadiumNBR/Gui/NodeGraphControllerGui.cpp b/src/libRender/RadiumNBR/Gui/NodeGraphControllerGui.cpp
index d62495e..3f10f8a 100644
--- a/src/libRender/RadiumNBR/Gui/NodeGraphControllerGui.cpp
+++ b/src/libRender/RadiumNBR/Gui/NodeGraphControllerGui.cpp
@@ -21,9 +21,8 @@ buildNodeGraphControllerGui( NodeBasedRenderer* renderer,
     auto controlPanel = new RendererPanel( renderer->getRendererName() );
 
     auto nodeEditor     = new RenderGraphEditorView( nullptr );
-    nodeEditor->current = renderer;
-    auto editorRegistry = NodeGraphQtEditor::initializeNodeRegistry( renderer->getRenderGraph() );
-    nodeEditor->scene->setRegistry( editorRegistry );
+    nodeEditor->setGraph( renderer->getRenderGraph() );
+
 
     // TODO: find a way to refresh the main window when a widget gets updated instead of
     // when the mouse moves
diff --git a/src/libRender/RadiumNBR/Gui/RenderGraphEditor/ConnectionStatusData.hpp b/src/libRender/RadiumNBR/Gui/RenderGraphEditor/ConnectionStatusData.hpp
index 09fb79a..3d25e7a 100644
--- a/src/libRender/RadiumNBR/Gui/RenderGraphEditor/ConnectionStatusData.hpp
+++ b/src/libRender/RadiumNBR/Gui/RenderGraphEditor/ConnectionStatusData.hpp
@@ -1,8 +1,8 @@
 #pragma once
 #include <RadiumNBR/NodeBasedRendererMacro.hpp>
-#include <nodes/NodeDataModel>
+#include <RadiumNBR/NodeGraph/Node.hpp>
 
-#include "RadiumNBR/NodeGraph/Node.hpp"
+#include <nodes/NodeDataModel>
 
 #include <string>
 
diff --git a/src/libRender/RadiumNBR/NodeBasedRenderer.cpp b/src/libRender/RadiumNBR/NodeBasedRenderer.cpp
index c400b1e..e9f71a3 100644
--- a/src/libRender/RadiumNBR/NodeBasedRenderer.cpp
+++ b/src/libRender/RadiumNBR/NodeBasedRenderer.cpp
@@ -86,7 +86,6 @@ void NodeBasedRenderer::loadFromJson( const std::string& jsonFilePath ) {
 }
 
 void NodeBasedRenderer::compileRenderGraph() {
-    std::cout << "NodeBasedRenderer::compileRenderGraph\n";
     m_originalRenderGraph.init();
     m_originalRenderGraph.resize( m_width, m_height );
     buildAllRenderTechniques();
@@ -282,24 +281,25 @@ void NodeBasedRenderer::uiInternal( const ViewingParameters& renderData ) {
 }
 
 void NodeBasedRenderer::postProcessInternal( const ViewingParameters& /* renderData */ ) {
+    if (m_colorTexture) {
+        m_postprocessFbo->bind();
 
-    m_postprocessFbo->bind();
-
-    GL_ASSERT( glDrawBuffers( 1, buffers ) );
+        GL_ASSERT( glDrawBuffers( 1, buffers ) );
 
-    GL_ASSERT( glDisable( GL_DEPTH_TEST ) );
-    GL_ASSERT( glDepthMask( GL_FALSE ) );
+        GL_ASSERT( glDisable( GL_DEPTH_TEST ) );
+        GL_ASSERT( glDepthMask( GL_FALSE ) );
 
-    auto shader = m_postProcessEnabled ? m_shaderProgramManager->getShaderProgram( "Hdr2Ldr" )
-                                       : m_shaderProgramManager->getShaderProgram( "DrawScreen" );
-    shader->bind();
-    shader->setUniform( "screenTexture", m_colorTexture, 0 );
-    m_quadMesh->render( shader );
+        auto shader = m_postProcessEnabled ? m_shaderProgramManager->getShaderProgram( "Hdr2Ldr" )
+                                           : m_shaderProgramManager->getShaderProgram( "DrawScreen" );
+        shader->bind();
+        shader->setUniform( "screenTexture", m_colorTexture, 0 );
+        m_quadMesh->render( shader );
 
-    GL_ASSERT( glDepthMask( GL_TRUE ) );
-    GL_ASSERT( glEnable( GL_DEPTH_TEST ) );
+        GL_ASSERT( glDepthMask( GL_TRUE ) );
+        GL_ASSERT( glEnable( GL_DEPTH_TEST ) );
 
-    m_postprocessFbo->unbind();
+        m_postprocessFbo->unbind();
+    }
 }
 
 void NodeBasedRenderer::updateStepInternal( const ViewingParameters& renderData ) {
@@ -345,8 +345,8 @@ void NodeBasedRenderer::setDisplayNode( DisplaySinkNode* displayNode ) {
 void NodeBasedRenderer::observeDisplaySink( const std::vector<NodeTypeTexture*>& graphOutput ) {
     // TODO : find a way to make the renderer observable to manage ouput texture in the applicaiton
     // gui if needed
-    std::cout << "NodeBasedRenderer::observeDisplaySink - connected textures ("
-              << graphOutput.size() << ") : \n";
+    // std::cout << "NodeBasedRenderer::observeDisplaySink - connected textures ("
+    //          << graphOutput.size() << ") : \n";
     /*
     for ( const auto t : graphOutput )
     {
diff --git a/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp b/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp
index f6ed666..e52a737 100644
--- a/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp
+++ b/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp
@@ -149,15 +149,17 @@ void RenderGraph::loadFromJson( const std::string& jsonFilePath ) {
             {
                 std::cerr << "Error when reading JSON file \"" << jsonFilePath
                           << "\": Output index " << fromIndex << " for node \""
-                          << nodeFrom->getName() << "\" must be between 0 and "
-                          << nodeFrom->getOutputs().size() - 1 << "." << std::endl;
+                          << nodeFrom->getTypeName() << "\" must be between 0 and "
+                          << nodeFrom->getOutputs().size() - 1 << ". Link not added." << std::endl;
+                continue;
             }
         }
         else
         {
             std::cerr << "Error when reading JSON file \"" << jsonFilePath
-                      << "\": Could not find a node associated with id " << l["out_id"] << "."
+                      << "\": Could not find a node associated with id " << l["out_id"] << ". Link not added."
                       << std::endl;
+            continue;
         }
 
         if ( nodeById.find( l["in_id"] ) != nodeById.end() )
@@ -170,16 +172,18 @@ void RenderGraph::loadFromJson( const std::string& jsonFilePath ) {
             else
             {
                 std::cerr << "Error when reading JSON file \"" << jsonFilePath << "\": Input index "
-                          << toIndex << " for node \"" << nodeTo->getName()
-                          << "\" must be between 0 and " << nodeTo->getInputs().size() - 1 << "."
+                          << toIndex << " for node \"" << nodeTo->getTypeName()
+                          << "\" must be between 0 and " << nodeTo->getInputs().size() - 1 << ". Link not added."
                           << std::endl;
+                continue;
             }
         }
         else
         {
             std::cerr << "Error when reading JSON file \"" << jsonFilePath
-                      << "\": Could not find a node associated with id " << l["in_id"] << "."
+                      << "\": Could not find a node associated with id " << l["in_id"] << ". Link not added."
                       << std::endl;
+            continue;
         }
 
         if ( nodeFrom && ( fromOutput != "" ) && nodeTo && ( toInput != "" ) )
@@ -188,7 +192,7 @@ void RenderGraph::loadFromJson( const std::string& jsonFilePath ) {
         {
             std::cerr << "Error when reading JSON file \"" << jsonFilePath
                       << "\": Could not add a link (missing or wrong information, please refer to "
-                         "the previous error messages)."
+                         "the previous error messages). Link not added."
                       << std::endl;
         }
     }
@@ -200,7 +204,7 @@ bool RenderGraph::addNode( Node* newNode ) {
               << newNode->getName() << "\"..." << std::endl;
 #endif
     // Check if the new node already exists (= same name)
-    if ( findNode( newNode->getName() ) == -1 )
+    if ( findNode( newNode->getTypeName() ) == -1 )
     {
 #ifdef GRAPH_CALL_TRACE
         std::cout << "\e[32m\e[1mRenderGraph\e[0m \"" << m_name << "\": success adding node \""
@@ -226,7 +230,7 @@ bool RenderGraph::removeNode( Node* node ) {
 #endif
     // Check if the new node already exists (= same name)
     int index = -1;
-    if ( ( index = findNode( node->getName() ) ) == -1 )
+    if ( ( index = findNode( node->getTypeName() ) ) == -1 )
     {
 #ifdef GRAPH_CALL_TRACE
         std::cerr << "\e[32m\e[1mRenderGraph\e[0m \"" << m_name << "\": could not remove node \""
@@ -257,7 +261,7 @@ bool RenderGraph::addLink( Node* nodeFrom,
               << std::endl;
 #endif
     // Check node "from" existence in the graph
-    if ( findNode( nodeFrom->getName() ) == -1 )
+    if ( findNode( nodeFrom->getTypeName() ) == -1 )
     {
 #ifdef GRAPH_CALL_TRACE
         std::cerr << "ADD LINK : node \"from\" \"" + nodeFrom->getName() + "\" does not exist."
@@ -267,7 +271,7 @@ bool RenderGraph::addLink( Node* nodeFrom,
     }
 
     // Check node "to" existence in the graph
-    if ( findNode( nodeTo->getName() ) == -1 )
+    if ( findNode( nodeTo->getTypeName() ) == -1 )
     {
 #ifdef GRAPH_CALL_TRACE
         std::cerr << "ADD LINK : node \"to\" \"" + nodeTo->getName() + "\" does not exist."
@@ -367,7 +371,7 @@ bool RenderGraph::addLink( Node* nodeFrom,
 
 bool RenderGraph::removeLink( Node* node, const std::string& nodeInputName ) {
     // Check node's existence in the graph
-    if ( findNode( node->getName() ) == -1 )
+    if ( findNode( node->getTypeName() ) == -1 )
     {
 #ifdef GRAPH_CALL_TRACE
         std::cerr << "REMOVE LINK : node \"" + node->getName() + "\" does not exist." << std::endl;
@@ -410,7 +414,7 @@ bool RenderGraph::removeLink( Node* node, const std::string& nodeInputName ) {
 int RenderGraph::findNode( const std::string& name ) {
     for ( size_t i = 0; i < m_nodes.size(); i++ )
     {
-        if ( m_nodes[i]->getName() == name ) { return i; }
+        if ( m_nodes[i]->getTypeName() == name ) { return i; }
     }
 
     return -1;
diff --git a/src/libRender/RadiumNBR/NodeGraph/RenderGraph.hpp b/src/libRender/RadiumNBR/NodeGraph/RenderGraph.hpp
index 7c18fc1..0a415fa 100644
--- a/src/libRender/RadiumNBR/NodeGraph/RenderGraph.hpp
+++ b/src/libRender/RadiumNBR/NodeGraph/RenderGraph.hpp
@@ -1,9 +1,12 @@
 #pragma once
 #include <RadiumNBR/NodeBasedRendererMacro.hpp>
-#include <RadiumNBR/NodeGraph/Node.hpp>
+
 #include <RadiumNBR/NodeGraph/PremadeNodes/Sinks/DisplaySinkNode.hpp>
 #include <RadiumNBR/NodeGraph/PremadeNodes/Sources/DataNode.hpp>
 
+#include <RadiumNBR/NodeGraph/Node.hpp>
+
+
 // TODO : Find a new name, it is not a RENDER graph only anymore
 class NodeBasedRenderer_LIBRARY_API RenderGraph : public Node
 {
-- 
GitLab