Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Xrey274

Pages: [1] 2 3 ... 6
1
General / Re: Making Flood Fill Algorithm more efficient.
« on: March 01, 2020, 07:55:31 pm »
I have modified the function a bit, and it works(sometimes), but if all recursive directions are enabled is segfaults. If two of them are commented out while the rest are not, it works perfectly fine. Possibly connected with running out of memory?

void BucketTool::rgbFill(sf::Image& canvas_image, sf::Vector2i origin, sf::Color discriminator)
{
        if(canvas_image.getPixel(origin.x, origin.y) == discriminator)
        {
                if(!(origin.x < 0 || origin.x >= canvas_image.getSize().x || origin.y < 0 || origin.y >= canvas_image.getSize().y))
                {
                        //std::cout << origin.x << " " << origin.y << std::endl;
                        canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);

                        rgbFill(canvas_image, sf::Vector2i(origin.x + 1, origin.y), discriminator); //if two of there are commented out it works fine
                        rgbFill(canvas_image, sf::Vector2i(origin.x - 1, origin.y), discriminator);
                        rgbFill(canvas_image, sf::Vector2i(origin.x, origin.y + 1), discriminator);
                        rgbFill(canvas_image, sf::Vector2i(origin.x, origin.y - 1), discriminator);
                }
        }
}

2
General / Re: Making Flood Fill Algorithm more efficient.
« on: February 12, 2020, 09:28:47 pm »
Thanks for the input! Worth mentioning that the function called to save the image(also the second setPixel call) was actually there for testing and is not part of the code itself(commented out). Otherwise I agree completely. One question though - Is get/setPixel slower than directly modifying the pixel array?

3
General / Making Flood Fill Algorithm more efficient.
« on: February 12, 2020, 02:50:01 pm »
I am working on a Flood Fill Algorithm. Unfortunately I have been having performance issues with said algorithm. It hammers the CPU. It's constantly at 100%(or at least one of the cores is, since the app is single threaded). This is what I have come up with so far:

sf::Image BucketTool::rgbFill(sf::Image& canvas_image, sf::Vector2f origin, sf::Color discriminator)
{
        if(origin.x < 0 || origin.x >= canvas_image.getSize().x || origin.y < 0 || origin.y >= canvas_image.getSize().y)
        {
        return canvas_image;
        }

        if(canvas_image.getPixel(origin.x, origin.y) != discriminator)
        {
                return canvas_image;
        }

        canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);

        ///std::cout<<origin.x<<" "<<origin.y<<std::endl;

        rgbFill(canvas_image, sf::Vector2f(origin.x + 1, origin.y), discriminator);
        rgbFill(canvas_image, sf::Vector2f(origin.x - 1, origin.y), discriminator);
        rgbFill(canvas_image, sf::Vector2f(origin.x, origin.y + 1), discriminator);
        rgbFill(canvas_image, sf::Vector2f(origin.x, origin.y - 1), discriminator);

        canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);
        canvas_image.saveToFile("example.png");

        return canvas_image;
}

4
General / Re: Single line of code breaks program.
« on: October 03, 2019, 04:29:25 pm »
Yeah thanks for the links. I have figured out that the problem this whole time was applying antiAliasing to the renderTexture. Any ideas why that would happen?

    textureSettings.antialiasingLevel = texture.getMaximumAntialiasingLevel();

    texture.create(size.x, size.y, textureSettings);

5
General / Re: Single line of code breaks program.
« on: October 03, 2019, 03:49:23 pm »
May I ask what is the texture rect?

I don't think this is the case, as at line 11 in Resources.cpp I clearly define the size of the Canvas.

    canvas.setSize(sf::Vector2f(1408, 792));

Just found out that when I remove line 12 at Resources.cpp the artifacts are gone. That line applied the context settings(antialiasing 8). Now I have to find out why the Canvas doesn't show up at all.

6
General / Re: Single line of code breaks program.
« on: October 03, 2019, 01:32:30 pm »
I found out that Circle::isSelectingSize is causing a segmenationFault(for somereason) so I removed it and found out that the whole canvas is corrupted the world over. It not only static, but also random images I don't even have on my pc.

https://imgur.com/a/6ms95Ee

