Laser Cutter application v1.0

Classes | Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
LaserCutter Class Reference

Main Class for the whole application. More...

`#include <lasercutter.h>`

Inheritance diagram for LaserCutter:

## Classes
struct | sCamera
| Structure for Camera info, maximum resolution and currenlty seleceted camera. More...

## Public Member Functions
| LaserCutter ()
| Default c'tor. More...
| ~LaserCutter ()
| Default d'tor. More...
void | RotateInit (int aRotate)
| Initializes the dial in the ui. More...
void | SvgLabelInfo (const SvgLabel &aSlabel)
| Obtains the information about the SvgLabel instance. More...

## Protected Member Functions
void | mousePressEvent (QMouseEvent *event) override
| mousePressEvent Overloaded event of the mousePress handling More...
void | keyReleaseEvent (QKeyEvent *event) override
| keyReleaseEvent Overloaded event of the keyRelease handling More...
void | closeEvent (QCloseEvent *event) override
| closeEvent Overloaded event of the closeEvent handling More...

## Private Slots
bool | PerspectiveTransform ()
| PerspectiveTransform. More...
void | ShowPortInfo (int idx)
| Shows the ports info based on the idx. More...
void | Initialize ()
| Initialization of the app. More...
void | ResetApp ()
| Reset of the app. More...
void | CuttingFinished (int exitCode, QProcess::ExitStatus exitStatus)
| Prompts the user if the cutting process has finished. More...

## Private Member Functions
void | UpdateCamerasMenu ()
| Updates the Devices menu when it is about to show. More...
QPointF | GetRotatedPoint (const QPointF &p, const QPointF &center, const qreal &angleRads)
| GetRotatedPoint Calculates the coordinates of a point rotated around a refernce point. More...
QRectF | GetMinimumBoundingRect (const QRect &r, const qreal &angleRads)
| GetMinimumBoundingRect Calculates the minimum bounding box of a rotated image. More...
void | RotateLabel ()
| RotateLabel Rotates an SvgLabel. More...
void | InitCutterInfo ()
| Initializes the cutter parameters. More...
void | SetCamera (const QCameraInfo &cameraInfo)
| Sets the Camera. More...
void | DisplayCameraError ()
| Displays the camera error. More...
void | OpenFiles ()
| Opens SVG files from the selected folder. More...
void | SaveXML_copies ()
| Saves the currently displayed SvgLabels. More...
void | ClearWorkspace ()
| Clears the workspace (image_destination DragWidget instance) More...
void | GetImagePositions ()
| Acquires the position of each of the images. More...
void | SetupUiFrameSize ()
| Sets up the dimensions of the `camera` frame and the `image_destination` DragWidget instance. More...
void | UpdateCameraDevice (QAction *action)
| Updates the camera device on action trigger. More...
bool | CameraMarkerDetection ()
| Detection of ArucoMarkers from camera input. More...
void | GetTransferRatio ()
| Calculates the transform ratio for each axis (px~mm) More...
void | Transform_to_normalized (double *aTransform_ratio, QLabel &label)
| Normalizes a QLabel's dimensions. More...
void | SetImageSource (QString aPath)
| Sets up the image_source DragWidget instance. More...
double | Pythagoras (const cv::Point2d &aUno, const cv::Point2d &aDuo)
| Calculates the Euclidian distance between two points in the image. More...
QPixmap | MatToPixmap (cv::Mat src)
| Converts cv::Mat to QPixmap. More...
cv::Mat | QImageToMat (const QImage &inImage, bool inCloneImageData)
| Converts QImage to cv::Mat. More...
bool | MatIsEqual (const cv::Mat &mat1, const cv::Mat &mat2)
| Determines whether two cv::Mat instances are equal. More...
bool | CheckSvgsPositions ()
| Checks the positions of the SvgLabel instance whether they are within the bounds of the material. More...
void | TrackMaterial (bool tracking_enabled)
| Track the material. More...
void | FillPortsInfo ()
| Fills the COM ports Info. More...
void | HotkeysDialog ()
| Creates an instance of the Hotkeys class.(new window) More...
void | ShowManual ()
| Shows the user manual. More...

