##

SVGLoader.hh
Go to the documentation of this file.
/*
* Copyright (C) 2015 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _GAZEBO_SVGLOADER_HH_
#define _GAZEBO_SVGLOADER_HH_
#include <stdexcept>
#include <string>
#include <vector>
#include <ignition/math/Vector2.hh>
#include <ignition/math/Matrix3.hh>
#include "gazebo/common/Console.hh"
class TiXmlElement;
class TiXmlNode;
namespace gazebo
{
namespace common
{
class SVGLoaderPrivate;
class GZ_COMMON_VISIBLE SvgError: public std::runtime_error
{
public: explicit SvgError(const std::string &_what);
};
class GZ_COMMON_VISIBLE SVGCommand
{
public: SVGCommand() : cmd(' ') {}
public: virtual ~SVGCommand() = default;
public: char cmd;
public: std::vector<double> numbers;
};
struct GZ_COMMON_VISIBLE SVGPath
{
std::string id;
std::string style;
ignition::math::Matrix3d transform;
std::vector< std::vector<SVGCommand> > subpaths;
std::vector< std::vector<ignition::math::Vector2d> > polylines;
};
class GZ_COMMON_VISIBLE SVGLoader
{
public: explicit SVGLoader(unsigned int _samples);
public: ~SVGLoader();
public: bool Parse(const std::string &_filename,
std::vector<SVGPath> &_paths);
public: static void PathsToClosedPolylines(
const std::vector<common::SVGPath> &_paths,
double _tol,
std::vector< std::vector<ignition::math::Vector2d> > &_closedPolys,
std::vector< std::vector<ignition::math::Vector2d> > &_openPolys);
public: void DumpPaths(const std::vector<SVGPath> &_paths,
std::ostream &_out) const;
private: void GetPathCommands(const std::vector<std::string> &_tokens,
SVGPath &_path);
private: void GetPathAttribs(TiXmlElement *_pElement, SVGPath &_path);
private: void GetSvgPaths(TiXmlNode *_pParent,
std::vector<SVGPath> &_paths);
private: void ExpandCommands(
const std::vector< std::vector<SVGCommand> > &_subpaths,
SVGPath& _path);
private: void SplitSubpaths(const std::vector<SVGCommand> &_cmds,
std::vector< std::vector<SVGCommand> > &_subpaths);
private: void PathToPoints(const SVGPath &_path,
double _resolution,
std::vector< std::vector<ignition::math::Vector2d> > &_polys);
private: ignition::math::Vector2d SubpathToPolyline(
const std::vector<SVGCommand> &_subpath,
ignition::math::Vector2d _last,
std::vector<ignition::math::Vector2d> &_polyline);
private: SVGLoaderPrivate *dataPtr;
};
}
}
#endif
gazebo::common::SvgError::SvgError
SvgError(const std::string &_what)
constructor
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::SVGPath::style
std::string style
The style (i.e. stroke style, color, thickness etc)
Definition: SVGLoader.hh:70
gazebo::common::SVGCommand::cmd
char cmd
A letter that describe the segment.
Definition: SVGLoader.hh:57
gazebo::common::SVGCommand
SVG command data structure.
Definition: SVGLoader.hh:48
common
common
Definition: FuelModelDatabase.hh:37
gazebo::common::SVGLoader::Parse
bool Parse(const std::string &_filename, std::vector< SVGPath > &_paths)
Reads an SVG file and loads all the paths.
Console.hh
gazebo::common::SVGPath::id
std::string id
An id or name.
Definition: SVGLoader.hh:67
gazebo::common::SVGLoader::DumpPaths
void DumpPaths(const std::vector< SVGPath > &_paths, std::ostream &_out) const
Outputs the content of the paths to file (or console)
gazebo::common::SVGPath::transform
ignition::math::Matrix3d transform
A 2D transform (or a list of transforms)
Definition: SVGLoader.hh:73
gazebo::common::SVGCommand::~SVGCommand
virtual ~SVGCommand()=default
Destructor.
gazebo::common::SVGPath
An SVG path element data structure.
Definition: SVGLoader.hh:64
gazebo::common::SVGPath::polylines
std::vector< std::vector< ignition::math::Vector2d > > polylines
The polylines described by the commands.
Definition: SVGLoader.hh:79
gazebo::common::SVGLoader
A loader for SVG files.
Definition: SVGLoader.hh:83
gazebo::common::SvgError
Handles errors during SVG parsing.
Definition: SVGLoader.hh:40
gazebo::common::SVGCommand::SVGCommand
SVGCommand()
Constructor.
Definition: SVGLoader.hh:51
gazebo::common::SVGLoader::~SVGLoader
~SVGLoader()
destructor
gazebo::common::SVGLoader::SVGLoader
SVGLoader(unsigned int _samples)
Constructor.
gazebo::common::SVGCommand::numbers
std::vector< double > numbers
Coordinates for the command.
Definition: SVGLoader.hh:60
gazebo::common::SVGLoader::PathsToClosedPolylines
static void PathsToClosedPolylines(const std::vector< common::SVGPath > &_paths, double _tol, std::vector< std::vector< ignition::math::Vector2d > > &_closedPolys, std::vector< std::vector< ignition::math::Vector2d > > &_openPolys)
Reads in paths and outputs closed polylines and open polylines.
gazebo::common::SVGPath::subpaths
std::vector< std::vector< SVGCommand > > subpaths
A list of subpaths (as lists of commands)
Definition: SVGLoader.hh:76