Greetings, this is my first post.
I have a query.
Context:
I am using a Bresenham Line implementation using the basic sf::Image functionality in SFML C++; not OpenCV or anything like that, so I'm using Get and SetPixel to read specific (x, y) positions, rather than Points.
Content:
I want to draw a line depending on the specific sf::Colour of specific Pixels, taking an entire Image into consideration, which is read from outside the Line Function.
To do this I have a Bresenham Line Function embedded inside a For Loop, which loops through all the Pixel positions for x and y and checks for sf::Colour.
The Run portion of the Bresenham line Code is embedded in the For Loop, the Rise is outside the y portion of the Loop, as I believe that in order for the line to be drawn, with slope taken into consideration, only one position (the x Pixel or 'width' position) is necessary.
I also speculate that, if not done this way, the Run portion will not increment in the Loop, as the x and y Loop will 'take over' and make the Line think that it is always moving in vertical/horizontal directions, hence no Line is drawn.
However, if this is wrong please chime in.
Depending on an 'if' & 'else' statement in the Run portion of the Code, Pixel Colours are Set to two other Colours, corresponding roughly to the edges of the Pixel regions that have the Colour being checked for (in the original For Loop).
Expectations:
I would expect this implementation of the Line to skirt the edges of regions with Colour being checked for, it would draw lines of one Pixel in two Colours, depending on the 'direction' of the Line (corresponding to the overall x-direction of the line).
Questions:
1) The first question was raised above: is taking the Run portion of the Code outside the y Loop necessary?
2) Secondly, do I need to 'Cast' the values of specific Pixels at x and y and create new floating values at their respective current positions?
Apologies if this is a silly question, but I am not yet a master of C++.
At present I am using x and y then x1, y1 etc., as you might see in a conventional Bresenham Line implementation, but I think the specific updated Pixel Positions might need to be updated in the Function, as the Loop Runs.
I have seen people use 'Tiles' in a similar manner for Raycasting, without updating the Tile Positions in the manner I describe above. Tiles are a specific Struct in SFML (not Pixels), so I am not sure if different rules apply for them.
3) I want to check that the Line Algorithm works; at present there are no Compiler errors in the Script and it Runs.
At first I was going to create an Array of points and push the points in the lines to the Array, however it will be easier for me to see if the line is working if I can actually draw it, on the Image in the manner I describe above.
Is there an easy way to draw the Line, as I have outlined, using SFML::Line or similar functionality that won't interfere with the overall reading/writing of the Image in the Script?
Thanks for your help with this,
Much Appreciated,
Randy Savage.