Ocean
Loading...
Searching...
No Matches
SVGImage.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_CV_CALIBRATION_SVG_IMAGE_H
9#define META_OCEAN_CV_CALIBRATION_SVG_IMAGE_H
10
14
15#include <iostream>
16
17namespace Ocean
18{
19
20namespace CV
21{
22
23namespace Calibration
24{
25
26/**
27 * This class implements functions to write SVG images.
28 * @ingroup cvcalibration
29 */
30class OCEAN_CV_CALIBRATION_EXPORT SVGImage
31{
32 public:
33
34 /**
35 * Writes a SVG image with a calibration board.
36 * @param filename The filename of the SVG image to be written, must be valid
37 * @param width The width of the image (or the paper the image is printed on), must be valid
38 * @param height The height of the image (or the paper the image is printed on), must be valid
39 * @param calibrationBoard The calibration board from which the SVG image will be created, must be valid
40 * @param unitType The unit type which will be used in the resulting SVG image, must be valid
41 * @param precision The number of decimal places to use, with range [0, infinity)
42 * @param debugImage True, to create a debug image with additional information
43 * @param centerDot True, to add a dot in the center of the calibration board (e.g., for manual calibration)
44 * @return True, if succeeded
45 */
46 static bool writeCalibrationBoardImage(const std::string& filename, const MetricSize& width, const MetricSize& height, const CalibrationBoard& calibrationBoard, const MetricSize::UnitType unitType = MetricSize::UT_MILLIMETER, const unsigned int precision = 4u, const bool debugImage = false, const bool centerDot = false);
47
48 /**
49 * Writes a SVG test image holding all possible markers.
50 * @param filename The filename of the SVG image to be written, must be valid
51 * @param width The width of the image (or the paper the image is printed on), must be valid
52 * @param height The height of the image (or the paper the image is printed on), must be valid
53 * @param sign True, to create an image with black points (and white markers); False, to create an image with white points (and black markers)
54 * @param unitType The unit type which will be used in the resulting SVG image, must be valid
55 * @param precision The number of decimal places to use, with range [0, infinity)
56 * @return True, if succeeded
57 */
58 static bool writeMarkerTestImage(const std::string& filename, const MetricSize& width, const MetricSize& height, const bool sign = true, const MetricSize::UnitType unitType = MetricSize::UT_MILLIMETER, const unsigned int precision = 4u);
59
60 /**
61 * Write a SVG test image showing points with different sizes.
62 * @param filename The filename of the SVG image to be written, must be valid
63 * @param width The width of the image (or the paper the image is printed on), must be valid
64 * @param height The height of the image (or the paper the image is printed on), must be valid
65 * @param unitType The unit type which will be used in the resulting SVG image, must be valid
66 * @param precision The number of decimal places to use, with range [0, infinity)
67 * @return True, if succeeded
68 */
69 static bool writePointTestImage(const std::string& filename, const MetricSize& width, const MetricSize& height, const MetricSize::UnitType unitType = MetricSize::UT_MILLIMETER, const unsigned int precision = 4u);
70
71 protected:
72
73 /**
74 * Writes the SVG version to the SVG file.
75 * @param stream The stream to which the SVG image will be written, must be valid
76 * @param majorVersion The major version of the SVG image, with range [1, infinity)
77 * @param minorVersion The minor version of the SVG image, with range [0, infinity)
78 * @return True, if succeeded
79 */
80 static bool writeVersion(std::ostream& stream, const unsigned int majorVersion = 1u, const unsigned int minorVersion = 1u);
81
82 /**
83 * Writes a value to the SVG file.
84 * @param stream The stream to which the SVG image will be written, must be valid
85 * @param name The name of the value, must be valid
86 * @param value The value to be written, must be valid
87 * @param unitType The unit type which will be used, must be valid
88 * @param precision The number of decimal places to use, with range [0, infinity)
89 * @return True, if succeeded
90 */
91 static bool writeValue(std::ostream& stream, const std::string& name, const MetricSize& value, const MetricSize::UnitType unitType, const unsigned int precision);
92
93 /**
94 * Writes a value to the SVG file.
95 * @param stream The stream to which the SVG image will be written, must be valid
96 * @param name The name of the value, must be valid
97 * @param value The value to be written, must be valid
98 * @return True, if succeeded
99 */
100 static bool writeValue(std::ostream& stream, const std::string& name, const std::string& value);
101
102 /**
103 * Writes a position to the SVG file.
104 * @param stream The stream to which the SVG image will be written, must be valid
105 * @param x The x value of the position, must be valid
106 * @param y The y value of the position, must be valid
107 * @param unitType The unit type which will be used, must be valid
108 * @param precision The number of decimal places to use, with range [0, infinity)
109 * @param xName The name of the x value, must be valid
110 * @param yName The name of the y value, must be valid
111 * @return True, if succeeded
112 */
113 static bool writePosition(std::ostream& stream, const MetricSize& x, const MetricSize& y, const MetricSize::UnitType unitType, const unsigned int precision, const std::string& xName = "x", const std::string& yName = "y");
114
115 /**
116 * Writes a size/dimension to the SVG file.
117 * @param stream The stream to which the SVG image will be written, must be valid
118 * @param width The width of the size, must be valid
119 * @param height The height of the size, must be valid
120 * @param unitType The unit type which will be used, must be valid
121 * @param precision The number of decimal places to use, with range [0, infinity)
122 * @param widthName The name of the width value, must be valid
123 * @param heightName The name of the height value, must be valid
124 * @return True, if succeeded
125 */
126 static bool writeSize(std::ostream& stream, const MetricSize& width, const MetricSize& height, const MetricSize::UnitType unitType, const unsigned int precision, const std::string& widthName = "width", const std::string& heightName = "height");
127
128 /**
129 * Writes a rectangle to the SVG file.
130 * @param stream The stream to which the SVG image will be written, must be valid
131 * @param indentation The optional indentation within the SVG file when writing the text, can be empty
132 * @param left The left position of the rectangle, must be valid
133 * @param top The top position of the rectangle, must be valid
134 * @param width The width of the rectangle, must be valid
135 * @param height The height of the rectangle, must be valid
136 * @param color The filling color of the rectangle, must be valid
137 * @param unitType The unit type which will be used, must be valid
138 * @param precision The number of decimal places to use, with range [0, infinity)
139 * @return True, if succeeded
140 */
141 static bool writeRectangle(std::ostream& stream, const std::string& indentation, const MetricSize& left, const MetricSize& top, const MetricSize& width, const MetricSize& height, const std::string& color, const MetricSize::UnitType unitType, const unsigned int precision);
142
143 /**
144 * Writes a circle to the SVG file.
145 * @param stream The stream to which the SVG image will be written, must be valid
146 * @param indentation The optional indentation within the SVG file when writing the text, can be empty
147 * @param x The x position of the center of the circle, must be valid
148 * @param y The y position of the center of the circle, must be valid
149 * @param radius The radius of the circle, must be valid
150 * @param color The filling color of the circle, must be valid
151 * @param unitType The unit type which will be used, must be valid
152 * @param precision The number of decimal places to use, with range [0, infinity)
153 * @return True, if succeeded
154 */
155 static bool writeCircle(std::ostream& stream, const std::string& indentation, const MetricSize& x, const MetricSize& y, const MetricSize& radius, const std::string& color, const MetricSize::UnitType unitType, const unsigned int precision);
156
157 /**
158 * Writes a line to the SVG file.
159 * @param stream The stream to which the SVG image will be written, must be valid
160 * @param indentation The optional indentation within the SVG file when writing the text, can be empty
161 * @param x1 The x position of the start of the line, must be valid
162 * @param y1 The y position of the start of the line, must be valid
163 * @param x2 The x position of the end of the line, must be valid
164 * @param y2 The y position of the end of the line, must be valid
165 * @param thickness The thickness of the line, must be valid
166 * @param color The color of the line, must be valid
167 * @param unitType The unit type which will be used, must be valid
168 * @param precision The number of decimal places to use, with range [0, infinity)
169 * @return True, if succeeded
170 */
171 static bool writeLine(std::ostream& stream, const std::string& indentation, const MetricSize& x1, const MetricSize& y1, const MetricSize& x2, const MetricSize& y2, const MetricSize& thickness, const std::string& color, const MetricSize::UnitType unitType, const unsigned int precision);
172
173 /**
174 * Writes a text to the SVG file.
175 * @param stream The stream to which the SVG image will be written, must be valid
176 * @param indentation The optional indentation within the SVG file when writing the text, can be empty
177 * @param text The text to be written, must be valid
178 * @param x The x position of the text, must be valid
179 * @param y The y position of the text, must be valid
180 * @param size The size of the text, must be valid
181 * @param color The color of the text, must be valid
182 * @param unitType The unit type which will be used, must be valid
183 * @param precision The number of decimal places to use, with range [0, infinity)
184 * @param fontFamily The font family of the text, can be empty
185 * @return True, if succeeded
186 */
187 static bool writeText(std::ostream& stream, const std::string& indentation, const std::string& text, const MetricSize& x, const MetricSize& y, const MetricSize& size, const std::string& color, const MetricSize::UnitType unitType, const unsigned int precision, const std::string& fontFamily = std::string());
188
189 /**
190 * Writes a comment to the SVG file.
191 * @param stream The stream to which the SVG image will be written, must be valid
192 * @param indentation The optional indentation within the SVG file when writing the markers, can be empty
193 * @param comment The comment to be written, must be valid
194 */
195 static bool writeComment(std::ostream& stream, const std::string& indentation, const std::string& comment);
196
197 /**
198 * Writes the board markers of a calibration board to the SVG file.
199 * @param stream The stream to which the SVG image will be written, must be valid
200 * @param indentation The optional indentation within the SVG file when writing the markers, can be empty
201 * @param boardMarkers The board markers to be written, must be valid
202 * @param left The left position of the first marker, must be valid
203 * @param top The top position of the first marker, must be valid
204 * @param markerSize The size of the markers (the edge length of each marker), must be valid
205 * @param dotRadius The radius of the dots within the markers, must be valid
206 * @param unitType The unit type which will be used in the resulting SVG image, must be valid
207 * @param precision The number of decimal places to use, with range [0, infinity)
208 * @param debugMarker True, to create a debug marker with additional information
209 * @return True, if succeeded
210 */
211 static bool writeBoardMarker(std::ostream& stream, const std::string& indentation, const CalibrationBoard::BoardMarker& boardMarker, const MetricSize& left, const MetricSize& top, const MetricSize& markerSize, const MetricSize& dotRadius, const MetricSize::UnitType unitType, const unsigned int precision, const bool debugMarker = false);
212
213 /**
214 * Writes four measurement indications at the corners of a calibration board.
215 * @param stream The stream to which the SVG image will be written, must be valid
216 * @param indentation The optional indentation within the SVG file when writing the measurement indications, can be empty
217 * @param markersWidth The width of all markers, must be valid
218 * @param markersHeight The height of all markers, must be valid
219 * @param padding The padding around the markers (the offset between indication and marker), must be valid
220 * @param markerStartLeft The left position of the first marker, must be valid
221 * @param markerStartTop The top position of the first marker, must be valid
222 * @param measurementIndicationSize The size/length of the measurement indications, must be valid
223 * @param measurementIndicationThickness The thickness of the measurement indications, must be valid
224 * @param color The color of the measurement indications, must be valid
225 * @param unitType The unit type which will be used in the resulting SVG image, must be valid
226 * @param precision The number of decimal places to use, with range [0, infinity)
227 * @return True, if succeeded
228 */
229 static bool writeMeasurementIndication(std::ostream& stream, const std::string& indentation, const MetricSize& markersWidth, const MetricSize& markersHeight, const MetricSize& padding, const MetricSize& markerStartLeft, const MetricSize& markerStartTop, const MetricSize& measurementIndicationSize, const MetricSize& measurementIndicationThickness, const std::string& color, const MetricSize::UnitType unitType, const unsigned int precision);
230};
231
232}
233
234}
235
236}
237
238#endif // META_OCEAN_CV_CALIBRATION_SVG_IMAGE_H
This class implements a marker in a calibration board.
Definition CalibrationBoard.h:50
This class implements a basic calibration board.
Definition CalibrationBoard.h:38
This class implements an object holding a metric size like width, height, length, or thickness.
Definition MetricSize.h:32
UnitType
Definition of different unit types.
Definition MetricSize.h:39
This class implements functions to write SVG images.
Definition SVGImage.h:31
static bool writeRectangle(std::ostream &stream, const std::string &indentation, const MetricSize &left, const MetricSize &top, const MetricSize &width, const MetricSize &height, const std::string &color, const MetricSize::UnitType unitType, const unsigned int precision)
Writes a rectangle to the SVG file.
static bool writeBoardMarker(std::ostream &stream, const std::string &indentation, const CalibrationBoard::BoardMarker &boardMarker, const MetricSize &left, const MetricSize &top, const MetricSize &markerSize, const MetricSize &dotRadius, const MetricSize::UnitType unitType, const unsigned int precision, const bool debugMarker=false)
Writes the board markers of a calibration board to the SVG file.
static bool writeMarkerTestImage(const std::string &filename, const MetricSize &width, const MetricSize &height, const bool sign=true, const MetricSize::UnitType unitType=MetricSize::UT_MILLIMETER, const unsigned int precision=4u)
Writes a SVG test image holding all possible markers.
static bool writePosition(std::ostream &stream, const MetricSize &x, const MetricSize &y, const MetricSize::UnitType unitType, const unsigned int precision, const std::string &xName="x", const std::string &yName="y")
Writes a position to the SVG file.
static bool writeValue(std::ostream &stream, const std::string &name, const MetricSize &value, const MetricSize::UnitType unitType, const unsigned int precision)
Writes a value to the SVG file.
static bool writeText(std::ostream &stream, const std::string &indentation, const std::string &text, const MetricSize &x, const MetricSize &y, const MetricSize &size, const std::string &color, const MetricSize::UnitType unitType, const unsigned int precision, const std::string &fontFamily=std::string())
Writes a text to the SVG file.
static bool writeCalibrationBoardImage(const std::string &filename, const MetricSize &width, const MetricSize &height, const CalibrationBoard &calibrationBoard, const MetricSize::UnitType unitType=MetricSize::UT_MILLIMETER, const unsigned int precision=4u, const bool debugImage=false, const bool centerDot=false)
Writes a SVG image with a calibration board.
static bool writeSize(std::ostream &stream, const MetricSize &width, const MetricSize &height, const MetricSize::UnitType unitType, const unsigned int precision, const std::string &widthName="width", const std::string &heightName="height")
Writes a size/dimension to the SVG file.
static bool writeMeasurementIndication(std::ostream &stream, const std::string &indentation, const MetricSize &markersWidth, const MetricSize &markersHeight, const MetricSize &padding, const MetricSize &markerStartLeft, const MetricSize &markerStartTop, const MetricSize &measurementIndicationSize, const MetricSize &measurementIndicationThickness, const std::string &color, const MetricSize::UnitType unitType, const unsigned int precision)
Writes four measurement indications at the corners of a calibration board.
static bool writeCircle(std::ostream &stream, const std::string &indentation, const MetricSize &x, const MetricSize &y, const MetricSize &radius, const std::string &color, const MetricSize::UnitType unitType, const unsigned int precision)
Writes a circle to the SVG file.
static bool writeVersion(std::ostream &stream, const unsigned int majorVersion=1u, const unsigned int minorVersion=1u)
Writes the SVG version to the SVG file.
static bool writeComment(std::ostream &stream, const std::string &indentation, const std::string &comment)
Writes a comment to the SVG file.
static bool writeLine(std::ostream &stream, const std::string &indentation, const MetricSize &x1, const MetricSize &y1, const MetricSize &x2, const MetricSize &y2, const MetricSize &thickness, const std::string &color, const MetricSize::UnitType unitType, const unsigned int precision)
Writes a line to the SVG file.
static bool writePointTestImage(const std::string &filename, const MetricSize &width, const MetricSize &height, const MetricSize::UnitType unitType=MetricSize::UT_MILLIMETER, const unsigned int precision=4u)
Write a SVG test image showing points with different sizes.
static bool writeValue(std::ostream &stream, const std::string &name, const std::string &value)
Writes a value to the SVG file.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15