Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions visualizer/CMakeLists.txt
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})
12 changes: 12 additions & 0 deletions visualizer/include/BorderValidator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef VISUALIZER_BORDERVALIDATOR_H
#define VISUALIZER_BORDERVALIDATOR_H
Copy link
Copy Markdown
Owner

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


namespace models {

class BorderValidator {

};

} // models

#endif
21 changes: 21 additions & 0 deletions visualizer/include/Borders.h
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:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right order:
public
protected
private

virtual double findBorderValue(double y) = 0;

[[maybe_unused]] bool isValid();
virtual bool specificBorderIsValid() = 0;
};
Copy link
Copy Markdown
Owner

@osechkina-masha osechkina-masha Jan 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtual destructor here and further


}

#endif
16 changes: 16 additions & 0 deletions visualizer/include/ParabolaStrategy.h
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
25 changes: 25 additions & 0 deletions visualizer/include/Road.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
16 changes: 16 additions & 0 deletions visualizer/include/StrategyOfAddBorders.h
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
29 changes: 29 additions & 0 deletions visualizer/include/camera.h
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 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше именовать типы с заглавной, Camera. Это консистентно со схемой именования OpenCV, ну и вообще так почти все делают.

private:
cv::Mat cameraPlane;
cv::Mat internalCameraParameters;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[maybe_unused]] cv::Mat getCameraPlane();
[[maybe_unused]] cv::Mat getCameraPlane() const;

Если оно не должно менять состояние объекта

[[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
36 changes: 36 additions & 0 deletions visualizer/include/coordinateSystem.h
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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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
13 changes: 13 additions & 0 deletions visualizer/include/cube.h
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
39 changes: 39 additions & 0 deletions visualizer/include/models.h
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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for what?


[[maybe_unused]] void setCoordinatesOfCenter(cv::Vec3d vec);
};
}

#endif
20 changes: 20 additions & 0 deletions visualizer/include/objParser.h
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
24 changes: 24 additions & 0 deletions visualizer/include/parabola.h
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
44 changes: 44 additions & 0 deletions visualizer/include/plane.h
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
23 changes: 23 additions & 0 deletions visualizer/include/segment.h
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
4 changes: 4 additions & 0 deletions visualizer/source/BorderValidator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "../include/BorderValidator.h"

namespace models {
} // models
17 changes: 17 additions & 0 deletions visualizer/source/Borders.cpp
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
8 changes: 8 additions & 0 deletions visualizer/source/ParabolaStrategy.cpp
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
Loading