Laser Cutter application v1.0

lasercutter.h
Go to the documentation of this file.
1 #ifndef LASERCUTTER_H
2 #define LASERCUTTER_H
3
4 #include <QMainWindow>
5
6 #include <QCamera>
7 #include <QCameraImageCapture>
8 #include <QCameraInfo>
9 #include <QCameraViewfinder>
10 #include <QMediaRecorder>
11 #include <QMediaService>
12 #include <QMediaMetaData>
13 #include <QScopedPointer>
14
15 #include <opencv2/core/core.hpp>
16 #include <opencv2/highgui/highgui.hpp>
17 #include <opencv2/imgproc/imgproc.hpp>
18 #include <opencv2/imgproc/imgproc_c.h>
19 #include <opencv2/imgcodecs/imgcodecs.hpp>
20 #include <opencv2/aruco.hpp>
21 #include <opencv2/videoio.hpp>
22
23 #include <QtSvg>
24 #include <QPalette>
25
26 #include <QDial>
27 #include <QSerialPort>
28 #include <QSerialPortInfo>
29 #include <QElapsedTimer>
30
31 #include <QMessageBox>
32 #include <QFileDialog>
33
34 #include "dragwidget.h"
35 #include "svglabel.h"
36 #include "filehandling.h"
37 #include "hotkeys.h"
38
39 QT_BEGIN_NAMESPACE
40 namespace Ui { class LaserCutter; }
41 QT_END_NAMESPACE
42
43
48 class LaserCutter : public QMainWindow
49 {
50 Q_OBJECT
51
52 public:
57 LaserCutter();
58
63 ~LaserCutter();
64
70 void RotateInit(int aRotate);
71
78 void SvgLabelInfo(const SvgLabel& aSlabel);
79
80 protected:
86 void mousePressEvent(QMouseEvent *event) override;
87
93 void keyReleaseEvent(QKeyEvent *event) override;
94
100 void closeEvent(QCloseEvent *event) override;
101
102 private:
103 Ui::LaserCutter *ui;
104
108 size_t m_image_source_counter;
109
113 QScopedPointer<QCamera> m_camera;
114
118 QActionGroup *m_videoDevicesGroup;
119
123 struct sCamera{
124 QList<QSize> resolutions;
125 int camera_selected = -1;
126 }m_CamInfo;
127
131 void UpdateCamerasMenu();
132
136 std::vector<cv::Point_<double>> m_corners;
137
141 double m_transfer_ratio[2];
142
146 std::vector<double> m_cutting_area;
147
151 QString m_Path_to_source;
152
156 int m_rotate;
157
165 QPointF GetRotatedPoint(const QPointF &p, const QPointF &center, const qreal &angleRads);
166
173 QRectF GetMinimumBoundingRect(const QRect &r, const qreal &angleRads);
174
180 void RotateLabel();
181
185 int m_label_tab_index;
186
190 std::array<size_t,2> m_img_source_placement;
191
195 std::vector<QString> m_res;
196
201 void InitCutterInfo();
202
208 void SetCamera(const QCameraInfo &cameraInfo);
209
213 void DisplayCameraError();
214
218 QElapsedTimer *m_tm;
219
223 QTimer *m_timer;
224
228 cv::VideoCapture inputVideo;
229
235 void OpenFiles();
236
241 void SaveXML_copies();
242
246 void ClearWorkspace();
247
252 void GetImagePositions();
253
257 void SetupUiFrameSize();
258
263 void UpdateCameraDevice(QAction *action);
264
271 bool CameraMarkerDetection();
272
276 void GetTransferRatio();
277
284 void Transform_to_normalized(double *aTransform_ratio, QLabel& label);
285
291 void SetImageSource(QString aPath);
292
296 QSize m_dimensions;
297
304 double Pythagoras(const cv::Point2d &aUno, const cv::Point2d &aDuo);
305
311 QPixmap MatToPixmap(cv::Mat src);
312
319 cv::Mat QImageToMat( const QImage &inImage, bool inCloneImageData);
320
327 bool MatIsEqual(const cv::Mat &mat1, const cv::Mat &mat2);
328
336 bool CheckSvgsPositions();
337
343 void TrackMaterial(bool tracking_enabled);
344
345 bool m_tracking_flag;
346
350 QPoint m_centroid;
351
355 QPoint m_old_centroid;
356
360 QString final_port; //storing the COM port number
361
365 void FillPortsInfo();
366
370 void HotkeysDialog();
371
375 Hotkeys *m_hotkeys;
376
380 void ShowManual();
381
385 QProcess *m_process_cut;
386
387 private slots:
388
393 bool PerspectiveTransform();
394
399 void ShowPortInfo(int idx);
400
401
408 void Initialize();
409
414 void ResetApp();
415
421 void CuttingFinished(int exitCode, QProcess::ExitStatus exitStatus);
422
423 };
424 #endif // LASERCUTTER_H
LaserCutter::m_dimensions
QSize m_dimensions
Dimensions of the cutting area.
Definition: lasercutter.h:296
LaserCutter::Initialize
void Initialize()
Initialization of the app.
Definition: lasercutter.cpp:615
LaserCutter::m_centroid
QPoint m_centroid
New position of the tracked centroid.
Definition: lasercutter.h:350
LaserCutter::sCamera::camera_selected
int camera_selected
Definition: lasercutter.h:125
LaserCutter::OpenFiles
void OpenFiles()
Opens SVG files from the selected folder.
Definition: lasercutter.cpp:748
LaserCutter::m_old_centroid
QPoint m_old_centroid
Old position of the tracked centroid.
Definition: lasercutter.h:355
LaserCutter::DisplayCameraError
void DisplayCameraError()
Displays the camera error.
Definition: lasercutter.cpp:556
filehandling.h
LaserCutter::~LaserCutter
~LaserCutter()
Default d'tor.
Definition: lasercutter.cpp:71
LaserCutter::inputVideo
cv::VideoCapture inputVideo
Used for Camera Hanlding, after the start of the application.
Definition: lasercutter.h:228
LaserCutter::LaserCutter
LaserCutter()
Default c'tor.
Definition: lasercutter.cpp:7
LaserCutter::m_cutting_area
std::vector< double > m_cutting_area
Cutting area dimensions of the laser cutter (width, height)
Definition: lasercutter.h:146
LaserCutter::PerspectiveTransform
bool PerspectiveTransform()
PerspectiveTransform.
Definition: lasercutter.cpp:889
dragwidget.h
LaserCutter::m_res
std::vector< QString > m_res
Vector of paths to the source images.
Definition: lasercutter.h:195
LaserCutter::GetTransferRatio
void GetTransferRatio()
Calculates the transform ratio for each axis (px~mm)
Definition: lasercutter.cpp:1218
LaserCutter::GetMinimumBoundingRect
QRectF GetMinimumBoundingRect(const QRect &r, const qreal &angleRads)
GetMinimumBoundingRect Calculates the minimum bounding box of a rotated image.
Definition: lasercutter.cpp:494
LaserCutter::m_tm
QElapsedTimer * m_tm
Timer used for PerspectiveTransform()
Definition: lasercutter.h:218
LaserCutter::SvgLabelInfo
void SvgLabelInfo(const SvgLabel &aSlabel)
Obtains the information about the SvgLabel instance.
Definition: lasercutter.cpp:87
LaserCutter::MatIsEqual
bool MatIsEqual(const cv::Mat &mat1, const cv::Mat &mat2)
Determines whether two cv::Mat instances are equal.
Definition: lasercutter.cpp:1204
LaserCutter::InitCutterInfo
void InitCutterInfo()
Initializes the cutter parameters.
Definition: lasercutter.cpp:781
LaserCutter::SetupUiFrameSize
void SetupUiFrameSize()
Sets up the dimensions of the camera frame and the image_destination DragWidget instance.
Definition: lasercutter.cpp:233
LaserCutter::m_tracking_flag
bool m_tracking_flag
Definition: lasercutter.h:345
LaserCutter::m_img_source_placement
std::array< size_t, 2 > m_img_source_placement
Utilized for placing the image in the image_source DragWidget instance.
Definition: lasercutter.h:190
LaserCutter::CameraMarkerDetection
bool CameraMarkerDetection()
Detection of ArucoMarkers from camera input.
Definition: lasercutter.cpp:827
LaserCutter::CheckSvgsPositions
bool CheckSvgsPositions()
Checks the positions of the SvgLabel instance whether they are within the bounds of the material.
Definition: lasercutter.cpp:1088
LaserCutter::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
mousePressEvent Overloaded event of the mousePress handling
Definition: lasercutter.cpp:103
LaserCutter::ClearWorkspace
void ClearWorkspace()
Clears the workspace (image_destination DragWidget instance)
Definition: lasercutter.cpp:1079
SvgLabel
Custom class used for handling SVG images and its transformations.
Definition: svglabel.h:18
LaserCutter::ShowPortInfo
void ShowPortInfo(int idx)
Shows the ports info based on the idx.
Definition: lasercutter.cpp:1226
LaserCutter::QImageToMat
cv::Mat QImageToMat(const QImage &inImage, bool inCloneImageData)
Converts QImage to cv::Mat.
Definition: lasercutter.cpp:1019
LaserCutter::closeEvent
void closeEvent(QCloseEvent *event) override
closeEvent Overloaded event of the closeEvent handling
Definition: lasercutter.cpp:567
LaserCutter::RotateInit
void RotateInit(int aRotate)
Initializes the dial in the ui.
Definition: lasercutter.cpp:82
LaserCutter::SetImageSource
void SetImageSource(QString aPath)
Sets up the image_source DragWidget instance.
Definition: lasercutter.cpp:525
LaserCutter::RotateLabel
void RotateLabel()
RotateLabel Rotates an SvgLabel.
Definition: lasercutter.cpp:119
LaserCutter::GetImagePositions
void GetImagePositions()
Acquires the position of each of the images.
Definition: lasercutter.cpp:815
LaserCutter::Transform_to_normalized
void Transform_to_normalized(double *aTransform_ratio, QLabel &label)
Normalizes a QLabel's dimensions.
Definition: lasercutter.cpp:514
LaserCutter::m_corners
std::vector< cv::Point_< double > > m_corners
Holds the position of the ArucoMarker's corners (corners with index 0)
Definition: lasercutter.h:136
LaserCutter::Pythagoras
double Pythagoras(const cv::Point2d &aUno, const cv::Point2d &aDuo)
Calculates the Euclidian distance between two points in the image.
Definition: lasercutter.cpp:990
LaserCutter::final_port
QString final_port
Selected COM port, used for the Svg2GcodeSend as an argument.
Definition: lasercutter.h:360
Hotkeys
A pop window to show the hotkeys of the application. A table of hotkeys is shown.
Definition: hotkeys.h:16
LaserCutter::m_process_cut
QProcess * m_process_cut
Pointer to the Svg2GcodeSend process.
Definition: lasercutter.h:385
LaserCutter::m_rotate
int m_rotate
Rotation of the currently selected SvgLabel instance.
Definition: lasercutter.h:156
LaserCutter::GetRotatedPoint
QPointF GetRotatedPoint(const QPointF &p, const QPointF &center, const qreal &angleRads)
GetRotatedPoint Calculates the coordinates of a point rotated around a refernce point.
Definition: lasercutter.cpp:474
LaserCutter::UpdateCamerasMenu
void UpdateCamerasMenu()
Updates the Devices menu when it is about to show.
Definition: lasercutter.cpp:600
LaserCutter::TrackMaterial
void TrackMaterial(bool tracking_enabled)
Track the material.
Definition: lasercutter.cpp:1172
Ui
Definition: hotkeys.h:8
LaserCutter::m_CamInfo
struct LaserCutter::sCamera m_CamInfo
LaserCutter::FillPortsInfo
void FillPortsInfo()
Fills the COM ports Info.
Definition: lasercutter.cpp:1235
LaserCutter::ResetApp
void ResetApp()
Reset of the app.
Definition: lasercutter.cpp:688
LaserCutter::sCamera
Structure for Camera info, maximum resolution and currenlty seleceted camera.
Definition: lasercutter.h:123
LaserCutter::m_transfer_ratio
double m_transfer_ratio[2]
Transform ratio of px~mm for each axis (x;y)
Definition: lasercutter.h:141
LaserCutter::ShowManual
void ShowManual()
Shows the user manual.
Definition: lasercutter.cpp:1253
LaserCutter::ui
Ui::LaserCutter * ui
Definition: lasercutter.h:103
LaserCutter::SaveXML_copies
void SaveXML_copies()
Saves the currently displayed SvgLabels.
Definition: lasercutter.cpp:164
LaserCutter::m_timer
QTimer * m_timer
Timer, its timeout used to call PerspectiveTransform()
Definition: lasercutter.h:223
LaserCutter::sCamera::resolutions
QList< QSize > resolutions
Definition: lasercutter.h:124
LaserCutter::m_hotkeys
Hotkeys * m_hotkeys
Pointer to the Hotkeys class instance.
Definition: lasercutter.h:375
LaserCutter::m_label_tab_index
int m_label_tab_index
Used for cycling through the SvgLabel instances by pressing 'Tab'.
Definition: lasercutter.h:185
LaserCutter::m_image_source_counter
size_t m_image_source_counter
Holds the counter for the image placement.
Definition: lasercutter.h:108
LaserCutter::SetCamera
void SetCamera(const QCameraInfo &cameraInfo)
Sets the Camera.
Definition: lasercutter.cpp:215
LaserCutter::m_camera
QScopedPointer< QCamera > m_camera
Used for Camera Hanlding, before the start of the application.
Definition: lasercutter.h:113
LaserCutter::UpdateCameraDevice
void UpdateCameraDevice(QAction *action)
Updates the camera device on action trigger.
Definition: lasercutter.cpp:561
LaserCutter
Main Class for the whole application.
Definition: lasercutter.h:49
LaserCutter::CuttingFinished
void CuttingFinished(int exitCode, QProcess::ExitStatus exitStatus)
Prompts the user if the cutting process has finished.
Definition: lasercutter.cpp:718
LaserCutter::m_Path_to_source
QString m_Path_to_source
Holds the path to the folder of the source images.
Definition: lasercutter.h:151
LaserCutter::MatToPixmap
QPixmap MatToPixmap(cv::Mat src)
Converts cv::Mat to QPixmap.
Definition: lasercutter.cpp:998
LaserCutter::HotkeysDialog
void HotkeysDialog()
Creates an instance of the Hotkeys class.(new window)
Definition: lasercutter.cpp:1247
hotkeys.h
svglabel.h
LaserCutter::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *event) override
keyReleaseEvent Overloaded event of the keyRelease handling
Definition: lasercutter.cpp:251
LaserCutter::m_videoDevicesGroup
QActionGroup * m_videoDevicesGroup
ActionGroup for the Devices menu.
Definition: lasercutter.h:118