diff --git a/Cassiopee/CPlot/CPlot/Data.h b/Cassiopee/CPlot/CPlot/Data.h index 0516da7ff..c1ed75f9d 100644 --- a/Cassiopee/CPlot/CPlot/Data.h +++ b/Cassiopee/CPlot/CPlot/Data.h @@ -551,6 +551,7 @@ class Data double alpha, double beta); void sharpenImage(E_Int w, E_Int h, char* im1, char* im2, double amount, E_Int radius, E_Int threshold); + void specPostProcess(char* in, E_Int ni, E_Int nj, float* depth, char* out); FILE* fopenw(const char* path, const char* mode); void exportFile(); void finalizeExport(); diff --git a/Cassiopee/CPlot/CPlot/Plugins/imagePost.cpp b/Cassiopee/CPlot/CPlot/Plugins/imagePost.cpp index 6aedc8c30..5a4657446 100644 --- a/Cassiopee/CPlot/CPlot/Plugins/imagePost.cpp +++ b/Cassiopee/CPlot/CPlot/Plugins/imagePost.cpp @@ -247,3 +247,141 @@ void Data::sharpenImage(E_Int w, E_Int h, char* im1, char* im2, double amount, free(im3); } + +//============================================================================ +// specific post-processing applied to interlaced color buffer (3), return out +// do darken color with depth, blur with depth (dof) +//============================================================================ +void Data::specPostProcess(char* in, E_Int ni, E_Int nj, float* depth, char* out) +{ + uint8_t r, g, b; + printf("Specific post process\n"); + float dmin, dmax; + // compute min/max of depth + dmin = 1.e30; dmax = -1.e30; + for (E_Int i = 0; i < ni*nj; i++) + { + dmin = std::min(dmin, depth[i]); + // pix with 4.e7 are no body + if (depth[i] < 1.e7) dmax = std::max(dmax, depth[i]); + } + + printf("dmin=%g dmax=%g\n", dmin, dmax); + E_Float dx = _view.xeye - _view.xcam; + E_Float dy = _view.yeye - _view.ycam; + E_Float dz = _view.zeye - _view.zcam; + printf("dist=%g\n", std::sqrt(dx*dx+dy*dy+dz*dz)); + dmax = 0.3; // hard value for create for all 360 views + + // normalize depth + for (E_Int i = 0; i < ni*nj; i++) + { + depth[i] = (depth[i]-dmin)/(dmax-dmin); + } + + // darken far pixels + E_Float percentage = 0.5; + E_Float ramp1 = 0.35; E_Float ramp2 = 0.6; + E_Float p, q, s; + for (E_Int i = 0; i < ni*nj; i++) + { + if (depth[i] <= ramp1) + { + out[3*i] = in[3*i]; + out[3*i+1] = in[3*i+1]; + out[3*i+2] = in[3*i+2]; + } + else if (depth[i] <= ramp2) + { + p = (percentage-1.)/(ramp2-ramp1); + q = 1.-p*ramp1; + s = p*depth[i]+q; + r = (uint8_t)in[3*i]; + g = (uint8_t)in[3*i+1]; + b = (uint8_t)in[3*i+2]; + r = (uint8_t)(r*s); + g = (uint8_t)(g*s); + b = (uint8_t)(b*s); + out[3*i] = r; + out[3*i+1] = g; + out[3*i+2] = b; + } + else + { + r = (uint8_t)in[3*i]; + g = (uint8_t)in[3*i+1]; + b = (uint8_t)in[3*i+2]; + r = (uint8_t)(r*percentage); + g = (uint8_t)(g*percentage); + b = (uint8_t)(b*percentage); + out[3*i] = r; + out[3*i+1] = g; + out[3*i+2] = b; + } + } + + for (E_Int i = 0; i < ni*nj; i++) + { + in[3*i] = out[3*i]; + in[3*i+1] = out[3*i+1]; + in[3*i+2] = out[3*i+2]; + } + + // DBX - output depth + /* + for (E_Int i = 0; i < ni*nj; i++) + { + r = (uint8_t)(depth[i]*255.); + out[3*i] = r; + out[3*i+1] = r; + out[3*i+2] = r; + }*/ + + // dof + E_Float blurSigma = 0.6; + E_Float sigma, sigma2, c; + E_Int ind; + E_Int n = 5; // max coc + + // blur + E_Float rc, gc, bc; + for (E_Int j = n; j < nj-n; j++) + for (E_Int i = n; i < ni-n; i++) + { + ind = i+j*ni; + if (depth[ind] <= ramp1) sigma = 0.; + else if (depth[ind] <= ramp2) + { + p = (blurSigma)/(ramp2-ramp1); + q = -p*ramp1; + sigma = p*depth[ind]+q; + sigma = 0.; + } + else sigma = blurSigma; + + sigma2 = sigma*sigma; + + rc = 0.; gc = 0.; bc = 0.; + for (E_Int ki = -n; ki <= n; ki++) + for (E_Int kj = -n; kj <= n; kj++) + { + if (sigma2 < 1.e-12) + { + if (ki == 0 && kj == 0) c = 1.; + else c = 0.; + } + else c = exp( -(ki*ki+kj*kj)/(2.*sigma2) ) / (sigma2*2.*M_PI); + r = (uint8_t)in[3*(ind+ki+kj*ni)]; + g = (uint8_t)in[3*(ind+ki+kj*ni)+1]; + b = (uint8_t)in[3*(ind+ki+kj*ni)+2]; + rc += (r*c); + gc += (g*c); + bc += (b*c); + } + + out[3*ind] = (uint8_t)rc; + out[3*ind+1] = (uint8_t)gc; + out[3*ind+2] = (uint8_t)bc; + } + +} diff --git a/Cassiopee/CPlot/CPlot/Plugins/screenDump.cpp b/Cassiopee/CPlot/CPlot/Plugins/screenDump.cpp index 68add1081..e2035a52b 100644 --- a/Cassiopee/CPlot/CPlot/Plugins/screenDump.cpp +++ b/Cassiopee/CPlot/CPlot/Plugins/screenDump.cpp @@ -26,8 +26,6 @@ void accumulateSlit(E_Int ni, E_Int nj, char* imf, char* imt, char* imb, E_Int i, E_Int nil, E_Int njl, char* imOut); -void specPostProcess(char* in, E_Int ni, E_Int nj, float* depth, char* out); - //============================================================================= // Screen dump plugins //============================================================================= @@ -335,17 +333,18 @@ char* Data::export2Image(E_Int exportWidth, E_Int exportHeight) free(localBuf); free(localDepth); } + MPI_Barrier(MPI_COMM_WORLD); // seems needed + // software postprocessing on final buffer (just before screen dump) - /* if (rank == 0) { - char* bfl = new char [_view.w * _view.h]; + char* bfl = new char [3*_view.w*_view.h]; for (E_Int i = 0; i < 3*_view.w*_view.h; i++) bfl[i] = buffer[i]; specPostProcess(bfl, _view.w, _view.h, depth, buffer); delete [] bfl; - }*/ + } + free(depth); - MPI_Barrier(MPI_COMM_WORLD); // seems needed #else printf("Error: CPlot: mesa offscreen or MPI unavailable.\n"); diff --git a/Cassiopee/CPlot/CPlot/blur.cpp b/Cassiopee/CPlot/CPlot/blur.cpp index b4a831ba3..de565e700 100644 --- a/Cassiopee/CPlot/CPlot/blur.cpp +++ b/Cassiopee/CPlot/CPlot/blur.cpp @@ -22,10 +22,12 @@ #define M_PI 3.1415926535897932384626433832795 +//======================================================================= // Create 1D half gaussian kernel coefficients // IN: sigma: in pixels // IN: n: half size of kernel // OUT: c: half kernel coefficients +//======================================================================= void createGaussFilter(E_Float sigma, E_Int n, E_Float* c) { E_Float sigma2 = (sigma*sigma); @@ -49,12 +51,15 @@ void createGaussFilter(E_Float sigma, E_Int n, E_Float* c) */ } +//======================================================================= // Apply gaussian blur to in (single scalar) // IN: in: color array // IN: ni,nj: image size // IN: c: kernel coef // IN: n: kernel half size // OUT: out: color array (already allocated) +// Apply 1D filter in both directions +//======================================================================= void gaussianBlur2(E_Float* in, E_Int ni, E_Int nj, E_Float* c, E_Int n, E_Float* out) { E_Int ind; @@ -84,8 +89,6 @@ void gaussianBlur2(E_Float* in, E_Int ni, E_Int nj, E_Float* c, E_Int n, E_Float for (E_Int i = 0; i < ni; i++) { ind = i+j*ni; - in[ind] = out[ind]*c[0]; - for (E_Int k = 1; k <= n; k++) { out[ind] += in[ind-k*ni]*c[k]; @@ -94,71 +97,9 @@ void gaussianBlur2(E_Float* in, E_Int ni, E_Int nj, E_Float* c, E_Int n, E_Float } } -// specific post-processing applied to interlaced color buffer (3), return out -void specPostProcess(char* in, E_Int ni, E_Int nj, float* depth, char* out) -{ - float dmin, dmax; - // compute min/max of depth - dmin = 1.e30; dmax = -1.e30; - for (E_Int i = 0; i < ni*nj; i++) - { - dmin = std::min(dmin, depth[i]); - dmax = std::max(dmax, depth[i]); - } - // normalize depth - for (E_Int i = 0; i < ni*nj; i++) - { - depth[i] = (depth[i]-dmin)/(dmax-dmin); - } - - // assombrit les pixels lointains - double percentage = 0.8; - for (E_Int i = 0; i < ni*nj; i++) - { - if (depth[i] > 0.5) - { - out[3*i] = in[3*i]*percentage; - out[3*i+1] = in[3*i+1]*percentage; - out[3*i+2] = in[3*i+2]*percentage; - } - } - - // dof - /* - // blur en i - for (E_Int j = 0; j < nj; j++) - for (E_Int i = n; i < ni-n; i++) - { - ind = i+j*ni; - out[3*ind] = in[3*ind]*c[0]; - out[3*ind+1] = in[3*ind+1]*c[0]; - out[3*ind+2] = in[3*ind+2]*c[0]; - - for (E_Int k = 1; k <= n; k++) - { - out[ind] += in[i-k+j*ni]*c[k]; // right - out[ind] += in[i+k+j*ni]*c[k]; // left - } - } - - // blur en j - for (E_Int j = n; j < nj-n; j++) - for (E_Int i = 0; i < ni; i++) - { - in[i+j*ni] = out[i+j*ni]*c[0]; - - for (E_Int k = 1; k <= n; k++) - { - out[i+j*ni] += in[i+(j-k)*ni]*c[k]; - out[i+j*ni] += in[i+(j+k)*ni]*c[k]; - } - } - */ - // antialiasing - -} - -// blur array +//======================================================================= +// blur array, python function +//======================================================================= PyObject* K_CPLOT::blur(PyObject* self, PyObject* args) { // Get the 4 arrays of cube images (left, right, bottom, top, back, front) @@ -217,4 +158,4 @@ PyObject* K_CPLOT::blur(PyObject* self, PyObject* args) RELEASESHAREDS(array, im); return Py_None; -} \ No newline at end of file +} diff --git a/Cassiopee/KCore/Dist.py b/Cassiopee/KCore/Dist.py index a5d7f6a99..3adba0e95 100644 --- a/Cassiopee/KCore/Dist.py +++ b/Cassiopee/KCore/Dist.py @@ -1,7 +1,7 @@ # Functions used in *Cassiopee* modules setup.py import os, sys, distutils.sysconfig, platform, glob, subprocess -# Toggle to True for compiling for debug (valgrind, inspector) +# Toggle to True for compiling for debug (valgrind, inspector, sanitizer) DEBUG = False # Toggle to True for compiling Cassiopee in i8