7
General / Re: Single line of code breaks program.
« on: October 03, 2019, 06:32:29 am »
Problem is that I am not doing any of those or nearly. Also the program is not crashing, the gui(from TGUI library) stops appearing along with the canvas(which is really just a class that inherits from sf::Sprite with a renderTexture inside it). It's almost as if the clear() command is repeadetly called. When I try to draw on the canvas things appear for a fraction of a section then disappear.

8
General / Single line of code breaks program.
« on: October 02, 2019, 09:57:03 pm »
I am having a proble m with a personal project of mine. Whenever I try to remove this line in file "Canvas.cpp" in function draw my program breaks. Nothing is displayed.

File: Canvas.cpp Function: draw() Line: 69
if(!circle.isSelectingSize())
{
    texture.draw(circle); //this line
}
 

Github page for code :https://github.com/Xrey274/Splash/tree/beta

I know it's a big project with many files, but I have removed every trace of the Circle class, even from CMakeLists.txt(meaning it was not even compiled), but no matter what I did this problem persisted. If you are on Linux you can compile it for youself and try it out.

9
General / Re: Interpolation method?
« on: September 23, 2019, 07:29:43 pm »
Trying this out for Bezier interpolation rn. Doesn't work correctly when moving the mouse. It does when there are predefined static points.

        if(circles.size() > 2)
        {
                int X0 = circles[circles.size() - 3].getPosition().x;
                int Y0 = circles[circles.size() - 3].getPosition().y;

                int X1 = circles[circles.size() - 2].getPosition().x;
                int Y1 = circles[circles.size() - 2].getPosition().y;

                int X2 = circles[circles.size() - 1].getPosition().x;
                int Y2 = circles[circles.size() - 1].getPosition().y;

                for(float t = 0.01; t < 1; t+=0.01f)
                {
                        int x =(1 - t) * (1 - t) * X0 + 2 * (1 - t) * t * X1 + t * t * X2;
                        int y =(1 - t) * (1 - t) * Y0 + 2 * (1 - t) * t * Y1 + t * t * Y2;

                        curves.push_back(newCircle(sf::Vector2f(x, y), sf::Color::Blue));
                }
        }

Pic 1 - predefined points
Pic 2 - moving the mouse

10
General / Re: Interpolation method?
« on: September 23, 2019, 04:08:48 pm »
Here's what is looks like right now.

11
General / Re: Interpolation method?
« on: September 18, 2019, 02:24:15 pm »
I have found that atleast at my dpi settings and mouse sensitivity, that it happens quite offten almost all of the time. About those "corners" - what exactly are you refering to?

12
General / Re: Interpolation method?
« on: September 07, 2019, 12:25:01 am »
I have already done that - making them into vertex arrays. Draw calls are not the problem - problem is that even when limiting the fps of the windows to 144, moving the mouse fast makes lines choppy (have a flat spots where the rectangle connectors are quite visible). That's why I want to know if interpolation is the right choice.

13
General / Interpolation method?
« on: September 04, 2019, 03:42:45 pm »
What would be the best interpolation method to use for drawing a line(with mouse)? I am currently thinking about bezier curve. The line is consists of circle shapes that need to be connected. I have tried by connecting them with a rectangle shape, which works only if your fps is >1000 for the lines to be smooth when curved. So what do you think will work best in this case?

PS: I am not asking for a code, nor guidence on how to implement it, just your opinion on what would be the best in my case.

14
General / Re: How to convert shape to vertex array.
« on: August 29, 2019, 03:51:01 pm »
This is the code I use to check if a vertex belongs to the rectangle shape.

void FreeDraw::convertToVertex(sf::RectangleShape box)
{
    box.setOrigin(sf::Vector2f(0, 0));    

    sf::Vector2f minCoords = box.getPosition();
    sf::Vector2f maxCoords = box.getPosition() + box.getSize();

     for(int y = minCoords.y; y < maxCoords.y; ++y)
     {
        for(int x = minCoords.x; x < maxCoords.x; ++x)
        {
            if(box.getGlobalBounds().contains(sf::Vector2f(x, y)))
            {
                sf::Vertex dot;
                dot.position = sf::Vector2f(x, y);
                dot.color    = sf::Color::Blue;

                line.append(dot);
            }
        }
    }
}

15
General / Re: How to convert shape to vertex array.
« on: August 29, 2019, 03:44:18 pm »
I didn't see the transformPoint in the documentation of sf::Vertex.

Pages: [1] 2 3 ... 6