in IsometricPatternMatcher/IsometricPattern.cpp [233:284]
void IsometricGridDot::SaveSVG(
const std::string& filename, const std::string& color0,
const std::string& color1, const std::string& bgcolor,
int patternGroupIndex) // patternGroupIndex only for testing
const {
std::ofstream f(filename.c_str());
const Eigen::MatrixXi& M = patternGroup_[patternGroupIndex];
const double offsetInMm = horizontalSpacing_ * 1000; // meters to millimeters
f << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl
<< "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
<< std::endl;
f << ISOMETRIC_PATTERN_TRAILING_STRING << " -vertical-spacing "
<< verticalSpacing_ << " -horizontal-spacing " << horizontalSpacing_
<< " -layer-number " << numberLayer_ << " -rows " << gridRowsCols_[0]
<< " -cols " << gridRowsCols_[1] << " -grid-dotRadius " << dotRadius_;
f << " -grid-pattern ";
for (int r = 0; r < M.rows(); ++r) {
for (int q = 0; q < M.cols(); ++q) f << M(r, q);
}
f << std::endl << " -matrix " << std::endl << M;
f << " -->" << std::endl;
// units in mm
const double canvasWidth =
((gridRowsCols_[1] - 1) * horizontalSpacing_ * 1000) + offsetInMm * 2.;
const double canvasHeight =
((gridRowsCols_[0] - 1) * verticalSpacing_ * 1000) + offsetInMm * 2.;
f << fmt::format(R"#(<svg width="{}mm" height="{}mm">)#", canvasWidth,
canvasHeight);
f << std::endl;
f << fmt::format(
R"#(<rect width="{}mm" height="{}mm" style="fill:{}" z-index="-1"/>)#",
canvasWidth, canvasHeight, bgcolor);
f << std::endl;
for (int r = 0; r < M.rows(); ++r) {
for (int q = 0; q < M.cols(); ++q) {
if (M(r, q) == 0 || M(r, q) == 1) {
std::string color = (M(r, q) == 1) ? color1 : color0;
f << fmt::format(
R"#(<circle cx="{}mm" cy="{}mm" r="{}mm" fill="{}" stroke-width="0"/>)#",
patternPts_(0, r * M.cols() + q) * 1000 + offsetInMm,
patternPts_(1, r * M.cols() + q) * 1000 + offsetInMm,
dotRadius_ * 1000, // meters to millimeters
color);
f << std::endl;
}
}
}
f << "</svg>" << std::endl;
}