[hd, hdui] Add a button on the Hydra Scene Browser to dump scene index contents to...
authorrajabala <rajabala@users.noreply.github.com>
Mon, 22 Jan 2024 22:36:35 +0000 (14:36 -0800)
committerpixar-oss <pixar-oss@users.noreply.github.com>
Mon, 22 Jan 2024 23:03:27 +0000 (15:03 -0800)
(Internal change: 2312284)

extras/imaging/examples/hdui/sceneIndexDebuggerWidget.cpp
pxr/imaging/hd/utils.cpp
pxr/imaging/hd/utils.h

index 2a01a10a9027d29c4c127a529cce814b57b44be1..4ae20e4ccea39be64b9960e2147a60bbeb81d4fc 100644 (file)
@@ -30,7 +30,9 @@
 #include "sceneIndexObserverLoggingTreeView.h"
 
 #include "pxr/imaging/hd/filteringSceneIndex.h"
+#include "pxr/imaging/hd/utils.h"
 
+#include "pxr/base/arch/fileSystem.h"
 #include "pxr/base/tf/stringUtils.h"
 
 #include <QHBoxLayout>
@@ -38,6 +40,7 @@
 #include <QSplitter>
 #include <QWidgetAction>
 
+#include <fstream>
 #include <iostream>
 #include <sstream>
 #include <typeinfo>
@@ -67,6 +70,9 @@ HduiSceneIndexDebuggerWidget::HduiSceneIndexDebuggerWidget(QWidget *parent)
     QPushButton * loggerButton = new QPushButton("Show Notice Logger");
     toolbarLayout->addWidget(loggerButton);
 
+    QPushButton * writeToFileButton = new QPushButton("Write to file");
+    toolbarLayout->addWidget(writeToFileButton);
+
     toolbarLayout->addStretch();
 
     QSplitter * splitter = new QSplitter(Qt::Horizontal);
@@ -126,6 +132,33 @@ HduiSceneIndexDebuggerWidget::HduiSceneIndexDebuggerWidget(QWidget *parent)
                     this->_currentSceneIndex);
             }
     });
+
+    QObject::connect(writeToFileButton, &QPushButton::clicked,
+        [this](){
+            const HdSceneIndexBaseRefPtr si = this->_currentSceneIndex;
+            if (si) {
+                const std::string fileNamePrefix =
+                    "si_" + si->GetDisplayName() + "_";
+                
+                std::string filePath;
+                if (ArchMakeTmpFile(fileNamePrefix, &filePath) == -1) {
+                    TF_RUNTIME_ERROR(
+                        "Could not create file to write out scene index.");
+                    return;
+                }
+
+                // XXX May be useful to allow a subtree to be dumped.
+                //     For now, use the absolute root.
+                const SdfPath &rootPath = SdfPath::AbsoluteRootPath();
+
+                std::fstream output(filePath, std::ios::out);
+                HdUtils::PrintSceneIndex(output, si, rootPath);
+                output.close();
+
+                std::cerr << "Wrote scene index contents to "
+                          << filePath << std::endl;
+            }
+    });
 }
 
 void
index 5188620b37c518aec1c7fc9d7918799338341be1..832cdc837eda8e45d731156390a5646df9434d3e 100644 (file)
 
 #include "pxr/imaging/hd/sceneGlobalsSchema.h"
 #include "pxr/imaging/hd/sceneIndex.h"
+#include "pxr/imaging/hd/sceneIndexPrimView.h"
 #include "pxr/imaging/hd/tokens.h"
 
-#include "pxr/usd/sdf/path.h"
-
 PXR_NAMESPACE_OPEN_SCOPE
 
 namespace HdUtils {
@@ -86,6 +85,34 @@ ToConformWindowPolicy(const TfToken &token)
     return CameraUtilFit;
 }
 
+void
+PrintSceneIndex(
+    std::ostream &out,
+    const HdSceneIndexBaseRefPtr &si,
+    const SdfPath &rootPath /* = SdfPath::AbsoluteRootPath()*/)
+{
+    // Traverse the scene index to populate a lexicographically 
+    // ordered path set.
+    SdfPathSet primPathSet;
+    HdSceneIndexPrimView view(si, rootPath);
+    for (auto it = view.begin(); it != view.end(); ++it) {
+        const SdfPath &primPath = *it;
+        primPathSet.insert(primPath);
+    }
+
+    // Write out each prim without indenting it based on its depth in the 
+    // hierarchy for ease of readability,
+    for (const SdfPath &primPath : primPathSet) {
+        HdSceneIndexPrim prim = si->GetPrim(primPath);
+        if (prim.dataSource) {
+            out << "<" << primPath << "> type = " << prim.primType << std::endl;
+            
+            HdDebugPrintDataSource(out, prim.dataSource, /* indent = */1);
+        }
+    }
+}
+
+
 }
 
 PXR_NAMESPACE_CLOSE_SCOPE
index 3ed4add363327da1d1c7c99cf77d6f661903af53..a92b407aa7e05fdd0c42e2a79eef225e3006e88f 100644 (file)
@@ -30,7 +30,9 @@
 #include "pxr/imaging/cameraUtil/conformWindow.h"
 
 #include "pxr/base/tf/declarePtrs.h"
+#include "pxr/usd/sdf/path.h"
 
+#include <iosfwd>
 #include <memory>
 #include <string>
 #include <unordered_map>
@@ -39,7 +41,6 @@ PXR_NAMESPACE_OPEN_SCOPE
 
 TF_DECLARE_REF_PTRS(HdSceneIndexBase);
 
-class SdfPath;
 class TfToken;
 
 namespace HdUtils {
@@ -138,10 +139,21 @@ HasActiveRenderSettingsPrim(
 
 /// Translate the given aspect ratio conform policy \p token into an equivalent 
 /// CameraUtilConformWindowPolicy enum. 
+///
 HD_API
 CameraUtilConformWindowPolicy
 ToConformWindowPolicy(const TfToken &token);
 
+/// Lexicographically sorts the scene index prims in the subtree rooted at
+/// \p rootPath and writes them out.
+///
+HD_API
+void
+PrintSceneIndex(
+    std::ostream &out,
+    const HdSceneIndexBaseRefPtr &si,
+    const SdfPath &rootPath = SdfPath::AbsoluteRootPath());
+
 }
 
 PXR_NAMESPACE_CLOSE_SCOPE