MCPcopy Create free account
hub / github.com/RenderKit/oidn / dumpImpl

Method dumpImpl

core/tensor.cpp:94–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92
93 template<typename T, TensorLayout accessorLayout>
94 void Tensor::dumpImpl(const std::string& filenamePrefix)
95 {
96 if (buffer && buffer->getStorage() == Storage::Device)
97 throw std::runtime_error("tensor dump not implemented for device storage");
98
99 TensorAccessor3D<T, accessorLayout> acc = *this;
100
101 for (int c = 0; c < acc.C; ++c)
102 {
103 // Open the file
104 const std::string filename = filenamePrefix + toString(c) + ".pfm";
105 std::ofstream file(filename, std::ios::binary);
106 if (file.fail())
107 throw std::runtime_error("cannot open image file: " + std::string(filename));
108
109 // Write the header
110 file << "Pf" << std::endl;
111 file << acc.W << " " << acc.H << std::endl;
112 file << "-1.0" << std::endl;
113
114 // Write the pixels
115 for (int h = acc.H-1; h >= 0; --h)
116 {
117 for (int w = 0; w < acc.W; ++w)
118 {
119 const float x = acc(c, h, w);
120 file.write((char*)&x, sizeof(float));
121 }
122 }
123 }
124 }
125#endif
126
127 // -----------------------------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 4

toStringFunction · 0.85
failMethod · 0.80
getStorageMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected