Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SVG] module refactoring #2157

Merged
merged 3 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions docs/sphinx/rst/openMVG/other/vectorDrawing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Vector drawing
*******************

openMVG considers that visualizing data is important. OpenMVG provides a class that help to perform vector graphics (SVG) drawing in order to have the best possible visualization of his algorithm output. Vector graphics allows keeping details when you zoom what is not done when you use raster graphics. (SVG files are supported by web navigator and the Inkscape software).
openMVG considers that visualizing data is important. OpenMVG provides a class that help to perform vector graphics (SVG) drawing in order to have the best possible visualization of his algorithm output. Vector graphics allows keeping details when you zoom what is not done when you use raster graphics. (SVG files are supported by web navigator and the Inkscape software).

.. code-block:: c++

Expand All @@ -20,22 +20,21 @@ openMVG considers that visualizing data is important. OpenMVG provides a class t
}
// Create a svg surface and add the cardiod polyline
svgDrawer svgSurface (6 *S, 6 *S); //Create a svg object
svgSurface.drawPolyline (
vec_x.begin( ) , vec_x.end( ),
vec_y.begin( ) , vec_y.end( ),
svgStyle( ).stroke( "blue", 2));
svgSurface << drawPolyline (
vec_x.cbegin() , vec_x.cend(),
vec_y.cbegin() , vec_y.cend(),
svgAttributes().stroke( "blue", 2));

//Export the SVG stream to a file
std::string sFileName = "ThirdExample.svg";
std::ofstream svgFile ( sFileName.c_str( ));
svgFile << svgSurface.closeSvgFile( ).str( );
svgFile.close( );
std::ofstream svgFile ( sFileName.c_str() );
svgFile << svgSurface.closeSvgFile().str();
svgFile.close();
}

Here the result exported vector graphic:

.. figure:: vectorGraphic.png
:align: center
:alt: alternate text
:figclass: align-center

1 change: 1 addition & 0 deletions src/openMVG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_subdirectory(spherical)
add_subdirectory(system)
add_subdirectory(sfm)
add_subdirectory(stl)
add_subdirectory(vector_graphics)

