Add basic visualization to performance mode

This commit is contained in:
karl 2020-11-29 00:25:18 +01:00
parent 083ba53d67
commit 1e9511a3ac
2 changed files with 47 additions and 12 deletions

View File

@ -1,5 +1,6 @@
CXX = g++
CXXFLAGS = -Wall -O3 -g
SFMLFLAGS = -lsfml-system -lsfml-window -lsfml-graphics
# In case you installed SFML to a non-standard path, you'll need to tell the compiler where to find the SFML headers (.hpp files):
# g++ -c main.cpp -I<sfml-install-path>/include
@ -9,10 +10,10 @@ CXXFLAGS = -Wall -O3 -g
quickhull: main.o Quickhull.h Point.h Line.h Triangle.h Timing.o Display.o
# link with sfml libs; -lsfml-network -lsfml-audio currently not needed
$(CXX) $(CXXFLAGS) -o quickhull main.o Quickhull.h Point.h Line.h Triangle.h Timing.o Display.o -lsfml-system -lsfml-window -lsfml-graphics
$(CXX) $(CXXFLAGS) -o quickhull main.o Quickhull.h Point.h Line.h Triangle.h Timing.o Display.o $(SFMLFLAGS)
performance: performance.cpp
$(CXX) $(CXXFLAGS) -o performance performance.cpp
performance: performance.cpp Display.o
$(CXX) $(CXXFLAGS) -o performance Display.o performance.cpp $(SFMLFLAGS)
main.o: main.cpp Timing.h
$(CXX) $(CXXFLAGS) -c main.cpp

View File

@ -1,22 +1,56 @@
#include "Quickhull.h"
#include "NumberGenerator.h"
#include "Display.h"
int main()
{
std::list<Point> points = {
Point(1, 1),
Point(-1, -1),
Point(-1, 1),
Point(1, -1),
Point(0.5, 0) // Should not be in the hull
};
std::list<Point> points = NumberGenerator::get_circle_numbers(500);
std::list<Point> hull;
Quickhull::get_hull(points, hull);
for (const Point &point : hull)
// create the window
sf::RenderWindow window(sf::VideoMode(800, 800), "k-d-tree");
sf::CircleShape normal_p(2);
normal_p.setFillColor(sf::Color(250, 250, 250));
sf::CircleShape hull_p(2);
hull_p.setFillColor(sf::Color(250, 100, 50));
// run the program as long as the window is open
while (window.isOpen())
{
std::cout << point.x() << ", " << point.y() << std::endl;
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
// clear the window with black color
window.clear(sf::Color::Black);
// Draw all points
for (const Point &point : points)
{
normal_p.setPosition(point.x() + 50, point.y() + 50);
window.draw(normal_p);
}
// Draw hull points
for (const Point &point : hull)
{
hull_p.setPosition(point.x() + 50, point.y() + 50);
window.draw(hull_p);
}
// end the current frame
window.display();
}
return 0;
}