## Private Attributes
Ui::LaserCutter * | ui
size_t | m_image_source_counter
| Holds the counter for the image placement. More...
QScopedPointer< QCamera > | m_camera
| Used for Camera Hanlding, before the start of the application. More...
QActionGroup * | m_videoDevicesGroup
| ActionGroup for the Devices menu. More...
struct LaserCutter::sCamera | m_CamInfo
std::vector< cv::Point_< double > > | m_corners
| Holds the position of the ArucoMarker's corners (corners with index 0) More...
double | m_transfer_ratio [2]
| Transform ratio of px~mm for each axis (x;y) More...
std::vector< double > | m_cutting_area
| Cutting area dimensions of the laser cutter (width, height) More...
QString | m_Path_to_source
| Holds the path to the folder of the source images. More...
int | m_rotate
| Rotation of the currently selected SvgLabel instance. More...
int | m_label_tab_index
| Used for cycling through the SvgLabel instances by pressing 'Tab'. More...
std::array< size_t, 2 > | m_img_source_placement
| Utilized for placing the image in the image_source DragWidget instance. More...
std::vector< QString > | m_res
| Vector of paths to the source images. More...
QElapsedTimer * | m_tm
| Timer used for PerspectiveTransform() More...
QTimer * | m_timer
| Timer, its timeout used to call PerspectiveTransform() More...
cv::VideoCapture | inputVideo
| Used for Camera Hanlding, after the start of the application. More...
QSize | m_dimensions
| Dimensions of the cutting area. More...
bool | m_tracking_flag
QPoint | m_centroid
| New position of the tracked centroid. More...
QPoint | m_old_centroid
| Old position of the tracked centroid. More...
QString | final_port
| Selected COM port, used for the Svg2GcodeSend as an argument. More...
Hotkeys * | m_hotkeys
| Pointer to the Hotkeys class instance. More...
QProcess * | m_process_cut
| Pointer to the Svg2GcodeSend process. More...

## Detailed Description

Main Class for the whole application.

Handles most of the funcionalities of from the user's side. Implements the OpenCV methods and controls the workflow of the application.

## Constructor & Destructor Documentation

## ◆ LaserCutter()

LaserCutter::LaserCutter | ( |  | ) |

Default c'tor.

Initializes the UI, connects majority of the signals and creates a list of available cameras

## ◆ ~LaserCutter()

LaserCutter::~LaserCutter | ( |  | ) |

Default d'tor.

Deletes the UI and removes the TEMP directories

## Member Function Documentation

## ◆ CameraMarkerDetection()

bool LaserCutter::CameraMarkerDetection | ( |  | ) |
| private

Detection of ArucoMarkers from camera input.

Detects the four markers from the selected camera. If the markers are not detected after five seconds, returns false. Also stores the positions of each of the [0] corneres of the Arucos to m_corners variable

Returns
  Returns true if the all four markers are found, otherwise false

## ◆ CheckSvgsPositions()

bool LaserCutter::CheckSvgsPositions | ( |  | ) |
| private

Checks the positions of the SvgLabel instance whether they are within the bounds of the material.

Takes an image from the camera input and applies binary thresholding (inverse, non-inverse). Grabs the image from the image_destination DragWidget instance with black and white background. Applies the same thresholding. The white_label is then negated. ANDs the corresponding images and compares them with original(of the camera frame thresholded images). If the Images are equal, objects are within the bounds of the material

Returns
  Returns true if images are within the bounds of the material, otherwise false.

## ◆ ClearWorkspace()

void LaserCutter::ClearWorkspace | ( |  | ) |
| private

Clears the workspace (image_destination DragWidget instance)

## ◆ closeEvent()

void LaserCutter::closeEvent | ( | QCloseEvent * | event | ) |
| override protected

closeEvent Overloaded event of the closeEvent handling

Pops a dialog about quitting the application, automatically saves the path to the image source folder to the config file

Parameters

  event | close event