#INSTALL RULES
install(
Expand Down
10 changes: 5 additions & 5 deletions src/openMVG/features/sift/sift_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "openMVG/features/sift/SIFT_Anatomy_Image_Describer.hpp"
#include "openMVG/image/image_io.hpp"
#include "openMVG/system/timer.hpp"
#include "third_party/vectorGraphics/svgDrawer.hpp"
#include "openMVG/vector_graphics/svgDrawer.hpp"

#include "testing/testing.h"

Expand Down Expand Up @@ -102,14 +102,14 @@ TEST( Sift_Keypoint , DetectionAndDescription )
//--
using namespace svg;
svgDrawer svgStream( image.Width(), image.Height());
svgStream.drawImage(png_filename, image.Width(), image.Height());
svgStream << svg::drawImage(png_filename, image.Width(), image.Height());
for (size_t i = 0; i < keypoints.size(); ++i) {
const Keypoint & key = keypoints[i];
svgStream.drawCircle(key.x, key.y, key.sigma, svgStyle().stroke("yellow", 2.0));
svgStream << svg::drawCircle(key.x, key.y, key.sigma, svgAttributes().stroke("yellow", 2.0));
// Orientation
svgStream.drawLine(key.x, key.y,
svgStream << svg::drawLine(key.x, key.y,
key.x + cos(key.sigma) * key.sigma,
key.y + sin(key.sigma) * key.sigma, svgStyle().stroke("green", 2.0));
key.y + sin(key.sigma) * key.sigma, svgAttributes().stroke("green", 2.0));
}
std::string out_filename = "Sift_Features.svg";
std::ofstream svgFile( out_filename );
Expand Down
38 changes: 19 additions & 19 deletions src/openMVG/features/svg_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <openMVG/features/svg_features.hpp>
#include <openMVG/system/logger.hpp>
#include "third_party/vectorGraphics/svgDrawer.hpp"
#include "openMVG/vector_graphics/svgDrawer.hpp"

namespace openMVG {
namespace features {
Expand All @@ -26,14 +26,14 @@ bool Features2SVG
svg::svgDrawer svgStream(image_size.first, image_size.second);

// Draw image
svgStream.drawImage(image_path, image_size.first, image_size.second);
svgStream << svg::drawImage(image_path, image_size.first, image_size.second);

// Draw features
for (const features::PointFeature & feat_it : features) {
// Draw the feature (circle)
svgStream.drawCircle(
svgStream << svg::drawCircle(
feat_it.x(), feat_it.y(), feature_circle_radius,
svg::svgStyle().stroke("yellow", stroke_size));
svg::svgAttributes().stroke("yellow", stroke_size));
}

// Save the SVG file
Expand All @@ -60,14 +60,14 @@ bool Features2SVG
svg::svgDrawer svgStream(image_size.first, image_size.second);

// Draw image
svgStream.drawImage(image_path, image_size.first, image_size.second);
svgStream << svg::drawImage(image_path, image_size.first, image_size.second);

// Draw features
for (const features::SIOPointFeature & feat_it : features) {
// Draw the feature (circle)
svgStream.drawCircle(
svgStream << svg::drawCircle(
feat_it.x(), feat_it.y(), feat_it.scale(),
svg::svgStyle().stroke("yellow", stroke_size));
svg::svgAttributes().stroke("yellow", stroke_size));
}

// Save the SVG file
Expand Down Expand Up @@ -116,21 +116,21 @@ bool Features2SVG
svg::svgDrawer svgStream(svg_w, svg_h);

// Draw image side by side
svgStream.drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream.drawImage(right_image_path, right_image_size.first, right_image_size.second,
svgStream << svg::drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream << svg::drawImage(right_image_path, right_image_size.first, right_image_size.second,
b_vertical_display ? 0 : left_image_size.first,
b_vertical_display ? left_image_size.second : 0);

// Display feature circles
for (const features::PointFeature & feat_it : left_features) {
svgStream.drawCircle(
svgStream << svg::drawCircle(
feat_it.x(), feat_it.y(), feature_circle_radius,
svg::svgStyle().stroke("yellow", stroke_size));
svg::svgAttributes().stroke("yellow", stroke_size));
}
for (const features::PointFeature & feat_it : right_features) {
svgStream.drawCircle(
svgStream << svg::drawCircle(
feat_it.x() + svg_offset_x, feat_it.y() + svg_offset_y, feature_circle_radius,
svg::svgStyle().stroke("yellow", stroke_size));
svg::svgAttributes().stroke("yellow", stroke_size));
}

// Save the SVG file
Expand Down Expand Up @@ -178,21 +178,21 @@ bool Features2SVG
svg::svgDrawer svgStream(svg_w, svg_h);

// Draw image side by side
svgStream.drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream.drawImage(right_image_path, right_image_size.first, right_image_size.second,
svgStream << svg::drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream << svg::drawImage(right_image_path, right_image_size.first, right_image_size.second,
b_vertical_display ? 0 : left_image_size.first,
b_vertical_display ? left_image_size.second : 0);

// Display feature circles
for (const features::SIOPointFeature & feat_it : left_features) {
svgStream.drawCircle(
svgStream << svg::drawCircle(
feat_it.x(), feat_it.y(), feat_it.scale(),
svg::svgStyle().stroke("yellow", stroke_size));
svg::svgAttributes().stroke("yellow", stroke_size));
}
for (const features::SIOPointFeature & feat_it : right_features) {
svgStream.drawCircle(
svgStream << svg::drawCircle(
feat_it.x() + svg_offset_x, feat_it.y() + svg_offset_y, feat_it.scale(),
svg::svgStyle().stroke("yellow", stroke_size));
svg::svgAttributes().stroke("yellow", stroke_size));
}

// Save the SVG file
Expand Down
31 changes: 15 additions & 16 deletions src/openMVG/matching/pairwiseAdjacencyDisplay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "openMVG/matching/indMatch.hpp"
#include "openMVG/graphics/color_gradient.hpp"
#include "third_party/vectorGraphics/svgDrawer.hpp"
#include "openMVG/vector_graphics/svgDrawer.hpp"

namespace openMVG {
namespace matching {
Expand Down Expand Up @@ -45,36 +45,35 @@ void PairWiseMatchingToAdjacencyMatrixSVG
auto iterSearch = map_Matches.find({I,J});
if (iterSearch != map_Matches.end() && !iterSearch->second.empty())
{
// Display as a tooltip: "(IndexI, IndexJ NbMatches)"
std::ostringstream os_tooltip;
os_tooltip << "(" << J << "," << I << " " << iterSearch->second.size() <<")";

// Display as a tooltip: (IndexI, IndexJ NbMatches)
std::ostringstream os;
os << "(" << J << "," << I << " " << iterSearch->second.size() <<")";
float r,g,b;
heatMapGradient.getColor(iterSearch->second.size() / max_match_count, r, g, b);
std::ostringstream os_color;
os_color << "rgb(" << int(r * 255) << "," << int(g * 255) << "," << int(b * 255) << ")";

svgStream.drawSquare(J*scaleFactor, I*scaleFactor, scaleFactor/2.0f,
svg::svgStyle().fill(os_color.str()).noStroke().tooltip(os_tooltip.str()));
}
svgStream << svg::drawSquare(J*scaleFactor, I*scaleFactor, scaleFactor/2.0f,
svg::svgAttributes().fill(os_color.str()).noStroke());
} // HINT : THINK ABOUT OPACITY [0.4 -> 1.0] TO EXPRESS MATCH COUNT
}
}
// Display axes with 0 -> NbImages annotation : _|
std::ostringstream osNbImages;
osNbImages << NbImages;
svgStream.drawText((NbImages+1)*scaleFactor, scaleFactor, scaleFactor, "0", "black");
svgStream.drawText((NbImages+1)*scaleFactor,
svgStream << svg::drawText((NbImages+1)*scaleFactor, scaleFactor, scaleFactor, "0", "black");
svgStream << svg::drawText((NbImages+1)*scaleFactor,
(NbImages)*scaleFactor - scaleFactor, scaleFactor, osNbImages.str(), "black");
svgStream.drawLine((NbImages+1)*scaleFactor, 2*scaleFactor,
svgStream << svg::drawLine((NbImages+1)*scaleFactor, 2*scaleFactor,
(NbImages+1)*scaleFactor, (NbImages)*scaleFactor - 2*scaleFactor,
svg::svgStyle().stroke("black", 1.0));
svg::svgAttributes().stroke("black", 1.0));

svgStream.drawText(scaleFactor, (NbImages+1)*scaleFactor, scaleFactor, "0", "black");
svgStream.drawText((NbImages)*scaleFactor - scaleFactor,
svgStream << svg::drawText(scaleFactor, (NbImages+1)*scaleFactor, scaleFactor, "0", "black");
svgStream << svg::drawText((NbImages)*scaleFactor - scaleFactor,
(NbImages+1)*scaleFactor, scaleFactor, osNbImages.str(), "black");
svgStream.drawLine(2*scaleFactor, (NbImages+1)*scaleFactor,
svgStream << svg::drawLine(2*scaleFactor, (NbImages+1)*scaleFactor,
(NbImages)*scaleFactor - 2*scaleFactor, (NbImages+1)*scaleFactor,
svg::svgStyle().stroke("black", 1.0));
svg::svgAttributes().stroke("black", 1.0));

std::ofstream svgFileStream( sOutName);
svgFileStream << svgStream.closeSvgFile().str();
Expand Down
34 changes: 17 additions & 17 deletions src/openMVG/matching/svg_matches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <openMVG/matching/svg_matches.hpp>
#include <openMVG/features/feature.hpp>
#include "third_party/vectorGraphics/svgDrawer.hpp"
#include "openMVG/vector_graphics/svgDrawer.hpp"

namespace openMVG {
namespace matching {
Expand Down Expand Up @@ -87,8 +87,8 @@ std::string Matches2SVGString
svg::svgDrawer svgStream(svg_w, svg_h);

// Draw image side by side
svgStream.drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream.drawImage(right_image_path, right_image_size.first, right_image_size.second,
svgStream << svg::drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream << svg::drawImage(right_image_path, right_image_size.first, right_image_size.second,
b_vertical_display ? 0 : left_image_size.first,
b_vertical_display ? left_image_size.second : 0);

Expand All @@ -109,23 +109,23 @@ std::string Matches2SVGString
colors.push_back(osCol.str());
}
// Draw the line between the corresponding feature positions
svgStream.drawLine(
svgStream << svg::drawLine(
L.x(), L.y(),
R.x() + svg_offset_x, R.y() + svg_offset_y,
svg::svgStyle().stroke(colors.back(), stroke_size));
svg::svgAttributes().stroke(colors.back(), stroke_size));
}
// 2. Then display features circles
for (size_t i = 0; i < matches.size(); ++i) {
// Get back linked features
const features::PointFeature & L = left_features[matches[i].i_];
const features::PointFeature & R = right_features[matches[i].j_];
// Draw the features (circle)
svgStream.drawCircle(
svgStream << svg::drawCircle(
L.x(), L.y(), feature_circle_radius,
svg::svgStyle().stroke(colors[i], stroke_size));
svgStream.drawCircle(
svg::svgAttributes().stroke(colors[i], stroke_size));
svgStream << svg::drawCircle(
R.x() + svg_offset_x, R.y() + svg_offset_y, feature_circle_radius,
svg::svgStyle().stroke(colors[i], stroke_size));
svg::svgAttributes().stroke(colors[i], stroke_size));
}
return svgStream.closeSvgFile().str();
}
Expand Down Expand Up @@ -206,8 +206,8 @@ bool InlierMatches2SVG
svg::svgDrawer svgStream(svg_w, svg_h);

// Draw image side by side
svgStream.drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream.drawImage(right_image_path, right_image_size.first, right_image_size.second,
svgStream << svg::drawImage(left_image_path, left_image_size.first, left_image_size.second);
svgStream << svg::drawImage(right_image_path, right_image_size.first, right_image_size.second,
b_vertical_display ? 0 : left_image_size.first,
b_vertical_display ? left_image_size.second : 0);

Expand All @@ -228,23 +228,23 @@ bool InlierMatches2SVG
colors.push_back(osCol.str());
}
// Draw the line between the corresponding feature positions
svgStream.drawLine(
svgStream << svg::drawLine(
L.x(), L.y(),
R.x() + svg_offset_x, R.y() + svg_offset_y,
svg::svgStyle().stroke(colors.back(), stroke_size));
svg::svgAttributes().stroke(colors.back(), stroke_size));
}

for (size_t i = 0; i < inliers.size(); ++i) {
// Get back linked features
const features::PointFeature & L = left_features[matches[inliers[i]].i_];
const features::PointFeature & R = right_features[matches[inliers[i]].j_];
// Draw the features (circle)
svgStream.drawCircle(
svgStream << svg::drawCircle(
L.x(), L.y(), feature_circle_radius,
svg::svgStyle().stroke(colors[i], stroke_size));
svgStream.drawCircle(
svg::svgAttributes().stroke(colors[i], stroke_size));
svgStream << svg::drawCircle(
R.x() + svg_offset_x, R.y() + svg_offset_y, feature_circle_radius,
svg::svgStyle().stroke(colors[i], stroke_size));
svg::svgAttributes().stroke(colors[i], stroke_size));
}

// Save the SVG file
Expand Down
6 changes: 3 additions & 3 deletions src/openMVG/multiview/translation_averaging_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "openMVG/multiview/test_data_sets.hpp"
#include "openMVG/multiview/translation_averaging_common.hpp"
#include "openMVG/numeric/numeric.h"
#include "openMVG/vector_graphics/svgDrawer.hpp"

#include "testing/testing.h"
#include "third_party/vectorGraphics/svgDrawer.hpp"

int modifiedMod
(
Expand Down Expand Up @@ -67,8 +67,8 @@ void visibleCamPosToSVGSurface
svg::svgDrawer svgSurface_GT(size,size);
for (size_t i = 0; i < vec_Ci.size(); ++i)
{
svgSurface_GT.drawCircle(out[i](0), out[i](2),
3,svg::svgStyle().stroke("black",0.2).fill("red"));
svgSurface_GT << svg::drawCircle(out[i](0), out[i](2),
3,svg::svgAttributes().stroke("black",0.2).fill("red"));
}
std::ostringstream osSvgGT;
osSvgGT << fileName;
Expand Down
10 changes: 5 additions & 5 deletions src/openMVG/numeric/lm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include "openMVG/numeric/numeric.h"
#include "openMVG/numeric/lm.hpp"
#include "openMVG/vector_graphics/svgDrawer.hpp"

#include "testing/testing.h"
#include "third_party/vectorGraphics/svgDrawer.hpp"

#include <unsupported/Eigen/NonLinearOptimization>
#include <unsupported/Eigen/NumericalDiff>
Expand Down Expand Up @@ -101,15 +101,15 @@ TEST(LM, MimimaSearchViaLM) {
yFound[cpt] = (4 - (exp(xlm[0] * i) + xlm[1]))*dFactor;
}

svgSurface.drawPolyline(
svgSurface << svg::drawPolyline(
xFound.data(), xFound.data()+30,
yFound.data(), yFound.data()+30,
svgStyle().stroke("blue", 1.f));
svgAttributes().stroke("blue", 1.f));

//Draw point in a second time to put them in the top layer
for (Vec::Index i = 0; i < x.rows(); ++i)
svgSurface.drawCircle(x[i]*dFactor, (4-y[i])*dFactor, 1,
svgStyle().fill("red").noStroke());
svgSurface << svg::drawCircle(x[i]*dFactor, (4-y[i])*dFactor, 1,
svgAttributes().fill("red").noStroke());

std::ostringstream osSvg;
osSvg << "exponentialRegression_unit_test.svg";
Expand Down