-
Notifications
You must be signed in to change notification settings - Fork 2
Visualizer #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Visualizer #2
Changes from all commits
c7097e3
93e86f7
82d3ca0
0ff39db
4797968
575810a
6b6c233
58a553a
c2648ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| cmake_minimum_required(VERSION 3.23) | ||
| project(Visualizer) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 23) | ||
|
|
||
| find_package( OpenCV REQUIRED ) | ||
| include_directories( ${OpenCV_INCLUDE_DIRS} ) | ||
|
|
||
| add_executable(${PROJECT_NAME} source/coordinateSystem.cpp source/models.cpp source/camera.cpp source/plane.cpp | ||
| source/cube.cpp source/objParser.cpp source/main.cpp source/parabola.cpp source/segment.cpp source/StrategyOfAddBorders.cpp source/ParabolaStrategy.cpp source/Road.cpp include/Road.h source/Borders.cpp include/Borders.h source/BorderValidator.cpp include/BorderValidator.h) | ||
| set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER include/coordinateSystem.h include/models.h | ||
| include/camera.h include/plane.h include/cube.h include/parabola.h include/StrategyOfAddBorders.h | ||
| include/ParabolaStrategy.h include/segment.h include/objParser.h lol) | ||
|
|
||
| target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef VISUALIZER_BORDERVALIDATOR_H | ||
| #define VISUALIZER_BORDERVALIDATOR_H | ||
|
|
||
| namespace models { | ||
|
|
||
| class BorderValidator { | ||
|
|
||
| }; | ||
|
|
||
| } // models | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #ifndef VISUALIZER_BORDERS_H | ||
| #define VISUALIZER_BORDERS_H | ||
|
|
||
| #include "models.h" | ||
| #include "BorderValidator.h" | ||
|
|
||
| namespace models { | ||
|
|
||
| class Borders: public models{ | ||
| protected: | ||
| std::shared_ptr<BorderValidator> validator; | ||
| public: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right order: |
||
| virtual double findBorderValue(double y) = 0; | ||
|
|
||
| [[maybe_unused]] bool isValid(); | ||
| virtual bool specificBorderIsValid() = 0; | ||
| }; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. virtual destructor here and further |
||
|
|
||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #ifndef VISUALIZER_PARABOLASTRATEGY_H | ||
| #define VISUALIZER_PARABOLASTRATEGY_H | ||
|
|
||
| #include "StrategyOfAddBorders.h" | ||
| #include "parabola.h" | ||
|
|
||
| namespace models { | ||
|
|
||
| class [[maybe_unused]] ParabolaStrategy : public StrategyOfAddBorders{ | ||
| public: | ||
| std::shared_ptr<Borders> Strategy(std::vector<cv::Point2d> vector) override; | ||
| }; | ||
|
|
||
| } // models | ||
|
|
||
| #endif //VISUALIZER_PARABOLASTRATEGY_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #ifndef VISUALIZER_ROAD_H | ||
| #define VISUALIZER_ROAD_H | ||
|
|
||
| #include "models.h" | ||
| #include "plane.h" | ||
|
|
||
| namespace models { | ||
|
|
||
| class [[maybe_unused]] Road { | ||
| private: | ||
| std::shared_ptr<StrategyOfAddBorders> strategy; | ||
| std::vector<std::shared_ptr<plane>> planes; | ||
| public: | ||
| [[maybe_unused]] std::vector<std::vector<cv::Vec3d>> getRoadPoints(double stepOfYAxis); | ||
|
|
||
| [[maybe_unused]] void addBorders(const std::shared_ptr<plane>& p, std::vector<cv::Point2d> vector); | ||
|
|
||
| [[maybe_unused]] void setStrategy(std::shared_ptr<StrategyOfAddBorders> newStrategy); | ||
|
|
||
| [[maybe_unused]] void IsValidBorders(); | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #ifndef VISUALIZER_STRATEGYOFADDBORDERS_H | ||
| #define VISUALIZER_STRATEGYOFADDBORDERS_H | ||
|
|
||
| #include <vector> | ||
| #include <opencv2/core/types.hpp> | ||
| #include "Borders.h" | ||
| namespace models { | ||
|
|
||
| class StrategyOfAddBorders { | ||
| public: | ||
| virtual std::shared_ptr<Borders> Strategy(std::vector<cv::Point2d> vector) = 0; | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| #ifndef VISUALIZER_CAMERA_H | ||||||
| #define VISUALIZER_CAMERA_H | ||||||
|
|
||||||
| #include "models.h" | ||||||
| #include "plane.h" | ||||||
| namespace models { | ||||||
| class [[maybe_unused]] camera: public models { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лучше именовать типы с заглавной, Camera. Это консистентно со схемой именования OpenCV, ну и вообще так почти все делают. |
||||||
| private: | ||||||
| cv::Mat cameraPlane; | ||||||
| cv::Mat internalCameraParameters; | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intrinsic not internal |
||||||
| cv::Mat inverseInternalCameraParameters; | ||||||
| std::vector<std::shared_ptr<models>> model; | ||||||
| [[maybe_unused]] double speedAtMomentInTime{}; | ||||||
| cv::Mat perturbation; | ||||||
| public: | ||||||
|
|
||||||
| [[maybe_unused]] explicit camera(cv::Mat internalCameraParameters); | ||||||
| [[maybe_unused]] void displayModelPoints(const std::shared_ptr<models>& models); | ||||||
| [[maybe_unused]] cv::Mat getCameraPlane(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Если оно не должно менять состояние объекта |
||||||
| [[maybe_unused]] void moveAroundTheCircle(float angle); | ||||||
| [[maybe_unused]] void clear(); | ||||||
|
|
||||||
| [[maybe_unused]] virtual void moveAlongTheRoad() = 0; | ||||||
| [[maybe_unused]] std::vector<cv::Point2d> reverseProject(const std::shared_ptr<plane> &plane, const std::vector<cv::Point2i>& vector); | ||||||
| [[maybe_unused]] void displayPoints(const std::vector<cv::Point3d> &points); | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| #endif | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #ifndef UNTITLED_COORDINATESYSTEM_H | ||
| #define UNTITLED_COORDINATESYSTEM_H | ||
|
|
||
| #include "opencv2/opencv.hpp" | ||
|
|
||
| namespace coordinateSystem { | ||
| enum Axis{ | ||
| xAxis, | ||
| yAxis, | ||
| zAxis | ||
| }; | ||
|
|
||
| class coordinateSystem { | ||
| private: | ||
| cv::Mat coordinatesOfCenterOfCoordinateSystem; | ||
| cv::Mat rotationMatrix; | ||
| cv::Mat generateRotationMatrix(double angle, Axis axis); | ||
| double xAngle; | ||
| double yAngle; | ||
| double zAngle; | ||
|
|
||
| public: | ||
| void move(const cv::Vec3d& offset); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. translate? |
||
| coordinateSystem(); | ||
| void rotate(double angle, Axis axis); | ||
| cv::Mat moveToGlobalCoordinates(const cv::Vec3d& coordinates); | ||
| cv::Mat moveToLocalCoordinates(const cv::Vec3d& coordinates); | ||
| [[nodiscard]] double getAngle(Axis axis) const; | ||
| cv::Mat getCoordinatesOfCenter(); | ||
| void setCoordinatesOfCenter(const cv::Vec3d& vector); | ||
|
|
||
| [[maybe_unused]] cv::Mat getRotationMatrix(); | ||
| }; | ||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #ifndef VISUALIZER_CUBE_H | ||
| #define VISUALIZER_CUBE_H | ||
|
|
||
| #include "models.h" | ||
|
|
||
| namespace models { | ||
| class [[maybe_unused]] cube : public models { | ||
| public: | ||
| [[maybe_unused]] cube(const cv::Vec3d& planeCoordinates, double width, double length, double height); | ||
| }; | ||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #ifndef VISUALIZER_MODELS_H | ||
| #define VISUALIZER_MODELS_H | ||
|
|
||
| #include "coordinateSystem.h" | ||
|
|
||
| namespace models { | ||
| class models { | ||
| friend class objParser; | ||
| protected: | ||
| // Система координат модели | ||
| std::shared_ptr<coordinateSystem::coordinateSystem> coordinateSystem; | ||
|
|
||
| // Точки модели в локальной системе координат | ||
| std::vector<cv::Point3d> localPoints; | ||
|
|
||
| // Точки модели в глобальной системе координат | ||
| std::vector<cv::Point3d> globalPoints; | ||
|
|
||
| // Список вершин полиогонов для хранение в формате .obj | ||
| std::vector<std::vector<int>> indexes; | ||
|
|
||
| public: | ||
| void move(cv::Vec3d vector); | ||
| std::shared_ptr<coordinateSystem::coordinateSystem> getCoordinateSystem(); | ||
| void rotate(double angle, coordinateSystem::Axis axis); | ||
| std::vector<cv::Point3d>& getGlobalPoints(); | ||
| void addGlobalPoints(const cv::Vec3d& vec); | ||
|
|
||
| [[maybe_unused]] std::vector<cv::Point3d>& getLocalPoints(); | ||
| std::vector<std::vector<int>> getIndexes(); | ||
| cv::Vec3d getCoordinatesOfCenter(); | ||
| models(); | ||
| void moveInLocalCoordinates(cv::Vec3d vector); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for what? |
||
|
|
||
| [[maybe_unused]] void setCoordinatesOfCenter(cv::Vec3d vec); | ||
| }; | ||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #ifndef VISUALIZER_OBJPARSER_H | ||
| #define VISUALIZER_OBJPARSER_H | ||
|
|
||
| #include <iostream> | ||
| #include "models.h" | ||
| #include <fstream> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <opencv2/opencv.hpp> | ||
|
|
||
| namespace models { | ||
| class [[maybe_unused]] objParser { | ||
| public: | ||
| [[maybe_unused]] static std::shared_ptr<models> parse(const std::string& pathToFile); | ||
|
|
||
| [[maybe_unused]] static void write(const std::vector<std::shared_ptr<models>>& models, const std::string& pathToFile); | ||
| }; | ||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #ifndef VISUALIZER_PARABOLA_H | ||
| #define VISUALIZER_PARABOLA_H | ||
|
|
||
| #include "models.h" | ||
| #include "Borders.h" | ||
| namespace models { | ||
| class [[maybe_unused]] parabola : public Borders { | ||
| private: | ||
| [[maybe_unused]] double firstCoefficient{}; | ||
| [[maybe_unused]] double secondCoefficient{}; | ||
| [[maybe_unused]] double thirdCoefficient{}; | ||
| [[nodiscard]] double countParabolaValue(double x) const; | ||
| void calculateParabolaPoints(const cv::Point2d &firstPoint, const cv::Point2d &secondPoint, | ||
| const cv::Point2d &thirdPoint); | ||
| public: | ||
| [[maybe_unused]] parabola(const cv::Point2d& firstPoint, const cv::Point2d& secondPoint, const cv::Point2d& thirdPoint); | ||
| [[maybe_unused]] [[nodiscard]] cv::Vec3d parabolaCoefficient() const; | ||
|
|
||
| double findBorderValue(double y) override; | ||
| bool specificBorderIsValid() override; | ||
| }; | ||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #ifndef VISUALIZER_PLANE_H | ||
| #define VISUALIZER_PLANE_H | ||
|
|
||
| #include "models.h" | ||
| #include "StrategyOfAddBorders.h" | ||
| #include "Borders.h" | ||
| namespace models { | ||
| class [[maybe_unused]] plane : public models{ | ||
| private: | ||
| double width; | ||
| double length; | ||
| void initializateLocalPoints(); | ||
| std::vector<std::shared_ptr<Borders>> leftBorderModels; | ||
| std::vector<std::shared_ptr<Borders>> rightBorderModels; | ||
| public: | ||
|
|
||
| plane(const cv::Vec3d& planeCoordinates, double width, double length); | ||
|
|
||
| // Поменять длину и ширину плоскости | ||
| [[maybe_unused]] void changeWidthAndLength(double width, double length); | ||
|
|
||
| // Соеденить плоскости | ||
| [[maybe_unused]] std::vector<std::shared_ptr<plane>> mergePlanes(coordinateSystem::Axis axis, double maxAngle, double stepLength, double stepAngle); | ||
|
|
||
| // Получить длину и ширину | ||
| [[maybe_unused]] [[nodiscard]] double getWidth() const; | ||
|
|
||
| [[maybe_unused]] [[nodiscard]] double getLength() const; | ||
|
|
||
| [[maybe_unused]] void addLeftBorder(std::shared_ptr<Borders>); | ||
| [[maybe_unused]] void addRightBorder(std::shared_ptr<Borders>); | ||
|
|
||
|
|
||
| /* | ||
| [[maybe_unused]] std::vector<cv::Point3d> getLeftBorder(); | ||
|
|
||
| std::vector<cv::Point3d> getRightBorder();*/ | ||
|
|
||
| std::vector<std::shared_ptr<Borders>> getRightBorderModels(); | ||
| std::vector<std::shared_ptr<Borders>> getLeftBorderModels(); | ||
| }; | ||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #ifndef VISUALIZER_SEGMENT_H | ||
| #define VISUALIZER_SEGMENT_H | ||
| #include "models.h" | ||
| #include "Borders.h" | ||
|
|
||
| namespace models { | ||
|
|
||
| class [[maybe_unused]] segment: public Borders { | ||
| private: | ||
| [[maybe_unused]] double firstCoefficient{}; | ||
| [[maybe_unused]] double secondCoefficient{}; | ||
| [[nodiscard]] double countSegmentValue(double x) const; | ||
| void calculateSegmentPoints(const cv::Point2d &firstPoint, const cv::Point2d &secondPoint); | ||
| public: | ||
| [[maybe_unused]] [[maybe_unused]] segment(const cv::Point2d& firstPoint, const cv::Point2d& secondPoint); | ||
|
|
||
| [[maybe_unused]] [[maybe_unused]] [[nodiscard]] cv::Vec2d segmentCoefficient() const; | ||
| double findBorderValue(double y) override; | ||
| bool specificBorderIsValid() override; | ||
| }; | ||
|
|
||
| } | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #include "../include/BorderValidator.h" | ||
|
|
||
| namespace models { | ||
| } // models |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "../include/Borders.h" | ||
|
|
||
| namespace models { | ||
| [[maybe_unused]] bool Borders::isValid() { | ||
| auto points = this->getLocalPoints(); | ||
|
|
||
| double firstX = points[0].x; | ||
|
|
||
| for (int i = 1 ; i < points.size(); i++) { | ||
| if (points[i].x * firstX < 0) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } // models |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #include "../include/ParabolaStrategy.h" | ||
| #include "../include/models.h" | ||
|
|
||
| namespace models { | ||
| std::shared_ptr<Borders> ParabolaStrategy::Strategy(std::vector<cv::Point2d> vector) { | ||
| return std::make_shared<parabola>(vector[0], vector[1], vector[2]); | ||
| } | ||
| } // models |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#pragma once
here and further