## ◆ CuttingFinished

void LaserCutter::CuttingFinished | ( | int | exitCode,
|  | QProcess::ExitStatus | exitStatus
| ) |  |
| private slot

Prompts the user if the cutting process has finished.

Parameters

  exitCode | ExitCode of the Svg2GcodeSend process
  exitStatus | {Parameter unused}

## ◆ DisplayCameraError()

void LaserCutter::DisplayCameraError | ( |  | ) |
| private

Displays the camera error.

## ◆ FillPortsInfo()

void LaserCutter::FillPortsInfo | ( |  | ) |
| private

Fills the COM ports Info.

## ◆ GetImagePositions()

void LaserCutter::GetImagePositions | ( |  | ) |
| private

Acquires the position of each of the images.

The position is with regards to the top left corner [0,0]. All of the images on the image_destination DragWidget instance

## ◆ GetMinimumBoundingRect()

QRectF LaserCutter::GetMinimumBoundingRect | ( | const QRect & | r,
|  | const qreal & | angleRads
| ) |  |
| private

GetMinimumBoundingRect Calculates the minimum bounding box of a rotated image.

Parameters

  r | The bounding box of the image
  angleRads | Angle of rotation

Returns
  Returns the minimum bounding box

## ◆ GetRotatedPoint()

QPointF LaserCutter::GetRotatedPoint | ( | const QPointF & | p,
|  | const QPointF & | center,
|  | const qreal & | angleRads
| ) |  |
| private

GetRotatedPoint Calculates the coordinates of a point rotated around a refernce point.

Parameters

  p | Point being rotated
  center | Point of rotation (reference point)
  angleRads | Angle of rotation on radians

Returns
  Returns the new coordinates of the rotated point

## ◆ GetTransferRatio()

void LaserCutter::GetTransferRatio | ( |  | ) |
| private

Calculates the transform ratio for each axis (px~mm)

## ◆ HotkeysDialog()

void LaserCutter::HotkeysDialog | ( |  | ) |
| private

Creates an instance of the Hotkeys class.(new window)

## ◆ InitCutterInfo()

void LaserCutter::InitCutterInfo | ( |  | ) |
| private

Initializes the cutter parameters.

Initializes the cutter parameters, width and height of the cutting area and the path to the image source folder, from the config.xml file.

## ◆ Initialize

void LaserCutter::Initialize | ( |  | ) |
| private slot

Initialization of the app.

Calls the InitCutterInfo() method to obtain the neccessary paramters. Hands over the camera transmission to the CameraMarkerDetection() method, and later to the PerspectiveTransform() method. Restarts the timers in place. and initializes the spinBox values. If marker detection succeeds, calls SetupUiFrameSize(), GetTransferRatio() methods, creates the Temp folders, calls CopySvgsFromDir(). Connects the neccessary signals.

## ◆ keyReleaseEvent()

void LaserCutter::keyReleaseEvent | ( | QKeyEvent * | event | ) |
| override protected

keyReleaseEvent Overloaded event of the keyRelease handling

The event allows for the usage of hotkeys in the application

Parameters

  event | key release event

## ◆ MatIsEqual()

bool LaserCutter::MatIsEqual | ( | const cv::Mat & | mat1,
|  | const cv::Mat & | mat2
| ) |  |
| private

Determines whether two cv::Mat instances are equal.

Parameters

  mat1 | Matrix A
  mat2 | Matrix B

Returns
  Returns true, if A and B are equal, otherwise false

## ◆ MatToPixmap()

QPixmap LaserCutter::MatToPixmap | ( | cv::Mat | src | ) |
| private

Converts cv::Mat to QPixmap.

Parameters

  src | Source image

Returns
  Returns the converted QPixmap

## ◆ mousePressEvent()

void LaserCutter::mousePressEvent | ( | QMouseEvent * | event | ) |
| override protected

mousePressEvent Overloaded event of the mousePress handling

The press event clears focus (deselects) of the UI components

Parameters

  event | mouse press event

## ◆ OpenFiles()

void LaserCutter::OpenFiles | ( |  | ) |
| private

