33 this->m_inputProgram =
nullptr;
35 this->m__switch = 0.5f;
36 this->m_distance = 0.0f;
41 if (this->m_distance < 0.0f) {
42 this->m_scope = -this->m_distance + this->m_inset;
45 if (this->m_inset * 2 > this->m_distance) {
46 this->m_scope =
MAX2(this->m_inset * 2 - this->m_distance, this->m_distance);
49 this->m_scope = this->m_distance;
52 if (this->m_scope < 3) {
66 const float sw = this->m__switch;
67 const float distance = this->m_distance;
69 const float rd = this->m_scope * this->m_scope;
70 const float inset = this->m_inset;
71 float mindist = rd * 2;
76 const int minx =
MAX2(
x - this->m_scope, input_rect.
xmin);
77 const int miny =
MAX2(
y - this->m_scope, input_rect.
ymin);
78 const int maxx =
MIN2(
x + this->m_scope, input_rect.
xmax);
79 const int maxy =
MIN2(
y + this->m_scope, input_rect.
ymax);
80 const int bufferWidth = inputBuffer->
getWidth();
83 inputBuffer->
read(inputValue,
x,
y);
84 if (inputValue[0] > sw) {
85 for (
int yi = miny; yi < maxy; yi++) {
86 const float dy = yi -
y;
87 offset = ((yi - input_rect.
ymin) * bufferWidth + (minx - input_rect.
xmin));
88 for (
int xi = minx; xi < maxx; xi++) {
90 const float dx = xi -
x;
91 const float dis = dx * dx + dy * dy;
92 mindist =
MIN2(mindist, dis);
97 pixelvalue = -
sqrtf(mindist);
100 for (
int yi = miny; yi < maxy; yi++) {
101 const float dy = yi -
y;
102 offset = ((yi - input_rect.
ymin) * bufferWidth + (minx - input_rect.
xmin));
103 for (
int xi = minx; xi < maxx; xi++) {
104 if (
buffer[offset] > sw) {
105 const float dx = xi -
x;
106 const float dis = dx * dx + dy * dy;
107 mindist =
MIN2(mindist, dis);
112 pixelvalue =
sqrtf(mindist);
116 const float delta =
distance - pixelvalue;
118 if (delta >= inset) {
122 output[0] = delta / inset;
130 const float delta = -
distance + pixelvalue;
132 if (delta < -inset) {
136 output[0] = (-delta) / inset;
147 this->m_inputProgram =
nullptr;
155 newInput.
xmax = input->
xmax + this->m_scope;
156 newInput.
xmin = input->
xmin - this->m_scope;
157 newInput.
ymax = input->
ymax + this->m_scope;
158 newInput.
ymin = input->
ymin - this->m_scope;
200 const int bufferWidth = inputBuffer->
getWidth();
205 for (
int yi = miny; yi < maxy; yi++) {
206 const float dy = yi -
y;
207 offset = ((yi - input_rect.
ymin) * bufferWidth + (minx - input_rect.
xmin));
208 for (
int xi = minx; xi < maxx; xi++) {
209 const float dx = xi -
x;
210 const float dis = dx * dx + dy * dy;
211 if (dis <= mindist) {
241 cl_mem clOutputBuffer,
243 std::list<cl_mem> *clMemToCleanUp,
244 std::list<cl_kernel> * )
252 dilateKernel, 0, 2, clMemToCleanUp, inputMemoryBuffers, this->
m_inputProgram);
255 clSetKernelArg(dilateKernel, 4,
sizeof(cl_int), &scope);
256 clSetKernelArg(dilateKernel, 5,
sizeof(cl_int), &distanceSquared);
279 const int bufferWidth = inputBuffer->
getWidth();
284 for (
int yi = miny; yi < maxy; yi++) {
285 const float dy = yi -
y;
286 offset = ((yi - input_rect.
ymin) * bufferWidth + (minx - input_rect.
xmin));
287 for (
int xi = minx; xi < maxx; xi++) {
288 const float dx = xi -
x;
289 const float dis = dx * dx + dy * dy;
290 if (dis <= mindist) {
301 cl_mem clOutputBuffer,
303 std::list<cl_mem> *clMemToCleanUp,
304 std::list<cl_kernel> * )
312 erodeKernel, 0, 2, clMemToCleanUp, inputMemoryBuffers, this->
m_inputProgram);
315 clSetKernelArg(erodeKernel, 4,
sizeof(cl_int), &scope);
316 clSetKernelArg(erodeKernel, 5,
sizeof(cl_int), &distanceSquared);
348 result->width = xmax - xmin;
350 "dilate erode cache");
363 int window = half_window * 2 + 1;
365 int xmin =
MAX2(0, rect->
xmin - half_window);
366 int ymin =
MAX2(0, rect->
ymin - half_window);
370 int bwidth = rect->
xmax - rect->
xmin;
371 int bheight = rect->
ymax - rect->
ymin;
377 float *rectf =
result->buffer;
382 float *temp = (
float *)
MEM_mallocN(
sizeof(
float) * (2 * window - 1),
"dilate erode temp");
383 float *buf = (
float *)
MEM_mallocN(
sizeof(
float) * (
MAX2(bwidth, bheight) + 5 * half_window),
388 for (
y = ymin;
y < ymax;
y++) {
389 for (
x = 0;
x < bwidth + 5 * half_window;
x++) {
392 for (
x = xmin;
x < xmax;
x++) {
396 for (i = 0; i < (bwidth + 3 * half_window) / window; i++) {
397 int start = (i + 1) * window - 1;
399 temp[window - 1] = buf[start];
400 for (
x = 1;
x < window;
x++) {
401 temp[window - 1 -
x] =
MAX2(temp[window -
x], buf[start -
x]);
402 temp[window - 1 +
x] =
MAX2(temp[window +
x - 2], buf[start +
x]);
405 start = half_window + (i - 1) * window + 1;
406 for (
x = -
MIN2(0, start);
x < window -
MAX2(0, start + window - bwidth);
x++) {
407 rectf[bwidth * (
y - ymin) + (start +
x)] =
MAX2(temp[
x], temp[
x + window - 1]);
413 for (
x = 0;
x < bwidth;
x++) {
414 for (
y = 0;
y < bheight + 5 * half_window;
y++) {
417 for (
y = ymin;
y < ymax;
y++) {
418 buf[
y - rect->
ymin + window - 1] = rectf[(
y - ymin) * bwidth +
x];
421 for (i = 0; i < (bheight + 3 * half_window) / window; i++) {
422 int start = (i + 1) * window - 1;
424 temp[window - 1] = buf[start];
425 for (
y = 1;
y < window;
y++) {
426 temp[window - 1 -
y] =
MAX2(temp[window -
y], buf[start -
y]);
427 temp[window - 1 +
y] =
MAX2(temp[window +
y - 2], buf[start +
y]);
430 start = half_window + (i - 1) * window + 1;
431 for (
y = -
MIN2(0, start);
y < window -
MAX2(0, start + window - bheight);
y++) {
432 rectf[bwidth * (
y + start + (rect->
ymin - ymin)) +
x] =
MAX2(temp[
y],
433 temp[
y + window - 1]);
493 int window = half_window * 2 + 1;
495 int xmin =
MAX2(0, rect->
xmin - half_window);
496 int ymin =
MAX2(0, rect->
ymin - half_window);
500 int bwidth = rect->
xmax - rect->
xmin;
501 int bheight = rect->
ymax - rect->
ymin;
507 float *rectf =
result->buffer;
512 float *temp = (
float *)
MEM_mallocN(
sizeof(
float) * (2 * window - 1),
"dilate erode temp");
513 float *buf = (
float *)
MEM_mallocN(
sizeof(
float) * (
MAX2(bwidth, bheight) + 5 * half_window),
518 for (
y = ymin;
y < ymax;
y++) {
519 for (
x = 0;
x < bwidth + 5 * half_window;
x++) {
522 for (
x = xmin;
x < xmax;
x++) {
526 for (i = 0; i < (bwidth + 3 * half_window) / window; i++) {
527 int start = (i + 1) * window - 1;
529 temp[window - 1] = buf[start];
530 for (
x = 1;
x < window;
x++) {
531 temp[window - 1 -
x] =
MIN2(temp[window -
x], buf[start -
x]);
532 temp[window - 1 +
x] =
MIN2(temp[window +
x - 2], buf[start +
x]);
535 start = half_window + (i - 1) * window + 1;
536 for (
x = -
MIN2(0, start);
x < window -
MAX2(0, start + window - bwidth);
x++) {
537 rectf[bwidth * (
y - ymin) + (start +
x)] =
MIN2(temp[
x], temp[
x + window - 1]);
543 for (
x = 0;
x < bwidth;
x++) {
544 for (
y = 0;
y < bheight + 5 * half_window;
y++) {
547 for (
y = ymin;
y < ymax;
y++) {
548 buf[
y - rect->
ymin + window - 1] = rectf[(
y - ymin) * bwidth +
x];
551 for (i = 0; i < (bheight + 3 * half_window) / window; i++) {
552 int start = (i + 1) * window - 1;
554 temp[window - 1] = buf[start];
555 for (
y = 1;
y < window;
y++) {
556 temp[window - 1 -
y] =
MIN2(temp[window -
y], buf[start -
y]);
557 temp[window - 1 +
y] =
MIN2(temp[window +
y - 2], buf[start +
y]);
560 start = half_window + (i - 1) * window + 1;
561 for (
y = -
MIN2(0, start);
y < window -
MAX2(0, start + window - bheight);
y++) {
562 rectf[bwidth * (
y + start + (rect->
ymin - ymin)) +
x] =
MIN2(temp[
y],
563 temp[
y + window - 1]);
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble ny
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Read Guarded memory(de)allocation.
void * initializeTileData(rcti *rect) override
void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, std::list< cl_mem > *clMemToCleanUp, std::list< cl_kernel > *clKernelsToCleanUp) override
custom handle to add new tasks to the OpenCL command queue in order to execute a chunk on an GPUDevic...
DilateDistanceOperation()
void initExecution() override
SocketReader * m_inputProgram
void deinitExecution() override
void executePixel(float output[4], int x, int y, void *data) override
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void initExecution() override
DilateErodeThresholdOperation()
void * initializeTileData(rcti *rect) override
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void executePixel(float output[4], int x, int y, void *data) override
void deinitExecution() override
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void * initializeTileData(rcti *rect) override
void deinitializeTileData(rcti *rect, void *data) override
void initExecution() override
SocketReader * m_inputProgram
void deinitExecution() override
void executePixel(float output[4], int x, int y, void *data) override
void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, std::list< cl_mem > *clMemToCleanUp, std::list< cl_kernel > *clKernelsToCleanUp) override
custom handle to add new tasks to the OpenCL command queue in order to execute a chunk on an GPUDevic...
void executePixel(float output[4], int x, int y, void *data) override
void * initializeTileData(rcti *rect) override
a MemoryBuffer contains access to the data of a chunk
void read(float *result, int x, int y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip)
const rcti & get_rect() const
get the rect of this MemoryBuffer
const int getHeight() const
get the height of this MemoryBuffer
const int getWidth() const
get the width of this MemoryBuffer
float * getBuffer()
get the data of this MemoryBuffer
virtual void * initializeTileData(rcti *)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void addOutputSocket(DataType datatype)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
device representing an GPU OpenCL device. an instance of this class represents a single cl_device
void COM_clAttachMemoryBufferOffsetToKernelParameter(cl_kernel kernel, int offsetIndex, MemoryBuffer *memoryBuffers)
cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex, std::list< cl_mem > *cleanup, MemoryBuffer **inputMemoryBuffers, SocketReader *reader)
void COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer)
void COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, cl_mem clOutputMemoryBuffer)
void COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex, NodeOperation *operation)
cl_kernel COM_clCreateKernel(const char *kernelname, std::list< cl_kernel > *clKernelsToCleanUp)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
static tile_info * create_cache(int xmin, int xmax, int ymin, int ymax)
ccl_device_inline float distance(const float2 &a, const float2 &b)