FuncSketch
Loading...
Searching...
No Matches
plotting_util.cpp File Reference

Implementation of functions for internal implementation of plotting. More...

#include "func_sketch/plotter/plotting_util.h"
#include <cassert>
#include <cmath>
#include <opencv2/imgproc.hpp>
#include "func_sketch/common_types.h"
#include "func_sketch/exceptions.h"
Include dependency graph for plotting_util.cpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

cv::Scalar func_sketch::plotter::convert_color (const RGBColor &color)
 Convert a color from RGBColor to cv::Scalar.
cv::Point func_sketch::plotter::convert_position (const Point &position, const PlotRange &range, const PlotConfig &config, int left_margin, const cv::MatSize &size)
 Convert a position from plot coordinates to image coordinates.
cv::Point func_sketch::plotter::convert_position_with_shift (const Point &position, const PlotRange &range, const PlotConfig &config, int left_margin, const cv::MatSize &size, int shift)
 Convert a position from plot coordinates to image coordinates with shift.
void func_sketch::plotter::write_line (Image &image, const Point &start_point, const Point &end_point, const cv::Scalar &color, int line_width, const PlotRange &range, const PlotConfig &config, int left_margin)
 Write a line on an image.
bool func_sketch::plotter::try_clamp_infinity (Point &point, const PlotRange &range)
 Try to clamp a point with infinity to the range.
Point func_sketch::plotter::compute_intersection_with_vertical_line (const Point &point1, const Point &point2, Real x_value)
 Compute the intersection of a line segment with a vertical line.
Point func_sketch::plotter::compute_intersection_with_horizontal_line (const Point &point1, const Point &point2, Real y_value)
 Compute the intersection of a line segment with a horizontal line.
Point func_sketch::plotter::compute_intersection_with_range (const Point &point_in_range, const Point &point_out_of_range, const PlotRange &range)
 Compute the intersection of a line segment with the boundary of the plot range.

Detailed Description

Implementation of functions for internal implementation of plotting.

Definition in file plotting_util.cpp.

Function Documentation

◆ convert_color()

cv::Scalar func_sketch::plotter::convert_color ( const RGBColor & color)
nodiscard

Convert a color from RGBColor to cv::Scalar.

Parameters
[in]colorColor to convert.
Returns
Converted color.
Note
This function assumes that the image is in RGB format, not BGR format as in default of OpenCV.

Definition at line 32 of file plotting_util.cpp.

◆ convert_position()

cv::Point func_sketch::plotter::convert_position ( const Point & position,
const PlotRange & range,
const PlotConfig & config,
int left_margin,
const cv::MatSize & size )
nodiscard

Convert a position from plot coordinates to image coordinates.

Parameters
[in]positionPosition in plot coordinates.
[in]rangeRange of plots.
[in]configConfiguration of plots.
[in]left_marginLeft margin of plots in pixels. (This value is used over the value in config because tuning of the left margin is needed.)
[in]sizeSize of the image.
Returns
Converted position in image coordinates.

Definition at line 37 of file plotting_util.cpp.

◆ convert_position_with_shift()

cv::Point func_sketch::plotter::convert_position_with_shift ( const Point & position,
const PlotRange & range,
const PlotConfig & config,
int left_margin,
const cv::MatSize & size,
int shift )
nodiscard

Convert a position from plot coordinates to image coordinates with shift.

Parameters
[in]positionPosition in plot coordinates.
[in]rangeRange of plots.
[in]configConfiguration of plots.
[in]left_marginLeft margin of plots in pixels. (This value is used over the value in config because tuning of the left margin is needed.)
[in]sizeSize of the image.
[in]shiftNumber of fractional bits in the image coordinates.
Returns
Converted position in image coordinates.

Definition at line 72 of file plotting_util.cpp.

◆ write_line()

void func_sketch::plotter::write_line ( Image & image,
const Point & start_point,
const Point & end_point,
const cv::Scalar & color,
int line_width,
const PlotRange & range,
const PlotConfig & config,
int left_margin )

Write a line on an image.

Parameters
[out]imageImage to write on.
[in]start_pointStarting point of the line.
[in]end_pointEnding point of the line.
[in]colorColor of the line.
[in]line_widthWidth of the line.
[in]rangeRange of plots.
[in]configConfiguration of plots.
[in]left_marginLeft margin of plots in pixels. (This value is used over the value in config because tuning of the left margin is needed.)

Definition at line 101 of file plotting_util.cpp.

◆ try_clamp_infinity()

bool func_sketch::plotter::try_clamp_infinity ( Point & point,
const PlotRange & range )
nodiscard

Try to clamp a point with infinity to the range.

Parameters
[in,out]pointPoint to clamp.
[in]rangeRange to clamp the point to.
Return values
trueThe point was clamped or the point was finite.
falseThe point could not be clamped because it was infinite in both coordinates.
Note
This function does not check for NaN values.

Definition at line 114 of file plotting_util.cpp.

◆ compute_intersection_with_vertical_line()

Point func_sketch::plotter::compute_intersection_with_vertical_line ( const Point & point1,
const Point & point2,
Real x_value )

Compute the intersection of a line segment with a vertical line.

Parameters
[in]point1First point of the line segment.
[in]point2Second point of the line segment.
[in]x_valueX-coordinate of the vertical line.
Returns
Intersection point of the line segment with the vertical line.

Definition at line 137 of file plotting_util.cpp.

◆ compute_intersection_with_horizontal_line()

Point func_sketch::plotter::compute_intersection_with_horizontal_line ( const Point & point1,
const Point & point2,
Real y_value )

Compute the intersection of a line segment with a horizontal line.

Parameters
[in]point1First point of the line segment.
[in]point2Second point of the line segment.
[in]y_valueY-coordinate of the horizontal line.
Returns
Intersection point of the line segment with the horizontal line.

Definition at line 153 of file plotting_util.cpp.

◆ compute_intersection_with_range()

Point func_sketch::plotter::compute_intersection_with_range ( const Point & point_in_range,
const Point & point_out_of_range,
const PlotRange & range )
nodiscard

Compute the intersection of a line segment with the boundary of the plot range.

Parameters
[in]point_in_rangePoint inside the range.
[in]point_out_of_rangePoint outside the range.
[in]rangeRange of plots.
Returns
Intersection point of the line segment with the range.
Note
This function assumes that all coordinates are finite and that the line segment intersects with the boundary of the range.

Definition at line 161 of file plotting_util.cpp.