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>
62 void clear(
int log2 = 7);
72template<
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
96 template<
typename U = BufferT>
97 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
101template<
typename BufferT>
106 *
reinterpret_cast<ImageData*
>(mBuffer.data()) = data;
107 this->
image()->clear(log2);
117 const int checkerboard = 1 << log2;
120 for (
int h =
y0;
h !=
y1; ++
h) {
121 const int n =
h & checkerboard;
123 for (
int w =
x0; w !=
x1; ++w) {
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");
153 << this->
width() <<
" " << this->
height() <<
"\n255\n";
154 os.write((
const char*)&(*
this)(0, 0), this->
size() *
sizeof(
ColorRGB));
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
#define __hostdev__
Definition NanoVDB.h:192
Definition DenseGrid.h:402
std::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceUpload(void *stream=nullptr, bool sync=true)
Definition Image.h:94
std::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceDownload(void *stream=nullptr, bool sync=true)
Definition Image.h:98
Image * image()
Definition Image.h:82
std::enable_if< BufferTraits< U >::hasDeviceDual, constImage * >::type deviceImage() const
Definition Image.h:86
const Image * image() const
Definition Image.h:80
std::enable_if< BufferTraits< U >::hasDeviceDual, Image * >::type deviceImage()
Definition Image.h:90
ImageHandle(int width, int height, int log2=7)
Definition Image.h:102
__hostdev__ float u(int w) const
Definition Image.h:66
__hostdev__ int width() const
Definition Image.h:63
__hostdev__ int size() const
Definition Image.h:65
__hostdev__ int height() const
Definition Image.h:64
__hostdev__ ColorRGB & operator()(int w, int h)
Definition Image.h:140
__hostdev__ float v(int h) const
Definition Image.h:67
void writePPM(const std::string &fileName, const std::string &comment="width height 255")
Definition Image.h:147
void clear(int log2=7)
Definition Image.h:110
ImageData(int w, int h)
Definition Image.h:37
int mHeight
Definition Image.h:35
int mSize
Definition Image.h:35
int mWidth
Definition Image.h:35
float mScale[2]
Definition Image.h:36
uint8_t g
Definition Image.h:54
uint8_t b
Definition Image.h:54
uint8_t r
Definition Image.h:54
__hostdev__ ColorRGB(float _r, float _g, float _b)
Definition Image.h:55