From c97746bbb79d7d28277e623ca4fe6de867964ee5 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 14 Jun 2020 19:28:01 +0200 Subject: [PATCH 01/54] Prepare next dev cycle for 1.8.0 --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 497c670b..9a55f51b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,9 +43,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/dependencies.cmake) ### versioning set(PLD_VERSION_MAJOR 1) -set(PLD_VERSION_MINOR 7) +set(PLD_VERSION_MINOR 8) set(PLD_VERSION_PATCH 0) -set(PLD_VERSION_PRE "") # set to empty string for final releases +set(PLD_VERSION_PRE "-dev.0") # set to empty string for final releases if(NOT PLD_VERSION_BUILD) set(PLD_VERSION_BUILD DEV) endif() From 0f9c52c75add1671c73bcc9c27c832e397839cea Mon Sep 17 00:00:00 2001 From: Andreas Frischknecht Date: Wed, 1 Jul 2020 17:37:49 +0200 Subject: [PATCH 02/54] pipeline: activate upload reporting. (cherry picked from commit 6480caebfb125a08a3db07c585f43b5d41beafe1) --- pipeline.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pipeline.groovy b/pipeline.groovy index 7a5632ea..9239172e 100644 --- a/pipeline.groovy +++ b/pipeline.groovy @@ -6,7 +6,7 @@ import com.esri.zrh.jenkins.JenkinsTools import com.esri.zrh.jenkins.ce.CityEnginePipelineLibrary import com.esri.zrh.jenkins.ce.PrtAppPipelineLibrary -@Field def psl = new PipelineSupportLibrary(this) +@Field def psl = PslFactory.create(this, UploadTrackingPsl.ID) @Field def cepl = new CityEnginePipelineLibrary(this, psl) @Field def papl = new PrtAppPipelineLibrary(cepl) @@ -39,6 +39,7 @@ import com.esri.zrh.jenkins.ce.PrtAppPipelineLibrary // entry point for standalone pipeline def pipeline(String branchName = null) { cepl.runParallel(getTasks(branchName)) + papl.finalizeRun('palladio', myBranch) } // entry point for embedded pipeline @@ -101,4 +102,4 @@ def taskBuildPalladio(cfg) { // -- make embeddable -return this \ No newline at end of file +return this From 33bc2be6fe12712ac9b0842f0e0424dd642f52c9 Mon Sep 17 00:00:00 2001 From: Andreas Frischknecht Date: Wed, 1 Jul 2020 17:41:00 +0200 Subject: [PATCH 03/54] pipeline: added missing imports. (cherry picked from commit 7290e0411ba153253f508bb3fa85745c36f5c73b) --- pipeline.groovy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pipeline.groovy b/pipeline.groovy index 9239172e..d5c4593e 100644 --- a/pipeline.groovy +++ b/pipeline.groovy @@ -5,6 +5,8 @@ import com.esri.zrh.jenkins.PipelineSupportLibrary import com.esri.zrh.jenkins.JenkinsTools import com.esri.zrh.jenkins.ce.CityEnginePipelineLibrary import com.esri.zrh.jenkins.ce.PrtAppPipelineLibrary +import com.esri.zrh.jenkins.PslFactory +import com.esri.zrh.jenkins.psl.UploadTrackingPsl @Field def psl = PslFactory.create(this, UploadTrackingPsl.ID) @Field def cepl = new CityEnginePipelineLibrary(this, psl) From be3e7bcd7376689cf77c02a731691b8dbd8182bf Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 14 Jun 2020 19:33:47 +0200 Subject: [PATCH 04/54] conan: updated required CE SDK (PRT) version to 2.2.6332 CityEngine 2020.0 --- src/conanfile-h17.py | 2 +- src/conanfile-h175.py | 2 +- src/conanfile-h180.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conanfile-h17.py b/src/conanfile-h17.py index d0359ef2..d40e73fd 100644 --- a/src/conanfile-h17.py +++ b/src/conanfile-h17.py @@ -18,5 +18,5 @@ def requirements(self): if "PLD_CONAN_CESDK_VERSION" in os.environ: cesdk_version = os.environ["PLD_CONAN_CESDK_VERSION"] else: - cesdk_version = "2.1.5704" + cesdk_version = "2.2.6332" self.requires("cesdk/{}@esri-rd-zurich/stable".format(cesdk_version)) diff --git a/src/conanfile-h175.py b/src/conanfile-h175.py index 058bfa43..ccd852a3 100644 --- a/src/conanfile-h175.py +++ b/src/conanfile-h175.py @@ -18,5 +18,5 @@ def requirements(self): if "PLD_CONAN_CESDK_VERSION" in os.environ: cesdk_version = os.environ["PLD_CONAN_CESDK_VERSION"] else: - cesdk_version = "2.1.5704" + cesdk_version = "2.2.6332" self.requires("cesdk/{}@esri-rd-zurich/stable".format(cesdk_version)) diff --git a/src/conanfile-h180.py b/src/conanfile-h180.py index 8413038a..a7887f7c 100644 --- a/src/conanfile-h180.py +++ b/src/conanfile-h180.py @@ -18,5 +18,5 @@ def requirements(self): if "PLD_CONAN_CESDK_VERSION" in os.environ: cesdk_version = os.environ["PLD_CONAN_CESDK_VERSION"] else: - cesdk_version = "2.1.5704" + cesdk_version = "2.2.6332" self.requires("cesdk/{}@esri-rd-zurich/stable".format(cesdk_version)) From c20a400f8cefec66c6741e81182891cbe9a57b50 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 10:17:56 +0200 Subject: [PATCH 05/54] compile fix: avoid clash of LT macro with Houdini headers --- src/palladio/LogHandler.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/palladio/LogHandler.h b/src/palladio/LogHandler.h index 3ba47cfd..3890dcb7 100644 --- a/src/palladio/LogHandler.h +++ b/src/palladio/LogHandler.h @@ -97,17 +97,17 @@ class LogHandler : public prt::LogHandler { using LogHandlerPtr = std::unique_ptr; -} // namespace log - +// switch logger here between PRTLogger and StreamLogger +template +using LT = PRTLogger; -// switch logger here -#define LT logging::PRTLogger +} // namespace log -using _LOG_DBG = LT; -using _LOG_INF = LT; -using _LOG_WRN = LT; -using _LOG_ERR = LT; -using _LOG_FTL = LT; +using _LOG_DBG = logging::LT; +using _LOG_INF = logging::LT; +using _LOG_WRN = logging::LT; +using _LOG_ERR = logging::LT; +using _LOG_FTL = logging::LT; // convenience shortcuts in global namespace #define LOG_DBG _LOG_DBG() << __FUNCTION__ << ": " From 55e07a2af177c7a69fe291e696fa2b3a51b1ffff Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 10:34:59 +0200 Subject: [PATCH 06/54] compile fix: adapt to PRT 2.2 API changes --- src/palladio/AttrEvalCallbacks.h | 6 +++++- src/palladio/ModelConverter.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/palladio/AttrEvalCallbacks.h b/src/palladio/AttrEvalCallbacks.h index 7851b7ab..8daf71ae 100644 --- a/src/palladio/AttrEvalCallbacks.h +++ b/src/palladio/AttrEvalCallbacks.h @@ -39,7 +39,11 @@ class AttrEvalCallbacks: public prt::Callbacks { prt::Status attrFloat(size_t isIndex, int32_t shapeID, const wchar_t* key, double value) override; prt::Status attrString(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* value) override; -#if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) +#if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 1) + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } +#elif (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size) override { return prt::STATUS_OK; } prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size) override { return prt::STATUS_OK; } prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size) override { return prt::STATUS_OK; } diff --git a/src/palladio/ModelConverter.h b/src/palladio/ModelConverter.h index cd6f7973..de2a2704 100644 --- a/src/palladio/ModelConverter.h +++ b/src/palladio/ModelConverter.h @@ -96,7 +96,11 @@ class ModelConverter : public HoudiniCallbacks { prt::Status attrFloat(size_t isIndex, int32_t shapeID, const wchar_t* key, double value) override; prt::Status attrString(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* value) override; -#if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) +#if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 1) + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } +#elif (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size) override { return prt::STATUS_OK; } prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size) override { return prt::STATUS_OK; } prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size) override { return prt::STATUS_OK; } From 64d3fc9a61fdd241244973475c9daa23f46af2f6 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 09:51:28 +0200 Subject: [PATCH 07/54] clang-format: adopting definitions from Serlio. --- .clang-format | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..ecfdb130 --- /dev/null +++ b/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM + +AccessModifierOffset: -4 +AllowShortFunctionsOnASingleLine: Empty +AlwaysBreakTemplateDeclarations: Yes +BraceWrapping: + BeforeCatch: true + BeforeElse: true +BreakBeforeBraces: Custom +ColumnLimit: 120 +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: AfterHash +IndentWidth: 4 +PointerAlignment: Left +TabWidth: 4 +UseTab: ForIndentation From 37348acd219367293c39d48682a937d4c55e021c Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 10:17:09 +0200 Subject: [PATCH 08/54] clang-format: prevent messing with our boost include redirection --- src/palladio/AttributeConversion.cpp | 2 ++ src/palladio/AttributeConversion.h | 2 ++ src/palladio/BoostRedirect.h | 2 ++ src/palladio/LRUCache.h | 2 ++ src/palladio/ModelConverter.cpp | 2 ++ src/palladio/NodeParameter.h | 3 ++- src/palladio/PRTContext.h | 2 ++ src/palladio/PrimitivePartition.h | 2 ++ src/palladio/ResolveMapCache.h | 2 ++ src/palladio/SOPAssign.cpp | 3 ++- src/palladio/ShapeConverter.cpp | 3 ++- src/palladio/ShapeConverter.h | 2 ++ src/palladio/Utils.cpp | 2 ++ src/test/TestCallbacks.h | 2 ++ src/test/TestUtils.h | 2 ++ src/test/tests.cpp | 2 ++ 16 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index b88082a2..5699e2ad 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -19,8 +19,10 @@ #include "LogHandler.h" #include "MultiWatch.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/algorithm/string.hpp) +// clang-format on #include #include diff --git a/src/palladio/AttributeConversion.h b/src/palladio/AttributeConversion.h index 42b70641..d4a0bcb4 100644 --- a/src/palladio/AttributeConversion.h +++ b/src/palladio/AttributeConversion.h @@ -21,8 +21,10 @@ #include "GU/GU_Detail.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/variant.hpp) +// clang-format on #include diff --git a/src/palladio/BoostRedirect.h b/src/palladio/BoostRedirect.h index 11d32b0b..c671e919 100644 --- a/src/palladio/BoostRedirect.h +++ b/src/palladio/BoostRedirect.h @@ -16,7 +16,9 @@ #pragma once +// clang-format off #define PLD_STRINGIFY(x) PLD_STR(x) #define PLD_STR(x) #x #define PLD_EXPAND(x) x #define PLD_BOOST_INCLUDE(p) PLD_STRINGIFY(PLD_EXPAND(PLD_BOOST_NS)PLD_EXPAND(p)) +// clang-format on \ No newline at end of file diff --git a/src/palladio/LRUCache.h b/src/palladio/LRUCache.h index 2c7cf809..f2db5f44 100644 --- a/src/palladio/LRUCache.h +++ b/src/palladio/LRUCache.h @@ -1,7 +1,9 @@ # pragma once +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/optional.hpp) +// clang-format on #include #include diff --git a/src/palladio/ModelConverter.cpp b/src/palladio/ModelConverter.cpp index c9dd3f9a..463beca9 100644 --- a/src/palladio/ModelConverter.cpp +++ b/src/palladio/ModelConverter.cpp @@ -22,8 +22,10 @@ #include "GU/GU_HoleInfo.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/variant.hpp) +// clang-format on #include diff --git a/src/palladio/NodeParameter.h b/src/palladio/NodeParameter.h index 5ebe08ea..826047e7 100644 --- a/src/palladio/NodeParameter.h +++ b/src/palladio/NodeParameter.h @@ -28,9 +28,10 @@ #include "GA/GA_Types.h" #include "OP/OP_Node.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/filesystem/path.hpp) - +// clang-format on namespace AssignNodeParams { diff --git a/src/palladio/PRTContext.h b/src/palladio/PRTContext.h index 0698711a..c7af5054 100644 --- a/src/palladio/PRTContext.h +++ b/src/palladio/PRTContext.h @@ -22,8 +22,10 @@ #include "prt/Object.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/filesystem.hpp) +// clang-format on #include diff --git a/src/palladio/PrimitivePartition.h b/src/palladio/PrimitivePartition.h index 2e9ddb0f..c68add95 100644 --- a/src/palladio/PrimitivePartition.h +++ b/src/palladio/PrimitivePartition.h @@ -22,8 +22,10 @@ #include "GA/GA_Primitive.h" #include "GU/GU_Detail.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/variant.hpp) +// clang-format on #include #include diff --git a/src/palladio/ResolveMapCache.h b/src/palladio/ResolveMapCache.h index 773b08ea..f7a1edcc 100644 --- a/src/palladio/ResolveMapCache.h +++ b/src/palladio/ResolveMapCache.h @@ -18,8 +18,10 @@ #include "Utils.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/filesystem.hpp) +// clang-format on #include #include diff --git a/src/palladio/SOPAssign.cpp b/src/palladio/SOPAssign.cpp index 7c4ddaa9..c7bb3bec 100644 --- a/src/palladio/SOPAssign.cpp +++ b/src/palladio/SOPAssign.cpp @@ -28,9 +28,10 @@ #include "UT/UT_Interrupt.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/algorithm/string.hpp) - +// clang-format on namespace { diff --git a/src/palladio/ShapeConverter.cpp b/src/palladio/ShapeConverter.cpp index 9f05e522..9b1c8806 100644 --- a/src/palladio/ShapeConverter.cpp +++ b/src/palladio/ShapeConverter.cpp @@ -26,11 +26,12 @@ #include "GEO/GEO_PrimPolySoup.h" #include "UT/UT_String.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/variant.hpp) #include PLD_BOOST_INCLUDE(/algorithm/string.hpp) #include PLD_BOOST_INCLUDE(/functional/hash.hpp) - +// clang-format on namespace { diff --git a/src/palladio/ShapeConverter.h b/src/palladio/ShapeConverter.h index f68fe433..c633d362 100644 --- a/src/palladio/ShapeConverter.h +++ b/src/palladio/ShapeConverter.h @@ -21,8 +21,10 @@ #include "UT/UT_String.h" +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/filesystem/path.hpp) +// clang-format on #include diff --git a/src/palladio/Utils.cpp b/src/palladio/Utils.cpp index e8823500..e51206e0 100644 --- a/src/palladio/Utils.cpp +++ b/src/palladio/Utils.cpp @@ -24,9 +24,11 @@ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-local-typedefs" #endif +// clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/algorithm/string.hpp) #include PLD_BOOST_INCLUDE(/filesystem.hpp) +// clang-format on #ifndef _WIN32 # pragma GCC diagnostic pop #endif diff --git a/src/test/TestCallbacks.h b/src/test/TestCallbacks.h index 1815b411..458034d0 100644 --- a/src/test/TestCallbacks.h +++ b/src/test/TestCallbacks.h @@ -22,8 +22,10 @@ #include "prt/API.h" #include "prt/AttributeMap.h" +// clang-format off #include "../palladio/BoostRedirect.h" #include PLD_BOOST_INCLUDE(/variant.hpp) +// clang-format on #include #include diff --git a/src/test/TestUtils.h b/src/test/TestUtils.h index 07c8ef41..ad56ed29 100644 --- a/src/test/TestUtils.h +++ b/src/test/TestUtils.h @@ -21,8 +21,10 @@ #include "../palladio/PRTContext.h" #include "../palladio/Utils.h" +// clang-format off #include "../palladio/BoostRedirect.h" #include PLD_BOOST_INCLUDE(/filesystem.hpp) +// clang-format on #include #include diff --git a/src/test/tests.cpp b/src/test/tests.cpp index aa6e950c..54017d7e 100644 --- a/src/test/tests.cpp +++ b/src/test/tests.cpp @@ -27,8 +27,10 @@ #include "prtx/Geometry.h" #include "prtx/Mesh.h" +// clang-format off #include "../palladio/BoostRedirect.h" #include PLD_BOOST_INCLUDE(/filesystem/path.hpp) +// clang-format on #define CATCH_CONFIG_RUNNER #include "catch.hpp" From fcc74eaa7199b0bccb29805489746727d6b0aa9d Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 10:39:32 +0200 Subject: [PATCH 09/54] clang-format: run --- src/codec/CodecMain.cpp | 14 +- src/codec/CodecMain.h | 2 +- src/codec/encoder/HoudiniCallbacks.h | 31 +- src/codec/encoder/HoudiniEncoder.cpp | 426 ++++++++++++++------------- src/codec/encoder/HoudiniEncoder.h | 37 ++- src/palladio/AttrEvalCallbacks.cpp | 22 +- src/palladio/AttrEvalCallbacks.h | 42 ++- src/palladio/AttributeConversion.cpp | 166 ++++++----- src/palladio/AttributeConversion.h | 30 +- src/palladio/LRUCache.h | 224 +++++++------- src/palladio/LogHandler.h | 78 +++-- src/palladio/ModelConverter.cpp | 119 ++++---- src/palladio/ModelConverter.h | 88 +++--- src/palladio/MultiWatch.cpp | 21 +- src/palladio/MultiWatch.h | 13 +- src/palladio/NodeParameter.cpp | 45 ++- src/palladio/NodeParameter.h | 85 +++--- src/palladio/PRTContext.cpp | 91 +++--- src/palladio/PRTContext.h | 19 +- src/palladio/PalladioMain.cpp | 20 +- src/palladio/PalladioMain.h | 4 +- src/palladio/PrimitiveClassifier.cpp | 4 +- src/palladio/PrimitiveClassifier.h | 7 +- src/palladio/PrimitivePartition.cpp | 30 +- src/palladio/PrimitivePartition.h | 7 +- src/palladio/ResolveMapCache.cpp | 34 ++- src/palladio/ResolveMapCache.h | 3 +- src/palladio/SOPAssign.cpp | 55 ++-- src/palladio/SOPAssign.h | 13 +- src/palladio/SOPGenerate.cpp | 75 +++-- src/palladio/SOPGenerate.h | 19 +- src/palladio/ShapeConverter.cpp | 89 +++--- src/palladio/ShapeConverter.h | 20 +- src/palladio/ShapeData.cpp | 36 +-- src/palladio/ShapeData.h | 49 +-- src/palladio/ShapeGenerator.cpp | 46 ++- src/palladio/ShapeGenerator.h | 4 +- src/palladio/Utils.cpp | 44 +-- src/palladio/Utils.h | 57 ++-- src/test/TestCallbacks.h | 51 ++-- src/test/TestUtils.cpp | 49 +-- src/test/TestUtils.h | 19 +- src/test/tests.cpp | 305 ++++++++++--------- 43 files changed, 1298 insertions(+), 1295 deletions(-) diff --git a/src/codec/CodecMain.cpp b/src/codec/CodecMain.cpp index 578efaf1..63c877c3 100644 --- a/src/codec/CodecMain.cpp +++ b/src/codec/CodecMain.cpp @@ -18,35 +18,27 @@ #include "encoder/HoudiniEncoder.h" -#include "prtx/prtx.h" #include "prtx/ExtensionManager.h" - +#include "prtx/prtx.h" namespace { const int VERSION_MAJOR = PRT_VERSION_MAJOR; const int VERSION_MINOR = PRT_VERSION_MINOR; -} +} // namespace extern "C" { - CODEC_EXPORTS_API void registerExtensionFactories(prtx::ExtensionManager* manager) { manager->addFactory(HoudiniEncoderFactory::createInstance()); } - -CODEC_EXPORTS_API void unregisterExtensionFactories(prtx::ExtensionManager* /*manager*/) { -} - +CODEC_EXPORTS_API void unregisterExtensionFactories(prtx::ExtensionManager* /*manager*/) {} CODEC_EXPORTS_API int getVersionMajor() { return VERSION_MAJOR; } - CODEC_EXPORTS_API int getVersionMinor() { return VERSION_MINOR; } - - } diff --git a/src/codec/CodecMain.h b/src/codec/CodecMain.h index 0bbeeac0..d8057614 100644 --- a/src/codec/CodecMain.h +++ b/src/codec/CodecMain.h @@ -19,5 +19,5 @@ #ifdef _WIN32 # define CODEC_EXPORTS_API __declspec(dllexport) #else -# define CODEC_EXPORTS_API __attribute__ ((visibility ("default"))) +# define CODEC_EXPORTS_API __attribute__((visibility("default"))) #endif diff --git a/src/codec/encoder/HoudiniCallbacks.h b/src/codec/encoder/HoudiniCallbacks.h index 7c406870..66566e83 100644 --- a/src/codec/encoder/HoudiniCallbacks.h +++ b/src/codec/encoder/HoudiniCallbacks.h @@ -20,13 +20,11 @@ constexpr const wchar_t* ENCODER_ID_HOUDINI = L"HoudiniEncoder"; constexpr const wchar_t* EO_EMIT_ATTRIBUTES = L"emitAttributes"; -constexpr const wchar_t* EO_EMIT_MATERIALS = L"emitMaterials"; -constexpr const wchar_t* EO_EMIT_REPORTS = L"emitReports"; - +constexpr const wchar_t* EO_EMIT_MATERIALS = L"emitMaterials"; +constexpr const wchar_t* EO_EMIT_REPORTS = L"emitReports"; class HoudiniCallbacks : public prt::Callbacks { public: - virtual ~HoudiniCallbacks() override = default; /** @@ -47,25 +45,18 @@ class HoudiniCallbacks : public prt::Callbacks { * @param uvIndicesSizes number of uv indices per face per uv set * @param uvSets number of uv sets * @param faceRanges ranges for materials and reports - * @param materials contains faceRangesSize-1 attribute maps (all materials must have an identical set of keys and types) + * @param materials contains faceRangesSize-1 attribute maps (all materials must have an identical set of keys and + * types) * @param reports contains faceRangesSize-1 attribute maps * @param shapeIDs shape ids per face, contains faceRangesSize-1 values */ - virtual void add( - const wchar_t* name, - const double* vtx, size_t vtxSize, - const double* nrm, size_t nrmSize, - const uint32_t* counts, size_t countsSize, - const uint32_t* indices, size_t indicesSize, + virtual void add(const wchar_t* name, const double* vtx, size_t vtxSize, const double* nrm, size_t nrmSize, + const uint32_t* counts, size_t countsSize, const uint32_t* indices, size_t indicesSize, - double const* const* uvs, size_t const* uvsSizes, - uint32_t const* const* uvCounts, size_t const* uvCountsSizes, - uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, - uint32_t uvSets, + double const* const* uvs, size_t const* uvsSizes, uint32_t const* const* uvCounts, + size_t const* uvCountsSizes, uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, + uint32_t uvSets, - const uint32_t* faceRanges, size_t faceRangesSize, - const prt::AttributeMap** materials, - const prt::AttributeMap** reports, - const int32_t* shapeIDs - ) = 0; + const uint32_t* faceRanges, size_t faceRangesSize, const prt::AttributeMap** materials, + const prt::AttributeMap** reports, const int32_t* shapeIDs) = 0; }; diff --git a/src/codec/encoder/HoudiniEncoder.cpp b/src/codec/encoder/HoudiniEncoder.cpp index 25273fcb..bce2bbfc 100644 --- a/src/codec/encoder/HoudiniEncoder.cpp +++ b/src/codec/encoder/HoudiniEncoder.cpp @@ -17,48 +17,48 @@ #include "HoudiniEncoder.h" #include "HoudiniCallbacks.h" +#include "prtx/Attributable.h" #include "prtx/Exception.h" -#include "prtx/Log.h" +#include "prtx/ExtensionManager.h" +#include "prtx/GenerateContext.h" #include "prtx/Geometry.h" -#include "prtx/Mesh.h" +#include "prtx/Log.h" #include "prtx/Material.h" +#include "prtx/Mesh.h" +#include "prtx/ReportsCollector.h" #include "prtx/Shape.h" #include "prtx/ShapeIterator.h" -#include "prtx/ExtensionManager.h" -#include "prtx/GenerateContext.h" -#include "prtx/Attributable.h" #include "prtx/URI.h" -#include "prtx/ReportsCollector.h" #include "prt/prt.h" +#include #include -#include -#include -#include #include -#include -#include #include - +#include +#include +#include +#include namespace { -constexpr bool DBG = false; +constexpr bool DBG = false; -constexpr const wchar_t* ENC_NAME = L"SideFX(tm) Houdini(tm) Encoder"; -constexpr const wchar_t* ENC_DESCRIPTION = L"Encodes geometry into the Houdini format."; +constexpr const wchar_t* ENC_NAME = L"SideFX(tm) Houdini(tm) Encoder"; +constexpr const wchar_t* ENC_DESCRIPTION = L"Encodes geometry into the Houdini format."; -const prtx::EncodePreparator::PreparationFlags PREP_FLAGS = prtx::EncodePreparator::PreparationFlags() - .instancing(false) - .mergeByMaterial(false) - .triangulate(false) - .processHoles(prtx::HoleProcessor::TRIANGULATE_FACES_WITH_HOLES) - .mergeVertices(true) - .cleanupVertexNormals(true) - .cleanupUVs(true) - .processVertexNormals(prtx::VertexNormalProcessor::SET_MISSING_TO_FACE_NORMALS) - .indexSharing(prtx::EncodePreparator::PreparationFlags::INDICES_SAME_FOR_ALL_VERTEX_ATTRIBUTES); +const prtx::EncodePreparator::PreparationFlags PREP_FLAGS = + prtx::EncodePreparator::PreparationFlags() + .instancing(false) + .mergeByMaterial(false) + .triangulate(false) + .processHoles(prtx::HoleProcessor::TRIANGULATE_FACES_WITH_HOLES) + .mergeVertices(true) + .cleanupVertexNormals(true) + .cleanupUVs(true) + .processVertexNormals(prtx::VertexNormalProcessor::SET_MISSING_TO_FACE_NORMALS) + .indexSharing(prtx::EncodePreparator::PreparationFlags::INDICES_SAME_FOR_ALL_VERTEX_ATTRIBUTES); std::vector toPtrVec(const prtx::WStringVector& wsv) { std::vector pw(wsv.size()); @@ -67,7 +67,7 @@ std::vector toPtrVec(const prtx::WStringVector& wsv) { return pw; } -template +template std::pair, std::vector> toPtrVec(const std::vector>& v) { std::vector pv(v.size()); std::vector ps(v.size()); @@ -78,107 +78,106 @@ std::pair, std::vector> toPtrVec(const std::vector return std::make_pair(pv, ps); } -std::wstring uriToPath(const prtx::TexturePtr& t){ +std::wstring uriToPath(const prtx::TexturePtr& t) { return t->getURI()->getPath(); } // we blacklist all CGA-style material attribute keys, see prtx/Material.h const std::set MATERIAL_ATTRIBUTE_BLACKLIST = { - L"ambient.b", - L"ambient.g", - L"ambient.r", - L"bumpmap.rw", - L"bumpmap.su", - L"bumpmap.sv", - L"bumpmap.tu", - L"bumpmap.tv", - L"color.a", - L"color.b", - L"color.g", - L"color.r", - L"color.rgb", - L"colormap.rw", - L"colormap.su", - L"colormap.sv", - L"colormap.tu", - L"colormap.tv", - L"dirtmap.rw", - L"dirtmap.su", - L"dirtmap.sv", - L"dirtmap.tu", - L"dirtmap.tv", - L"normalmap.rw", - L"normalmap.su", - L"normalmap.sv", - L"normalmap.tu", - L"normalmap.tv", - L"opacitymap.rw", - L"opacitymap.su", - L"opacitymap.sv", - L"opacitymap.tu", - L"opacitymap.tv", - L"specular.b", - L"specular.g", - L"specular.r", - L"specularmap.rw", - L"specularmap.su", - L"specularmap.sv", - L"specularmap.tu", - L"specularmap.tv", - L"bumpmap", - L"colormap", - L"dirtmap", - L"normalmap", - L"opacitymap", - L"specularmap" + L"ambient.b", + L"ambient.g", + L"ambient.r", + L"bumpmap.rw", + L"bumpmap.su", + L"bumpmap.sv", + L"bumpmap.tu", + L"bumpmap.tv", + L"color.a", + L"color.b", + L"color.g", + L"color.r", + L"color.rgb", + L"colormap.rw", + L"colormap.su", + L"colormap.sv", + L"colormap.tu", + L"colormap.tv", + L"dirtmap.rw", + L"dirtmap.su", + L"dirtmap.sv", + L"dirtmap.tu", + L"dirtmap.tv", + L"normalmap.rw", + L"normalmap.su", + L"normalmap.sv", + L"normalmap.tu", + L"normalmap.tv", + L"opacitymap.rw", + L"opacitymap.su", + L"opacitymap.sv", + L"opacitymap.tu", + L"opacitymap.tv", + L"specular.b", + L"specular.g", + L"specular.r", + L"specularmap.rw", + L"specularmap.su", + L"specularmap.sv", + L"specularmap.tu", + L"specularmap.tv", + L"bumpmap", + L"colormap", + L"dirtmap", + L"normalmap", + L"opacitymap", + L"specularmap" #if PRT_VERSION_MAJOR > 1 - // also blacklist CGA-style PBR attrs from CE 2019.0, PRT 2.x - , - L"opacitymap.mode", - L"emissive.b", - L"emissive.g", - L"emissive.r", - L"emissivemap.rw", - L"emissivemap.su", - L"emissivemap.sv", - L"emissivemap.tu", - L"emissivemap.tv", - L"metallicmap.rw", - L"metallicmap.su", - L"metallicmap.sv", - L"metallicmap.tu", - L"metallicmap.tv", - L"occlusionmap.rw", - L"occlusionmap.su", - L"occlusionmap.sv", - L"occlusionmap.tu", - L"occlusionmap.tv", - L"roughnessmap.rw", - L"roughnessmap.su", - L"roughnessmap.sv", - L"roughnessmap.tu", - L"roughnessmap.tv", - L"emissivemap", - L"metallicmap", - L"occlusionmap", - L"roughnessmap" + // also blacklist CGA-style PBR attrs from CE 2019.0, PRT 2.x + , + L"opacitymap.mode", + L"emissive.b", + L"emissive.g", + L"emissive.r", + L"emissivemap.rw", + L"emissivemap.su", + L"emissivemap.sv", + L"emissivemap.tu", + L"emissivemap.tv", + L"metallicmap.rw", + L"metallicmap.su", + L"metallicmap.sv", + L"metallicmap.tu", + L"metallicmap.tv", + L"occlusionmap.rw", + L"occlusionmap.su", + L"occlusionmap.sv", + L"occlusionmap.tu", + L"occlusionmap.tv", + L"roughnessmap.rw", + L"roughnessmap.su", + L"roughnessmap.sv", + L"roughnessmap.tu", + L"roughnessmap.tv", + L"emissivemap", + L"metallicmap", + L"occlusionmap", + L"roughnessmap" #endif }; -void convertMaterialToAttributeMap( - prtx::PRTUtils::AttributeMapBuilderPtr& aBuilder, - const prtx::Material& prtxAttr, - const prtx::WStringVector& keys -) { - if (DBG) log_debug(L"-- converting material: %1%") % prtxAttr.name(); - for(const auto& key : keys) { +void convertMaterialToAttributeMap(prtx::PRTUtils::AttributeMapBuilderPtr& aBuilder, const prtx::Material& prtxAttr, + const prtx::WStringVector& keys) { + if (DBG) + log_debug(L"-- converting material: %1%") % prtxAttr.name(); + for (const auto& key : keys) { if (MATERIAL_ATTRIBUTE_BLACKLIST.count(key) > 0) continue; - if (DBG) log_debug(L" key: %1%") % key; + if (DBG) + log_debug(L" key: %1%") % key; - switch(prtxAttr.getType(key)) { + switch (prtxAttr.getType(key)) { case prt::Attributable::PT_BOOL: aBuilder->setBool(key.c_str(), prtxAttr.getBool(key) == prtx::PRTX_TRUE); break; @@ -193,7 +192,7 @@ void convertMaterialToAttributeMap( case prt::Attributable::PT_STRING: { const std::wstring& v = prtxAttr.getString(key); // explicit copy - aBuilder->setString(key.c_str(), v.c_str()); // also passing on empty strings + aBuilder->setString(key.c_str(), v.c_str()); // also passing on empty strings break; } @@ -244,7 +243,8 @@ void convertMaterialToAttributeMap( } default: - if (DBG) log_debug(L"ignored atttribute '%s' with type %d") % key % prtxAttr.getType(key); + if (DBG) + log_debug(L"ignored atttribute '%s' with type %d") % key % prtxAttr.getType(key); break; } } @@ -254,15 +254,15 @@ void convertReportsToAttributeMap(prtx::PRTUtils::AttributeMapBuilderPtr& amb, c if (!r) return; - for (const auto& b: r->mBools) + for (const auto& b : r->mBools) amb->setBool(b.first->c_str(), b.second); - for (const auto& f: r->mFloats) + for (const auto& f : r->mFloats) amb->setFloat(f.first->c_str(), f.second); - for (const auto& s: r->mStrings) + for (const auto& s : r->mStrings) amb->setString(s.first->c_str(), s.second->c_str()); } -template +template void forEachKey(prt::Attributable const* a, F f) { if (a == nullptr) return; @@ -276,28 +276,30 @@ void forEachKey(prt::Attributable const* a, F f) { } } -void forwardGenericAttributes(HoudiniCallbacks* hc, size_t initialShapeIndex, const prtx::InitialShape& initialShape, const prtx::ShapePtr& shape) { - forEachKey(initialShape.getAttributeMap(), [&hc,&shape,&initialShapeIndex,&initialShape](prt::Attributable const* a, wchar_t const* key) { - switch (shape->getType(key)) { - case prtx::Attributable::PT_STRING: { - const auto v = shape->getString(key); - hc->attrString(initialShapeIndex, shape->getID(), key, v.c_str()); - break; - } - case prtx::Attributable::PT_FLOAT: { - const auto v = shape->getFloat(key); - hc->attrFloat(initialShapeIndex, shape->getID(), key, v); - break; - } - case prtx::Attributable::PT_BOOL: { - const auto v = shape->getBool(key); - hc->attrBool(initialShapeIndex, shape->getID(), key, (v == prtx::PRTX_TRUE)); - break; - } - default: - break; - } - }); +void forwardGenericAttributes(HoudiniCallbacks* hc, size_t initialShapeIndex, const prtx::InitialShape& initialShape, + const prtx::ShapePtr& shape) { + forEachKey(initialShape.getAttributeMap(), + [&hc, &shape, &initialShapeIndex, &initialShape](prt::Attributable const* a, wchar_t const* key) { + switch (shape->getType(key)) { + case prtx::Attributable::PT_STRING: { + const auto v = shape->getString(key); + hc->attrString(initialShapeIndex, shape->getID(), key, v.c_str()); + break; + } + case prtx::Attributable::PT_FLOAT: { + const auto v = shape->getFloat(key); + hc->attrFloat(initialShapeIndex, shape->getID(), key, v); + break; + } + case prtx::Attributable::PT_BOOL: { + const auto v = shape->getBool(key); + hc->attrBool(initialShapeIndex, shape->getID(), key, (v == prtx::PRTX_TRUE)); + break; + } + default: + break; + } + }); } using AttributeMapNOPtrVector = std::vector; @@ -305,43 +307,46 @@ using AttributeMapNOPtrVector = std::vector; struct AttributeMapNOPtrVectorOwner { AttributeMapNOPtrVector v; ~AttributeMapNOPtrVectorOwner() { - for (const auto& m: v) { - if (m) m->destroy(); + for (const auto& m : v) { + if (m) + m->destroy(); } } }; struct TextureUVMapping { std::wstring key; - uint8_t index; - int8_t uvSet; + uint8_t index; + int8_t uvSet; }; const std::vector TEXTURE_UV_MAPPINGS = []() -> std::vector { return { // shader key | idx | uv set | CGA key - { L"diffuseMap", 0, 0 }, // colormap - { L"bumpMap", 0, 1 }, // bumpmap - { L"diffuseMap", 1, 2 }, // dirtmap - { L"specularMap", 0, 3 }, // specularmap - { L"opacityMap", 0, 4 }, // opacitymap - { L"normalMap", 0, 5 } // normalmap + {L"diffuseMap", 0, 0}, // colormap + {L"bumpMap", 0, 1}, // bumpmap + {L"diffuseMap", 1, 2}, // dirtmap + {L"specularMap", 0, 3}, // specularmap + {L"opacityMap", 0, 4}, // opacitymap + { + L"normalMap", 0, 5 + } // normalmap #if PRT_VERSION_MAJOR > 1 - , - { L"emissiveMap", 0, 6 }, // emissivemap - { L"occlusionMap", 0, 7 }, // occlusionmap - { L"roughnessMap", 0, 8 }, // roughnessmap - { L"metallicMap", 0, 9 } // metallicmap + , {L"emissiveMap", 0, 6}, // emissivemap + {L"occlusionMap", 0, 7}, // occlusionmap + {L"roughnessMap", 0, 8}, // roughnessmap + { + L"metallicMap", 0, 9 + } // metallicmap #endif - }; }(); // return the highest required uv set (where a valid texture is present) uint32_t scanValidTextures(const prtx::MaterialPtr& mat) { int8_t highestUVSet = -1; - for (const auto& t: TEXTURE_UV_MAPPINGS) { + for (const auto& t : TEXTURE_UV_MAPPINGS) { const auto& ta = mat->getTextureArray(t.key); if (ta.size() > t.index && ta[t.index]->isValid()) highestUVSet = std::max(highestUVSet, t.uvSet); @@ -349,7 +354,7 @@ uint32_t scanValidTextures(const prtx::MaterialPtr& mat) { if (highestUVSet < 0) return 0; else - return highestUVSet+1; + return highestUVSet + 1; } const prtx::DoubleVector EMPTY_UVS; @@ -357,10 +362,10 @@ const prtx::IndexVector EMPTY_IDX; } // namespace - namespace detail { -SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, const std::vector& materials) { +SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, + const std::vector& materials) { // PASS 1: scan uint32_t numCoords = 0; uint32_t numNormalCoords = 0; @@ -368,11 +373,11 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, uint32_t numIndices = 0; uint32_t maxNumUVSets = 0; auto matsIt = materials.cbegin(); - for (const auto& geo: geometries) { + for (const auto& geo : geometries) { const prtx::MeshPtrVector& meshes = geo->getMeshes(); const prtx::MaterialPtrVector& mats = *matsIt; auto matIt = mats.cbegin(); - for (const auto& mesh: meshes) { + for (const auto& mesh : meshes) { numCoords += mesh->getVertexCoords().size(); numNormalCoords += mesh->getVertexNormalsCoords().size(); @@ -392,9 +397,9 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, // PASS 2: copy uint32_t vertexIndexBase = 0; std::vector uvIndexBases(maxNumUVSets, 0u); - for (const auto& geo: geometries) { + for (const auto& geo : geometries) { const prtx::MeshPtrVector& meshes = geo->getMeshes(); - for (const auto& mesh: meshes) { + for (const auto& mesh : meshes) { // append points const prtx::DoubleVector& verts = mesh->getVertexCoords(); sg.coords.insert(sg.coords.end(), verts.begin(), verts.end()); @@ -408,8 +413,10 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, // - if mesh has less uv sets than maxNumUVSets, copy uv set 0 to the missing higher sets const uint32_t numUVSets = mesh->getUVSetsCount(); const prtx::DoubleVector& uvs0 = (numUVSets > 0) ? mesh->getUVCoords(0) : EMPTY_UVS; - const prtx::IndexVector faceUVCounts0 = (numUVSets > 0) ? mesh->getFaceUVCounts(0) : prtx::IndexVector(mesh->getFaceCount(), 0); - if (DBG) log_debug("-- mesh: numUVSets = %1%") % numUVSets; + const prtx::IndexVector faceUVCounts0 = + (numUVSets > 0) ? mesh->getFaceUVCounts(0) : prtx::IndexVector(mesh->getFaceCount(), 0); + if (DBG) + log_debug("-- mesh: numUVSets = %1%") % numUVSets; for (uint32_t uvSet = 0; uvSet < sg.uvs.size(); uvSet++) { // append texture coordinates @@ -419,20 +426,26 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, tgt.insert(tgt.end(), src.begin(), src.end()); // append uv face counts - const prtx::IndexVector& faceUVCounts = (uvSet < numUVSets && !uvs.empty()) ? mesh->getFaceUVCounts(uvSet) : faceUVCounts0; + const prtx::IndexVector& faceUVCounts = + (uvSet < numUVSets && !uvs.empty()) ? mesh->getFaceUVCounts(uvSet) : faceUVCounts0; assert(faceUVCounts.size() == mesh->getFaceCount()); auto& tgtCnts = sg.uvCounts[uvSet]; tgtCnts.insert(tgtCnts.end(), faceUVCounts.begin(), faceUVCounts.end()); - if (DBG) log_debug(" -- uvset %1%: face counts size = %2%") % uvSet % faceUVCounts.size(); + if (DBG) + log_debug(" -- uvset %1%: face counts size = %2%") % uvSet % faceUVCounts.size(); // append uv vertex indices for (uint32_t fi = 0, faceCount = faceUVCounts.size(); fi < faceCount; ++fi) { const uint32_t* faceUVIdx0 = (numUVSets > 0) ? mesh->getFaceUVIndices(fi, 0) : EMPTY_IDX.data(); - const uint32_t* faceUVIdx = (uvSet < numUVSets && !uvs.empty()) ? mesh->getFaceUVIndices(fi, uvSet) : faceUVIdx0; + const uint32_t* faceUVIdx = + (uvSet < numUVSets && !uvs.empty()) ? mesh->getFaceUVIndices(fi, uvSet) : faceUVIdx0; const uint32_t faceUVCnt = faceUVCounts[fi]; - if (DBG) log_debug(" fi %1%: faceUVCnt = %2%, faceVtxCnt = %3%") % fi % faceUVCnt % mesh->getFaceVertexCount(fi); + if (DBG) + log_debug(" fi %1%: faceUVCnt = %2%, faceVtxCnt = %3%") % fi % faceUVCnt % + mesh->getFaceVertexCount(fi); for (uint32_t vi = 0; vi < faceUVCnt; vi++) - sg.uvIndices[uvSet].push_back(uvIndexBases[uvSet] + faceUVIdx[faceUVCnt - vi - 1]); // reverse winding + sg.uvIndices[uvSet].push_back(uvIndexBases[uvSet] + + faceUVIdx[faceUVCnt - vi - 1]); // reverse winding } uvIndexBases[uvSet] += src.size() / 2u; @@ -449,24 +462,25 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, vertexIndexBase += (uint32_t)verts.size() / 3u; } // for all meshes - } // for all geometries + } // for all geometries return sg; } } // namespace detail - HoudiniEncoder::HoudiniEncoder(const std::wstring& id, const prt::AttributeMap* options, prt::Callbacks* callbacks) -: prtx::GeometryEncoder(id, options, callbacks) -{ } + : prtx::GeometryEncoder(id, options, callbacks) {} void HoudiniEncoder::init(prtx::GenerateContext&) { prt::Callbacks* cb = getCallbacks(); - if (DBG) log_debug("HoudiniEncoder::init: cb = %x") % (size_t)cb; + if (DBG) + log_debug("HoudiniEncoder::init: cb = %x") % (size_t)cb; auto* oh = dynamic_cast(cb); - if (DBG) log_debug(" oh = %x") % (size_t)oh; - if(oh == nullptr) throw prtx::StatusException(prt::STATUS_ILLEGAL_CALLBACK_OBJECT); + if (DBG) + log_debug(" oh = %x") % (size_t)oh; + if (oh == nullptr) + throw prtx::StatusException(prt::STATUS_ILLEGAL_CALLBACK_OBJECT); } void HoudiniEncoder::encode(prtx::GenerateContext& context, size_t initialShapeIndex) { @@ -475,14 +489,15 @@ void HoudiniEncoder::encode(prtx::GenerateContext& context, size_t initialShapeI const bool emitAttrs = getOptions()->getBool(EO_EMIT_ATTRIBUTES); - prtx::DefaultNamePreparator namePrep; - prtx::NamePreparator::NamespacePtr nsMesh = namePrep.newNamespace(); + prtx::DefaultNamePreparator namePrep; + prtx::NamePreparator::NamespacePtr nsMesh = namePrep.newNamespace(); prtx::NamePreparator::NamespacePtr nsMaterial = namePrep.newNamespace(); prtx::EncodePreparatorPtr encPrep = prtx::EncodePreparator::create(true, namePrep, nsMesh, nsMaterial); // generate geometry prtx::ReportsAccumulatorPtr reportsAccumulator{prtx::WriteFirstReportsAccumulator::create()}; - prtx::ReportingStrategyPtr reportsCollector{prtx::LeafShapeReportingStrategy::create(context, initialShapeIndex, reportsAccumulator)}; + prtx::ReportingStrategyPtr reportsCollector{ + prtx::LeafShapeReportingStrategy::create(context, initialShapeIndex, reportsAccumulator)}; prtx::LeafIteratorPtr li = prtx::LeafIterator::create(context, initialShapeIndex); for (prtx::ShapePtr shape = li->getNext(); shape; shape = li->getNext()) { prtx::ReportsPtr r = reportsCollector->getReports(shape->getID()); @@ -499,9 +514,7 @@ void HoudiniEncoder::encode(prtx::GenerateContext& context, size_t initialShapeI } void HoudiniEncoder::convertGeometry(const prtx::InitialShape& initialShape, - const prtx::EncodePreparator::InstanceVector& instances, - HoudiniCallbacks* cb) -{ + const prtx::EncodePreparator::InstanceVector& instances, HoudiniCallbacks* cb) { const bool emitMaterials = getOptions()->getBool(EO_EMIT_MATERIALS); const bool emitReports = getOptions()->getBool(EO_EMIT_REPORTS); @@ -515,7 +528,7 @@ void HoudiniEncoder::convertGeometry(const prtx::InitialShape& initialShape, reports.reserve(instances.size()); shapeIDs.reserve(instances.size()); - for (const auto& inst: instances) { + for (const auto& inst : instances) { geometries.push_back(inst.getGeometry()); materials.push_back(inst.getMaterials()); reports.push_back(inst.getReports()); @@ -539,7 +552,7 @@ void HoudiniEncoder::convertGeometry(const prtx::InitialShape& initialShape, auto matIt = materials.cbegin(); auto repIt = reports.cbegin(); prtx::PRTUtils::AttributeMapBuilderPtr amb(prt::AttributeMapBuilder::create()); - for (const auto& geo: geometries) { + for (const auto& geo : geometries) { const prtx::MeshPtrVector& meshes = geo->getMeshes(); for (size_t mi = 0; mi < meshes.size(); mi++) { @@ -556,7 +569,8 @@ void HoudiniEncoder::convertGeometry(const prtx::InitialShape& initialShape, if (emitReports) { convertReportsToAttributeMap(amb, *repIt); reportAttrMaps.v.push_back(amb->createAttributeMapAndReset()); - if (DBG) log_debug("report attr map: %1%") % prtx::PRTUtils::objectToXML(reportAttrMaps.v.back()); + if (DBG) + log_debug("report attr map: %1%") % prtx::PRTUtils::objectToXML(reportAttrMaps.v.back()); } faceCount += m->getFaceCount(); @@ -567,9 +581,9 @@ void HoudiniEncoder::convertGeometry(const prtx::InitialShape& initialShape, } faceRanges.push_back(faceCount); // close last range - assert(matAttrMaps.v.empty() || matAttrMaps.v.size() == faceRanges.size()-1); - assert(reportAttrMaps.v.empty() || reportAttrMaps.v.size() == faceRanges.size()-1); - assert(shapeIDs.size() == faceRanges.size()-1); + assert(matAttrMaps.v.empty() || matAttrMaps.v.size() == faceRanges.size() - 1); + assert(reportAttrMaps.v.empty() || reportAttrMaps.v.size() == faceRanges.size() - 1); + assert(shapeIDs.size() == faceRanges.size() - 1); assert(sg.uvs.size() == sg.uvCounts.size()); assert(sg.uvs.size() == sg.uvIndices.size()); @@ -581,28 +595,20 @@ void HoudiniEncoder::convertGeometry(const prtx::InitialShape& initialShape, assert(sg.uvs.size() == puvCounts.first.size()); assert(sg.uvs.size() == puvCounts.second.size()); - cb->add(initialShape.getName(), - sg.coords.data(), sg.coords.size(), - sg.normals.data(), sg.normals.size(), - sg.counts.data(), sg.counts.size(), - sg.indices.data(), sg.indices.size(), + cb->add(initialShape.getName(), sg.coords.data(), sg.coords.size(), sg.normals.data(), sg.normals.size(), + sg.counts.data(), sg.counts.size(), sg.indices.data(), sg.indices.size(), - puvs.first.data(), puvs.second.data(), - puvCounts.first.data(), puvCounts.second.data(), - puvIndices.first.data(), puvIndices.second.data(), - sg.uvs.size(), + puvs.first.data(), puvs.second.data(), puvCounts.first.data(), puvCounts.second.data(), + puvIndices.first.data(), puvIndices.second.data(), sg.uvs.size(), - faceRanges.data(), faceRanges.size(), - matAttrMaps.v.empty() ? nullptr : matAttrMaps.v.data(), - reportAttrMaps.v.empty() ? nullptr : reportAttrMaps.v.data(), - shapeIDs.data()); - - if (DBG) log_debug("HoudiniEncoder::convertGeometry: end"); -} + faceRanges.data(), faceRanges.size(), matAttrMaps.v.empty() ? nullptr : matAttrMaps.v.data(), + reportAttrMaps.v.empty() ? nullptr : reportAttrMaps.v.data(), shapeIDs.data()); -void HoudiniEncoder::finish(prtx::GenerateContext& /*context*/) { + if (DBG) + log_debug("HoudiniEncoder::convertGeometry: end"); } +void HoudiniEncoder::finish(prtx::GenerateContext& /*context*/) {} HoudiniEncoderFactory* HoudiniEncoderFactory::createInstance() { prtx::EncoderInfoBuilder encoderInfoBuilder; @@ -614,8 +620,8 @@ HoudiniEncoderFactory* HoudiniEncoderFactory::createInstance() { prtx::PRTUtils::AttributeMapBuilderPtr amb(prt::AttributeMapBuilder::create()); amb->setBool(EO_EMIT_ATTRIBUTES, prtx::PRTX_FALSE); - amb->setBool(EO_EMIT_MATERIALS, prtx::PRTX_FALSE); - amb->setBool(EO_EMIT_REPORTS, prtx::PRTX_FALSE); + amb->setBool(EO_EMIT_MATERIALS, prtx::PRTX_FALSE); + amb->setBool(EO_EMIT_REPORTS, prtx::PRTX_FALSE); encoderInfoBuilder.setDefaultOptions(amb->createAttributeMap()); return new HoudiniEncoderFactory(encoderInfoBuilder.create()); diff --git a/src/codec/encoder/HoudiniEncoder.h b/src/codec/encoder/HoudiniEncoder.h index 8b4c6e3f..768448b4 100644 --- a/src/codec/encoder/HoudiniEncoder.h +++ b/src/codec/encoder/HoudiniEncoder.h @@ -18,40 +18,39 @@ #include "../CodecMain.h" -#include "prtx/Mesh.h" -#include "prtx/ResolveMap.h" +#include "prtx/EncodePreparator.h" #include "prtx/Encoder.h" #include "prtx/EncoderFactory.h" #include "prtx/EncoderInfoBuilder.h" +#include "prtx/Mesh.h" #include "prtx/PRTUtils.h" +#include "prtx/ResolveMap.h" #include "prtx/Singleton.h" -#include "prtx/EncodePreparator.h" #include "prt/ContentType.h" #include "prt/InitialShape.h" -#include #include #include - +#include class HoudiniCallbacks; namespace detail { struct SerializedGeometry { - prtx::DoubleVector coords; - prtx::DoubleVector normals; // uses same indexing as coords - std::vector counts; - std::vector indices; + prtx::DoubleVector coords; + prtx::DoubleVector normals; // uses same indexing as coords + std::vector counts; + std::vector indices; std::vector uvs; - std::vector uvCounts; - std::vector uvIndices; + std::vector uvCounts; + std::vector uvIndices; - SerializedGeometry(uint32_t numCoords, uint32_t numNormalCoords, uint32_t numCounts, uint32_t numIndices, uint32_t uvSets) - : uvs(uvSets), uvCounts(uvSets), uvIndices(uvSets) - { + SerializedGeometry(uint32_t numCoords, uint32_t numNormalCoords, uint32_t numCounts, uint32_t numIndices, + uint32_t uvSets) + : uvs(uvSets), uvCounts(uvSets), uvIndices(uvSets) { coords.reserve(3 * numCoords); normals.reserve(3 * numNormalCoords); counts.reserve(numCounts); @@ -60,11 +59,11 @@ struct SerializedGeometry { }; // visible for tests -CODEC_EXPORTS_API SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector &geometries, const std::vector& materials); +CODEC_EXPORTS_API SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, + const std::vector& materials); } // namespace detail - class HoudiniEncoder : public prtx::GeometryEncoder { public: HoudiniEncoder(const std::wstring& id, const prt::AttributeMap* options, prt::Callbacks* callbacks); @@ -77,16 +76,14 @@ class HoudiniEncoder : public prtx::GeometryEncoder { private: void convertGeometry(const prtx::InitialShape& initialShape, - const prtx::EncodePreparator::InstanceVector& instances, - HoudiniCallbacks* callbacks); + const prtx::EncodePreparator::InstanceVector& instances, HoudiniCallbacks* callbacks); }; - class HoudiniEncoderFactory : public prtx::EncoderFactory, public prtx::Singleton { public: static HoudiniEncoderFactory* createInstance(); - explicit HoudiniEncoderFactory(const prt::EncoderInfo* info) : prtx::EncoderFactory(info) { } + explicit HoudiniEncoderFactory(const prt::EncoderInfo* info) : prtx::EncoderFactory(info) {} ~HoudiniEncoderFactory() override = default; HoudiniEncoder* create(const prt::AttributeMap* options, prt::Callbacks* callbacks) const override { diff --git a/src/palladio/AttrEvalCallbacks.cpp b/src/palladio/AttrEvalCallbacks.cpp index dab66c33..452992fe 100644 --- a/src/palladio/AttrEvalCallbacks.cpp +++ b/src/palladio/AttrEvalCallbacks.cpp @@ -17,10 +17,9 @@ #include "AttrEvalCallbacks.h" #include "LogHandler.h" - namespace { -constexpr bool DBG = false; +constexpr bool DBG = false; constexpr const wchar_t* CGA_ANNOTATION_HIDDEN = L"@Hidden"; bool isHiddenAttribute(const RuleFileInfoUPtr& ruleFileInfo, const wchar_t* key) { @@ -39,16 +38,17 @@ bool isHiddenAttribute(const RuleFileInfoUPtr& ruleFileInfo, const wchar_t* key) } // namespace - prt::Status AttrEvalCallbacks::generateError(size_t isIndex, prt::Status status, const wchar_t* message) { return prt::STATUS_OK; } -prt::Status AttrEvalCallbacks::assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, const wchar_t* message) { +prt::Status AttrEvalCallbacks::assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, + const wchar_t* uri, const wchar_t* message) { return prt::STATUS_OK; } -prt::Status AttrEvalCallbacks::cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, const wchar_t* message) { +prt::Status AttrEvalCallbacks::cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, + int32_t pc, const wchar_t* message) { LOG_ERR << message; return prt::STATUS_OK; } @@ -65,26 +65,30 @@ prt::Status AttrEvalCallbacks::cgaReportFloat(size_t isIndex, int32_t shapeID, c return prt::STATUS_OK; } -prt::Status AttrEvalCallbacks::cgaReportString(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* value) { +prt::Status AttrEvalCallbacks::cgaReportString(size_t isIndex, int32_t shapeID, const wchar_t* key, + const wchar_t* value) { return prt::STATUS_OK; } prt::Status AttrEvalCallbacks::attrBool(size_t isIndex, int32_t shapeID, const wchar_t* key, bool value) { - if (DBG) LOG_DBG << "attrBool: isIndex = " << isIndex << ", key = " << key << " = " << value; + if (DBG) + LOG_DBG << "attrBool: isIndex = " << isIndex << ", key = " << key << " = " << value; if (mRuleFileInfo[isIndex] && !isHiddenAttribute(mRuleFileInfo[isIndex], key)) mAMBS[isIndex]->setBool(key, value); return prt::STATUS_OK; } prt::Status AttrEvalCallbacks::attrFloat(size_t isIndex, int32_t shapeID, const wchar_t* key, double value) { - if (DBG) LOG_DBG << "attrFloat: isIndex = " << isIndex << ", key = " << key << " = " << value; + if (DBG) + LOG_DBG << "attrFloat: isIndex = " << isIndex << ", key = " << key << " = " << value; if (mRuleFileInfo[isIndex] && !isHiddenAttribute(mRuleFileInfo[isIndex], key)) mAMBS[isIndex]->setFloat(key, value); return prt::STATUS_OK; } prt::Status AttrEvalCallbacks::attrString(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* value) { - if (DBG) LOG_DBG << "attrString: isIndex = " << isIndex << ", key = " << key << " = " << value; + if (DBG) + LOG_DBG << "attrString: isIndex = " << isIndex << ", key = " << key << " = " << value; if (mRuleFileInfo[isIndex] && !isHiddenAttribute(mRuleFileInfo[isIndex], key)) mAMBS[isIndex]->setString(key, value); return prt::STATUS_OK; diff --git a/src/palladio/AttrEvalCallbacks.h b/src/palladio/AttrEvalCallbacks.h index 8daf71ae..98f609dd 100644 --- a/src/palladio/AttrEvalCallbacks.h +++ b/src/palladio/AttrEvalCallbacks.h @@ -22,15 +22,17 @@ #include - -class AttrEvalCallbacks: public prt::Callbacks { +class AttrEvalCallbacks : public prt::Callbacks { public: - explicit AttrEvalCallbacks(AttributeMapBuilderVector& ambs, const std::vector& ruleFileInfo) : mAMBS(ambs), mRuleFileInfo(ruleFileInfo) { } + explicit AttrEvalCallbacks(AttributeMapBuilderVector& ambs, const std::vector& ruleFileInfo) + : mAMBS(ambs), mRuleFileInfo(ruleFileInfo) {} ~AttrEvalCallbacks() override = default; prt::Status generateError(size_t isIndex, prt::Status status, const wchar_t* message) override; - prt::Status assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, const wchar_t* message) override; - prt::Status cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, const wchar_t* message) override; + prt::Status assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, + const wchar_t* message) override; + prt::Status cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, + const wchar_t* message) override; prt::Status cgaPrint(size_t isIndex, int32_t shapeID, const wchar_t* txt) override; prt::Status cgaReportBool(size_t isIndex, int32_t shapeID, const wchar_t* key, bool value) override; prt::Status cgaReportFloat(size_t isIndex, int32_t shapeID, const wchar_t* key, double value) override; @@ -40,13 +42,31 @@ class AttrEvalCallbacks: public prt::Callbacks { prt::Status attrString(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* value) override; #if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 1) - prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } - prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } - prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, + size_t nRows) override { + return prt::STATUS_OK; + } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, + size_t nRows) override { + return prt::STATUS_OK; + } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, + size_t size, size_t nRows) override { + return prt::STATUS_OK; + } #elif (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) - prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size) override { return prt::STATUS_OK; } - prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size) override { return prt::STATUS_OK; } - prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size) override { return prt::STATUS_OK; } + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, + size_t size) override { + return prt::STATUS_OK; + } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, + size_t size) override { + return prt::STATUS_OK; + } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, + size_t size) override { + return prt::STATUS_OK; + } #endif private: diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index 5699e2ad..42b613d0 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -27,81 +27,93 @@ #include #include - namespace { constexpr bool DBG = false; namespace StringConversionCaches { - LockedLRUCache toPrimAttr(1 << 12); +LockedLRUCache toPrimAttr(1 << 12); } -template -void setHandleRange(const GA_IndexMap& indexMap, H& handle, GA_Offset start, GA_Size size, int component, const V& value); +template +void setHandleRange(const GA_IndexMap& indexMap, H& handle, GA_Offset start, GA_Size size, int component, + const V& value); -template<> -void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleC& handle, GA_Offset start, GA_Size size, int component, const bool& value) { +template <> +void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleC& handle, GA_Offset start, GA_Size size, + int component, const bool& value) { constexpr int8_t valFalse = 0; - constexpr int8_t valTrue = 1; + constexpr int8_t valTrue = 1; const int8_t hv = value ? valTrue : valFalse; handle.setBlock(start, size, &hv, 0, component); - if (DBG) LOG_DBG << "bool attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() << " = " << value; + if (DBG) + LOG_DBG << "bool attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() + << " = " << value; } -template<> -void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleI& handle, GA_Offset start, GA_Size size, int component, const int32_t& value) { +template <> +void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleI& handle, GA_Offset start, GA_Size size, + int component, const int32_t& value) { handle.setBlock(start, size, &value, 0, component); - if (DBG) LOG_DBG << "int attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() << " = " << value; + if (DBG) + LOG_DBG << "int attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() + << " = " << value; } -template<> -void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleF& handle, GA_Offset start, GA_Size size, int component, const double& value) { +template <> +void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleF& handle, GA_Offset start, GA_Size size, + int component, const double& value) { const auto hv = static_cast(value); handle.setBlock(start, size, &hv, 0, component); // using stride = 0 to always set the same value - if (DBG) LOG_DBG << "float attr: component = " << component << ", range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() << " = " << value; + if (DBG) + LOG_DBG << "float attr: component = " << component << ", range = [" << start << ", " << start + size + << "): " << handle.getAttribute()->getName() << " = " << value; } -template<> -void setHandleRange(const GA_IndexMap& indexMap, GA_RWBatchHandleS& handle, GA_Offset start, GA_Size size, int component, const std::wstring& value) { - const UT_String attrValue = [&value]() { - const auto sh = StringConversionCaches::toPrimAttr.get(value); - if (sh) - return sh.get(); - const std::string nv = toOSNarrowFromUTF16(value); - UT_String hv(UT_String::ALWAYS_DEEP, nv); // ensure owning UT_String inside cache - StringConversionCaches::toPrimAttr.insert(value, hv); - return hv; - }(); - - const GA_Range range(indexMap, start, start+size); +template <> +void setHandleRange(const GA_IndexMap& indexMap, GA_RWBatchHandleS& handle, GA_Offset start, GA_Size size, + int component, const std::wstring& value) { + const UT_String attrValue = [&value]() { + const auto sh = StringConversionCaches::toPrimAttr.get(value); + if (sh) + return sh.get(); + const std::string nv = toOSNarrowFromUTF16(value); + UT_String hv(UT_String::ALWAYS_DEEP, nv); // ensure owning UT_String inside cache + StringConversionCaches::toPrimAttr.insert(value, hv); + return hv; + }(); + + const GA_Range range(indexMap, start, start + size); handle.set(range, component, attrValue); - if (DBG) LOG_DBG << "string attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() << " = " << attrValue; + if (DBG) + LOG_DBG << "string attr: range = [" << start << ", " << start + size + << "): " << handle.getAttribute()->getName() << " = " << attrValue; } class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { private: const AttributeConversion::ProtoHandle& protoHandle; - const prt::AttributeMap* attrMap; - const GA_IndexMap& primIndexMap; - GA_Offset rangeStart; - GA_Size rangeSize; + const prt::AttributeMap* attrMap; + const GA_IndexMap& primIndexMap; + GA_Offset rangeStart; + GA_Size rangeSize; public: - HandleVisitor(const AttributeConversion::ProtoHandle& ph, const prt::AttributeMap* m, - const GA_IndexMap& pim, GA_Offset rStart, GA_Size rSize) - : protoHandle(ph), attrMap(m), primIndexMap(pim), rangeStart(rStart), rangeSize(rSize) { } - - void operator()(const AttributeConversion::NoHandle& handle) const { } - - void operator()(GA_RWBatchHandleS& handle) const { - if (protoHandle.type == prt::Attributable::PT_STRING) { - wchar_t const* const v = attrMap->getString(protoHandle.key.c_str()); - if (v && std::wcslen(v) > 0) { - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, std::wstring(v)); - } - } - else if (protoHandle.type == prt::Attributable::PT_STRING_ARRAY) { + HandleVisitor(const AttributeConversion::ProtoHandle& ph, const prt::AttributeMap* m, const GA_IndexMap& pim, + GA_Offset rStart, GA_Size rSize) + : protoHandle(ph), attrMap(m), primIndexMap(pim), rangeStart(rStart), rangeSize(rSize) {} + + void operator()(const AttributeConversion::NoHandle& handle) const {} + + void operator()(GA_RWBatchHandleS& handle) const { + if (protoHandle.type == prt::Attributable::PT_STRING) { + wchar_t const* const v = attrMap->getString(protoHandle.key.c_str()); + if (v && std::wcslen(v) > 0) { + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, std::wstring(v)); + } + } + else if (protoHandle.type == prt::Attributable::PT_STRING_ARRAY) { size_t arraySize = 0; wchar_t const* const* const v = attrMap->getStringArray(protoHandle.key.c_str(), &arraySize); for (size_t i = 0; i < arraySize; i++) { @@ -109,10 +121,10 @@ class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { setHandleRange(primIndexMap, handle, rangeStart, rangeSize, i, std::wstring(v[i])); } } - } - } + } + } - void operator()(const GA_RWHandleI& handle) const { + void operator()(const GA_RWHandleI& handle) const { if (protoHandle.type == prt::Attributable::PT_INT) { const int32_t v = attrMap->getInt(protoHandle.key.c_str()); setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); @@ -120,9 +132,9 @@ class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { else if (protoHandle.type == prt::Attributable::PT_INT_ARRAY) { LOG_ERR << "int arrays not yet implemented"; } - } + } - void operator()(const GA_RWHandleC& handle) const { + void operator()(const GA_RWHandleC& handle) const { if (protoHandle.type == prt::Attributable::PT_BOOL) { const bool v = attrMap->getBool(protoHandle.key.c_str()); setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); @@ -130,9 +142,9 @@ class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { else if (protoHandle.type == prt::Attributable::PT_BOOL_ARRAY) { LOG_ERR << "bool arrays not yet implemented"; } - } + } - void operator()(const GA_RWHandleF& handle) const { + void operator()(const GA_RWHandleF& handle) const { if (protoHandle.type == prt::Attributable::PT_FLOAT) { const auto v = attrMap->getFloat(protoHandle.key.c_str()); setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); @@ -148,16 +160,17 @@ class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { }; void addProtoHandle(AttributeConversion::HandleMap& handleMap, const std::wstring& handleName, - AttributeConversion::ProtoHandle&& ph) -{ + AttributeConversion::ProtoHandle&& ph) { WA("all"); const UT_StringHolder& utName = NameConversion::toPrimAttr(handleName); - if (DBG) LOG_DBG << "handle name conversion: handleName = " << handleName << ", utName = " << utName; + if (DBG) + LOG_DBG << "handle name conversion: handleName = " << handleName << ", utName = " << utName; handleMap.emplace(utName, std::move(ph)); } -size_t getAttributeCardinality(const prt::AttributeMap* attrMap, const std::wstring& key, const prt::Attributable::PrimitiveType& type) { +size_t getAttributeCardinality(const prt::AttributeMap* attrMap, const std::wstring& key, + const prt::Attributable::PrimitiveType& type) { size_t cardinality = -1; switch (type) { case prt::Attributable::PT_STRING_ARRAY: { @@ -186,7 +199,6 @@ size_t getAttributeCardinality(const prt::AttributeMap* attrMap, const std::wstr } // namespace - namespace AttributeConversion { void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMap) { @@ -206,7 +218,7 @@ void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMa void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap) { WA("all"); - for (auto& hm: handleMap) { + for (auto& hm : handleMap) { const auto& utKey = hm.first; const auto& type = hm.second.type; @@ -215,7 +227,8 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap) { switch (type) { case prt::Attributable::PT_BOOL: case prt::Attributable::PT_BOOL_ARRAY: { - GA_RWHandleC h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality, GA_Defaults(0), nullptr, nullptr, GA_STORE_INT8)); + GA_RWHandleC h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality, GA_Defaults(0), + nullptr, nullptr, GA_STORE_INT8)); if (h.isValid()) handle = h; break; @@ -242,22 +255,24 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap) { break; } default: - if (DBG) LOG_DBG << "ignored: " << utKey; + if (DBG) + LOG_DBG << "ignored: " << utKey; break; } if (handle.which() != 0) { hm.second.handleType = handle; - if (DBG) LOG_DBG << "added attr handle " << utKey << " of type " << handle.type().name(); + if (DBG) + LOG_DBG << "added attr handle " << utKey << " of type " << handle.type().name(); } - else if (DBG) LOG_DBG << "could not update handle for primitive attribute " << utKey; + else if (DBG) + LOG_DBG << "could not update handle for primitive attribute " << utKey; } } -void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, - const GA_IndexMap& primIndexMap, const GA_Offset rangeStart, const GA_Size rangeSize) -{ - for (auto& h: handleMap) { +void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, const GA_IndexMap& primIndexMap, + const GA_Offset rangeStart, const GA_Size rangeSize) { + for (auto& h : handleMap) { if (attrMap->hasKey(h.second.key.c_str())) { const HandleVisitor hv(h.second, attrMap, primIndexMap, rangeStart, rangeSize); PLD_BOOST_NS::apply_visitor(hv, h.second.handleType); @@ -267,19 +282,16 @@ void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, } // namespace AttributeConversion - namespace { -constexpr const char* RULE_ATTR_NAME_TO_PRIM_ATTR[][2] = { - { ".", "__" } -}; -constexpr size_t RULE_ATTR_NAME_TO_PRIM_ATTR_N = sizeof(RULE_ATTR_NAME_TO_PRIM_ATTR)/sizeof(RULE_ATTR_NAME_TO_PRIM_ATTR[0]); +constexpr const char* RULE_ATTR_NAME_TO_PRIM_ATTR[][2] = {{".", "__"}}; +constexpr size_t RULE_ATTR_NAME_TO_PRIM_ATTR_N = + sizeof(RULE_ATTR_NAME_TO_PRIM_ATTR) / sizeof(RULE_ATTR_NAME_TO_PRIM_ATTR[0]); constexpr wchar_t STYLE_SEPARATOR = L'$'; } // namespace - namespace NameConversion { std::wstring addStyle(const std::wstring& n, const std::wstring& style) { @@ -289,7 +301,7 @@ std::wstring addStyle(const std::wstring& n, const std::wstring& style) { std::wstring removeStyle(const std::wstring& n) { const auto p = n.find_first_of(STYLE_SEPARATOR); if (p != std::string::npos) - return n.substr(p+1); + return n.substr(p + 1); return n; } @@ -326,14 +338,14 @@ void separate(const std::wstring& fqName, std::wstring& style, std::wstring& nam if (p == std::wstring::npos) { name.assign(fqName); } - else if (p > 0 && p < fqName.length()-1) { - style.assign(fqName.substr(0,p)); + else if (p > 0 && p < fqName.length() - 1) { + style.assign(fqName.substr(0, p)); name.assign(fqName.substr(p + 1)); } else if (p == 0) { // empty style name = fqName.substr(1); } - else if (p == fqName.length()-1) { // empty name + else if (p == fqName.length() - 1) { // empty name style = fqName.substr(0, p); } } diff --git a/src/palladio/AttributeConversion.h b/src/palladio/AttributeConversion.h index d4a0bcb4..f601d017 100644 --- a/src/palladio/AttributeConversion.h +++ b/src/palladio/AttributeConversion.h @@ -28,15 +28,14 @@ #include - namespace std { - template<> struct hash { - std::size_t operator()(UT_String const& s) const noexcept { - return s.hash(); - } - }; -} - +template <> +struct hash { + std::size_t operator()(UT_String const& s) const noexcept { + return s.hash(); + } +}; +} // namespace std namespace AttributeConversion { @@ -47,29 +46,26 @@ namespace AttributeConversion { * bool -> int8_t * double -> float (single precision!) */ -using NoHandle = int8_t; +using NoHandle = int8_t; using HandleType = PLD_BOOST_NS::variant; - // bound to life time of PRT attribute map struct ProtoHandle { - HandleType handleType; - std::wstring key; + HandleType handleType; + std::wstring key; prt::AttributeMap::PrimitiveType type; // original PRT type - size_t cardinality; + size_t cardinality; }; using HandleMap = std::unordered_map; PLD_TEST_EXPORTS_API void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMap); void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap); -void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, - const GA_IndexMap& primIndexMap, const GA_Offset rangeStart, - const GA_Size rangeSize); +void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, const GA_IndexMap& primIndexMap, + const GA_Offset rangeStart, const GA_Size rangeSize); } // namespace AttributeConversion - namespace NameConversion { std::wstring addStyle(const std::wstring& n, const std::wstring& style); diff --git a/src/palladio/LRUCache.h b/src/palladio/LRUCache.h index f2db5f44..fcba6597 100644 --- a/src/palladio/LRUCache.h +++ b/src/palladio/LRUCache.h @@ -1,4 +1,4 @@ -# pragma once +#pragma once // clang-format off #include "BoostRedirect.h" @@ -9,7 +9,6 @@ #include #include - // shamelessly copied from boost (houdini's hboost does not include this header) // http://www.boost.org/doc/libs/1_66_0/boost/compute/detail/lru_cache.hpp @@ -24,117 +23,99 @@ //---------------------------------------------------------------------------// // a cache which evicts the least recently used item when it is full -template -class lru_cache -{ +template +class lru_cache { public: - typedef Key key_type; - typedef Value value_type; - typedef std::list list_type; - typedef std::map< - key_type, - std::pair - > map_type; - - lru_cache(size_t capacity) - : m_capacity(capacity) - { - } - - ~lru_cache() - { - } - - size_t size() const - { - return m_map.size(); - } - - size_t capacity() const - { - return m_capacity; - } - - bool empty() const - { - return m_map.empty(); - } - - bool contains(const key_type &key) - { - return m_map.find(key) != m_map.end(); - } - - void insert(const key_type &key, const value_type &value) - { - typename map_type::iterator i = m_map.find(key); - if(i == m_map.end()){ - // insert item into the mCache, but first check if it is full - if(size() >= m_capacity){ - // mCache is full, evict the least recently used item - evict(); - } - - // insert the new item - m_list.push_front(key); - m_map[key] = std::make_pair(value, m_list.begin()); - } - } - - PLD_BOOST_NS::optional get(const key_type &key) - { - // lookup value in the mCache - typename map_type::iterator i = m_map.find(key); - if(i == m_map.end()){ - // value not in mCache - return PLD_BOOST_NS::none; - } - - // return the value, but first update its place in the most - // recently used list - typename list_type::iterator j = i->second.second; - if(j != m_list.begin()){ - // move item to the front of the most recently used list - m_list.erase(j); - m_list.push_front(key); - - // update iterator in map - j = m_list.begin(); - const value_type &value = i->second.first; - m_map[key] = std::make_pair(value, j); - - // return the value - return value; - } - else { - // the item is already at the front of the most recently - // used list so just return it - return i->second.first; - } - } - - void clear() - { - m_map.clear(); - m_list.clear(); - } + typedef Key key_type; + typedef Value value_type; + typedef std::list list_type; + typedef std::map> map_type; + + lru_cache(size_t capacity) : m_capacity(capacity) {} + + ~lru_cache() {} + + size_t size() const { + return m_map.size(); + } + + size_t capacity() const { + return m_capacity; + } + + bool empty() const { + return m_map.empty(); + } + + bool contains(const key_type& key) { + return m_map.find(key) != m_map.end(); + } + + void insert(const key_type& key, const value_type& value) { + typename map_type::iterator i = m_map.find(key); + if (i == m_map.end()) { + // insert item into the mCache, but first check if it is full + if (size() >= m_capacity) { + // mCache is full, evict the least recently used item + evict(); + } + + // insert the new item + m_list.push_front(key); + m_map[key] = std::make_pair(value, m_list.begin()); + } + } + + PLD_BOOST_NS::optional get(const key_type& key) { + // lookup value in the mCache + typename map_type::iterator i = m_map.find(key); + if (i == m_map.end()) { + // value not in mCache + return PLD_BOOST_NS::none; + } + + // return the value, but first update its place in the most + // recently used list + typename list_type::iterator j = i->second.second; + if (j != m_list.begin()) { + // move item to the front of the most recently used list + m_list.erase(j); + m_list.push_front(key); + + // update iterator in map + j = m_list.begin(); + const value_type& value = i->second.first; + m_map[key] = std::make_pair(value, j); + + // return the value + return value; + } + else { + // the item is already at the front of the most recently + // used list so just return it + return i->second.first; + } + } + + void clear() { + m_map.clear(); + m_list.clear(); + } private: - void evict() - { - // evict item from the end of most recently used list - typename list_type::iterator i = --m_list.end(); - m_map.erase(*i); - m_list.erase(i); - } + void evict() { + // evict item from the end of most recently used list + typename list_type::iterator i = --m_list.end(); + m_map.erase(*i); + m_list.erase(i); + } private: - map_type m_map; - list_type m_list; - size_t m_capacity; + map_type m_map; + list_type m_list; + size_t m_capacity; }; - /* * Copyright 2014-2019 Esri R&D Zurich and VRBN * @@ -153,12 +134,12 @@ class lru_cache #undef LOCKED_LRU_CACHE_STATS -template -class LockedLRUCache : public lru_cache { +template +class LockedLRUCache : public lru_cache { private: - using Base = lru_cache; + using Base = lru_cache; - std::mutex mMutex; + std::mutex mMutex; #ifdef LOCKED_LRU_CACHE_STATS size_t hits = 0; @@ -166,30 +147,31 @@ class LockedLRUCache : public lru_cache { #endif public: - LockedLRUCache(size_t capacity) : Base{capacity} { } + LockedLRUCache(size_t capacity) : Base{capacity} {} ~LockedLRUCache() { #ifdef LOCKED_LRU_CACHE_STATS - std::wcout << L"~LockedLRUCache: capacity = " << this->capacity() << L", size = " << this->size() << L", hits = " << hits << L", misses = " << misses << std::endl; + std::wcout << L"~LockedLRUCache: capacity = " << this->capacity() << L", size = " << this->size() + << L", hits = " << hits << L", misses = " << misses << std::endl; #endif } - void insert(const K& key, const V& value) { + void insert(const K& key, const V& value) { std::lock_guard guard(mMutex); - Base::insert(key, value); - } + Base::insert(key, value); + } - PLD_BOOST_NS::optional get(const K& key) { + PLD_BOOST_NS::optional get(const K& key) { std::lock_guard guard(mMutex); - auto v = Base::get(key); + auto v = Base::get(key); #ifdef LOCKED_LRU_CACHE_STATS if (v) hits++; - else - misses++; + else + misses++; #endif - return v; - } + return v; + } }; diff --git a/src/palladio/LogHandler.h b/src/palladio/LogHandler.h index 3890dcb7..9f3e364c 100644 --- a/src/palladio/LogHandler.h +++ b/src/palladio/LogHandler.h @@ -19,58 +19,84 @@ #include "prt/API.h" #include "prt/LogHandler.h" -#include -#include +#include #include +#include #include #include -#include -#include - +#include +#include namespace logging { -struct Logger { }; +struct Logger {}; -const std::string LEVELS[] = { "trace", "debug", "info", "warning", "error", "fatal" }; -const std::wstring WLEVELS[] = { L"trace", L"debug", L"info", L"warning", L"error", L"fatal" }; +const std::string LEVELS[] = {"trace", "debug", "info", "warning", "error", "fatal"}; +const std::wstring WLEVELS[] = {L"trace", L"debug", L"info", L"warning", L"error", L"fatal"}; // log to std streams -template struct StreamLogger : Logger { - StreamLogger(std::wostream& out = std::wcout) : Logger(), mOut(out) { mOut << prefix(); } - virtual ~StreamLogger() { mOut << std::endl; } - StreamLogger& operator<<(std::wostream&(*x)(std::wostream&)) { mOut << x; return *this; } - StreamLogger& operator<<(const std::string& x) { std::copy(x.begin(), x.end(), std::ostream_iterator(mOut)); return *this; } - template StreamLogger& operator<<(const T& x) { mOut << x; return *this; } - static std::wstring prefix() { return L"[" + WLEVELS[L] + L"] "; } +template +struct StreamLogger : Logger { + StreamLogger(std::wostream& out = std::wcout) : Logger(), mOut(out) { + mOut << prefix(); + } + virtual ~StreamLogger() { + mOut << std::endl; + } + StreamLogger& operator<<(std::wostream& (*x)(std::wostream&)) { + mOut << x; + return *this; + } + StreamLogger& operator<<(const std::string& x) { + std::copy(x.begin(), x.end(), std::ostream_iterator(mOut)); + return *this; + } + template + StreamLogger& operator<<(const T& x) { + mOut << x; + return *this; + } + static std::wstring prefix() { + return L"[" + WLEVELS[L] + L"] "; + } std::wostream& mOut; }; // log through the prt logger -template struct PRTLogger : Logger { - PRTLogger() : Logger() { } - virtual ~PRTLogger() { prt::log(wstr.str().c_str(), L); } - PRTLogger& operator<<(std::wostream&(*x)(std::wostream&)) { wstr << x; return *this; } +template +struct PRTLogger : Logger { + PRTLogger() : Logger() {} + virtual ~PRTLogger() { + prt::log(wstr.str().c_str(), L); + } + PRTLogger& operator<<(std::wostream& (*x)(std::wostream&)) { + wstr << x; + return *this; + } PRTLogger& operator<<(const std::string& x) { std::copy(x.begin(), x.end(), std::ostream_iterator(wstr)); return *this; } - template PRTLogger& operator<<(const std::vector& v) { + template + PRTLogger& operator<<(const std::vector& v) { wstr << L"[ "; - for (const T& x: v) { + for (const T& x : v) { wstr << x << L" "; } wstr << L"]"; return *this; } - template PRTLogger& operator<<(const T& x) { wstr << x; return *this; } + template + PRTLogger& operator<<(const T& x) { + wstr << x; + return *this; + } std::wostringstream wstr; }; class LogHandler : public prt::LogHandler { public: - LogHandler(const std::wstring& name) : mName(name) { - } + LogHandler(const std::wstring& name) : mName(name) {} virtual void handleLogEvent(const wchar_t* msg, prt::LogLevel level) override { // probably not the best idea - is there a houdini logging framework? @@ -98,10 +124,10 @@ class LogHandler : public prt::LogHandler { using LogHandlerPtr = std::unique_ptr; // switch logger here between PRTLogger and StreamLogger -template +template using LT = PRTLogger; -} // namespace log +} // namespace logging using _LOG_DBG = logging::LT; using _LOG_INF = logging::LT; diff --git a/src/palladio/ModelConverter.cpp b/src/palladio/ModelConverter.cpp index 463beca9..a9c160cb 100644 --- a/src/palladio/ModelConverter.cpp +++ b/src/palladio/ModelConverter.cpp @@ -16,9 +16,9 @@ #include "ModelConverter.h" #include "AttributeConversion.h" -#include "ShapeConverter.h" #include "LogHandler.h" #include "MultiWatch.h" +#include "ShapeConverter.h" #include "GU/GU_HoleInfo.h" @@ -29,7 +29,6 @@ #include - namespace { constexpr bool DBG = false; @@ -48,14 +47,12 @@ UTVector3FVector convertVertices(const double* vtx, size_t vtxSize) { return utPoints; } -void setVertexNormals( - GA_RWHandleV3& handle, const GA_Detail::OffsetMarker& marker, - const double* nrm, size_t nrmSize, const uint32_t* indices -) { +void setVertexNormals(GA_RWHandleV3& handle, const GA_Detail::OffsetMarker& marker, const double* nrm, size_t nrmSize, + const uint32_t* indices) { uint32_t vi = 0; for (GA_Iterator it(marker.vertexRange()); !it.atEnd(); ++it, ++vi) { const auto nrmIdx = indices[vi]; - const auto nrmPos = nrmIdx*3; + const auto nrmPos = nrmIdx * 3; assert(nrmPos + 2 < nrmSize); const auto nx = static_cast(nrm[nrmPos + 0]); const auto ny = static_cast(nrm[nrmPos + 1]); @@ -68,19 +65,13 @@ std::mutex mDetailMutex; // guard the houdini detail object } // namespace - namespace ModelConversion { -GA_Offset createPrimitives(GU_Detail* mDetail, GroupCreation gc, const wchar_t* name, - const double* vtx, size_t vtxSize, - const double* nrm, size_t nrmSize, - const uint32_t* counts, size_t countsSize, - const uint32_t* indices, size_t indicesSize, - double const* const* uvs, size_t const* uvsSizes, - uint32_t const* const* uvCounts, size_t const* uvCountsSizes, - uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, - uint32_t uvSets) -{ +GA_Offset createPrimitives(GU_Detail* mDetail, GroupCreation gc, const wchar_t* name, const double* vtx, size_t vtxSize, + const double* nrm, size_t nrmSize, const uint32_t* counts, size_t countsSize, + const uint32_t* indices, size_t indicesSize, double const* const* uvs, + size_t const* uvsSizes, uint32_t const* const* uvCounts, size_t const* uvCountsSizes, + uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, uint32_t uvSets) { WA("all"); // -- create primitives @@ -88,11 +79,12 @@ GA_Offset createPrimitives(GU_Detail* mDetail, GroupCreation gc, const wchar_t* const UTVector3FVector utPoints = convertVertices(vtx, vtxSize); const GEO_PolyCounts geoPolyCounts = [&counts, &countsSize]() { GEO_PolyCounts pc; - for (size_t ci = 0; ci < countsSize; ci++) pc.append(counts[ci]); + for (size_t ci = 0; ci < countsSize; ci++) + pc.append(counts[ci]); return pc; }(); - const GA_Offset primStartOffset = GU_PrimPoly::buildBlock(mDetail, utPoints.data(), utPoints.size(), - geoPolyCounts, reinterpret_cast(indices)); + const GA_Offset primStartOffset = GU_PrimPoly::buildBlock(mDetail, utPoints.data(), utPoints.size(), geoPolyCounts, + reinterpret_cast(indices)); // -- add vertex normals if (nrmSize > 0) { @@ -102,10 +94,12 @@ GA_Offset createPrimitives(GU_Detail* mDetail, GroupCreation gc, const wchar_t* // -- add texture coordinates for (size_t uvSet = 0; uvSet < uvSets; uvSet++) { - size_t const psUVSSize = uvsSizes[uvSet]; - size_t const psUVCountsSize = uvCountsSizes[uvSet]; + size_t const psUVSSize = uvsSizes[uvSet]; + size_t const psUVCountsSize = uvCountsSizes[uvSet]; size_t const psUVIndicesSize = uvIndicesSizes[uvSet]; - if (DBG) LOG_DBG << "-- uvset " << uvSet << ": psUVCountsSize = " << psUVCountsSize << ", psUVIndicesSize = " << psUVIndicesSize; + if (DBG) + LOG_DBG << "-- uvset " << uvSet << ": psUVCountsSize = " << psUVCountsSize + << ", psUVIndicesSize = " << psUVIndicesSize; if (psUVSSize > 0 && psUVIndicesSize > 0 && psUVCountsSize > 0) { GA_RWHandleV3 uvh; @@ -116,19 +110,22 @@ GA_Offset createPrimitives(GU_Detail* mDetail, GroupCreation gc, const wchar_t* uvh.bind(mDetail->addTuple(GA_STORE_REAL32, GA_ATTRIB_VERTEX, GA_SCOPE_PUBLIC, n.c_str(), 3)); } - double const* const psUVS = uvs[uvSet]; - uint32_t const* const psUVCounts = uvCounts[uvSet]; + double const* const psUVS = uvs[uvSet]; + uint32_t const* const psUVCounts = uvCounts[uvSet]; uint32_t const* const psUVIndices = uvIndices[uvSet]; size_t fi = 0; size_t uvi = 0; for (GA_Iterator pit(marker.primitiveRange()); !pit.atEnd(); ++pit, ++fi) { GA_Primitive* prim = mDetail->getPrimitive(pit.getOffset()); - if (DBG) LOG_DBG << " fi = " << fi << ": prim vtx cnt = " << prim->getVertexCount() << ", vtx cnt = " << counts[fi] << ", uv cnt = " << psUVCounts[fi]; + if (DBG) + LOG_DBG << " fi = " << fi << ": prim vtx cnt = " << prim->getVertexCount() + << ", vtx cnt = " << counts[fi] << ", uv cnt = " << psUVCounts[fi]; if (psUVCounts[fi] > 0) { for (GA_Iterator vit(prim->getVertexRange()); !vit.atEnd(); ++vit, ++uvi) { - if (DBG) LOG_DBG << " vi = " << *vit << ": uvi = " << uvi; + if (DBG) + LOG_DBG << " vi = " << *vit << ": uvi = " << uvi; assert(uvi < psUVIndicesSize); const uint32_t uvIdx = psUVIndices[uvi]; const auto du = psUVS[uvIdx * 2 + 0]; @@ -155,46 +152,35 @@ GA_Offset createPrimitives(GU_Detail* mDetail, GroupCreation gc, const wchar_t* } // namespace ModelConversion - -ModelConverter::ModelConverter(GU_Detail* detail, GroupCreation gc, std::vector& statuses, UT_AutoInterrupt* autoInterrupt) -: mDetail(detail), mGroupCreation(gc), mStatuses(statuses), mAutoInterrupt(autoInterrupt) { } - -void ModelConverter::add( - const wchar_t* name, - const double* vtx, size_t vtxSize, - const double* nrm, size_t nrmSize, - const uint32_t* counts, size_t countsSize, - const uint32_t* indices, size_t indicesSize, - double const* const* uvs, size_t const* uvsSizes, - uint32_t const* const* uvCounts, size_t const* uvCountsSizes, - uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, - uint32_t uvSets, - const uint32_t* faceRanges, size_t faceRangesSize, - const prt::AttributeMap** materials, - const prt::AttributeMap** reports, - const int32_t* shapeIDs) -{ +ModelConverter::ModelConverter(GU_Detail* detail, GroupCreation gc, std::vector& statuses, + UT_AutoInterrupt* autoInterrupt) + : mDetail(detail), mGroupCreation(gc), mStatuses(statuses), mAutoInterrupt(autoInterrupt) {} + +void ModelConverter::add(const wchar_t* name, const double* vtx, size_t vtxSize, const double* nrm, size_t nrmSize, + const uint32_t* counts, size_t countsSize, const uint32_t* indices, size_t indicesSize, + double const* const* uvs, size_t const* uvsSizes, uint32_t const* const* uvCounts, + size_t const* uvCountsSizes, uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, + uint32_t uvSets, const uint32_t* faceRanges, size_t faceRangesSize, + const prt::AttributeMap** materials, const prt::AttributeMap** reports, + const int32_t* shapeIDs) { // we need to protect mDetail, it is accessed by multiple generate threads std::lock_guard guard(mDetailMutex); - const GA_Offset primStartOffset = ModelConversion::createPrimitives(mDetail, mGroupCreation, name, - vtx, vtxSize, nrm, nrmSize, - counts, countsSize, indices, indicesSize, - uvs, uvsSizes, - uvCounts, uvCountsSizes, - uvIndices, uvIndicesSizes, - uvSets); + const GA_Offset primStartOffset = ModelConversion::createPrimitives( + mDetail, mGroupCreation, name, vtx, vtxSize, nrm, nrmSize, counts, countsSize, indices, indicesSize, uvs, + uvsSizes, uvCounts, uvCountsSizes, uvIndices, uvIndicesSizes, uvSets); // -- convert materials/reports into primitive attributes based on face ranges - if (DBG) LOG_DBG << "got " << faceRangesSize-1 << " face ranges"; + if (DBG) + LOG_DBG << "got " << faceRangesSize - 1 << " face ranges"; if (faceRangesSize > 1) { WA("add materials/reports"); AttributeConversion::HandleMap handleMap; const GA_IndexMap& primIndexMap = mDetail->getIndexMap(GA_ATTRIB_PRIMITIVE); - for (size_t fri = 0; fri < faceRangesSize-1; fri++) { + for (size_t fri = 0; fri < faceRangesSize - 1; fri++) { const GA_Offset rangeStart = primStartOffset + faceRanges[fri]; - const GA_Size rangeSize = faceRanges[fri + 1] - faceRanges[fri]; + const GA_Size rangeSize = faceRanges[fri + 1] - faceRanges[fri]; if (materials != nullptr) { const prt::AttributeMap* attrMap = materials[fri]; @@ -218,8 +204,8 @@ void ModelConverter::add( const AttributeMapUPtr attrMap(it->second->createAttributeMap()); AttributeConversion::extractAttributeNames(handleMap, attrMap.get()); AttributeConversion::createAttributeHandles(mDetail, handleMap); - AttributeConversion::setAttributeValues(handleMap, attrMap.get(), primIndexMap, - rangeStart, rangeSize); + AttributeConversion::setAttributeValues(handleMap, attrMap.get(), primIndexMap, rangeStart, + rangeSize); } } } @@ -232,12 +218,14 @@ prt::Status ModelConverter::generateError(size_t isIndex, prt::Status status, co return prt::STATUS_OK; } -prt::Status ModelConverter::assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, const wchar_t* message) { +prt::Status ModelConverter::assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, + const wchar_t* message) { LOG_WRN << key << L": " << message; return prt::STATUS_OK; } -prt::Status ModelConverter::cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, const wchar_t* message) { +prt::Status ModelConverter::cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, + int32_t pc, const wchar_t* message) { LOG_WRN << message; return prt::STATUS_OK; } @@ -271,19 +259,22 @@ AttributeMapBuilderUPtr& getBuilder(std::map& } // namespace prt::Status ModelConverter::attrBool(size_t isIndex, int32_t shapeID, const wchar_t* key, bool value) { - if (DBG) LOG_DBG << "attrBool: shapeID :" << shapeID << ", key: " << key << ", val: " << value; + if (DBG) + LOG_DBG << "attrBool: shapeID :" << shapeID << ", key: " << key << ", val: " << value; getBuilder(mShapeAttributeBuilders, shapeID)->setBool(key, value); return prt::STATUS_OK; } prt::Status ModelConverter::attrFloat(size_t isIndex, int32_t shapeID, const wchar_t* key, double value) { - if (DBG) LOG_DBG << "attrFloat: shapeID :" << shapeID << ", key: " << key << ", val: " << value; + if (DBG) + LOG_DBG << "attrFloat: shapeID :" << shapeID << ", key: " << key << ", val: " << value; getBuilder(mShapeAttributeBuilders, shapeID)->setFloat(key, value); return prt::STATUS_OK; } prt::Status ModelConverter::attrString(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* value) { - if (DBG) LOG_DBG << "attrString: shapeID :" << shapeID << ", key: " << key << ", val: " << value; + if (DBG) + LOG_DBG << "attrString: shapeID :" << shapeID << ", key: " << key << ", val: " << value; getBuilder(mShapeAttributeBuilders, shapeID)->setString(key, value); return prt::STATUS_OK; } diff --git a/src/palladio/ModelConverter.h b/src/palladio/ModelConverter.h index de2a2704..077c6dde 100644 --- a/src/palladio/ModelConverter.h +++ b/src/palladio/ModelConverter.h @@ -32,8 +32,8 @@ #include "GEO/GEO_PolyCounts.h" #include "GU/GU_Detail.h" #include "GU/GU_PrimPoly.h" -#include "UT/UT_Vector3.h" #include "UT/UT_Interrupt.h" +#include "UT/UT_Vector3.h" #ifdef PLD_TC_GCC # pragma GCC diagnostic pop @@ -42,52 +42,36 @@ #include #include - namespace ModelConversion { -PLD_TEST_EXPORTS_API void getUVSet( - std::vector& uvIndicesPerSet, - const uint32_t* counts, size_t countsSize, - const uint32_t* uvCounts, size_t uvCountsSize, - uint32_t uvSet, uint32_t uvSets, - const uint32_t* uvIndices, size_t uvIndicesSize -); - -void setUVs( - GA_RWHandleV3& handle, const GA_Detail::OffsetMarker& marker, - const uint32_t* counts, size_t countsSize, - const uint32_t* uvCounts, size_t uvCountsSize, - uint32_t uvSet, uint32_t uvSets, - const uint32_t* uvIndices, size_t uvIndicesSize, - const double* uvs, size_t uvsSize -); +PLD_TEST_EXPORTS_API void getUVSet(std::vector& uvIndicesPerSet, const uint32_t* counts, size_t countsSize, + const uint32_t* uvCounts, size_t uvCountsSize, uint32_t uvSet, uint32_t uvSets, + const uint32_t* uvIndices, size_t uvIndicesSize); + +void setUVs(GA_RWHandleV3& handle, const GA_Detail::OffsetMarker& marker, const uint32_t* counts, size_t countsSize, + const uint32_t* uvCounts, size_t uvCountsSize, uint32_t uvSet, uint32_t uvSets, const uint32_t* uvIndices, + size_t uvIndicesSize, const double* uvs, size_t uvsSize); } // namespace ModelConversion class ModelConverter : public HoudiniCallbacks { public: - explicit ModelConverter(GU_Detail* gdp, GroupCreation gc, std::vector& statuses, UT_AutoInterrupt* autoInterrupt = nullptr); + explicit ModelConverter(GU_Detail* gdp, GroupCreation gc, std::vector& statuses, + UT_AutoInterrupt* autoInterrupt = nullptr); protected: - void add( - const wchar_t* name, - const double* vtx, size_t vtxSize, - const double* nrm, size_t nrmSize, - const uint32_t* counts, size_t countsSize, - const uint32_t* indices, size_t indicesSize, - double const* const* uvs, size_t const* uvsSizes, - uint32_t const* const* uvCounts, size_t const* uvCountsSizes, - uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, - uint32_t uvSets, - const uint32_t* faceRanges, size_t faceRangesSize, - const prt::AttributeMap** materials, - const prt::AttributeMap** reports, - const int32_t* shapeIDs - ) override; + void add(const wchar_t* name, const double* vtx, size_t vtxSize, const double* nrm, size_t nrmSize, + const uint32_t* counts, size_t countsSize, const uint32_t* indices, size_t indicesSize, + double const* const* uvs, size_t const* uvsSizes, uint32_t const* const* uvCounts, + size_t const* uvCountsSizes, uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, + uint32_t uvSets, const uint32_t* faceRanges, size_t faceRangesSize, const prt::AttributeMap** materials, + const prt::AttributeMap** reports, const int32_t* shapeIDs) override; prt::Status generateError(size_t isIndex, prt::Status status, const wchar_t* message) override; - prt::Status assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, const wchar_t* message) override; - prt::Status cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, const wchar_t* message) override; + prt::Status assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, + const wchar_t* message) override; + prt::Status cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, + const wchar_t* message) override; prt::Status cgaPrint(size_t isIndex, int32_t shapeID, const wchar_t* txt) override; prt::Status cgaReportBool(size_t isIndex, int32_t shapeID, const wchar_t* key, bool value) override; prt::Status cgaReportFloat(size_t isIndex, int32_t shapeID, const wchar_t* key, double value) override; @@ -97,13 +81,31 @@ class ModelConverter : public HoudiniCallbacks { prt::Status attrString(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* value) override; #if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 1) - prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } - prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } - prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size, size_t nRows) override { return prt::STATUS_OK; } + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, + size_t nRows) override { + return prt::STATUS_OK; + } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, + size_t nRows) override { + return prt::STATUS_OK; + } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, + size_t size, size_t nRows) override { + return prt::STATUS_OK; + } #elif (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) - prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size) override { return prt::STATUS_OK; } - prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size) override { return prt::STATUS_OK; } - prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, size_t size) override { return prt::STATUS_OK; } + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, + size_t size) override { + return prt::STATUS_OK; + } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, + size_t size) override { + return prt::STATUS_OK; + } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, + size_t size) override { + return prt::STATUS_OK; + } #endif prt::Callbacks::Continuation progress(float percentageCompleted) override { @@ -114,7 +116,7 @@ class ModelConverter : public HoudiniCallbacks { private: GU_Detail* mDetail; - GroupCreation mGroupCreation; + GroupCreation mGroupCreation; std::vector& mStatuses; UT_AutoInterrupt* mAutoInterrupt; std::map mShapeAttributeBuilders; diff --git a/src/palladio/MultiWatch.cpp b/src/palladio/MultiWatch.cpp index aba604c9..77b88dbd 100644 --- a/src/palladio/MultiWatch.cpp +++ b/src/palladio/MultiWatch.cpp @@ -17,12 +17,11 @@ #include "MultiWatch.h" #include "LogHandler.h" -#include -#include #include -#include #include - +#include +#include +#include namespace { @@ -65,14 +64,14 @@ void MultiWatch::stop(const std::string& name) { void MultiWatch::printTimings() const { std::map> lapTimes; - for (const auto& l: laps) { - for (const auto& ctx: l) { + for (const auto& l : laps) { + for (const auto& ctx : l) { lapTimes[ctx.first].push_back(ctx.second); } } LOG_FTL << "-- timings:"; - for (const auto& l: lapTimes) { + for (const auto& l : lapTimes) { const auto& ctxName = l.first; const auto& lt = l.second; @@ -80,9 +79,9 @@ void MultiWatch::printTimings() const { const double lapSum = std::accumulate(lt.begin(), lt.end(), 0.0); const double lapAvg = lapSum / (double)numLaps; const auto avgIntStrWidth = std::to_string(std::trunc(lapAvg)).size(); - LOG_FTL << " " << ctxName - << std::setw(75 - ctxName.size()) << std::right << std::fixed << std::setprecision(5-avgIntStrWidth) << lapAvg << "s" - << std::setw(15) << std::right << "(#laps = " << numLaps << ")"; + LOG_FTL << " " << ctxName << std::setw(75 - ctxName.size()) << std::right << std::fixed + << std::setprecision(5 - avgIntStrWidth) << lapAvg << "s" << std::setw(15) << std::right + << "(#laps = " << numLaps << ")"; } } @@ -97,5 +96,5 @@ WatchAgent::~WatchAgent() { std::string WatchAgent::stripArgs(const std::string& s) { std::string t = s.substr(0, s.find_first_of('(')); auto p = t.find_last_of(' '); - return (p != std::string::npos) ? t.substr(p+1) : t; + return (p != std::string::npos) ? t.substr(p + 1) : t; } diff --git a/src/palladio/MultiWatch.h b/src/palladio/MultiWatch.h index 1d618497..8d36c13a 100644 --- a/src/palladio/MultiWatch.h +++ b/src/palladio/MultiWatch.h @@ -16,16 +16,14 @@ #pragma once -#include -#include #include +#include +#include #include - -#define WA(x) //WatchAgent wa_(x, __PRETTY_FUNCTION__) -#define WA_NEW_LAP //theWatch.newLap(); -#define WA_PRINT_TIMINGS //theWatch.printTimings(); - +#define WA(x) // WatchAgent wa_(x, __PRETTY_FUNCTION__) +#define WA_NEW_LAP // theWatch.newLap(); +#define WA_PRINT_TIMINGS // theWatch.printTimings(); class MultiWatch { public: @@ -43,7 +41,6 @@ class MultiWatch { extern MultiWatch theWatch; - class WatchAgent { public: const std::string mContext; diff --git a/src/palladio/NodeParameter.cpp b/src/palladio/NodeParameter.cpp index ad55d5a0..6c7c114e 100644 --- a/src/palladio/NodeParameter.cpp +++ b/src/palladio/NodeParameter.cpp @@ -15,11 +15,11 @@ */ #include "NodeParameter.h" -#include "SOPAssign.h" #include "AttributeConversion.h" +#include "LogHandler.h" +#include "SOPAssign.h" #include "ShapeConverter.h" #include "Utils.h" -#include "LogHandler.h" #include "prt/API.h" @@ -28,16 +28,14 @@ #include #include - namespace { constexpr const wchar_t* CGA_ANNOTATION_START_RULE = L"@StartRule"; -constexpr const size_t CGA_NO_START_RULE_FOUND = size_t(-1); - -using StringPairVector = std::vector>; -bool compareSecond (const StringPairVector::value_type& a, const StringPairVector::value_type& b) { - return ( a.second < b.second ); +constexpr const size_t CGA_NO_START_RULE_FOUND = size_t(-1); +using StringPairVector = std::vector>; +bool compareSecond(const StringPairVector::value_type& a, const StringPairVector::value_type& b) { + return (a.second < b.second); } /** @@ -49,7 +47,7 @@ std::wstring findStartRule(const RuleFileInfoUPtr& info) { auto startRuleIdx = CGA_NO_START_RULE_FOUND; for (size_t ri = 0; ri < numRules; ri++) { - const prt::RuleFileInfo::Entry *re = info->getRule(ri); + const prt::RuleFileInfo::Entry* re = info->getRule(ri); for (size_t ai = 0; ai < re->getNumAnnotations(); ai++) { if (std::wcscmp(re->getAnnotation(ai)->getName(), CGA_ANNOTATION_START_RULE) == 0) { startRuleIdx = ri; @@ -61,16 +59,15 @@ std::wstring findStartRule(const RuleFileInfoUPtr& info) { if (startRuleIdx == CGA_NO_START_RULE_FOUND) startRuleIdx = 0; // use first rule as fallback - const prt::RuleFileInfo::Entry *re = info->getRule(startRuleIdx); - return { re->getName() }; + const prt::RuleFileInfo::Entry* re = info->getRule(startRuleIdx); + return {re->getName()}; } constexpr const int NOT_CHANGED = 0; -constexpr const int CHANGED = 1; +constexpr const int CHANGED = 1; } // namespace - namespace AssignNodeParams { /** @@ -85,7 +82,7 @@ int updateRPK(void* data, int, fpreal32 time, const PRM_Template*) { const PLD_BOOST_NS::filesystem::path nextRPK(utNextRPKStr.toStdString()); ResolveMapSPtr resolveMap = prtCtx->getResolveMap(nextRPK); - if (!resolveMap ) { + if (!resolveMap) { LOG_WRN << "invalid resolve map"; return NOT_CHANGED; } @@ -99,10 +96,12 @@ int updateRPK(void* data, int, fpreal32 time, const PRM_Template*) { } const std::wstring cgbKey = cgbs.front().first; const std::wstring cgbURI = cgbs.front().second; - LOG_DBG << "cgbKey = " << cgbKey << ", " << "cgbURI = " << cgbURI; + LOG_DBG << "cgbKey = " << cgbKey << ", " + << "cgbURI = " << cgbURI; prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; - const RuleFileInfoUPtr ruleFileInfo(prt::createRuleFileInfo(cgbURI.c_str(), prtCtx->mPRTCache.get(), &status)); // TODO: cache + const RuleFileInfoUPtr ruleFileInfo( + prt::createRuleFileInfo(cgbURI.c_str(), prtCtx->mPRTCache.get(), &status)); // TODO: cache if (!ruleFileInfo || (status != prt::STATUS_OK) || (ruleFileInfo->getNumRules() == 0)) { LOG_ERR << "failed to get rule file info or rule file does not contain any rules"; return NOT_CHANGED; @@ -110,10 +109,10 @@ int updateRPK(void* data, int, fpreal32 time, const PRM_Template*) { const std::wstring fqStartRule = findStartRule(ruleFileInfo); // -- get style/name from start rule - auto getStartRuleComponents = [](const std::wstring& fqRule) -> std::pair { + auto getStartRuleComponents = [](const std::wstring& fqRule) -> std::pair { std::wstring style, name; NameConversion::separate(fqRule, style, name); - return { style, name }; + return {style, name}; }; const auto startRuleComponents = getStartRuleComponents(fqStartRule); LOG_DBG << "start rule: style = " << startRuleComponents.first << ", name = " << startRuleComponents.second; @@ -135,7 +134,7 @@ void buildStartRuleMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM const auto* node = static_cast(data); const PRTContextUPtr& prtCtx = node->getPRTCtx(); - const fpreal now = CHgetEvalTime(); + const fpreal now = CHgetEvalTime(); const PLD_BOOST_NS::filesystem::path rpk = getRPK(node, now); const std::wstring ruleFile = getRuleFile(node, now); @@ -203,7 +202,7 @@ void buildRuleFileMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM_ const auto* node = static_cast(data); const auto& prtCtx = node->getPRTCtx(); - const fpreal now = CHgetEvalTime(); + const fpreal now = CHgetEvalTime(); const PLD_BOOST_NS::filesystem::path rpk = getRPK(node, now); ResolveMapSPtr resolveMap = prtCtx->getResolveMap(rpk); @@ -212,7 +211,7 @@ void buildRuleFileMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM_ return; } - std::vector> cgbs; // key -> uri + std::vector> cgbs; // key -> uri getCGBs(resolveMap, cgbs); const size_t limit = std::min(cgbs.size(), static_cast(theMaxSize)); @@ -233,7 +232,7 @@ void buildStyleMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM_Spa const auto* node = static_cast(data); const PRTContextUPtr& prtCtx = node->getPRTCtx(); - const fpreal now = CHgetEvalTime(); + const fpreal now = CHgetEvalTime(); const PLD_BOOST_NS::filesystem::path rpk = getRPK(node, now); const std::wstring ruleFile = getRuleFile(node, now); @@ -257,7 +256,7 @@ void buildStyleMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM_Spa const prt::RuleFileInfo::Entry* re = rfi->getRule(ri); styles.emplace(extractStyle(re)); } - for (size_t ai = 0; ai < rfi->getNumAttributes(); ai++) { + for (size_t ai = 0; ai < rfi->getNumAttributes(); ai++) { const prt::RuleFileInfo::Entry* re = rfi->getAttribute(ai); styles.emplace(extractStyle(re)); } diff --git a/src/palladio/NodeParameter.h b/src/palladio/NodeParameter.h index 826047e7..b94f0c0f 100644 --- a/src/palladio/NodeParameter.h +++ b/src/palladio/NodeParameter.h @@ -16,17 +16,17 @@ #pragma once -#include "ShapeConverter.h" #include "PrimitiveClassifier.h" +#include "ShapeConverter.h" #include "Utils.h" +#include "GA/GA_Types.h" +#include "OP/OP_Node.h" +#include "PRM/PRM_Callback.h" #include "PRM/PRM_ChoiceList.h" #include "PRM/PRM_Parm.h" -#include "PRM/PRM_SpareData.h" #include "PRM/PRM_Shared.h" -#include "PRM/PRM_Callback.h" -#include "GA/GA_Types.h" -#include "OP/OP_Node.h" +#include "PRM/PRM_SpareData.h" // clang-format off #include "BoostRedirect.h" @@ -37,7 +37,8 @@ namespace AssignNodeParams { // -- PRIMITIVE CLASSIFIER NAME static PRM_Name PRIM_CLS("primClsAttr", "Primitive Classifier"); -const std::string PRIM_CLS_HELP = "Classifies primitives into input shapes and sets value for primitive attribute '" + PLD_PRIM_CLS_NAME.toStdString() + "'"; +const std::string PRIM_CLS_HELP = "Classifies primitives into input shapes and sets value for primitive attribute '" + + PLD_PRIM_CLS_NAME.toStdString() + "'"; static PRM_Default PRIM_CLS_DEFAULT(0.0f, "primCls", CH_STRING_LITERAL); const auto getPrimClsName = [](const OP_Node* node, fpreal t) -> UT_String { @@ -50,7 +51,6 @@ const auto setPrimClsName = [](OP_Node* node, const UT_String& name, fpreal t) { node->setString(name, CH_STRING_LITERAL, PRIM_CLS.getToken(), 0, t); }; - // -- RULE PACKAGE static PRM_Name RPK("rpk", "Rule Package"); const std::string RPK_HELP = "Sets value for primitive attribute '" + PLD_RPK.toStdString() + "'"; @@ -65,16 +65,14 @@ const auto getRPK = [](const OP_Node* node, fpreal t) -> PLD_BOOST_NS::filesyste return s.toStdString(); }; - // -- RPK RELOADER static PRM_Name RPK_RELOAD("rpkReload", "Reload Rule Package"); - // -- RULE FILE (cgb) static PRM_Name RULE_FILE("ruleFile", "Rule File"); const std::string RULE_FILE_HELP = "Sets value for primitive attribute '" + PLD_RULE_FILE.toStdString() + "'"; -void buildRuleFileMenu(void *data, PRM_Name *theMenu, int theMaxSize, const PRM_SpareData *, const PRM_Parm *); +void buildRuleFileMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM_SpareData*, const PRM_Parm*); static PRM_ChoiceList ruleFileMenu(static_cast(PRM_CHOICELIST_REPLACE), &buildRuleFileMenu); @@ -89,12 +87,11 @@ const auto setRuleFile = [](OP_Node* node, const std::wstring& ruleFile, fpreal node->setString(val, CH_STRING_LITERAL, RULE_FILE.getToken(), 0, t); }; - // -- STYLE static PRM_Name STYLE("style", "Style"); const std::string STYLE_HELP = "Sets value for primitive attribute '" + PLD_STYLE.toStdString() + "'"; -void buildStyleMenu(void *data, PRM_Name *theMenu, int theMaxSize, const PRM_SpareData *, const PRM_Parm *); +void buildStyleMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM_SpareData*, const PRM_Parm*); static PRM_ChoiceList styleMenu(static_cast(PRM_CHOICELIST_REPLACE), &buildStyleMenu); @@ -109,12 +106,11 @@ const auto setStyle = [](OP_Node* node, const std::wstring& s, fpreal t) { node->setString(val, CH_STRING_LITERAL, STYLE.getToken(), 0, t); }; - // -- START RULE static PRM_Name START_RULE("startRule", "Start Rule"); const std::string START_RULE_HELP = "Sets value for primitive attribute '" + PLD_START_RULE.toStdString() + "'"; -void buildStartRuleMenu(void *data, PRM_Name *theMenu, int theMaxSize, const PRM_SpareData *, const PRM_Parm *); +void buildStartRuleMenu(void* data, PRM_Name* theMenu, int theMaxSize, const PRM_SpareData*, const PRM_Parm*); static PRM_ChoiceList startRuleMenu(static_cast(PRM_CHOICELIST_REPLACE), &buildStartRuleMenu); @@ -129,56 +125,55 @@ const auto setStartRule = [](OP_Node* node, const std::wstring& s, fpreal t) { node->setString(val, CH_STRING_LITERAL, START_RULE.getToken(), 0, t); }; - // -- ASSIGN NODE PARAMS static PRM_Template PARAM_TEMPLATES[] = { - PRM_Template(PRM_STRING, 1, &PRIM_CLS, &PRIM_CLS_DEFAULT, nullptr, nullptr, PRM_Callback(), nullptr, 1, PRIM_CLS_HELP.c_str()), - PRM_Template(PRM_FILE, 1, &RPK, &RPK_DEFAULT, nullptr, nullptr, rpkCallback, &PRM_SpareData::fileChooserModeRead, 1, RPK_HELP.c_str()), - PRM_Template(PRM_CALLBACK, 1, &RPK_RELOAD, PRMoneDefaults, nullptr, nullptr, rpkCallback), - PRM_Template(PRM_STRING, 1, &RULE_FILE, PRMoneDefaults, &ruleFileMenu, nullptr, PRM_Callback(), nullptr, 1, RULE_FILE_HELP.c_str()), - PRM_Template(PRM_STRING, 1, &STYLE, PRMoneDefaults, &styleMenu, nullptr, PRM_Callback(), nullptr, 1, STYLE_HELP.c_str()), - PRM_Template(PRM_STRING, 1, &START_RULE, PRMoneDefaults, &startRuleMenu, nullptr, PRM_Callback(), nullptr, 1, START_RULE_HELP.c_str()), - PRM_Template() -}; + PRM_Template(PRM_STRING, 1, &PRIM_CLS, &PRIM_CLS_DEFAULT, nullptr, nullptr, PRM_Callback(), nullptr, 1, + PRIM_CLS_HELP.c_str()), + PRM_Template(PRM_FILE, 1, &RPK, &RPK_DEFAULT, nullptr, nullptr, rpkCallback, + &PRM_SpareData::fileChooserModeRead, 1, RPK_HELP.c_str()), + PRM_Template(PRM_CALLBACK, 1, &RPK_RELOAD, PRMoneDefaults, nullptr, nullptr, rpkCallback), + PRM_Template(PRM_STRING, 1, &RULE_FILE, PRMoneDefaults, &ruleFileMenu, nullptr, PRM_Callback(), nullptr, 1, + RULE_FILE_HELP.c_str()), + PRM_Template(PRM_STRING, 1, &STYLE, PRMoneDefaults, &styleMenu, nullptr, PRM_Callback(), nullptr, 1, + STYLE_HELP.c_str()), + PRM_Template(PRM_STRING, 1, &START_RULE, PRMoneDefaults, &startRuleMenu, nullptr, PRM_Callback(), nullptr, 1, + START_RULE_HELP.c_str()), + PRM_Template()}; } // namespace AssignNodeParams - namespace GenerateNodeParams { static PRM_Name GROUP_CREATION("groupCreation", "Primitive Groups"); -static const char* GROUP_CREATION_TOKENS[] = { "NONE", "PRIMCLS" }; -static const char* GROUP_CREATION_LABELS[] = { - "Do not create groups", - "One group per primitive classifier" -}; -static PRM_Name GROUP_CREATION_MENU_ITEMS[] = { - PRM_Name(GROUP_CREATION_TOKENS[0], GROUP_CREATION_LABELS[0]), - PRM_Name(GROUP_CREATION_TOKENS[1], GROUP_CREATION_LABELS[1]), - PRM_Name(nullptr) -}; -static PRM_ChoiceList groupCreationMenu((PRM_ChoiceListType)(PRM_CHOICELIST_EXCLUSIVE | PRM_CHOICELIST_REPLACE), GROUP_CREATION_MENU_ITEMS); +static const char* GROUP_CREATION_TOKENS[] = {"NONE", "PRIMCLS"}; +static const char* GROUP_CREATION_LABELS[] = {"Do not create groups", "One group per primitive classifier"}; +static PRM_Name GROUP_CREATION_MENU_ITEMS[] = {PRM_Name(GROUP_CREATION_TOKENS[0], GROUP_CREATION_LABELS[0]), + PRM_Name(GROUP_CREATION_TOKENS[1], GROUP_CREATION_LABELS[1]), + PRM_Name(nullptr)}; +static PRM_ChoiceList groupCreationMenu((PRM_ChoiceListType)(PRM_CHOICELIST_EXCLUSIVE | PRM_CHOICELIST_REPLACE), + GROUP_CREATION_MENU_ITEMS); const size_t DEFAULT_GROUP_CREATION_ORDINAL = 0; static PRM_Default DEFAULT_GROUP_CREATION(0, GROUP_CREATION_TOKENS[DEFAULT_GROUP_CREATION_ORDINAL]); const auto getGroupCreation = [](const OP_Node* node, fpreal t) -> GroupCreation { const auto ord = node->evalInt(GROUP_CREATION.getToken(), 0, t); switch (ord) { - case 0: return GroupCreation::NONE; - case 1: return GroupCreation::PRIMCLS; - default: return GroupCreation::NONE; + case 0: + return GroupCreation::NONE; + case 1: + return GroupCreation::PRIMCLS; + default: + return GroupCreation::NONE; } }; static PRM_Name EMIT_ATTRS("emitAttrs", "Re-emit set CGA attributes"); static PRM_Name EMIT_MATERIAL("emitMaterials", "Emit material attributes"); static PRM_Name EMIT_REPORTS("emitReports", "Emit CGA reports"); -static PRM_Template PARAM_TEMPLATES[] { - PRM_Template(PRM_ORD, PRM_Template::PRM_EXPORT_MAX, 1, &GROUP_CREATION, &DEFAULT_GROUP_CREATION, &groupCreationMenu), - PRM_Template(PRM_TOGGLE, 1, &EMIT_ATTRS), - PRM_Template(PRM_TOGGLE, 1, &EMIT_MATERIAL), - PRM_Template(PRM_TOGGLE, 1, &EMIT_REPORTS), - PRM_Template() -}; +static PRM_Template PARAM_TEMPLATES[]{PRM_Template(PRM_ORD, PRM_Template::PRM_EXPORT_MAX, 1, &GROUP_CREATION, + &DEFAULT_GROUP_CREATION, &groupCreationMenu), + PRM_Template(PRM_TOGGLE, 1, &EMIT_ATTRS), + PRM_Template(PRM_TOGGLE, 1, &EMIT_MATERIAL), + PRM_Template(PRM_TOGGLE, 1, &EMIT_REPORTS), PRM_Template()}; } // namespace GenerateNodeParams diff --git a/src/palladio/PRTContext.cpp b/src/palladio/PRTContext.cpp index d3e0b8bc..4781e3f2 100644 --- a/src/palladio/PRTContext.cpp +++ b/src/palladio/PRTContext.cpp @@ -15,42 +15,41 @@ */ #include "PRTContext.h" -#include "PalladioMain.h" #include "LogHandler.h" +#include "PalladioMain.h" #include "SOPAssign.h" #if PRT_VERSION_MAJOR < 2 # include "prt/FlexLicParams.h" #endif -#include "OP/OP_Node.h" #include "OP/OP_Director.h" #include "OP/OP_Network.h" +#include "OP/OP_Node.h" -#include #include - +#include namespace { -constexpr const wchar_t* PLD_LOG_PREFIX = L"pld"; -constexpr const char* PLD_TMP_PREFIX = "palladio_"; +constexpr const wchar_t* PLD_LOG_PREFIX = L"pld"; +constexpr const char* PLD_TMP_PREFIX = "palladio_"; -constexpr const char* PRT_LIB_SUBDIR = "prtlib"; +constexpr const char* PRT_LIB_SUBDIR = "prtlib"; -constexpr const prt::LogLevel PRT_LOG_LEVEL_DEFAULT = prt::LOG_ERROR; -constexpr const char* PRT_LOG_LEVEL_ENV_VAR = "CITYENGINE_LOG_LEVEL"; -constexpr const char* PRT_LOG_LEVEL_STRINGS[] = { "trace", "debug", "info", "warning", "error", "fatal" }; -constexpr const size_t PRT_LOG_LEVEL_STRINGS_N = sizeof(PRT_LOG_LEVEL_STRINGS)/sizeof(PRT_LOG_LEVEL_STRINGS[0]); +constexpr const prt::LogLevel PRT_LOG_LEVEL_DEFAULT = prt::LOG_ERROR; +constexpr const char* PRT_LOG_LEVEL_ENV_VAR = "CITYENGINE_LOG_LEVEL"; +constexpr const char* PRT_LOG_LEVEL_STRINGS[] = {"trace", "debug", "info", "warning", "error", "fatal"}; +constexpr const size_t PRT_LOG_LEVEL_STRINGS_N = sizeof(PRT_LOG_LEVEL_STRINGS) / sizeof(PRT_LOG_LEVEL_STRINGS[0]); #if PRT_VERSION_MAJOR < 2 -constexpr const char* FILE_FLEXNET_LIB = "flexnet_prt"; -constexpr const char* PRT_LIC_ENV_VAR = "CITYENGINE_LICENSE_SERVER"; +constexpr const char* FILE_FLEXNET_LIB = "flexnet_prt"; +constexpr const char* PRT_LIC_ENV_VAR = "CITYENGINE_LICENSE_SERVER"; class License { private: - prt::FlexLicParams flexLicParams; + prt::FlexLicParams flexLicParams; std::string libflexnetPath; // owns flexLicParams.mActLibPath char ptr std::string licFeature; // owns flexLicParams.mFeature @@ -58,7 +57,7 @@ class License { public: License(const PLD_BOOST_NS::filesystem::path& prtRootPath) { - const std::string libflexnet = getSharedLibraryPrefix() + FILE_FLEXNET_LIB + getSharedLibrarySuffix(); + const std::string libflexnet = getSharedLibraryPrefix() + FILE_FLEXNET_LIB + getSharedLibrarySuffix(); libflexnetPath = (prtRootPath / libflexnet).string(); flexLicParams.mActLibPath = libflexnetPath.c_str(); @@ -72,7 +71,7 @@ class License { } flexLicParams.mFeature = licFeature.c_str(); - flexLicParams.mHostName = licServer.c_str(); + flexLicParams.mHostName = licServer.c_str(); LOG_INF << "CityEngine license: feature = '" << licFeature << "', server = '" << licServer << "'"; } @@ -95,10 +94,10 @@ prt::LogLevel getLogLevel() { return PRT_LOG_LEVEL_DEFAULT; } -template +template std::vector toPtrVec(const std::vector>& sv) { std::vector pv(sv.size()); - std::transform(sv.begin(), sv.end(), pv.begin(), [](const std::basic_string& s){ return s.c_str(); }); + std::transform(sv.begin(), sv.end(), pv.begin(), [](const std::basic_string& s) { return s.c_str(); }); return pv; } @@ -116,17 +115,18 @@ void scheduleRecook(const PLD_BOOST_NS::filesystem::path& rpk) { auto visitedRPK = reinterpret_cast(data); SOPAssign& sa = static_cast(n); if (sa.getRPK() == *visitedRPK) { - LOG_DBG << "forcing recook of: " << n.getName() << ", " << n.getOpType() << ", " << n.getOperator()->getName(); + LOG_DBG << "forcing recook of: " << n.getName() << ", " << n.getOpType() << ", " + << n.getOperator()->getName(); sa.forceRecook(); } } return false; }; - if (OPgetDirector() != nullptr) { - OP_Network* objMgr = OPgetDirector()->getManager("obj"); - objMgr->traverseChildren(visit, const_cast(reinterpret_cast(&rpk)), true); - } + if (OPgetDirector() != nullptr) { + OP_Network* objMgr = OPgetDirector()->getManager("obj"); + objMgr->traverseChildren(visit, const_cast(reinterpret_cast(&rpk)), true); + } } PLD_BOOST_NS::filesystem::path getProcessTempDir() { @@ -135,41 +135,36 @@ PLD_BOOST_NS::filesystem::path getProcessTempDir() { if (!ec) tp = "/tmp/"; // TODO: other OSes std::string n = std::string(PLD_TMP_PREFIX) + std::to_string(::getpid()); - return { "/tmp/" + n }; + return {"/tmp/" + n}; } } // namespace - PRTContext::PRTContext(const std::vector& addExtDirs) - : mLogHandler(new logging::LogHandler(PLD_LOG_PREFIX)), - mPRTHandle{nullptr}, - mPRTCache{prt::CacheObject::create(prt::CacheObject::CACHE_TYPE_DEFAULT)}, - mCores{getNumCores()}, - mResolveMapCache{new ResolveMapCache(getProcessTempDir())} -{ - const prt::LogLevel logLevel = getLogLevel(); + : mLogHandler(new logging::LogHandler(PLD_LOG_PREFIX)), mPRTHandle{nullptr}, + mPRTCache{prt::CacheObject::create(prt::CacheObject::CACHE_TYPE_DEFAULT)}, mCores{getNumCores()}, + mResolveMapCache{new ResolveMapCache(getProcessTempDir())} { + const prt::LogLevel logLevel = getLogLevel(); prt::setLogLevel(logLevel); prt::addLogHandler(mLogHandler.get()); // -- get the dir containing prt core library - const auto rootPath = [](){ - PLD_BOOST_NS::filesystem::path prtCorePath; + const auto rootPath = []() { + PLD_BOOST_NS::filesystem::path prtCorePath; getLibraryPath(prtCorePath, reinterpret_cast(prt::init)); return prtCorePath.parent_path(); }(); - #if PRT_VERSION_MAJOR < 2 // -- detect license const License license(rootPath); #endif // -- scan for directories with prt extensions - const std::vector extDirs = [&rootPath,&addExtDirs](){ + const std::vector extDirs = [&rootPath, &addExtDirs]() { std::vector ed; ed.emplace_back(rootPath / PRT_LIB_SUBDIR); - for (auto d: addExtDirs) { // get a copy + for (auto d : addExtDirs) { // get a copy if (PLD_BOOST_NS::filesystem::is_regular_file(d)) d = d.parent_path(); if (!d.is_absolute()) @@ -180,26 +175,26 @@ PRTContext::PRTContext(const std::vector& addExt }(); const std::vector extDirStrs = [&extDirs]() { std::vector sv; - for (const auto& d: extDirs) + for (const auto& d : extDirs) sv.emplace_back(d.wstring()); return sv; }(); const auto extDirCStrs = toPtrVec(extDirStrs); // depends on extDirStrs life-time! // -- initialize PRT - prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; - mPRTHandle.reset(prt::init(extDirCStrs.data(), extDirCStrs.size(), logLevel, + prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; + mPRTHandle.reset(prt::init(extDirCStrs.data(), extDirCStrs.size(), logLevel, #if PRT_VERSION_MAJOR < 2 - license.getParams(), + license.getParams(), #endif - &status)); - if (status != prt::STATUS_OK) { - LOG_FTL << "Could not initialize PRT: " << prt::getStatusDescription(status); - } + &status)); + if (status != prt::STATUS_OK) { + LOG_FTL << "Could not initialize PRT: " << prt::getStatusDescription(status); + } } PRTContext::~PRTContext() { - mResolveMapCache.reset(); + mResolveMapCache.reset(); LOG_INF << "Released RPK Cache"; mPRTCache.reset(); // calling reset manually to ensure order @@ -208,11 +203,11 @@ PRTContext::~PRTContext() { mPRTHandle.reset(); // same here LOG_INF << "Shutdown PRT & returned license"; - prt::removeLogHandler(mLogHandler.get()); + prt::removeLogHandler(mLogHandler.get()); } namespace { - std::mutex mResolveMapCacheMutex; +std::mutex mResolveMapCacheMutex; } ResolveMapSPtr PRTContext::getResolveMap(const PLD_BOOST_NS::filesystem::path& rpk) { diff --git a/src/palladio/PRTContext.h b/src/palladio/PRTContext.h index c7af5054..8f9dc4ec 100644 --- a/src/palladio/PRTContext.h +++ b/src/palladio/PRTContext.h @@ -29,11 +29,10 @@ #include - namespace logging { class LogHandler; using LogHandlerPtr = std::unique_ptr; -} +} // namespace logging /** * manage PRT "lifetime" (actually, its license lifetime) @@ -47,13 +46,15 @@ struct PLD_TEST_EXPORTS_API PRTContext final { ~PRTContext(); ResolveMapSPtr getResolveMap(const PLD_BOOST_NS::filesystem::path& rpk); - bool isAlive() const { return mPRTHandle.operator bool(); } - - logging::LogHandlerPtr mLogHandler; - ObjectUPtr mPRTHandle; - CacheObjectUPtr mPRTCache; - const uint32_t mCores; - ResolveMapCacheUPtr mResolveMapCache; + bool isAlive() const { + return mPRTHandle.operator bool(); + } + + logging::LogHandlerPtr mLogHandler; + ObjectUPtr mPRTHandle; + CacheObjectUPtr mPRTCache; + const uint32_t mCores; + ResolveMapCacheUPtr mResolveMapCache; }; using PRTContextUPtr = std::unique_ptr; diff --git a/src/palladio/PalladioMain.cpp b/src/palladio/PalladioMain.cpp index ee45a510..faa061ef 100644 --- a/src/palladio/PalladioMain.cpp +++ b/src/palladio/PalladioMain.cpp @@ -16,10 +16,10 @@ #include "PalladioMain.h" +#include "NodeParameter.h" #include "PRTContext.h" #include "SOPAssign.h" #include "SOPGenerate.h" -#include "NodeParameter.h" #include "OP/OP_OperatorTable.h" #include "UT/UT_Exit.h" @@ -28,7 +28,6 @@ //#undef minor #include "UT/UT_DSOVersion.h" - namespace { // prt lifecycle @@ -36,29 +35,26 @@ PRTContextUPtr prtCtx; } // namespace - -void newSopOperator(OP_OperatorTable *table) { +void newSopOperator(OP_OperatorTable* table) { if (!prtCtx) { prtCtx.reset(new PRTContext()); - UT_Exit::addExitCallback([](void *) { prtCtx.reset(); }); + UT_Exit::addExitCallback([](void*) { prtCtx.reset(); }); } if (!prtCtx->isAlive()) return; // instantiate assign sop - auto createSOPAssign = [](OP_Network *net, const char *name, OP_Operator *op) -> OP_Node* { + auto createSOPAssign = [](OP_Network* net, const char* name, OP_Operator* op) -> OP_Node* { return new SOPAssign(prtCtx, net, name, op); }; - table->addOperator(new OP_Operator(OP_PLD_ASSIGN, OP_PLD_ASSIGN, createSOPAssign, - AssignNodeParams::PARAM_TEMPLATES, 1, 1, nullptr, OP_FLAG_GENERATOR - )); + table->addOperator(new OP_Operator(OP_PLD_ASSIGN, OP_PLD_ASSIGN, createSOPAssign, AssignNodeParams::PARAM_TEMPLATES, + 1, 1, nullptr, OP_FLAG_GENERATOR)); // instantiate generator sop - auto createSOPGenerate = [](OP_Network *net, const char *name, OP_Operator *op) -> OP_Node* { + auto createSOPGenerate = [](OP_Network* net, const char* name, OP_Operator* op) -> OP_Node* { return new SOPGenerate(prtCtx, net, name, op); }; table->addOperator(new OP_Operator(OP_PLD_GENERATE, OP_PLD_GENERATE, createSOPGenerate, - GenerateNodeParams::PARAM_TEMPLATES, 1, 1, nullptr, OP_FLAG_GENERATOR - )); + GenerateNodeParams::PARAM_TEMPLATES, 1, 1, nullptr, OP_FLAG_GENERATOR)); } diff --git a/src/palladio/PalladioMain.h b/src/palladio/PalladioMain.h index 1930080b..1259d6ab 100644 --- a/src/palladio/PalladioMain.h +++ b/src/palladio/PalladioMain.h @@ -23,8 +23,8 @@ # define PLD_TEST_EXPORTS_API # endif #else -# define PLD_TEST_EXPORTS_API __attribute__ ((visibility ("default"))) +# define PLD_TEST_EXPORTS_API __attribute__((visibility("default"))) #endif -constexpr const char* OP_PLD_ASSIGN = "pldAssign"; +constexpr const char* OP_PLD_ASSIGN = "pldAssign"; constexpr const char* OP_PLD_GENERATE = "pldGenerate"; diff --git a/src/palladio/PrimitiveClassifier.cpp b/src/palladio/PrimitiveClassifier.cpp index 7a39a33f..57b20cac 100644 --- a/src/palladio/PrimitiveClassifier.cpp +++ b/src/palladio/PrimitiveClassifier.cpp @@ -17,12 +17,12 @@ #include "PrimitiveClassifier.h" #include "NodeParameter.h" - PrimitiveClassifier::PrimitiveClassifier(SOP_Node* node, const GA_Detail* detail, const OP_Context& context) { get(node, detail, context); } -void PrimitiveClassifier::updateFromPrimitive(PrimitiveClassifier& derived, const GA_Detail* detail, const GA_Primitive* p) const { +void PrimitiveClassifier::updateFromPrimitive(PrimitiveClassifier& derived, const GA_Detail* detail, + const GA_Primitive* p) const { const GA_ROAttributeRef primClsAttrNameRef = detail->findPrimitiveAttribute(PLD_PRIM_CLS_NAME); if (primClsAttrNameRef.isValid()) { const GA_ROHandleS nameH(primClsAttrNameRef); diff --git a/src/palladio/PrimitiveClassifier.h b/src/palladio/PrimitiveClassifier.h index fe530790..cb59d9c9 100644 --- a/src/palladio/PrimitiveClassifier.h +++ b/src/palladio/PrimitiveClassifier.h @@ -16,18 +16,17 @@ #pragma once -#include "SOP/SOP_Node.h" -#include "OP/OP_Context.h" #include "GA/GA_Handle.h" #include "GA/GA_Types.h" +#include "OP/OP_Context.h" +#include "SOP/SOP_Node.h" #include "UT/UT_String.h" - const UT_String PLD_PRIM_CLS_NAME = "pldPrimClsName"; class PrimitiveClassifier { public: - UT_String name; + UT_String name; GA_RWHandleS clsAttrNameH; PrimitiveClassifier() = default; diff --git a/src/palladio/PrimitivePartition.cpp b/src/palladio/PrimitivePartition.cpp index 0159f8a8..6e3e2319 100644 --- a/src/palladio/PrimitivePartition.cpp +++ b/src/palladio/PrimitivePartition.cpp @@ -15,18 +15,16 @@ */ #include "PrimitivePartition.h" -#include "PrimitiveClassifier.h" #include "LogHandler.h" - +#include "PrimitiveClassifier.h" namespace { -constexpr bool DBG = false; +constexpr bool DBG = false; constexpr int32 INVALID_CLS_VALUE = -1; } // namespace - PrimitivePartition::PrimitivePartition(const GA_Detail* detail, const PrimitiveClassifier& primCls) { const GA_Primitive* prim = nullptr; GA_FOR_ALL_PRIMITIVES(detail, prim) { @@ -35,7 +33,8 @@ PrimitivePartition::PrimitivePartition(const GA_Detail* detail, const PrimitiveC } void PrimitivePartition::add(const GA_Detail* detail, const PrimitiveClassifier& primCls, const GA_Primitive* p) { - if (DBG) LOG_DBG << " adding prim: " << detail->primitiveIndex(p->getMapOffset()); + if (DBG) + LOG_DBG << " adding prim: " << detail->primitiveIndex(p->getMapOffset()); PrimitiveClassifier updatedPrimCls; primCls.updateFromPrimitive(updatedPrimCls, detail, p); @@ -49,24 +48,28 @@ void PrimitivePartition::add(const GA_Detail* detail, const PrimitiveClassifier& if (sc == GA_STORECLASS_STRING || sc == GA_STORECLASS_INT) primClsAttrRef = r; // we found the primitive classifier attribute itself else - LOG_WRN << "Ignoring primitive classifier '" << r->getName() << "', it is neither of type string or int"; + LOG_WRN << "Ignoring primitive classifier '" << r->getName() + << "', it is neither of type string or int"; } } // try to read actual attr value and classify primitive if (primClsAttrRef.isInvalid()) { mPrimitives[INVALID_CLS_VALUE].push_back(p); - if (DBG) LOG_DBG << " missing cls name: adding prim to fallback shape!"; + if (DBG) + LOG_DBG << " missing cls name: adding prim to fallback shape!"; } else if (primClsAttrRef.isInt()) { const GA_ROHandleI av(primClsAttrRef); if (av.isValid()) { const int32 v = av.get(p->getMapOffset()); - if (DBG) LOG_DBG << " got int classifier value: " << v; + if (DBG) + LOG_DBG << " got int classifier value: " << v; mPrimitives[v].push_back(p); } else { - if (DBG) LOG_DBG << " int: invalid handle!"; + if (DBG) + LOG_DBG << " int: invalid handle!"; } } else if (primClsAttrRef.isString()) { @@ -74,7 +77,8 @@ void PrimitivePartition::add(const GA_Detail* detail, const PrimitiveClassifier& if (av.isValid()) { const char* v = av.get(p->getMapOffset()); if (v) { - if (DBG) LOG_DBG << " got string classifier value: " << v; + if (DBG) + LOG_DBG << " got string classifier value: " << v; mPrimitives[UT_String(v)].push_back(p); } else { @@ -83,10 +87,12 @@ void PrimitivePartition::add(const GA_Detail* detail, const PrimitiveClassifier& } } else { - if (DBG) LOG_DBG << " string: invalid handle!"; + if (DBG) + LOG_DBG << " string: invalid handle!"; } } else { - if (DBG) LOG_DBG << " wrong type!"; + if (DBG) + LOG_DBG << " wrong type!"; } } diff --git a/src/palladio/PrimitivePartition.h b/src/palladio/PrimitivePartition.h index c68add95..e8a3b698 100644 --- a/src/palladio/PrimitivePartition.h +++ b/src/palladio/PrimitivePartition.h @@ -18,9 +18,9 @@ #include "NodeParameter.h" -#include "SOP/SOP_Node.h" #include "GA/GA_Primitive.h" #include "GU/GU_Detail.h" +#include "SOP/SOP_Node.h" // clang-format off #include "BoostRedirect.h" @@ -30,14 +30,13 @@ #include #include - class PrimitiveClassifier; class PrimitivePartition { public: using ClassifierValueType = PLD_BOOST_NS::variant; - using PrimitiveVector = std::vector; - using PartitionMap = std::map; + using PrimitiveVector = std::vector; + using PartitionMap = std::map; PartitionMap mPrimitives; diff --git a/src/palladio/ResolveMapCache.cpp b/src/palladio/ResolveMapCache.cpp index 7eabac60..ebc774fc 100644 --- a/src/palladio/ResolveMapCache.cpp +++ b/src/palladio/ResolveMapCache.cpp @@ -17,19 +17,18 @@ #include "ResolveMapCache.h" #include "LogHandler.h" -#include "UT/UT_IStream.h" #include "FS/FS_Reader.h" - +#include "UT/UT_IStream.h" namespace { const ResolveMapSPtr RESOLVE_MAP_NONE; -const ResolveMapCache::LookupResult LOOKUP_FAILURE = { RESOLVE_MAP_NONE, ResolveMapCache::CacheStatus::MISS }; +const ResolveMapCache::LookupResult LOOKUP_FAILURE = {RESOLVE_MAP_NONE, ResolveMapCache::CacheStatus::MISS}; const std::chrono::system_clock::time_point INVALID_TIMESTAMP; constexpr const char* SCHEMA_OPDEF = "opdef:"; constexpr const char* SCHEMA_OPLIB = "oplib:"; -const std::vector EMBEDDED_SCHEMAS = { SCHEMA_OPDEF, SCHEMA_OPLIB }; +const std::vector EMBEDDED_SCHEMAS = {SCHEMA_OPDEF, SCHEMA_OPLIB}; bool isEmbedded(const PLD_BOOST_NS::filesystem::path& p) { return startsWithAnyOf(p.string(), EMBEDDED_SCHEMAS); @@ -74,7 +73,7 @@ struct PathRemover { } } }; -using ScopedPath = std::unique_ptr; +using ScopedPath = std::unique_ptr; ScopedPath resolveFromHDA(const PLD_BOOST_NS::filesystem::path& p) { LOG_DBG << "detected embedded resource in HDA: " << p; @@ -85,7 +84,8 @@ ScopedPath resolveFromHDA(const PLD_BOOST_NS::filesystem::path& p) { auto resName = p.leaf().string(); std::replace(resName.begin(), resName.end(), '?', '_'); // TODO: generalize - ScopedPath extractedResource(new PLD_BOOST_NS::filesystem::path(PLD_BOOST_NS::filesystem::temp_directory_path() / resName)); + ScopedPath extractedResource( + new PLD_BOOST_NS::filesystem::path(PLD_BOOST_NS::filesystem::temp_directory_path() / resName)); if (fsr.isGood()) { UT_WorkBuffer wb; @@ -103,17 +103,17 @@ ScopedPath resolveFromHDA(const PLD_BOOST_NS::filesystem::path& p) { } // namespace - ResolveMapCache::~ResolveMapCache() { - PLD_BOOST_NS::filesystem::remove_all(mRPKUnpackPath); - LOG_INF << "Removed RPK unpack directory"; + PLD_BOOST_NS::filesystem::remove_all(mRPKUnpackPath); + LOG_INF << "Removed RPK unpack directory"; } ResolveMapCache::LookupResult ResolveMapCache::get(const PLD_BOOST_NS::filesystem::path& rpk) { const auto cacheKey = createCacheKey(rpk); const auto timeStamp = getFileModificationTime(rpk); - LOG_DBG << "rpk: current timestamp: " << std::chrono::duration_cast(timeStamp.time_since_epoch()).count() << "ns"; + LOG_DBG << "rpk: current timestamp: " + << std::chrono::duration_cast(timeStamp.time_since_epoch()).count() << "ns"; // verify timestamp if (timeStamp == INVALID_TIMESTAMP) @@ -122,11 +122,15 @@ ResolveMapCache::LookupResult ResolveMapCache::get(const PLD_BOOST_NS::filesyste CacheStatus cs = CacheStatus::HIT; auto it = mCache.find(cacheKey); if (it != mCache.end()) { - LOG_DBG << "rpk: cache timestamp: " << std::chrono::duration_cast(it->second.mTimeStamp.time_since_epoch()).count() << "ns"; + LOG_DBG << "rpk: cache timestamp: " + << std::chrono::duration_cast(it->second.mTimeStamp.time_since_epoch()) + .count() + << "ns"; if (it->second.mTimeStamp != timeStamp) { mCache.erase(it); const auto cnt = PLD_BOOST_NS::filesystem::remove_all(mRPKUnpackPath / rpk.leaf()); - LOG_INF << "RPK change detected, forcing reload and clearing cache for " << rpk << " (removed " << cnt << " files)"; + LOG_INF << "RPK change detected, forcing reload and clearing cache for " << rpk << " (removed " << cnt + << " files)"; cs = CacheStatus::MISS; } } @@ -151,7 +155,8 @@ ResolveMapCache::LookupResult ResolveMapCache::get(const PLD_BOOST_NS::filesyste prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; LOG_DBG << "createResolveMap from " << rpkURI; - rmce.mResolveMap.reset(prt::createResolveMap(rpkURI.c_str(), mRPKUnpackPath.wstring().c_str(), &status), PRTDestroyer()); + rmce.mResolveMap.reset(prt::createResolveMap(rpkURI.c_str(), mRPKUnpackPath.wstring().c_str(), &status), + PRTDestroyer()); if (status != prt::STATUS_OK) return LOOKUP_FAILURE; @@ -159,6 +164,5 @@ ResolveMapCache::LookupResult ResolveMapCache::get(const PLD_BOOST_NS::filesyste LOG_INF << "Upacked RPK " << actualRPK << " to " << mRPKUnpackPath; } - return { it->second.mResolveMap, cs }; + return {it->second.mResolveMap, cs}; } - diff --git a/src/palladio/ResolveMapCache.h b/src/palladio/ResolveMapCache.h index f7a1edcc..d7ce9657 100644 --- a/src/palladio/ResolveMapCache.h +++ b/src/palladio/ResolveMapCache.h @@ -26,12 +26,11 @@ #include #include - class ResolveMapCache { public: using KeyType = std::string; - explicit ResolveMapCache(const PLD_BOOST_NS::filesystem::path& unpackPath) : mRPKUnpackPath{unpackPath} { } + explicit ResolveMapCache(const PLD_BOOST_NS::filesystem::path& unpackPath) : mRPKUnpackPath{unpackPath} {} ResolveMapCache(const ResolveMapCache&) = delete; ResolveMapCache(ResolveMapCache&&) = delete; ResolveMapCache& operator=(ResolveMapCache const&) = delete; diff --git a/src/palladio/SOPAssign.cpp b/src/palladio/SOPAssign.cpp index c7bb3bec..02b44eb2 100644 --- a/src/palladio/SOPAssign.cpp +++ b/src/palladio/SOPAssign.cpp @@ -16,13 +16,13 @@ #include "SOPAssign.h" #include "AttrEvalCallbacks.h" -#include "PrimitiveClassifier.h" -#include "ShapeGenerator.h" -#include "ShapeData.h" -#include "ModelConverter.h" -#include "NodeParameter.h" #include "LogHandler.h" +#include "ModelConverter.h" #include "MultiWatch.h" +#include "NodeParameter.h" +#include "PrimitiveClassifier.h" +#include "ShapeData.h" +#include "ShapeGenerator.h" #include "prt/API.h" @@ -35,7 +35,7 @@ namespace { -constexpr bool DBG = false; +constexpr bool DBG = false; constexpr const wchar_t* ENCODER_ID_CGA_EVALATTR = L"com.esri.prt.core.AttributeEvalEncoder"; AttributeMapUPtr getValidEncoderInfo(const wchar_t* encID) { @@ -61,21 +61,17 @@ RuleFileInfoUPtr getRuleFileInfo(const MainAttributes& ma, const ResolveMapSPtr& return rfi; } -bool evaluateDefaultRuleAttributes( - const GU_Detail* detail, - ShapeData& shapeData, - const ShapeConverterUPtr& shapeConverter, - const PRTContextUPtr& prtCtx -) { +bool evaluateDefaultRuleAttributes(const GU_Detail* detail, ShapeData& shapeData, + const ShapeConverterUPtr& shapeConverter, const PRTContextUPtr& prtCtx) { WA("all"); assert(shapeData.isValid()); // setup encoder options for attribute evaluation encoder - constexpr const wchar_t* encs[] = { ENCODER_ID_CGA_EVALATTR }; + constexpr const wchar_t* encs[] = {ENCODER_ID_CGA_EVALATTR}; constexpr size_t encsCount = sizeof(encs) / sizeof(encs[0]); const AttributeMapUPtr encOpts = getValidEncoderInfo(ENCODER_ID_CGA_EVALATTR); - const prt::AttributeMap* encsOpts[] = { encOpts.get() }; + const prt::AttributeMap* encsOpts[] = {encOpts.get()}; const size_t numShapes = shapeData.getInitialShapeBuilders().size(); @@ -93,27 +89,24 @@ bool evaluateDefaultRuleAttributes( // try to get a resolve map ResolveMapSPtr resolveMap = prtCtx->getResolveMap(ma.mRPK); if (!resolveMap) { - LOG_WRN << "Could not create resolve map from rpk " << ma.mRPK << ", aborting default rule attribute evaluation"; + LOG_WRN << "Could not create resolve map from rpk " << ma.mRPK + << ", aborting default rule attribute evaluation"; return false; } ruleFileInfos[isIdx] = getRuleFileInfo(ma, resolveMap, prtCtx->mPRTCache.get()); const std::wstring shapeName = L"shape_" + std::to_wstring(isIdx); - if (DBG) LOG_DBG << "evaluating attrs for shape: " << shapeName; + if (DBG) + LOG_DBG << "evaluating attrs for shape: " << shapeName; // persist rule attributes even if empty (need to live until prt::generate is done) AttributeMapBuilderUPtr amb(prt::AttributeMapBuilder::create()); AttributeMapUPtr ruleAttr(amb->createAttributeMap()); auto& isb = shapeData.getInitialShapeBuilder(isIdx); - isb->setAttributes( - ma.mRuleFile.c_str(), - ma.mStartRule.c_str(), - shapeData.getInitialShapeRandomSeed(isIdx), - shapeName.c_str(), - ruleAttr.get(), - resolveMap.get()); + isb->setAttributes(ma.mRuleFile.c_str(), ma.mStartRule.c_str(), shapeData.getInitialShapeRandomSeed(isIdx), + shapeName.c_str(), ruleAttr.get(), resolveMap.get()); prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; const prt::InitialShape* initialShape = isb->createInitialShapeAndReset(&status); @@ -131,7 +124,8 @@ bool evaluateDefaultRuleAttributes( const prt::Status stat = prt::generate(is.data(), is.size(), nullptr, encs, encsCount, encsOpts, &aec, prtCtx->mPRTCache.get(), nullptr, nullptr, nullptr); if (stat != prt::STATUS_OK) { - LOG_ERR << "assign: prt::generate() failed with status: '" << prt::getStatusDescription(stat) << "' (" << stat << ")"; + LOG_ERR << "assign: prt::generate() failed with status: '" << prt::getStatusDescription(stat) << "' (" << stat + << ")"; } assert(shapeData.isValid()); @@ -141,9 +135,8 @@ bool evaluateDefaultRuleAttributes( } // namespace - SOPAssign::SOPAssign(const PRTContextUPtr& pCtx, OP_Network* net, const char* name, OP_Operator* op) -: SOP_Node(net, name, op), mPRTCtx(pCtx), mShapeConverter(new ShapeConverter()) { } + : SOP_Node(net, name, op), mPRTCtx(pCtx), mShapeConverter(new ShapeConverter()) {} OP_ERROR SOPAssign::cookMySop(OP_Context& context) { WA_NEW_LAP @@ -176,10 +169,10 @@ OP_ERROR SOPAssign::cookMySop(OP_Context& context) { return error(); } -void SOPAssign::opChanged(OP_EventType reason, void *data) { - SOP_Node::opChanged(reason, data); +void SOPAssign::opChanged(OP_EventType reason, void* data) { + SOP_Node::opChanged(reason, data); - // trigger recook on name change, we use the node name in various output places - if (reason == OP_NAME_CHANGED) - forceRecook(); + // trigger recook on name change, we use the node name in various output places + if (reason == OP_NAME_CHANGED) + forceRecook(); } diff --git a/src/palladio/SOPAssign.h b/src/palladio/SOPAssign.h index ed8a258b..33b0524a 100644 --- a/src/palladio/SOPAssign.h +++ b/src/palladio/SOPAssign.h @@ -21,14 +21,17 @@ #include "SOP/SOP_Node.h" - class SOPAssign : public SOP_Node { public: - SOPAssign(const PRTContextUPtr& pCtx, OP_Network *net, const char *name, OP_Operator *op); + SOPAssign(const PRTContextUPtr& pCtx, OP_Network* net, const char* name, OP_Operator* op); ~SOPAssign() override = default; - const PRTContextUPtr& getPRTCtx() const { return mPRTCtx; } - const PLD_BOOST_NS::filesystem::path& getRPK() const { return mShapeConverter->mDefaultMainAttributes.mRPK; } + const PRTContextUPtr& getPRTCtx() const { + return mPRTCtx; + } + const PLD_BOOST_NS::filesystem::path& getRPK() const { + return mShapeConverter->mDefaultMainAttributes.mRPK; + } void opChanged(OP_EventType reason, void* data = nullptr) override; @@ -37,5 +40,5 @@ class SOPAssign : public SOP_Node { private: const PRTContextUPtr& mPRTCtx; - ShapeConverterUPtr mShapeConverter; + ShapeConverterUPtr mShapeConverter; }; diff --git a/src/palladio/SOPGenerate.cpp b/src/palladio/SOPGenerate.cpp index 5a213b35..073a1ae3 100644 --- a/src/palladio/SOPGenerate.cpp +++ b/src/palladio/SOPGenerate.cpp @@ -15,23 +15,22 @@ */ #include "SOPGenerate.h" -#include "NodeParameter.h" -#include "ShapeGenerator.h" -#include "ShapeData.h" -#include "PrimitiveClassifier.h" #include "ModelConverter.h" #include "MultiWatch.h" +#include "NodeParameter.h" +#include "PrimitiveClassifier.h" +#include "ShapeData.h" +#include "ShapeGenerator.h" #include "UT/UT_Interrupt.h" -#include #include - +#include namespace { -constexpr const wchar_t* FILE_CGA_ERROR = L"CGAErrors.txt"; -constexpr const wchar_t* FILE_CGA_PRINT = L"CGAPrint.txt"; +constexpr const wchar_t* FILE_CGA_ERROR = L"CGAErrors.txt"; +constexpr const wchar_t* FILE_CGA_PRINT = L"CGAPrint.txt"; constexpr const wchar_t* ENCODER_ID_CGA_ERROR = L"com.esri.prt.core.CGAErrorEncoder"; constexpr const wchar_t* ENCODER_ID_CGA_PRINT = L"com.esri.prt.core.CGAPrintEncoder"; @@ -40,10 +39,8 @@ const PrimitiveClassifier DEFAULT_PRIMITIVE_CLASSIFIER; } // namespace - SOPGenerate::SOPGenerate(const PRTContextUPtr& pCtx, OP_Network* net, const char* name, OP_Operator* op) -: SOP_Node(net, name, op), mPRTCtx(pCtx) -{ + : SOP_Node(net, name, op), mPRTCtx(pCtx) { AttributeMapBuilderUPtr optionsBuilder(prt::AttributeMapBuilder::create()); optionsBuilder->setString(L"name", FILE_CGA_ERROR); @@ -62,8 +59,8 @@ SOPGenerate::SOPGenerate(const PRTContextUPtr& pCtx, OP_Network* net, const char bool SOPGenerate::handleParams(OP_Context& context) { const auto now = context.getTime(); const bool emitAttributes = (evalInt(GenerateNodeParams::EMIT_ATTRS.getToken(), 0, now) > 0); - const bool emitMaterial = (evalInt(GenerateNodeParams::EMIT_MATERIAL.getToken(), 0, now) > 0); - const bool emitReports = (evalInt(GenerateNodeParams::EMIT_REPORTS.getToken(), 0, now) > 0); + const bool emitMaterial = (evalInt(GenerateNodeParams::EMIT_MATERIAL.getToken(), 0, now) > 0); + const bool emitReports = (evalInt(GenerateNodeParams::EMIT_REPORTS.getToken(), 0, now) > 0); AttributeMapBuilderUPtr optionsBuilder(prt::AttributeMapBuilder::create()); optionsBuilder->setBool(EO_EMIT_ATTRIBUTES, emitAttributes); @@ -74,8 +71,8 @@ bool SOPGenerate::handleParams(OP_Context& context) { if (!mHoudiniEncoderOptions) return false; - mAllEncoders = { ENCODER_ID_HOUDINI, ENCODER_ID_CGA_ERROR, ENCODER_ID_CGA_PRINT }; - mAllEncoderOptions = { mHoudiniEncoderOptions.get(), mCGAErrorOptions.get(), mCGAPrintOptions.get() }; + mAllEncoders = {ENCODER_ID_HOUDINI, ENCODER_ID_CGA_ERROR, ENCODER_ID_CGA_PRINT}; + mAllEncoderOptions = {mHoudiniEncoderOptions.get(), mCGAErrorOptions.get(), mCGAPrintOptions.get()}; return true; } @@ -83,26 +80,21 @@ bool SOPGenerate::handleParams(OP_Context& context) { namespace { enum class BatchMode { OCCLUSION, GENERATION }; -const std::vector BATCH_MODE_NAMES = { "occlusion", "generation" }; +const std::vector BATCH_MODE_NAMES = {"occlusion", "generation"}; -std::vector batchGenerate(BatchMode mode, - size_t nThreads, - std::vector& hg, - size_t isRangeSize, - const InitialShapeNOPtrVector& is, +std::vector batchGenerate(BatchMode mode, size_t nThreads, std::vector& hg, + size_t isRangeSize, const InitialShapeNOPtrVector& is, const std::vector& allEncoders, const AttributeMapNOPtrVector& allEncoderOptions, std::vector& occlusionHandles, - OcclusionSetUPtr& occlusionSet, - CacheObjectUPtr& prtCache, - const AttributeMapUPtr& genOpts) -{ + OcclusionSetUPtr& occlusionSet, CacheObjectUPtr& prtCache, + const AttributeMapUPtr& genOpts) { std::vector batchStatus(nThreads, prt::STATUS_UNSPECIFIED_ERROR); std::vector> futures; futures.reserve(nThreads); for (int8_t ti = 0; ti < nThreads; ti++) { - auto f = std::async(std::launch::async, [&,ti] { // capture thread index by value, else we have is range chaos + auto f = std::async(std::launch::async, [&, ti] { // capture thread index by value, else we have is range chaos const size_t isStartPos = ti * isRangeSize; const size_t isPastEndPos = (ti < nThreads - 1) ? (ti + 1) * isRangeSize : is.size(); const size_t isActualRangeSize = isPastEndPos - isStartPos; @@ -113,8 +105,8 @@ std::vector batchGenerate(BatchMode mode, switch (mode) { case BatchMode::OCCLUSION: { - batchStatus[ti] = prt::generateOccluders(isRangeStart, isActualRangeSize, isOcclRangeStart, - nullptr, 0, nullptr, hg[ti].get(), prtCache.get(), + batchStatus[ti] = prt::generateOccluders(isRangeStart, isActualRangeSize, isOcclRangeStart, nullptr, + 0, nullptr, hg[ti].get(), prtCache.get(), occlusionSet.get(), genOpts.get()); break; } @@ -127,9 +119,8 @@ std::vector batchGenerate(BatchMode mode, } if (batchStatus[ti] != prt::STATUS_OK) { - LOG_WRN << "batch mode " << BATCH_MODE_NAMES[(int)mode] << " failed with status: '" - << prt::getStatusDescription(batchStatus[ti]) << "' (" - << batchStatus[ti] << ")"; + LOG_WRN << "batch mode " << BATCH_MODE_NAMES[(int)mode] << " failed with status: '" + << prt::getStatusDescription(batchStatus[ti]) << "' (" << batchStatus[ti] << ")"; } }); @@ -184,15 +175,17 @@ OP_ERROR SOPGenerate::cookMySop(OP_Context& context) { // prt requires one callback instance per generate call std::vector hg(nThreads); - std::generate(hg.begin(), hg.end(), [this, &groupCreation, &initialShapeStatus, &progress]() -> ModelConverterUPtr { - return ModelConverterUPtr(new ModelConverter(gdp, groupCreation, initialShapeStatus, &progress)); - }); + std::generate(hg.begin(), hg.end(), + [this, &groupCreation, &initialShapeStatus, &progress]() -> ModelConverterUPtr { + return ModelConverterUPtr( + new ModelConverter(gdp, groupCreation, initialShapeStatus, &progress)); + }); std::vector occlusionHandles(is.size()); OcclusionSetUPtr occlusionSet{prt::OcclusionSet::create()}; - LOG_INF << getName() << ": calling generate: #initial shapes = " << is.size() << ", #threads = " - << nThreads << ", initial shapes per thread = " << isRangeSize; + LOG_INF << getName() << ": calling generate: #initial shapes = " << is.size() << ", #threads = " << nThreads + << ", initial shapes per thread = " << isRangeSize; batchGenerate(BatchMode::OCCLUSION, nThreads, hg, isRangeSize, is, mAllEncoders, mAllEncoderOptions, occlusionHandles, occlusionSet, mPRTCtx->mPRTCache, mGenerateOptions); @@ -221,10 +214,10 @@ OP_ERROR SOPGenerate::cookMySop(OP_Context& context) { return error(); } -void SOPGenerate::opChanged(OP_EventType reason, void *data) { - SOP_Node::opChanged(reason, data); +void SOPGenerate::opChanged(OP_EventType reason, void* data) { + SOP_Node::opChanged(reason, data); - // trigger recook on name change, we use the node name in various output places - if (reason == OP_NAME_CHANGED) - forceRecook(); + // trigger recook on name change, we use the node name in various output places + if (reason == OP_NAME_CHANGED) + forceRecook(); } diff --git a/src/palladio/SOPGenerate.h b/src/palladio/SOPGenerate.h index ac78b82b..488ffb0f 100644 --- a/src/palladio/SOPGenerate.h +++ b/src/palladio/SOPGenerate.h @@ -16,34 +16,33 @@ #pragma once +#include "LogHandler.h" #include "PRTContext.h" #include "ShapeConverter.h" -#include "LogHandler.h" #include "Utils.h" #include "SOP/SOP_Node.h" - class SOPGenerate : public SOP_Node { public: - SOPGenerate(const PRTContextUPtr& pCtx, OP_Network *net, const char *name, OP_Operator *op); + SOPGenerate(const PRTContextUPtr& pCtx, OP_Network* net, const char* name, OP_Operator* op); ~SOPGenerate() override = default; void opChanged(OP_EventType reason, void* data = nullptr) override; protected: - OP_ERROR cookMySop(OP_Context &context) override; + OP_ERROR cookMySop(OP_Context& context) override; private: bool handleParams(OP_Context& context); private: - const PRTContextUPtr& mPRTCtx; + const PRTContextUPtr& mPRTCtx; - AttributeMapUPtr mHoudiniEncoderOptions; - AttributeMapUPtr mCGAPrintOptions; - AttributeMapUPtr mCGAErrorOptions; + AttributeMapUPtr mHoudiniEncoderOptions; + AttributeMapUPtr mCGAPrintOptions; + AttributeMapUPtr mCGAErrorOptions; std::vector mAllEncoders; - AttributeMapNOPtrVector mAllEncoderOptions; - AttributeMapUPtr mGenerateOptions; + AttributeMapNOPtrVector mAllEncoderOptions; + AttributeMapUPtr mGenerateOptions; }; diff --git a/src/palladio/ShapeConverter.cpp b/src/palladio/ShapeConverter.cpp index 9b1c8806..d3263c8d 100644 --- a/src/palladio/ShapeConverter.cpp +++ b/src/palladio/ShapeConverter.cpp @@ -15,15 +15,15 @@ */ #include "ShapeConverter.h" -#include "ShapeData.h" -#include "PrimitiveClassifier.h" #include "AttributeConversion.h" #include "LogHandler.h" #include "MultiWatch.h" +#include "PrimitiveClassifier.h" +#include "ShapeData.h" -#include "GU/GU_Detail.h" #include "GA/GA_PageHandle.h" #include "GEO/GEO_PrimPolySoup.h" +#include "GU/GU_Detail.h" #include "UT/UT_String.h" // clang-format off @@ -46,7 +46,7 @@ struct ConversionHelper { std::vector indices; std::vector faceCounts; std::vector holes; - std::vector uvSets; + std::vector uvSets; const std::vector& coords; const std::vector& uvHandles; @@ -58,13 +58,14 @@ struct ConversionHelper { InitialShapeBuilderUPtr createInitialShape() const { InitialShapeBuilderUPtr isb(prt::InitialShapeBuilder::create()); - isb->setGeometry(coords.data(), coords.size(), indices.data(), indices.size(), - faceCounts.data(), faceCounts.size(), holes.data(), holes.size()); + isb->setGeometry(coords.data(), coords.size(), indices.data(), indices.size(), faceCounts.data(), + faceCounts.size(), holes.data(), holes.size()); for (size_t u = 0; u < uvHandles.size(); u++) { const auto& uvSet = uvSets[u]; if (!uvHandles[u].isInvalid() && !uvSet.uvs.empty()) { - isb->setUVs(uvSet.uvs.data(), uvSet.uvs.size(), uvSet.idx.data(), uvSet.idx.size(), faceCounts.data(), faceCounts.size(), u); + isb->setUVs(uvSet.uvs.data(), uvSet.uvs.size(), uvSet.idx.data(), uvSet.idx.size(), faceCounts.data(), + faceCounts.size(), u); } } @@ -73,14 +74,15 @@ struct ConversionHelper { }; // transfer texture coordinates -const std::vector UV_ATTR_NAMES{ - "uv", "uv1", "uv2", "uv3", "uv4", "uv5" +const std::vector UV_ATTR_NAMES { + "uv", "uv1", "uv2", "uv3", "uv4", "uv5" #if PRT_VERSION_MAJOR > 1 - , "uv6", "uv7", "uv8", "uv9" + , + "uv6", "uv7", "uv8", "uv9" #endif }; -template +template void convertPolygon(ConversionHelper& ch, const P& p, const std::vector& uvHandles) { const GA_Size vtxCnt = p.getVertexCount(); @@ -88,7 +90,8 @@ void convertPolygon(ConversionHelper& ch, const P& p, const std::vector= 0; i--) { ch.indices.push_back(static_cast(p.getPointIndex(i))); - if (DBG) LOG_DBG << " vtx " << i << ": point idx = " << p.getPointIndex(i); + if (DBG) + LOG_DBG << " vtx " << i << ": point idx = " << p.getPointIndex(i); } for (size_t u = 0; u < uvHandles.size(); u++) { @@ -104,22 +107,23 @@ void convertPolygon(ConversionHelper& ch, const P& p, const std::vector getCentroid(const std::vector& coords, const ConversionHelper& ch) { - std::array centroid = { 0.0, 0.0, 0.0 }; + std::array centroid = {0.0, 0.0, 0.0}; for (size_t i = 0; i < ch.indices.size(); i++) { auto idx = ch.indices[i]; centroid[0] += coords[3 * idx + 0]; centroid[1] += coords[3 * idx + 1]; centroid[2] += coords[3 * idx + 2]; } - centroid[0] /= (double) ch.indices.size(); - centroid[1] /= (double) ch.indices.size(); - centroid[2] /= (double) ch.indices.size(); + centroid[0] /= (double)ch.indices.size(); + centroid[1] /= (double)ch.indices.size(); + centroid[2] /= (double)ch.indices.size(); return centroid; } @@ -168,14 +172,14 @@ struct MainAttributeHandles { GA_RWAttributeRef styleRef(detail->addStringTuple(GA_ATTRIB_PRIMITIVE, PLD_STYLE, 1)); style.bind(styleRef); - GA_RWAttributeRef seedRef(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, PLD_RANDOM_SEED, 1, GA_Defaults(0), nullptr, nullptr, GA_STORE_INT32)); + GA_RWAttributeRef seedRef(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, PLD_RANDOM_SEED, 1, GA_Defaults(0), nullptr, + nullptr, GA_STORE_INT32)); seed.bind(seedRef); } }; -void ShapeConverter::get(const GU_Detail* detail, const PrimitiveClassifier& primCls, - ShapeData& shapeData, const PRTContextUPtr& prtCtx) -{ +void ShapeConverter::get(const GU_Detail* detail, const PrimitiveClassifier& primCls, ShapeData& shapeData, + const PRTContextUPtr& prtCtx) { WA("all"); assert(shapeData.isValid()); @@ -187,11 +191,12 @@ void ShapeConverter::get(const GU_Detail* detail, const PrimitiveClassifier& pri // -- copy all coordinates std::vector coords; assert(detail->getPointRange().getEntries() == detail->getNumPoints()); - coords.reserve(detail->getNumPoints()*3); + coords.reserve(detail->getNumPoints() * 3); GA_Offset ptoff; GA_FOR_ALL_PTOFF(detail, ptoff) { const UT_Vector3 p = detail->getPos3(ptoff); - if (DBG) LOG_DBG << "coords " << coords.size()/3 << ": " << p.x() << ", " << p.y() << ", " << p.z(); + if (DBG) + LOG_DBG << "coords " << coords.size() / 3 << ": " << p.x() << ", " << p.y() << ", " << p.z(); coords.push_back(static_cast(p.x())); coords.push_back(static_cast(p.y())); coords.push_back(static_cast(p.z())); @@ -200,33 +205,38 @@ void ShapeConverter::get(const GU_Detail* detail, const PrimitiveClassifier& pri // scan for uv attributes std::vector uvHandles(UV_ATTR_NAMES.size()); for (uint32_t uvSet = 0; uvSet < UV_ATTR_NAMES.size(); uvSet++) { - const std::string &attrName = UV_ATTR_NAMES[uvSet]; - const GA_Attribute *attrib = detail->findFloatTuple(GA_ATTRIB_VERTEX, attrName, 2); + const std::string& attrName = UV_ATTR_NAMES[uvSet]; + const GA_Attribute* attrib = detail->findFloatTuple(GA_ATTRIB_VERTEX, attrName, 2); uvHandles[uvSet].bind(attrib); } // -- loop over all primitive partitions and create shape builders uint32_t isIdx = 0; for (auto pIt = partitions.cbegin(); pIt != partitions.cend(); ++pIt, ++isIdx) { - if (DBG) LOG_DBG << " -- creating initial shape " << isIdx << ", prim count = " << pIt->second.size(); + if (DBG) + LOG_DBG << " -- creating initial shape " << isIdx << ", prim count = " << pIt->second.size(); ConversionHelper ch(coords, uvHandles); // merge primitive geometry inside partition (potential multi-polygon initial shape) - for (const auto& prim: pIt->second) { - if (DBG) LOG_DBG << " -- prim index " << prim->getMapIndex() << ", type: " << prim->getTypeName() << ", id = " << prim->getTypeId().get(); + for (const auto& prim : pIt->second) { + if (DBG) + LOG_DBG << " -- prim index " << prim->getMapIndex() << ", type: " << prim->getTypeName() + << ", id = " << prim->getTypeId().get(); const auto& primType = prim->getTypeId(); switch (primType.get()) { case GA_PRIMPOLY: convertPolygon(ch, *prim, uvHandles); break; case GA_PRIMPOLYSOUP: - for (GEO_PrimPolySoup::PolygonIterator pit(static_cast(*prim)); !pit.atEnd(); ++pit) { + for (GEO_PrimPolySoup::PolygonIterator pit(static_cast(*prim)); + !pit.atEnd(); ++pit) { convertPolygon(ch, pit, uvHandles); } break; default: - if (DBG) LOG_DBG << " ignoring primitive of type " << prim->getTypeName(); + if (DBG) + LOG_DBG << " ignoring primitive of type " << prim->getTypeName(); break; } } // for each primitive @@ -251,36 +261,36 @@ void ShapeConverter::put(GU_Detail* detail, PrimitiveClassifier& primCls, const const auto& pv = shapeData.getPrimitiveMapping(isIdx); const int32_t randomSeed = shapeData.getInitialShapeRandomSeed(isIdx); - for (auto& prim: pv) { + for (auto& prim : pv) { primCls.put(prim); putMainAttributes(detail, mah, prim); const GA_Offset& off = prim->getMapOffset(); mah.seed.set(off, randomSeed); } // for all primitives in initial shape - } // for all initial shapes + } // for all initial shapes } void ShapeConverter::getMainAttributes(SOP_Node* node, const OP_Context& context) { const fpreal now = context.getTime(); - mDefaultMainAttributes.mRPK = AssignNodeParams::getRPK(node, now); - mDefaultMainAttributes.mRuleFile = AssignNodeParams::getRuleFile(node, now); - mDefaultMainAttributes.mStyle = AssignNodeParams::getStyle(node, now); + mDefaultMainAttributes.mRPK = AssignNodeParams::getRPK(node, now); + mDefaultMainAttributes.mRuleFile = AssignNodeParams::getRuleFile(node, now); + mDefaultMainAttributes.mStyle = AssignNodeParams::getStyle(node, now); mDefaultMainAttributes.mStartRule = AssignNodeParams::getStartRule(node, now); } namespace { -template +template T convert(const UT_StringHolder& s) { return T{s.toStdString()}; } -template<> +template <> std::wstring convert(const UT_StringHolder& s) { return toUTF16FromOSNarrow(s.toStdString()); } -template +template void tryAssign(T& v, const GA_ROAttributeRef& ref, const GA_Offset& off) { if (ref.isInvalid()) return; @@ -314,7 +324,8 @@ MainAttributes ShapeConverter::getMainAttributesFromPrimitive(const GU_Detail* d return ma; } -void ShapeConverter::putMainAttributes(const GU_Detail* detail, MainAttributeHandles& mah, const GA_Primitive* primitive) const { +void ShapeConverter::putMainAttributes(const GU_Detail* detail, MainAttributeHandles& mah, + const GA_Primitive* primitive) const { MainAttributes ma = getMainAttributesFromPrimitive(detail, primitive); const GA_Offset& off = primitive->getMapOffset(); diff --git a/src/palladio/ShapeConverter.h b/src/palladio/ShapeConverter.h index c633d362..72dfd309 100644 --- a/src/palladio/ShapeConverter.h +++ b/src/palladio/ShapeConverter.h @@ -28,7 +28,6 @@ #include - class GU_Detail; class GA_Primitive; class OP_Context; @@ -37,25 +36,25 @@ class PrimitiveClassifier; class MainAttributeHandles; class ShapeData; -const UT_String PLD_RPK = "pldRPK"; -const UT_String PLD_RULE_FILE = "pldRuleFile"; -const UT_String PLD_START_RULE = "pldStartRule"; -const UT_String PLD_STYLE = "pldStyle"; +const UT_String PLD_RPK = "pldRPK"; +const UT_String PLD_RULE_FILE = "pldRuleFile"; +const UT_String PLD_START_RULE = "pldStartRule"; +const UT_String PLD_STYLE = "pldStyle"; const UT_String PLD_RANDOM_SEED = "pldRandomSeed"; enum class GroupCreation { NONE, PRIMCLS }; struct MainAttributes { PLD_BOOST_NS::filesystem::path mRPK; - std::wstring mRuleFile; - std::wstring mStyle; - std::wstring mStartRule; + std::wstring mRuleFile; + std::wstring mStyle; + std::wstring mStartRule; }; class ShapeConverter { public: - virtual void get(const GU_Detail* detail, const PrimitiveClassifier& primCls, - ShapeData& shapeData, const PRTContextUPtr& prtCtx); + virtual void get(const GU_Detail* detail, const PrimitiveClassifier& primCls, ShapeData& shapeData, + const PRTContextUPtr& prtCtx); void put(GU_Detail* detail, PrimitiveClassifier& primCls, const ShapeData& shapeData) const; void getMainAttributes(SOP_Node* node, const OP_Context& context); // TODO: integrate into get @@ -67,4 +66,3 @@ class ShapeConverter { }; using ShapeConverterUPtr = std::unique_ptr; - diff --git a/src/palladio/ShapeData.cpp b/src/palladio/ShapeData.cpp index 7fe9d398..07833b52 100644 --- a/src/palladio/ShapeData.cpp +++ b/src/palladio/ShapeData.cpp @@ -16,31 +16,30 @@ #include "ShapeData.h" - namespace { -const std::wstring DEFAULT_SHAPE_NAME = L"pldShape"; +const std::wstring DEFAULT_SHAPE_NAME = L"pldShape"; const std::wstring GROUP_NAME_LEGAL_CHARS = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789"; -const std::wstring INVALID_GROUP_NAME = L"_invalid_"; +const std::wstring INVALID_GROUP_NAME = L"_invalid_"; /** * creates initial shape and primitive group name from primitive classifier value */ class NameFromPrimPart : public PLD_BOOST_NS::static_visitor<> { public: - NameFromPrimPart(std::wstring& name, const std::wstring& prefix) : mName(name), mPrefix(prefix) { } + NameFromPrimPart(std::wstring& name, const std::wstring& prefix) : mName(name), mPrefix(prefix) {} - void operator()(const UT_String& s) { - mName.assign(toUTF16FromOSNarrow(s.toStdString())); - replace_all_not_of(mName, GROUP_NAME_LEGAL_CHARS); - if (mName.empty()) // handle empty primCls string value - mName.assign(INVALID_GROUP_NAME); - } + void operator()(const UT_String& s) { + mName.assign(toUTF16FromOSNarrow(s.toStdString())); + replace_all_not_of(mName, GROUP_NAME_LEGAL_CHARS); + if (mName.empty()) // handle empty primCls string value + mName.assign(INVALID_GROUP_NAME); + } - void operator()(const int32& i) { - mName.assign(mPrefix).append(L"_").append(std::to_wstring(i)); - replace_all_not_of(mName, GROUP_NAME_LEGAL_CHARS); - } + void operator()(const int32& i) { + mName.assign(mPrefix).append(L"_").append(std::to_wstring(i)); + replace_all_not_of(mName, GROUP_NAME_LEGAL_CHARS); + } private: std::wstring& mName; @@ -49,18 +48,15 @@ class NameFromPrimPart : public PLD_BOOST_NS::static_visitor<> { } // namespace - ShapeData::~ShapeData() { - std::for_each(mInitialShapes.begin(), mInitialShapes.end(), [](const prt::InitialShape* is){ + std::for_each(mInitialShapes.begin(), mInitialShapes.end(), [](const prt::InitialShape* is) { if (is) is->destroy(); }); } -void ShapeData::addBuilder(InitialShapeBuilderUPtr&& isb, int32_t randomSeed, - const PrimitiveNOPtrVector& primMappings, - const PrimitivePartition::ClassifierValueType& clsVal) -{ +void ShapeData::addBuilder(InitialShapeBuilderUPtr&& isb, int32_t randomSeed, const PrimitiveNOPtrVector& primMappings, + const PrimitivePartition::ClassifierValueType& clsVal) { mInitialShapeBuilders.emplace_back(std::move(isb)); mRandomSeeds.push_back(randomSeed); mPrimitiveMapping.emplace_back(primMappings); diff --git a/src/palladio/ShapeData.h b/src/palladio/ShapeData.h index 748f885b..9da2ae6e 100644 --- a/src/palladio/ShapeData.h +++ b/src/palladio/ShapeData.h @@ -16,15 +16,14 @@ #pragma once -#include "PrimitivePartition.h" #include "NodeParameter.h" +#include "PrimitivePartition.h" #include "Utils.h" - class ShapeData final { public: ShapeData() = default; - ShapeData(const GroupCreation& gc, const std::wstring& namePrefix) : mGroupCreation(gc), mNamePrefix(namePrefix) { } + ShapeData(const GroupCreation& gc, const std::wstring& namePrefix) : mGroupCreation(gc), mNamePrefix(namePrefix) {} ShapeData(const ShapeData&) = delete; ShapeData(ShapeData&&) = delete; ~ShapeData(); @@ -34,31 +33,45 @@ class ShapeData final { void addShape(const prt::InitialShape* is, AttributeMapBuilderUPtr&& amb, AttributeMapUPtr&& ruleAttr); - InitialShapeBuilderVector& getInitialShapeBuilders() { return mInitialShapeBuilders; } - int32_t getInitialShapeRandomSeed(size_t isIdx) const { return mRandomSeeds[isIdx]; } - InitialShapeBuilderUPtr& getInitialShapeBuilder(size_t isIdx) { return mInitialShapeBuilders[isIdx]; } - const PrimitiveNOPtrVector& getPrimitiveMapping(size_t isIdx) const { return mPrimitiveMapping[isIdx]; } + InitialShapeBuilderVector& getInitialShapeBuilders() { + return mInitialShapeBuilders; + } + int32_t getInitialShapeRandomSeed(size_t isIdx) const { + return mRandomSeeds[isIdx]; + } + InitialShapeBuilderUPtr& getInitialShapeBuilder(size_t isIdx) { + return mInitialShapeBuilders[isIdx]; + } + const PrimitiveNOPtrVector& getPrimitiveMapping(size_t isIdx) const { + return mPrimitiveMapping[isIdx]; + } - AttributeMapBuilderVector& getRuleAttributeMapBuilders() { return mRuleAttributeBuilders; } - const AttributeMapBuilderVector& getRuleAttributeMapBuilders() const { return mRuleAttributeBuilders; } + AttributeMapBuilderVector& getRuleAttributeMapBuilders() { + return mRuleAttributeBuilders; + } + const AttributeMapBuilderVector& getRuleAttributeMapBuilders() const { + return mRuleAttributeBuilders; + } const std::wstring& getInitialShapeName(size_t isIdx) const; - const InitialShapeNOPtrVector& getInitialShapes() const { return mInitialShapes; } + const InitialShapeNOPtrVector& getInitialShapes() const { + return mInitialShapes; + } bool isValid() const; private: std::vector mPrimitiveMapping; - InitialShapeBuilderVector mInitialShapeBuilders; - InitialShapeNOPtrVector mInitialShapes; + InitialShapeBuilderVector mInitialShapeBuilders; + InitialShapeNOPtrVector mInitialShapes; - AttributeMapBuilderVector mRuleAttributeBuilders; - AttributeMapVector mRuleAttributes; + AttributeMapBuilderVector mRuleAttributeBuilders; + AttributeMapVector mRuleAttributes; - GroupCreation mGroupCreation = GroupCreation::NONE; - std::vector mInitialShapeNames; - std::wstring mNamePrefix; + GroupCreation mGroupCreation = GroupCreation::NONE; + std::vector mInitialShapeNames; + std::wstring mNamePrefix; - std::vector mRandomSeeds; + std::vector mRandomSeeds; }; diff --git a/src/palladio/ShapeGenerator.cpp b/src/palladio/ShapeGenerator.cpp index a533ce9b..86cf6983 100644 --- a/src/palladio/ShapeGenerator.cpp +++ b/src/palladio/ShapeGenerator.cpp @@ -15,25 +15,24 @@ */ #include "ShapeGenerator.h" -#include "ShapeData.h" -#include "PrimitivePartition.h" -#include "PrimitiveClassifier.h" #include "AttributeConversion.h" #include "LogHandler.h" #include "MultiWatch.h" +#include "PrimitiveClassifier.h" +#include "PrimitivePartition.h" +#include "ShapeData.h" #include "GA/GA_Primitive.h" #include "GU/GU_Detail.h" #include - namespace { constexpr bool DBG = true; -const std::set ATTRIBUTE_BLACKLIST = { PLD_PRIM_CLS_NAME, PLD_RPK, PLD_RULE_FILE, - PLD_START_RULE, PLD_STYLE, PLD_RANDOM_SEED }; +const std::set ATTRIBUTE_BLACKLIST = {PLD_PRIM_CLS_NAME, PLD_RPK, PLD_RULE_FILE, + PLD_START_RULE, PLD_STYLE, PLD_RANDOM_SEED}; std::wstring getFullyQualifiedStartRule(const MainAttributes& ma) { if (ma.mStartRule.find(L'$') != std::wstring::npos) @@ -44,10 +43,8 @@ std::wstring getFullyQualifiedStartRule(const MainAttributes& ma) { } // namespace - -void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& primCls, - ShapeData& shapeData, const PRTContextUPtr& prtCtx) -{ +void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& primCls, ShapeData& shapeData, + const PRTContextUPtr& prtCtx) { WA("all"); // extract initial shape geometry @@ -92,7 +89,8 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri const auto& firstPrimitive = pv.front(); const auto& primitiveMapOffset = firstPrimitive->getMapOffset(); - if (DBG) LOG_DBG << " -- creating initial shape " << isIdx << ", prim count = " << pv.size(); + if (DBG) + LOG_DBG << " -- creating initial shape " << isIdx << ", prim count = " << pv.size(); // extract main attrs from first prim in initial shape prim group const MainAttributes ma = getMainAttributesFromPrimitive(detail, firstPrimitive); @@ -103,7 +101,7 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri // extract primitive attributes AttributeMapBuilderUPtr amb(prt::AttributeMapBuilder::create()); - for (const auto& attr: attributes) { + for (const auto& attr : attributes) { const GA_ROAttributeRef& ar = attr.second; if (ar.isInvalid()) @@ -116,7 +114,8 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri GA_ROHandleD av(ar); if (av.isValid()) { double v = av.get(primitiveMapOffset); - if (DBG) LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; + if (DBG) + LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; amb->setFloat(ruleAttrName.c_str(), v); } break; @@ -126,7 +125,8 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri if (av.isValid()) { const char* v = av.get(primitiveMapOffset); const std::wstring wv = toUTF16FromOSNarrow(v); - if (DBG) LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; + if (DBG) + LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; amb->setString(ruleAttrName.c_str(), wv.c_str()); } break; @@ -136,7 +136,8 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri if (av.isValid()) { const int v = av.get(primitiveMapOffset); const bool bv = (v > 0); - if (DBG) LOG_DBG << " prim bool attr: " << ar->getName() << " = " << v; + if (DBG) + LOG_DBG << " prim bool attr: " << ar->getName() << " = " << v; amb->setBool(ruleAttrName.c_str(), bv); } break; @@ -146,7 +147,7 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri break; } } // switch key type - } // for each primitive attribute + } // for each primitive attribute AttributeMapUPtr ruleAttr(amb->createAttributeMap()); @@ -155,19 +156,14 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri const auto& shapeName = shapeData.getInitialShapeName(isIdx); const auto fqStartRule = getFullyQualifiedStartRule(ma); - isb->setAttributes( - ma.mRuleFile.c_str(), - fqStartRule.c_str(), - randomSeed, - shapeName.c_str(), - ruleAttr.get(), - assetsMap.get() - ); + isb->setAttributes(ma.mRuleFile.c_str(), fqStartRule.c_str(), randomSeed, shapeName.c_str(), ruleAttr.get(), + assetsMap.get()); prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; const prt::InitialShape* initialShape = isb->createInitialShapeAndReset(&status); if (status == prt::STATUS_OK && initialShape != nullptr) { - if (DBG) LOG_DBG << objectToXML(initialShape); + if (DBG) + LOG_DBG << objectToXML(initialShape); shapeData.addShape(initialShape, std::move(amb), std::move(ruleAttr)); } else diff --git a/src/palladio/ShapeGenerator.h b/src/palladio/ShapeGenerator.h index b11e015b..7659b2f1 100644 --- a/src/palladio/ShapeGenerator.h +++ b/src/palladio/ShapeGenerator.h @@ -23,6 +23,6 @@ class GU_Detail; struct ShapeGenerator final : ShapeConverter { - void get(const GU_Detail* detail, const PrimitiveClassifier& primCls, - ShapeData& shapeData, const PRTContextUPtr& prtCtx) override; + void get(const GU_Detail* detail, const PrimitiveClassifier& primCls, ShapeData& shapeData, + const PRTContextUPtr& prtCtx) override; }; diff --git a/src/palladio/Utils.cpp b/src/palladio/Utils.cpp index e51206e0..dce80663 100644 --- a/src/palladio/Utils.cpp +++ b/src/palladio/Utils.cpp @@ -33,21 +33,19 @@ # pragma GCC diagnostic pop #endif - #ifdef _WIN32 # include #else # include #endif - -void getCGBs(const ResolveMapSPtr& rm, std::vector>& cgbs) { - constexpr const wchar_t* PROJECT = L""; - constexpr const wchar_t* PATTERN = L"*.cgb"; - constexpr const size_t START_SIZE = 16 * 1024; +void getCGBs(const ResolveMapSPtr& rm, std::vector>& cgbs) { + constexpr const wchar_t* PROJECT = L""; + constexpr const wchar_t* PATTERN = L"*.cgb"; + constexpr const size_t START_SIZE = 16 * 1024; size_t resultSize = START_SIZE; - auto * result = new wchar_t[resultSize]; // TODO: use std::array + auto* result = new wchar_t[resultSize]; // TODO: use std::array rm->searchKey(PROJECT, PATTERN, result, &resultSize); if (resultSize >= START_SIZE) { delete[] result; @@ -60,8 +58,9 @@ void getCGBs(const ResolveMapSPtr& rm, std::vector tok; PLD_BOOST_NS::split(tok, cgbList, PLD_BOOST_NS::is_any_of(L";"), PLD_BOOST_NS::algorithm::token_compress_on); - for(const std::wstring& t: tok) { - if (t.empty()) continue; + for (const std::wstring& t : tok) { + if (t.empty()) + continue; LOG_DBG << "token: '" << t << "'"; const wchar_t* s = rm->getString(t.c_str()); if (s != nullptr) { @@ -75,7 +74,8 @@ const prt::AttributeMap* createValidatedOptions(const wchar_t* encID, const prt: const EncoderInfoUPtr encInfo(prt::createEncoderInfo(encID)); const prt::AttributeMap* validatedOptions = nullptr; const prt::AttributeMap* optionStates = nullptr; - const prt::Status s = encInfo->createValidatedOptionsAndStates(unvalidatedOptions, &validatedOptions, &optionStates); + const prt::Status s = + encInfo->createValidatedOptionsAndStates(unvalidatedOptions, &validatedOptions, &optionStates); if (optionStates != nullptr) optionStates->destroy(); return (s == prt::STATUS_OK) ? validatedOptions : nullptr; @@ -89,7 +89,7 @@ std::string objectToXML(prt::Object const* obj) { std::vector buffer(SIZE, ' '); obj->toXML(buffer.data(), &actualSize); buffer.resize(actualSize); - if(actualSize > SIZE) + if (actualSize > SIZE) obj->toXML(buffer.data(), &actualSize); return std::string(buffer.data()); } @@ -97,26 +97,26 @@ std::string objectToXML(prt::Object const* obj) { void getLibraryPath(PLD_BOOST_NS::filesystem::path& path, const void* func) { #ifdef _WIN32 HMODULE dllHandle = 0; - if(!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)func, &dllHandle)) { + if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)func, &dllHandle)) { DWORD c = GetLastError(); char msg[255]; - FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, c, 0, msg, 255, 0); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, c, 0, msg, 255, 0); throw std::runtime_error("error while trying to get current module handle': " + std::string(msg)); } assert(sizeof(TCHAR) == 1); const size_t PATHMAXSIZE = 4096; TCHAR pathA[PATHMAXSIZE]; DWORD pathSize = GetModuleFileName(dllHandle, pathA, PATHMAXSIZE); - if(pathSize == 0 || pathSize == PATHMAXSIZE) { + if (pathSize == 0 || pathSize == PATHMAXSIZE) { DWORD c = GetLastError(); char msg[255]; - FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, c, 0, msg, 255, 0); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, c, 0, msg, 255, 0); throw std::runtime_error("error while trying to get current module path': " + std::string(msg)); } path = pathA; #else /* macosx or linux */ Dl_info dl_info; - if(dladdr(func, &dl_info) == 0) { + if (dladdr(func, &dl_info) == 0) { char* error = dlerror(); throw std::runtime_error("error while trying to get current module path': " + std::string(error ? error : "")); } @@ -153,7 +153,7 @@ std::string toOSNarrowFromUTF16(const std::wstring& osWString) { size_t size = temp.size(); prt::Status status = prt::STATUS_OK; prt::StringUtils::toOSNarrowFromUTF16(osWString.c_str(), temp.data(), &size, &status); - if(size > temp.size()) { + if (size > temp.size()) { temp.resize(size); prt::StringUtils::toOSNarrowFromUTF16(osWString.c_str(), temp.data(), &size, &status); } @@ -165,7 +165,7 @@ std::wstring toUTF16FromOSNarrow(const std::string& osString) { size_t size = temp.size(); prt::Status status = prt::STATUS_OK; prt::StringUtils::toUTF16FromOSNarrow(osString.c_str(), temp.data(), &size, &status); - if(size > temp.size()) { + if (size > temp.size()) { temp.resize(size); prt::StringUtils::toUTF16FromOSNarrow(osString.c_str(), temp.data(), &size, &status); } @@ -178,7 +178,7 @@ std::string toUTF8FromOSNarrow(const std::string& osString) { size_t size = temp.size(); prt::Status status = prt::STATUS_OK; prt::StringUtils::toUTF8FromUTF16(utf16String.c_str(), temp.data(), &size, &status); - if(size > temp.size()) { + if (size > temp.size()) { temp.resize(size); prt::StringUtils::toUTF8FromUTF16(utf16String.c_str(), temp.data(), &size, &status); } @@ -197,11 +197,11 @@ std::wstring toFileURI(const PLD_BOOST_NS::filesystem::path& p) { } std::wstring percentEncode(const std::string& utf8String) { - std::vector temp(2*utf8String.size()); + std::vector temp(2 * utf8String.size()); size_t size = temp.size(); prt::Status status = prt::STATUS_OK; prt::StringUtils::percentEncode(utf8String.c_str(), temp.data(), &size, &status); - if(size > temp.size()) { + if (size > temp.size()) { temp.resize(size); prt::StringUtils::percentEncode(utf8String.c_str(), temp.data(), &size, &status); } @@ -209,7 +209,7 @@ std::wstring percentEncode(const std::string& utf8String) { std::vector u16temp(temp.size()); size = u16temp.size(); prt::StringUtils::toUTF16FromUTF8(temp.data(), u16temp.data(), &size, &status); - if(size > u16temp.size()) { + if (size > u16temp.size()) { u16temp.resize(size); prt::StringUtils::toUTF16FromUTF8(temp.data(), u16temp.data(), &size, &status); } diff --git a/src/palladio/Utils.h b/src/palladio/Utils.h index d229bf9f..2db94023 100644 --- a/src/palladio/Utils.h +++ b/src/palladio/Utils.h @@ -18,13 +18,13 @@ #include "PalladioMain.h" -#include "prt/Object.h" #include "prt/AttributeMap.h" -#include "prt/ResolveMap.h" -#include "prt/InitialShape.h" -#include "prt/RuleFileInfo.h" #include "prt/EncoderInfo.h" +#include "prt/InitialShape.h" +#include "prt/Object.h" #include "prt/OcclusionSet.h" +#include "prt/ResolveMap.h" +#include "prt/RuleFileInfo.h" #include "GA/GA_Primitive.h" @@ -32,36 +32,41 @@ #include #include - -namespace PLD_BOOST_NS { namespace filesystem { class path; } } +namespace PLD_BOOST_NS { +namespace filesystem { +class path; +} +} // namespace PLD_BOOST_NS struct PRTDestroyer { void operator()(prt::Object const* p) { - if (p) p->destroy(); + if (p) + p->destroy(); } }; -using PrimitiveNOPtrVector = std::vector; +using PrimitiveNOPtrVector = std::vector; -using ObjectUPtr = std::unique_ptr; -using InitialShapeNOPtrVector = std::vector; -using AttributeMapNOPtrVector = std::vector; -using CacheObjectUPtr = std::unique_ptr; -using AttributeMapUPtr = std::unique_ptr; -using AttributeMapVector = std::vector; -using AttributeMapBuilderUPtr = std::unique_ptr; +using ObjectUPtr = std::unique_ptr; +using InitialShapeNOPtrVector = std::vector; +using AttributeMapNOPtrVector = std::vector; +using CacheObjectUPtr = std::unique_ptr; +using AttributeMapUPtr = std::unique_ptr; +using AttributeMapVector = std::vector; +using AttributeMapBuilderUPtr = std::unique_ptr; using AttributeMapBuilderVector = std::vector; -using InitialShapeBuilderUPtr = std::unique_ptr; +using InitialShapeBuilderUPtr = std::unique_ptr; using InitialShapeBuilderVector = std::vector; -using ResolveMapSPtr = std::shared_ptr; -using ResolveMapUPtr = std::unique_ptr; -using ResolveMapBuilderUPtr = std::unique_ptr; -using RuleFileInfoUPtr = std::unique_ptr; -using EncoderInfoUPtr = std::unique_ptr; -using OcclusionSetUPtr = std::unique_ptr; - -PLD_TEST_EXPORTS_API void getCGBs(const ResolveMapSPtr& rm, std::vector>& cgbs); -PLD_TEST_EXPORTS_API const prt::AttributeMap* createValidatedOptions(const wchar_t* encID, const prt::AttributeMap* unvalidatedOptions); +using ResolveMapSPtr = std::shared_ptr; +using ResolveMapUPtr = std::unique_ptr; +using ResolveMapBuilderUPtr = std::unique_ptr; +using RuleFileInfoUPtr = std::unique_ptr; +using EncoderInfoUPtr = std::unique_ptr; +using OcclusionSetUPtr = std::unique_ptr; + +PLD_TEST_EXPORTS_API void getCGBs(const ResolveMapSPtr& rm, std::vector>& cgbs); +PLD_TEST_EXPORTS_API const prt::AttributeMap* createValidatedOptions(const wchar_t* encID, + const prt::AttributeMap* unvalidatedOptions); PLD_TEST_EXPORTS_API std::string objectToXML(prt::Object const* obj); void getLibraryPath(PLD_BOOST_NS::filesystem::path& path, const void* func); @@ -86,7 +91,7 @@ inline void replace_all_not_of(std::wstring& s, const std::wstring& allowedChars } inline bool startsWithAnyOf(const std::string& s, const std::vector& sv) { - for (const auto& v: sv) { + for (const auto& v : sv) { if (s.find(v) == 0) return true; } diff --git a/src/test/TestCallbacks.h b/src/test/TestCallbacks.h index 458034d0..a9363e48 100644 --- a/src/test/TestCallbacks.h +++ b/src/test/TestCallbacks.h @@ -16,8 +16,8 @@ #pragma once -#include "../palladio/Utils.h" #include "../codec/encoder/HoudiniCallbacks.h" +#include "../palladio/Utils.h" #include "prt/API.h" #include "prt/AttributeMap.h" @@ -30,7 +30,6 @@ #include #include - struct CallbackResult { std::wstring name; std::vector vtx; @@ -44,7 +43,7 @@ struct CallbackResult { std::vector materials; std::map attrsPerShapeID; - explicit CallbackResult(size_t uvSets) : uvs(uvSets), uvCounts(uvSets), uvIndices(uvSets) { } + explicit CallbackResult(size_t uvSets) : uvs(uvSets), uvCounts(uvSets), uvIndices(uvSets) {} }; class TestCallbacks : public HoudiniCallbacks { @@ -52,43 +51,35 @@ class TestCallbacks : public HoudiniCallbacks { std::vector results; std::map attrs; - void add(const wchar_t* name, - const double* vtx, size_t vtxSize, - const double* nrm, size_t nrmSize, - const uint32_t* counts, size_t countsSize, - const uint32_t* indices, size_t indicesSize, - double const* const* uvs, size_t const* uvsSizes, - uint32_t const* const* uvCounts, size_t const* uvCountsSizes, - uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, - uint32_t uvSets, - const uint32_t* faceRanges, size_t faceRangesSize, - const prt::AttributeMap** materials, - const prt::AttributeMap** reports, - const int32_t* shapeIDs - ) override { + void add(const wchar_t* name, const double* vtx, size_t vtxSize, const double* nrm, size_t nrmSize, + const uint32_t* counts, size_t countsSize, const uint32_t* indices, size_t indicesSize, + double const* const* uvs, size_t const* uvsSizes, uint32_t const* const* uvCounts, + size_t const* uvCountsSizes, uint32_t const* const* uvIndices, size_t const* uvIndicesSizes, + uint32_t uvSets, const uint32_t* faceRanges, size_t faceRangesSize, const prt::AttributeMap** materials, + const prt::AttributeMap** reports, const int32_t* shapeIDs) override { results.emplace_back(CallbackResult(uvSets)); auto& cr = results.back(); cr.name = name; - cr.vtx.assign(vtx, vtx+vtxSize); - cr.nrm.assign(nrm, nrm+nrmSize); - cr.cnts.assign(counts, counts+countsSize); - cr.idx.assign(indices, indices+indicesSize); + cr.vtx.assign(vtx, vtx + vtxSize); + cr.nrm.assign(nrm, nrm + nrmSize); + cr.cnts.assign(counts, counts + countsSize); + cr.idx.assign(indices, indices + indicesSize); for (size_t i = 0; i < uvSets; i++) { - cr.uvs[i].assign(uvs[i], uvs[i]+uvsSizes[i]); - cr.uvCounts[i].assign(uvCounts[i], uvCounts[i]+uvCountsSizes[i]); - cr.uvIndices[i].assign(uvIndices[i], uvIndices[i]+uvIndicesSizes[i]); + cr.uvs[i].assign(uvs[i], uvs[i] + uvsSizes[i]); + cr.uvCounts[i].assign(uvCounts[i], uvCounts[i] + uvCountsSizes[i]); + cr.uvIndices[i].assign(uvIndices[i], uvIndices[i] + uvIndicesSizes[i]); } - cr.faceRanges.assign(faceRanges, faceRanges+faceRangesSize); + cr.faceRanges.assign(faceRanges, faceRanges + faceRangesSize); - for (size_t mi = 0; mi < faceRangesSize-1; mi++) { + for (size_t mi = 0; mi < faceRangesSize - 1; mi++) { AttributeMapBuilderUPtr amb(prt::AttributeMapBuilder::createFromAttributeMap(materials[mi])); cr.materials.emplace_back(amb->createAttributeMap()); } - for (size_t si = 0; si < faceRangesSize-1; si++) { + for (size_t si = 0; si < faceRangesSize - 1; si++) { const int32_t sid = shapeIDs[si]; cr.attrsPerShapeID.emplace(sid, AttributeMapUPtr(attrs.at(sid)->createAttributeMap())); } @@ -99,11 +90,13 @@ class TestCallbacks : public HoudiniCallbacks { return prt::STATUS_OK; } - prt::Status assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, const wchar_t* message) override { + prt::Status assetError(size_t isIndex, prt::CGAErrorLevel level, const wchar_t* key, const wchar_t* uri, + const wchar_t* message) override { return prt::STATUS_OK; } - prt::Status cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, const wchar_t* message) override { + prt::Status cgaError(size_t isIndex, int32_t shapeID, prt::CGAErrorLevel level, int32_t methodId, int32_t pc, + const wchar_t* message) override { return prt::STATUS_OK; } diff --git a/src/test/TestUtils.cpp b/src/test/TestUtils.cpp index 82532728..01d39d18 100644 --- a/src/test/TestUtils.cpp +++ b/src/test/TestUtils.cpp @@ -20,7 +20,6 @@ #include "catch.hpp" - namespace { constexpr const wchar_t* ENCODER_ID_CGA_ERROR = L"com.esri.prt.core.CGAErrorEncoder"; @@ -30,14 +29,9 @@ constexpr const wchar_t* FILE_CGA_PRINT = L"CGAPrint.txt"; } // namespace - -void generate(TestCallbacks& tc, - const PRTContextUPtr& prtCtx, - const PLD_BOOST_NS::filesystem::path& rpkPath, - const std::wstring& ruleFile, - const std::vector& initialShapeURIs, - const std::vector& startRules) -{ +void generate(TestCallbacks& tc, const PRTContextUPtr& prtCtx, const PLD_BOOST_NS::filesystem::path& rpkPath, + const std::wstring& ruleFile, const std::vector& initialShapeURIs, + const std::vector& startRules) { REQUIRE(initialShapeURIs.size() == startRules.size()); ResolveMapSPtr rpkRM = prtCtx->getResolveMap(rpkPath); @@ -50,11 +44,20 @@ void generate(TestCallbacks& tc, for (size_t ai = 0, numAttrs = ruleFileInfo->getNumAttributes(); ai < numAttrs; ai++) { const auto* a = ruleFileInfo->getAttribute(ai); switch (a->getReturnType()) { - case prt::AAT_BOOL: amb->setBool(a->getName(), false); break; - case prt::AAT_FLOAT: amb->setFloat(a->getName(), 0.0); break; - case prt::AAT_STR: amb->setString(a->getName(), L""); break; - case prt::AAT_INT: amb->setInt(a->getName(), 0); break; - default: break; + case prt::AAT_BOOL: + amb->setBool(a->getName(), false); + break; + case prt::AAT_FLOAT: + amb->setFloat(a->getName(), 0.0); + break; + case prt::AAT_STR: + amb->setString(a->getName(), L""); + break; + case prt::AAT_INT: + amb->setInt(a->getName(), 0); + break; + default: + break; } } const AttributeMapUPtr isAttrsProto(amb->createAttributeMapAndReset()); @@ -67,7 +70,8 @@ void generate(TestCallbacks& tc, gd.mInitialShapeBuilders.emplace_back(prt::InitialShapeBuilder::create()); auto& isb = gd.mInitialShapeBuilders.back(); - gd.mRuleAttributeBuilders.emplace_back(prt::AttributeMapBuilder::createFromAttributeMap(isAttrsProto.get())); // TODO: use shared_ptr + gd.mRuleAttributeBuilders.emplace_back( + prt::AttributeMapBuilder::createFromAttributeMap(isAttrsProto.get())); // TODO: use shared_ptr const auto& rab = gd.mRuleAttributeBuilders.back(); gd.mRuleAttributes.emplace_back(rab->createAttributeMap()); const auto& am = gd.mRuleAttributes.back(); @@ -75,7 +79,8 @@ void generate(TestCallbacks& tc, const std::wstring sn = L"shape" + std::to_wstring(i); REQUIRE(isb->resolveGeometry(uri.c_str()) == prt::STATUS_OK); - REQUIRE(isb->setAttributes(ruleFile.c_str(), sr.c_str(), 0, sn.c_str(), am.get(), rpkRM.get()) == prt::STATUS_OK); + REQUIRE(isb->setAttributes(ruleFile.c_str(), sr.c_str(), 0, sn.c_str(), am.get(), rpkRM.get()) == + prt::STATUS_OK); prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; const prt::InitialShape* is = isb->createInitialShapeAndReset(&status); @@ -100,12 +105,12 @@ void generate(TestCallbacks& tc, amb->setInt(L"numberWorkerThreads", prtCtx->mCores); const AttributeMapUPtr generateOptions(amb->createAttributeMapAndReset()); - const std::vector allEncoders = { ENCODER_ID_HOUDINI, ENCODER_ID_CGA_ERROR, ENCODER_ID_CGA_PRINT }; - const AttributeMapNOPtrVector allEncoderOptions = { houdiniEncOpts.get(), cgaErrorOptions.get(), - cgaPrintOptions.get() }; + const std::vector allEncoders = {ENCODER_ID_HOUDINI, ENCODER_ID_CGA_ERROR, ENCODER_ID_CGA_PRINT}; + const AttributeMapNOPtrVector allEncoderOptions = {houdiniEncOpts.get(), cgaErrorOptions.get(), + cgaPrintOptions.get()}; - prt::Status stat = prt::generate(gd.mInitialShapes.data(), gd.mInitialShapes.size(), nullptr, - allEncoders.data(), allEncoders.size(), allEncoderOptions.data(), &tc, - prtCtx->mPRTCache.get(), nullptr, generateOptions.get()); + prt::Status stat = prt::generate(gd.mInitialShapes.data(), gd.mInitialShapes.size(), nullptr, allEncoders.data(), + allEncoders.size(), allEncoderOptions.data(), &tc, prtCtx->mPRTCache.get(), + nullptr, generateOptions.get()); REQUIRE(stat == prt::STATUS_OK); } diff --git a/src/test/TestUtils.h b/src/test/TestUtils.h index ad56ed29..940c0fbe 100644 --- a/src/test/TestUtils.h +++ b/src/test/TestUtils.h @@ -29,26 +29,21 @@ #include #include - struct GenerateData { // TODO: could use ShapeData from production code - InitialShapeBuilderVector mInitialShapeBuilders; - InitialShapeNOPtrVector mInitialShapes; + InitialShapeBuilderVector mInitialShapeBuilders; + InitialShapeNOPtrVector mInitialShapes; - AttributeMapBuilderVector mRuleAttributeBuilders; - AttributeMapVector mRuleAttributes; + AttributeMapBuilderVector mRuleAttributeBuilders; + AttributeMapVector mRuleAttributes; ~GenerateData() { - std::for_each(mInitialShapes.begin(), mInitialShapes.end(), [](const prt::InitialShape* is){ + std::for_each(mInitialShapes.begin(), mInitialShapes.end(), [](const prt::InitialShape* is) { assert(is != nullptr); is->destroy(); }); } }; - -void generate(TestCallbacks& tc, - const PRTContextUPtr& prtCtx, - const PLD_BOOST_NS::filesystem::path& rpkPath, - const std::wstring& ruleFile, - const std::vector& initialShapeURIs, +void generate(TestCallbacks& tc, const PRTContextUPtr& prtCtx, const PLD_BOOST_NS::filesystem::path& rpkPath, + const std::wstring& ruleFile, const std::vector& initialShapeURIs, const std::vector& startRules); diff --git a/src/test/tests.cpp b/src/test/tests.cpp index 54017d7e..e6f0a56e 100644 --- a/src/test/tests.cpp +++ b/src/test/tests.cpp @@ -17,11 +17,11 @@ #include "TestCallbacks.h" #include "TestUtils.h" +#include "../codec/encoder/HoudiniEncoder.h" +#include "../palladio/AttributeConversion.h" +#include "../palladio/ModelConverter.h" #include "../palladio/PRTContext.h" #include "../palladio/Utils.h" -#include "../palladio/ModelConverter.h" -#include "../palladio/AttributeConversion.h" -#include "../codec/encoder/HoudiniEncoder.h" #include "prt/AttributeMap.h" #include "prtx/Geometry.h" @@ -37,13 +37,12 @@ #include - namespace { PRTContextUPtr prtCtx; const PLD_BOOST_NS::filesystem::path testDataPath = TEST_DATA_PATH; -template +template void compareReversed(const std::vector& a, const std::vector& b) { REQUIRE(a.size() == b.size()); for (size_t i = 0, num = a.size(); i < num; i++) @@ -52,43 +51,42 @@ void compareReversed(const std::vector& a, const std::vector& b) { } // namespace - -int main( int argc, char* argv[] ) { +int main(int argc, char* argv[]) { assert(!prtCtx); const std::vector addExtDirs = { - //"../lib", // adapt to default prt dir layout (core is in bin subdir) - HOUDINI_CODEC_PATH // set to absolute path to houdini encoder lib via cmake + //"../lib", // adapt to default prt dir layout (core is in bin subdir) + HOUDINI_CODEC_PATH // set to absolute path to houdini encoder lib via cmake }; prtCtx.reset(new PRTContext(addExtDirs)); - int result = Catch::Session().run( argc, argv ); + int result = Catch::Session().run(argc, argv); prtCtx.reset(); return result; } - -TEST_CASE("create file URI from path", "[utils]" ) { +TEST_CASE("create file URI from path", "[utils]") { #ifdef PLD_LINUX const auto u = toFileURI(PLD_BOOST_NS::filesystem::path("/tmp/foo.txt")); - CHECK(u.compare(L"file:/tmp/foo.txt") == 0); + CHECK(u.compare(L"file:/tmp/foo.txt") == 0); #elif defined(PLD_WINDOWS) const auto u = toFileURI(PLD_BOOST_NS::filesystem::path("c:\\tmp\\foo.txt")); - INFO(toOSNarrowFromUTF16(u)); - CHECK(u.compare(L"file:/c:/tmp/foo.txt") == 0); + INFO(toOSNarrowFromUTF16(u)); + CHECK(u.compare(L"file:/c:/tmp/foo.txt") == 0); #endif } TEST_CASE("percent-encode a UTF-8 string", "[utils]") { - CHECK(percentEncode("with space") == L"with%20space"); + CHECK(percentEncode("with space") == L"with%20space"); } TEST_CASE("get XML representation of a PRT object", "[utils]") { - AttributeMapBuilderUPtr amb(prt::AttributeMapBuilder::create()); + AttributeMapBuilderUPtr amb(prt::AttributeMapBuilder::create()); amb->setString(L"foo", L"bar"); - AttributeMapUPtr am(amb->createAttributeMap()); - std::string xml = objectToXML(am.get()); - CHECK(xml == "\n\t\n"); // TODO: use R? + AttributeMapUPtr am(amb->createAttributeMap()); + std::string xml = objectToXML(am.get()); + CHECK(xml == + "\n\t\n"); // TODO: use R? } TEST_CASE("replace chars not in set", "[utils]") { @@ -163,35 +161,37 @@ TEST_CASE("separate fully qualified name into style and name", "[NameConversion] CHECK(style == L"foo"); CHECK(name == L"bar$baz"); } - } - // -- encoder test cases TEST_CASE("serialize basic mesh") { - const std::vector faceCnt = { 4 }; - const prtx::DoubleVector vtx = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; - const std::vector vtxInd = { 0, 1, 2, 3 }; - const std::vector vtxIndRev = [&vtxInd]() { auto c = vtxInd; std::reverse_copy(vtxInd.begin(), vtxInd.end(), c.begin()); return c; }(); + const std::vector faceCnt = {4}; + const prtx::DoubleVector vtx = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0}; + const std::vector vtxInd = {0, 1, 2, 3}; + const std::vector vtxIndRev = [&vtxInd]() { + auto c = vtxInd; + std::reverse_copy(vtxInd.begin(), vtxInd.end(), c.begin()); + return c; + }(); - prtx::MeshBuilder mb; - mb.addVertexCoords(vtx); - uint32_t faceIdx = mb.addFace(); - mb.setFaceVertexIndices(faceIdx, vtxInd); + prtx::MeshBuilder mb; + mb.addVertexCoords(vtx); + uint32_t faceIdx = mb.addFace(); + mb.setFaceVertexIndices(faceIdx, vtxInd); - prtx::GeometryBuilder gb; - gb.addMesh(mb.createShared()); + prtx::GeometryBuilder gb; + gb.addMesh(mb.createShared()); - auto geo = gb.createShared(); + auto geo = gb.createShared(); CHECK(geo->getMeshes().front()->getUVSetsCount() == 0); - const prtx::GeometryPtrVector geos = { geo }; - const std::vector mats = { geo->getMeshes().front()->getMaterials() }; + const prtx::GeometryPtrVector geos = {geo}; + const std::vector mats = {geo->getMeshes().front()->getMaterials()}; const detail::SerializedGeometry sg = detail::serializeGeometry(geos, mats); - CHECK(sg.counts == faceCnt); + CHECK(sg.counts == faceCnt); CHECK(sg.coords == vtx); CHECK(sg.indices == vtxIndRev); // reverses winding @@ -201,17 +201,17 @@ TEST_CASE("serialize basic mesh") { } TEST_CASE("serialize mesh with one uv set") { - const prtx::IndexVector faceCnt = { 4 }; - const prtx::DoubleVector vtx = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; - const prtx::IndexVector vtxIdx = { 0, 1, 2, 3 }; - const prtx::DoubleVector uvs = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; - const prtx::IndexVector uvIdx = { 0, 1, 2, 3 }; - - prtx::MeshBuilder mb; - mb.addVertexCoords(vtx); + const prtx::IndexVector faceCnt = {4}; + const prtx::DoubleVector vtx = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0}; + const prtx::IndexVector vtxIdx = {0, 1, 2, 3}; + const prtx::DoubleVector uvs = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; + const prtx::IndexVector uvIdx = {0, 1, 2, 3}; + + prtx::MeshBuilder mb; + mb.addVertexCoords(vtx); mb.addUVCoords(0, uvs); - uint32_t faceIdx = mb.addFace(); - mb.setFaceVertexIndices(faceIdx, vtxIdx); + uint32_t faceIdx = mb.addFace(); + mb.setFaceVertexIndices(faceIdx, vtxIdx); mb.setFaceUVIndices(faceIdx, 0, uvIdx); const auto m = mb.createShared(); @@ -221,17 +221,17 @@ TEST_CASE("serialize mesh with one uv set") { CHECK(m->getUVSetsCount() == 1); #endif - prtx::GeometryBuilder gb; - gb.addMesh(m); - auto geo = gb.createShared(); - const prtx::GeometryPtrVector geos = { geo }; - const std::vector mats = { m->getMaterials() }; + prtx::GeometryBuilder gb; + gb.addMesh(m); + auto geo = gb.createShared(); + const prtx::GeometryPtrVector geos = {geo}; + const std::vector mats = {m->getMaterials()}; const detail::SerializedGeometry sg = detail::serializeGeometry(geos, mats); - CHECK(sg.counts == faceCnt); - CHECK(sg.coords == vtx); - const prtx::IndexVector vtxIdxExp = { 3, 2, 1, 0 }; + CHECK(sg.counts == faceCnt); + CHECK(sg.coords == vtx); + const prtx::IndexVector vtxIdxExp = {3, 2, 1, 0}; CHECK(sg.indices == vtxIdxExp); #if PRT_VERSION_MAJOR < 2 @@ -247,69 +247,69 @@ TEST_CASE("serialize mesh with one uv set") { } TEST_CASE("serialize mesh with two uv sets") { - const prtx::IndexVector faceCnt = { 4 }; - const prtx::DoubleVector vtx = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; - const prtx::IndexVector vtxIdx = { 0, 1, 2, 3 }; - const prtx::DoubleVector uvs0 = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; - const prtx::IndexVector uvIdx0 = { 0, 1, 2, 3 }; - const prtx::DoubleVector uvs1 = { 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5 }; - const prtx::IndexVector uvIdx1 = { 3, 2, 1, 0 }; - - prtx::MeshBuilder mb; - mb.addVertexCoords(vtx); + const prtx::IndexVector faceCnt = {4}; + const prtx::DoubleVector vtx = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0}; + const prtx::IndexVector vtxIdx = {0, 1, 2, 3}; + const prtx::DoubleVector uvs0 = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; + const prtx::IndexVector uvIdx0 = {0, 1, 2, 3}; + const prtx::DoubleVector uvs1 = {0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5}; + const prtx::IndexVector uvIdx1 = {3, 2, 1, 0}; + + prtx::MeshBuilder mb; + mb.addVertexCoords(vtx); mb.addUVCoords(0, uvs0); mb.addUVCoords(1, uvs1); - uint32_t faceIdx = mb.addFace(); - mb.setFaceVertexIndices(faceIdx, vtxIdx); + uint32_t faceIdx = mb.addFace(); + mb.setFaceVertexIndices(faceIdx, vtxIdx); mb.setFaceUVIndices(faceIdx, 0, uvIdx0); mb.setFaceUVIndices(faceIdx, 1, uvIdx1); const auto m = mb.createShared(); CHECK(m->getUVSetsCount() == 2); - prtx::GeometryBuilder gb; - gb.addMesh(m); - auto geo = gb.createShared(); - const prtx::GeometryPtrVector geos = { geo }; - const std::vector mats = { m->getMaterials() }; + prtx::GeometryBuilder gb; + gb.addMesh(m); + auto geo = gb.createShared(); + const prtx::GeometryPtrVector geos = {geo}; + const std::vector mats = {m->getMaterials()}; const detail::SerializedGeometry sg = detail::serializeGeometry(geos, mats); - CHECK(sg.counts == faceCnt); - CHECK(sg.coords == vtx); - const prtx::IndexVector vtxIdxExp = { 3, 2, 1, 0 }; + CHECK(sg.counts == faceCnt); + CHECK(sg.coords == vtx); + const prtx::IndexVector vtxIdxExp = {3, 2, 1, 0}; CHECK(sg.indices == vtxIdxExp); CHECK(sg.uvs.size() == 2); CHECK(sg.uvCounts.size() == 2); CHECK(sg.uvIndices.size() == 2); - const prtx::DoubleVector uvs0Exp = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; + const prtx::DoubleVector uvs0Exp = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; CHECK(sg.uvs[0] == uvs0Exp); CHECK(sg.uvCounts[0] == faceCnt); compareReversed(sg.uvIndices[0], uvIdx0); - const prtx::DoubleVector uvs1Exp = { 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5 }; + const prtx::DoubleVector uvs1Exp = {0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5}; CHECK(sg.uvs[1] == uvs1Exp); CHECK(sg.uvCounts[1] == faceCnt); compareReversed(sg.uvIndices[1], uvIdx1); } TEST_CASE("serialize mesh with two non-consecutive uv sets") { - const prtx::IndexVector faceCnt = { 4 }; - const prtx::DoubleVector vtx = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; - const prtx::IndexVector vtxIdx = { 0, 1, 2, 3 }; - const prtx::DoubleVector uvs0 = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; - const prtx::IndexVector uvIdx0 = { 0, 1, 2, 3 }; - const prtx::DoubleVector uvs2 = { 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5 }; - const prtx::IndexVector uvIdx2 = { 3, 2, 1, 0 }; - - prtx::MeshBuilder mb; - mb.addVertexCoords(vtx); + const prtx::IndexVector faceCnt = {4}; + const prtx::DoubleVector vtx = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0}; + const prtx::IndexVector vtxIdx = {0, 1, 2, 3}; + const prtx::DoubleVector uvs0 = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; + const prtx::IndexVector uvIdx0 = {0, 1, 2, 3}; + const prtx::DoubleVector uvs2 = {0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5}; + const prtx::IndexVector uvIdx2 = {3, 2, 1, 0}; + + prtx::MeshBuilder mb; + mb.addVertexCoords(vtx); mb.addUVCoords(0, uvs0); mb.addUVCoords(2, uvs2); - uint32_t faceIdx = mb.addFace(); - mb.setFaceVertexIndices(faceIdx, vtxIdx); + uint32_t faceIdx = mb.addFace(); + mb.setFaceVertexIndices(faceIdx, vtxIdx); mb.setFaceUVIndices(faceIdx, 0, uvIdx0); mb.setFaceUVIndices(faceIdx, 2, uvIdx2); const auto m = mb.createShared(); @@ -320,16 +320,16 @@ TEST_CASE("serialize mesh with two non-consecutive uv sets") { CHECK(m->getUVSetsCount() == 3); #endif - prtx::GeometryBuilder gb; - gb.addMesh(m); - auto geo = gb.createShared(); - const prtx::GeometryPtrVector geos = { geo }; - const std::vector mats = { m->getMaterials() }; + prtx::GeometryBuilder gb; + gb.addMesh(m); + auto geo = gb.createShared(); + const prtx::GeometryPtrVector geos = {geo}; + const std::vector mats = {m->getMaterials()}; const detail::SerializedGeometry sg = detail::serializeGeometry(geos, mats); - CHECK(sg.counts == faceCnt); - CHECK(sg.coords == vtx); + CHECK(sg.counts == faceCnt); + CHECK(sg.coords == vtx); compareReversed(sg.indices, vtxIdx); #if PRT_VERSION_MAJOR < 2 @@ -340,7 +340,7 @@ TEST_CASE("serialize mesh with two non-consecutive uv sets") { CHECK(sg.uvIndices.size() == 3); #endif - const prtx::DoubleVector uvs0Exp = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; + const prtx::DoubleVector uvs0Exp = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; CHECK(sg.uvs[0] == uvs0Exp); CHECK(sg.uvCounts[0] == faceCnt); compareReversed(sg.uvIndices[0], uvIdx0); @@ -350,33 +350,33 @@ TEST_CASE("serialize mesh with two non-consecutive uv sets") { CHECK(sg.uvCounts[1] == faceCnt); compareReversed(sg.uvIndices[1], uvIdx0); - const prtx::DoubleVector uvs2Exp = { 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5 }; + const prtx::DoubleVector uvs2Exp = {0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5}; CHECK(sg.uvs[2] == uvs2Exp); CHECK(sg.uvCounts[2] == faceCnt); compareReversed(sg.uvIndices[2], uvIdx2); } TEST_CASE("serialize mesh with mixed face uvs (one uv set)") { - const prtx::IndexVector faceCnt = { 4, 3, 5 }; - const prtx::DoubleVector vtx = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0 }; - const prtx::IndexVector vtxIdx[] = { { 0, 1, 2, 3 }, { 0, 1, 4 }, { 0, 1, 2, 3, 4 } }; - const prtx::DoubleVector uvs = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; - const prtx::IndexVector uvIdx[] = { { 0, 1, 2, 3 }, { }, { 0, 1, 2, 3, 0 } }; // face 1 has no uvs - - prtx::MeshBuilder mb; - mb.addVertexCoords(vtx); + const prtx::IndexVector faceCnt = {4, 3, 5}; + const prtx::DoubleVector vtx = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0}; + const prtx::IndexVector vtxIdx[] = {{0, 1, 2, 3}, {0, 1, 4}, {0, 1, 2, 3, 4}}; + const prtx::DoubleVector uvs = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; + const prtx::IndexVector uvIdx[] = {{0, 1, 2, 3}, {}, {0, 1, 2, 3, 0}}; // face 1 has no uvs + + prtx::MeshBuilder mb; + mb.addVertexCoords(vtx); mb.addUVCoords(0, uvs); - mb.addFace(); - mb.setFaceVertexIndices(0, vtxIdx[0]); + mb.addFace(); + mb.setFaceVertexIndices(0, vtxIdx[0]); mb.setFaceUVIndices(0, 0, uvIdx[0]); - mb.addFace(); - mb.setFaceVertexIndices(1, vtxIdx[1]); + mb.addFace(); + mb.setFaceVertexIndices(1, vtxIdx[1]); mb.setFaceUVIndices(1, 0, uvIdx[1]); // has no uvs - mb.addFace(); - mb.setFaceVertexIndices(2, vtxIdx[2]); + mb.addFace(); + mb.setFaceVertexIndices(2, vtxIdx[2]); mb.setFaceUVIndices(2, 0, uvIdx[2]); const auto m = mb.createShared(); @@ -387,18 +387,18 @@ TEST_CASE("serialize mesh with mixed face uvs (one uv set)") { CHECK(m->getUVSetsCount() == 1); #endif - prtx::GeometryBuilder gb; - gb.addMesh(m); - auto geo = gb.createShared(); - const prtx::GeometryPtrVector geos = { geo }; - const std::vector mats = { m->getMaterials() }; + prtx::GeometryBuilder gb; + gb.addMesh(m); + auto geo = gb.createShared(); + const prtx::GeometryPtrVector geos = {geo}; + const std::vector mats = {m->getMaterials()}; const detail::SerializedGeometry sg = detail::serializeGeometry(geos, mats); - CHECK(sg.counts == faceCnt); + CHECK(sg.counts == faceCnt); CHECK(sg.coords == vtx); - const prtx::IndexVector vtxIdxExp = { 3, 2, 1, 0, 4, 1, 0, 4, 3, 2, 1, 0 }; + const prtx::IndexVector vtxIdxExp = {3, 2, 1, 0, 4, 1, 0, 4, 3, 2, 1, 0}; CHECK(sg.indices == vtxIdxExp); #if PRT_VERSION_MAJOR < 2 @@ -411,10 +411,10 @@ TEST_CASE("serialize mesh with mixed face uvs (one uv set)") { #endif CHECK(sg.uvs[0] == uvs); - const prtx::IndexVector uvCountsExp = { 4, 0, 5 }; + const prtx::IndexVector uvCountsExp = {4, 0, 5}; CHECK(sg.uvCounts[0] == uvCountsExp); - const prtx::IndexVector uvIdxExp = { 3, 2, 1, 0, 0, 3, 2, 1, 0 }; + const prtx::IndexVector uvIdxExp = {3, 2, 1, 0, 0, 3, 2, 1, 0}; CHECK(sg.uvIndices[0] == uvIdxExp); } @@ -447,18 +447,19 @@ TEST_CASE("serialize two meshes with one uv set") { gb.addMesh(m2); auto geo = gb.createShared(); const prtx::GeometryPtrVector geos = {geo}; - const std::vector mats = { { geo->getMeshes()[0]->getMaterials().front(), geo->getMeshes()[1]->getMaterials().front() } }; + const std::vector mats = { + {geo->getMeshes()[0]->getMaterials().front(), geo->getMeshes()[1]->getMaterials().front()}}; const detail::SerializedGeometry sg = detail::serializeGeometry(geos, mats); const prtx::IndexVector expFaceCnt = {4, 4}; CHECK(sg.counts == expFaceCnt); - const prtx::DoubleVector expVtx = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, - 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; + const prtx::DoubleVector expVtx = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0}; CHECK(sg.coords == expVtx); - const prtx::IndexVector expVtxIdx = { 3, 2, 1, 0, 7, 6, 5, 4 }; + const prtx::IndexVector expVtxIdx = {3, 2, 1, 0, 7, 6, 5, 4}; CHECK(sg.indices == expVtxIdx); #if PRT_VERSION_MAJOR < 2 @@ -469,8 +470,7 @@ TEST_CASE("serialize two meshes with one uv set") { CHECK(sg.uvIndices.size() == 1); #endif - const prtx::DoubleVector expUvs = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, - 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; + const prtx::DoubleVector expUvs = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; CHECK(sg.uvs[0] == expUvs); CHECK(sg.uvCounts[0] == expFaceCnt); CHECK(sg.uvIndices[0] == expVtxIdx); @@ -510,18 +510,19 @@ TEST_CASE("serialize two meshes where one does not have uvs (issue 108)") { gb.addMesh(m2); auto geo = gb.createShared(); const prtx::GeometryPtrVector geos = {geo}; - const std::vector mats = { { geo->getMeshes()[0]->getMaterials().front(), geo->getMeshes()[1]->getMaterials().front() } }; + const std::vector mats = { + {geo->getMeshes()[0]->getMaterials().front(), geo->getMeshes()[1]->getMaterials().front()}}; const detail::SerializedGeometry sg = detail::serializeGeometry(geos, mats); const prtx::IndexVector expFaceCnt = {4, 4}; CHECK(sg.counts == expFaceCnt); - const prtx::DoubleVector expVtx = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, - 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; + const prtx::DoubleVector expVtx = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0}; CHECK(sg.coords == expVtx); - const prtx::IndexVector expVtxIdx = { 3, 2, 1, 0, 7, 6, 5, 4 }; + const prtx::IndexVector expVtxIdx = {3, 2, 1, 0, 7, 6, 5, 4}; CHECK(sg.indices == expVtxIdx); #if PRT_VERSION_MAJOR < 2 @@ -532,31 +533,24 @@ TEST_CASE("serialize two meshes where one does not have uvs (issue 108)") { CHECK(sg.uvIndices.size() == 1); #endif - const prtx::DoubleVector expUvs = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; + const prtx::DoubleVector expUvs = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; CHECK(sg.uvs[0] == expUvs); const prtx::IndexVector expFaceUVCnt = {4, 0}; CHECK(sg.uvCounts[0] == expFaceUVCnt); - const prtx::IndexVector expUVIdx = { 3, 2, 1, 0 }; + const prtx::IndexVector expUVIdx = {3, 2, 1, 0}; CHECK(sg.uvIndices[0] == expUVIdx); } TEST_CASE("generate two cubes with two uv sets") { - const std::vector initialShapeSources = { - testDataPath / "quad0.obj", - testDataPath / "quad1.obj" - }; + const std::vector initialShapeSources = {testDataPath / "quad0.obj", + testDataPath / "quad1.obj"}; - const std::vector initialShapeURIs = { - toFileURI(initialShapeSources[0]), - toFileURI(initialShapeSources[1]) - }; + const std::vector initialShapeURIs = {toFileURI(initialShapeSources[0]), + toFileURI(initialShapeSources[1])}; - const std::vector startRules = { - L"Default$OneSet", - L"Default$TwoSets" - }; + const std::vector startRules = {L"Default$OneSet", L"Default$TwoSets"}; const PLD_BOOST_NS::filesystem::path rpkPath = testDataPath / "uvsets.rpk"; const std::wstring ruleFile = L"bin/r1.cgb"; @@ -571,10 +565,11 @@ TEST_CASE("generate two cubes with two uv sets") { const CallbackResult& cr = tc.results[0]; CHECK(cr.name == L"shape0"); - const std::vector cntsExp = { 4, 4, 4, 4, 4, 4 }; + const std::vector cntsExp = {4, 4, 4, 4, 4, 4}; CHECK(cr.cnts == cntsExp); - const std::vector idxExp = { 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20 }; + const std::vector idxExp = {3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, + 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20}; CHECK(cr.idx == idxExp); #if PRT_VERSION_MAJOR < 2 @@ -588,7 +583,7 @@ TEST_CASE("generate two cubes with two uv sets") { CHECK(cr.uvCounts[0] == cntsExp); CHECK(cr.uvIndices[0] == idxExp); - const std::vector faceRangesExp = { 0, 6 }; + const std::vector faceRangesExp = {0, 6}; CHECK(cr.faceRanges == faceRangesExp); } @@ -596,11 +591,11 @@ TEST_CASE("generate two cubes with two uv sets") { const CallbackResult& cr = tc.results[1]; CHECK(cr.name == L"shape1"); - const std::vector cntsExp = { 4, 4, 4, 4, 4, 4 }; + const std::vector cntsExp = {4, 4, 4, 4, 4, 4}; CHECK(cr.cnts == cntsExp); - const std::vector idxExp = { 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, - 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20 }; + const std::vector idxExp = {3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, + 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20}; CHECK(cr.idx == idxExp); #if PRT_VERSION_MAJOR < 2 @@ -620,15 +615,15 @@ TEST_CASE("generate two cubes with two uv sets") { CHECK(cr.uvCounts[2] == cntsExp); CHECK(cr.uvIndices[2] == idxExp); - const std::vector faceRangesExp = { 0, 1, 2, 3, 4, 5, 6 }; + const std::vector faceRangesExp = {0, 1, 2, 3, 4, 5, 6}; CHECK(cr.faceRanges == faceRangesExp); } } TEST_CASE("generate with generic attributes") { - const std::vector initialShapeSources = { testDataPath / "quad0.obj" }; - const std::vector initialShapeURIs = { toFileURI(initialShapeSources[0]) }; - const std::vector startRules = { L"Default$Init" }; + const std::vector initialShapeSources = {testDataPath / "quad0.obj"}; + const std::vector initialShapeURIs = {toFileURI(initialShapeSources[0])}; + const std::vector startRules = {L"Default$Init"}; const PLD_BOOST_NS::filesystem::path rpkPath = testDataPath / "GenAttrs1.rpk"; const std::wstring ruleFile = L"bin/r1.cgb"; @@ -638,7 +633,7 @@ TEST_CASE("generate with generic attributes") { REQUIRE(tc.results.size() == 1); const CallbackResult& cr = tc.results[0]; - const std::vector faceRangesExp = { 0, 6, 12 }; + const std::vector faceRangesExp = {0, 6, 12}; CHECK(cr.faceRanges == faceRangesExp); REQUIRE(cr.attrsPerShapeID.size() == 2); From a893b97f0f7a03514e6c904c63715733d9db3fbd Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 13:23:10 +0200 Subject: [PATCH 10/54] array attributes: add support for float64, int32, string arrays --- src/palladio/ShapeGenerator.cpp | 113 ++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 20 deletions(-) diff --git a/src/palladio/ShapeGenerator.cpp b/src/palladio/ShapeGenerator.cpp index 86cf6983..780a4207 100644 --- a/src/palladio/ShapeGenerator.cpp +++ b/src/palladio/ShapeGenerator.cpp @@ -41,6 +41,10 @@ std::wstring getFullyQualifiedStartRule(const MainAttributes& ma) { return ma.mStyle + L'$' + ma.mStartRule; } +bool isArrayAttribute(const GA_ROAttributeRef& ar) { + return (ar.getAIFNumericArray() != nullptr) || (ar.getAIFSharedStringArray() != nullptr); +} + } // namespace void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& primCls, ShapeData& shapeData, @@ -111,35 +115,104 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri switch (ar.getStorageClass()) { case GA_STORECLASS_FLOAT: { - GA_ROHandleD av(ar); - if (av.isValid()) { - double v = av.get(primitiveMapOffset); - if (DBG) - LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; - amb->setFloat(ruleAttrName.c_str(), v); + if (isArrayAttribute(ar)) { + GA_ROHandleDA av(ar); + if (av.isValid()) { + UT_Fpreal64Array v; + av.get(primitiveMapOffset, v); + if (DBG) + LOG_DBG << " prim float array attr: " << ar->getName() << " = " << v; + amb->setFloatArray(ruleAttrName.c_str(), v.data(), v.size()); + } + } + else { + GA_ROHandleD av(ar); + if (av.isValid()) { + double v = av.get(primitiveMapOffset); + if (DBG) + LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; + amb->setFloat(ruleAttrName.c_str(), v); + } } break; } case GA_STORECLASS_STRING: { - GA_ROHandleS av(ar); - if (av.isValid()) { - const char* v = av.get(primitiveMapOffset); - const std::wstring wv = toUTF16FromOSNarrow(v); - if (DBG) - LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; - amb->setString(ruleAttrName.c_str(), wv.c_str()); + if (isArrayAttribute(ar)) { + GA_ROHandleSA av(ar); + if (av.isValid()) { + UT_StringArray v; + av.get(primitiveMapOffset, v); + if (DBG) + LOG_DBG << " prim string array attr: " << ar->getName() << " = " << v; + + std::vector wstrings(v.size()); + std::vector wstringPtrs(v.size()); + for (size_t i = 0; i < v.size(); i++) { + wstrings[i] = toUTF16FromOSNarrow(v[i].toStdString()); + wstringPtrs[i] = wstrings[i].c_str(); + } + amb->setStringArray(ruleAttrName.c_str(), wstringPtrs.data(), wstringPtrs.size()); + } + } + else { + GA_ROHandleS av(ar); + if (av.isValid()) { + const char* v = av.get(primitiveMapOffset); + const std::wstring wv = toUTF16FromOSNarrow(v); + if (DBG) + LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; + amb->setString(ruleAttrName.c_str(), wv.c_str()); + } } break; } case GA_STORECLASS_INT: { - GA_ROHandleI av(ar); - if (av.isValid()) { - const int v = av.get(primitiveMapOffset); - const bool bv = (v > 0); - if (DBG) - LOG_DBG << " prim bool attr: " << ar->getName() << " = " << v; - amb->setBool(ruleAttrName.c_str(), bv); + if (isArrayAttribute(ar)) { + if (ar.getAIFNumericArray()->getStorage(ar.get()) == GA_STORE_INT8) { + GA_ROHandleIA av(ar); + if (av.isValid()) { + UT_Int32Array v; // there is no U_Int8Array + av.get(primitiveMapOffset, v); + if (DBG) + LOG_DBG << " prim bool array attr: " << ar->getName() << " = " << v; + const std::unique_ptr vPtrs(new bool[v.size()]); + for (size_t i = 0; i < v.size(); i++) + vPtrs[i] = (v[i] > 0); + amb->setBoolArray(ruleAttrName.c_str(), vPtrs.get(), v.size()); + } + } + else { + GA_ROHandleIA av(ar); + if (av.isValid()) { + UT_Int32Array v; + av.get(primitiveMapOffset, v); + if (DBG) + LOG_DBG << " prim int array attr: " << ar->getName() << " = " << v; + amb->setIntArray(ruleAttrName.c_str(), v.data(), v.size()); + } + } } + else { + if (ar.getAIFTuple()->getStorage(ar.get()) == GA_STORE_INT8) { + GA_ROHandleI av(ar); + if (av.isValid()) { + const int v = av.get(primitiveMapOffset); + const bool bv = (v > 0); + if (DBG) + LOG_DBG << " prim bool attr: " << ar->getName() << " = " << bv; + amb->setBool(ruleAttrName.c_str(), bv); + } + } + else { + GA_ROHandleI av(ar); + if (av.isValid()) { + const int v = av.get(primitiveMapOffset); + if (DBG) + LOG_DBG << " prim int attr: " << ar->getName() << " = " << v; + amb->setInt(ruleAttrName.c_str(), v); + } + } + } // int break; } default: { From 1e0c9f896e9d1551400702fd27f5712542cb1122 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 15:02:14 +0200 Subject: [PATCH 11/54] array attributes: prevent exceptions in encoder for non-existing shape attribute keys --- src/codec/encoder/HoudiniEncoder.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/codec/encoder/HoudiniEncoder.cpp b/src/codec/encoder/HoudiniEncoder.cpp index bce2bbfc..07e710da 100644 --- a/src/codec/encoder/HoudiniEncoder.cpp +++ b/src/codec/encoder/HoudiniEncoder.cpp @@ -280,19 +280,25 @@ void forwardGenericAttributes(HoudiniCallbacks* hc, size_t initialShapeIndex, co const prtx::ShapePtr& shape) { forEachKey(initialShape.getAttributeMap(), [&hc, &shape, &initialShapeIndex, &initialShape](prt::Attributable const* a, wchar_t const* key) { - switch (shape->getType(key)) { + assert(key != nullptr); + const std::wstring keyStr(key); + + if (!shape->hasKey(keyStr)) + return; + + switch (shape->getType(keyStr)) { case prtx::Attributable::PT_STRING: { - const auto v = shape->getString(key); + const auto v = shape->getString(keyStr); hc->attrString(initialShapeIndex, shape->getID(), key, v.c_str()); break; } case prtx::Attributable::PT_FLOAT: { - const auto v = shape->getFloat(key); + const auto v = shape->getFloat(keyStr); hc->attrFloat(initialShapeIndex, shape->getID(), key, v); break; } case prtx::Attributable::PT_BOOL: { - const auto v = shape->getBool(key); + const auto v = shape->getBool(keyStr); hc->attrBool(initialShapeIndex, shape->getID(), key, (v == prtx::PRTX_TRUE)); break; } From 5977158becd69680848b50889f28039ce47d0382 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 15:29:20 +0200 Subject: [PATCH 12/54] array attributes: pass from encoder to callbacks --- src/codec/encoder/HoudiniEncoder.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/codec/encoder/HoudiniEncoder.cpp b/src/codec/encoder/HoudiniEncoder.cpp index 07e710da..beb14cdb 100644 --- a/src/codec/encoder/HoudiniEncoder.cpp +++ b/src/codec/encoder/HoudiniEncoder.cpp @@ -302,6 +302,24 @@ void forwardGenericAttributes(HoudiniCallbacks* hc, size_t initialShapeIndex, co hc->attrBool(initialShapeIndex, shape->getID(), key, (v == prtx::PRTX_TRUE)); break; } + case prtx::Attributable::PT_STRING_ARRAY: { + const prtx::WStringVector& v = shape->getStringArray(keyStr); + const std::vector vPtrs = toPtrVec(v); + hc->attrStringArray(initialShapeIndex, shape->getID(), key, vPtrs.data(), vPtrs.size(), 1); + break; + } + case prtx::Attributable::PT_FLOAT_ARRAY: { + const prtx::DoubleVector& v = shape->getFloatArray(keyStr); + hc->attrFloatArray(initialShapeIndex, shape->getID(), key, v.data(), v.size(), 1); + break; + } + case prtx::Attributable::PT_BOOL_ARRAY: { + const prtx::BoolVector& v = shape->getBoolArray(keyStr); + const std::unique_ptr vPtrs(new bool[v.size()]); + for (size_t i = 0; i < v.size(); i++) vPtrs[i] = prtx::toPrimitive(v[i]); + hc->attrBoolArray(initialShapeIndex, shape->getID(), key, vPtrs.get(), v.size(), 1); + break; + } default: break; } From 2f5384bf236f72b0906068b0eed0db35776095d2 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 15:30:14 +0200 Subject: [PATCH 13/54] array attributes: receive array attrs from encoder callbacks --- src/palladio/ModelConverter.cpp | 29 +++++++++++++++++++++++++++++ src/palladio/ModelConverter.h | 12 +++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/palladio/ModelConverter.cpp b/src/palladio/ModelConverter.cpp index a9c160cb..842f287c 100644 --- a/src/palladio/ModelConverter.cpp +++ b/src/palladio/ModelConverter.cpp @@ -278,3 +278,32 @@ prt::Status ModelConverter::attrString(size_t isIndex, int32_t shapeID, const wc getBuilder(mShapeAttributeBuilders, shapeID)->setString(key, value); return prt::STATUS_OK; } + +#if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 1) + +prt::Status ModelConverter::attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, + size_t size, size_t nRows) { + if (DBG) + LOG_DBG << "attrBoolArray: shapeID :" << shapeID << ", key: " << key << ", val: " << ptr << ", size: " << size; + getBuilder(mShapeAttributeBuilders, shapeID)->setBoolArray(key, ptr, size); + return prt::STATUS_OK; +} + +prt::Status ModelConverter::attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, + size_t size, size_t nRows) { + if (DBG) + LOG_DBG << "attrFloatArray: shapeID :" << shapeID << ", key: " << key << ", val: " << ptr << ", size: " << size; + getBuilder(mShapeAttributeBuilders, shapeID)->setFloatArray(key, ptr, size); + return prt::STATUS_OK; +} + +prt::Status ModelConverter::attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, + const wchar_t* const* ptr, size_t size, size_t nRows) { + if (DBG) + LOG_DBG << "attrStringArray: shapeID :" << shapeID << ", key: " << key << ", val: " << ptr + << ", size: " << size; + getBuilder(mShapeAttributeBuilders, shapeID)->setStringArray(key, ptr, size); + return prt::STATUS_OK; +} + +#endif \ No newline at end of file diff --git a/src/palladio/ModelConverter.h b/src/palladio/ModelConverter.h index 077c6dde..84f93142 100644 --- a/src/palladio/ModelConverter.h +++ b/src/palladio/ModelConverter.h @@ -82,17 +82,11 @@ class ModelConverter : public HoudiniCallbacks { #if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 1) prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, - size_t nRows) override { - return prt::STATUS_OK; - } + size_t nRows) override; prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, - size_t nRows) override { - return prt::STATUS_OK; - } + size_t nRows) override; prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, - size_t size, size_t nRows) override { - return prt::STATUS_OK; - } + size_t size, size_t nRows) override; #elif (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size) override { From b1645005f44b855590a56c18a77237cc2fb58ced Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Tue, 21 Jul 2020 17:04:24 +0200 Subject: [PATCH 14/54] array attributes: conversion support to real primitive array attributes --- src/palladio/AttributeConversion.cpp | 153 ++++++++++++++++++++++----- src/palladio/AttributeConversion.h | 5 +- 2 files changed, 131 insertions(+), 27 deletions(-) diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index 42b613d0..0bdc1bfd 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -40,8 +40,8 @@ void setHandleRange(const GA_IndexMap& indexMap, H& handle, GA_Offset start, GA_ const V& value); template <> -void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleC& handle, GA_Offset start, GA_Size size, - int component, const bool& value) { +void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleC& handle, GA_Offset start, GA_Size size, int component, + const bool& value) { constexpr int8_t valFalse = 0; constexpr int8_t valTrue = 1; const int8_t hv = value ? valTrue : valFalse; @@ -52,8 +52,8 @@ void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleC& handle, GA_ } template <> -void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleI& handle, GA_Offset start, GA_Size size, - int component, const int32_t& value) { +void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleI& handle, GA_Offset start, GA_Size size, int component, + const int32_t& value) { handle.setBlock(start, size, &value, 0, component); if (DBG) LOG_DBG << "int attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() @@ -61,8 +61,8 @@ void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleI& handle, GA_ } template <> -void setHandleRange(const GA_IndexMap& indexMap, const GA_RWHandleF& handle, GA_Offset start, GA_Size size, - int component, const double& value) { +void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleF& handle, GA_Offset start, GA_Size size, int component, + const double& value) { const auto hv = static_cast(value); handle.setBlock(start, size, &hv, 0, component); // using stride = 0 to always set the same value if (DBG) @@ -91,6 +91,52 @@ void setHandleRange(const GA_IndexMap& indexMap, GA_RWBatchHandleS& handle, GA_O << "): " << handle.getAttribute()->getName() << " = " << attrValue; } +void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleDA& handle, GA_Offset start, GA_Size size, + const double* ptr, size_t ptrSize) { + UT_Fpreal64Array hv; + hv.append(ptr, ptrSize); + for (GA_Offset off = start; off < start + size; off++) + handle.set(off, hv); + if (DBG) + LOG_DBG << "float array attr: range = [" << start << ", " << start + size + << "): " << handle.getAttribute()->getName() << " = " << hv; +} + +void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleIA& handle, GA_Offset start, GA_Size size, + const int32_t* ptr, size_t ptrSize) { + UT_Int32Array hv; + hv.append(ptr, ptrSize); + for (GA_Offset off = start; off < start + size; off++) + handle.set(off, hv); + if (DBG) + LOG_DBG << "int array attr: range = [" << start << ", " << start + size + << "): " << handle.getAttribute()->getName() << " = " << hv; +} + +void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleIA& handle, GA_Offset start, GA_Size size, const bool* ptr, + size_t ptrSize) { + UT_IntArray hv(ptrSize, ptrSize); // there is no UT_Int8Array + for (size_t i = 0; i < ptrSize; i++) + hv[i] = ptr[i] ? 1u : 0u; + for (GA_Offset off = start; off < start + size; off++) + handle.set(off, hv); + if (DBG) + LOG_DBG << "int array attr: range = [" << start << ", " << start + size + << "): " << handle.getAttribute()->getName() << " = " << hv; +} + +void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleSA& handle, GA_Offset start, GA_Size size, + wchar_t const* const* ptr, size_t ptrSize) { + UT_StringArray hv(ptrSize, ptrSize); + for (size_t i = 0; i < ptrSize; i++) + hv[i] = UT_StringHolder(toOSNarrowFromUTF16(ptr[i])); + for (GA_Offset off = start; off < start + size; off++) + handle.set(off, hv); + if (DBG) + LOG_DBG << "int array attr: range = [" << start << ", " << start + size + << "): " << handle.getAttribute()->getName() << " = " << hv; +} + class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { private: const AttributeConversion::ProtoHandle& protoHandle; @@ -124,27 +170,27 @@ class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { } } - void operator()(const GA_RWHandleI& handle) const { + void operator()(GA_RWHandleI& handle) const { if (protoHandle.type == prt::Attributable::PT_INT) { const int32_t v = attrMap->getInt(protoHandle.key.c_str()); setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); } else if (protoHandle.type == prt::Attributable::PT_INT_ARRAY) { - LOG_ERR << "int arrays not yet implemented"; + LOG_ERR << "int arrays as tuples not yet implemented"; } } - void operator()(const GA_RWHandleC& handle) const { + void operator()(GA_RWHandleC& handle) const { if (protoHandle.type == prt::Attributable::PT_BOOL) { const bool v = attrMap->getBool(protoHandle.key.c_str()); setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); } else if (protoHandle.type == prt::Attributable::PT_BOOL_ARRAY) { - LOG_ERR << "bool arrays not yet implemented"; + LOG_ERR << "bool arrays as tuples not yet implemented"; } } - void operator()(const GA_RWHandleF& handle) const { + void operator()(GA_RWHandleF& handle) const { if (protoHandle.type == prt::Attributable::PT_FLOAT) { const auto v = attrMap->getFloat(protoHandle.key.c_str()); setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); @@ -157,6 +203,31 @@ class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { } } } + + void operator()(GA_RWHandleDA& handle) const { + size_t arraySize = 0; + const double* const array = attrMap->getFloatArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); + } + + void operator()(GA_RWHandleIA& handle) const { + if (protoHandle.type == prt::Attributable::PT_BOOL_ARRAY) { + size_t arraySize = 0; + const bool* array = attrMap->getBoolArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); + } + else { + size_t arraySize = 0; + const int32_t* array = attrMap->getIntArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); + } + } + + void operator()(GA_RWHandleSA& handle) const { + size_t arraySize = 0; + wchar_t const* const* const array = attrMap->getStringArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); + } }; void addProtoHandle(AttributeConversion::HandleMap& handleMap, const std::wstring& handleName, @@ -215,7 +286,7 @@ void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMa } } -void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap) { +void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArrayTypes) { WA("all"); for (auto& hm : handleMap) { @@ -227,31 +298,63 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap) { switch (type) { case prt::Attributable::PT_BOOL: case prt::Attributable::PT_BOOL_ARRAY: { - GA_RWHandleC h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality, GA_Defaults(0), - nullptr, nullptr, GA_STORE_INT8)); - if (h.isValid()) - handle = h; + if (useArrayTypes && (type == prt::Attributable::PT_BOOL_ARRAY)) { + GA_RWHandleIA h( + detail->addIntArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_INT8)); + if (h.isValid()) + handle = h; + } + else { + GA_RWHandleC h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality, + GA_Defaults(0), nullptr, nullptr, GA_STORE_INT8)); + if (h.isValid()) + handle = h; + } break; } case prt::Attributable::PT_FLOAT: case prt::Attributable::PT_FLOAT_ARRAY: { - GA_RWHandleF h(detail->addFloatTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); - if (h.isValid()) - handle = h; + if (useArrayTypes && (type == prt::Attributable::PT_FLOAT_ARRAY)) { + GA_RWHandleDA h( + detail->addFloatArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_REAL64)); + if (h.isValid()) + handle = h; + } + else { + GA_RWHandleF h(detail->addFloatTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); + if (h.isValid()) + handle = h; + } break; } case prt::Attributable::PT_INT: case prt::Attributable::PT_INT_ARRAY: { - GA_RWHandleI h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); - if (h.isValid()) - handle = h; + if (useArrayTypes && (type == prt::Attributable::PT_INT_ARRAY)) { + GA_RWHandleIA h( + detail->addIntArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_INT32)); + if (h.isValid()) + handle = h; + } + else { + GA_RWHandleI h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); + if (h.isValid()) + handle = h; + } break; } case prt::Attributable::PT_STRING: case prt::Attributable::PT_STRING_ARRAY: { - GA_RWBatchHandleS h(detail->addStringTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); - if (h.isValid()) - handle = h; + if (useArrayTypes && (type == prt::Attributable::PT_STRING_ARRAY)) { + GA_RWHandleSA h( + detail->addStringArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_STRING)); + if (h.isValid()) + handle = h; + } + else { + GA_RWBatchHandleS h(detail->addStringTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); + if (h.isValid()) + handle = h; + } break; } default: diff --git a/src/palladio/AttributeConversion.h b/src/palladio/AttributeConversion.h index f601d017..00fd0149 100644 --- a/src/palladio/AttributeConversion.h +++ b/src/palladio/AttributeConversion.h @@ -47,7 +47,8 @@ namespace AttributeConversion { * double -> float (single precision!) */ using NoHandle = int8_t; -using HandleType = PLD_BOOST_NS::variant; +using HandleType = PLD_BOOST_NS::variant; // bound to life time of PRT attribute map struct ProtoHandle { @@ -60,7 +61,7 @@ struct ProtoHandle { using HandleMap = std::unordered_map; PLD_TEST_EXPORTS_API void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMap); -void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap); +void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArrayTypes = false); void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, const GA_IndexMap& primIndexMap, const GA_Offset rangeStart, const GA_Size rangeSize); From 719fd59072a677586f5437650d5dd5b13fefd486 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 08:40:22 +0200 Subject: [PATCH 15/54] array attributes: use arrays instead of tuples for rule attributes --- src/palladio/ModelConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/palladio/ModelConverter.cpp b/src/palladio/ModelConverter.cpp index 842f287c..d1d78a5f 100644 --- a/src/palladio/ModelConverter.cpp +++ b/src/palladio/ModelConverter.cpp @@ -203,7 +203,7 @@ void ModelConverter::add(const wchar_t* name, const double* vtx, size_t vtxSize, if (it != mShapeAttributeBuilders.end()) { const AttributeMapUPtr attrMap(it->second->createAttributeMap()); AttributeConversion::extractAttributeNames(handleMap, attrMap.get()); - AttributeConversion::createAttributeHandles(mDetail, handleMap); + AttributeConversion::createAttributeHandles(mDetail, handleMap, true); AttributeConversion::setAttributeValues(handleMap, attrMap.get(), primIndexMap, rangeStart, rangeSize); } From 0c70b09bd4ff076d3b04d5a6cec819f1be5e1ca3 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 10:49:41 +0200 Subject: [PATCH 16/54] cleanup: remove unnecessary templates, these are just normal overloads --- src/palladio/AttributeConversion.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index 0bdc1bfd..db1e1891 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -35,11 +35,6 @@ namespace StringConversionCaches { LockedLRUCache toPrimAttr(1 << 12); } -template -void setHandleRange(const GA_IndexMap& indexMap, H& handle, GA_Offset start, GA_Size size, int component, - const V& value); - -template <> void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleC& handle, GA_Offset start, GA_Size size, int component, const bool& value) { constexpr int8_t valFalse = 0; @@ -51,7 +46,6 @@ void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleC& handle, GA_Offset << " = " << value; } -template <> void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleI& handle, GA_Offset start, GA_Size size, int component, const int32_t& value) { handle.setBlock(start, size, &value, 0, component); @@ -60,7 +54,6 @@ void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleI& handle, GA_Offset << " = " << value; } -template <> void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleF& handle, GA_Offset start, GA_Size size, int component, const double& value) { const auto hv = static_cast(value); @@ -70,7 +63,6 @@ void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleF& handle, GA_Offset << "): " << handle.getAttribute()->getName() << " = " << value; } -template <> void setHandleRange(const GA_IndexMap& indexMap, GA_RWBatchHandleS& handle, GA_Offset start, GA_Size size, int component, const std::wstring& value) { const UT_String attrValue = [&value]() { From e5f2d1b09dbdb9ccfe0f8862c0a0eb34deaceca5 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 11:24:18 +0200 Subject: [PATCH 17/54] cleanup: avoid code copy in attribute conversion --- src/palladio/AttributeConversion.cpp | 8 ++++++++ src/palladio/AttributeConversion.h | 8 ++++---- src/palladio/ModelConverter.cpp | 17 ++++------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index db1e1891..935a6b1c 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -375,6 +375,14 @@ void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, } } +void convertAttributes(GU_Detail* detail, HandleMap& handleMap, const prt::AttributeMap* attrMap, + const GA_Offset rangeStart, const GA_Size rangeSize, ArrayHandling arrayHandling) { + const GA_IndexMap& primIndexMap = detail->getIndexMap(GA_ATTRIB_PRIMITIVE); + extractAttributeNames(handleMap, attrMap); + createAttributeHandles(detail, handleMap, arrayHandling == ArrayHandling::ARRAY); + setAttributeValues(handleMap, attrMap, primIndexMap, rangeStart, rangeSize); +} + } // namespace AttributeConversion namespace { diff --git a/src/palladio/AttributeConversion.h b/src/palladio/AttributeConversion.h index 00fd0149..9db0f85d 100644 --- a/src/palladio/AttributeConversion.h +++ b/src/palladio/AttributeConversion.h @@ -60,10 +60,10 @@ struct ProtoHandle { using HandleMap = std::unordered_map; -PLD_TEST_EXPORTS_API void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMap); -void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArrayTypes = false); -void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, const GA_IndexMap& primIndexMap, - const GA_Offset rangeStart, const GA_Size rangeSize); +enum class ArrayHandling { TUPLE, ARRAY }; +void convertAttributes(GU_Detail* detail, HandleMap& handleMap, const prt::AttributeMap* attrMap, + const GA_Offset rangeStart, const GA_Size rangeSize, + ArrayHandling arrayHandling = ArrayHandling::TUPLE); } // namespace AttributeConversion diff --git a/src/palladio/ModelConverter.cpp b/src/palladio/ModelConverter.cpp index d1d78a5f..f95c942d 100644 --- a/src/palladio/ModelConverter.cpp +++ b/src/palladio/ModelConverter.cpp @@ -177,23 +177,16 @@ void ModelConverter::add(const wchar_t* name, const double* vtx, size_t vtxSize, WA("add materials/reports"); AttributeConversion::HandleMap handleMap; - const GA_IndexMap& primIndexMap = mDetail->getIndexMap(GA_ATTRIB_PRIMITIVE); for (size_t fri = 0; fri < faceRangesSize - 1; fri++) { const GA_Offset rangeStart = primStartOffset + faceRanges[fri]; const GA_Size rangeSize = faceRanges[fri + 1] - faceRanges[fri]; if (materials != nullptr) { - const prt::AttributeMap* attrMap = materials[fri]; - AttributeConversion::extractAttributeNames(handleMap, attrMap); - AttributeConversion::createAttributeHandles(mDetail, handleMap); - AttributeConversion::setAttributeValues(handleMap, attrMap, primIndexMap, rangeStart, rangeSize); + AttributeConversion::convertAttributes(mDetail, handleMap, materials[fri], rangeStart, rangeSize); } if (reports != nullptr) { - const prt::AttributeMap* attrMap = reports[fri]; - AttributeConversion::extractAttributeNames(handleMap, attrMap); - AttributeConversion::createAttributeHandles(mDetail, handleMap); - AttributeConversion::setAttributeValues(handleMap, attrMap, primIndexMap, rangeStart, rangeSize); + AttributeConversion::convertAttributes(mDetail, handleMap, reports[fri], rangeStart, rangeSize); } if (!mShapeAttributeBuilders.empty()) { @@ -202,10 +195,8 @@ void ModelConverter::add(const wchar_t* name, const double* vtx, size_t vtxSize, auto it = mShapeAttributeBuilders.find(shapeID); if (it != mShapeAttributeBuilders.end()) { const AttributeMapUPtr attrMap(it->second->createAttributeMap()); - AttributeConversion::extractAttributeNames(handleMap, attrMap.get()); - AttributeConversion::createAttributeHandles(mDetail, handleMap, true); - AttributeConversion::setAttributeValues(handleMap, attrMap.get(), primIndexMap, rangeStart, - rangeSize); + AttributeConversion::convertAttributes(mDetail, handleMap, attrMap.get(), rangeStart, rangeSize, + AttributeConversion::ArrayHandling::ARRAY); } } } From 95c340ab2eba2bd3b5c1b54c62e677b2b117171a Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 16:08:12 +0200 Subject: [PATCH 18/54] tests: fix TestCallbacks for tests without attributes --- src/test/TestCallbacks.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/TestCallbacks.h b/src/test/TestCallbacks.h index a9363e48..f7fa9034 100644 --- a/src/test/TestCallbacks.h +++ b/src/test/TestCallbacks.h @@ -81,7 +81,8 @@ class TestCallbacks : public HoudiniCallbacks { for (size_t si = 0; si < faceRangesSize - 1; si++) { const int32_t sid = shapeIDs[si]; - cr.attrsPerShapeID.emplace(sid, AttributeMapUPtr(attrs.at(sid)->createAttributeMap())); + if (attrs.count(sid) > 0) + cr.attrsPerShapeID.emplace(sid, AttributeMapUPtr(attrs.at(sid)->createAttributeMap())); } attrs.clear(); } From 51846db8218e65606d0b2042b262ba8c045eb20b Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 16:08:31 +0200 Subject: [PATCH 19/54] tests: fix TestCallbacks for API changes in PRT 2.2 --- src/test/TestCallbacks.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/TestCallbacks.h b/src/test/TestCallbacks.h index f7fa9034..8d5a6f59 100644 --- a/src/test/TestCallbacks.h +++ b/src/test/TestCallbacks.h @@ -117,6 +117,34 @@ class TestCallbacks : public HoudiniCallbacks { return prt::STATUS_OK; } +#if (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 1) + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, size_t size, + size_t nRows) override { + return prt::STATUS_OK; + } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, size_t size, + size_t nRows) override { + return prt::STATUS_OK; + } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, + size_t size, size_t nRows) override { + return prt::STATUS_OK; + } +#elif (PRT_VERSION_MAJOR > 1 && PRT_VERSION_MINOR > 0) + prt::Status attrBoolArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const bool* ptr, + size_t size) override { + return prt::STATUS_OK; + } + prt::Status attrFloatArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const double* ptr, + size_t size) override { + return prt::STATUS_OK; + } + prt::Status attrStringArray(size_t isIndex, int32_t shapeID, const wchar_t* key, const wchar_t* const* ptr, + size_t size) override { + return prt::STATUS_OK; + } +#endif + prt::Status attrBool(size_t isIndex, int32_t shapeID, const wchar_t* key, bool value) override { auto it = attrs.emplace(shapeID, AttributeMapBuilderUPtr(prt::AttributeMapBuilder::create())); it.first->second->setBool(key, value); From fc0a0b982ae615df985779bda061322ef2c392c1 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 16:09:06 +0200 Subject: [PATCH 20/54] tests: update cmake script to sync it with main build --- src/test/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index fd9c3a4c..c2b764b4 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -13,7 +13,7 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE -DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data") if(PLD_LINUX) - target_compile_options(${PROJECT_NAME} PRIVATE -std=c++11) + target_compile_options(${PROJECT_NAME} PRIVATE -std=c++14) endif() target_include_directories(${PROJECT_NAME} PRIVATE @@ -30,6 +30,6 @@ pld_add_dependency_houdini(${PROJECT_NAME}) # copy libraries next to test excutable so they can be found add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${CMAKE_BINARY_DIR}/bin - COMMAND ${CMAKE_COMMAND} ARGS -E copy ${PRT_LIBRARIES} ${CMAKE_BINARY_DIR}/bin + COMMAND ${CMAKE_COMMAND} ARGS -E copy ${PLD_PRT_LIBRARIES} ${CMAKE_BINARY_DIR}/bin COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${CMAKE_BINARY_DIR}/lib - COMMAND ${CMAKE_COMMAND} ARGS -E copy ${PRT_EXT_LIBRARIES} ${CMAKE_BINARY_DIR}/lib) + COMMAND ${CMAKE_COMMAND} ARGS -E copy ${PLD_PRT_EXT_LIBRARIES} ${CMAKE_BINARY_DIR}/lib) From d7970d42b13fdaa5415ed7f89c0c39cfcc29728a Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 17:39:42 +0200 Subject: [PATCH 21/54] conan: adding profile for MSVC 14.2 (Visual Studio 2019 toolchain) --- conan/profiles/windows-v142 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 conan/profiles/windows-v142 diff --git a/conan/profiles/windows-v142 b/conan/profiles/windows-v142 new file mode 100644 index 00000000..b71df0a7 --- /dev/null +++ b/conan/profiles/windows-v142 @@ -0,0 +1,15 @@ +[settings] +os=Windows +os_build=Windows +arch=x86_64 +arch_build=x86_64 +build_type=Release +compiler=Visual Studio +compiler.version=16 +compiler.runtime=MD + +[options] + +[build_requires] + +[env] From eae56e84647a1ac28ec100f69f13cba3ec76c08d Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 17:40:34 +0200 Subject: [PATCH 22/54] conan: updating conan package for CE SDK with MSVC 14.2 toolchain requirement on Windows --- conan/cesdk/conanfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conan/cesdk/conanfile.py b/conan/cesdk/conanfile.py index af850fd7..00419443 100644 --- a/conan/cesdk/conanfile.py +++ b/conan/cesdk/conanfile.py @@ -1,6 +1,6 @@ from conans import ConanFile from conans import tools - +from conans.model.version import Version class CESDKConan(ConanFile): name = "cesdk" @@ -12,7 +12,8 @@ class CESDKConan(ConanFile): def build(self): if self.settings.os == "Windows": - url = self.baseURL.format(self.version, self.version, "win10", "vc141") + toolchain = "vc142" if self.version >= Version("2.2.6332") else "vc141" + url = self.baseURL.format(self.version, self.version, "win10", toolchain) elif self.settings.os == "Linux": url = self.baseURL.format(self.version, self.version, "rhel7", "gcc63") elif self.settings.os == "Macos": From 10f542698b4557c9f8e78b5278578cd9ca043acc Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Wed, 22 Jul 2020 17:40:58 +0200 Subject: [PATCH 23/54] cmake: call conan on Windows with MSVC 14.2 toolchain profile --- src/dependencies.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dependencies.cmake b/src/dependencies.cmake index bbc535c4..fd9dbb1a 100644 --- a/src/dependencies.cmake +++ b/src/dependencies.cmake @@ -44,7 +44,7 @@ endif() ### run conan if(PLD_WINDOWS) - set(PLD_CONAN_PROFILE "${PLD_CONAN_TOOLS}/profiles/windows-v141") + set(PLD_CONAN_PROFILE "${PLD_CONAN_TOOLS}/profiles/windows-v142") elseif(PLD_LINUX) set(PLD_CONAN_PROFILE "${PLD_CONAN_TOOLS}/profiles/linux-gcc63") endif() From 7832a2c7ca981379cc534189e026b185cbc4b06c Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Thu, 23 Jul 2020 18:08:43 +0200 Subject: [PATCH 24/54] conan: fix deprecated version range syntax --- src/conanfile-h17.py | 2 +- src/conanfile-h175.py | 2 +- src/conanfile-h180.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conanfile-h17.py b/src/conanfile-h17.py index d40e73fd..f7974417 100644 --- a/src/conanfile-h17.py +++ b/src/conanfile-h17.py @@ -12,7 +12,7 @@ def requirements(self): if "PLD_CONAN_HOUDINI_VERSION" in os.environ: self.requires("houdini/{}@sidefx/stable".format(os.environ["PLD_CONAN_HOUDINI_VERSION"])) else: - self.requires("houdini/[>17.0.0,<17.5.0]@sidefx/stable") + self.requires("houdini/[>17.0.0 <17.5.0]@sidefx/stable") if "PLD_CONAN_SKIP_CESDK" not in os.environ: if "PLD_CONAN_CESDK_VERSION" in os.environ: diff --git a/src/conanfile-h175.py b/src/conanfile-h175.py index ccd852a3..f125bbdc 100644 --- a/src/conanfile-h175.py +++ b/src/conanfile-h175.py @@ -12,7 +12,7 @@ def requirements(self): if "PLD_CONAN_HOUDINI_VERSION" in os.environ: self.requires("houdini/{}@sidefx/stable".format(os.environ["PLD_CONAN_HOUDINI_VERSION"])) else: - self.requires("houdini/[>17.5.0,<18.0.0]@sidefx/stable") + self.requires("houdini/[>17.5.0 <18.0.0]@sidefx/stable") if "PLD_CONAN_SKIP_CESDK" not in os.environ: if "PLD_CONAN_CESDK_VERSION" in os.environ: diff --git a/src/conanfile-h180.py b/src/conanfile-h180.py index a7887f7c..04a219d0 100644 --- a/src/conanfile-h180.py +++ b/src/conanfile-h180.py @@ -12,7 +12,7 @@ def requirements(self): if "PLD_CONAN_HOUDINI_VERSION" in os.environ: self.requires("houdini/{}@sidefx/stable".format(os.environ["PLD_CONAN_HOUDINI_VERSION"])) else: - self.requires("houdini/[>18.0.0,<18.5.0]@sidefx/stable") + self.requires("houdini/[>18.0.0 <18.5.0]@sidefx/stable") if "PLD_CONAN_SKIP_CESDK" not in os.environ: if "PLD_CONAN_CESDK_VERSION" in os.environ: From e11f91e17c93d39b0b943678173f4ab26c28fa21 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Fri, 24 Jul 2020 09:12:49 +0200 Subject: [PATCH 25/54] pipeline: switch Windows builds to MSVC 14.2x --- pipeline.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pipeline.groovy b/pipeline.groovy index 7a5632ea..44b32e82 100644 --- a/pipeline.groovy +++ b/pipeline.groovy @@ -19,17 +19,17 @@ import com.esri.zrh.jenkins.ce.PrtAppPipelineLibrary @Field final List CONFIGS_HOUDINI_170 = [ [ os: cepl.CFG_OS_RHEL7, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_GCC63, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.0' ], - [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC141, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.0' ], + [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC142, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.0' ], ] @Field final List CONFIGS_HOUDINI_175 = [ [ os: cepl.CFG_OS_RHEL7, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_GCC63, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.5' ], - [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC141, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.5' ], + [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC142, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.5' ], ] @Field final List CONFIGS_HOUDINI_180 = [ [ os: cepl.CFG_OS_RHEL7, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_GCC63, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '18.0' ], - [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC141, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '18.0' ], + [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC142, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '18.0' ], ] // -- PIPELINE From 0296cb01091b391066f5f0437f87862a5896a7aa Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Fri, 24 Jul 2020 10:18:21 +0200 Subject: [PATCH 26/54] conan: declare Houdini package compatible with GCC 6/8 and MSVC 14.1/14.2 --- conan/houdini/conanfile.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/conan/houdini/conanfile.py b/conan/houdini/conanfile.py index 70920a6d..0409cc81 100644 --- a/conan/houdini/conanfile.py +++ b/conan/houdini/conanfile.py @@ -1,4 +1,5 @@ from conans import ConanFile +from conans.model.version import Version import os class HoudiniConan(ConanFile): @@ -38,3 +39,10 @@ def package_info(self): self.cpp_info.libdirs = ['dsolib'] self.cpp_info.libs = ['HoudiniUI', 'HoudiniOPZ', 'HoudiniOP3', 'HoudiniOP2', 'HoudiniOP1', 'HoudiniGEO', 'HoudiniPRM', 'HoudiniUT'] + + def package_id(self): + v = Version(str(self.settings.compiler.version)) + if self.settings.compiler == "Visual Studio" and ("15" <= v <= "16"): + self.info.settings.compiler.version = "Compatible with MSVC 14.1 and 14.2" + elif self.settings.compiler == "gcc" and ("6" <= v < "9"): + self.info.settings.compiler.version = "Compatible with GCC 6 tru 8" From 3cf8e72d26266d78ac2edcfe7e240a9d8a2a5147 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Fri, 24 Jul 2020 10:32:33 +0200 Subject: [PATCH 27/54] pipeline: stop building for Houdini 17.0 --- pipeline.groovy | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pipeline.groovy b/pipeline.groovy index 44b32e82..896de01e 100644 --- a/pipeline.groovy +++ b/pipeline.groovy @@ -17,11 +17,6 @@ import com.esri.zrh.jenkins.ce.PrtAppPipelineLibrary @Field final String SOURCE = "palladio.git/src" @Field final String BUILD_TARGET = 'package' -@Field final List CONFIGS_HOUDINI_170 = [ - [ os: cepl.CFG_OS_RHEL7, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_GCC63, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.0' ], - [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC142, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.0' ], -] - @Field final List CONFIGS_HOUDINI_175 = [ [ os: cepl.CFG_OS_RHEL7, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_GCC63, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.5' ], [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC142, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64, houdini: '17.5' ], @@ -57,7 +52,6 @@ Map getTasks(String branchName = null) { Map taskGenPalladio() { Map tasks = [:] // FIXME: this is a workaround to get unique task names - tasks << cepl.generateTasks('pld-hdn17.0', this.&taskBuildPalladio, CONFIGS_HOUDINI_170) tasks << cepl.generateTasks('pld-hdn17.5', this.&taskBuildPalladio, CONFIGS_HOUDINI_175) tasks << cepl.generateTasks('pld-hdn18.0', this.&taskBuildPalladio, CONFIGS_HOUDINI_180) return tasks; From da9bd98c37677a782fd5334f7e5ad497e53b0343 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Fri, 24 Jul 2020 10:59:38 +0200 Subject: [PATCH 28/54] cleanup: fix sign mismatch compiler warnings --- src/codec/encoder/HoudiniEncoder.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/codec/encoder/HoudiniEncoder.cpp b/src/codec/encoder/HoudiniEncoder.cpp index beb14cdb..745aa25e 100644 --- a/src/codec/encoder/HoudiniEncoder.cpp +++ b/src/codec/encoder/HoudiniEncoder.cpp @@ -402,8 +402,8 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, const prtx::MaterialPtrVector& mats = *matsIt; auto matIt = mats.cbegin(); for (const auto& mesh : meshes) { - numCoords += mesh->getVertexCoords().size(); - numNormalCoords += mesh->getVertexNormalsCoords().size(); + numCoords += static_cast(mesh->getVertexCoords().size()); + numNormalCoords += static_cast(mesh->getVertexNormalsCoords().size()); numCounts += mesh->getFaceCount(); const auto& vtxCnts = mesh->getFaceVertexCounts(); @@ -459,7 +459,7 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, log_debug(" -- uvset %1%: face counts size = %2%") % uvSet % faceUVCounts.size(); // append uv vertex indices - for (uint32_t fi = 0, faceCount = faceUVCounts.size(); fi < faceCount; ++fi) { + for (uint32_t fi = 0, faceCount = static_cast(faceUVCounts.size()); fi < faceCount; ++fi) { const uint32_t* faceUVIdx0 = (numUVSets > 0) ? mesh->getFaceUVIndices(fi, 0) : EMPTY_IDX.data(); const uint32_t* faceUVIdx = (uvSet < numUVSets && !uvs.empty()) ? mesh->getFaceUVIndices(fi, uvSet) : faceUVIdx0; @@ -472,7 +472,7 @@ SerializedGeometry serializeGeometry(const prtx::GeometryPtrVector& geometries, faceUVIdx[faceUVCnt - vi - 1]); // reverse winding } - uvIndexBases[uvSet] += src.size() / 2u; + uvIndexBases[uvSet] += static_cast(src.size()) / 2u; } // for all uv sets // append counts and indices for vertices and vertex normals @@ -623,7 +623,7 @@ void HoudiniEncoder::convertGeometry(const prtx::InitialShape& initialShape, sg.counts.data(), sg.counts.size(), sg.indices.data(), sg.indices.size(), puvs.first.data(), puvs.second.data(), puvCounts.first.data(), puvCounts.second.data(), - puvIndices.first.data(), puvIndices.second.data(), sg.uvs.size(), + puvIndices.first.data(), puvIndices.second.data(), static_cast(sg.uvs.size()), faceRanges.data(), faceRanges.size(), matAttrMaps.v.empty() ? nullptr : matAttrMaps.v.data(), reportAttrMaps.v.empty() ? nullptr : reportAttrMaps.v.data(), shapeIDs.data()); From 934fb6f88ab7deb81e85b244fa7b0374523ab9f5 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Fri, 24 Jul 2020 11:42:32 +0200 Subject: [PATCH 29/54] Print info log entry with version once Palladio is fully loaded. --- src/CMakeLists.txt | 9 +++++++++ src/palladio/CMakeLists.txt | 1 + src/palladio/PalladioMain.cpp | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a55f51b..d1baebd5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,6 +58,15 @@ set(PLD_VERSION "${PLD_VERSION_MAJOR}.${PLD_VERSION_MINOR}.${PLD_VERSION_PATCH}$ .prt${PRT_VERSION_MAJOR}-${PRT_VERSION_MINOR}-${PRT_VERSION_MICRO}") message(STATUS "Using PLD_VERSION = ${PLD_VERSION}") +function(pld_add_version_definitions TGT) + target_compile_definitions(${TGT} PRIVATE + -DPLD_VERSION_MAJOR=${PLD_VERSION_MAJOR} + -DPLD_VERSION_MINOR=${PLD_VERSION_MINOR} + -DPLD_VERSION_PATCH=${PLD_VERSION_PATCH} + -DPLD_VERSION_PRE=\"${PLD_VERSION_PRE}\" # quoted, might be a string + -DPLD_VERSION_BUILD=${PLD_VERSION_BUILD} + -DPLD_VERSION=\"${PLD_VERSION}\") # quoted, is a string +endfunction() ### setup installation target diff --git a/src/palladio/CMakeLists.txt b/src/palladio/CMakeLists.txt index a56009cf..7114d306 100644 --- a/src/palladio/CMakeLists.txt +++ b/src/palladio/CMakeLists.txt @@ -37,6 +37,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ### compiler settings add_toolchain_definition(${PROJECT_NAME}) +pld_add_version_definitions(${PROJECT_NAME}) if(PLD_TEST) message(STATUS "Enabling test exports...") diff --git a/src/palladio/PalladioMain.cpp b/src/palladio/PalladioMain.cpp index faa061ef..ed6d2405 100644 --- a/src/palladio/PalladioMain.cpp +++ b/src/palladio/PalladioMain.cpp @@ -20,6 +20,7 @@ #include "PRTContext.h" #include "SOPAssign.h" #include "SOPGenerate.h" +#include "LogHandler.h" #include "OP/OP_OperatorTable.h" #include "UT/UT_Exit.h" @@ -57,4 +58,6 @@ void newSopOperator(OP_OperatorTable* table) { }; table->addOperator(new OP_Operator(OP_PLD_GENERATE, OP_PLD_GENERATE, createSOPGenerate, GenerateNodeParams::PARAM_TEMPLATES, 1, 1, nullptr, OP_FLAG_GENERATOR)); + + LOG_INF << "Palladio " << PLD_VERSION << " initialized."; } From af423855b99e8b1130b7508efec0e2fa5e74b796 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Thu, 30 Jul 2020 09:04:51 +0200 Subject: [PATCH 30/54] review: fix copy/paste errors Co-authored-by: Benjamin Neukom --- src/palladio/AttributeConversion.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index 935a6b1c..d49ac5b8 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -113,7 +113,7 @@ void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleIA& handle, GA_Offse for (GA_Offset off = start; off < start + size; off++) handle.set(off, hv); if (DBG) - LOG_DBG << "int array attr: range = [" << start << ", " << start + size + LOG_DBG << "bool array attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() << " = " << hv; } @@ -125,7 +125,7 @@ void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleSA& handle, GA_Offse for (GA_Offset off = start; off < start + size; off++) handle.set(off, hv); if (DBG) - LOG_DBG << "int array attr: range = [" << start << ", " << start + size + LOG_DBG << "string array attr: range = [" << start << ", " << start + size << "): " << handle.getAttribute()->getName() << " = " << hv; } @@ -453,4 +453,4 @@ void separate(const std::wstring& fqName, std::wstring& style, std::wstring& nam } } -} // namespace NameConversion \ No newline at end of file +} // namespace NameConversion From 76745cdea93a20c93b0543791ae69f1342f5be10 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Thu, 30 Jul 2020 09:57:19 +0200 Subject: [PATCH 31/54] review: factor out attribute conversion into FromHoudini class --- src/palladio/AttributeConversion.h | 146 +++++++++++++++++++++++++++++ src/palladio/ShapeGenerator.cpp | 117 +---------------------- 2 files changed, 149 insertions(+), 114 deletions(-) diff --git a/src/palladio/AttributeConversion.h b/src/palladio/AttributeConversion.h index 9db0f85d..31deefa0 100644 --- a/src/palladio/AttributeConversion.h +++ b/src/palladio/AttributeConversion.h @@ -16,6 +16,7 @@ #pragma once +#include "LogHandler.h" #include "PalladioMain.h" #include "Utils.h" @@ -39,6 +40,151 @@ struct hash { namespace AttributeConversion { +class FromHoudini { +private: + static const bool DBG = true; + +public: + FromHoudini(prt::AttributeMapBuilder& builder) : mBuilder(builder) {} + + bool convert(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { + if (isArrayAttribute(ar)) + return handleArray(ar, offset, name); + else + return handleScalar(ar, offset, name); + } + +private: + bool handleScalar(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { + bool conversionResult = true; + switch (ar.getStorageClass()) { + case GA_STORECLASS_FLOAT: { + GA_ROHandleD av(ar); + if (av.isValid()) { + double v = av.get(offset); + if (DBG) + LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; + mBuilder.setFloat(name.c_str(), v); + } + break; + } + case GA_STORECLASS_STRING: { + GA_ROHandleS av(ar); + if (av.isValid()) { + const char* v = av.get(offset); + const std::wstring wv = toUTF16FromOSNarrow(v); + if (DBG) + LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; + mBuilder.setString(name.c_str(), wv.c_str()); + } + break; + } + case GA_STORECLASS_INT: { + if (ar.getAIFTuple()->getStorage(ar.get()) == GA_STORE_INT8) { + GA_ROHandleI av(ar); + if (av.isValid()) { + const int v = av.get(offset); + const bool bv = (v > 0); + if (DBG) + LOG_DBG << " prim bool attr: " << ar->getName() << " = " << bv; + mBuilder.setBool(name.c_str(), bv); + } + } + else { + GA_ROHandleI av(ar); + if (av.isValid()) { + const int v = av.get(offset); + if (DBG) + LOG_DBG << " prim int attr: " << ar->getName() << " = " << v; + mBuilder.setInt(name.c_str(), v); + } + } + break; + } + default: { + LOG_WRN << "prim attr " << ar->getName() << ": unsupported storage class"; + conversionResult = false; + break; + } + } + return conversionResult; + } + + bool handleArray(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { + bool conversionResult = true; + switch (ar.getStorageClass()) { + case GA_STORECLASS_FLOAT: { + GA_ROHandleDA av(ar); + if (av.isValid()) { + UT_Fpreal64Array v; + av.get(offset, v); + if (DBG) + LOG_DBG << " prim float array attr: " << ar->getName() << " = " << v; + mBuilder.setFloatArray(name.c_str(), v.data(), v.size()); + } + break; + } + case GA_STORECLASS_STRING: { + GA_ROHandleSA av(ar); + if (av.isValid()) { + UT_StringArray v; + av.get(offset, v); + if (DBG) + LOG_DBG << " prim string array attr: " << ar->getName() << " = " << v; + + std::vector wstrings(v.size()); + std::vector wstringPtrs(v.size()); + for (size_t i = 0; i < v.size(); i++) { + wstrings[i] = toUTF16FromOSNarrow(v[i].toStdString()); + wstringPtrs[i] = wstrings[i].c_str(); + } + mBuilder.setStringArray(name.c_str(), wstringPtrs.data(), wstringPtrs.size()); + } + break; + } + case GA_STORECLASS_INT: { + if (ar.getAIFNumericArray()->getStorage(ar.get()) == GA_STORE_INT8) { + GA_ROHandleIA av(ar); + if (av.isValid()) { + UT_Int32Array v; // there is no U_Int8Array + av.get(offset, v); + if (DBG) + LOG_DBG << " prim bool array attr: " << ar->getName() << " = " << v; + const std::unique_ptr vPtrs(new bool[v.size()]); + for (size_t i = 0; i < v.size(); i++) + vPtrs[i] = (v[i] > 0); + mBuilder.setBoolArray(name.c_str(), vPtrs.get(), v.size()); + } + } + else { + GA_ROHandleIA av(ar); + if (av.isValid()) { + UT_Int32Array v; + av.get(offset, v); + if (DBG) + LOG_DBG << " prim int array attr: " << ar->getName() << " = " << v; + mBuilder.setIntArray(name.c_str(), v.data(), v.size()); + } + } + break; + } + default: { + LOG_WRN << "prim attr " << ar->getName() << ": unsupported storage class"; + conversionResult = false; + break; + } + } + return conversionResult; + } + + bool isArrayAttribute(const GA_ROAttributeRef& ar) { + return (ar.getAIFNumericArray() != nullptr) || (ar.getAIFSharedStringArray() != nullptr); + } + +private: + prt::AttributeMapBuilder& mBuilder; +}; + /** * attribute type conversion from PRT to Houdini: * wstring -> narrow string diff --git a/src/palladio/ShapeGenerator.cpp b/src/palladio/ShapeGenerator.cpp index 780a4207..7925efe7 100644 --- a/src/palladio/ShapeGenerator.cpp +++ b/src/palladio/ShapeGenerator.cpp @@ -41,10 +41,6 @@ std::wstring getFullyQualifiedStartRule(const MainAttributes& ma) { return ma.mStyle + L'$' + ma.mStartRule; } -bool isArrayAttribute(const GA_ROAttributeRef& ar) { - return (ar.getAIFNumericArray() != nullptr) || (ar.getAIFSharedStringArray() != nullptr); -} - } // namespace void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& primCls, ShapeData& shapeData, @@ -105,122 +101,15 @@ void ShapeGenerator::get(const GU_Detail* detail, const PrimitiveClassifier& pri // extract primitive attributes AttributeMapBuilderUPtr amb(prt::AttributeMapBuilder::create()); + AttributeConversion::FromHoudini fromHoudini(*amb); for (const auto& attr : attributes) { const GA_ROAttributeRef& ar = attr.second; - if (ar.isInvalid()) continue; const std::wstring ruleAttrName = NameConversion::toRuleAttr(ma.mStyle, attr.first); - - switch (ar.getStorageClass()) { - case GA_STORECLASS_FLOAT: { - if (isArrayAttribute(ar)) { - GA_ROHandleDA av(ar); - if (av.isValid()) { - UT_Fpreal64Array v; - av.get(primitiveMapOffset, v); - if (DBG) - LOG_DBG << " prim float array attr: " << ar->getName() << " = " << v; - amb->setFloatArray(ruleAttrName.c_str(), v.data(), v.size()); - } - } - else { - GA_ROHandleD av(ar); - if (av.isValid()) { - double v = av.get(primitiveMapOffset); - if (DBG) - LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; - amb->setFloat(ruleAttrName.c_str(), v); - } - } - break; - } - case GA_STORECLASS_STRING: { - if (isArrayAttribute(ar)) { - GA_ROHandleSA av(ar); - if (av.isValid()) { - UT_StringArray v; - av.get(primitiveMapOffset, v); - if (DBG) - LOG_DBG << " prim string array attr: " << ar->getName() << " = " << v; - - std::vector wstrings(v.size()); - std::vector wstringPtrs(v.size()); - for (size_t i = 0; i < v.size(); i++) { - wstrings[i] = toUTF16FromOSNarrow(v[i].toStdString()); - wstringPtrs[i] = wstrings[i].c_str(); - } - amb->setStringArray(ruleAttrName.c_str(), wstringPtrs.data(), wstringPtrs.size()); - } - } - else { - GA_ROHandleS av(ar); - if (av.isValid()) { - const char* v = av.get(primitiveMapOffset); - const std::wstring wv = toUTF16FromOSNarrow(v); - if (DBG) - LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; - amb->setString(ruleAttrName.c_str(), wv.c_str()); - } - } - break; - } - case GA_STORECLASS_INT: { - if (isArrayAttribute(ar)) { - if (ar.getAIFNumericArray()->getStorage(ar.get()) == GA_STORE_INT8) { - GA_ROHandleIA av(ar); - if (av.isValid()) { - UT_Int32Array v; // there is no U_Int8Array - av.get(primitiveMapOffset, v); - if (DBG) - LOG_DBG << " prim bool array attr: " << ar->getName() << " = " << v; - const std::unique_ptr vPtrs(new bool[v.size()]); - for (size_t i = 0; i < v.size(); i++) - vPtrs[i] = (v[i] > 0); - amb->setBoolArray(ruleAttrName.c_str(), vPtrs.get(), v.size()); - } - } - else { - GA_ROHandleIA av(ar); - if (av.isValid()) { - UT_Int32Array v; - av.get(primitiveMapOffset, v); - if (DBG) - LOG_DBG << " prim int array attr: " << ar->getName() << " = " << v; - amb->setIntArray(ruleAttrName.c_str(), v.data(), v.size()); - } - } - } - else { - if (ar.getAIFTuple()->getStorage(ar.get()) == GA_STORE_INT8) { - GA_ROHandleI av(ar); - if (av.isValid()) { - const int v = av.get(primitiveMapOffset); - const bool bv = (v > 0); - if (DBG) - LOG_DBG << " prim bool attr: " << ar->getName() << " = " << bv; - amb->setBool(ruleAttrName.c_str(), bv); - } - } - else { - GA_ROHandleI av(ar); - if (av.isValid()) { - const int v = av.get(primitiveMapOffset); - if (DBG) - LOG_DBG << " prim int attr: " << ar->getName() << " = " << v; - amb->setInt(ruleAttrName.c_str(), v); - } - } - } // int - break; - } - default: { - LOG_WRN << "prim attr " << ar->getName() << ": unsupported storage class"; - break; - } - } // switch key type - } // for each primitive attribute + fromHoudini.convert(ar, primitiveMapOffset, ruleAttrName); + } AttributeMapUPtr ruleAttr(amb->createAttributeMap()); From 07b08cb2821353ec63922e94cbf2ae1836f07a93 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Thu, 30 Jul 2020 10:28:52 +0200 Subject: [PATCH 32/54] review: made attribute conversion component more symmetrical introduced ToHoudini class --- src/palladio/AttributeConversion.cpp | 366 ++++++++++++++++++--------- src/palladio/AttributeConversion.h | 234 ++++++----------- src/palladio/ModelConverter.cpp | 10 +- 3 files changed, 322 insertions(+), 288 deletions(-) diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index d49ac5b8..a715e16c 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -129,109 +129,6 @@ void setHandleRange(const GA_IndexMap& indexMap, GA_RWHandleSA& handle, GA_Offse << "): " << handle.getAttribute()->getName() << " = " << hv; } -class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { -private: - const AttributeConversion::ProtoHandle& protoHandle; - const prt::AttributeMap* attrMap; - const GA_IndexMap& primIndexMap; - GA_Offset rangeStart; - GA_Size rangeSize; - -public: - HandleVisitor(const AttributeConversion::ProtoHandle& ph, const prt::AttributeMap* m, const GA_IndexMap& pim, - GA_Offset rStart, GA_Size rSize) - : protoHandle(ph), attrMap(m), primIndexMap(pim), rangeStart(rStart), rangeSize(rSize) {} - - void operator()(const AttributeConversion::NoHandle& handle) const {} - - void operator()(GA_RWBatchHandleS& handle) const { - if (protoHandle.type == prt::Attributable::PT_STRING) { - wchar_t const* const v = attrMap->getString(protoHandle.key.c_str()); - if (v && std::wcslen(v) > 0) { - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, std::wstring(v)); - } - } - else if (protoHandle.type == prt::Attributable::PT_STRING_ARRAY) { - size_t arraySize = 0; - wchar_t const* const* const v = attrMap->getStringArray(protoHandle.key.c_str(), &arraySize); - for (size_t i = 0; i < arraySize; i++) { - if (v && v[i] && std::wcslen(v[i]) > 0) { - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, i, std::wstring(v[i])); - } - } - } - } - - void operator()(GA_RWHandleI& handle) const { - if (protoHandle.type == prt::Attributable::PT_INT) { - const int32_t v = attrMap->getInt(protoHandle.key.c_str()); - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); - } - else if (protoHandle.type == prt::Attributable::PT_INT_ARRAY) { - LOG_ERR << "int arrays as tuples not yet implemented"; - } - } - - void operator()(GA_RWHandleC& handle) const { - if (protoHandle.type == prt::Attributable::PT_BOOL) { - const bool v = attrMap->getBool(protoHandle.key.c_str()); - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); - } - else if (protoHandle.type == prt::Attributable::PT_BOOL_ARRAY) { - LOG_ERR << "bool arrays as tuples not yet implemented"; - } - } - - void operator()(GA_RWHandleF& handle) const { - if (protoHandle.type == prt::Attributable::PT_FLOAT) { - const auto v = attrMap->getFloat(protoHandle.key.c_str()); - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); - } - else if (protoHandle.type == prt::Attributable::PT_FLOAT_ARRAY) { - size_t arraySize = 0; - const double* const v = attrMap->getFloatArray(protoHandle.key.c_str(), &arraySize); - for (size_t i = 0; i < arraySize; i++) { - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, i, v[i]); - } - } - } - - void operator()(GA_RWHandleDA& handle) const { - size_t arraySize = 0; - const double* const array = attrMap->getFloatArray(protoHandle.key.c_str(), &arraySize); - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); - } - - void operator()(GA_RWHandleIA& handle) const { - if (protoHandle.type == prt::Attributable::PT_BOOL_ARRAY) { - size_t arraySize = 0; - const bool* array = attrMap->getBoolArray(protoHandle.key.c_str(), &arraySize); - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); - } - else { - size_t arraySize = 0; - const int32_t* array = attrMap->getIntArray(protoHandle.key.c_str(), &arraySize); - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); - } - } - - void operator()(GA_RWHandleSA& handle) const { - size_t arraySize = 0; - wchar_t const* const* const array = attrMap->getStringArray(protoHandle.key.c_str(), &arraySize); - setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); - } -}; - -void addProtoHandle(AttributeConversion::HandleMap& handleMap, const std::wstring& handleName, - AttributeConversion::ProtoHandle&& ph) { - WA("all"); - - const UT_StringHolder& utName = NameConversion::toPrimAttr(handleName); - if (DBG) - LOG_DBG << "handle name conversion: handleName = " << handleName << ", utName = " << utName; - handleMap.emplace(utName, std::move(ph)); -} - size_t getAttributeCardinality(const prt::AttributeMap* attrMap, const std::wstring& key, const prt::Attributable::PrimitiveType& type) { size_t cardinality = -1; @@ -260,11 +157,152 @@ size_t getAttributeCardinality(const prt::AttributeMap* attrMap, const std::wstr return cardinality; } +bool isArrayAttribute(const GA_ROAttributeRef& ar) { + return (ar.getAIFNumericArray() != nullptr) || (ar.getAIFSharedStringArray() != nullptr); +} + } // namespace namespace AttributeConversion { -void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMap) { +bool FromHoudini::convert(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { + if (isArrayAttribute(ar)) + return handleArray(ar, offset, name); + else + return handleScalar(ar, offset, name); +} + +bool FromHoudini::handleScalar(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { + bool conversionResult = true; + switch (ar.getStorageClass()) { + case GA_STORECLASS_FLOAT: { + GA_ROHandleD av(ar); + if (av.isValid()) { + double v = av.get(offset); + if (DBG) + LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; + mBuilder.setFloat(name.c_str(), v); + } + break; + } + case GA_STORECLASS_STRING: { + GA_ROHandleS av(ar); + if (av.isValid()) { + const char* v = av.get(offset); + const std::wstring wv = toUTF16FromOSNarrow(v); + if (DBG) + LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; + mBuilder.setString(name.c_str(), wv.c_str()); + } + break; + } + case GA_STORECLASS_INT: { + if (ar.getAIFTuple()->getStorage(ar.get()) == GA_STORE_INT8) { + GA_ROHandleI av(ar); + if (av.isValid()) { + const int v = av.get(offset); + const bool bv = (v > 0); + if (DBG) + LOG_DBG << " prim bool attr: " << ar->getName() << " = " << bv; + mBuilder.setBool(name.c_str(), bv); + } + } + else { + GA_ROHandleI av(ar); + if (av.isValid()) { + const int v = av.get(offset); + if (DBG) + LOG_DBG << " prim int attr: " << ar->getName() << " = " << v; + mBuilder.setInt(name.c_str(), v); + } + } + break; + } + default: { + LOG_WRN << "prim attr " << ar->getName() << ": unsupported storage class"; + conversionResult = false; + break; + } + } + return conversionResult; +} + +bool FromHoudini::handleArray(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { + bool conversionResult = true; + switch (ar.getStorageClass()) { + case GA_STORECLASS_FLOAT: { + GA_ROHandleDA av(ar); + if (av.isValid()) { + UT_Fpreal64Array v; + av.get(offset, v); + if (DBG) + LOG_DBG << " prim float array attr: " << ar->getName() << " = " << v; + mBuilder.setFloatArray(name.c_str(), v.data(), v.size()); + } + break; + } + case GA_STORECLASS_STRING: { + GA_ROHandleSA av(ar); + if (av.isValid()) { + UT_StringArray v; + av.get(offset, v); + if (DBG) + LOG_DBG << " prim string array attr: " << ar->getName() << " = " << v; + + std::vector wstrings(v.size()); + std::vector wstringPtrs(v.size()); + for (size_t i = 0; i < v.size(); i++) { + wstrings[i] = toUTF16FromOSNarrow(v[i].toStdString()); + wstringPtrs[i] = wstrings[i].c_str(); + } + mBuilder.setStringArray(name.c_str(), wstringPtrs.data(), wstringPtrs.size()); + } + break; + } + case GA_STORECLASS_INT: { + if (ar.getAIFNumericArray()->getStorage(ar.get()) == GA_STORE_INT8) { + GA_ROHandleIA av(ar); + if (av.isValid()) { + UT_Int32Array v; // there is no U_Int8Array + av.get(offset, v); + if (DBG) + LOG_DBG << " prim bool array attr: " << ar->getName() << " = " << v; + const std::unique_ptr vPtrs(new bool[v.size()]); + for (size_t i = 0; i < v.size(); i++) + vPtrs[i] = (v[i] > 0); + mBuilder.setBoolArray(name.c_str(), vPtrs.get(), v.size()); + } + } + else { + GA_ROHandleIA av(ar); + if (av.isValid()) { + UT_Int32Array v; + av.get(offset, v); + if (DBG) + LOG_DBG << " prim int array attr: " << ar->getName() << " = " << v; + mBuilder.setIntArray(name.c_str(), v.data(), v.size()); + } + } + break; + } + default: { + LOG_WRN << "prim attr " << ar->getName() << ": unsupported storage class"; + conversionResult = false; + break; + } + } + return conversionResult; +} + +void ToHoudini::convert(const prt::AttributeMap* attrMap, const GA_Offset rangeStart, const GA_Size rangeSize, + ArrayHandling arrayHandling) { + const GA_IndexMap& primIndexMap = mDetail->getIndexMap(GA_ATTRIB_PRIMITIVE); + extractAttributeNames(attrMap); + createAttributeHandles(arrayHandling == ArrayHandling::ARRAY); + setAttributeValues(attrMap, primIndexMap, rangeStart, rangeSize); +} + +void ToHoudini::extractAttributeNames(const prt::AttributeMap* attrMap) { size_t keyCount = 0; wchar_t const* const* keys = attrMap->getKeys(&keyCount); for (size_t k = 0; k < keyCount; k++) { @@ -274,14 +312,14 @@ void extractAttributeNames(HandleMap& handleMap, const prt::AttributeMap* attrMa ph.type = attrMap->getType(key); ph.key.assign(key); ph.cardinality = getAttributeCardinality(attrMap, ph.key, ph.type); - addProtoHandle(handleMap, key, std::move(ph)); + addProtoHandle(mHandleMap, key, std::move(ph)); } } -void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArrayTypes) { +void ToHoudini::createAttributeHandles(bool useArrayTypes) { WA("all"); - for (auto& hm : handleMap) { + for (auto& hm : mHandleMap) { const auto& utKey = hm.first; const auto& type = hm.second.type; @@ -292,13 +330,13 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArr case prt::Attributable::PT_BOOL_ARRAY: { if (useArrayTypes && (type == prt::Attributable::PT_BOOL_ARRAY)) { GA_RWHandleIA h( - detail->addIntArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_INT8)); + mDetail->addIntArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_INT8)); if (h.isValid()) handle = h; } else { - GA_RWHandleC h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality, - GA_Defaults(0), nullptr, nullptr, GA_STORE_INT8)); + GA_RWHandleC h(mDetail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality, + GA_Defaults(0), nullptr, nullptr, GA_STORE_INT8)); if (h.isValid()) handle = h; } @@ -308,12 +346,12 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArr case prt::Attributable::PT_FLOAT_ARRAY: { if (useArrayTypes && (type == prt::Attributable::PT_FLOAT_ARRAY)) { GA_RWHandleDA h( - detail->addFloatArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_REAL64)); + mDetail->addFloatArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_REAL64)); if (h.isValid()) handle = h; } else { - GA_RWHandleF h(detail->addFloatTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); + GA_RWHandleF h(mDetail->addFloatTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); if (h.isValid()) handle = h; } @@ -323,12 +361,12 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArr case prt::Attributable::PT_INT_ARRAY: { if (useArrayTypes && (type == prt::Attributable::PT_INT_ARRAY)) { GA_RWHandleIA h( - detail->addIntArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_INT32)); + mDetail->addIntArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_INT32)); if (h.isValid()) handle = h; } else { - GA_RWHandleI h(detail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); + GA_RWHandleI h(mDetail->addIntTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); if (h.isValid()) handle = h; } @@ -338,12 +376,12 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArr case prt::Attributable::PT_STRING_ARRAY: { if (useArrayTypes && (type == prt::Attributable::PT_STRING_ARRAY)) { GA_RWHandleSA h( - detail->addStringArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_STRING)); + mDetail->addStringArray(GA_ATTRIB_PRIMITIVE, utKey, 1, nullptr, nullptr, GA_STORE_STRING)); if (h.isValid()) handle = h; } else { - GA_RWBatchHandleS h(detail->addStringTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); + GA_RWBatchHandleS h(mDetail->addStringTuple(GA_ATTRIB_PRIMITIVE, utKey, hm.second.cardinality)); if (h.isValid()) handle = h; } @@ -365,9 +403,9 @@ void createAttributeHandles(GU_Detail* detail, HandleMap& handleMap, bool useArr } } -void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, const GA_IndexMap& primIndexMap, - const GA_Offset rangeStart, const GA_Size rangeSize) { - for (auto& h : handleMap) { +void ToHoudini::setAttributeValues(const prt::AttributeMap* attrMap, const GA_IndexMap& primIndexMap, + const GA_Offset rangeStart, const GA_Size rangeSize) { + for (auto& h : mHandleMap) { if (attrMap->hasKey(h.second.key.c_str())) { const HandleVisitor hv(h.second, attrMap, primIndexMap, rangeStart, rangeSize); PLD_BOOST_NS::apply_visitor(hv, h.second.handleType); @@ -375,12 +413,90 @@ void setAttributeValues(HandleMap& handleMap, const prt::AttributeMap* attrMap, } } -void convertAttributes(GU_Detail* detail, HandleMap& handleMap, const prt::AttributeMap* attrMap, - const GA_Offset rangeStart, const GA_Size rangeSize, ArrayHandling arrayHandling) { - const GA_IndexMap& primIndexMap = detail->getIndexMap(GA_ATTRIB_PRIMITIVE); - extractAttributeNames(handleMap, attrMap); - createAttributeHandles(detail, handleMap, arrayHandling == ArrayHandling::ARRAY); - setAttributeValues(handleMap, attrMap, primIndexMap, rangeStart, rangeSize); +void ToHoudini::addProtoHandle(HandleMap& handleMap, const std::wstring& handleName, ProtoHandle&& ph) { + WA("all"); + + const UT_StringHolder& utName = NameConversion::toPrimAttr(handleName); + if (DBG) + LOG_DBG << "handle name conversion: handleName = " << handleName << ", utName = " << utName; + handleMap.emplace(utName, std::move(ph)); +} + +void ToHoudini::HandleVisitor::operator()(GA_RWBatchHandleS& handle) const { + if (protoHandle.type == prt::Attributable::PT_STRING) { + wchar_t const* const v = attrMap->getString(protoHandle.key.c_str()); + if (v && std::wcslen(v) > 0) { + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, std::wstring(v)); + } + } + else if (protoHandle.type == prt::Attributable::PT_STRING_ARRAY) { + size_t arraySize = 0; + wchar_t const* const* const v = attrMap->getStringArray(protoHandle.key.c_str(), &arraySize); + for (size_t i = 0; i < arraySize; i++) { + if (v && v[i] && std::wcslen(v[i]) > 0) { + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, i, std::wstring(v[i])); + } + } + } +} + +void ToHoudini::HandleVisitor::operator()(GA_RWHandleI& handle) const { + if (protoHandle.type == prt::Attributable::PT_INT) { + const int32_t v = attrMap->getInt(protoHandle.key.c_str()); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); + } + else if (protoHandle.type == prt::Attributable::PT_INT_ARRAY) { + LOG_ERR << "int arrays as tuples not yet implemented"; + } +} + +void ToHoudini::HandleVisitor::operator()(GA_RWHandleC& handle) const { + if (protoHandle.type == prt::Attributable::PT_BOOL) { + const bool v = attrMap->getBool(protoHandle.key.c_str()); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); + } + else if (protoHandle.type == prt::Attributable::PT_BOOL_ARRAY) { + LOG_ERR << "bool arrays as tuples not yet implemented"; + } +} + +void ToHoudini::HandleVisitor::operator()(GA_RWHandleF& handle) const { + if (protoHandle.type == prt::Attributable::PT_FLOAT) { + const auto v = attrMap->getFloat(protoHandle.key.c_str()); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, 0, v); + } + else if (protoHandle.type == prt::Attributable::PT_FLOAT_ARRAY) { + size_t arraySize = 0; + const double* const v = attrMap->getFloatArray(protoHandle.key.c_str(), &arraySize); + for (size_t i = 0; i < arraySize; i++) { + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, i, v[i]); + } + } +} + +void ToHoudini::HandleVisitor::operator()(GA_RWHandleDA& handle) const { + size_t arraySize = 0; + const double* const array = attrMap->getFloatArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); +} + +void ToHoudini::HandleVisitor::operator()(GA_RWHandleIA& handle) const { + if (protoHandle.type == prt::Attributable::PT_BOOL_ARRAY) { + size_t arraySize = 0; + const bool* array = attrMap->getBoolArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); + } + else { + size_t arraySize = 0; + const int32_t* array = attrMap->getIntArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); + } +} + +void ToHoudini::HandleVisitor::operator()(GA_RWHandleSA& handle) const { + size_t arraySize = 0; + wchar_t const* const* const array = attrMap->getStringArray(protoHandle.key.c_str(), &arraySize); + setHandleRange(primIndexMap, handle, rangeStart, rangeSize, array, arraySize); } } // namespace AttributeConversion diff --git a/src/palladio/AttributeConversion.h b/src/palladio/AttributeConversion.h index 31deefa0..10ec47b2 100644 --- a/src/palladio/AttributeConversion.h +++ b/src/palladio/AttributeConversion.h @@ -16,10 +16,11 @@ #pragma once -#include "LogHandler.h" #include "PalladioMain.h" #include "Utils.h" +#include "prt/AttributeMap.h" + #include "GU/GU_Detail.h" // clang-format off @@ -28,6 +29,7 @@ // clang-format on #include +#include namespace std { template <> @@ -40,176 +42,92 @@ struct hash { namespace AttributeConversion { -class FromHoudini { -private: - static const bool DBG = true; +/** + * attribute type conversion between PRT and Houdini: + * wstring <-> narrow string + * int32_t <-> int32_t + * bool <-> int8_t + * double <-> double + */ +class FromHoudini { public: FromHoudini(prt::AttributeMapBuilder& builder) : mBuilder(builder) {} + FromHoudini(const FromHoudini&) = delete; + FromHoudini(FromHoudini&&) = delete; + FromHoudini& operator=(const FromHoudini&) = delete; + FromHoudini& operator=(FromHoudini&&) = delete; + virtual ~FromHoudini() = default; - bool convert(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { - if (isArrayAttribute(ar)) - return handleArray(ar, offset, name); - else - return handleScalar(ar, offset, name); - } + bool convert(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name); private: - bool handleScalar(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { - bool conversionResult = true; - switch (ar.getStorageClass()) { - case GA_STORECLASS_FLOAT: { - GA_ROHandleD av(ar); - if (av.isValid()) { - double v = av.get(offset); - if (DBG) - LOG_DBG << " prim float attr: " << ar->getName() << " = " << v; - mBuilder.setFloat(name.c_str(), v); - } - break; - } - case GA_STORECLASS_STRING: { - GA_ROHandleS av(ar); - if (av.isValid()) { - const char* v = av.get(offset); - const std::wstring wv = toUTF16FromOSNarrow(v); - if (DBG) - LOG_DBG << " prim string attr: " << ar->getName() << " = " << v; - mBuilder.setString(name.c_str(), wv.c_str()); - } - break; - } - case GA_STORECLASS_INT: { - if (ar.getAIFTuple()->getStorage(ar.get()) == GA_STORE_INT8) { - GA_ROHandleI av(ar); - if (av.isValid()) { - const int v = av.get(offset); - const bool bv = (v > 0); - if (DBG) - LOG_DBG << " prim bool attr: " << ar->getName() << " = " << bv; - mBuilder.setBool(name.c_str(), bv); - } - } - else { - GA_ROHandleI av(ar); - if (av.isValid()) { - const int v = av.get(offset); - if (DBG) - LOG_DBG << " prim int attr: " << ar->getName() << " = " << v; - mBuilder.setInt(name.c_str(), v); - } - } - break; - } - default: { - LOG_WRN << "prim attr " << ar->getName() << ": unsupported storage class"; - conversionResult = false; - break; - } - } - return conversionResult; - } - - bool handleArray(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name) { - bool conversionResult = true; - switch (ar.getStorageClass()) { - case GA_STORECLASS_FLOAT: { - GA_ROHandleDA av(ar); - if (av.isValid()) { - UT_Fpreal64Array v; - av.get(offset, v); - if (DBG) - LOG_DBG << " prim float array attr: " << ar->getName() << " = " << v; - mBuilder.setFloatArray(name.c_str(), v.data(), v.size()); - } - break; - } - case GA_STORECLASS_STRING: { - GA_ROHandleSA av(ar); - if (av.isValid()) { - UT_StringArray v; - av.get(offset, v); - if (DBG) - LOG_DBG << " prim string array attr: " << ar->getName() << " = " << v; - - std::vector wstrings(v.size()); - std::vector wstringPtrs(v.size()); - for (size_t i = 0; i < v.size(); i++) { - wstrings[i] = toUTF16FromOSNarrow(v[i].toStdString()); - wstringPtrs[i] = wstrings[i].c_str(); - } - mBuilder.setStringArray(name.c_str(), wstringPtrs.data(), wstringPtrs.size()); - } - break; - } - case GA_STORECLASS_INT: { - if (ar.getAIFNumericArray()->getStorage(ar.get()) == GA_STORE_INT8) { - GA_ROHandleIA av(ar); - if (av.isValid()) { - UT_Int32Array v; // there is no U_Int8Array - av.get(offset, v); - if (DBG) - LOG_DBG << " prim bool array attr: " << ar->getName() << " = " << v; - const std::unique_ptr vPtrs(new bool[v.size()]); - for (size_t i = 0; i < v.size(); i++) - vPtrs[i] = (v[i] > 0); - mBuilder.setBoolArray(name.c_str(), vPtrs.get(), v.size()); - } - } - else { - GA_ROHandleIA av(ar); - if (av.isValid()) { - UT_Int32Array v; - av.get(offset, v); - if (DBG) - LOG_DBG << " prim int array attr: " << ar->getName() << " = " << v; - mBuilder.setIntArray(name.c_str(), v.data(), v.size()); - } - } - break; - } - default: { - LOG_WRN << "prim attr " << ar->getName() << ": unsupported storage class"; - conversionResult = false; - break; - } - } - return conversionResult; - } - - bool isArrayAttribute(const GA_ROAttributeRef& ar) { - return (ar.getAIFNumericArray() != nullptr) || (ar.getAIFSharedStringArray() != nullptr); - } + bool handleScalar(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name); + bool handleArray(const GA_ROAttributeRef& ar, const GA_Offset& offset, const std::wstring& name); private: prt::AttributeMapBuilder& mBuilder; }; -/** - * attribute type conversion from PRT to Houdini: - * wstring -> narrow string - * int32_t -> int32_t - * bool -> int8_t - * double -> float (single precision!) - */ -using NoHandle = int8_t; -using HandleType = PLD_BOOST_NS::variant; - -// bound to life time of PRT attribute map -struct ProtoHandle { - HandleType handleType; - std::wstring key; - prt::AttributeMap::PrimitiveType type; // original PRT type - size_t cardinality; -}; +class ToHoudini { +public: + ToHoudini(GU_Detail* detail) : mDetail(detail) {} + ToHoudini(const ToHoudini&) = delete; + ToHoudini(ToHoudini&&) = delete; + ToHoudini& operator=(const ToHoudini&) = delete; + ToHoudini& operator=(ToHoudini&&) = delete; + virtual ~ToHoudini() = default; + + enum class ArrayHandling { TUPLE, ARRAY }; + void convert(const prt::AttributeMap* attrMap, const GA_Offset rangeStart, const GA_Size rangeSize, + ArrayHandling arrayHandling = ArrayHandling::TUPLE); -using HandleMap = std::unordered_map; +private: + using NoHandle = int8_t; + using HandleType = PLD_BOOST_NS::variant; + + struct ProtoHandle { + HandleType handleType; + std::wstring key; + prt::AttributeMap::PrimitiveType type; // original PRT type + size_t cardinality; + }; + + class HandleVisitor : public PLD_BOOST_NS::static_visitor<> { + public: + HandleVisitor(const ProtoHandle& ph, const prt::AttributeMap* m, const GA_IndexMap& pim, GA_Offset rStart, + GA_Size rSize) + : protoHandle(ph), attrMap(m), primIndexMap(pim), rangeStart(rStart), rangeSize(rSize) {} + void operator()(const NoHandle& handle) const {} + void operator()(GA_RWBatchHandleS& handle) const; + void operator()(GA_RWHandleI& handle) const; + void operator()(GA_RWHandleC& handle) const; + void operator()(GA_RWHandleF& handle) const; + void operator()(GA_RWHandleDA& handle) const; + void operator()(GA_RWHandleIA& handle) const; + void operator()(GA_RWHandleSA& handle) const; + + private: + const ProtoHandle& protoHandle; + const prt::AttributeMap* attrMap; + const GA_IndexMap& primIndexMap; + GA_Offset rangeStart; + GA_Size rangeSize; + }; + + using HandleMap = std::unordered_map; + + void extractAttributeNames(const prt::AttributeMap* attrMap); + void createAttributeHandles(bool useArrayTypes); + void setAttributeValues(const prt::AttributeMap* attrMap, const GA_IndexMap& primIndexMap, + const GA_Offset rangeStart, const GA_Size rangeSize); + void addProtoHandle(HandleMap& handleMap, const std::wstring& handleName, ProtoHandle&& ph); -enum class ArrayHandling { TUPLE, ARRAY }; -void convertAttributes(GU_Detail* detail, HandleMap& handleMap, const prt::AttributeMap* attrMap, - const GA_Offset rangeStart, const GA_Size rangeSize, - ArrayHandling arrayHandling = ArrayHandling::TUPLE); +private: + GU_Detail* mDetail; + HandleMap mHandleMap; +}; } // namespace AttributeConversion diff --git a/src/palladio/ModelConverter.cpp b/src/palladio/ModelConverter.cpp index f95c942d..9fcf89a5 100644 --- a/src/palladio/ModelConverter.cpp +++ b/src/palladio/ModelConverter.cpp @@ -176,17 +176,17 @@ void ModelConverter::add(const wchar_t* name, const double* vtx, size_t vtxSize, if (faceRangesSize > 1) { WA("add materials/reports"); - AttributeConversion::HandleMap handleMap; + AttributeConversion::ToHoudini toHoudini(mDetail); for (size_t fri = 0; fri < faceRangesSize - 1; fri++) { const GA_Offset rangeStart = primStartOffset + faceRanges[fri]; const GA_Size rangeSize = faceRanges[fri + 1] - faceRanges[fri]; if (materials != nullptr) { - AttributeConversion::convertAttributes(mDetail, handleMap, materials[fri], rangeStart, rangeSize); + toHoudini.convert(materials[fri], rangeStart, rangeSize); } if (reports != nullptr) { - AttributeConversion::convertAttributes(mDetail, handleMap, reports[fri], rangeStart, rangeSize); + toHoudini.convert(reports[fri], rangeStart, rangeSize); } if (!mShapeAttributeBuilders.empty()) { @@ -195,8 +195,8 @@ void ModelConverter::add(const wchar_t* name, const double* vtx, size_t vtxSize, auto it = mShapeAttributeBuilders.find(shapeID); if (it != mShapeAttributeBuilders.end()) { const AttributeMapUPtr attrMap(it->second->createAttributeMap()); - AttributeConversion::convertAttributes(mDetail, handleMap, attrMap.get(), rangeStart, rangeSize, - AttributeConversion::ArrayHandling::ARRAY); + toHoudini.convert(attrMap.get(), rangeStart, rangeSize, + AttributeConversion::ToHoudini::ArrayHandling::ARRAY); } } } From 2cd563fc691feaf8b0f37a558e689221ad627f5e Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:18:32 +0200 Subject: [PATCH 33/54] doc: official name of CityEngine is now "ArcGIS CityEngine" we simplify by removing any prefix --- README.md | 2 +- doc/build.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1de2dabe..49ecbc04 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ *Binaries and examples are available at https://esri.github.io/palladio* -Palladio is a plugin for [SideFX Houdini](https://www.sidefx.com). It provides operator nodes which enable the execution of [Esri CityEngine](http://www.esri.com/software/cityengine) ‘rules’ within Houdini networks. Therefore, a 3D environment artist does not have to leave their familiar Houdini toolset anymore to make use of CityEngine’s procedural modeling power. Complicated export-import pipelines are no longer needed, which also means that the procedural building models do not need to be “baked” anymore. The buildings stay procedural during the entire modeling workflow (optionally even at render time). Consequently, the 3D environment artist can change the height, style and appearance of buildings easily with a parametric interface at any point during production. +Palladio is a plugin for [SideFX Houdini](https://www.sidefx.com). It provides operator nodes which enable the execution of [CityEngine](http://www.esri.com/software/cityengine) ‘rules’ within Houdini networks. Therefore, a 3D environment artist does not have to leave their familiar Houdini toolset anymore to make use of CityEngine’s procedural modeling power. Complicated export-import pipelines are no longer needed, which also means that the procedural building models do not need to be “baked” anymore. The buildings stay procedural during the entire modeling workflow (optionally even at render time). Consequently, the 3D environment artist can change the height, style and appearance of buildings easily with a parametric interface at any point during production. Palladio requires so-called rule packages (RPK) as input, which are authored in CityEngine. An RPK includes assets and a CGA rule file which encodes an architectural style. Comprehensive RPK examples are available below and can be used “out-of-the-box” in Palladio. diff --git a/doc/build.md b/doc/build.md index a655dd66..8cad618e 100644 --- a/doc/build.md +++ b/doc/build.md @@ -17,7 +17,7 @@ * Installation of Houdini 17.0 or later (see https://sidefx.com/download) The following will be automatically fetched via the bootstrap steps below: -* [Esri CityEngine SDK](https://github.com/Esri/esri-cityengine-sdk) +* [CityEngine SDK](https://github.com/esri/cityengine-sdk) * SideFX Houdini HDK From eec4175e18e82a4abb66c1b05a322206cf4b7957 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:18:52 +0200 Subject: [PATCH 34/54] doc: add link to CityEngine product page --- doc/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage.md b/doc/usage.md index 57c5f5e8..76fafb1a 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -6,7 +6,7 @@ * RedHat Enterprise Linux 7 (and compatible) or Windows 7/8.1/10 * Houdini 17.0 or later (all editions) * To create CityEngine rule packages, an installation of CityEngine (2019.0 or later) -* For commercial work, a license for CityEngine (2019.0 or later) +* For commercial work, a [license](https://esri.com/cityengine) for CityEngine (2019.0 or later) ## Installation From 8776ad219d72bf1f12c293ad1e7c0256ba51debf Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:20:04 +0200 Subject: [PATCH 35/54] doc: support for older Windows versions is now non-official --- doc/build.md | 2 +- doc/usage.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/build.md b/doc/build.md index 8cad618e..6ff9fafa 100644 --- a/doc/build.md +++ b/doc/build.md @@ -5,7 +5,7 @@ ### Supported Operating Systems * RedHat Enterprise Linux 7 (and compatible) -* Windows 7/8.1/10 +* Windows 10 ### Required Toolchain & Compiler * [cmake 3.13 or later](https://cmake.org/download) diff --git a/doc/usage.md b/doc/usage.md index 76fafb1a..fe9d622c 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -3,7 +3,7 @@ ## Prerequisites -* RedHat Enterprise Linux 7 (and compatible) or Windows 7/8.1/10 +* RedHat Enterprise Linux 7 (and compatible) or Windows 10 * Houdini 17.0 or later (all editions) * To create CityEngine rule packages, an installation of CityEngine (2019.0 or later) * For commercial work, a [license](https://esri.com/cityengine) for CityEngine (2019.0 or later) From cd8f48af15aa7e00ca966dd07e799cc52ffc84a9 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:28:44 +0200 Subject: [PATCH 36/54] doc: the new default CityEngine SDK 2.2 requires MSVC 14.2 --- doc/build.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/build.md b/doc/build.md index 6ff9fafa..5bb661d2 100644 --- a/doc/build.md +++ b/doc/build.md @@ -11,7 +11,7 @@ * [cmake 3.13 or later](https://cmake.org/download) * [conan 1.20 or later](https://www.conan.io/downloads) * Linux: GCC 6.3 -* Windows: Visual Studio 2017 (MSVC 14.1) +* Windows: Visual Studio 2019 (MSVC 14.2) ### Required Build Dependencies * Installation of Houdini 17.0 or later (see https://sidefx.com/download) From 1610b7713d69a51380d513e11611038a737ae22a Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:31:56 +0200 Subject: [PATCH 37/54] doc: added change log for v1.8.0 beta 1 --- doc/changelog.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/changelog.md b/doc/changelog.md index c52bf902..3f9388f6 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -1,5 +1,15 @@ # Palladio ChangeLog +## v1.8.0-beta.1 (Aug 23, 2020) +* Update default CityEngine SDK to 2.2 (CityEngine 2020.0) (#146). +* Added support for CGA array attributes (#146). +* At startup, print Palladio version on console if log level is "info" or lower. +* Development + * On Windows, building Palladio now requires MSVC 14.2 (#146). + * Various code cleanups and adoption of clang-format rules from [Serlio](https://github.com/esri/serlio). + * Pruned releasing for Houdini 17.0 (you can still build yourself for 17.0). + * Relaxed Python/Conan version requirements. + ## v1.7.0 (June 14, 2020) * No functional changes compared to Beta 1 From 250db9998bd8f7df77f713bfcb9b5736d5bc7684 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:55:16 +0200 Subject: [PATCH 38/54] doc: clarify Houdini version requirement --- doc/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage.md b/doc/usage.md index fe9d622c..5781474c 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -4,7 +4,7 @@ ## Prerequisites * RedHat Enterprise Linux 7 (and compatible) or Windows 10 -* Houdini 17.0 or later (all editions) +* Houdini 17.5 or later (building is supported from Houdini 17.0 or later) * To create CityEngine rule packages, an installation of CityEngine (2019.0 or later) * For commercial work, a [license](https://esri.com/cityengine) for CityEngine (2019.0 or later) From 8cc65a1ea5062768511567fa92fe0d2dbff503fb Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 13:02:57 +0200 Subject: [PATCH 39/54] doc: make change log titles less cryptic --- doc/changelog.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 3f9388f6..23b430da 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -1,6 +1,6 @@ # Palladio ChangeLog -## v1.8.0-beta.1 (Aug 23, 2020) +## v1.8.0 Beta 1 (Aug 23, 2020) * Update default CityEngine SDK to 2.2 (CityEngine 2020.0) (#146). * Added support for CGA array attributes (#146). * At startup, print Palladio version on console if log level is "info" or lower. @@ -13,13 +13,13 @@ ## v1.7.0 (June 14, 2020) * No functional changes compared to Beta 1 -## v1.7.0-beta.1 (Dec 9, 2019) +## v1.7.0 Beta 1 (Dec 9, 2019) * Added support for Houdini 18 and removed Houdini 16 (#143). * Updated built artifacts to latest Houdini versions (#139). * Filter unnecessary components of PRT from release (#141). * Fixed pipeline to not install files outside of the install directory (#138). -## v1.7.0-pre (Oct 20, 2019) +## v1.7.0 Pre-Release (Oct 20, 2019) * Improved setting start rule from primitive attribute (i.e. do not prepend style to start rule if it is already present). * Improved installation experience (avoid setting OS PATH on Windows). * Update default CityEngine SDK version to 2.1 (CityEngine 2019.1). @@ -47,10 +47,10 @@ ## v1.5.0 (May 7, 2019) * No functional change to beta 2. -## v1.5.0-beta.2 (Mar 19, 2019) +## v1.5.0 Beta 2 (Mar 19, 2019) * Fixed crash in pldAssign node if no RPK is set. -## v1.5.0-beta.1 (Mar 14, 2019) +## v1.5.0 Beta 1 (Mar 14, 2019) * Added support for Rule Packages (RPK) embedded in Houdini Digital Assets (HDA) * Added support for Houdini 17.5 @@ -75,7 +75,7 @@ * Added pipenv script for easier access to conan. * Reduced Houdini package size. -## v1.2.0-rc.1 (Jun 11, 2018) +## v1.2.0 RC 1 (Jun 11, 2018) * Support for inter-shape occlusion queries (#33). ## v1.1.1 (Apr 16, 2018) From e48a65e7865ca6d29a7c2fc792a99be3cfe9895a Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:32:43 +0200 Subject: [PATCH 40/54] Increase version to v1.8.0 Beta 1 --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1baebd5..6e5c4583 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,7 +45,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/dependencies.cmake) set(PLD_VERSION_MAJOR 1) set(PLD_VERSION_MINOR 8) set(PLD_VERSION_PATCH 0) -set(PLD_VERSION_PRE "-dev.0") # set to empty string for final releases +set(PLD_VERSION_PRE "-beta.1") # set to empty string for final releases if(NOT PLD_VERSION_BUILD) set(PLD_VERSION_BUILD DEV) endif() From e5f659e870af89701df9d61c55fab1b0e00ab710 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 12:40:31 +0200 Subject: [PATCH 41/54] pipenv: remove python 3.6 requirement and relax conan version requirement * we do not care which python is used to install conan * conan is now stable enough that we can auto upgrade to 1.x versions --- src/Pipfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Pipfile b/src/Pipfile index e9f16cfa..3c57505f 100644 --- a/src/Pipfile +++ b/src/Pipfile @@ -6,7 +6,4 @@ verify_ssl = true [dev-packages] [packages] -conan = "==1.20.*" - -[requires] -python_version = "3.6" +conan = "==1.*" From fb97a497595c13f8475f6551a0dd48d11c758f67 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 13:50:08 +0200 Subject: [PATCH 42/54] cmake/conan: update conan cmake helper to 0.15 --- conan/{conan-0.14.cmake => conan-0.15.cmake} | 112 ++++++++++++++----- src/dependencies.cmake | 2 +- 2 files changed, 85 insertions(+), 29 deletions(-) rename conan/{conan-0.14.cmake => conan-0.15.cmake} (85%) diff --git a/conan/conan-0.14.cmake b/conan/conan-0.15.cmake similarity index 85% rename from conan/conan-0.14.cmake rename to conan/conan-0.15.cmake index aac3b9c8..b27dc33b 100644 --- a/conan/conan-0.14.cmake +++ b/conan/conan-0.15.cmake @@ -33,6 +33,7 @@ # but it is only necessary on the end-user side. It is not necessary to create conan # packages, in fact it shouldn't be use for that. Check the project documentation. +# version: 0.15.0 include(CMakeParseArguments) @@ -157,8 +158,8 @@ function(conan_cmake_settings result) set(_CONAN_SETTING_COMPILER clang) set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) if(APPLE) - cmake_policy(GET CMP0025 APPLE_CLANG_POLICY_ENABLED) - if(NOT APPLE_CLANG_POLICY_ENABLED) + cmake_policy(GET CMP0025 APPLE_CLANG_POLICY) + if(NOT APPLE_CLANG_POLICY STREQUAL NEW) message(STATUS "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it") set(_CONAN_SETTING_COMPILER apple-clang) endif() @@ -220,7 +221,7 @@ function(conan_cmake_settings result) endif() foreach(ARG ${_APPLIED_PROFILES}) - set(_SETTINGS ${_SETTINGS} -pr ${ARG}) + set(_SETTINGS ${_SETTINGS} -pr=${ARG}) endforeach() if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") @@ -298,14 +299,16 @@ function(conan_cmake_detect_vs_runtime result) string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) foreach(variable ${variables}) - string(REPLACE " " ";" flags ${${variable}}) - foreach (flag ${flags}) - if(${flag} STREQUAL "/MD" OR ${flag} STREQUAL "/MDd" OR ${flag} STREQUAL "/MT" OR ${flag} STREQUAL "/MTd") - string(SUBSTRING ${flag} 1 -1 runtime) - set(${result} ${runtime} PARENT_SCOPE) - return() - endif() - endforeach() + if(NOT "${${variable}}" STREQUAL "") + string(REPLACE " " ";" flags ${${variable}}) + foreach (flag ${flags}) + if(${flag} STREQUAL "/MD" OR ${flag} STREQUAL "/MDd" OR ${flag} STREQUAL "/MT" OR ${flag} STREQUAL "/MTd") + string(SUBSTRING ${flag} 1 -1 runtime) + set(${result} ${runtime} PARENT_SCOPE) + return() + endif() + endforeach() + endif() endforeach() if(${build_type} STREQUAL "DEBUG") set(${result} "MDd" PARENT_SCOPE) @@ -316,11 +319,11 @@ endfunction() macro(parse_arguments) - set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS) + set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD) set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND) set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO - INSTALL_ARGS) + INSTALL_ARGS CONFIGURATION_TYPES) cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) endmacro() @@ -348,9 +351,9 @@ function(conan_cmake_install) endif() endforeach() if(ARGUMENTS_CONAN_COMMAND) - set(conan_command ${ARGUMENTS_CONAN_COMMAND}) + set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND}) else() - set(conan_command conan) + conan_check(REQUIRED) endif() set(CONAN_OPTIONS "") if(ARGUMENTS_CONANFILE) @@ -381,16 +384,16 @@ function(conan_cmake_install) set(conan_args install ${CONANFILE} ${settings} ${CONAN_ENV_VARS} ${CONAN_GENERATORS} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_INSTALL_NO_IMPORTS} ${CONAN_OPTIONS} ${CONAN_INSTALL_FOLDER} ${ARGUMENTS_INSTALL_ARGS}) string (REPLACE ";" " " _conan_args "${conan_args}") - message(STATUS "Conan executing: ${conan_command} ${_conan_args}") + message(STATUS "Conan executing: ${CONAN_CMD} ${_conan_args}") if(ARGUMENTS_OUTPUT_QUIET) - execute_process(COMMAND ${conan_command} ${conan_args} + execute_process(COMMAND ${CONAN_CMD} ${conan_args} RESULT_VARIABLE return_code OUTPUT_VARIABLE conan_output ERROR_VARIABLE conan_output WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) else() - execute_process(COMMAND ${conan_command} ${conan_args} + execute_process(COMMAND ${CONAN_CMD} ${conan_args} RESULT_VARIABLE return_code WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif() @@ -407,7 +410,7 @@ function(conan_cmake_setup_conanfile) if(ARGUMENTS_CONANFILE) get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME) # configure_file will make sure cmake re-runs when conanfile is updated - configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) + configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk COPYONLY) file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) else() conan_cmake_generate_conanfile(${ARGV}) @@ -462,10 +465,19 @@ endmacro() macro(conan_cmake_run) parse_arguments(${ARGV}) + + if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES) + message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators") + elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE) + message(WARNING "CONFIGURATION_TYPES and BUILD_TYPE arguments should not be defined at the same time.") + endif() if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE AND NOT CONAN_EXPORTED AND NOT ARGUMENTS_BUILD_TYPE) set(CONAN_CMAKE_MULTI ON) + if (NOT ARGUMENTS_CONFIGURATION_TYPES) + set(ARGUMENTS_CONFIGURATION_TYPES "Release;Debug") + endif() message(STATUS "Conan: Using cmake-multi generator") else() set(CONAN_CMAKE_MULTI OFF) @@ -474,7 +486,7 @@ macro(conan_cmake_run) if(NOT CONAN_EXPORTED) conan_cmake_setup_conanfile(${ARGV}) if(CONAN_CMAKE_MULTI) - foreach(CMAKE_BUILD_TYPE "Release" "Debug") + foreach(CMAKE_BUILD_TYPE ${ARGUMENTS_CONFIGURATION_TYPES}) set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE}) conan_cmake_settings(settings ${ARGV}) conan_cmake_install(SETTINGS ${settings} ${ARGV}) @@ -487,11 +499,11 @@ macro(conan_cmake_run) endif() if (NOT ARGUMENTS_NO_LOAD) - conan_load_buildinfo() + conan_load_buildinfo() endif() if(ARGUMENTS_BASIC_SETUP) - foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS) + foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS SKIP_STD) if(ARGUMENTS_${_option}) if(${_option} STREQUAL "CMAKE_TARGETS") list(APPEND _setup_options "TARGETS") @@ -509,7 +521,7 @@ macro(conan_check) # Arguments REQUIRED and VERSION are optional # Example usage: # conan_check(VERSION 1.0.0 REQUIRED) - message(STATUS "Conan: checking conan executable in path") + message(STATUS "Conan: checking conan executable") set(options REQUIRED) set(oneValueArgs VERSION) cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN}) @@ -535,20 +547,64 @@ macro(conan_check) endif() endmacro() -macro(conan_add_remote) +function(conan_add_remote) # Adds a remote - # Arguments URL and NAME are required, INDEX is optional + # Arguments URL and NAME are required, INDEX and COMMAND are optional # Example usage: # conan_add_remote(NAME bincrafters INDEX 1 # URL https://api.bintray.com/conan/bincrafters/public-conan) - set(oneValueArgs URL NAME INDEX) + set(oneValueArgs URL NAME INDEX COMMAND) cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN}) if(DEFINED CONAN_INDEX) set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}") endif() - - message(STATUS "Conan: Adding ${CONAN_NAME} remote repositoy (${CONAN_URL})") + if(CONAN_COMMAND) + set(CONAN_CMD ${CONAN_COMMAND}) + else() + conan_check(REQUIRED) + endif() + message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL})") execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_URL} ${CONAN_INDEX_ARG} -f) +endfunction() + +macro(conan_config_install) + # install a full configuration from a local or remote zip file + # Argument ITEM is required, arguments TYPE, SOURCE, TARGET and VERIFY_SSL are optional + # Example usage: + # conan_config_install(ITEM https://github.com/conan-io/cmake-conan.git + # TYPE git SOURCE source-folder TARGET target-folder VERIFY_SSL false) + set(oneValueArgs ITEM TYPE SOURCE TARGET VERIFY_SSL) + set(multiValueArgs ARGS) + cmake_parse_arguments(CONAN "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(CONAN_CONFIG_INSTALL_ARGS "") + + find_program(CONAN_CMD conan) + if(NOT CONAN_CMD AND CONAN_REQUIRED) + message(FATAL_ERROR "Conan executable not found!") + endif() + + if(DEFINED CONAN_VERIFY_SSL) + set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --verify-ssl ${CONAN_VERIFY_SSL}") + endif() + + if(DEFINED CONAN_TYPE) + set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --type ${CONAN_TYPE}") + endif() + + if(DEFINED CONAN_ARGS) + set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --args \"${CONAN_ARGS}\"") + endif() + + if(DEFINED CONAN_SOURCE) + set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --source-folder ${CONAN_SOURCE}") + endif() + + if(DEFINED CONAN_TARGET) + set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --target-folder ${CONAN_TARGET}") + endif() + + message(STATUS "Conan: Installing config from ${CONAN_ITEM}") + execute_process(COMMAND ${CONAN_CMD} config install ${CONAN_CONFIG_INSTALL_ARGS} ${CONAN_ITEM}) endmacro() diff --git a/src/dependencies.cmake b/src/dependencies.cmake index fd9dbb1a..4cd70e6a 100644 --- a/src/dependencies.cmake +++ b/src/dependencies.cmake @@ -1,7 +1,7 @@ ### setup conan set(PLD_CONAN_TOOLS "${CMAKE_SOURCE_DIR}/../conan") -include(${PLD_CONAN_TOOLS}/conan-0.14.cmake) +include(${PLD_CONAN_TOOLS}/conan-0.15.cmake) conan_check(VERSION 1.20 REQUIRED) From a9c06ad38195a59d99946161ede6437dff998e02 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 14:35:58 +0200 Subject: [PATCH 43/54] conan: more robust (version check) package recipe for Houdini --- conan/houdini/conanfile.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/conan/houdini/conanfile.py b/conan/houdini/conanfile.py index 0409cc81..d19e703c 100644 --- a/conan/houdini/conanfile.py +++ b/conan/houdini/conanfile.py @@ -1,7 +1,9 @@ from conans import ConanFile from conans.model.version import Version +from conans.errors import ConanInvalidConfiguration import os + class HoudiniConan(ConanFile): name = "houdini" settings = "os", "compiler", "arch" @@ -10,30 +12,25 @@ class HoudiniConan(ConanFile): license = "SIDE EFFECTS SOFTWARE LICENSE AGREEMENT, https://www.sidefx.com/legal/license-agreement" short_paths = True - houdiniDefaultInstallationPath = r'C:\Program Files\Side Effects Software\Houdini {}' + local_houdini_installation = "" def build(self): - pass + proto_installation_path = r'C:\Program Files\Side Effects Software\Houdini {}' \ + if self.settings.os == "Windows" else "/opt/hfs{}" + self.local_houdini_installation = os.getenv( + 'HOUDINI_INSTALL') if 'HOUDINI_INSTALL' in os.environ else proto_installation_path.format(self.version) + if not os.path.exists(self.local_houdini_installation): + raise ConanInvalidConfiguration("Invalid Houdini installation path: {}".format(self.local_houdini_installation)) def package(self): + self.copy("bin/*", ".", self.local_houdini_installation) # needed for sesitag etc + self.copy("toolkit/*", ".", self.local_houdini_installation) if self.settings.os == "Windows": - local_install = os.getenv('HOUDINI_INSTALL')\ - if 'HOUDINI_INSTALL' in os.environ\ - else self.houdiniDefaultInstallationPath.format(self.version) - self.copy("bin/*", ".", local_install) # needed for sesitag etc - self.copy("custom/*", ".", local_install) - self.copy("toolkit/*", ".", local_install) + self.copy("custom/*", ".", self.local_houdini_installation) elif self.settings.os == "Linux": - local_install = os.getenv('HOUDINI_INSTALL')\ - if 'HOUDINI_INSTALL' in os.environ\ - else "/opt/hfs{}".format(self.version) - self.copy("houdini_setup*", ".", local_install) # needed for sesitag etc - self.copy("bin/*", ".", local_install) # needed for sesitag etc - self.copy("dsolib/*", ".", local_install) - self.copy("toolkit/*", ".", local_install) - self.copy("houdini/Licensing.opt", ".", local_install) - else: - raise Exception("platform not supported!") + self.copy("houdini_setup*", ".", self.local_houdini_installation) # needed for sesitag etc + self.copy("dsolib/*", ".", self.local_houdini_installation) + self.copy("houdini/Licensing.opt", ".", self.local_houdini_installation) def package_info(self): self.cpp_info.libdirs = ['dsolib'] From 361f3a4bafaf44939033dafee92d6dcc380ae8d4 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 15:08:32 +0200 Subject: [PATCH 44/54] #30: introduce log level parameter --- src/palladio/NodeParameter.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/palladio/NodeParameter.h b/src/palladio/NodeParameter.h index b94f0c0f..7aa3e8d4 100644 --- a/src/palladio/NodeParameter.h +++ b/src/palladio/NodeParameter.h @@ -33,6 +33,21 @@ #include PLD_BOOST_INCLUDE(/filesystem/path.hpp) // clang-format on +namespace CommonNodeParams { + +static PRM_Name LOG_LEVEL("logLevel", "Log Level"); +static const char* LOG_LEVEL_TOKENS[] = {"Default", "Debug", "Info", "Warning", "Error", "Fatal", "None"}; +static PRM_Name LOG_LEVEL_MENU_ITEMS[] = {PRM_Name(LOG_LEVEL_TOKENS[0]), PRM_Name(LOG_LEVEL_TOKENS[1]), + PRM_Name(LOG_LEVEL_TOKENS[2]), PRM_Name(LOG_LEVEL_TOKENS[3]), + PRM_Name(LOG_LEVEL_TOKENS[4]), PRM_Name(LOG_LEVEL_TOKENS[5]), + PRM_Name(LOG_LEVEL_TOKENS[6]), PRM_Name(nullptr)}; +static PRM_ChoiceList logLevelMenu((PRM_ChoiceListType)(PRM_CHOICELIST_EXCLUSIVE | PRM_CHOICELIST_REPLACE), + LOG_LEVEL_MENU_ITEMS); +const size_t DEFAULT_LOG_LEVEL_ORDINAL = 0; +static PRM_Default DEFAULT_LOG_LEVEL(0, LOG_LEVEL_TOKENS[DEFAULT_LOG_LEVEL_ORDINAL]); + +} // namespace CommonNodeParams + namespace AssignNodeParams { // -- PRIMITIVE CLASSIFIER NAME @@ -138,6 +153,8 @@ static PRM_Template PARAM_TEMPLATES[] = { STYLE_HELP.c_str()), PRM_Template(PRM_STRING, 1, &START_RULE, PRMoneDefaults, &startRuleMenu, nullptr, PRM_Callback(), nullptr, 1, START_RULE_HELP.c_str()), + PRM_Template(PRM_ORD, PRM_Template::PRM_EXPORT_MAX, 1, &CommonNodeParams::LOG_LEVEL, + &CommonNodeParams::DEFAULT_LOG_LEVEL, &CommonNodeParams::logLevelMenu), PRM_Template()}; } // namespace AssignNodeParams @@ -174,6 +191,10 @@ static PRM_Template PARAM_TEMPLATES[]{PRM_Template(PRM_ORD, PRM_Template::PRM_EX &DEFAULT_GROUP_CREATION, &groupCreationMenu), PRM_Template(PRM_TOGGLE, 1, &EMIT_ATTRS), PRM_Template(PRM_TOGGLE, 1, &EMIT_MATERIAL), - PRM_Template(PRM_TOGGLE, 1, &EMIT_REPORTS), PRM_Template()}; + PRM_Template(PRM_TOGGLE, 1, &EMIT_REPORTS), + PRM_Template(PRM_ORD, PRM_Template::PRM_EXPORT_MAX, 1, + &CommonNodeParams::LOG_LEVEL, &CommonNodeParams::DEFAULT_LOG_LEVEL, + &CommonNodeParams::logLevelMenu), + PRM_Template()}; } // namespace GenerateNodeParams From 193c30657730d1536b830dad9411cf9dd6e45db6 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 15:12:23 +0200 Subject: [PATCH 45/54] #30: clarify function name to get initial log level --- src/palladio/PRTContext.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/palladio/PRTContext.cpp b/src/palladio/PRTContext.cpp index 4781e3f2..4fa388f5 100644 --- a/src/palladio/PRTContext.cpp +++ b/src/palladio/PRTContext.cpp @@ -84,7 +84,7 @@ class License { #endif // PRT_VERSION_MAJOR < 2 // TODO: move to LogHandler -prt::LogLevel getLogLevel() { +prt::LogLevel getDefaultLogLevel() { const char* e = std::getenv(PRT_LOG_LEVEL_ENV_VAR); if (e == nullptr || strlen(e) == 0) return PRT_LOG_LEVEL_DEFAULT; @@ -144,8 +144,8 @@ PRTContext::PRTContext(const std::vector& addExt : mLogHandler(new logging::LogHandler(PLD_LOG_PREFIX)), mPRTHandle{nullptr}, mPRTCache{prt::CacheObject::create(prt::CacheObject::CACHE_TYPE_DEFAULT)}, mCores{getNumCores()}, mResolveMapCache{new ResolveMapCache(getProcessTempDir())} { - const prt::LogLevel logLevel = getLogLevel(); - prt::setLogLevel(logLevel); + const prt::LogLevel defaultLogLevel = getDefaultLogLevel(); + prt::setLogLevel(defaultLogLevel); prt::addLogHandler(mLogHandler.get()); // -- get the dir containing prt core library @@ -183,7 +183,7 @@ PRTContext::PRTContext(const std::vector& addExt // -- initialize PRT prt::Status status = prt::STATUS_UNSPECIFIED_ERROR; - mPRTHandle.reset(prt::init(extDirCStrs.data(), extDirCStrs.size(), logLevel, + mPRTHandle.reset(prt::init(extDirCStrs.data(), extDirCStrs.size(), defaultLogLevel, #if PRT_VERSION_MAJOR < 2 license.getParams(), #endif From 0391a0347973a0b6c10dd31e078ae5f3d511a63e Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 15:21:24 +0200 Subject: [PATCH 46/54] #30: move getDefaultLogLevel to logging namespace --- src/palladio/CMakeLists.txt | 2 +- src/palladio/LogHandler.cpp | 42 +++++++++++++++++++++++++++++++++++++ src/palladio/LogHandler.h | 2 ++ src/palladio/PRTContext.cpp | 18 +--------------- 4 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 src/palladio/LogHandler.cpp diff --git a/src/palladio/CMakeLists.txt b/src/palladio/CMakeLists.txt index 7114d306..278dcdcb 100644 --- a/src/palladio/CMakeLists.txt +++ b/src/palladio/CMakeLists.txt @@ -25,7 +25,7 @@ add_library(${PROJECT_NAME} SHARED AttributeConversion.cpp MultiWatch.cpp PrimitiveClassifier.cpp - LogHandler.h + LogHandler.cpp LRUCache.h BoostRedirect.h) diff --git a/src/palladio/LogHandler.cpp b/src/palladio/LogHandler.cpp new file mode 100644 index 00000000..17be4ab2 --- /dev/null +++ b/src/palladio/LogHandler.cpp @@ -0,0 +1,42 @@ +/* + * Copyright 2014-2019 Esri R&D Zurich and VRBN + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LogHandler.h" + +#include + +namespace { + +constexpr const prt::LogLevel PRT_LOG_LEVEL_DEFAULT = prt::LOG_ERROR; +constexpr const char* PRT_LOG_LEVEL_ENV_VAR = "CITYENGINE_LOG_LEVEL"; +constexpr const char* PRT_LOG_LEVEL_STRINGS[] = {"trace", "debug", "info", "warning", "error", "fatal"}; +constexpr const size_t PRT_LOG_LEVEL_STRINGS_N = sizeof(PRT_LOG_LEVEL_STRINGS) / sizeof(PRT_LOG_LEVEL_STRINGS[0]); + +} // namespace + +namespace logging { + +prt::LogLevel getDefaultLogLevel() { + const char* e = std::getenv(PRT_LOG_LEVEL_ENV_VAR); + if (e == nullptr || std::strlen(e) == 0) + return PRT_LOG_LEVEL_DEFAULT; + for (size_t i = 0; i < PRT_LOG_LEVEL_STRINGS_N; i++) + if (std::strcmp(e, PRT_LOG_LEVEL_STRINGS[i]) == 0) + return static_cast(i); + return PRT_LOG_LEVEL_DEFAULT; +} + +} // namespace logging \ No newline at end of file diff --git a/src/palladio/LogHandler.h b/src/palladio/LogHandler.h index 9f3e364c..1d07d9c4 100644 --- a/src/palladio/LogHandler.h +++ b/src/palladio/LogHandler.h @@ -29,6 +29,8 @@ namespace logging { +prt::LogLevel getDefaultLogLevel(); + struct Logger {}; const std::string LEVELS[] = {"trace", "debug", "info", "warning", "error", "fatal"}; diff --git a/src/palladio/PRTContext.cpp b/src/palladio/PRTContext.cpp index 4fa388f5..f573d543 100644 --- a/src/palladio/PRTContext.cpp +++ b/src/palladio/PRTContext.cpp @@ -37,11 +37,6 @@ constexpr const char* PLD_TMP_PREFIX = "palladio_"; constexpr const char* PRT_LIB_SUBDIR = "prtlib"; -constexpr const prt::LogLevel PRT_LOG_LEVEL_DEFAULT = prt::LOG_ERROR; -constexpr const char* PRT_LOG_LEVEL_ENV_VAR = "CITYENGINE_LOG_LEVEL"; -constexpr const char* PRT_LOG_LEVEL_STRINGS[] = {"trace", "debug", "info", "warning", "error", "fatal"}; -constexpr const size_t PRT_LOG_LEVEL_STRINGS_N = sizeof(PRT_LOG_LEVEL_STRINGS) / sizeof(PRT_LOG_LEVEL_STRINGS[0]); - #if PRT_VERSION_MAJOR < 2 constexpr const char* FILE_FLEXNET_LIB = "flexnet_prt"; @@ -83,17 +78,6 @@ class License { #endif // PRT_VERSION_MAJOR < 2 -// TODO: move to LogHandler -prt::LogLevel getDefaultLogLevel() { - const char* e = std::getenv(PRT_LOG_LEVEL_ENV_VAR); - if (e == nullptr || strlen(e) == 0) - return PRT_LOG_LEVEL_DEFAULT; - for (size_t i = 0; i < PRT_LOG_LEVEL_STRINGS_N; i++) - if (strcmp(e, PRT_LOG_LEVEL_STRINGS[i]) == 0) - return static_cast(i); - return PRT_LOG_LEVEL_DEFAULT; -} - template std::vector toPtrVec(const std::vector>& sv) { std::vector pv(sv.size()); @@ -144,7 +128,7 @@ PRTContext::PRTContext(const std::vector& addExt : mLogHandler(new logging::LogHandler(PLD_LOG_PREFIX)), mPRTHandle{nullptr}, mPRTCache{prt::CacheObject::create(prt::CacheObject::CACHE_TYPE_DEFAULT)}, mCores{getNumCores()}, mResolveMapCache{new ResolveMapCache(getProcessTempDir())} { - const prt::LogLevel defaultLogLevel = getDefaultLogLevel(); + const prt::LogLevel defaultLogLevel = logging::getDefaultLogLevel(); prt::setLogLevel(defaultLogLevel); prt::addLogHandler(mLogHandler.get()); From eafc023612e50dc25aca9f7f82d33b21137440a2 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 15:28:15 +0200 Subject: [PATCH 47/54] #30: add helper function to get per-node log level --- src/palladio/NodeParameter.cpp | 25 +++++++++++++++++++++++++ src/palladio/NodeParameter.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/src/palladio/NodeParameter.cpp b/src/palladio/NodeParameter.cpp index 6c7c114e..a0f1758f 100644 --- a/src/palladio/NodeParameter.cpp +++ b/src/palladio/NodeParameter.cpp @@ -68,6 +68,31 @@ constexpr const int CHANGED = 1; } // namespace +namespace CommonNodeParams { + +prt::LogLevel getLogLevel(const OP_Node* node, fpreal t) { + const auto ord = node->evalInt(LOG_LEVEL.getToken(), 0, t); + switch (ord) { + case 1: + return prt::LOG_DEBUG; + case 2: + return prt::LOG_INFO; + case 3: + return prt::LOG_WARNING; + case 4: + return prt::LOG_ERROR; + case 5: + return prt::LOG_FATAL; + case 6: + return prt::LOG_NO; + default: + break; + } + return logging::getDefaultLogLevel(); +}; + +} // namespace CommonNodeParams + namespace AssignNodeParams { /** diff --git a/src/palladio/NodeParameter.h b/src/palladio/NodeParameter.h index 7aa3e8d4..90f21287 100644 --- a/src/palladio/NodeParameter.h +++ b/src/palladio/NodeParameter.h @@ -28,6 +28,8 @@ #include "PRM/PRM_Shared.h" #include "PRM/PRM_SpareData.h" +#include "prt/LogLevel.h" + // clang-format off #include "BoostRedirect.h" #include PLD_BOOST_INCLUDE(/filesystem/path.hpp) @@ -46,6 +48,8 @@ static PRM_ChoiceList logLevelMenu((PRM_ChoiceListType)(PRM_CHOICELIST_EXCLUSIVE const size_t DEFAULT_LOG_LEVEL_ORDINAL = 0; static PRM_Default DEFAULT_LOG_LEVEL(0, LOG_LEVEL_TOKENS[DEFAULT_LOG_LEVEL_ORDINAL]); +prt::LogLevel getLogLevel(const OP_Node* node, fpreal t); + } // namespace CommonNodeParams namespace AssignNodeParams { From 28fe11decba67ae74a9fea0fa5b2b604346b5c45 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 15:46:44 +0200 Subject: [PATCH 48/54] #30: added RAII-style log level modifier --- src/palladio/LogHandler.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/palladio/LogHandler.h b/src/palladio/LogHandler.h index 1d07d9c4..3d5c10a8 100644 --- a/src/palladio/LogHandler.h +++ b/src/palladio/LogHandler.h @@ -31,6 +31,20 @@ namespace logging { prt::LogLevel getDefaultLogLevel(); +class ScopedLogLevelModifier { +public: + ScopedLogLevelModifier() = delete; + explicit ScopedLogLevelModifier(prt::LogLevel newLevel) : mOriginalLevel(prt::getLogLevel()) { + prt::setLogLevel(newLevel); + } + ~ScopedLogLevelModifier() { + prt::setLogLevel(mOriginalLevel); + } + +private: + prt::LogLevel mOriginalLevel; +}; + struct Logger {}; const std::string LEVELS[] = {"trace", "debug", "info", "warning", "error", "fatal"}; From 405d7f83651c96b518da5e0afc6a3de6381d7ca1 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 15:47:03 +0200 Subject: [PATCH 49/54] #30: override log level per node --- src/palladio/SOPAssign.cpp | 2 ++ src/palladio/SOPGenerate.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/palladio/SOPAssign.cpp b/src/palladio/SOPAssign.cpp index 02b44eb2..a6e5db3d 100644 --- a/src/palladio/SOPAssign.cpp +++ b/src/palladio/SOPAssign.cpp @@ -142,6 +142,8 @@ OP_ERROR SOPAssign::cookMySop(OP_Context& context) { WA_NEW_LAP WA("all"); + logging::ScopedLogLevelModifier scopedLogLevel(CommonNodeParams::getLogLevel(this, context.getTime())); + if (lockInputs(context) >= UT_ERROR_ABORT) { LOG_DBG << "lockInputs error"; return error(); diff --git a/src/palladio/SOPGenerate.cpp b/src/palladio/SOPGenerate.cpp index 073a1ae3..486f00e4 100644 --- a/src/palladio/SOPGenerate.cpp +++ b/src/palladio/SOPGenerate.cpp @@ -136,6 +136,8 @@ std::vector batchGenerate(BatchMode mode, size_t nThreads, std::vec OP_ERROR SOPGenerate::cookMySop(OP_Context& context) { WA("all"); + logging::ScopedLogLevelModifier scopedLogLevel(CommonNodeParams::getLogLevel(this, context.getTime())); + if (!handleParams(context)) return UT_ERROR_ABORT; From 8630f6480d558356f0f6bf3b6b00ac173fb98f58 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Sun, 23 Aug 2020 16:18:41 +0200 Subject: [PATCH 50/54] Updated change log for #30 --- doc/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog.md b/doc/changelog.md index 23b430da..defcb1f7 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -3,6 +3,7 @@ ## v1.8.0 Beta 1 (Aug 23, 2020) * Update default CityEngine SDK to 2.2 (CityEngine 2020.0) (#146). * Added support for CGA array attributes (#146). +* Added per-node control of log level (#30). * At startup, print Palladio version on console if log level is "info" or lower. * Development * On Windows, building Palladio now requires MSVC 14.2 (#146). From 15d3d7a377930a85d29074e5c139ea28ad036ba7 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Thu, 17 Sep 2020 16:50:00 +0200 Subject: [PATCH 51/54] Update copyright statements to 2020 --- LICENSE | 2 +- src/codec/CodecMain.cpp | 2 +- src/codec/CodecMain.h | 2 +- src/codec/encoder/HoudiniCallbacks.h | 2 +- src/codec/encoder/HoudiniEncoder.cpp | 2 +- src/codec/encoder/HoudiniEncoder.h | 2 +- src/palladio/AttrEvalCallbacks.cpp | 2 +- src/palladio/AttrEvalCallbacks.h | 2 +- src/palladio/AttributeConversion.cpp | 2 +- src/palladio/AttributeConversion.h | 2 +- src/palladio/BoostRedirect.h | 2 +- src/palladio/LRUCache.h | 2 +- src/palladio/LogHandler.cpp | 2 +- src/palladio/LogHandler.h | 2 +- src/palladio/ModelConverter.cpp | 2 +- src/palladio/ModelConverter.h | 2 +- src/palladio/MultiWatch.cpp | 2 +- src/palladio/MultiWatch.h | 2 +- src/palladio/NodeParameter.cpp | 2 +- src/palladio/NodeParameter.h | 2 +- src/palladio/PRTContext.cpp | 2 +- src/palladio/PRTContext.h | 2 +- src/palladio/PalladioMain.cpp | 2 +- src/palladio/PalladioMain.h | 2 +- src/palladio/PrimitiveClassifier.cpp | 2 +- src/palladio/PrimitiveClassifier.h | 2 +- src/palladio/PrimitivePartition.cpp | 2 +- src/palladio/PrimitivePartition.h | 2 +- src/palladio/ResolveMapCache.cpp | 2 +- src/palladio/ResolveMapCache.h | 2 +- src/palladio/SOPAssign.cpp | 2 +- src/palladio/SOPAssign.h | 2 +- src/palladio/SOPGenerate.cpp | 2 +- src/palladio/SOPGenerate.h | 2 +- src/palladio/ShapeConverter.cpp | 2 +- src/palladio/ShapeConverter.h | 2 +- src/palladio/ShapeData.cpp | 2 +- src/palladio/ShapeData.h | 2 +- src/palladio/ShapeGenerator.cpp | 2 +- src/palladio/ShapeGenerator.h | 2 +- src/palladio/Utils.cpp | 2 +- src/palladio/Utils.h | 2 +- src/test/TestCallbacks.h | 2 +- src/test/TestUtils.cpp | 2 +- src/test/TestUtils.h | 2 +- src/test/tests.cpp | 2 +- 46 files changed, 46 insertions(+), 46 deletions(-) diff --git a/LICENSE b/LICENSE index 799bde35..f3cc1b89 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2014-2019 Esri R&D Zurich and VRBN + Copyright 2014-2020 Esri R&D Zurich and VRBN Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/codec/CodecMain.cpp b/src/codec/CodecMain.cpp index 63c877c3..e41f6952 100644 --- a/src/codec/CodecMain.cpp +++ b/src/codec/CodecMain.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/codec/CodecMain.h b/src/codec/CodecMain.h index d8057614..7c03a896 100644 --- a/src/codec/CodecMain.h +++ b/src/codec/CodecMain.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/codec/encoder/HoudiniCallbacks.h b/src/codec/encoder/HoudiniCallbacks.h index 66566e83..23265ba9 100644 --- a/src/codec/encoder/HoudiniCallbacks.h +++ b/src/codec/encoder/HoudiniCallbacks.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/codec/encoder/HoudiniEncoder.cpp b/src/codec/encoder/HoudiniEncoder.cpp index 745aa25e..9c1f9c6b 100644 --- a/src/codec/encoder/HoudiniEncoder.cpp +++ b/src/codec/encoder/HoudiniEncoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/codec/encoder/HoudiniEncoder.h b/src/codec/encoder/HoudiniEncoder.h index 768448b4..3cb6cc23 100644 --- a/src/codec/encoder/HoudiniEncoder.h +++ b/src/codec/encoder/HoudiniEncoder.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/AttrEvalCallbacks.cpp b/src/palladio/AttrEvalCallbacks.cpp index 452992fe..83954b47 100644 --- a/src/palladio/AttrEvalCallbacks.cpp +++ b/src/palladio/AttrEvalCallbacks.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/AttrEvalCallbacks.h b/src/palladio/AttrEvalCallbacks.h index 98f609dd..83566727 100644 --- a/src/palladio/AttrEvalCallbacks.h +++ b/src/palladio/AttrEvalCallbacks.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/AttributeConversion.cpp b/src/palladio/AttributeConversion.cpp index a715e16c..02108e14 100644 --- a/src/palladio/AttributeConversion.cpp +++ b/src/palladio/AttributeConversion.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/AttributeConversion.h b/src/palladio/AttributeConversion.h index 10ec47b2..d4799730 100644 --- a/src/palladio/AttributeConversion.h +++ b/src/palladio/AttributeConversion.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/BoostRedirect.h b/src/palladio/BoostRedirect.h index c671e919..bc9e88fe 100644 --- a/src/palladio/BoostRedirect.h +++ b/src/palladio/BoostRedirect.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/LRUCache.h b/src/palladio/LRUCache.h index fcba6597..c7878bf9 100644 --- a/src/palladio/LRUCache.h +++ b/src/palladio/LRUCache.h @@ -117,7 +117,7 @@ class lru_cache { }; /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/LogHandler.cpp b/src/palladio/LogHandler.cpp index 17be4ab2..b03b496b 100644 --- a/src/palladio/LogHandler.cpp +++ b/src/palladio/LogHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/LogHandler.h b/src/palladio/LogHandler.h index 3d5c10a8..4a22fedd 100644 --- a/src/palladio/LogHandler.h +++ b/src/palladio/LogHandler.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ModelConverter.cpp b/src/palladio/ModelConverter.cpp index 9fcf89a5..f5a870b7 100644 --- a/src/palladio/ModelConverter.cpp +++ b/src/palladio/ModelConverter.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ModelConverter.h b/src/palladio/ModelConverter.h index 84f93142..586fb42c 100644 --- a/src/palladio/ModelConverter.h +++ b/src/palladio/ModelConverter.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/MultiWatch.cpp b/src/palladio/MultiWatch.cpp index 77b88dbd..b808eb20 100644 --- a/src/palladio/MultiWatch.cpp +++ b/src/palladio/MultiWatch.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/MultiWatch.h b/src/palladio/MultiWatch.h index 8d36c13a..0a90c38e 100644 --- a/src/palladio/MultiWatch.h +++ b/src/palladio/MultiWatch.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/NodeParameter.cpp b/src/palladio/NodeParameter.cpp index a0f1758f..2d0cf97b 100644 --- a/src/palladio/NodeParameter.cpp +++ b/src/palladio/NodeParameter.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/NodeParameter.h b/src/palladio/NodeParameter.h index 90f21287..f943a355 100644 --- a/src/palladio/NodeParameter.h +++ b/src/palladio/NodeParameter.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PRTContext.cpp b/src/palladio/PRTContext.cpp index f573d543..646ed864 100644 --- a/src/palladio/PRTContext.cpp +++ b/src/palladio/PRTContext.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PRTContext.h b/src/palladio/PRTContext.h index 8f9dc4ec..feebef58 100644 --- a/src/palladio/PRTContext.h +++ b/src/palladio/PRTContext.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PalladioMain.cpp b/src/palladio/PalladioMain.cpp index ed6d2405..d7ca3586 100644 --- a/src/palladio/PalladioMain.cpp +++ b/src/palladio/PalladioMain.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PalladioMain.h b/src/palladio/PalladioMain.h index 1259d6ab..a51c32c8 100644 --- a/src/palladio/PalladioMain.h +++ b/src/palladio/PalladioMain.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PrimitiveClassifier.cpp b/src/palladio/PrimitiveClassifier.cpp index 57b20cac..88ba0fc7 100644 --- a/src/palladio/PrimitiveClassifier.cpp +++ b/src/palladio/PrimitiveClassifier.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PrimitiveClassifier.h b/src/palladio/PrimitiveClassifier.h index cb59d9c9..0596d853 100644 --- a/src/palladio/PrimitiveClassifier.h +++ b/src/palladio/PrimitiveClassifier.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PrimitivePartition.cpp b/src/palladio/PrimitivePartition.cpp index 6e3e2319..9fe29b84 100644 --- a/src/palladio/PrimitivePartition.cpp +++ b/src/palladio/PrimitivePartition.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/PrimitivePartition.h b/src/palladio/PrimitivePartition.h index e8a3b698..cc6ed714 100644 --- a/src/palladio/PrimitivePartition.h +++ b/src/palladio/PrimitivePartition.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ResolveMapCache.cpp b/src/palladio/ResolveMapCache.cpp index ebc774fc..e1bec1fe 100644 --- a/src/palladio/ResolveMapCache.cpp +++ b/src/palladio/ResolveMapCache.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ResolveMapCache.h b/src/palladio/ResolveMapCache.h index d7ce9657..b918d229 100644 --- a/src/palladio/ResolveMapCache.h +++ b/src/palladio/ResolveMapCache.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/SOPAssign.cpp b/src/palladio/SOPAssign.cpp index a6e5db3d..5fdb64b3 100644 --- a/src/palladio/SOPAssign.cpp +++ b/src/palladio/SOPAssign.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/SOPAssign.h b/src/palladio/SOPAssign.h index 33b0524a..ad17505e 100644 --- a/src/palladio/SOPAssign.h +++ b/src/palladio/SOPAssign.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/SOPGenerate.cpp b/src/palladio/SOPGenerate.cpp index 486f00e4..1d40cf6b 100644 --- a/src/palladio/SOPGenerate.cpp +++ b/src/palladio/SOPGenerate.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/SOPGenerate.h b/src/palladio/SOPGenerate.h index 488ffb0f..fa46bfc8 100644 --- a/src/palladio/SOPGenerate.h +++ b/src/palladio/SOPGenerate.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ShapeConverter.cpp b/src/palladio/ShapeConverter.cpp index d3263c8d..21e9c519 100644 --- a/src/palladio/ShapeConverter.cpp +++ b/src/palladio/ShapeConverter.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ShapeConverter.h b/src/palladio/ShapeConverter.h index 72dfd309..e76d21a8 100644 --- a/src/palladio/ShapeConverter.h +++ b/src/palladio/ShapeConverter.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ShapeData.cpp b/src/palladio/ShapeData.cpp index 07833b52..4bf8d381 100644 --- a/src/palladio/ShapeData.cpp +++ b/src/palladio/ShapeData.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ShapeData.h b/src/palladio/ShapeData.h index 9da2ae6e..c89fc5f7 100644 --- a/src/palladio/ShapeData.h +++ b/src/palladio/ShapeData.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ShapeGenerator.cpp b/src/palladio/ShapeGenerator.cpp index 7925efe7..26735d86 100644 --- a/src/palladio/ShapeGenerator.cpp +++ b/src/palladio/ShapeGenerator.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/ShapeGenerator.h b/src/palladio/ShapeGenerator.h index 7659b2f1..6fb3fa88 100644 --- a/src/palladio/ShapeGenerator.h +++ b/src/palladio/ShapeGenerator.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/Utils.cpp b/src/palladio/Utils.cpp index dce80663..081773ff 100644 --- a/src/palladio/Utils.cpp +++ b/src/palladio/Utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/palladio/Utils.h b/src/palladio/Utils.h index 2db94023..e62db205 100644 --- a/src/palladio/Utils.h +++ b/src/palladio/Utils.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/TestCallbacks.h b/src/test/TestCallbacks.h index 8d5a6f59..37fb338e 100644 --- a/src/test/TestCallbacks.h +++ b/src/test/TestCallbacks.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/TestUtils.cpp b/src/test/TestUtils.cpp index 01d39d18..c42b3ca4 100644 --- a/src/test/TestUtils.cpp +++ b/src/test/TestUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/TestUtils.h b/src/test/TestUtils.h index 940c0fbe..bafa56e6 100644 --- a/src/test/TestUtils.h +++ b/src/test/TestUtils.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/tests.cpp b/src/test/tests.cpp index e6f0a56e..96fe424e 100644 --- a/src/test/tests.cpp +++ b/src/test/tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 Esri R&D Zurich and VRBN + * Copyright 2014-2020 Esri R&D Zurich and VRBN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 3cef9cc4722b4d3193505c5edc1b92eec62f10ed Mon Sep 17 00:00:00 2001 From: Andreas Frischknecht Date: Fri, 18 Sep 2020 13:34:50 +0200 Subject: [PATCH 52/54] Use https url to avoid need for SSH credentials. Since this is a public repository and since the build only reads from the repo, it makes sense to avoid the need to manage credentials for the repository and use the https url for cloning. If at a later point we decide that we need write access to the repo we can switch to using a deploy key. --- pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline.groovy b/pipeline.groovy index 88dbdd40..99c27564 100644 --- a/pipeline.groovy +++ b/pipeline.groovy @@ -15,7 +15,7 @@ import com.esri.zrh.jenkins.psl.UploadTrackingPsl // -- GLOBAL DEFINITIONS -@Field final String REPO = 'git@github.com:Esri/palladio.git' +@Field final String REPO = 'https://github.com/Esri/palladio.git' @Field final String SOURCE = "palladio.git/src" @Field final String BUILD_TARGET = 'package' From 7f2f5f9359ec8d46f7524cfedfa699e405351188 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Mon, 5 Oct 2020 10:28:27 +0200 Subject: [PATCH 53/54] Switch to version 1.8.0 final --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e5c4583..60dc26d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,7 +45,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/dependencies.cmake) set(PLD_VERSION_MAJOR 1) set(PLD_VERSION_MINOR 8) set(PLD_VERSION_PATCH 0) -set(PLD_VERSION_PRE "-beta.1") # set to empty string for final releases +set(PLD_VERSION_PRE "") # set to empty string for final releases if(NOT PLD_VERSION_BUILD) set(PLD_VERSION_BUILD DEV) endif() From d3ffb477a490877a510bc97ec44a5379c2eba1f1 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Mon, 5 Oct 2020 10:31:59 +0200 Subject: [PATCH 54/54] Updated changelog for 1.8.0 --- doc/changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/changelog.md b/doc/changelog.md index defcb1f7..d67ca3ec 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -1,5 +1,8 @@ # Palladio ChangeLog +## v1.8.0 (Oct 5, 2020) +* No functional changes compared to Beta 1. + ## v1.8.0 Beta 1 (Aug 23, 2020) * Update default CityEngine SDK to 2.2 (CityEngine 2020.0) (#146). * Added support for CGA array attributes (#146).