@@ -566,7 +566,6 @@ void Drawer::traverse_and_collect(const Key& key, std::vector<Node*>& visible_oc
566
566
}
567
567
}
568
568
569
-
570
569
void Drawer::query_rendered_point ()
571
570
{
572
571
pp.clear ();
@@ -584,187 +583,3 @@ void Drawer::setPointSize(float size)
584
583
{
585
584
if (size > 0 ) this ->point_size = size;
586
585
}
587
-
588
-
589
- /* if (postprod)
590
- {
591
- std::vector<unsigned char> pixelData(width * height * 4); // Assuming RGBA
592
- glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
593
-
594
- // Step 3: Identify and fill holes
595
- int maxIterations = 5; // Number of passes to make
596
- for (int iter = 0; iter < maxIterations; ++iter) {
597
- for (int y = WS; y < height - WS; ++y) {
598
- for (int x = WS; x < width - WS; ++x) {
599
- int index = (y * width + x) * 4;
600
- if (isBackgroundPixel(pixelData[index], pixelData[index + 1], pixelData[index + 2], pixelData[index + 3]))
601
- {
602
- //pixelData[index] = 0; pixelData[index + 1] = 255; pixelData[index + 2] = 0;
603
- if (hasSurroundingForegroundPixels(pixelData, x, y, width)) {
604
- //pixelData[index] = 255; pixelData[index + 1] = 255; pixelData[index + 2] = 255;
605
- fillHole(pixelData, x, y, width);
606
- }
607
- }
608
- }
609
- }
610
- }
611
-
612
- glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
613
- }*/
614
-
615
-
616
- // depth-buffer edge detection
617
- /* std::vector< GLfloat > depth( width * height, 0 );
618
- glReadPixels( 0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, &depth[0] );
619
-
620
- // Linearize depth and convert to unsigned byte
621
- std::vector<GLubyte> depthImage(width * height);
622
- for (size_t i = 0; i < depth.size(); ++i) {
623
- float linearDepth = (2.0f * zNear) / (zFar + zNear - depth[i] * (zFar - zNear));
624
- depthImage[i] = static_cast<GLubyte>(linearDepth * 255.0f); // Map to [0, 255]
625
- }
626
-
627
- int Gx[3][3] = {
628
- {-1, 0, 1},
629
- {-2, 0, 2},
630
- {-1, 0, 1}
631
- };
632
-
633
- int Gy[3][3] = {
634
- {-1, -2, -1},
635
- { 0, 0, 0},
636
- { 1, 2, 1}
637
- };
638
-
639
- std::vector<GLubyte> edgeImage(width * height, 0);
640
-
641
- for (int y = 1; y < height - 1; ++y) {
642
- for (int x = 1; x < width - 1; ++x) {
643
- float gx = 0.0f;
644
- float gy = 0.0f;
645
-
646
- for (int i = -1; i <= 1; ++i) {
647
- for (int j = -1; j <= 1; ++j) {
648
- gx += Gx[i + 1][j + 1] * depthImage[(y + i) * width + (x + j)];
649
- gy += Gy[i + 1][j + 1] * depthImage[(y + i) * width + (x + j)];
650
- }
651
- }
652
-
653
- float gradient = sqrt(gx * gx + gy * gy);
654
- edgeImage[y * width + x] = static_cast<GLubyte>(std::min(gradient, 255.0f)); // Clamp to [0, 255]
655
- }
656
- }
657
-
658
- // Step 4: Replace values >= 255 with 0
659
- for (size_t i = 0; i < edgeImage.size(); ++i) {
660
- if (edgeImage[i] >= 220) {
661
- edgeImage[i] = 0;
662
- }
663
- }
664
-
665
- // Step 5: Find the new maximum value
666
- GLubyte newMaxValue = 0;
667
- for (size_t i = 0; i < edgeImage.size(); ++i) {
668
- if (edgeImage[i] > newMaxValue) {
669
- newMaxValue = edgeImage[i];
670
- }
671
- }
672
-
673
- // Step 6: Rescale the image to the range [0, 255]
674
- if (newMaxValue > 0) { // Avoid division by zero
675
- for (size_t i = 0; i < edgeImage.size(); ++i) {
676
- edgeImage[i] = static_cast<GLubyte>((edgeImage[i] * 255.0f) / newMaxValue);
677
- }
678
- }
679
-
680
- // Step 7: Create the shadow image
681
- std::vector<GLubyte> shadowImage(width * height * 4, 0); // Initialize as white with full alpha
682
-
683
- for (int y = 0; y < height; ++y) {
684
- for (int x = 0; x < width; ++x) {
685
- size_t index = y * width + x;
686
- if (edgeImage[index] == 0) {
687
- // Set to black with some alpha value (e.g., 128 for semi-transparency)
688
- shadowImage[index * 4 + 0] = 0;
689
- shadowImage[index * 4 + 1] = 0;
690
- shadowImage[index * 4 + 2] = 0;
691
- shadowImage[index * 4 + 3] = 128; // Alpha value (0-255, where 0 is fully transparent and 255 is fully opaque)
692
- }
693
- }
694
- }
695
-
696
- // Step 8: Enable blending and set blend function
697
- glEnable(GL_BLEND);
698
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
699
-
700
- // Step 9: Render the shadow image
701
- glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, shadowImage.data());
702
- */
703
-
704
- /*
705
- * #define WS 5
706
-
707
- bool isBackgroundPixel(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
708
- // Define what you consider as a background pixel.
709
- // Example: A black pixel with full transparency.
710
- return (r < 200 && g < 200 && b < 200);
711
- }
712
-
713
- bool hasSurroundingForegroundPixels(const std::vector<unsigned char>& pixelData, int x, int y, int width) {
714
- int offsets[] = {-WS, 0, WS}; // To iterate over neighboring pixels
715
- int n = 0;
716
- for (int dy : offsets) {
717
- for (int dx : offsets) {
718
- if (dx == 0 && dy == 0) continue; // Skip the center pixel itself
719
-
720
- int neighborIndex = ((y + dy) * width + (x + dx)) * 4; // Calculate neighbor's index in the array
721
- unsigned char r = pixelData[neighborIndex];
722
- unsigned char g = pixelData[neighborIndex + 1];
723
- unsigned char b = pixelData[neighborIndex + 2];
724
- unsigned char a = pixelData[neighborIndex + 3];
725
-
726
- if (!isBackgroundPixel(r, g, b, a)) {
727
- n++;
728
- }
729
- }
730
- }
731
- if (n >= 8) return true;
732
- return false; // No foreground pixels around
733
- }
734
-
735
- void fillHole(std::vector<unsigned char>& pixelData, int x, int y, int width) {
736
- int offsets[] = {-WS, 0, WS}; // To iterate over neighboring pixels
737
- int rSum = 0, gSum = 0, bSum = 0, aSum = 0;
738
- int count = 0;
739
-
740
- // Calculate the sum of the colors of the surrounding foreground pixels
741
- for (int dy : offsets) {
742
- for (int dx : offsets) {
743
- if (dx == 0 && dy == 0) continue; // Skip the center pixel itself
744
-
745
- int neighborIndex = ((y + dy) * width + (x + dx)) * 4;
746
- unsigned char r = pixelData[neighborIndex];
747
- unsigned char g = pixelData[neighborIndex + 1];
748
- unsigned char b = pixelData[neighborIndex + 2];
749
- unsigned char a = pixelData[neighborIndex + 3];
750
-
751
- if (!isBackgroundPixel(r, g, b, a)) {
752
- rSum += r;
753
- gSum += g;
754
- bSum += b;
755
- aSum += a;
756
- count++;
757
- }
758
- }
759
- }
760
-
761
- // Avoid division by zero
762
- if (count > 0) {
763
- int index = (y * width + x) * 4;
764
- pixelData[index] = rSum / count;
765
- pixelData[index + 1] = gSum / count;
766
- pixelData[index + 2] = bSum / count;
767
- pixelData[index + 3] = aSum / count;
768
- }
769
- }*/
770
-
0 commit comments