Opens SVG files from the selected folder.

A dialog window appears wanting to select the source image folder. Clears the TEMP dirs and the image_source, image_destinantion DragWidget instances. Copies the images from the selected folder to the `Temp_img_source` folder

## ◆ PerspectiveTransform

bool LaserCutter::PerspectiveTransform | ( |  | ) |
| private slot

PerspectiveTransform.

Returns

## ◆ Pythagoras()

double LaserCutter::Pythagoras | ( | const cv::Point2d & | aUno,
|  | const cv::Point2d & | aDuo
| ) |  |
| private

Calculates the Euclidian distance between two points in the image.

Parameters

  aUno | Point 1
  aDuo | Point 2

Returns
  Returns the Euclidian distance

## ◆ QImageToMat()

cv::Mat LaserCutter::QImageToMat | ( | const QImage & | inImage,
|  | bool | inCloneImageData = `true`
| ) |  |
| private

Converts QImage to cv::Mat.

Parameters

  inImage | Input QImage
  inCloneImageData | Flag for creatin a copy

Returns
  Returns the converted cv::Mat

## ◆ ResetApp

void LaserCutter::ResetApp | ( |  | ) |
| private slot

Reset of the app.

Stops the perspective transform and reinitializes the app to the default state. Clearing the Temp folders and DragWidget instances.

## ◆ RotateInit()

void LaserCutter::RotateInit | ( | int | aRotate | ) |

Initializes the dial in the ui.

Sets the value of the rotate dial based on the argument of the SvgLabel m_rotate member variable

Parameters

  aRotate | Value used as the initializer

## ◆ RotateLabel()

void LaserCutter::RotateLabel | ( |  | ) |
| private

RotateLabel Rotates an SvgLabel.

Rotates the currently selected SvgLabels. Uses the `GetMinimumBoundingRect` method to calculate the dimensions of the bounding box. Moves the SvgLabel by the offset regarding the rotation. Utilizes `QTransform` (affine transformation) to rotate the SvgLabel.

## ◆ SaveXML_copies()

void LaserCutter::SaveXML_copies | ( |  | ) |
| private

Saves the currently displayed SvgLabels.

Copies each displayed SvgLabel from the `Temp_img_source` to the `Temp_img` folder. Edits the SVG file according to the applied transformation (transfrom matrix)

## ◆ SetCamera()

void LaserCutter::SetCamera | ( | const QCameraInfo & | cameraInfo | ) |
| private

Sets the Camera.

Sets the currently selected camera and displays the transmission

Parameters

  cameraInfo | Neccessary camera info

## ◆ SetImageSource()

void LaserCutter::SetImageSource | ( | QString | aPath | ) |
| private

Sets up the image_source DragWidget instance.

Places each QLabel to image_source DragWidget instance. Maximum of 60 images.

Parameters

  aPath | Path to the image.

## ◆ SetupUiFrameSize()

void LaserCutter::SetupUiFrameSize | ( |  | ) |
| private

Sets up the dimensions of the `camera` frame and the `image_destination` DragWidget instance.

## ◆ ShowManual()

void LaserCutter::ShowManual | ( |  | ) |
| private

Shows the user manual.

## ◆ ShowPortInfo

void LaserCutter::ShowPortInfo | ( | int | idx | ) |
| private slot

Shows the ports info based on the idx.

Parameters

  idx | Index of the list (COM port)

## ◆ SvgLabelInfo()

void LaserCutter::SvgLabelInfo | ( | const SvgLabel & | aSlabel | ) |

Obtains the information about the SvgLabel instance.

Acquires the position of the SvgLabel within the bounds of the cutting area(camera frame). Position "x", position "y" and rotation of the SvgLabel The parameters are shown in the UI. Positions are calculated with regards to the top left corner [0,0].

Parameters

  aSlabel | The Targeted SvgLabel

## ◆ TrackMaterial()

void LaserCutter::TrackMaterial | ( | bool | tracking_enabled | ) |
| private

Track the material.

