From a95bec62b8a3744cad64f2f11b4df74a92d606be Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 25 Jan 2025 18:25:53 +0000 Subject: [PATCH 1/5] Added basic IO support for CoordinateSpace --- include/vsg/utils/CoordinateSpace.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/vsg/utils/CoordinateSpace.h b/include/vsg/utils/CoordinateSpace.h index 956ffedc84..8be548716d 100644 --- a/include/vsg/utils/CoordinateSpace.h +++ b/include/vsg/utils/CoordinateSpace.h @@ -25,6 +25,28 @@ namespace vsg LINEAR = (1 << 0), sRGB = (1 << 1) }; + VSG_type_name(vsg::CoordinateSpace); + + inline std::istream& operator>>(std::istream& input, CoordinateSpace& coordinateSpace) + { + std::string value; + input >> value; + + if (value == "LINEAR") coordinateSpace = CoordinateSpace::LINEAR; + else if (value == "sRGB") coordinateSpace = CoordinateSpace::sRGB; + else coordinateSpace = CoordinateSpace::NO_PREFERENCE; + + return input; + } + + inline std::ostream& operator<<(std::ostream& output, const CoordinateSpace& coordinateSpace) + { + if (coordinateSpace==CoordinateSpace::LINEAR) output<<"LINEAR"; + else if (coordinateSpace==CoordinateSpace::sRGB) output<<"sRGB"; + else output<<"NO_PREFERENCE"; + + return output; + } template constexpr T linear_to_sRGB_component(T c) From 7d3bbf400efa7a74dacaf564da3e2cd2e2462e14 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 27 Jan 2025 16:56:29 +0000 Subject: [PATCH 2/5] Moved CoordinateSpace io to stream.h header. --- include/vsg/io/stream.h | 24 ++++++++++++++++++++++++ include/vsg/utils/CoordinateSpace.h | 23 ----------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/vsg/io/stream.h b/include/vsg/io/stream.h index c306e71e06..59a516445b 100644 --- a/include/vsg/io/stream.h +++ b/include/vsg/io/stream.h @@ -25,6 +25,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include @@ -284,4 +285,27 @@ namespace vsg return output; } + + inline std::istream& operator>>(std::istream& input, CoordinateSpace& coordinateSpace) + { + std::string value; + input >> value; + + if (value == "LINEAR") coordinateSpace = CoordinateSpace::LINEAR; + else if (value == "sRGB") coordinateSpace = CoordinateSpace::sRGB; + else coordinateSpace = CoordinateSpace::NO_PREFERENCE; + + return input; + } + + inline std::ostream& operator<<(std::ostream& output, const CoordinateSpace& coordinateSpace) + { + if (coordinateSpace==CoordinateSpace::LINEAR) output<<"LINEAR"; + else if (coordinateSpace==CoordinateSpace::sRGB) output<<"sRGB"; + else output<<"NO_PREFERENCE"; + + return output; + } + + } // namespace vsg diff --git a/include/vsg/utils/CoordinateSpace.h b/include/vsg/utils/CoordinateSpace.h index 8be548716d..0eae64d622 100644 --- a/include/vsg/utils/CoordinateSpace.h +++ b/include/vsg/utils/CoordinateSpace.h @@ -12,8 +12,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include -#include #include namespace vsg @@ -27,27 +25,6 @@ namespace vsg }; VSG_type_name(vsg::CoordinateSpace); - inline std::istream& operator>>(std::istream& input, CoordinateSpace& coordinateSpace) - { - std::string value; - input >> value; - - if (value == "LINEAR") coordinateSpace = CoordinateSpace::LINEAR; - else if (value == "sRGB") coordinateSpace = CoordinateSpace::sRGB; - else coordinateSpace = CoordinateSpace::NO_PREFERENCE; - - return input; - } - - inline std::ostream& operator<<(std::ostream& output, const CoordinateSpace& coordinateSpace) - { - if (coordinateSpace==CoordinateSpace::LINEAR) output<<"LINEAR"; - else if (coordinateSpace==CoordinateSpace::sRGB) output<<"sRGB"; - else output<<"NO_PREFERENCE"; - - return output; - } - template constexpr T linear_to_sRGB_component(T c) { From b96560e44c8df20c9780551188a0ecbc57a62117 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Jan 2025 12:25:31 +0000 Subject: [PATCH 3/5] Added vsg::clone() template function. --- include/vsg/core/Object.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/vsg/core/Object.h b/include/vsg/core/Object.h index 43a4302559..e992d55c6f 100644 --- a/include/vsg/core/Object.h +++ b/include/vsg/core/Object.h @@ -259,4 +259,12 @@ namespace vsg return dest; } + template + ref_ptr clone(vsg::ref_ptr object) + { + if (!object) return {}; + auto new_object = object->clone(); + return new_object.template cast(); + } + } // namespace vsg From 8aa4f48c08e2bd58429d644da37bfec4fa34d37a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Jan 2025 13:02:21 +0000 Subject: [PATCH 4/5] Implemented standard vsg::Object::clone()/CopyOp support. --- include/vsg/io/Options.h | 14 +++++++++----- src/vsg/io/Options.cpp | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/vsg/io/Options.h b/include/vsg/io/Options.h index ffca00a2ad..be5d94b6c3 100644 --- a/include/vsg/io/Options.h +++ b/include/vsg/io/Options.h @@ -37,7 +37,7 @@ namespace vsg { public: Options(); - explicit Options(const Options& options); + Options(const Options& rhs, const CopyOp& copyop = {}); template explicit Options(Args... args) @@ -47,14 +47,10 @@ namespace vsg Options& operator=(const Options& rhs) = delete; - int compare(const Object& rhs) const override; /// read command line options, assign values to this options object to later use with reading/writing files virtual bool readOptions(CommandLine& arguments); - void read(Input& input) override; - void write(Output& output) const override; - void add(ref_ptr rw = {}); void add(const ReaderWriters& rws); @@ -108,6 +104,14 @@ namespace vsg /// mechanism for propogating dynamic objects classification up parental chain so that cloning is done on all dynamic objects to avoid sharing of dyanmic parts. ref_ptr propagateDynamicObjects; + public: + + ref_ptr clone(const CopyOp& copyop = {}) const override { return Options::create(*this, copyop); } + int compare(const Object& rhs) const override; + + void read(Input& input) override; + void write(Output& output) const override; + protected: virtual ~Options(); }; diff --git a/src/vsg/io/Options.cpp b/src/vsg/io/Options.cpp index 4c2bc654b2..9ee9a858e0 100644 --- a/src/vsg/io/Options.cpp +++ b/src/vsg/io/Options.cpp @@ -36,8 +36,8 @@ Options::Options() propagateDynamicObjects = PropagateDynamicObjects::create(); } -Options::Options(const Options& options) : - Inherit(), +Options::Options(const Options& options, const CopyOp& copyop) : + Inherit(options, copyop), sharedObjects(options.sharedObjects), readerWriters(options.readerWriters), operationThreads(options.operationThreads), From f00fcb490183d36ab95e40e03face633c4b8154e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Jan 2025 13:21:21 +0000 Subject: [PATCH 5/5] Added const vsg::clone() template function and use. --- include/vsg/core/Object.h | 8 ++++++++ src/vsg/nodes/TileDatabase.cpp | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/vsg/core/Object.h b/include/vsg/core/Object.h index e992d55c6f..fce17f532b 100644 --- a/include/vsg/core/Object.h +++ b/include/vsg/core/Object.h @@ -259,6 +259,14 @@ namespace vsg return dest; } + template + ref_ptr clone(vsg::ref_ptr object) + { + if (!object) return {}; + auto new_object = object->clone(); + return new_object.template cast(); + } + template ref_ptr clone(vsg::ref_ptr object) { diff --git a/src/vsg/nodes/TileDatabase.cpp b/src/vsg/nodes/TileDatabase.cpp index 1fe7f31024..68f51ab53e 100644 --- a/src/vsg/nodes/TileDatabase.cpp +++ b/src/vsg/nodes/TileDatabase.cpp @@ -187,7 +187,7 @@ bool TileDatabase::readDatabase(vsg::ref_ptr options) auto tileReader = tile::create(settings, options); - auto local_options = options ? vsg::Options::create(*options) : vsg::Options::create(); + auto local_options = options ? vsg::clone(options) : vsg::Options::create(); local_options->readerWriters.insert(local_options->readerWriters.begin(), tileReader); auto result = vsg::read("root.tile", local_options); @@ -255,7 +255,7 @@ ref_ptr vsg::createBingMapsSettings(const std::string& ima vsg::info("metadata_url = ", metadata_url); - auto txt_options = vsg::Options::create(*options); + auto txt_options = vsg::clone(options); txt_options->extensionHint = ".txt"; if (auto metadata = vsg::read_cast(metadata_url, txt_options))