From 911aeb4150b2f4966c31dd049d5cfbb074de54ec Mon Sep 17 00:00:00 2001 From: gapry Date: Tue, 26 Nov 2024 23:22:33 +0800 Subject: [PATCH 01/19] resolve rebase conflicts manually --- plugins/usd/module/vtkF3DUSDImporter.cxx | 2 + vtkext/private/module/vtkF3DEXRReader.cxx | 91 +++++++++++++++++++---- vtkext/private/module/vtkF3DEXRReader.h | 58 +++++++++++++++ 3 files changed, 137 insertions(+), 14 deletions(-) diff --git a/plugins/usd/module/vtkF3DUSDImporter.cxx b/plugins/usd/module/vtkF3DUSDImporter.cxx index 8c34cafd83..9c9dbed402 100644 --- a/plugins/usd/module/vtkF3DUSDImporter.cxx +++ b/plugins/usd/module/vtkF3DUSDImporter.cxx @@ -883,6 +883,7 @@ class vtkF3DUSDImporter::vtkInternals if (!asset) { // cannot get USD asset + std::cout << "HEREHRHEHRE no asset" << std::endl; return nullptr; } @@ -890,6 +891,7 @@ class vtkF3DUSDImporter::vtkInternals if (!buffer) { + std::cout << "HEREHRHEHRE no buffer" << std::endl; // buffer invalid return nullptr; } diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 4eb4f28dff..6fe8bb2e03 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -30,7 +31,7 @@ void vtkF3DEXRReader::PrintSelf(ostream& os, vtkIndent indent) //------------------------------------------------------------------------------ void vtkF3DEXRReader::ExecuteInformation() { - // XXX: Needed because of VTK initialize file pattern in the constructor for some reasons + // XXX: Needed because of VTK initialize file pattern in the constructor for some reasons delete[] this->FilePattern; this->FilePattern = nullptr; @@ -38,13 +39,13 @@ void vtkF3DEXRReader::ExecuteInformation() this->ComputeInternalFileName(this->DataExtent[4]); if (this->InternalFileName == nullptr || this->InternalFileName[0] == '\0') { - return; + // If we have no file then maybe we have the file in memory + if (!this->MemoryBuffer) + return; } - try + auto execute = [&](Imf::RgbaInputFile& file) { - Imf::RgbaInputFile file(this->InternalFileName); - Imath::Box2i dw = file.dataWindow(); this->DataExtent[0] = dw.min.x; this->DataExtent[1] = dw.max.x; @@ -56,6 +57,21 @@ void vtkF3DEXRReader::ExecuteInformation() { throw std::runtime_error("only RGB and RGBA channels are supported"); } + }; + + try + { + if (this->MemoryBuffer) + { + MemStream memoryStream("EXRmemoryStream", this->MemoryBuffer, this->MemoryBufferLength); + Imf::RgbaInputFile file = Imf::RgbaInputFile(memoryStream); + execute(file); + } + else + { + Imf::RgbaInputFile file(this->InternalFileName); + execute(file); + } } catch (const std::exception& e) { @@ -65,13 +81,14 @@ void vtkF3DEXRReader::ExecuteInformation() this->SetNumberOfScalarComponents(3); this->SetDataScalarTypeToFloat(); - + std::cout << "made it ExecuteInformation\n"; this->vtkImageReader::ExecuteInformation(); } //------------------------------------------------------------------------------ int vtkF3DEXRReader::CanReadFile(const char* fname) { + std::cout << "can read\n"; // get the magic number by reading in a file vtksys::ifstream ifs(fname, vtksys::ifstream::in); @@ -95,10 +112,12 @@ int vtkF3DEXRReader::CanReadFile(const char* fname) //------------------------------------------------------------------------------ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInformation* outInfo) { + std::cout << "execute with info exr\n"; vtkImageData* data = this->AllocateOutputData(output, outInfo); if (this->UpdateExtentIsEmpty(outInfo, output)) { + std::cout << "ret 1\n"; return; } @@ -106,23 +125,18 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor if (!scalars) { vtkErrorMacro(<< "Could not find expected scalar array"); + std::cout << "ret 2\n"; return; } - + std::cout << "setting pix\n"; scalars->SetName("Pixels"); float* dataPtr = scalars->GetPointer(0); - try + auto execute = [&](Imf::RgbaInputFile& file) { - assert(this->InternalFileName); - Imf::setGlobalThreadCount(std::thread::hardware_concurrency()); - Imf::RgbaInputFile file(this->InternalFileName); - Imf::Array2D pixels(this->GetHeight(), this->GetWidth()); - file.setFrameBuffer(&pixels[0][0], 1, this->GetWidth()); file.readPixels(this->DataExtent[2], this->DataExtent[3]); - for (int y = this->GetHeight() - 1; y >= 0; y--) { for (int x = 0; x < this->GetWidth(); x++) @@ -134,6 +148,25 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor dataPtr += 3; } } + }; + + try + { + assert(this->InternalFileName); + Imf::setGlobalThreadCount(std::thread::hardware_concurrency()); + + if (this->MemoryBuffer) + { + MemStream memoryStream("EXRmemoryStream", this->MemoryBuffer, this->MemoryBufferLength); + Imf::RgbaInputFile file = Imf::RgbaInputFile(memoryStream); + execute(file); + } + else + { + Imf::RgbaInputFile file(this->InternalFileName); + execute(file); + } + std::cout << "also made it\n"; } catch (const std::exception& e) { @@ -142,6 +175,24 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor } } +//------------------------------------------------------------------------------ +/** + * Read from memory instead of file + */ +void vtkF3DEXRReader::SetMemoryBuffer(const void* buff) +{ + this->MemoryBuffer = buff; +} + +//------------------------------------------------------------------------------ +/** + * Specify the in memory image buffer length. + */ +void vtkF3DEXRReader::SetMemoryBufferLength(vtkIdType buflen) +{ + this->MemoryBufferLength = buflen; +} + //------------------------------------------------------------------------------ int vtkF3DEXRReader::GetWidth() const { @@ -153,3 +204,15 @@ int vtkF3DEXRReader::GetHeight() const { return this->DataExtent[3] - this->DataExtent[2] + 1; } + +//------------------------------------------------------------------------------ +bool vtkF3DEXRReader::MemStream::read(char c[], int n) +{ + if (pos + n <= buflen) + { + memcpy(c, buffer + pos, n); + pos += n; + return true; + } + return false; +} \ No newline at end of file diff --git a/vtkext/private/module/vtkF3DEXRReader.h b/vtkext/private/module/vtkF3DEXRReader.h index 5edabf8222..6d58ccaeb7 100644 --- a/vtkext/private/module/vtkF3DEXRReader.h +++ b/vtkext/private/module/vtkF3DEXRReader.h @@ -3,6 +3,8 @@ #include "vtkImageReader.h" +#include + class vtkF3DEXRReader : public vtkImageReader { public: @@ -31,6 +33,16 @@ class vtkF3DEXRReader : public vtkImageReader return "OpenEXR"; } + /** + * Read from memory instead of file + */ + void SetMemoryBuffer(const void* buff) override; + + /** + * Specify the in memory image buffer length. + */ + void SetMemoryBufferLength(vtkIdType buflen) override; + protected: vtkF3DEXRReader(); ~vtkF3DEXRReader() override; @@ -44,6 +56,52 @@ class vtkF3DEXRReader : public vtkImageReader private: vtkF3DEXRReader(const vtkF3DEXRReader&) = delete; void operator=(const vtkF3DEXRReader&) = delete; + + /** + * Class to treat file contents in memory like it were still in a file. + */ + class MemStream : public Imf::IStream + { + public: + MemStream(const char* name, const void* buffer, vtkIdType buflen) + : Imf::IStream(name) + , buffer(buffer) + , buflen(buflen) + , pos(0) + { + } + + bool read(char c[], int n) override; + + /** + * returns the current reading position, in bytes, from the beginning of the file. + * The next read() call will begin reading at the indicated position + */ + uint64_t tellg() override + { + return pos; + } + + /** + * sets the current reading position to pos bytes from the beginning of the "file" + */ + void seekg(uint64_t new_pos) override + { + pos = new_pos; + } + + /** + * clears any error flags (we dont have to worry about this) + */ + void clear() override + { + } + + private: + const void* buffer; + vtkIdType buflen; + uint64_t pos; + }; }; #endif From fbc487d32362186a49edc879a73815c83b033669 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Fri, 31 May 2024 17:42:55 -0400 Subject: [PATCH 02/19] resolve rebase conflicts manually --- plugins/usd/module/vtkF3DUSDImporter.cxx | 2 -- vtkext/private/module/vtkF3DEXRReader.cxx | 7 ------- 2 files changed, 9 deletions(-) diff --git a/plugins/usd/module/vtkF3DUSDImporter.cxx b/plugins/usd/module/vtkF3DUSDImporter.cxx index 9c9dbed402..8c34cafd83 100644 --- a/plugins/usd/module/vtkF3DUSDImporter.cxx +++ b/plugins/usd/module/vtkF3DUSDImporter.cxx @@ -883,7 +883,6 @@ class vtkF3DUSDImporter::vtkInternals if (!asset) { // cannot get USD asset - std::cout << "HEREHRHEHRE no asset" << std::endl; return nullptr; } @@ -891,7 +890,6 @@ class vtkF3DUSDImporter::vtkInternals if (!buffer) { - std::cout << "HEREHRHEHRE no buffer" << std::endl; // buffer invalid return nullptr; } diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 6fe8bb2e03..e51bf46955 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -81,14 +81,12 @@ void vtkF3DEXRReader::ExecuteInformation() this->SetNumberOfScalarComponents(3); this->SetDataScalarTypeToFloat(); - std::cout << "made it ExecuteInformation\n"; this->vtkImageReader::ExecuteInformation(); } //------------------------------------------------------------------------------ int vtkF3DEXRReader::CanReadFile(const char* fname) { - std::cout << "can read\n"; // get the magic number by reading in a file vtksys::ifstream ifs(fname, vtksys::ifstream::in); @@ -112,12 +110,10 @@ int vtkF3DEXRReader::CanReadFile(const char* fname) //------------------------------------------------------------------------------ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInformation* outInfo) { - std::cout << "execute with info exr\n"; vtkImageData* data = this->AllocateOutputData(output, outInfo); if (this->UpdateExtentIsEmpty(outInfo, output)) { - std::cout << "ret 1\n"; return; } @@ -125,10 +121,8 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor if (!scalars) { vtkErrorMacro(<< "Could not find expected scalar array"); - std::cout << "ret 2\n"; return; } - std::cout << "setting pix\n"; scalars->SetName("Pixels"); float* dataPtr = scalars->GetPointer(0); @@ -166,7 +160,6 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor Imf::RgbaInputFile file(this->InternalFileName); execute(file); } - std::cout << "also made it\n"; } catch (const std::exception& e) { From 69f3a6022fd5d0149445f2b9331222791750bd82 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Fri, 31 May 2024 18:50:08 -0400 Subject: [PATCH 03/19] clean up file --- vtkext/private/module/vtkF3DEXRReader.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index e51bf46955..4a916b8eb1 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -31,7 +31,7 @@ void vtkF3DEXRReader::PrintSelf(ostream& os, vtkIndent indent) //------------------------------------------------------------------------------ void vtkF3DEXRReader::ExecuteInformation() { - // XXX: Needed because of VTK initialize file pattern in the constructor for some reasons + // XXX: Needed because of VTK initialize file pattern in the constructor for some reasons delete[] this->FilePattern; this->FilePattern = nullptr; @@ -81,6 +81,7 @@ void vtkF3DEXRReader::ExecuteInformation() this->SetNumberOfScalarComponents(3); this->SetDataScalarTypeToFloat(); + this->vtkImageReader::ExecuteInformation(); } @@ -123,14 +124,17 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor vtkErrorMacro(<< "Could not find expected scalar array"); return; } + scalars->SetName("Pixels"); float* dataPtr = scalars->GetPointer(0); auto execute = [&](Imf::RgbaInputFile& file) { Imf::Array2D pixels(this->GetHeight(), this->GetWidth()); + file.setFrameBuffer(&pixels[0][0], 1, this->GetWidth()); file.readPixels(this->DataExtent[2], this->DataExtent[3]); + for (int y = this->GetHeight() - 1; y >= 0; y--) { for (int x = 0; x < this->GetWidth(); x++) @@ -208,4 +212,4 @@ bool vtkF3DEXRReader::MemStream::read(char c[], int n) return true; } return false; -} \ No newline at end of file +} From 68dcfc4757d5d5decb50a15f1f585f95218ff2c6 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Fri, 31 May 2024 20:54:39 -0400 Subject: [PATCH 04/19] fixed CI issues --- vtkext/private/module/vtkF3DEXRReader.cxx | 6 +++--- vtkext/private/module/vtkF3DEXRReader.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 4a916b8eb1..94b3d0ebb4 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -185,9 +185,9 @@ void vtkF3DEXRReader::SetMemoryBuffer(const void* buff) /** * Specify the in memory image buffer length. */ -void vtkF3DEXRReader::SetMemoryBufferLength(vtkIdType buflen) +void vtkF3DEXRReader::SetMemoryBufferLength(vtkIdType bufferLen) { - this->MemoryBufferLength = buflen; + this->MemoryBufferLength = bufferLen; } //------------------------------------------------------------------------------ @@ -205,7 +205,7 @@ int vtkF3DEXRReader::GetHeight() const //------------------------------------------------------------------------------ bool vtkF3DEXRReader::MemStream::read(char c[], int n) { - if (pos + n <= buflen) + if (pos + n <= bufflen) { memcpy(c, buffer + pos, n); pos += n; diff --git a/vtkext/private/module/vtkF3DEXRReader.h b/vtkext/private/module/vtkF3DEXRReader.h index 6d58ccaeb7..45346736b5 100644 --- a/vtkext/private/module/vtkF3DEXRReader.h +++ b/vtkext/private/module/vtkF3DEXRReader.h @@ -63,10 +63,10 @@ class vtkF3DEXRReader : public vtkImageReader class MemStream : public Imf::IStream { public: - MemStream(const char* name, const void* buffer, vtkIdType buflen) + MemStream(const char* name, const void* buff, vtkIdType bufferLen) : Imf::IStream(name) - , buffer(buffer) - , buflen(buflen) + , buffer(static_cast(buff)) + , bufflen(static_cast(bufferLen)) , pos(0) { } @@ -98,8 +98,8 @@ class vtkF3DEXRReader : public vtkImageReader } private: - const void* buffer; - vtkIdType buflen; + const char* buffer; + size_t bufflen; uint64_t pos; }; }; From ec7f2be731864f9765ff00ca49130e87c772e959 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Sun, 2 Jun 2024 02:00:33 -0400 Subject: [PATCH 05/19] moved class to cpp file and added unit tests --- testing/data/Rec709.exr | 3 + vtkext/private/module/Testing/CMakeLists.txt | 3 +- .../module/Testing/TestF3DEXRMemReader.cxx | 54 ++++++++++++++ vtkext/private/module/vtkF3DEXRReader.cxx | 72 +++++++++++++++---- vtkext/private/module/vtkF3DEXRReader.h | 48 ------------- 5 files changed, 117 insertions(+), 63 deletions(-) create mode 100644 testing/data/Rec709.exr create mode 100644 vtkext/private/module/Testing/TestF3DEXRMemReader.cxx diff --git a/testing/data/Rec709.exr b/testing/data/Rec709.exr new file mode 100644 index 0000000000..ce1412e961 --- /dev/null +++ b/testing/data/Rec709.exr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15028cbf7bf0efa43738890af715ec550d26ae9e32a1020d0f4e7c785d3a370e +size 908168 diff --git a/vtkext/private/module/Testing/CMakeLists.txt b/vtkext/private/module/Testing/CMakeLists.txt index 93f6579b7c..43fd894b82 100644 --- a/vtkext/private/module/Testing/CMakeLists.txt +++ b/vtkext/private/module/Testing/CMakeLists.txt @@ -17,7 +17,8 @@ endif() if(F3D_MODULE_EXR) list(APPEND test_sources TestF3DEXRReader.cxx - TestF3DEXRReaderInvalid.cxx) + TestF3DEXRReaderInvalid.cxx + TestF3DEXRMemReader.cxx) endif() vtk_add_test_cxx(vtkextPrivateTests tests diff --git a/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx new file mode 100644 index 0000000000..b269f66db2 --- /dev/null +++ b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx @@ -0,0 +1,54 @@ +#include +#include + +#include "vtkF3DEXRReader.h" + +#include +#include +#include + +bool readFileToVector(const std::string& filename, std::vector& buffer) +{ + std::ifstream file(filename, std::ios::binary | std::ios::ate); + if (!file) + { + return false; + } + + std::streamsize size = file.tellg(); + file.seekg(0, std::ios::beg); + + buffer.resize(size); + + if (file.read(buffer.data(), size)) + return true; + return false; +} + +int TestF3DEXRMemReader(int argc, char* argv[]) +{ + vtkNew reader; + + std::string actual_filename = std::string(argv[1]) + "data/Rec709.exr"; + std::string filename = "readFromMem.exr"; + reader->SetFileName(filename.c_str()); + std::vector buff; + readFileToVector(actual_filename, buff); + reader->SetMemoryBuffer(buff.data()); + reader->SetMemoryBufferLength(buff.size()); + reader->Update(); + + reader->Print(cout); + + vtkImageData* img = reader->GetOutput(); + + int* dims = img->GetDimensions(); + + if (dims[0] != 610 && dims[1] != 406) + { + std::cerr << "Incorrect EXR image size." << dims[0] << ":" << dims[1] << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 94b3d0ebb4..bc7a0d3cca 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -8,12 +8,68 @@ #include "vtksys/FStream.hxx" #include +#include #include #include #include #include +/** + * Class to treat file contents in memory like it were still in a file. + */ +class MemStream : public Imf::IStream +{ +public: + MemStream(const char* name, const void* buff, vtkIdType bufferLen) + : Imf::IStream(name) + , buffer(static_cast(buff)) + , bufflen(static_cast(bufferLen)) + , pos(0) + { + } + + bool read(char c[], int n) override + { + if (pos + n <= bufflen) + { + memcpy(c, buffer + pos, n); + pos += n; + return true; + } + return false; + } + + /** + * returns the current reading position, in bytes, from the beginning of the file. + * The next read() call will begin reading at the indicated position + */ + uint64_t tellg() override + { + return pos; + } + + /** + * sets the current reading position to pos bytes from the beginning of the "file" + */ + void seekg(uint64_t new_pos) override + { + pos = new_pos; + } + + /** + * clears any error flags (we dont have to worry about this) + */ + void clear() override + { + } + +private: + const char* buffer; + size_t bufflen; + uint64_t pos; +}; + vtkStandardNewMacro(vtkF3DEXRReader); //------------------------------------------------------------------------------ @@ -178,7 +234,7 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor */ void vtkF3DEXRReader::SetMemoryBuffer(const void* buff) { - this->MemoryBuffer = buff; + MemoryBuffer = buff; } //------------------------------------------------------------------------------ @@ -187,7 +243,7 @@ void vtkF3DEXRReader::SetMemoryBuffer(const void* buff) */ void vtkF3DEXRReader::SetMemoryBufferLength(vtkIdType bufferLen) { - this->MemoryBufferLength = bufferLen; + MemoryBufferLength = bufferLen; } //------------------------------------------------------------------------------ @@ -201,15 +257,3 @@ int vtkF3DEXRReader::GetHeight() const { return this->DataExtent[3] - this->DataExtent[2] + 1; } - -//------------------------------------------------------------------------------ -bool vtkF3DEXRReader::MemStream::read(char c[], int n) -{ - if (pos + n <= bufflen) - { - memcpy(c, buffer + pos, n); - pos += n; - return true; - } - return false; -} diff --git a/vtkext/private/module/vtkF3DEXRReader.h b/vtkext/private/module/vtkF3DEXRReader.h index 45346736b5..be87206357 100644 --- a/vtkext/private/module/vtkF3DEXRReader.h +++ b/vtkext/private/module/vtkF3DEXRReader.h @@ -3,8 +3,6 @@ #include "vtkImageReader.h" -#include - class vtkF3DEXRReader : public vtkImageReader { public: @@ -56,52 +54,6 @@ class vtkF3DEXRReader : public vtkImageReader private: vtkF3DEXRReader(const vtkF3DEXRReader&) = delete; void operator=(const vtkF3DEXRReader&) = delete; - - /** - * Class to treat file contents in memory like it were still in a file. - */ - class MemStream : public Imf::IStream - { - public: - MemStream(const char* name, const void* buff, vtkIdType bufferLen) - : Imf::IStream(name) - , buffer(static_cast(buff)) - , bufflen(static_cast(bufferLen)) - , pos(0) - { - } - - bool read(char c[], int n) override; - - /** - * returns the current reading position, in bytes, from the beginning of the file. - * The next read() call will begin reading at the indicated position - */ - uint64_t tellg() override - { - return pos; - } - - /** - * sets the current reading position to pos bytes from the beginning of the "file" - */ - void seekg(uint64_t new_pos) override - { - pos = new_pos; - } - - /** - * clears any error flags (we dont have to worry about this) - */ - void clear() override - { - } - - private: - const char* buffer; - size_t bufflen; - uint64_t pos; - }; }; #endif From e508fb086e0724f077f12e9eee4c70e45296085d Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Sun, 2 Jun 2024 02:03:15 -0400 Subject: [PATCH 06/19] add comment with image file source --- vtkext/private/module/Testing/TestF3DEXRMemReader.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx index b269f66db2..6dd8adee66 100644 --- a/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx +++ b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx @@ -6,7 +6,10 @@ #include #include #include - +/** + * image file taken from + * https://github.com/AcademySoftwareFoundation/openexr/blob/370db2835843ac75f85e1386c05455f26a6ff58c/website/test_images/Chromaticities/Rec709.rst + */ bool readFileToVector(const std::string& filename, std::vector& buffer) { std::ifstream file(filename, std::ios::binary | std::ios::ate); From bd32458b35b7a089c633fabf1ac857c896f7bb0d Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Sun, 2 Jun 2024 08:00:19 -0400 Subject: [PATCH 07/19] remove unused function --- vtkext/private/module/vtkF3DEXRReader.cxx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index bc7a0d3cca..adef84c304 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -57,13 +57,6 @@ class MemStream : public Imf::IStream pos = new_pos; } - /** - * clears any error flags (we dont have to worry about this) - */ - void clear() override - { - } - private: const char* buffer; size_t bufflen; From a851a440e620b81a062563171b268eac93de9c9e Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Mon, 3 Jun 2024 01:39:46 -0400 Subject: [PATCH 08/19] resolve rebase conflicts manually --- testing/baselines/TestEXRReadMemory.png | 3 +++ testing/data/sphere8.usdz | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 testing/baselines/TestEXRReadMemory.png create mode 100644 testing/data/sphere8.usdz diff --git a/testing/baselines/TestEXRReadMemory.png b/testing/baselines/TestEXRReadMemory.png new file mode 100644 index 0000000000..6e30136b34 --- /dev/null +++ b/testing/baselines/TestEXRReadMemory.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:068c4a7428c7eeb961d5502905a642b67c85a796eb830930468b0cca780dafc4 +size 8970 diff --git a/testing/data/sphere8.usdz b/testing/data/sphere8.usdz new file mode 100644 index 0000000000..5add0f8ca3 --- /dev/null +++ b/testing/data/sphere8.usdz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e37ad350e719ad4b8dbf41176c787fee330bd293352d0863855117f51e504c51 +size 807801 From 03a0ae4b37a112d02ccc7ffcff3851895efb0ba4 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Wed, 12 Jun 2024 19:39:41 -0400 Subject: [PATCH 09/19] default initialize value --- vtkext/private/module/vtkF3DEXRReader.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index adef84c304..2b45847cfc 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -60,7 +60,7 @@ class MemStream : public Imf::IStream private: const char* buffer; size_t bufflen; - uint64_t pos; + uint64_t pos{ 0 }; }; vtkStandardNewMacro(vtkF3DEXRReader); From f22a8f1453e768f3e0487c5b8c3e84e920c2049e Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Fri, 14 Jun 2024 18:51:18 -0400 Subject: [PATCH 10/19] add license for testing data --- testing/data/DATA_LICENSES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/data/DATA_LICENSES.md b/testing/data/DATA_LICENSES.md index 8e890574e4..506b2692e9 100644 --- a/testing/data/DATA_LICENSES.md +++ b/testing/data/DATA_LICENSES.md @@ -57,6 +57,7 @@ - world*: VTK Data: BSD-3-Clause - 16bits.*: @bisechen: [CC0](https://creativecommons.org/publicdomain/zero/1.0/) - (ノಠ益ಠ )ノ.vtp: VTK Data: BSD-3-Clause +- Rec709.exr: [Copyright 2006 Industrial Light & Magic](https://github.com/AcademySoftwareFoundation/openexr/blob/370db2835843ac75f85e1386c05455f26a6ff58c/website/test_images/Chromaticities/Rec709.rst): BSD-3-Clause All other datasets are licensed under the BSD-3-Clause F3D license. From 64aa7a1d5d34219984382e31a6b13582c5361cfe Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Fri, 14 Jun 2024 19:05:45 -0400 Subject: [PATCH 11/19] change return for test --- vtkext/private/module/Testing/TestF3DEXRMemReader.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx index 6dd8adee66..a7fe9a5a46 100644 --- a/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx +++ b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx @@ -20,12 +20,8 @@ bool readFileToVector(const std::string& filename, std::vector& buffer) std::streamsize size = file.tellg(); file.seekg(0, std::ios::beg); - buffer.resize(size); - - if (file.read(buffer.data(), size)) - return true; - return false; + return file.read(buffer.data(), size) ? true : false; } int TestF3DEXRMemReader(int argc, char* argv[]) From 944887b2795ed932f9a826a5f4e0c1172ef310b2 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Wed, 19 Jun 2024 21:58:57 -0400 Subject: [PATCH 12/19] update formatting --- vtkext/private/module/vtkF3DEXRReader.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 2b45847cfc..43d4228292 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -90,7 +90,9 @@ void vtkF3DEXRReader::ExecuteInformation() { // If we have no file then maybe we have the file in memory if (!this->MemoryBuffer) + { return; + } } auto execute = [&](Imf::RgbaInputFile& file) From 887536349a92c18246d85907cad631b82d1231f6 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Fri, 21 Jun 2024 23:15:23 -0400 Subject: [PATCH 13/19] update tests --- testing/baselines/TestEXRReadMemory.png | 4 ++-- testing/data/small.usdz | 3 +++ testing/data/sphere8.usdz | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 testing/data/small.usdz delete mode 100644 testing/data/sphere8.usdz diff --git a/testing/baselines/TestEXRReadMemory.png b/testing/baselines/TestEXRReadMemory.png index 6e30136b34..3491aaa776 100644 --- a/testing/baselines/TestEXRReadMemory.png +++ b/testing/baselines/TestEXRReadMemory.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:068c4a7428c7eeb961d5502905a642b67c85a796eb830930468b0cca780dafc4 -size 8970 +oid sha256:704c2a3f892e071a30a6e2c4edaa3c4c107080931cbcde406a9c06927f77a787 +size 145875 diff --git a/testing/data/small.usdz b/testing/data/small.usdz new file mode 100644 index 0000000000..032d3da132 --- /dev/null +++ b/testing/data/small.usdz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:db6cd84120a9e61b18b05edcb6f825994da59a5878229658648e76af546f5514 +size 103799 diff --git a/testing/data/sphere8.usdz b/testing/data/sphere8.usdz deleted file mode 100644 index 5add0f8ca3..0000000000 --- a/testing/data/sphere8.usdz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e37ad350e719ad4b8dbf41176c787fee330bd293352d0863855117f51e504c51 -size 807801 From 33eecbfda63d651b1f41189d9e59e1ba560020ad Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Sat, 22 Jun 2024 20:57:46 -0400 Subject: [PATCH 14/19] update tests --- testing/baselines/TestEXRReadMemory.png | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/baselines/TestEXRReadMemory.png b/testing/baselines/TestEXRReadMemory.png index 3491aaa776..ffe28c6f8a 100644 --- a/testing/baselines/TestEXRReadMemory.png +++ b/testing/baselines/TestEXRReadMemory.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:704c2a3f892e071a30a6e2c4edaa3c4c107080931cbcde406a9c06927f77a787 -size 145875 +oid sha256:4f910864b9340e6cd52290610c62494bbbbcc18ab1dafb923e6c26a5a0e809ff +size 50088 From 07f604f70281a7fd7cdc655cdadb89136b5495c8 Mon Sep 17 00:00:00 2001 From: Nabiel Kandiel Date: Wed, 26 Jun 2024 19:40:59 -0400 Subject: [PATCH 15/19] Cleanup --- testing/data/DATA_LICENSES.md | 1 + vtkext/private/module/vtkF3DEXRReader.cxx | 33 +++++------------------ vtkext/private/module/vtkF3DEXRReader.h | 10 ------- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/testing/data/DATA_LICENSES.md b/testing/data/DATA_LICENSES.md index 506b2692e9..f7a0ec569d 100644 --- a/testing/data/DATA_LICENSES.md +++ b/testing/data/DATA_LICENSES.md @@ -58,6 +58,7 @@ - 16bits.*: @bisechen: [CC0](https://creativecommons.org/publicdomain/zero/1.0/) - (ノಠ益ಠ )ノ.vtp: VTK Data: BSD-3-Clause - Rec709.exr: [Copyright 2006 Industrial Light & Magic](https://github.com/AcademySoftwareFoundation/openexr/blob/370db2835843ac75f85e1386c05455f26a6ff58c/website/test_images/Chromaticities/Rec709.rst): BSD-3-Clause +- small.usdz: Copyright USD contributors: CC-BY 4.0 All other datasets are licensed under the BSD-3-Clause F3D license. diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 43d4228292..20c319fa97 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -25,7 +25,6 @@ class MemStream : public Imf::IStream : Imf::IStream(name) , buffer(static_cast(buff)) , bufflen(static_cast(bufferLen)) - , pos(0) { } @@ -86,13 +85,10 @@ void vtkF3DEXRReader::ExecuteInformation() // Setup filename to read the header this->ComputeInternalFileName(this->DataExtent[4]); - if (this->InternalFileName == nullptr || this->InternalFileName[0] == '\0') + if ((this->InternalFileName == nullptr || this->InternalFileName[0] == '\0') && + !this->MemoryBuffer) { - // If we have no file then maybe we have the file in memory - if (!this->MemoryBuffer) - { - return; - } + return; } auto execute = [&](Imf::RgbaInputFile& file) @@ -201,7 +197,6 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor try { - assert(this->InternalFileName); Imf::setGlobalThreadCount(std::thread::hardware_concurrency()); if (this->MemoryBuffer) @@ -212,6 +207,10 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor } else { + if (!(this->InternalFileName)) + { + throw std::invalid_argument("Not filename in EXR Reader when no Memory Buffer is set."); + } Imf::RgbaInputFile file(this->InternalFileName); execute(file); } @@ -223,24 +222,6 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor } } -//------------------------------------------------------------------------------ -/** - * Read from memory instead of file - */ -void vtkF3DEXRReader::SetMemoryBuffer(const void* buff) -{ - MemoryBuffer = buff; -} - -//------------------------------------------------------------------------------ -/** - * Specify the in memory image buffer length. - */ -void vtkF3DEXRReader::SetMemoryBufferLength(vtkIdType bufferLen) -{ - MemoryBufferLength = bufferLen; -} - //------------------------------------------------------------------------------ int vtkF3DEXRReader::GetWidth() const { diff --git a/vtkext/private/module/vtkF3DEXRReader.h b/vtkext/private/module/vtkF3DEXRReader.h index be87206357..5edabf8222 100644 --- a/vtkext/private/module/vtkF3DEXRReader.h +++ b/vtkext/private/module/vtkF3DEXRReader.h @@ -31,16 +31,6 @@ class vtkF3DEXRReader : public vtkImageReader return "OpenEXR"; } - /** - * Read from memory instead of file - */ - void SetMemoryBuffer(const void* buff) override; - - /** - * Specify the in memory image buffer length. - */ - void SetMemoryBufferLength(vtkIdType buflen) override; - protected: vtkF3DEXRReader(); ~vtkF3DEXRReader() override; From ad3aafd8e55bf9b9f410204e015785a2d8b8f1c1 Mon Sep 17 00:00:00 2001 From: gapry Date: Sat, 23 Nov 2024 23:05:52 +0800 Subject: [PATCH 16/19] add the links for small.usdz dataset license --- testing/data/DATA_LICENSES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/data/DATA_LICENSES.md b/testing/data/DATA_LICENSES.md index f7a0ec569d..d576462111 100644 --- a/testing/data/DATA_LICENSES.md +++ b/testing/data/DATA_LICENSES.md @@ -58,7 +58,7 @@ - 16bits.*: @bisechen: [CC0](https://creativecommons.org/publicdomain/zero/1.0/) - (ノಠ益ಠ )ノ.vtp: VTK Data: BSD-3-Clause - Rec709.exr: [Copyright 2006 Industrial Light & Magic](https://github.com/AcademySoftwareFoundation/openexr/blob/370db2835843ac75f85e1386c05455f26a6ff58c/website/test_images/Chromaticities/Rec709.rst): BSD-3-Clause -- small.usdz: Copyright USD contributors: CC-BY 4.0 +- small.usdz: [Copyright USD contributors](https://github.com/usd-wg/assets/tree/main/full_assets/StandardShaderBall): [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/) All other datasets are licensed under the BSD-3-Clause F3D license. From 979a0525745b1736c2fe960711dc8687608ebf84 Mon Sep 17 00:00:00 2001 From: gapry Date: Tue, 26 Nov 2024 23:11:11 +0800 Subject: [PATCH 17/19] remove the duplicate license claim --- vtkext/private/module/Testing/TestF3DEXRMemReader.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx index a7fe9a5a46..484904de06 100644 --- a/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx +++ b/vtkext/private/module/Testing/TestF3DEXRMemReader.cxx @@ -6,10 +6,7 @@ #include #include #include -/** - * image file taken from - * https://github.com/AcademySoftwareFoundation/openexr/blob/370db2835843ac75f85e1386c05455f26a6ff58c/website/test_images/Chromaticities/Rec709.rst - */ + bool readFileToVector(const std::string& filename, std::vector& buffer) { std::ifstream file(filename, std::ios::binary | std::ios::ate); From 36145e1fad6d4e241d3456ff7a23e5adf835aa90 Mon Sep 17 00:00:00 2001 From: gapry Date: Tue, 26 Nov 2024 23:53:25 +0800 Subject: [PATCH 18/19] remove the unnecessary exception throwing --- vtkext/private/module/vtkF3DEXRReader.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 20c319fa97..4f3e22e2d7 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -207,10 +207,6 @@ void vtkF3DEXRReader::ExecuteDataWithInformation(vtkDataObject* output, vtkInfor } else { - if (!(this->InternalFileName)) - { - throw std::invalid_argument("Not filename in EXR Reader when no Memory Buffer is set."); - } Imf::RgbaInputFile file(this->InternalFileName); execute(file); } From 4d6779a18a461662df6ba37ea8fce1edef4dfcdb Mon Sep 17 00:00:00 2001 From: gapry Date: Sat, 30 Nov 2024 15:29:08 +0800 Subject: [PATCH 19/19] use c++ copy_n to replace the c library memcpy --- vtkext/private/module/vtkF3DEXRReader.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vtkext/private/module/vtkF3DEXRReader.cxx b/vtkext/private/module/vtkF3DEXRReader.cxx index 4f3e22e2d7..2a8e482716 100644 --- a/vtkext/private/module/vtkF3DEXRReader.cxx +++ b/vtkext/private/module/vtkF3DEXRReader.cxx @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -32,7 +32,7 @@ class MemStream : public Imf::IStream { if (pos + n <= bufflen) { - memcpy(c, buffer + pos, n); + std::copy_n(buffer + pos, n, c); pos += n; return true; }