Tracks the centroid of the conours (= material) and moves all the images based on the difference with the previous centroid position

Parameters

  tracking_enabled | Flag for enabling the tracking

## ◆ Transform_to_normalized()

void LaserCutter::Transform_to_normalized | ( | double * | aTransform_ratio,
|  | QLabel & | label
| ) |  |
| private

Normalizes a QLabel's dimensions.

Utilizes the QTransform class to apply the scale transform

Parameters

  aTransform_ratio | Transform ratio used for each axis (x,y)
  label | The QLabel to be transformed

## ◆ UpdateCameraDevice()

void LaserCutter::UpdateCameraDevice | ( | QAction * | action | ) |
| private

Updates the camera device on action trigger.

Parameters

  action | Trigger for the method (change of the camera in the Devices menu)

## ◆ UpdateCamerasMenu()

void LaserCutter::UpdateCamerasMenu | ( |  | ) |
| private

Updates the Devices menu when it is about to show.

## Member Data Documentation

## ◆ final_port

QString LaserCutter::final_port
| private

Selected COM port, used for the Svg2GcodeSend as an argument.

## ◆ inputVideo

cv::VideoCapture LaserCutter::inputVideo
| private

Used for Camera Hanlding, after the start of the application.

## ◆ m_camera

QScopedPointer<QCamera> LaserCutter::m_camera
| private

Used for Camera Hanlding, before the start of the application.

## ◆ m_CamInfo

struct LaserCutter::sCamera LaserCutter::m_CamInfo
| private

## ◆ m_centroid

QPoint LaserCutter::m_centroid
| private

New position of the tracked centroid.

## ◆ m_corners

std::vector<cv::Point_<double> > LaserCutter::m_corners
| private

Holds the position of the ArucoMarker's corners (corners with index 0)

## ◆ m_cutting_area

std::vector<double> LaserCutter::m_cutting_area
| private

Cutting area dimensions of the laser cutter (width, height)

## ◆ m_dimensions

QSize LaserCutter::m_dimensions
| private

Dimensions of the cutting area.

## ◆ m_hotkeys

Hotkeys* LaserCutter::m_hotkeys
| private

Pointer to the Hotkeys class instance.

## ◆ m_image_source_counter

size_t LaserCutter::m_image_source_counter
| private

Holds the counter for the image placement.

## ◆ m_img_source_placement

std::array<size_t,2> LaserCutter::m_img_source_placement
| private

Utilized for placing the image in the image_source DragWidget instance.

## ◆ m_label_tab_index

int LaserCutter::m_label_tab_index
| private

Used for cycling through the SvgLabel instances by pressing 'Tab'.

## ◆ m_old_centroid

QPoint LaserCutter::m_old_centroid
| private

Old position of the tracked centroid.

## ◆ m_Path_to_source

QString LaserCutter::m_Path_to_source
| private

Holds the path to the folder of the source images.

## ◆ m_process_cut

QProcess* LaserCutter::m_process_cut
| private

Pointer to the Svg2GcodeSend process.

## ◆ m_res

std::vector<QString> LaserCutter::m_res
| private

Vector of paths to the source images.

## ◆ m_rotate

int LaserCutter::m_rotate
| private

Rotation of the currently selected SvgLabel instance.

## ◆ m_timer

QTimer* LaserCutter::m_timer
| private

Timer, its timeout used to call PerspectiveTransform()

## ◆ m_tm

QElapsedTimer* LaserCutter::m_tm
| private

Timer used for PerspectiveTransform()

## ◆ m_tracking_flag

bool LaserCutter::m_tracking_flag
| private

## ◆ m_transfer_ratio

double LaserCutter::m_transfer_ratio[2]
| private

Transform ratio of px~mm for each axis (x;y)

## ◆ m_videoDevicesGroup

QActionGroup* LaserCutter::m_videoDevicesGroup
| private

ActionGroup for the Devices menu.

## ◆ ui

Ui::LaserCutter* LaserCutter::ui
| private

The documentation for this class was generated from the following files:

- lasercutter.h
- lasercutter.cpp