From 0f61524acd7fdc03be368e04686149fcec6ec907 Mon Sep 17 00:00:00 2001 From: YingQ Date: Tue, 17 Oct 2023 16:47:00 +0800 Subject: [PATCH 01/14] prtest --- projects/ImgCV/ImageProcessing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ImgCV/ImageProcessing.cpp b/projects/ImgCV/ImageProcessing.cpp index 55c96c7357..94c682c2f3 100644 --- a/projects/ImgCV/ImageProcessing.cpp +++ b/projects/ImgCV/ImageProcessing.cpp @@ -2149,7 +2149,7 @@ struct ImageLevels: INode { std::vector histogramgreen(256, 0); std::vector histogramblue(256, 0); for (int i = 0; i < w * h; i++) { - histogramred[zeno::clamp(int(image->verts[i][0] * 255.99), 0, 255)]++; + histogramred[zeno::clamp(int(image->verts[i][0] * 255.99), 0, 255)]++;//int 没问题吗 histogramgreen[zeno::clamp(int(image->verts[i][1] * 255.99), 0, 255)]++; histogramblue[zeno::clamp(int(image->verts[i][2] * 255.99), 0, 255)]++; } From 26710d8bff0cab9d277f558525fdca3ba1163496 Mon Sep 17 00:00:00 2001 From: YingQ Date: Thu, 19 Oct 2023 18:33:09 +0800 Subject: [PATCH 02/14] review --- projects/ImgCV/ImageComposite.cpp | 601 +---------------------------- projects/ImgCV/ImageProcessing.cu | 0 projects/ImgCV/MachineLearning.cpp | 3 - 3 files changed, 7 insertions(+), 597 deletions(-) delete mode 100644 projects/ImgCV/ImageProcessing.cu delete mode 100644 projects/ImgCV/MachineLearning.cpp diff --git a/projects/ImgCV/ImageComposite.cpp b/projects/ImgCV/ImageComposite.cpp index 13df6ed641..d8cd2884f9 100644 --- a/projects/ImgCV/ImageComposite.cpp +++ b/projects/ImgCV/ImageComposite.cpp @@ -11,567 +11,10 @@ #include - namespace zeno { namespace { -static void RGBtoHSV(float r, float g, float b, float &h, float &s, float &v) { - float rd = r; - float gd = g; - float bd = b; - float cmax = fmax(rd, fmax(gd, bd)); - float cmin = fmin(rd, fmin(gd, bd)); - float delta = cmax - cmin; - - if (delta != 0) { - if (cmax == rd) { - h = fmod((gd - bd) / delta, 6.0); - } else if (cmax == gd) { - h = (bd - rd) / delta + 2.0; - } else if (cmax == bd) { - h = (rd - gd) / delta + 4.0; - } - h *= 60.0; - if (h < 0) { - h += 360.0; - } - } - s = (cmax != 0) ? delta / cmax : 0.0; - v = cmax; -} - -static void HSVtoRGB(float h, float s, float v, float &r, float &g, float &b) -{ - int i; - float f, p, q, t; - if( s == 0 ) { - // achromatic (grey) - r = g = b = v; - return; - } - h /= 60; // sector 0 to 5 - i = floor( h ); - f = h - i; // factorial part of h - p = v * ( 1 - s ); - q = v * ( 1 - s * f ); - t = v * ( 1 - s * ( 1 - f ) ); - switch( i ) { - case 0: - r = v; - g = t; - b = p; - break; - case 1: - r = q; - g = v; - b = p; - break; - case 2: - r = p; - g = v; - b = t; - break; - case 3: - r = p; - g = q; - b = v; - break; - case 4: - r = t; - g = p; - b = v; - break; - default: // case 5: - r = v; - g = p; - b = q; - break; - } -} -static void sobel(std::shared_ptr & grayImage, int width, int height, std::vector& dx, std::vector& dy) -{ - dx.resize(width * height); - dy.resize(width * height); - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - float gx = -grayImage->verts[(y - 1) * width + x - 1][0] + grayImage->verts[(y - 1) * width + x + 1][0] - - 2.0f * grayImage->verts[y * width + x - 1][0] + 2.0f * grayImage->verts[y * width + x + 1][0] - - grayImage->verts[(y + 1) * width + x - 1][0] + grayImage->verts[(y + 1) * width + x + 1][0]; - float gy = grayImage->verts[(y - 1) * width + x - 1][0] + 2.0f * grayImage->verts[(y - 1) * width + x][0] + - grayImage->verts[(y - 1) * width + x + 1][0] - - grayImage->verts[(y + 1) * width + x - 1][0] - 2.0f * grayImage->verts[(y + 1) * width + x][0] - - grayImage->verts[(y + 1) * width + x + 1][0]; - - dx[y * width + x] = gx; - dy[y * width + x] = gy; - } - } -} -// 计算法向量 -static void normalMap(std::shared_ptr& grayImage, int width, int height, std::vector& normal) -{ - std::vector dx, dy; - sobel(grayImage, width, height, dx, dy); - normal.resize(width * height * 3); - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - int i = y * width + x; - float gx = dx[i]; - float gy = dy[i]; - - float normalX = -gx; - float normalY = -gy; - float normalZ = 1.0f; - - float length = sqrt(normalX * normalX + normalY * normalY + normalZ * normalZ); - normalX /= length; - normalY /= length; - normalZ /= length; - - normal[i * 3 + 0] = normalX; - normal[i * 3 + 1] = normalY; - normal[i * 3 + 2] = normalZ; - } - } -} - -struct Composite: INode { - virtual void apply() override { - auto compmode = get_input2("Compmode"); - auto maskmode1 = get_input2("Mask1mode"); - auto maskmode2 = get_input2("Mask2mode"); - int w1 = 1024 ; - int h1 = 1024 ; - auto image1 = std::make_shared(); - image1->verts.resize(w1 * h1); - image1->userData().set2("isImage", 1); - image1->userData().set2("w", w1); - image1->userData().set2("h", h1); - auto image2 = std::make_shared(); - image2->verts.resize(w1 * h1); - image2->userData().set2("isImage", 1); - image2->userData().set2("w", w1); - image2->userData().set2("h", h1); - auto A1 = std::make_shared(); - A1->verts.resize(w1 * h1); - A1->userData().set2("isImage", 1); - A1->userData().set2("w", w1); - A1->userData().set2("h", h1); - A1->verts.add_attr("alpha"); - for(int i = 0;i < w1 * h1;i++){ - A1->verts.attr("alpha")[i] = 0.0; - } - std::vector &alpha1 = A1->verts.attr("alpha"); - auto A2 = std::make_shared(); - A2->verts.resize(w1 * h1); - A2->userData().set2("isImage", 1); - A2->userData().set2("w", w1); - A2->userData().set2("h", h1); - A2->verts.add_attr("alpha"); - for(int i = 0;i < w1 * h1;i++){ - A2->verts.attr("alpha")[i] = 0.0; - } - std::vector &alpha2 = A2->verts.attr("alpha"); - - if(has_input("Background")){ - image2 = get_input2("Background"); - auto &ud2 = image2->userData(); - w1 = ud2.get2("w"); - h1 = ud2.get2("h"); - if(image2->verts.has_attr("alpha")){ - alpha2 = image2->verts.attr("alpha"); - } - else{ - image2->verts.add_attr("alpha"); - for(int i = 0;i < w1 * h1;i++){ - image2->verts.attr("alpha")[i] = 1.0; - } - alpha2 = image2->verts.attr("alpha"); - } - if(!has_input("Foreground")){ - image1->verts.resize(image2->size()); - image1->userData().set2("w", w1); - image1->userData().set2("h", h1); - image1->verts.add_attr("alpha"); - for(int i = 0;i < w1 * h1;i++){ - image1->verts.attr("alpha")[i] = 0.0; - } - alpha1 = image1->verts.attr("alpha"); - } - } - if(has_input("Foreground")){ - image1 = get_input2("Foreground"); - auto &ud1 = image1->userData(); - w1 = ud1.get2("w"); - h1 = ud1.get2("h"); - if(image1->verts.has_attr("alpha")){ - alpha1 = image1->verts.attr("alpha"); - } - else{ - image1->verts.add_attr("alpha"); - for(int i = 0;i < w1 * h1;i++){ - image1->verts.attr("alpha")[i] = 1.0; - } - alpha1 = image1->verts.attr("alpha"); - } - if(!has_input("Background")){ - image2->verts.resize(image1->size()); - image2->userData().set2("w", w1); - image2->userData().set2("h", h1); - image2->verts.add_attr("alpha"); - for(int i = 0;i < w1 * h1;i++){ - image2->verts.attr("alpha")[i] = 0.0; - } - alpha2 = image2->verts.attr("alpha"); - } - if(has_input("Background")){ - auto &ud2 = image2->userData(); - int w2 = ud2.get2("w"); - int h2 = ud2.get2("h"); - if(image1->size() != image2->size() || w1 != w2 || h1 != h2){ - image2->verts.resize(image1->size()); - image2->userData().set2("w", w1); - image2->userData().set2("h", h1); -//todo: image1和image2大小不同的情况 -// for (int i = 0; i < h1; i++) { -// for (int j = 0; j < w1; j++) { -// -// } -// } - } - } - } - if(has_input("Mask1")) { - auto Mask1 = get_input2("Mask1"); - Mask1->verts.resize(w1 * h1); - Mask1->userData().set2("w", w1); - Mask1->userData().set2("h", h1); - if(maskmode1 == "R"){ - Mask1->verts.add_attr("alpha"); - for(int i = 0;i < Mask1->size();i ++){ - Mask1->verts.attr("alpha")[i] = Mask1->verts[i][0]; - } - alpha1 = Mask1->verts.attr("alpha"); - } - if(maskmode1 == "G"){ - Mask1->verts.add_attr("alpha"); - for(int i = 0;i < Mask1->size();i ++){ - Mask1->verts.attr("alpha")[i] = Mask1->verts[i][1]; - } - alpha1 = Mask1->verts.attr("alpha"); - } - if(maskmode1 == "B"){ - Mask1->verts.add_attr("alpha"); - for(int i = 0;i < Mask1->size();i ++){ - Mask1->verts.attr("alpha")[i] = Mask1->verts[i][2]; - } - alpha1 = Mask1->verts.attr("alpha"); - } - if(maskmode1 == "A"){ - if(Mask1->verts.has_attr("alpha")){ - alpha1 = Mask1->verts.attr("alpha"); - } - else{ - Mask1->verts.add_attr("alpha"); - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - Mask1->verts.attr("alpha")[i * w1 + j] = 1; - } - } - alpha1 = Mask1->verts.attr("alpha"); - } - } - } - if(has_input("Mask2")) { - auto Mask2 = get_input2("Mask2"); - Mask2->verts.resize(w1 * h1); - Mask2->userData().set2("w", w1); - Mask2->userData().set2("h", h1); - if(maskmode2 == "R"){ - Mask2->verts.add_attr("alpha"); - for(int i = 0;i < Mask2->size();i++){ - Mask2->verts.attr("alpha")[i] = Mask2->verts[i][0]; - } - alpha2 = Mask2->verts.attr("alpha"); - } - if(maskmode2 == "G"){ - Mask2->verts.add_attr("alpha"); - for(int i = 0;i < Mask2->size();i++){ - Mask2->verts.attr("alpha")[i] = Mask2->verts[i][1]; - } - alpha2 = Mask2->verts.attr("alpha"); - } - if(maskmode2 == "B"){ - Mask2->verts.add_attr("alpha"); - for(int i = 0;i < Mask2->size();i++){ - Mask2->verts.attr("alpha")[i] = Mask2->verts[i][2]; - } - alpha2 = Mask2->verts.attr("alpha"); - } - if(maskmode2 == "A"){ - if(Mask2->verts.has_attr("alpha")){ - alpha2 = Mask2->verts.attr("alpha"); - } - else{ - Mask2->verts.add_attr("alpha"); - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - Mask2->verts.attr("alpha")[i * w1 + j] = 1; - } - } - alpha2 = Mask2->verts.attr("alpha"); - } - } - } - if(compmode == "Over") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb1 * l1 + rgb2 * ((l1 != 1 && l2 != 0) ? std::min((1 - l1), l2) : 0); - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = ((l1 != 0 || l2 != 0) ? zeno::max(l2, l1) : 0); - } - } - } - if (compmode == "Under") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb2 * l2 + rgb1 * ((l2!=1 && l1!=0)? std::min((1-l2),l1) : 0); - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = ((l1!=0 || l2!=0)? zeno::max(l2,l1): 0); - } - } - } - if (compmode == "Atop") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb1 * ((l1 != 0 && l2 != 0) ? l1 : 0) + rgb2 * ((l1 == 0) && (l2 != 0) ? l2 : 0); - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = (l1 !=0 && l2 !=0)? l1 : l2; - } - } - } - if (compmode == "Inside") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb1 * ((l1 != 0) && (l2 != 0) ? l1 : 0); - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = (l1 !=0 && l2 !=0)? l1 : 0; - } - } - } - if (compmode == "Outside") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb1 * ((l1 != 0) && (l2 == 0) ? l1 : 0); - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = (l1 != 0 && l2 == 0)? l1 : 0; - } - } - } - if(compmode == "Screen"){ - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l = zeno::min(zeno::min(image1->verts[i * w1 + j][0],image1->verts[i * w1 + j][1]),image1->verts[i * w1 + j][2]); - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb2 * l2 + rgb2 * ((l1!=0 && l2!=0)? l: 0); - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = l2; - } - } - } - if (compmode == "Add") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb2 * l2 + rgb1 * l1; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Subtract") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb1 * l1 - rgb2 * l2 ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Multiply") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb1 * l1 * rgb2 * l2 ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Divide") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb1 * l1 / (rgb2 * l2) ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Diff") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = abs(rgb1 * l1 - (rgb2 * l2)) ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Min") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = l1 <= l2 ? rgb1 * l1 : rgb2 * l2 ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Max") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = l1 >= l2 ? rgb1 * l1 : rgb2 * l2 ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Average") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - vec3f rgb3 = (rgb1+rgb2)/2; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = rgb3 * (l1+l2) ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Xor") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - vec3f rgb3 = {0, 0, 0}; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - vec3f c = (((l1 != 0) && (l2 != 0)) ? rgb3 : rgb1 * l1 + rgb2 * l2) ; - image1->verts[i * w1 + j] = zeno::clamp(c, 0, 1); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "Alpha") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - vec3f rgb3 = {1,1,1}; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - image1->verts[i * w1 + j] = rgb3 * ((l1 != 0) || (l2 != 0) ? zeno::clamp(l1 + l2, 0, 1) : 0); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(l1 + l2, 0, 1); - } - } - } - if (compmode == "!Alpha") { - for (int i = 0; i < h1; i++) { - for (int j = 0; j < w1; j++) { - vec3f rgb1 = image1->verts[i * w1 + j]; - vec3f rgb2 = image2->verts[i * w1 + j]; - vec3f rgb3 = {1,1,1}; - float l1 = alpha1[i * w1 + j]; - float l2 = alpha2[i * w1 + j]; - image1->verts[i * w1 + j] = rgb3 * ((l1 != 0) || (l2 != 0) ? 0 : zeno::clamp(l1 + l2, 0, 1)); - image1->verts.attr("alpha")[i * w1 + j] = zeno::clamp(1 - (l1 + l2), 0, 1); - } - } - } - set_output("image", image1); - } -}; - -ZENDEFNODE(Composite, { - { - {"Foreground"}, - {"Background"}, - {"Mask1"}, - {"Mask2"}, - {"enum Over Under Atop Inside Outside Screen Add Subtract Multiply Divide Diff Min Max Average Xor Alpha !Alpha", "Compmode", "Over"}, - {"enum R G B A", "Mask1mode", "R"}, - {"enum R G B A", "Mask2mode", "R"}, - }, - { - {"image"} - }, - {}, - { "deprecated" }, -}); - - - template static T BlendMode(const float &alpha1, const float &alpha2, const T& rgb1, const T& rgb2, const T& background, const vec3f opacity, std::string compmode) { @@ -687,7 +130,7 @@ static zeno::vec3f BlendModeV(const float &alpha1, const float &alpha2, const ve } struct Blend: INode {//optimize - virtual void apply() override {//todo:: add blend scope RGBA and Premultiplied / Alpha Blending(https://github.com/jamieowen/glsl-blend/issues/6) + virtual void apply() override {//TODO:: add blend scope RGBA and Premultiplied / Alpha Blending(https://github.com/jamieowen/glsl-blend/issues/6) auto blend = get_input("Foreground"); auto base = get_input("Background"); auto maskopacity = get_input2("Mask Opacity"); @@ -750,8 +193,8 @@ struct Blend: INode {//optimize #pragma omp parallel for for (int i = 0; i < imagesize; i++) { vec3f opacity = zeno::clamp(mask->verts[i] * maskopacity, 0, 1); - float alpha = BlendMode(zeno::clamp(blendalpha[i] * opacity1, 0, 1), zeno::clamp(basealpha[i], 0, 1), - zeno::clamp(blendalpha[i] * opacity1, 0, 1), zeno::clamp(basealpha[i], 0, 1), zeno::clamp(basealpha[i] * opacity2, 0, 1), opacity, alphamode); + float alpha = BlendMode((blendalpha[i] * opacity1), basealpha[i],//还需要检查 在调整weight的时候 会有变化吗 + (blendalpha[i] * opacity1), basealpha[i], (basealpha[i] * opacity2), opacity, alphamode); image2alpha[i] = alpha; } } @@ -793,7 +236,7 @@ std::vector> createKernel(float blurValue, return kernel; } -struct CompBlur : INode { +struct CompBlur : INode {//TODO::delete virtual void apply() override { auto image = get_input("image"); auto s = get_input2("strength"); @@ -899,7 +342,7 @@ struct ImageExtractChannel : INode { if (image->verts.has_attr("alpha")) { auto &attr = image->verts.attr("alpha"); for(int i = 0; i < w * h; i++){ - image2->verts[i] = {attr[i], attr[i], attr[i]}; + image2->verts[i] = vec3f(attr[i]); } } else{ @@ -922,9 +365,7 @@ ZENDEFNODE(ImageExtractChannel, { }); /* 导入地形网格的属性,可能会有多个属性。它将地形的属性转换为图 -像,每个属性对应一个图层。 -可能需要的参数:outRemapRange,分辨率,属性名称,属性数据 -类型为float32 */ +像,每个属性对应一个图层。 */ struct CompImport : INode { virtual void apply() override { @@ -988,35 +429,7 @@ ZENDEFNODE(CompImport, { {}, { "comp" }, }); +//TODO::Channel shuffle、RGBA Shuffle -struct CompMixChanel : INode { - virtual void apply() override { - auto R = get_input("R"); - auto G = get_input("G"); - auto B = get_input("B"); - auto &ud = R->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); - - for(int i = 0;i < R->size();i++){ - R->verts[i][1] = G->verts[i][1]; - R->verts[i][2] = B->verts[i][2]; - } - set_output("image", R); - } -}; - -ZENDEFNODE(CompMixChanel, { - { - {"R"}, - {"G"}, - {"B"}, - }, - { - {"image"}, - }, - {}, - { "comp" }, -}); } } \ No newline at end of file diff --git a/projects/ImgCV/ImageProcessing.cu b/projects/ImgCV/ImageProcessing.cu deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/projects/ImgCV/MachineLearning.cpp b/projects/ImgCV/MachineLearning.cpp deleted file mode 100644 index 4820abdc91..0000000000 --- a/projects/ImgCV/MachineLearning.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// -// Created by Administrator on 2023/6/2. -// From 6e0041537981553c36cde77d97d88857eed4a656 Mon Sep 17 00:00:00 2001 From: YingQ Date: Thu, 19 Oct 2023 18:34:53 +0800 Subject: [PATCH 03/14] Update ImageProcessing.cpp --- projects/ImgCV/ImageProcessing.cpp | 791 +---------------------------- 1 file changed, 26 insertions(+), 765 deletions(-) diff --git a/projects/ImgCV/ImageProcessing.cpp b/projects/ImgCV/ImageProcessing.cpp index 94c682c2f3..b9c2c6de43 100644 --- a/projects/ImgCV/ImageProcessing.cpp +++ b/projects/ImgCV/ImageProcessing.cpp @@ -213,7 +213,7 @@ void rotateimage(std::shared_ptr src, std::shared_ptr image = get_input("image"); auto balpha = get_input2("alpha"); @@ -358,7 +358,7 @@ ZENDEFNODE(ImageRGB2HSV, { { "image" }, }); -struct ImageHSV2RGB : INode { +struct ImageHSV2RGB : INode {//TODO::DIFF WITH HOUDINI virtual void apply() override { auto image = get_input("image"); float R = 0, G = 0, B = 0; @@ -385,8 +385,8 @@ ZENDEFNODE(ImageHSV2RGB, { {}, { "image" }, }); - -struct ImageEditHSV : INode { +//TODO::add convert option↓ +struct ImageHSV : INode {//TODO::HSL HSV?? SD HSL HOUDINI HSV virtual void apply() override { auto image = get_input("image"); float H = 0, S = 0, V = 0; @@ -394,148 +394,27 @@ struct ImageEditHSV : INode { float Hi = get_input2("H"); float Si = get_input2("S"); float Vi = get_input2("V"); - if(Hue == "default"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "edit"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = Hi; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "red"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = 0; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "orange"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = 30; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "yellow"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = 60; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "green"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = 120; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "cyan"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = 180; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "blue"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = 240; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } - } - if(Hue == "purple"){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - zeno::RGBtoHSV(R, G, B, H, S, V); - H = 300; - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(Vi-1); - zeno::HSVtoRGB(H, S, V, R, G, B); - image->verts[i][0] = R; - image->verts[i][1] = G; - image->verts[i][2] = B; - } +#pragma omp parallel for + for (auto i = 0; i < image->verts.size(); i++) { + float R = image->verts[i][0]; + float G = image->verts[i][1]; + float B = image->verts[i][2]; + zeno::RGBtoHSV(R, G, B, H, S, V); + H = Hi; + S = S + (S - 0.5)*(Si-1); + V = V + (V - 0.5)*(Vi-1); + zeno::HSVtoRGB(H, S, V, R, G, B); + image->verts[i][0] = R; + image->verts[i][1] = G; + image->verts[i][2] = B; } set_output("image", image); } }; -ZENDEFNODE(ImageEditHSV, { +ZENDEFNODE(ImageHSV, { { {"image"}, - {"enum default edit red orange yellow green cyan blue purple ", "Hue", "edit"}, {"float", "H", "1"}, {"float", "S", "1"}, {"float", "V", "1"}, @@ -547,358 +426,9 @@ ZENDEFNODE(ImageEditHSV, { { "image" }, }); -struct ImageEdit: INode { - virtual void apply() override { - auto image = get_input("image"); - auto size = get_input2("Size"); - auto RGBA = get_input2("RGBA"); - auto Gray = get_input2("Gray"); - auto Invert = get_input2("Invert"); - auto RGBLevel = get_input2("RGBLevel"); - float R = RGBLevel[0]; - float G = RGBLevel[1]; - float B = RGBLevel[2]; - float L = get_input2("Luminace"); - float ContrastRatio = get_input2("ContrastRatio"); - float Si = get_input2("Saturation"); - auto &ud1 = image->userData(); - int w1 = ud1.get2("w"); - int h1 = ud1.get2("h"); - float H = 0, S = 0, V = 0; - if(RGBA == "RGBA") { - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = image->verts[i][0]; - float G1 = image->verts[i][1]; - float B1 = image->verts[i][2]; - R1 *= R; - G1 *= G; - B1 *= B; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1; - image->verts[i][1] = G1; - image->verts[i][2] = B1; - } - if(!image->verts.has_attr("alpha")){ - image->verts.add_attr("alpha"); - for(int i = 0;i < image->size();i++){ - image->verts.attr("alpha")[i] = 1; - } - } - } - if(RGBA == "RGB") { - if(image->verts.has_attr("alpha")){ - auto image2 = std::make_shared(); - image2->verts.resize(w1 * h1); - image2->userData().set2("isImage", 1); - image2->userData().set2("w", w1); - image2->userData().set2("h", h1); - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = image->verts[i][0] * R; - float G1 = image->verts[i][1] * G; - float B1 = image->verts[i][2] * B; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image2->verts[i][0] = R1; - image2->verts[i][1] = G1; - image2->verts[i][2] = B1; - } - image = image2; - } - else{ - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = image->verts[i][0] * R; - float G1 = image->verts[i][1] * G; - float B1 = image->verts[i][2] * B; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1; - image->verts[i][1] = G1; - image->verts[i][2] = B1; - } - } - } - if(RGBA == "RA") { - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = image->verts[i][0] * R; - float G1 = 0; - float B1 = 0; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1 ; - image->verts[i][1] = G1 ; - image->verts[i][2] = B1 ; - } - if(!image->verts.has_attr("alpha")){ - image->verts.add_attr("alpha"); - for(int i = 0;i < image->size();i++){ - image->verts.attr("alpha")[i] = 1; - } - } - } - if(RGBA == "GA") { - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = 0; - float G1 = G * image->verts[i][1]; - float B1 = 0; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1 ; - image->verts[i][1] = G1 ; - image->verts[i][2] = B1 ; - } - if(!image->verts.has_attr("alpha")){ - image->verts.add_attr("alpha"); - for(int i = 0;i < image->size();i++){ - image->verts.attr("alpha")[i] = 1; - } - } - } - if(RGBA == "BA") { - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = 0; - float G1 = 0; - float B1 = B * image->verts[i][2]; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1; - image->verts[i][1] = G1; - image->verts[i][2] = B1; - } - if(!image->verts.has_attr("alpha")){ - image->verts.add_attr("alpha"); - for(int i = 0;i < image->size();i++){ - image->verts.attr("alpha")[i] = 1; - } - } - } - if(RGBA == "R") { - if(image->verts.has_attr("alpha")){ - auto image2 = std::make_shared(); - image2->verts.resize(w1 * h1); - image2->userData().set2("isImage", 1); - image2->userData().set2("w", w1); - image2->userData().set2("h", h1); - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = image->verts[i][0] * R; - float G1 = 0; - float B1 = 0; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image2->verts[i][0] = R1; - image2->verts[i][1] = G1; - image2->verts[i][2] = B1; - } - image = image2; - } - else{ - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = image->verts[i][0] * R; - float G1 = 0; - float B1 = 0; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1 ; - image->verts[i][1] = G1 ; - image->verts[i][2] = B1 ; - } - } - } - if(RGBA == "G") { - if(image->verts.has_attr("alpha")){ - auto image2 = std::make_shared(); - image2->verts.resize(w1 * h1); - image2->userData().set2("isImage", 1); - image2->userData().set2("w", w1); - image2->userData().set2("h", h1); - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = 0; - float G1 = image->verts[i][1] * G; - float B1 = 0; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image2->verts[i][0] = R1; - image2->verts[i][1] = G1; - image2->verts[i][2] = B1; - } - image = image2; - } - else{ - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = 0; - float G1 = image->verts[i][1] * G; - float B1 = 0; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1 ; - image->verts[i][1] = G1 ; - image->verts[i][2] = B1 ; - } - } - } - if(RGBA == "B") { - if(image->verts.has_attr("alpha")){ - auto image2 = std::make_shared(); - image2->verts.resize(w1 * h1); - image2->userData().set2("isImage", 1); - image2->userData().set2("w", w1); - image2->userData().set2("h", h1); - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = 0; - float G1 = 0; - float B1 = image->verts[i][2] * B; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image2->verts[i][0] = R1; - image2->verts[i][1] = G1; - image2->verts[i][2] = B1; - } - image = image2; - } - else{ - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = 0; - float G1 = 0; - float B1 = image->verts[i][2] * B; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1 ; - image->verts[i][1] = G1 ; - image->verts[i][2] = B1 ; - } - } - } - if(RGBA == "A") { - for (auto i = 0; i < image->verts.size(); i++) { - float R1 = 1; - float G1 = 1; - float B1 = 1; - zeno::RGBtoHSV(R1, G1, B1, H, S, V); - S = S + (S - 0.5)*(Si-1); - V = V + (V - 0.5)*(L-1); - zeno::HSVtoRGB(H, S, V, R1, G1, B1); - image->verts[i][0] = R1; - image->verts[i][1] = G1; - image->verts[i][2] = B1; - } - if (image->verts.has_attr("alpha")) { - auto &Alpha = image->verts.attr("alpha"); - image->verts.add_attr("alpha"); - image->verts.attr("alpha")=image->verts.attr("alpha"); - } - else{ - image->verts.add_attr("alpha"); - for(int i = 0;i < w1 * h1;i++){ - image->verts.attr("alpha")[i] = 1.0; - } - } - } - for (auto i = 0; i < image->verts.size(); i++) { - image->verts[i] = image->verts[i] + (image->verts[i]-0.5) * (ContrastRatio-1); - } - if(Gray){ - for (auto i = 0; i < image->verts.size(); i++) { - float R = image->verts[i][0]; - float G = image->verts[i][1]; - float B = image->verts[i][2]; - float avr = (R + G + B)/3; - image->verts[i][0] = avr ; - image->verts[i][1] = avr ; - image->verts[i][2] = avr ; - } - } - if(Invert){ - for (auto i = 0; i < image->verts.size(); i++) { - image->verts[i] = 1 - image->verts[i]; - } - } - set_output("image", image); - } -}; - -ZENDEFNODE(ImageEdit, { - { - {"image"}, - {"vec2f", "Size", "1,1"}, - {"enum RGBA RGB RA GA BA R G B A", "RGBA", "RGB"}, - {"vec3f", "RGBLevel", "1,1,1"}, - {"float", "Saturation", "1"}, - {"float", "Luminace", "1"}, - {"float", "ContrastRatio", "1"}, - {"bool", "Gray", "0"}, - {"bool", "Invert", "0"}, - }, - { - {"image"} - }, - {}, - { "image" }, -}); - float gaussian(float x, float sigma) { return exp(-(x * x) / (2 * sigma * sigma)); } -void gaussian_filter(std::shared_ptr &image, std::shared_ptr &imagetmp, int width, int height, int sigma) { - - int size = (int)(2 * sigma + 1); - if (size % 2 == 0) { - size++; - } - - float* kernel = new float[size]; - float sum = 0.0; - int mid = size / 2; - for (int i = 0; i < size; i++) { - kernel[i] = gaussian(i - mid, sigma); - sum += kernel[i]; - } - for (int i = 0; i < size; i++) { - kernel[i] /= sum; - } - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - float sum0 = 0.0, sum1 = 0.0, sum2 = 0.0; - for (int i = -mid; i <= mid; i++) { - int nx = x + i; - if (nx < 0 || nx >= width) { - continue; - } - sum0 += kernel[i + mid] * image->verts[y * width + nx][0]; - sum1 += kernel[i + mid] * image->verts[y * width + nx][1]; - sum2 += kernel[i + mid] * image->verts[y * width + nx][2]; - } - imagetmp->verts[y * width + x] = {sum0,sum1,sum2}; - } - } - image = imagetmp; - - delete[] kernel; -} // MedianBlur void MedianBlur(std::shared_ptr &image, std::shared_ptr &imagetmp, int width, int height, int kernel_size) { @@ -1140,9 +670,6 @@ ZENDEFNODE(ImageEditContrast, { struct ImageEditInvert : INode{ virtual void apply() override { auto image = get_input("image"); - auto &ud = image->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); for (auto i = 0; i < image->verts.size(); i++) { image->verts[i] = 1 - image->verts[i]; } @@ -1157,7 +684,7 @@ ZENDEFNODE(ImageEditInvert, { "image", }, {}, - {"deprecated"}, + {"image"}, }); /* 将灰度图像转换为法线贴图 */ @@ -1178,9 +705,8 @@ struct ImageToNormalMap : INode { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { - int idx = i * w + j; if (i == 0 || i == h || j == 0 || j == w) { - normalmap->verts[idx] = {0, 0, 1}; + normalmap->verts[i * w + j] = {0, 0, 1}; } } } @@ -1213,7 +739,6 @@ struct ImageToNormalMap : INode { } } - set_output("image", normalmap); } }; @@ -1232,7 +757,7 @@ ZENDEFNODE(ImageToNormalMap, { { "image" }, }); -struct ImageGray : INode {//todo +struct ImageGray : INode {//TODO::fix luminace and add more mode void apply() override { auto image = get_input("image"); auto mode = get_input2("mode"); @@ -1403,7 +928,7 @@ void dilateImage(cv::Mat& src, cv::Mat& dst, int kheight, int kwidth, int Streng cv::Mat kernel = getStructuringElement(cv::MORPH_RECT, cv::Size(kheight, kwidth)); cv::dilate(src, dst, kernel, cv::Point(-1, -1), Strength); } -struct ImageDilate: INode { +struct ImageDilate: INode {//TODO::Merge with erode void apply() override { std::shared_ptr image = get_input("image"); int strength = get_input2("strength"); @@ -1614,227 +1139,7 @@ ZENDEFNODE(ImageColor2, { { "image" }, }); - -//TODO:: fix sparse convolution noise - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// Sparse Convolution Noise -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -// std::array perm = { -// 225, 155, 210, 108, 175, 199, 221, 144, 203, 116, 70, 213, 69, 158, 33, 252, 5, 82, 173, 133, 222, 139, -// 174, 27, 9, 71, 90, 246, 75, 130, 91, 191, 169, 138, 2, 151, 194, 235, 81, 7, 25, 113, 228, 159, -// 205, 253, 134, 142, 248, 65, 224, 217, 22, 121, 229, 63, 89, 103, 96, 104, 156, 17, 201, 129, 36, 8, -// 165, 110, 237, 117, 231, 56, 132, 211, 152, 20, 181, 111, 239, 218, 170, 163, 51, 172, 157, 47, 80, 212, -// 176, 250, 87, 49, 99, 242, 136, 189, 162, 115, 44, 43, 124, 94, 150, 16, 141, 247, 32, 10, 198, 223, -// 255, 72, 53, 131, 84, 57, 220, 197, 58, 50, 208, 11, 241, 28, 3, 192, 62, 202, 18, 215, 153, 24, -// 76, 41, 15, 179, 39, 46, 55, 6, 128, 167, 23, 188, 106, 34, 187, 140, 164, 73, 112, 182, 244, 195, -// 227, 13, 35, 77, 196, 185, 26, 200, 226, 119, 31, 123, 168, 125, 249, 68, 183, 230, 177, 135, 160, 180, -// 12, 1, 243, 148, 102, 166, 38, 238, 251, 37, 240, 126, 64, 74, 161, 40, 184, 149, 171, 178, 101, 66, -// 29, 59, 146, 61, 254, 107, 42, 86, 154, 4, 236, 232, 120, 21, 233, 209, 45, 98, 193, 114, 78, 19, -// 206, 14, 118, 127, 48, 79, 147, 85, 30, 207, 219, 54, 88, 234, 190, 122, 95, 67, 143, 109, 137, 214, -// 145, 93, 92, 100, 245, 0, 216, 186, 60, 83, 105, 97, 204, 52}; - -// template -// constexpr T PERM(T x) { -// return perm[(x)&255]; -// } - -// #define INDEX(ix, iy, iz) PERM((ix) + PERM((iy) + PERM(iz))) - -// std::random_device rd; -// std::default_random_engine engine(rd()); -// std::uniform_real_distribution d(0, 1); - -// float impulseTab[256 * 4]; -// void impulseTabInit() { -// int i; -// float *f = impulseTab; -// for (i = 0; i < 256; i++) { -// *f++ = d(engine); -// *f++ = d(engine); -// *f++ = d(engine); -// *f++ = 1. - 2. * d(engine); -// } -// } - -// float catrom2(float d, int griddist) { -// float x; -// int i; -// static float table[401]; -// static bool initialized = 0; -// if (d >= griddist * griddist) -// return 0; -// if (!initialized) { -// for (i = 0; i < 4 * 100 + 1; i++) { -// x = i / (float)100; -// x = sqrtf(x); -// if (x < 1) -// table[i] = 0.5 * (2 + x * x * (-5 + x * 3)); -// else -// table[i] = 0.5 * (4 + x * (-8 + x * (5 - x))); -// } -// initialized = 1; -// } -// d = d * 100 + 0.5; -// i = floor(d); -// if (i >= 4 * 100 + 1) -// return 0; -// return table[i]; -// } - -// #define NEXT(h) (((h) + 1) & 255) - -// float scnoise(float x, float y, float z, int pulsenum, int griddist) { -// static int initialized; -// float *fp = nullptr; -// int i, j, k, h, n; -// int ix, iy, iz; -// float sum = 0; -// float fx, fy, fz, dx, dy, dz, distsq; - -// /* Initialize the random impulse table if necessary. */ -// if (!initialized) { -// impulseTabInit(); -// initialized = 1; -// } -// ix = floor(x); -// fx = x - ix; -// iy = floor(y); -// fy = y - iy; -// iz = floor(z); -// fz = z - iz; - -// /* Perform the sparse convolution. */ -// for (i = -griddist; i <= griddist; i++) { //周围的grid : 2*griddist+1 -// for (j = -griddist; j <= griddist; j++) { -// for (k = -griddist; k <= griddist; k++) { /* Compute voxel hash code. */ -// h = INDEX(ix + i, iy + j, iz + k); //PSN -// for (n = pulsenum; n > 0; n--, h = NEXT(h)) { /* Convolve filter and impulse. */ -// //每个cell内随机产生pulsenum个impulse -// fp = &impulseTab[h * 4]; // get impulse -// dx = fx - (i + *fp++); //i + *fp++ 周围几个晶胞的脉冲 -// dy = fy - (j + *fp++); -// dz = fz - (k + *fp++); -// distsq = dx * dx + dy * dy + dz * dz; -// sum += catrom2(distsq, griddist) * -// *fp; // 第四个fp 指向的就是每个点的权重 filter kernel在gabor noise里面变成了gabor kernel。 -// } -// } -// } -// } -// return sum / pulsenum; -// } - -// struct ImageNoise : INode { -// virtual void apply() override { -// auto image = std::make_shared(); -// auto griddist = get_input2("griddist"); -// auto pulsenum = get_input2("pulsenum"); -// auto size = get_input2("Size"); -// auto elementsize = get_input2("elementsize"); -// image->verts.resize(size[0] * size[1]); -// image->userData().set2("isImage", 1); -// image->userData().set2("w", size[0]); -// image->userData().set2("h", size[1]); - -// //#pragma omp parallel -// for (int i = 0; i < size[1]; i++) { -// for (int j = 0; j < size[0]; j++) { -// i = i * 1/(elementsize); -// j = j * 1/(elementsize); -// //float x = (scnoise(i, 0, j, pulsenum, griddist) + 1) * 0.75; -// image->verts[i * size[0] + j][0] = (scnoise(i, 0, j, pulsenum, griddist) + 1) * 0.75; -// image->verts[i * size[0] + j][1] = (scnoise(j, 0, i, pulsenum, griddist) +1)*0.75; -// image->verts[i * size[0] + j][2] = (scnoise(0, i, j, pulsenum, griddist)+1)*0.75; -// } -// } - -// set_output("image", image); - -// } -// }; - -// ZENDEFNODE(ImageNoise, { -// { -// {"int", "pulsenum", "3"}, -// {"vec2i", "Size", "1024,1024"}, -// {"int", "elementsize", "50"}, -// {"int", "griddist", "2"} -// }, -// { -// {"image"}, -// }, -// {}, -// { "image" }, -// }); - - -struct ImageExtractColor : INode { - virtual void apply() override { - auto image = get_input("image"); - auto background = get_input2("background"); - auto &ud = image->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); - vec3f up = get_input2("high_threshold"); - vec3f low = get_input2("low_threshold"); - float upr = up[0]/255, upg = up[1]/255, upb = up[2]/255; - float lr = low[0]/255,lg = low[1]/255,lb = low[2]/255; - zeno::log_info("up:{}, {}, {}",upr,upg,upb); - zeno::log_info("low:{}, {}, {}",lr,lg,lb); - if(background == "transparent"){ - if(!image->has_attr("alpha")){ - image->verts.add_attr("alpha"); - for(int i = 0; i < image->verts.size();i++){ - image->verts.attr("alpha")[i] = 1; - } - } - for (auto i = 0; i < image->verts.size(); i++) { - if(((upr < image->verts[i][0]) || (image->verts[i][0] < lr)) || - ((upg < image->verts[i][1]) || (image->verts[i][1] < lg)) || - ((upb < image->verts[i][2]) || (image->verts[i][2] < lb))){ - image->verts.attr("alpha")[i] = 0; - } - } - } - else if(background == "black"){ - for (auto i = 0; i < image->verts.size(); i++) { - if(((upr < image->verts[i][0]) || (image->verts[i][0] < lr)) || - ((upg < image->verts[i][1]) || (image->verts[i][1] < lg)) || - ((upb < image->verts[i][2]) || (image->verts[i][2] < lb))){ - image->verts[i] = {0,0,0}; - - } - } - } - else if(background == "white"){ - for (auto i = 0; i < image->verts.size(); i++) { - if(((upr < image->verts[i][0]) || (image->verts[i][0] < lr)) || - ((upg < image->verts[i][1]) || (image->verts[i][1] < lg)) || - ((upb < image->verts[i][2]) || (image->verts[i][2] < lb))){ - image->verts[i] = {1,1,1}; - } - } - } - set_output("image", image); - } -}; -ZENDEFNODE(ImageExtractColor, { - { - {"image"}, - {"vec3f", "high_threshold", "255,255,255"}, - {"vec3f", "low_threshold", "0,0,0"}, - {"enum transparent black white", "background", "transparent"}, - }, - { - {"image"}, - }, - {}, - { "image" }, -}); - -struct ImageDelColor: INode { +struct ImageDelColor: INode {//TODO:: SD clamp color/? void apply() override { auto image = get_input("image"); auto background = get_input2("background"); @@ -1845,22 +1150,7 @@ struct ImageDelColor: INode { vec3f low = get_input2("low_threshold"); float upr = up[0]/255, upg = up[1]/255, upb = up[2]/255; float lr = low[0]/255,lg = low[1]/255,lb = low[2]/255; - if(background == "transparent"){ - if(!image->has_attr("alpha")){ - image->verts.add_attr("alpha"); - for(int i = 0; i < image->verts.size();i++){ - image->verts.attr("alpha")[i] = 1; - } - } - for (auto i = 0; i < image->verts.size(); i++) { - if(((lr <= image->verts[i][0]) && (image->verts[i][0] <= upr)) && - ((lg <= image->verts[i][1]) && (image->verts[i][1] <= upg)) && - ((lb <= image->verts[i][2]) && (image->verts[i][2] <= upb))){ - image->verts.attr("alpha")[i] = 0; - } - } - } - else if(background == "black"){ + if(background == "black"){ for (auto i = 0; i < image->verts.size(); i++) { if(((lr <= image->verts[i][0]) && (image->verts[i][0] <= upr)) && ((lg <= image->verts[i][1]) && (image->verts[i][1] <= upg)) && @@ -1887,7 +1177,7 @@ ZENDEFNODE(ImageDelColor, { {"image"}, {"vec3f", "high_threshold", "255,255,255"}, {"vec3f", "low_threshold", "0,0,0"}, - {"enum transparent black white", "background", "transparent"}, + {"enum black white", "background", "black"}, }, { {"image"}, @@ -1896,7 +1186,7 @@ ZENDEFNODE(ImageDelColor, { {"image"}, }); -struct ImageMatting: INode { +struct ImageMatting: INode {//TODO::optimize virtual void apply() override { auto image = get_input("image"); auto &ud = image->userData(); @@ -2075,7 +1365,6 @@ struct ImageMatting: INode { } } } - //todo else if (wg < w && hg < h) { } } @@ -2097,34 +1386,6 @@ ZENDEFNODE(ImageMatting, { { "image" }, }); -//根据灰度进行上色 -struct MaskEdit: INode { - void apply() override { - std::shared_ptr image = get_input("image"); - UserData &ud = image->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); - for(int i = 0;i < image->size();i++){ - - } - - set_output("image", image); - } -}; -ZENDEFNODE(MaskEdit, { - { - {"image"}, - {"int", "rows", "2"}, - {"int", "cols", "2"}, - }, - { - {"image"}, - }, - {}, - {"deprecated"}, -}); - - struct ImageLevels: INode { void apply() override { std::shared_ptr image = get_input("image"); From 30d526a0fbad4d329cfbb2b9e9794ac83b28d36d Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Fri, 20 Oct 2023 13:05:34 +0800 Subject: [PATCH 04/14] image_panel_cursor_info --- ui/zenoedit/panel/zenoimagepanel.cpp | 115 +++++++++++---------------- ui/zenoedit/panel/zenoimagepanel.h | 80 ++++++++++++++++++- 2 files changed, 126 insertions(+), 69 deletions(-) diff --git a/ui/zenoedit/panel/zenoimagepanel.cpp b/ui/zenoedit/panel/zenoimagepanel.cpp index 9ec9ea65ba..8fae5ca268 100644 --- a/ui/zenoedit/panel/zenoimagepanel.cpp +++ b/ui/zenoedit/panel/zenoimagepanel.cpp @@ -18,74 +18,6 @@ #include "viewport/displaywidget.h" -static float ziv_wheelZoomFactor = 1.25; - -class ZenoImageView: public QGraphicsView { -public: - QGraphicsPixmapItem *_image = nullptr; - QGraphicsScene *scene = nullptr; - bool fitMode = true; - explicit ZenoImageView(QWidget *parent) : QGraphicsView(parent) { - scene = new QGraphicsScene; - this->setScene(scene); - - setBackgroundBrush(QColor(37, 37, 37)); - } - - bool hasImage() { - return _image != nullptr; - } - - void clearImage() { - if (hasImage()) { - scene->removeItem(_image); - _image = nullptr; - } - } - - void setImage(const QImage &image) { - QPixmap pm = QPixmap::fromImage(image); - if (hasImage()) { - _image->setPixmap(pm); - } - else { - _image = this->scene->addPixmap(pm); - } - setSceneRect(QRectF(pm.rect())); // Set scene size to image size. - updateImageView(); - } - - void updateImageView() { - if (!hasImage()) { - return; - } - if (fitMode) { - fitInView(sceneRect(), Qt::AspectRatioMode::KeepAspectRatio); - } - } - void resizeEvent(QResizeEvent *event) override { - updateImageView(); - } - void wheelEvent(QWheelEvent* event) override { - fitMode = false; - qreal zoomFactor = 1; - if (event->angleDelta().y() > 0) - zoomFactor = ziv_wheelZoomFactor; - else if (event->angleDelta().y() < 0) - zoomFactor = 1 / ziv_wheelZoomFactor; - scale(zoomFactor, zoomFactor); - } - void mousePressEvent(QMouseEvent* event) override { - fitMode = false; - setDragMode(QGraphicsView::ScrollHandDrag); - QGraphicsView::mousePressEvent(event); - } - void mouseReleaseEvent(QMouseEvent* event) override { - QGraphicsView::mouseReleaseEvent(event); - setDragMode(QGraphicsView::NoDrag); - } -}; - void ZenoImagePanel::clear() { if (image_view) { image_view->clearImage(); @@ -284,5 +216,52 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { image_view->fitMode = true; image_view->updateImageView(); }); + connect(image_view, &ZenoImageView::pixelChanged, this, [=](float x, float y) { + std::string primid = pPrimName->text().toStdString(); + zenovis::Scene* scene = nullptr; + auto mainWin = zenoApp->getMainWindow(); + ZASSERT_EXIT(mainWin); + QVector wids = mainWin->viewports(); + if (!wids.isEmpty()) + { + auto session = wids[0]->getZenoVis()->getSession(); + ZASSERT_EXIT(session); + scene = session->get_scene(); + } + if (!scene) + return; + bool found = false; + for (auto const &[key, ptr]: scene->objectsMan->pairs()) { + if ((key.substr(0, key.find(":"))) != primid) { + continue; + } + auto &ud = ptr->userData(); + if (ud.get2("isImage", 0) == 0) { + continue; + } + found = true; + if (auto obj = dynamic_cast(ptr)) { + int width = ud.get2("w"); + int height = ud.get2("h"); + int w = int(zeno::clamp(x, 0, width - 1)); + int h = int(zeno::clamp(y, 0, height - 1)); + int i = h * width + w; + auto c = obj->verts[i]; + QString statusInfo = QString(zeno::format("width: {}, height: {} | ({}, {}) : ({}, {}, {})" + , width + , height + , w + , h + , c[0] + , c[1] + , c[2] + ).c_str()); + pStatusBar->setText(statusInfo); + } + } + if (found == false) { + clear(); + } + }); } diff --git a/ui/zenoedit/panel/zenoimagepanel.h b/ui/zenoedit/panel/zenoimagepanel.h index a9e18b71c2..b7a9ffb42d 100644 --- a/ui/zenoedit/panel/zenoimagepanel.h +++ b/ui/zenoedit/panel/zenoimagepanel.h @@ -6,7 +6,85 @@ #define ZENO_ZENOIMAGEPANEL_H #include -class ZenoImageView; + +class ZenoImageView: public QGraphicsView { + Q_OBJECT +public: + float ziv_wheelZoomFactor = 1.25; + QGraphicsPixmapItem *_image = nullptr; + QGraphicsScene *scene = nullptr; + bool fitMode = true; + explicit ZenoImageView(QWidget *parent) : QGraphicsView(parent) { + scene = new QGraphicsScene; + this->setScene(scene); + setMouseTracking(true); + + setBackgroundBrush(QColor(37, 37, 37)); + } + + bool hasImage() const { + return _image != nullptr; + } + + void clearImage() { + if (hasImage()) { + scene->removeItem(_image); + _image = nullptr; + } + } + + void setImage(const QImage &image) { + QPixmap pm = QPixmap::fromImage(image); + if (hasImage()) { + _image->setPixmap(pm); + } + else { + _image = this->scene->addPixmap(pm); + } + setSceneRect(QRectF(pm.rect())); // Set scene size to image size. + updateImageView(); + } + + void updateImageView() { + if (!hasImage()) { + return; + } + if (fitMode) { + fitInView(sceneRect(), Qt::AspectRatioMode::KeepAspectRatio); + } + } +signals: + void pixelChanged(float, float); +protected: + void resizeEvent(QResizeEvent *event) override { + updateImageView(); + } + void wheelEvent(QWheelEvent* event) override { + fitMode = false; + qreal zoomFactor = 1; + if (event->angleDelta().y() > 0) + zoomFactor = ziv_wheelZoomFactor; + else if (event->angleDelta().y() < 0) + zoomFactor = 1 / ziv_wheelZoomFactor; + scale(zoomFactor, zoomFactor); + } + void mousePressEvent(QMouseEvent* event) override { + fitMode = false; + setDragMode(QGraphicsView::ScrollHandDrag); + QGraphicsView::mousePressEvent(event); + } + void mouseReleaseEvent(QMouseEvent* event) override { + QGraphicsView::mouseReleaseEvent(event); + setDragMode(QGraphicsView::NoDrag); + } + void mouseMoveEvent(QMouseEvent* event) override { + if(auto *item = qgraphicsitem_cast(itemAt(event->pos()))){ + QPointF p = item->mapFromScene(mapToScene(event->pos())); + emit(pixelChanged(p.x(), p.y())); + } + QGraphicsView::mouseMoveEvent(event); + } +}; class ZenoImagePanel : public QWidget { Q_OBJECT From ca2a8f90401c192e2b57e77ca11e51d7e13d2b17 Mon Sep 17 00:00:00 2001 From: YingQ Date: Fri, 20 Oct 2023 15:05:03 +0800 Subject: [PATCH 05/14] Del edgedetect --- projects/ImgCV/ImageProcessing.cpp | 18 +- projects/ImgCV/ObjectRecog.cpp | 572 ++--------------------------- 2 files changed, 37 insertions(+), 553 deletions(-) diff --git a/projects/ImgCV/ImageProcessing.cpp b/projects/ImgCV/ImageProcessing.cpp index b9c2c6de43..4f46eb26a9 100644 --- a/projects/ImgCV/ImageProcessing.cpp +++ b/projects/ImgCV/ImageProcessing.cpp @@ -94,7 +94,7 @@ static void HSVtoRGB(float h, float s, float v, float &r, float &g, float &b) } -struct ImageResize: INode { +struct ImageResize: INode {//TODO::FIX BUG void apply() override { std::shared_ptr image = get_input("image"); int width = get_input2("width"); @@ -107,9 +107,9 @@ struct ImageResize: INode { image2->userData().set2("isImage", 1); image2->userData().set2("w", width); image2->userData().set2("h", height); - //if(image->has_attr("alpha")){ - //image2->verts.add_attr("alpha"); - //} + if(image->has_attr("alpha")){ + image2->verts.add_attr("alpha"); + } float scaleX = static_cast(w) / width; float scaleY = static_cast(h) / height; @@ -120,7 +120,7 @@ struct ImageResize: INode { int srcX = static_cast(x * scaleX); int srcY = static_cast(y * scaleY); image2->verts[y * width + x] = image->verts[srcY * w + srcX]; - //image2->verts.attr("alpha")[y * width + x] = image->verts.attr("alpha")[srcY * w + srcX]; + image2->verts.attr("alpha")[y * width + x] = image->verts.attr("alpha")[srcY * w + srcX]; } set_output("image", image2); } @@ -358,7 +358,7 @@ ZENDEFNODE(ImageRGB2HSV, { { "image" }, }); -struct ImageHSV2RGB : INode {//TODO::DIFF WITH HOUDINI +struct ImageHSV2RGB : INode { virtual void apply() override { auto image = get_input("image"); float R = 0, G = 0, B = 0; @@ -385,8 +385,8 @@ ZENDEFNODE(ImageHSV2RGB, { {}, { "image" }, }); -//TODO::add convert option↓ -struct ImageHSV : INode {//TODO::HSL HSV?? SD HSL HOUDINI HSV + +struct ImageEditHSV : INode {//TODO::HSL HSV?? SD HSL HOUDINI HSV virtual void apply() override { auto image = get_input("image"); float H = 0, S = 0, V = 0; @@ -412,7 +412,7 @@ struct ImageHSV : INode {//TODO::HSL HSV?? SD HSL HOUDINI HSV } }; -ZENDEFNODE(ImageHSV, { +ZENDEFNODE(ImageEditHSV, { { {"image"}, {"float", "H", "1"}, diff --git a/projects/ImgCV/ObjectRecog.cpp b/projects/ImgCV/ObjectRecog.cpp index c0f3574c25..6e73b34565 100644 --- a/projects/ImgCV/ObjectRecog.cpp +++ b/projects/ImgCV/ObjectRecog.cpp @@ -27,7 +27,7 @@ namespace zeno { namespace { -static void zenoedge(std::shared_ptr &grayImage, int width, int height, std::vector &dx, +/*static void zenoedge(std::shared_ptr &grayImage, int width, int height, std::vector &dx, std::vector &dy) { dx.resize(width * height); dy.resize(width * height); @@ -51,43 +51,7 @@ static void zenoedge(std::shared_ptr &grayImage, int width, int dy[y * width + x] = gy; } } -} - -static void scharr2(std::shared_ptr &src, std::shared_ptr &dst, int width, int height, - int threshold) { - std::vector gx(width * height); - std::vector gy(width * height); - dst->verts.resize(width * height); - - // Calculate gradients - for (int y = 1; y < height - 1; ++y) { - for (int x = 1; x < width - 1; ++x) { - int idx = y * width + x; - gx[idx] = (-3 * src->verts[(y - 1) * width + x - 1][0] - 10 * src->verts[y * width + x - 1][0] - - 3 * src->verts[(y + 1) * width + x - 1][0] + - 3 * src->verts[(y - 1) * width + x + 1][0] + 10 * src->verts[y * width + x + 1][0] + - 3 * src->verts[(y + 1) * width + x + 1][0]); - gy[idx] = (-3 * src->verts[(y - 1) * width + x - 1][0] - 10 * src->verts[(y - 1) * width + x][0] - - 3 * src->verts[(y - 1) * width + x + 1][0] + - 3 * src->verts[(y + 1) * width + x - 1][0] + 10 * src->verts[(y + 1) * width + x][0] + - 3 * src->verts[(y + 1) * width + x + 1][0]); - } - } - // Calculate gradient magnitude - for (int y = 1; y < height - 1; ++y) { - for (int x = 1; x < width - 1; ++x) { - int idx = y * width + x; - int mag = std::sqrt(gx[idx] * gx[idx] + gy[idx] * gy[idx]); - if (mag * 255 > threshold) { - dst->verts[idx] = {1, 1, 1}; - } else { - dst->verts[idx] = {0, 0, 0}; - } - float g = std::min(1, std::max(0, mag)); - dst->verts[idx] = {g, g, g}; - } - } -} +}*/ struct ImageEdgeDetect : INode { void apply() override { @@ -102,8 +66,8 @@ struct ImageEdgeDetect : INode { auto &ud = image->userData(); int w = ud.get2("w"); int h = ud.get2("h"); - - if (mode == "zeno_gray") { + float var = 1; + /*if (mode == "zeno_gray") { std::vector dx, dy; zenoedge(image, w, h, dx, dy); for (int i = 0; i < h; i++) { @@ -132,16 +96,15 @@ struct ImageEdgeDetect : INode { } } set_output("image", image); - } - if (mode == "sobel") {//todo:: + }*/ + if (mode == "Sobel") { cv::Mat imagecvin(h, w, CV_32F); - float grayvalue = 1; #pragma omp parallel for for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { vec3f rgb = image->verts[i * w + j]; - grayvalue = rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114;//todo detect rgb three channel? - imagecvin.at(i, j) = grayvalue; + var = rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114;//TODO:: detect rgb three channel? + imagecvin.at(i, j) = var; } } cv::Mat gradX, gradY; @@ -157,17 +120,16 @@ struct ImageEdgeDetect : INode { } set_output("image", image); } - - if (mode == "roberts_gray") { + else if (mode == "Roberts") { cv::Mat imagecvin(h, w, CV_32F); cv::Mat imagecvout(h, w, CV_32F); cv::Mat robertsX, robertsY; cv::Mat magnitude; - int var = 1; +#pragma omp parallel for for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); + var = (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); imagecvin.at(i, j) = var; } } @@ -178,22 +140,19 @@ struct ImageEdgeDetect : INode { cv::filter2D(imagecvin, robertsY, -1, kernelY); cv::magnitude(robertsX, robertsY, imagecvout); - +#pragma omp parallel for for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; + image->verts[i * w + j] = vec3f(imagecvout.at(i, j)); } } set_output("image", image); } - - if (mode == "roberts_threshold") { + /*if (mode == "roberts_threshold") { cv::Mat imagecvin(h, w, CV_32F); cv::Mat imagecvout(h, w, CV_32F); cv::Mat robertsX, robertsY; cv::Mat magnitude; - int var = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { vec3f rgb = image->verts[i * w + j]; @@ -214,17 +173,17 @@ struct ImageEdgeDetect : INode { } } set_output("image", image); - } - if (mode == "roberts_gray") { + }*/ + else if (mode == "Prewitt") { cv::Mat imagecvin(h, w, CV_32F); cv::Mat imagecvout(h, w, CV_32F); cv::Mat edges; cv::Mat prewittX, prewittY; - int var = 1; +#pragma omp parallel for for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); + var = (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); imagecvin.at(i, j) = var; } } @@ -235,55 +194,15 @@ struct ImageEdgeDetect : INode { cv::filter2D(imagecvin, prewittY, -1, kernelY); cv::magnitude(prewittX, prewittY, imagecvout); - - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - if (mode == "roberts_threshold") { - cv::Mat imagecvin(h, w, CV_32F); - cv::Mat imagecvout(h, w, CV_32F); - cv::Mat edges; - cv::Mat prewittX, prewittY; - cv::Mat magnitude; - int var = 1; - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); - imagecvin.at(i, j) = var; - } - } - cv::Mat kernelX = (cv::Mat_(3, 3) << -1, 0, 1, -1, 0, 1, -1, 0, 1); - cv::filter2D(imagecvin, prewittX, -1, kernelX); - - cv::Mat kernelY = (cv::Mat_(3, 3) << -1, -1, -1, 0, 0, 0, 1, 1, 1); - cv::filter2D(imagecvin, prewittY, -1, kernelY); - - cv::magnitude(prewittX, prewittY, magnitude); - - cv::threshold(magnitude, imagecvout, threshold, maxThreshold, cv::THRESH_BINARY); +#pragma omp parallel for for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; + image->verts[i * w + j] = vec3f(imagecvout.at(i, j)); } } set_output("image", image); } - if (mode == "canny_gray") { - cv::Mat imagecvin(h, w, CV_8U); - cv::Mat imagecvout(h, w, CV_8U); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - imagecvin.at(i, j) = int(rgb[0] * 255); - } - } + /*if (mode == "Canny") {//TODO:: Canny opencv only accept 8bit image cv::Mat thresholdImage; int maxValue = 255; // 最大像素值 int blockSize = 3; // 邻域块大小 @@ -294,32 +213,13 @@ struct ImageEdgeDetect : INode { int apertureSize = 3; // 孔径大小,默认为 3 bool L2gradient = false; // 使用 L1 范数计算梯度幅值 cv::Canny(thresholdImage, imagecvout, 0, 0, apertureSize, L2gradient); - - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } set_output("image", image); } if (mode == "canny_threshold") { - cv::Mat imagecvin(h, w, CV_8U); - cv::Mat imagecvout(h, w, CV_8U); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - imagecvin.at(i, j) = int(rgb[0] * 255); - } - } cv::Canny(imagecvin, imagecvout, threshold, maxThreshold); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); + }*/ + else{ + throw zeno::Exception("mode not supported"); } } }; @@ -327,9 +227,9 @@ struct ImageEdgeDetect : INode { ZENDEFNODE(ImageEdgeDetect, { { { "image" }, - { "enum zeno_gray zeno_threshold sobel roberts_gray roberts_threshold prewitt_gray prewitt_threshold canny_gray canny_threshold", "mode", "sobel" }, - { "float", "threshold", "50" }, - { "float", "maxThreshold", "9999" }, + { "enum Sobel Roberts Prewitt Canny", "mode", "Sobel" }, + //{ "float", "threshold", "50" }, + //{ "float", "maxThreshold", "9999" }, { "float", "kernelSize", "3"} }, { @@ -339,108 +239,7 @@ ZENDEFNODE(ImageEdgeDetect, { { "image" }, }); -struct ImageEdgeDetectDIY : INode { - void apply() override { - std::shared_ptr image = get_input2("image"); - auto mode = get_input2("mode"); - auto ktop = get_input2("kerneltop"); - auto kmid = get_input2("kernelmid"); - auto kbot = get_input2("kernelbot"); - int threshold = get_input2("threshold"); - int maxThreshold = get_input2("maxThreshold"); - auto &ud = image->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); - - if (mode == "diy_gray") { - cv::Mat imagecvin(h, w, CV_32F); - cv::Mat imagecvout(h, w, CV_32F); - cv::Mat edges; - cv::Mat prewittX, prewittY; - int var = 1; - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); - imagecvin.at(i, j) = var; - } - } - cv::Mat kernelX = (cv::Mat_(3, 3) << ktop[0], kmid[0], kbot[0], - ktop[1], kmid[1], kbot[1], - ktop[2], kmid[2], kbot[2]); - cv::filter2D(imagecvin, prewittX, -1, kernelX); - - cv::Mat kernelY = (cv::Mat_(3, 3) << ktop[0], kmid[1], kbot[2], - kmid[0], kmid[1], kbot[2], - kbot[0], kmid[1], kbot[2]); - cv::filter2D(imagecvin, prewittY, -1, kernelY); - cv::magnitude(prewittX, prewittY, imagecvout); - - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - - if (mode == "diy_threshold") { - cv::Mat imagecvin(h, w, CV_32F); - cv::Mat imagecvout(h, w, CV_32F); - cv::Mat edges; - cv::Mat prewittX, prewittY; - cv::Mat magnitude; - int var = 1; - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); - imagecvin.at(i, j) = var; - } - } - cv::Mat kernelX = (cv::Mat_(3, 3) << ktop[0], kmid[0], kbot[0], - ktop[1], kmid[1], kbot[1], - ktop[2], kmid[2], kbot[2]); - cv::filter2D(imagecvin, prewittX, -1, kernelX); - - cv::Mat kernelY = (cv::Mat_(3, 3) << ktop[0], kmid[1], kbot[2], - kmid[0], kmid[1], kbot[2], - kbot[0], kmid[1], kbot[2]); - cv::filter2D(imagecvin, prewittY, -1, kernelY); - - cv::magnitude(prewittX, prewittY, magnitude); - - cv::threshold(magnitude, imagecvout, threshold, maxThreshold, cv::THRESH_BINARY); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - } -}; - -ZENDEFNODE(ImageEdgeDetectDIY, { - { - { "image" }, - { "enum diy_gray diy_threshold", "mode", "diy_gray" }, - { "vec3f", "kerneltop", "-1,-2,-1" }, - { "vec3f", "kernelmid", "0,0,0" }, - { "vec3f", "kernelbot", "1,2,1" }, - { "float", "threshold", "50" }, - { "float", "maxThreshold", "9999" }, - }, - { - { "image" } - }, - {}, - { "deprecated" }, -}); - -struct ImageEdgeDetectMarr : INode { //need to gray? +struct ImageEdgeDetectMarr : INode {//TODO::not finished? void apply() override { std::shared_ptr image = get_input2("image"); auto kerneldiameter = get_input2("kernelDiameter"); @@ -519,248 +318,6 @@ ZENDEFNODE(ImageEdgeDetectMarr, { { "image" }, }); -struct ImageEdgeDetectRoberts : INode { - void apply() override { - std::shared_ptr image = get_input2("image"); - auto mode = get_input2("mode"); - int threshold = get_input2("threshold"); - int maxThreshold = get_input2("maxThreshold"); - auto &ud = image->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); - - if (mode == "roberts_gray") { - cv::Mat imagecvin(h, w, CV_32F); - cv::Mat imagecvout(h, w, CV_32F); - cv::Mat robertsX, robertsY; - cv::Mat magnitude; - int var = 1; - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); - imagecvin.at(i, j) = var; - } - } - cv::Mat kernelX = (cv::Mat_(2, 2) << 1, 0, 0, -1); - cv::filter2D(imagecvin, robertsX, -1, kernelX); - cv::Mat kernelY = (cv::Mat_(2, 2) << 0, 1, -1, 0); - cv::filter2D(imagecvin, robertsY, -1, kernelY); - cv::magnitude(robertsX, robertsY, imagecvout); - - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - - if (mode == "roberts_threshold") { - cv::Mat imagecvin(h, w, CV_32F); - cv::Mat imagecvout(h, w, CV_32F); - cv::Mat robertsX, robertsY; - cv::Mat magnitude; - int var = 1; - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); - imagecvin.at(i, j) = var; - } - } - cv::Mat kernelX = (cv::Mat_(2, 2) << 1, 0, 0, -1); - cv::filter2D(imagecvin, robertsX, -1, kernelX); - cv::Mat kernelY = (cv::Mat_(2, 2) << 0, 1, -1, 0); - cv::filter2D(imagecvin, robertsY, -1, kernelY); - cv::magnitude(robertsX, robertsY, magnitude); - cv::threshold(magnitude, imagecvout, threshold, maxThreshold, cv::THRESH_BINARY); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - } -}; - -ZENDEFNODE(ImageEdgeDetectRoberts, { - { - { "image" }, - { "enum roberts_gray roberts_threshold", "mode", "roberts_gray" }, - { "float", "threshold", "50" }, - { "float", "maxThreshold", "255" }, - }, - { - { "image" } - }, - {}, - { "image" }, -}); - -struct ImageEdgeDetectPrewitt : INode { - void apply() override { - std::shared_ptr image = get_input2("image"); - auto mode = get_input2("mode"); - int threshold = get_input2("threshold"); - int maxThreshold = get_input2("maxThreshold"); - auto &ud = image->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); - - if (mode == "roberts_gray") { - cv::Mat imagecvin(h, w, CV_32F); - cv::Mat imagecvout(h, w, CV_32F); - cv::Mat edges; - cv::Mat prewittX, prewittY; - int var = 1; - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); - imagecvin.at(i, j) = var; - } - } - cv::Mat kernelX = (cv::Mat_(3, 3) << -1, 0, 1, -1, 0, 1, -1, 0, 1); - cv::filter2D(imagecvin, prewittX, -1, kernelX); - - cv::Mat kernelY = (cv::Mat_(3, 3) << -1, -1, -1, 0, 0, 0, 1, 1, 1); - cv::filter2D(imagecvin, prewittY, -1, kernelY); - - cv::magnitude(prewittX, prewittY, imagecvout); - - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - - if (mode == "roberts_threshold") { - cv::Mat imagecvin(h, w, CV_32F); - cv::Mat imagecvout(h, w, CV_32F); - cv::Mat edges; - cv::Mat prewittX, prewittY; - cv::Mat magnitude; - int var = 1; - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - var = 255 * (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] *0.114); - imagecvin.at(i, j) = var; - } - } - cv::Mat kernelX = (cv::Mat_(3, 3) << -1, 0, 1, -1, 0, 1, -1, 0, 1); - cv::filter2D(imagecvin, prewittX, -1, kernelX); - - cv::Mat kernelY = (cv::Mat_(3, 3) << -1, -1, -1, 0, 0, 0, 1, 1, 1); - cv::filter2D(imagecvin, prewittY, -1, kernelY); - - cv::magnitude(prewittX, prewittY, magnitude); - - cv::threshold(magnitude, imagecvout, threshold, maxThreshold, cv::THRESH_BINARY); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - } -}; - -ZENDEFNODE(ImageEdgeDetectPrewitt, { - { - { "image" }, - { "enum prewitt_gray prewitt_threshold", "mode", "prewitt_gray" }, - { "float", "threshold", "50" }, - { "float", "maxThreshold", "255" }, - }, - { - { "image" } - }, - {}, - { "image" }, -}); - -struct ImageEdgeDetectCanny : INode { - void apply() override { - std::shared_ptr image = get_input2("image"); - auto mode = get_input2("mode"); - int threshold1 = get_input2("threshold1"); - int threshold2 = get_input2("threshold2"); - auto &ud = image->userData(); - int w = ud.get2("w"); - int h = ud.get2("h"); - - if (mode == "canny_gray") { - cv::Mat imagecvin(h, w, CV_8U); - cv::Mat imagecvout(h, w, CV_8U); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - imagecvin.at(i, j) = int(rgb[0] * 255); - } - } - cv::Mat thresholdImage; - int maxValue = 255; // 最大像素值 - int blockSize = 3; // 邻域块大小 - double C = 2; - cv::adaptiveThreshold(imagecvin, thresholdImage, maxValue, cv::ADAPTIVE_THRESH_MEAN_C, - cv::THRESH_BINARY, blockSize, C); - - int apertureSize = 3; // 孔径大小,默认为 3 - bool L2gradient = false; // 使用 L1 范数计算梯度幅值 - cv::Canny(thresholdImage, imagecvout, 0, 0, apertureSize, L2gradient); - - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - if (mode == "canny_threshold") { - cv::Mat imagecvin(h, w, CV_8U); - cv::Mat imagecvout(h, w, CV_8U); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - vec3f rgb = image->verts[i * w + j]; - imagecvin.at(i, j) = int(rgb[0] * 255); - } - } - cv::Canny(imagecvin, imagecvout, threshold1, threshold2, 3, false); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - float r = float(imagecvout.at(i, j)) / 255.f; - image->verts[i * w + j] = {r, r, r}; - } - } - set_output("image", image); - } - } -}; - -ZENDEFNODE(ImageEdgeDetectCanny, { - { - { "image" }, - { "enum canny_gray canny_threshold", "mode", "canny_gray" }, - { "float", "threshold1", "100" }, - { "float", "threshold2", "200" }, - }, - { - { "image" } - }, - {}, - { "image" }, -}); struct ImageStitching : INode { void apply() override { @@ -833,79 +390,6 @@ ZENDEFNODE(ImageStitching, { { "image" }, }); -//struct ImageStitchingList: INode { -// void apply() override { -// auto primList = get_input("listPrim")->getRaw(); -// auto mode = get_input2("mode"); -// auto &ud1 = image1->userData(); -// int w1 = ud1.get2("w"); -// int h1 = ud1.get2("h"); -//// auto &ud2 = image2->userData(); -//// int w2 = ud2.get2("w"); -//// int h2 = ud2.get2("h"); -// auto nFeatures = get_input2("nFeatures"); -// auto scaleFactor = get_input2("scaleFactor"); -// auto edgeThreshold = get_input2("edgeThreshold"); -// auto patchSize = get_input2("patchSize"); -// cv::Mat imagecvin1(h1, w1, CV_8UC3); -//// cv::Mat imagecvin2(h2, w2, CV_8UC3); -// cv::Mat descriptors1, descriptors2; -// std::vector ikeypoints; -// for (int i = 0; i < h1; i++) { -// for (int j = 0; j < w1; j++) { -// vec3f rgb1 = image1->verts[i * w1 + j]; -// cv::Vec3b& pixel = imagecvin1.at(i, j); -// pixel[0] = rgb1[0] * 255; -// pixel[1] = rgb1[1] * 255; -// pixel[2] = rgb1[2] * 255; -// } -// } -// for (int i = 0; i < h2; i++) { -// for (int j = 0; j < w2; j++) { -// vec3f rgb2 = image2->verts[i * w2 + j]; -// cv::Vec3b& pixel = imagecvin2.at(i, j); -// pixel[0] = rgb2[0] * 255; -// pixel[1] = rgb2[1] * 255; -// pixel[2] = rgb2[2] * 255; -// } -// } -// std::vector images; -// images.push_back(imagecvin1); -// images.push_back(imagecvin2); -// cv::Ptr stitcher = cv::Stitcher::create(); -// cv::Mat result; -// cv::Stitcher::Status status = stitcher->stitch(images, result); -// if (status == cv::Stitcher::OK) { -// int w = result.cols; -// int h = result.rows; -// image1->verts.resize(w*h); -// ud1.set2("w",w); -// ud1.set2("h",h); -// for (int i = 0; i < h; i++) { -// for (int j = 0; j < w; j++) { -// cv::Vec3b pixel = result.at(i, j); -// image1->verts[i * w + j][0] = static_cast(pixel[0])/255; -// image1->verts[i * w + j][1] = static_cast(pixel[1])/255; -// image1->verts[i * w + j][2] = static_cast(pixel[2])/255; -// } -// } -// } else { -// zeno::log_info("stitching failed"); -// } -// set_output("image", image1); -// } -//}; -// -//ZENDEFNODE(ImageStitchingList, { -// { -// {"list", "listPrim"}, -// }, -// { -// { "image" }, -// }, -// {}, -// { "image" }, -//}); struct ImageFeatureDetectORB : INode { void apply() override { auto image = get_input("image"); From 37b0e9002cc90a3f4bfa712316ac6bc7585fef86 Mon Sep 17 00:00:00 2001 From: YingQ Date: Fri, 20 Oct 2023 15:10:47 +0800 Subject: [PATCH 06/14] Revert "prtest" This reverts commit 0f61524acd7fdc03be368e04686149fcec6ec907. --- projects/ImgCV/ImageProcessing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ImgCV/ImageProcessing.cpp b/projects/ImgCV/ImageProcessing.cpp index 4f46eb26a9..29be678f03 100644 --- a/projects/ImgCV/ImageProcessing.cpp +++ b/projects/ImgCV/ImageProcessing.cpp @@ -1410,7 +1410,7 @@ struct ImageLevels: INode { std::vector histogramgreen(256, 0); std::vector histogramblue(256, 0); for (int i = 0; i < w * h; i++) { - histogramred[zeno::clamp(int(image->verts[i][0] * 255.99), 0, 255)]++;//int 没问题吗 + histogramred[zeno::clamp(int(image->verts[i][0] * 255.99), 0, 255)]++; histogramgreen[zeno::clamp(int(image->verts[i][1] * 255.99), 0, 255)]++; histogramblue[zeno::clamp(int(image->verts[i][2] * 255.99), 0, 255)]++; } From 9d8ce907d77a1c5493fd643ba81636cfe4163503 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Fri, 20 Oct 2023 17:36:19 +0800 Subject: [PATCH 07/14] mode RGB Red Green Blue Alpha --- ui/zenoedit/panel/zenoimagepanel.cpp | 77 +++++++++++++--------------- ui/zenoedit/panel/zenoimagepanel.h | 3 +- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/ui/zenoedit/panel/zenoimagepanel.cpp b/ui/zenoedit/panel/zenoimagepanel.cpp index 8fae5ca268..a02515eecd 100644 --- a/ui/zenoedit/panel/zenoimagepanel.cpp +++ b/ui/zenoedit/panel/zenoimagepanel.cpp @@ -9,7 +9,7 @@ #include "zeno/utils/format.h" #include #include -#include +#include "zeno/utils/vec.h" #include "zeno/utils/log.h" #include "zenoapplication.h" #include "zassert.h" @@ -43,7 +43,6 @@ void ZenoImagePanel::setPrim(std::string primid) { return; bool enableGamma = pGamma->checkState() == Qt::Checked; - bool enableAlpha = pAlpha->checkState() == Qt::Checked; bool found = false; for (auto const &[key, ptr]: scene->objectsMan->pairs()) { if ((key.substr(0, key.find(":"))) != primid) { @@ -58,52 +57,46 @@ void ZenoImagePanel::setPrim(std::string primid) { int width = ud.get2("w"); int height = ud.get2("h"); if (image_view) { - QImage img(width, height, QImage::Format_RGB32); - int gridSize = 50; - if (obj->verts.has_attr("alpha")&&enableAlpha) { - auto &alpha = obj->verts.attr("alpha"); + if (pMode->currentText() != "Alpha") { + QImage img(width, height, QImage::Format_RGB32); for (auto i = 0; i < obj->verts.size(); i++) { int h = i / width; - //int h = i % height; check image vert order int w = i % width; - //int w = i / height; - auto foreground = obj->verts[i]; + auto c = obj->verts[i]; if (enableGamma) { - foreground = zeno::pow(foreground, 1.0f / 2.2f); - } - zeno::vec3f background; - if ((h / gridSize) % 2 == (w / gridSize) % 2) { - background = {1, 1, 1}; - } - else { - background = {0.86, 0.86, 0.86}; + c = zeno::pow(c, 1.0f / 2.2f); } - zeno::vec3f c = zeno::mix(background, foreground, alpha[i]); - - int r = glm::clamp(int(c[0] * 255.99), 0, 255); - int g = glm::clamp(int(c[1] * 255.99), 0, 255); - int b = glm::clamp(int(c[2] * 255.99), 0, 255); + auto index = std::map{ + {"RGB", {0, 1, 2}}, + {"Red", {0, 0, 0}}, + {"Green", {1, 1, 1}}, + {"Blue", {2, 2, 2}}, + }.at(pMode->currentText()); + int r = glm::clamp(int(c[index[0]] * 255.99), 0, 255); + int g = glm::clamp(int(c[index[1]] * 255.99), 0, 255); + int b = glm::clamp(int(c[index[2]] * 255.99), 0, 255); img.setPixel(w, height - 1 - h, qRgb(r, g, b)); - //img.setPixel(width - 1 - w, h, qRgb(r, g, b)); } + image_view->setImage(img); } - else{ - for (auto i = 0; i < obj->verts.size(); i++) { - int h = i / width; - int w = i % width; - auto c = obj->verts[i]; - if (enableGamma) { - c = zeno::pow(c, 1.0f / 2.2f); - } - int r = glm::clamp(int(c[0] * 255.99), 0, 255); - int g = glm::clamp(int(c[1] * 255.99), 0, 255); - int b = glm::clamp(int(c[2] * 255.99), 0, 255); + else if (pMode->currentText() == "Alpha") { + QImage img(width, height, QImage::Format_RGB32); + if (obj->verts.has_attr("alpha")) { + auto &alpha = obj->verts.attr("alpha"); + for (auto i = 0; i < obj->verts.size(); i++) { + int h = i / width; + int w = i % width; + auto c = alpha[i]; + int r = glm::clamp(int(c * 255.99), 0, 255); + int g = glm::clamp(int(c * 255.99), 0, 255); + int b = glm::clamp(int(c * 255.99), 0, 255); - img.setPixel(w, height - 1 - h, qRgb(r, g, b)); + img.setPixel(w, height - 1 - h, qRgb(r, g, b)); + } } + image_view->setImage(img); } - image_view->setImage(img); } QString statusInfo = QString(zeno::format("width: {}, height: {}", width, height).c_str()); pStatusBar->setText(statusInfo); @@ -140,9 +133,13 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { pGamma->setCheckState(Qt::Checked); pTitleLayout->addWidget(pGamma); - pAlpha->setStyleSheet("color: white;"); - pAlpha->setCheckState(Qt::Unchecked); - pTitleLayout->addWidget(pAlpha); + pMode->addItem("RGB"); + pMode->addItem("Red"); + pMode->addItem("Green"); + pMode->addItem("Blue"); + pMode->addItem("Alpha"); + pMode->setCurrentIndex(0); + pTitleLayout->addWidget(pMode); pFit->setProperty("cssClass", "grayButton"); pTitleLayout->addWidget(pFit); @@ -197,7 +194,7 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { } } }); - connect(pAlpha, &QCheckBox::stateChanged, this, [=](int state) { + connect(pMode, &ZComboBox::_textActivated, [=](const QString& text) { std::string prim_name = pPrimName->text().toStdString(); Zenovis* zenovis = wids[0]->getZenoVis(); ZASSERT_EXIT(zenovis); diff --git a/ui/zenoedit/panel/zenoimagepanel.h b/ui/zenoedit/panel/zenoimagepanel.h index b7a9ffb42d..b4e0b21b76 100644 --- a/ui/zenoedit/panel/zenoimagepanel.h +++ b/ui/zenoedit/panel/zenoimagepanel.h @@ -6,6 +6,7 @@ #define ZENO_ZENOIMAGEPANEL_H #include +#include class ZenoImageView: public QGraphicsView { Q_OBJECT @@ -92,7 +93,7 @@ class ZenoImagePanel : public QWidget { QLabel* pStatusBar = new QLabel(); QLabel* pPrimName = new QLabel(); QCheckBox *pGamma = new QCheckBox("Gamma"); - QCheckBox *pAlpha = new QCheckBox("Checkerboard"); + ZComboBox *pMode = new ZComboBox(); QPushButton *pFit = new QPushButton("Fit"); ZenoImageView *image_view = nullptr; From 05d9d181424525a5028b0a8c8e5e11e3203714f9 Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Fri, 20 Oct 2023 17:48:19 +0800 Subject: [PATCH 08/14] Optimize the styles of run, kill and always buttons --- ui/zenoedit/dock/docktabcontent.cpp | 116 ++++++++++++------ ui/zenoedit/dock/docktabcontent.h | 20 ++- ui/zenoedit/res/icons.qrc | 10 +- ui/zenoedit/res/icons/RunKill.svg | 10 ++ ui/zenoedit/res/icons/RunKill_on.svg | 10 ++ ui/zenoedit/res/icons/always_checkbox.svg | 3 + ui/zenoedit/res/icons/always_checkbox_on.svg | 4 + ui/zenoedit/res/icons/run_all.svg | 7 +- ui/zenoedit/res/icons/run_all_btn.svg | 3 + ui/zenoedit/res/icons/run_all_disable.svg | 3 - ui/zenoedit/res/icons/run_lightcamera.svg | 6 +- ui/zenoedit/res/icons/run_lightcamera_btn.svg | 3 + .../res/icons/run_lightcamera_disable.svg | 3 - ui/zenoedit/res/icons/run_material.svg | 6 +- ui/zenoedit/res/icons/run_material_btn.svg | 3 + .../res/icons/run_material_disable.svg | 5 - ui/zenoedit/res/stylesheet/checkbox.qss | 30 +++++ ui/zenoedit/res/stylesheet/menu.qss | 4 + ui/zenoedit/res/stylesheet/pushbutton.qss | 34 +++++ ui/zenoui/comctrl/ztoolbutton.cpp | 6 - ui/zenoui/comctrl/ztoolbutton.h | 2 - ui/zenoui/comctrl/ztoolmenubutton.cpp | 32 ++++- ui/zenoui/comctrl/ztoolmenubutton.h | 17 +++ ui/zenoui/style/zenostyle.cpp | 8 -- ui/zenoui/style/zstyleoption.h | 1 - 25 files changed, 264 insertions(+), 82 deletions(-) create mode 100644 ui/zenoedit/res/icons/RunKill.svg create mode 100644 ui/zenoedit/res/icons/RunKill_on.svg create mode 100644 ui/zenoedit/res/icons/always_checkbox.svg create mode 100644 ui/zenoedit/res/icons/always_checkbox_on.svg create mode 100644 ui/zenoedit/res/icons/run_all_btn.svg delete mode 100644 ui/zenoedit/res/icons/run_all_disable.svg create mode 100644 ui/zenoedit/res/icons/run_lightcamera_btn.svg delete mode 100644 ui/zenoedit/res/icons/run_lightcamera_disable.svg create mode 100644 ui/zenoedit/res/icons/run_material_btn.svg delete mode 100644 ui/zenoedit/res/icons/run_material_disable.svg diff --git a/ui/zenoedit/dock/docktabcontent.cpp b/ui/zenoedit/dock/docktabcontent.cpp index 4e4d9dc391..2020449aaa 100644 --- a/ui/zenoedit/dock/docktabcontent.cpp +++ b/ui/zenoedit/dock/docktabcontent.cpp @@ -103,6 +103,42 @@ void ZToolRecordingButton::paintEvent(QPaintEvent *event) } #endif +ZTextIconButton::ZTextIconButton(const QString& text, QWidget* parent) + : QWidget(parent) + , m_pButton(new QPushButton(this)) + , m_pLablel(new QLabel(text, this)) + , m_shortcut(nullptr) +{ + setAttribute(Qt::WA_StyledBackground, true); + m_pButton->setCursor(Qt::PointingHandCursor); + m_pButton->setMaximumWidth(ZenoStyle::dpiScaled(24)); + m_pButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding)); + m_pLablel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + QHBoxLayout* pLayout = new QHBoxLayout(this); + pLayout->setMargin(0); + pLayout->addWidget(m_pLablel); + pLayout->addWidget(m_pButton); + connect(m_pButton, &QPushButton::clicked, this, &ZTextIconButton::clicked); +} + +ZTextIconButton::~ZTextIconButton() +{ +} + +void ZTextIconButton::setShortcut(QKeySequence text) +{ + if (!m_shortcut) + { + m_shortcut = new QShortcut(text, this); + connect(m_shortcut, &QShortcut::activated, this, &ZTextIconButton::clicked); + } + else + { + m_shortcut->setKey(text); + } +} + + const int DockToolbarWidget::sToolbarHeight = 28; @@ -267,7 +303,9 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout) pSearchBtn = new ZToolBarButton(true, ":/icons/toolbar_search_idle.svg", ":/icons/toolbar_search_light.svg"); pSettings = new ZToolBarButton(false, ":/icons/toolbar_localSetting_idle.svg", ":/icons/toolbar_localSetting_light.svg"); pLinkLineShape = new ZToolBarButton(true, ":/icons/timeline-curvemap.svg",":/icons/timeline-curvemap.svg"); - pAlways = new ZToolBarButton(true, ":/icons/Always.svg", ":/icons/AlwaysOn.svg"); + pAlways = new QCheckBox(tr("Auto"), this); + pAlways->setChecked(false); + pAlways->setProperty("cssClass", "AlwaysCheckBox"); pListView->setToolTip(tr("Subnet List")); pTreeView->setToolTip(tr("Node List")); @@ -284,37 +322,27 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout) m_btnRun->addAction(tr("Run"), ":/icons/run_all.svg"); m_btnRun->addAction(tr("RunLightCamera"), ":/icons/run_lightcamera.svg"); m_btnRun->addAction(tr("RunMaterial"), ":/icons/run_material.svg"); - m_btnKill = new ZToolButton; + m_btnKill = new ZTextIconButton(tr("Running..."), this); QFont fnt = QApplication::font(); - m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all.svg", - ":/icons/run_all.svg", "", "", ":/icons/run_all_disable.svg"); + m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all_btn.svg", + ":/icons/run_all_btn.svg", "", ""); m_btnRun->setRadius(ZenoStyle::dpiScaled(2)); m_btnRun->setFont(fnt); m_btnRun->setText(tr("Run")); m_btnRun->setCursor(QCursor(Qt::PointingHandCursor)); m_btnRun->setMargins(ZenoStyle::dpiScaledMargins(QMargins(11, 5, 14, 5))); - m_btnRun->setBackgroundClr(QColor("#4073B6"), QColor("#4073B6"), QColor("#4073B6"), QColor("#4073B6"), QColor("#4D5561")); + m_btnRun->setBackgroundClr(QColor("#1978E6"), QColor("#599EED"), QColor("#1978E6"), QColor("#1978E6")); m_btnRun->setTextClr(QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF")); ZenoSettingsManager &settings = ZenoSettingsManager::GetInstance(); m_btnRun->setShortcut(settings.getShortCut(ShortCut_Run)); m_btnRun->setCursor(QCursor(Qt::PointingHandCursor)); //kill - m_btnKill->setButtonOptions(ZToolButton::Opt_TextRightToIcon); - m_btnKill->setIcon(ZenoStyle::dpiScaledSize(QSize(14, 14)), ":/icons/timeline_kill_clean.svg", - ":/icons/timeline_kill_clean.svg", "", ""); - m_btnKill->setRadius(ZenoStyle::dpiScaled(2)); m_btnKill->setFont(fnt); - m_btnKill->setText(tr("Kill")); - m_btnKill->setCursor(QCursor(Qt::PointingHandCursor)); - m_btnKill->setMargins(ZenoStyle::dpiScaledMargins(QMargins(11, 5, 14, 5))); - m_btnKill->setBackgroundClr(QColor("#4578AC"), QColor("#4578AC"), QColor("#4578AC"), QColor("#4578AC"), QColor("#4D5561")); - m_btnKill->setTextClr(QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF")); m_btnKill->setShortcut(settings.getShortCut(ShortCut_Kill)); - m_btnKill->setCursor(QCursor(Qt::PointingHandCursor)); - m_btnKill->setEnabled(false); + m_btnKill->setVisible(false); QFontMetrics fontMetrics(fnt); @@ -369,7 +397,7 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout) pToolLayout->addWidget(pLinkLineShape); pToolLayout->addWidget(pAlways); - pToolLayout->addWidget(new ZLineWidget(false, QColor("#121416"))); + //pToolLayout->addWidget(new ZLineWidget(false, QColor("#121416"))); pToolLayout->addWidget(m_btnRun); pToolLayout->addWidget(m_btnKill); @@ -444,14 +472,14 @@ void DockContent_Editor::initConnections() ZenoMainWindow* pMainWin = zenoApp->getMainWindow(); ZASSERT_EXIT(pMainWin); std::function resetAlways = [=]() { - pAlways->toggle(false); + pAlways->setChecked(false); pMainWin->setAlways(false); pMainWin->setAlwaysLightCameraMaterial(false, false); }; connect(zenoApp->graphsManagment(), &GraphsManagment::fileOpened, this, resetAlways); connect(zenoApp->graphsManagment(), &GraphsManagment::modelInited, this, resetAlways); - connect(pAlways, &ZToolBarButton::toggled, this, [=](bool bChecked) { - if (bChecked) + connect(pAlways, &QCheckBox::toggled, this, [=](bool checked) { + if (checked) { QSettings settings(zsCompanyName, zsEditor); if (!settings.value("zencache-enable").toBool()) { @@ -506,8 +534,8 @@ void DockContent_Editor::initConnections() IGraphsModel* pGraphsModel = zenoApp->graphsManagment()->currentModel(); if (!pGraphsModel) return; - m_btnRun->setEnabled(false); - m_btnKill->setEnabled(true); + m_btnRun->setVisible(false); + m_btnKill->setVisible(true); std::shared_ptr mgr = zenoApp->cacheMgr(); ZASSERT_EXIT(mgr); ZenoMainWindow *pMainWin = zenoApp->getMainWindow(); @@ -548,33 +576,37 @@ void DockContent_Editor::initConnections() connect(m_btnRun, &ZToolMenuButton::textChanged, this, [=]() { if (pAlways->isChecked()) - emit pAlways->toggled(true); + pAlways->setChecked(false); QString text = m_btnRun->text(); QColor clr; + QColor hoverClr; if (text == tr("Run")) { - clr = QColor("#4073B6"); - m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all.svg", - ":/icons/run_all.svg", "", "", ":/icons/run_all_disable.svg"); + clr = QColor("#1978E6"); + hoverClr = QColor("#599EED"); + m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all_btn.svg", + ":/icons/run_all_btn.svg", "", ""); } else if (text == tr("RunLightCamera")) { - clr = QColor("#B66A40"); - m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_lightcamera.svg", - ":/icons/run_lightcamera.svg", "", "", ":/icons/run_lightcamera_disable.svg"); + clr = QColor("#E67B19"); + hoverClr = QColor("#EDA059"); + m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_lightcamera_btn.svg", + ":/icons/run_lightcamera_btn.svg", "", ""); } else if (text == tr("RunMaterial")) { - clr = QColor("#9740B6"); - m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_material.svg", - ":/icons/run_material.svg", "", "", ":/icons/run_material_disable.svg"); + clr = QColor("#BD19E6"); + hoverClr = QColor("#CF59ED"); + m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_material_btn.svg", + ":/icons/run_material_btn.svg", "", ""); } - m_btnRun->setBackgroundClr(clr, clr, clr, clr); + m_btnRun->setBackgroundClr(clr, hoverClr, clr, clr); }); - connect(m_btnKill, &ZToolButton::clicked, this, [=]() { + connect(m_btnKill, &ZTextIconButton::clicked, this, [=]() { killProgram(); - m_btnRun->setEnabled(true); - m_btnKill->setEnabled(false); + m_btnRun->setVisible(true); + m_btnKill->setVisible(false); }); connect(&ZenoSettingsManager::GetInstance(), &ZenoSettingsManager::valueChanged, this, [=](QString name) { @@ -602,6 +634,14 @@ void DockContent_Editor::initConnections() m_btnKill->setShortcut(ZenoSettingsManager::GetInstance().getShortCut(ShortCut_Kill)); } }); + + connect(pGraphsMgm, &GraphsManagment::modelDataChanged, this, [=]() { + if (pAlways->isChecked()) + { + m_btnRun->setVisible(false); + m_btnKill->setVisible(true); + } + }); } ZenoGraphsEditor* DockContent_Editor::getEditor() const @@ -611,8 +651,8 @@ ZenoGraphsEditor* DockContent_Editor::getEditor() const void DockContent_Editor::runFinished() { - m_btnRun->setEnabled(true); - m_btnKill->setEnabled(false); + m_btnRun->setVisible(true); + m_btnKill->setVisible(false); } void DockContent_Editor::onCommandDispatched(QAction* pAction, bool bTriggered) diff --git a/ui/zenoedit/dock/docktabcontent.h b/ui/zenoedit/dock/docktabcontent.h index dfb99d7527..19a294001d 100644 --- a/ui/zenoedit/dock/docktabcontent.h +++ b/ui/zenoedit/dock/docktabcontent.h @@ -35,6 +35,22 @@ class ZToolRecordingButton : public ZToolButton { #endif +class ZTextIconButton : public QWidget +{ + Q_OBJECT +public: + ZTextIconButton(const QString &text, QWidget *parent = nullptr); + ~ZTextIconButton(); + void setShortcut(QKeySequence text); +signals: + void clicked(); + +private: + QPushButton* m_pButton; + QLabel* m_pLablel; + QShortcut* m_shortcut; +}; + class DockToolbarWidget : public QWidget { Q_OBJECT @@ -98,12 +114,12 @@ class DockContent_Editor : public DockToolbarWidget ZToolBarButton *pCustomParam; ZToolBarButton *pGroup; ZToolBarButton *pLinkLineShape; - ZToolBarButton *pAlways; + QCheckBox*pAlways; ZToolBarButton *pSearchBtn; ZToolBarButton *pSettings; ZToolMenuButton *m_btnRun; - ZToolButton* m_btnKill; + ZTextIconButton* m_btnKill; QComboBox* cbZoom; }; diff --git a/ui/zenoedit/res/icons.qrc b/ui/zenoedit/res/icons.qrc index 36d75be084..66cb8b9b2a 100644 --- a/ui/zenoedit/res/icons.qrc +++ b/ui/zenoedit/res/icons.qrc @@ -351,12 +351,16 @@ icons/ZENO-logo64.png icons/update_main.png icons/update-reboot.png + icons/run_all_btn.svg + icons/run_lightcamera_btn.svg + icons/run_material_btn.svg icons/run_all.svg icons/run_lightcamera.svg icons/run_material.svg icons/down_arrow.svg - icons/run_lightcamera_disable.svg - icons/run_material_disable.svg - icons/run_all_disable.svg + icons/RunKill.svg + icons/RunKill_on.svg + icons/always_checkbox.svg + icons/always_checkbox_on.svg diff --git a/ui/zenoedit/res/icons/RunKill.svg b/ui/zenoedit/res/icons/RunKill.svg new file mode 100644 index 0000000000..96ff69a2d5 --- /dev/null +++ b/ui/zenoedit/res/icons/RunKill.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/ui/zenoedit/res/icons/RunKill_on.svg b/ui/zenoedit/res/icons/RunKill_on.svg new file mode 100644 index 0000000000..a794b6978f --- /dev/null +++ b/ui/zenoedit/res/icons/RunKill_on.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/ui/zenoedit/res/icons/always_checkbox.svg b/ui/zenoedit/res/icons/always_checkbox.svg new file mode 100644 index 0000000000..f98b6895c2 --- /dev/null +++ b/ui/zenoedit/res/icons/always_checkbox.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ui/zenoedit/res/icons/always_checkbox_on.svg b/ui/zenoedit/res/icons/always_checkbox_on.svg new file mode 100644 index 0000000000..d81e2c7da2 --- /dev/null +++ b/ui/zenoedit/res/icons/always_checkbox_on.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ui/zenoedit/res/icons/run_all.svg b/ui/zenoedit/res/icons/run_all.svg index 6518128617..50c50c9856 100644 --- a/ui/zenoedit/res/icons/run_all.svg +++ b/ui/zenoedit/res/icons/run_all.svg @@ -1,5 +1,4 @@ - - - + + + - diff --git a/ui/zenoedit/res/icons/run_all_btn.svg b/ui/zenoedit/res/icons/run_all_btn.svg new file mode 100644 index 0000000000..9ec193e50f --- /dev/null +++ b/ui/zenoedit/res/icons/run_all_btn.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ui/zenoedit/res/icons/run_all_disable.svg b/ui/zenoedit/res/icons/run_all_disable.svg deleted file mode 100644 index 21a767258f..0000000000 --- a/ui/zenoedit/res/icons/run_all_disable.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/ui/zenoedit/res/icons/run_lightcamera.svg b/ui/zenoedit/res/icons/run_lightcamera.svg index 075a45fdb0..9e232983bb 100644 --- a/ui/zenoedit/res/icons/run_lightcamera.svg +++ b/ui/zenoedit/res/icons/run_lightcamera.svg @@ -1,4 +1,4 @@ - - - + + + diff --git a/ui/zenoedit/res/icons/run_lightcamera_btn.svg b/ui/zenoedit/res/icons/run_lightcamera_btn.svg new file mode 100644 index 0000000000..83da36a8fb --- /dev/null +++ b/ui/zenoedit/res/icons/run_lightcamera_btn.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ui/zenoedit/res/icons/run_lightcamera_disable.svg b/ui/zenoedit/res/icons/run_lightcamera_disable.svg deleted file mode 100644 index f3ddd6e2f1..0000000000 --- a/ui/zenoedit/res/icons/run_lightcamera_disable.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/ui/zenoedit/res/icons/run_material.svg b/ui/zenoedit/res/icons/run_material.svg index 0c6090dcb7..5ba6a7d177 100644 --- a/ui/zenoedit/res/icons/run_material.svg +++ b/ui/zenoedit/res/icons/run_material.svg @@ -1,4 +1,4 @@ - - - + + + diff --git a/ui/zenoedit/res/icons/run_material_btn.svg b/ui/zenoedit/res/icons/run_material_btn.svg new file mode 100644 index 0000000000..be2758eb48 --- /dev/null +++ b/ui/zenoedit/res/icons/run_material_btn.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ui/zenoedit/res/icons/run_material_disable.svg b/ui/zenoedit/res/icons/run_material_disable.svg deleted file mode 100644 index 021d42d483..0000000000 --- a/ui/zenoedit/res/icons/run_material_disable.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/ui/zenoedit/res/stylesheet/checkbox.qss b/ui/zenoedit/res/stylesheet/checkbox.qss index 0c360c01ab..dc69672030 100644 --- a/ui/zenoedit/res/stylesheet/checkbox.qss +++ b/ui/zenoedit/res/stylesheet/checkbox.qss @@ -30,4 +30,34 @@ QCheckBox[cssClass = "curve-timeline"]::indicator:unchecked { QCheckBox[cssClass = "curve-timeline"]::indicator:checked { image: url(:/icons/checkbox_checked_normal.svg); +} + +QCheckBox[cssClass = "AlwaysCheckBox"] +{ + background-color:#465363; + color:#FFFFFF; + border-radius: 2px; + padding:2px 8px; +} + +QCheckBox[cssClass = "AlwaysCheckBox"]:hover +{ + background-color:#617389; + color:#FFFFFF; +} + +QCheckBox[cssClass = "AlwaysCheckBox"]::indicator +{ + width:16px; + height:16px; +} + +QCheckBox[cssClass = "AlwaysCheckBox"]::indicator:checked +{ + image: url(:/icons/always_checkbox_on.svg); +} + +QCheckBox[cssClass = "AlwaysCheckBox"]::indicator:unchecked +{ + image: url(:/icons/always_checkbox.svg); } \ No newline at end of file diff --git a/ui/zenoedit/res/stylesheet/menu.qss b/ui/zenoedit/res/stylesheet/menu.qss index aafe77f293..c0fd640949 100644 --- a/ui/zenoedit/res/stylesheet/menu.qss +++ b/ui/zenoedit/res/stylesheet/menu.qss @@ -42,6 +42,10 @@ QMenu[cssClass="menuButton"]::item:selected { color: #FFFFFF; } +QMenu[cssClass="menuButton"]::item { + padding: 2px 28px 2px 5px; +} + QMenuBar { background-color: #191D21; spacing: 3px; diff --git a/ui/zenoedit/res/stylesheet/pushbutton.qss b/ui/zenoedit/res/stylesheet/pushbutton.qss index 6c36fd5f90..890595cdcd 100644 --- a/ui/zenoedit/res/stylesheet/pushbutton.qss +++ b/ui/zenoedit/res/stylesheet/pushbutton.qss @@ -351,4 +351,38 @@ QPushButton#closebtn QPushButton#closebtn:hover { border-image: url(:/icons/closebtn_on.svg); +} + +ZTextIconButton +{ + border-radius: 2px; + background-color:#465363; + border:0; +} + +ZTextIconButton:hover +{ + background-color:#667890; +} + + +ZTextIconButton QPushButton +{ + border-image: url(:/icons/RunKill.svg); + background-color: transparent; + border-top-right-radius:2px; + border-bottom-right-radius:2px; + border:0; +} + +ZTextIconButton QPushButton:hover +{ + border-image: url(:/icons/RunKill_on.svg); +} + +ZTextIconButton QLabel +{ + color:#FFFFFF; + padding:0px 10px; + background-color: transparent; } \ No newline at end of file diff --git a/ui/zenoui/comctrl/ztoolbutton.cpp b/ui/zenoui/comctrl/ztoolbutton.cpp index 9b64e19fcf..0f3bd2b008 100644 --- a/ui/zenoui/comctrl/ztoolbutton.cpp +++ b/ui/zenoui/comctrl/ztoolbutton.cpp @@ -194,7 +194,6 @@ void ZToolButton::initStyleOption(ZStyleOptionToolButton* option) const if (isHovered()) { option->state |= QStyle::State_MouseOver; - option->borderColor = m_clrBorder; } option->state |= QStyle::State_AutoRaise; @@ -349,11 +348,6 @@ void ZToolButton::setArrowOption(int arrOpt ) { m_arrowOption = arrOpt; } -void ZToolButton::setBorderColor(const QColor& clr) -{ - m_clrBorder = clr; -} - void ZToolButton::setIconSize(const QSize& size) { m_iconSize = size; diff --git a/ui/zenoui/comctrl/ztoolbutton.h b/ui/zenoui/comctrl/ztoolbutton.h index b8c9f461a8..5e6dc35644 100644 --- a/ui/zenoui/comctrl/ztoolbutton.h +++ b/ui/zenoui/comctrl/ztoolbutton.h @@ -71,7 +71,6 @@ class ZToolButton : public QWidget void setFont(const QFont& font); void initAnimation(); void setArrowOption(int arrOpt); - void setBorderColor(const QColor &clr); public slots: void setText(const QString& text); @@ -125,7 +124,6 @@ public slots: QColor m_clrBgDisabled; QColor m_clrText, m_clrTextHover, m_clrTextOn, m_clrTextOnHover; - QColor m_clrBorder; int m_radius; int m_options; diff --git a/ui/zenoui/comctrl/ztoolmenubutton.cpp b/ui/zenoui/comctrl/ztoolmenubutton.cpp index 850e3fb4db..91e445eb00 100644 --- a/ui/zenoui/comctrl/ztoolmenubutton.cpp +++ b/ui/zenoui/comctrl/ztoolmenubutton.cpp @@ -2,14 +2,44 @@ #include "../style/zstyleoption.h" #include "../style/zenostyle.h" +CustomIconStyle::CustomIconStyle() +{ + mSize = 30; +} + +CustomIconStyle::~CustomIconStyle() +{ + +} + + +void CustomIconStyle::SetCustomSize(int nSize) +{ + mSize = nSize; +} + +int CustomIconStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const +{ + int s = QCommonStyle::pixelMetric(metric, option, widget); + if (metric == QStyle::PM_SmallIconSize) { + s = mSize; + } + + return s; + +} + + ZToolMenuButton::ZToolMenuButton(QWidget* parent) : ZToolButton(parent) { setButtonOptions(ZToolButton::Opt_TextRightToIcon); setArrowOption(ZStyleOptionToolButton::DOWNARROW); - setBorderColor(QColor(255,255,255,102)); m_pMenu = new QMenu(this); m_pMenu->setProperty("cssClass", "menuButton"); + CustomIconStyle* pStyle = new CustomIconStyle; + pStyle->SetCustomSize(ZenoStyle::dpiScaled(24)); + m_pMenu->setStyle(pStyle); } void ZToolMenuButton::addAction(const QString& action, const QString& icon) diff --git a/ui/zenoui/comctrl/ztoolmenubutton.h b/ui/zenoui/comctrl/ztoolmenubutton.h index d170bbc5e2..069e83132c 100644 --- a/ui/zenoui/comctrl/ztoolmenubutton.h +++ b/ui/zenoui/comctrl/ztoolmenubutton.h @@ -6,6 +6,23 @@ class ZStyleOptionToolButton; #include #include "ztoolbutton.h" +class CustomIconStyle : public QProxyStyle +{ + Q_OBJECT + +public: + CustomIconStyle(); + ~CustomIconStyle(); + + void SetCustomSize(int); +protected: + virtual int pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const; + +private: + int mSize; +}; + + class ZToolMenuButton : public ZToolButton { Q_OBJECT public: diff --git a/ui/zenoui/style/zenostyle.cpp b/ui/zenoui/style/zenostyle.cpp index 6e3cd1c1bc..fc9dff6501 100644 --- a/ui/zenoui/style/zenostyle.cpp +++ b/ui/zenoui/style/zenostyle.cpp @@ -533,14 +533,6 @@ void ZenoStyle::drawZenoToolButton(const ZStyleOptionToolButton* option, QPainte //todo } } - - //draw border - if (option->borderColor.isValid()) - { - painter->setPen(option->borderColor); - QRect rect = option->rect.adjusted(0, 0, -1, -1); - painter->drawRoundedRect(rect, option->bgRadius, option->bgRadius); - } } void ZenoStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const diff --git a/ui/zenoui/style/zstyleoption.h b/ui/zenoui/style/zstyleoption.h index 90167b548f..7055bf391c 100644 --- a/ui/zenoui/style/zstyleoption.h +++ b/ui/zenoui/style/zstyleoption.h @@ -34,7 +34,6 @@ class ZStyleOptionToolButton : public QStyleOptionToolButton QColor textColor; QColor textHoverColor; QColor textDownColor; - QColor borderColor; QColor borderInColor; QColor hoveredBgColor; QColor selectedBgColor; From ddfc2800bad52a57462c1e94b6cc325f687a17fa Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Fri, 20 Oct 2023 17:50:29 +0800 Subject: [PATCH 09/14] cursor info --- ui/zenoedit/panel/zenoimagepanel.cpp | 33 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/ui/zenoedit/panel/zenoimagepanel.cpp b/ui/zenoedit/panel/zenoimagepanel.cpp index a02515eecd..3d66974a54 100644 --- a/ui/zenoedit/panel/zenoimagepanel.cpp +++ b/ui/zenoedit/panel/zenoimagepanel.cpp @@ -242,17 +242,30 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { int height = ud.get2("h"); int w = int(zeno::clamp(x, 0, width - 1)); int h = int(zeno::clamp(y, 0, height - 1)); - int i = h * width + w; + int i = (height - 1 - h) * width + w; auto c = obj->verts[i]; - QString statusInfo = QString(zeno::format("width: {}, height: {} | ({}, {}) : ({}, {}, {})" - , width - , height - , w - , h - , c[0] - , c[1] - , c[2] - ).c_str()); + std::string info = zeno::format("width: {}, height: {}", width, height); + info += zeno::format(" | x: {}, y: {}", w, h); + if (pMode->currentText() == "RGB") { + info += zeno::format(" | value: {}, {}, {}", c[0], c[1], c[2]); + } + else if (pMode->currentText() == "Red") { + info += zeno::format(" | value: {}", c[0]); + } + else if (pMode->currentText() == "Green") { + info += zeno::format(" | value: {}", c[1]); + } + else if (pMode->currentText() == "Blue") { + info += zeno::format(" | value: {}", c[2]); + } + else if (pMode->currentText() == "Alpha") { + if (obj->verts.has_attr("alpha")) { + auto &alpha = obj->verts.attr("alpha"); + info += zeno::format(" | value: {}", alpha[i]); + } + } + + QString statusInfo = QString(info.c_str()); pStatusBar->setText(statusInfo); } } From 4a06826b8f83adaf47310fbb7d95398dd37732bb Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Fri, 20 Oct 2023 17:51:12 +0800 Subject: [PATCH 10/14] fix bug about transforming timeline position to frame number --- ui/zenoedit/timeline/zslider.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/zenoedit/timeline/zslider.cpp b/ui/zenoedit/timeline/zslider.cpp index 13f57490fd..1c4bfbb75c 100644 --- a/ui/zenoedit/timeline/zslider.cpp +++ b/ui/zenoedit/timeline/zslider.cpp @@ -61,8 +61,9 @@ void ZSlider::setSliderValue(int value) int ZSlider::_posToFrame(int x) { int W = width(); - qreal rate = (qreal)(x + 5 - m_sHMargin) / (W - 2 * m_sHMargin); - return rate * (m_to - m_from + 1) + m_from; + qreal distPerFrame = (qreal)(width() - 2 * m_sHMargin) / ((m_to - m_from) == 0 ? 1 : (m_to - m_from)); + qreal rate = (qreal)(x + distPerFrame / 2 - m_sHMargin) / (W - 2 * m_sHMargin); + return rate * (m_to - m_from) + m_from; } int ZSlider::_frameToPos(int frame) From 377771a03d6f075c6a8c072eb5a66e633d954e0d Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Fri, 20 Oct 2023 18:10:09 +0800 Subject: [PATCH 11/14] info rgba --- ui/zenoedit/panel/zenoimagepanel.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/ui/zenoedit/panel/zenoimagepanel.cpp b/ui/zenoedit/panel/zenoimagepanel.cpp index 3d66974a54..b2df705142 100644 --- a/ui/zenoedit/panel/zenoimagepanel.cpp +++ b/ui/zenoedit/panel/zenoimagepanel.cpp @@ -245,24 +245,13 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { int i = (height - 1 - h) * width + w; auto c = obj->verts[i]; std::string info = zeno::format("width: {}, height: {}", width, height); - info += zeno::format(" | x: {}, y: {}", w, h); - if (pMode->currentText() == "RGB") { - info += zeno::format(" | value: {}, {}, {}", c[0], c[1], c[2]); + info += zeno::format(" | x: {:5}, y: {:5}", w, h); + if (obj->verts.has_attr("alpha")) { + auto &alpha = obj->verts.attr("alpha"); + info += zeno::format(" | value: {:6f}, {:6f}, {:6f}, {:6f}", c[0], c[1], c[2], alpha[i]); } - else if (pMode->currentText() == "Red") { - info += zeno::format(" | value: {}", c[0]); - } - else if (pMode->currentText() == "Green") { - info += zeno::format(" | value: {}", c[1]); - } - else if (pMode->currentText() == "Blue") { - info += zeno::format(" | value: {}", c[2]); - } - else if (pMode->currentText() == "Alpha") { - if (obj->verts.has_attr("alpha")) { - auto &alpha = obj->verts.attr("alpha"); - info += zeno::format(" | value: {}", alpha[i]); - } + else { + info += zeno::format(" | value: {:6f}, {:6f}, {:6f}", c[0], c[1], c[2]); } QString statusInfo = QString(info.c_str()); From 4fbf474472dd189ca0e431b09077ff7eae256c2d Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Tue, 24 Oct 2023 12:25:10 +0800 Subject: [PATCH 12/14] envmaprot --- zeno/src/nodes/prim/UVProjectFromPlane.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/zeno/src/nodes/prim/UVProjectFromPlane.cpp b/zeno/src/nodes/prim/UVProjectFromPlane.cpp index 37d5424bcd..4f5f98bfb5 100644 --- a/zeno/src/nodes/prim/UVProjectFromPlane.cpp +++ b/zeno/src/nodes/prim/UVProjectFromPlane.cpp @@ -694,4 +694,50 @@ ZENDEFNODE(ImageFloatGaussianBlur, { {}, {"comp"}, }); + +struct EnvMapRot : INode { + virtual void apply() override { + auto path = get_input2("path"); + auto img = readImageFile(path); + int h = img->userData().get2("h"); + int w = img->userData().get2("w"); + int maxi = 0; + + float maxv = zeno::dot(img->verts[0], zeno::vec3f(0.33, 0.33, 0.33)); + for (auto i = 1; i < img->size(); i++) { + float value = zeno::dot(img->verts[i], zeno::vec3f(0.33, 0.33, 0.33)); + if (value > maxv) { + maxi = i; + maxv = value; + } + } + int x = maxi % w; + int y = h - 1 - maxi / w; + + float rot_phi = x / float(w) * 360 + 180; + set_output2("rotation", rot_phi); + + float rot_theta = y / float(h - 1) * 180; + + auto dir = get_input2("dir"); + dir = zeno::normalize(dir); + auto to_rot_theta = glm::degrees(acos(dir[1])); + auto diff_rot_theta = to_rot_theta - rot_theta; + + float rot_phi2 = glm::degrees(atan2(dir[2], dir[0])); + set_output2("rotation3d", vec3f(0, -rot_phi2, diff_rot_theta)); + } +}; +ZENDEFNODE(EnvMapRot, { + { + {"readpath", "path", ""}, + {"vec3f", "dir", "1, 1, 1"}, + }, + { + {"float", "rotation"}, + {"vec3f", "rotation3d"}, + }, + {}, + {"comp"}, +}); } From f1a27892afa64ed2f77f8439e834f355760f1b9a Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Tue, 24 Oct 2023 13:15:43 +0800 Subject: [PATCH 13/14] improve image panel --- ui/zenoedit/panel/zenoimagepanel.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/zenoedit/panel/zenoimagepanel.cpp b/ui/zenoedit/panel/zenoimagepanel.cpp index b2df705142..330bd654fa 100644 --- a/ui/zenoedit/panel/zenoimagepanel.cpp +++ b/ui/zenoedit/panel/zenoimagepanel.cpp @@ -59,6 +59,12 @@ void ZenoImagePanel::setPrim(std::string primid) { if (image_view) { if (pMode->currentText() != "Alpha") { QImage img(width, height, QImage::Format_RGB32); + auto index = std::map{ + {"RGB", {0, 1, 2}}, + {"Red", {0, 0, 0}}, + {"Green", {1, 1, 1}}, + {"Blue", {2, 2, 2}}, + }.at(pMode->currentText()); for (auto i = 0; i < obj->verts.size(); i++) { int h = i / width; int w = i % width; @@ -66,12 +72,6 @@ void ZenoImagePanel::setPrim(std::string primid) { if (enableGamma) { c = zeno::pow(c, 1.0f / 2.2f); } - auto index = std::map{ - {"RGB", {0, 1, 2}}, - {"Red", {0, 0, 0}}, - {"Green", {1, 1, 1}}, - {"Blue", {2, 2, 2}}, - }.at(pMode->currentText()); int r = glm::clamp(int(c[index[0]] * 255.99), 0, 255); int g = glm::clamp(int(c[index[1]] * 255.99), 0, 255); int b = glm::clamp(int(c[index[2]] * 255.99), 0, 255); From c436aad3c447603745a3fa032836eb2a93b4f8db Mon Sep 17 00:00:00 2001 From: iaomw Date: Tue, 24 Oct 2023 19:22:27 +0800 Subject: [PATCH 14/14] Sphere UV improvement --- zenovis/xinxinoptix/DeflMatShader.cu | 12 ++---------- zenovis/xinxinoptix/Light.cu | 8 -------- zenovis/xinxinoptix/Sampling.h | 11 +++++++++++ zenovis/xinxinoptix/proceduralSky.h | 18 ++++++++++-------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/zenovis/xinxinoptix/DeflMatShader.cu b/zenovis/xinxinoptix/DeflMatShader.cu index 8a9f79413d..f765674a32 100644 --- a/zenovis/xinxinoptix/DeflMatShader.cu +++ b/zenovis/xinxinoptix/DeflMatShader.cu @@ -184,14 +184,6 @@ static __inline__ __device__ bool isBadVector(float3& vector) { return isBadVector(tmp); } -static __inline__ __device__ float3 sphereUV(float3 &direction) { - - return float3 { - atan2(direction.x, direction.z) / (2.0f*M_PIf) + 0.5f, - direction.y * 0.5f + 0.5f, 0.0f - }; -} - extern "C" __global__ void __anyhit__shadow_cutout() { @@ -234,7 +226,7 @@ extern "C" __global__ void __anyhit__shadow_cutout() attrs.pos = P; attrs.nrm = N; - attrs.uv = sphereUV(_normal_object_); + attrs.uv = sphereUV(_normal_object_, false); attrs.clr = {}; attrs.tang = {}; @@ -505,7 +497,7 @@ extern "C" __global__ void __closesthit__radiance() attrs.pos = P; attrs.nrm = N; - attrs.uv = sphereUV(_normal_object_); + attrs.uv = sphereUV(_normal_object_, false); attrs.clr = {}; attrs.tang = {}; diff --git a/zenovis/xinxinoptix/Light.cu b/zenovis/xinxinoptix/Light.cu index 4e1b542789..edbf61c832 100644 --- a/zenovis/xinxinoptix/Light.cu +++ b/zenovis/xinxinoptix/Light.cu @@ -21,14 +21,6 @@ static __inline__ __device__ void evalSurface(float4* uniforms) { //GENERATED_BEGIN_MARK //GENERATED_END_MARK -} - -static __inline__ __device__ float3 sphereUV(float3 &direction) { - - return float3 { - atan2(direction.x, direction.z) / (2.0f*M_PIf) + 0.5f, - direction.y * 0.5f + 0.5f, 0.0f - }; } static __inline__ __device__ bool checkLightGAS(uint instanceId) { diff --git a/zenovis/xinxinoptix/Sampling.h b/zenovis/xinxinoptix/Sampling.h index 76358988a7..33eb6ca7d7 100644 --- a/zenovis/xinxinoptix/Sampling.h +++ b/zenovis/xinxinoptix/Sampling.h @@ -137,6 +137,17 @@ namespace rtgems { } } +static __host__ __device__ __inline__ float3 sphereUV(const float3 &dir, bool internal) { +//https://en.wikipedia.org/wiki/UV_mapping + + auto x = internal? dir.x:-dir.x; + + auto u = 0.5f + atan2f(dir.z, x) * 0.5f / M_PIf; + auto v = 0.5f + asinf(dir.y) / M_PIf; + + return float3 {u, v, 0.0f}; +} + // *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org // Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) diff --git a/zenovis/xinxinoptix/proceduralSky.h b/zenovis/xinxinoptix/proceduralSky.h index 80e5b6395f..47dd61b9f2 100644 --- a/zenovis/xinxinoptix/proceduralSky.h +++ b/zenovis/xinxinoptix/proceduralSky.h @@ -1,4 +1,5 @@ #pragma once +#include "Sampling.h" #include "zxxglslvec.h" #include "TraceStuff.h" @@ -304,8 +305,8 @@ static __inline__ __device__ vec3 hdrSky2( .rotX(to_radians(params.sky_rot_x)) .rotZ(to_radians(params.sky_rot_z)) .rotY(to_radians(params.sky_rot)); - float u = atan2(dir.z, dir.x) / 3.1415926f * 0.5f + 0.5f; - float v = asin(dir.y) / 3.1415926f + 0.5f; + + vec3 uv = sphereUV(dir, true); vec3 col = vec3(0); for(int jj=-2;jj<=2;jj++) { @@ -313,7 +314,7 @@ static __inline__ __device__ vec3 hdrSky2( { float dx = (float)ii / (float)(params.skynx); float dy = (float)jj / (float)(params.skyny); - col = col + (vec3)texture2D(params.sky_texture, vec2(u + dx, v + dy)) * params.sky_strength; + col = col + (vec3)texture2D(params.sky_texture, vec2(uv[0] + dx, uv[1] + dy)) * params.sky_strength; } } @@ -328,12 +329,13 @@ static __inline__ __device__ vec3 hdrSky( .rotX(to_radians(params.sky_rot_x)) .rotZ(to_radians(params.sky_rot_z)) .rotY(to_radians(params.sky_rot)); - float u = atan2(dir.z, dir.x) / 3.1415926f * 0.5f + 0.5f; - float v = asin(dir.y) / 3.1415926f + 0.5f; - vec3 col = (vec3)texture2D(params.sky_texture, vec2(u, v)) * params.sky_strength; + + vec3 uv = sphereUV(dir, true); + + vec3 col = (vec3)texture2D(params.sky_texture, vec2(uv[0], uv[1])) * params.sky_strength; vec3 col2 = clamp(col, vec3(0.0f), vec3(upperBound)); - int i = u * params.skynx; - int j = v * params.skyny; + int i = uv[0] * params.skynx; + int j = uv[1] * params.skyny; //float p = params.skycdf[params.skynx * params.skyny + j * params.skynx + i]; pdf = luminance(col) / params.envavg / (2.0f * M_PIf * M_PIf); return mix(col, col2, isclamp);