Skip to content

Commit

Permalink
Add skeleton for wrapper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Lentz committed Oct 22, 2023
1 parent 4e2dee4 commit d898a74
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FATAL: In-source builds are not allowed.
endif()


cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.14)


set(CMAKE_CXX_COMPILER g++)
Expand All @@ -29,10 +29,12 @@ include_directories(${INCLUDE_DIRECTORY})
add_executable(${PROJECT_NAME} ${SOURCES})
# =============================


# =============================
# Libraries
# NOTE: add each library's include directory to clang-tidy in the Linting section
add_subdirectory(deps/json)
add_subdirectory(deps/matplotplusplus)
target_link_libraries(${PROJECT_NAME}
PRIVATE
nlohmann_json::nlohmann_json
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ RUN apt-get update \
gdb \
git \
cmake \
clang-tidy
clang-tidy \
gnuplot
6 changes: 6 additions & 0 deletions deps/matplotplusplus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!.gitignore

!CMakeLists.txt
!CMakeLists.txt.in
16 changes: 16 additions & 0 deletions deps/matplotplusplus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include(FetchContent)

FetchContent_Declare(matplotplusplus
GIT_REPOSITORY https://github.com/alandefreitas/matplotplusplus
GIT_TAG origin/master) # or whatever tag you want

FetchContent_GetProperties(matplotplusplus)
if(NOT matplotplusplus_POPULATED)
FetchContent_Populate(matplotplusplus)
add_subdirectory(${matplotplusplus_SOURCE_DIR} ${matplotplusplus_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

target_link_libraries(${PROJECT_NAME}
PRIVATE
matplot
)
7 changes: 4 additions & 3 deletions include/core/states.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include <array>
#include <optional>

#include "utilities/datatypes.hpp"
#include "utilities/constants.hpp"
Expand Down Expand Up @@ -40,9 +41,9 @@ class PreparationState: public MissionState {
}

private:
Polygon flightBoundary;
Polygon airdropBoundary;
Polyline waypoints;
std::optional<Polygon> flightBoundary;
std::optional<Polygon> airdropBoundary;
std::optional<Polyline> waypoints;
std::array<CompetitionBottle, NUM_AIRDROP_BOTTLES> bottles;
};

Expand Down
68 changes: 68 additions & 0 deletions include/pathing/plotting.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef PATHING_PLOTTING_HPP
#define PATHING_PLOTTING_HPP

#include <list>

#include <matplot/matplot.h>
#include "utilities/datatypes.hpp"

class PathingPlot {
public:
void addPoints(std::vector<XYZCoord> pts);
void addPolygons(std::vector<Polygon> polygons);
void addPolylines(std::vector<Polyline> polylines);

// Used to group changes to the plot into logical chunks
virtual void beginUpdate() = 0; // Call before making changes to the plot
virtual void endUpdate() = 0; // Call when done making changes to the plot

virtual void addPolygon(Polygon polygon) = 0;
virtual void addPolyline(Polyline polyline) = 0;
virtual void addPoint(XYZCoord pt) = 0;

// Output to filename. Don't include extension as the subclass
// will add the correct extension itself
virtual void output(std::string filename) = 0;
};

// Saves a record of all of the updates that have been done
// When plotted, creates a GIF
class AnimationPathingPlot : public PathingPlot {
public:
AnimationPathingPlot();

void beginUpdate() override;
void endUpdate() override;

void addPolygon(Polygon polygon) override;
void addPolyline(Polyline polyline) override;
void addPoint(XYZCoord pt) override;

void output(std::string filename) override;
private:
std::list<std::list<XYZCoord>> coords;
std::list<std::list<Polygon>> polygons;
std::list<std::list<Polyline>> polylines;
};

// Only records the most recent state of the plot
// When plotted, creates a PNG
class StaticPathingPlot : public PathingPlot {
public:
StaticPathingPlot();

void beginUpdate() override;
void endUpdate() override;

void addPolygon(Polygon polygon) override;
void addPolyline(Polyline polyline) override;
void addPoint(XYZCoord pt) override;

void output(std::string filename) override;
private:
std::list<XYZCoord> coords;
std::list<Polygon> polygons;
std::list<Polyline> polylines;
};

#endif
28 changes: 23 additions & 5 deletions include/utilities/datatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define UTILITIES_DATATYPES_HPP_

#include <vector>
#include <matplot/matplot.h>

struct GPSCoord {
GPSCoord(double lat, double lon, double alt)
Expand All @@ -14,17 +15,34 @@ struct GPSCoord {

struct XYZCoord {
XYZCoord(double x, double y, double z)
:x(x), y(y), z(z) {}
:x(x), y(y), z(z), color(matplot::color::black) {}

XYZCoord(double x, double y, double z, matplot::color color)
:x(x), y(y), z(z), color(color) {}

double x;
double y;
double z;
matplot::color color;
};

// In the future maybe make these their own classes with methods, etc...
// should be easyish to migrate because the type names will be the same
typedef std::vector<XYZCoord> Polygon;
typedef std::vector<XYZCoord> Polyline;
class Polygon : public std::vector<XYZCoord> {
public:
Polygon(matplot::color color);

matplot::color getColor() const;
private:
matplot::color color;
};

class Polyline: public std::vector<XYZCoord> {
public:
Polyline(matplot::color color);

matplot::color getColor() const;
private:
matplot::color color;
};

// TODO: these will eventually be redefined in a protobuf, so once the generated protobuf code exists we remove these
enum class ODLCShape {
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>

#include "core/states.hpp"
#include "pathing/plotting.hpp"

int main() {
std::cout << "hello" << std::endl;
Expand Down
82 changes: 82 additions & 0 deletions src/pathing/plotting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "pathing/plotting.hpp"
#include "utilities/datatypes.hpp"

#include <vector>

void PathingPlot::addPoints(std::vector<XYZCoord> pts) {
for (auto pt : pts) {
this->addPoint(pt);
}
}

void PathingPlot::addPolygons(std::vector<Polygon> polygons) {
for (auto polygon : polygons) {
this->addPolygon(polygon);
}
}

void PathingPlot::addPolylines(std::vector<Polyline> polylines) {
for (auto polyline : polylines) {
this->addPolyline(polyline);
}
}


AnimationPathingPlot::AnimationPathingPlot() {
// TODO: init member vars
}

void AnimationPathingPlot::beginUpdate() {
// TODO: delineate update
}

void AnimationPathingPlot::endUpdate() {
// TODO: delinate end of update
}

void AnimationPathingPlot::addPoint(XYZCoord pt) {
// TODO: add point
}

void AnimationPathingPlot::addPolygon(Polygon polygon) {
// TODO: add polygon
}

void AnimationPathingPlot::addPolyline(Polyline polyline) {
// TODO: add polyline
}

void AnimationPathingPlot::output(std::string filename) {
// TODO: go through all the data and create GIF
// append .gif to filename param
}


StaticPathingPlot::StaticPathingPlot() {
// TODO: init member vars
}

void StaticPathingPlot::beginUpdate() {
// does nothing
}

void StaticPathingPlot::endUpdate() {
// does nothing
}

void StaticPathingPlot::addPoint(XYZCoord pt) {
// TODO: add point
}

void StaticPathingPlot::addPolygon(Polygon polygon) {
// TODO: add polygon
}

void StaticPathingPlot::addPolyline(Polyline polyline) {
// TODO: add polyline
}

void StaticPathingPlot::output(std::string filename) {
// TODO: go through all the data and create image
// append .png to filename param
}
9 changes: 9 additions & 0 deletions src/utilities/datatypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "utilities/datatypes.hpp"

Polygon::Polygon(matplot::color color) {
this->color = color;
}

Polyline::Polyline(matplot::color color) {
this->color = color;
}

0 comments on commit d898a74

Please sign in to comment.