16 #ifndef NANOVDB_IMAGE_H_HAS_BEEN_INCLUDED 17 #define NANOVDB_IMAGE_H_HAS_BEEN_INCLUDED 26 #if defined(NANOVDB_USE_TBB) 27 #include <tbb/parallel_for.h> 28 #include <tbb/blocked_range2d.h> 41 , mScale{1.0f / w, 1.0f / h}
56 : r(uint8_t(_r * 255.0f))
57 , g(uint8_t(_g * 255.0f))
58 , b(uint8_t(_b * 255.0f))
62 void clear(
int log2 = 7);
69 void writePPM(
const std::string& fileName,
const std::string& comment =
"width height 255");
72 template<
typename BufferT = HostBuffer>
80 const Image*
image()
const {
return reinterpret_cast<const Image*
>(mBuffer.data()); }
84 template<
typename U = BufferT>
85 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
const Image*>::type
88 template<
typename U = BufferT>
89 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
Image*>::type
92 template<
typename U = BufferT>
93 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
94 deviceUpload(
void* stream =
nullptr,
bool sync =
true) { mBuffer.deviceUpload(stream, sync); }
96 template<
typename U = BufferT>
97 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
98 deviceDownload(
void* stream =
nullptr,
bool sync =
true) { mBuffer.deviceDownload(stream, sync); }
101 template<
typename BufferT>
103 : mBuffer(sizeof(
ImageData) + width * height * sizeof(
Image::ColorRGB))
106 *
reinterpret_cast<ImageData*
>(mBuffer.data()) = data;
117 const int checkerboard = 1 << log2;
119 auto kernel2D = [&](
int x0,
int y0,
int x1,
int y1) {
120 for (
int h = y0; h != y1; ++h) {
121 const int n = h & checkerboard;
123 for (
int w = x0; w != x1; ++w) {
124 *(p + w) = (n ^ (w & checkerboard)) ?
ColorRGB(1, 1, 1) :
ColorRGB(0, 0, 0);
129 #if defined(NANOVDB_USE_TBB) 131 tbb::parallel_for(range, [&](
const tbb::blocked_range2d<int>& r) {
132 kernel2D(r.rows().begin(), r.cols().begin(), r.rows().end(), r.cols().end());
149 std::ofstream os(fileName, std::ios::out | std::ios::binary);
151 throw std::runtime_error(
"Unable to open file named \"" + fileName +
"\" for output");
152 os <<
"P6\n#" << comment <<
"\n" 153 << this->width() <<
" " << this->height() <<
"\n255\n";
154 os.write((
const char*)&(*
this)(0, 0), this->size() *
sizeof(
ColorRGB));
159 #endif // end of NANOVDB_IMAGE_H_HAS_BEEN_INCLUDED __hostdev__ int width() const
Definition: Image.h:63
void writePPM(const std::string &fileName, const std::string &comment="width height 255")
Definition: Image.h:147
ImageHandle(int width, int height, int log2=7)
Definition: Image.h:102
const Image * image() const
Definition: Image.h:80
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
__hostdev__ float v(int h) const
Definition: Image.h:67
__hostdev__ int size() const
Definition: Image.h:65
ImageData(int w, int h)
Definition: Image.h:37
std::enable_if< BufferTraits< U >::hasDeviceDual, const Image * >::type deviceImage() const
Definition: Image.h:86
std::enable_if< BufferTraits< U >::hasDeviceDual, Image * >::type deviceImage()
Definition: Image.h:90
Definition: NanoVDB.h:184
__hostdev__ ColorRGB & operator()(int w, int h)
Definition: Image.h:140
int mSize
Definition: Image.h:35
float mScale[2]
Definition: Image.h:36
uint8_t r
Definition: Image.h:54
int mHeight
Definition: Image.h:35
int mWidth
Definition: Image.h:35
std::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceUpload(void *stream=nullptr, bool sync=true)
Definition: Image.h:94
#define __hostdev__
Definition: NanoVDB.h:168
__hostdev__ ColorRGB(float _r, float _g, float _b)
Definition: Image.h:55
__hostdev__ float u(int w) const
Definition: Image.h:66
__hostdev__ int height() const
Definition: Image.h:64
Image * image()
Definition: Image.h:82
std::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceDownload(void *stream=nullptr, bool sync=true)
Definition: Image.h:98
void clear(int log2=7)
Definition: Image.h:110