1 #ifndef PMPL_IO_UTILS_H_
2 #define PMPL_IO_UTILS_H_
18 extern std::ofstream*
vdo;
22 void VDInit(std::string _filename);
46 template <
typename CfgType>
50 (*vdo) <<
"AddNode " << _cfg << std::endl;
55 template <
typename CfgType>
59 (*vdo) <<
"RemoveNode " << _cfg << std::endl;
64 template <
typename CfgType>
66 VDAddEdge(
const CfgType& _cfg1,
const CfgType& _cfg2) {
68 (*vdo) <<
"AddEdge " << _cfg1 <<
" " << _cfg2 << std::endl;
73 template <
typename CfgType>
77 (*vdo) <<
"RemoveEdge " << _cfg1 <<
" " << _cfg2 << std::endl;
82 template <
typename CfgType>
86 (*vdo) <<
"AddTempCfg " << _cfg <<
" " << _valid << std::endl;
91 template <
typename CfgType>
95 (*vdo) <<
"AddTempRay " << _cfg << std::endl;
100 template <
typename CfgType>
104 (*vdo) <<
"AddTempEdge " << _cfg1 <<
" " << _cfg2 << std::endl;
110 template <
typename AbstractRoadmapType>
116 const std::string label =
"VizmoDebug";
117 _r->InstallHook(AbstractRoadmapType::HookType::AddVertex, label,
118 [_r](
const typename AbstractRoadmapType::vertex_iterator _vi){
121 _r->InstallHook(AbstractRoadmapType::HookType::DeleteVertex, label,
122 [_r](
const typename AbstractRoadmapType::vertex_iterator _vi) {
125 _r->InstallHook(AbstractRoadmapType::HookType::AddEdge, label,
126 [_r](
const typename AbstractRoadmapType::adj_edge_iterator _ei) {
127 const auto source = (*_ei).source(),
128 target = (*_ei).target();
129 VDAddEdge(_r->GetVertex(source), _r->GetVertex(target));
131 _r->InstallHook(AbstractRoadmapType::HookType::DeleteEdge, label,
132 [_r](
const typename AbstractRoadmapType::adj_edge_iterator _ei) {
133 const auto source = (*_ei).source(),
134 target = (*_ei).target();
135 VDRemoveEdge(_r->GetVertex(source), _r->GetVertex(target));
143 template <
typename CfgType>
145 WritePath(
const std::string& _filename,
const std::vector<CfgType>& _path) {
146 std::ofstream ofs(_filename);
151 ofs <<
"VIZMO_PATH_FILE Path Version 2012" << std::endl
153 << _path.size() << std::endl;
156 for(
auto cit = _path.begin(); cit != _path.end(); ++cit)
157 ofs << *cit << std::endl;
162 template <
typename CfgType>
165 std::ifstream ifs(_filename);
170 std::string line1, line2;
171 std::getline(ifs, line1);
172 std::getline(ifs, line2);
176 if(line1 != std::string(
"VIZMO_PATH_FILE Path Version 2012")
177 or line2 != std::string(
"1")
180 <<
"' has ill-formed header.";
183 std::vector<CfgType> path(pathSize, CfgType(_robot));
184 for(
size_t i = 0; i < pathSize; ++i)
189 const bool end = ifs.peek() == EOF;
192 <<
" expected cfgs.";
201 bool FileExists(
const std::string& _filename);
218 std::string
GetPathName(
const std::string& _filename);
227 template <
typename T>
230 const std::string& _desc) {
238 else if(!isspace(c)) {
239 if (!(_is >> element))
261 const std::string& _desc,
const bool _toUpper =
true);
268 std::vector<std::string>
GetTokens(std::string _s, std::string _delimiters);
bool IsCommentLine(const char _c)
Definition: IOUtils.cpp:84
std::string ReadFieldString(std::istream &_is, CountingStreamBuffer &_cbs, const std::string &_desc, const bool _toUpper=true)
Definition: IOUtils.cpp:97
void VDAddNode(const CfgType &_cfg)
@TODO
Definition: IOUtils.h:48
void WritePath(const std::string &_filename, const std::vector< CfgType > &_path)
Write a list of Cfgs from a path to file.
Definition: IOUtils.h:145
void VDClearComments()
@TODO
Definition: IOUtils.cpp:52
void VDAddTempEdge(const CfgType &_cfg1, const CfgType &_cfg2)
@TODO
Definition: IOUtils.h:102
void VDAddEdge(const CfgType &_cfg1, const CfgType &_cfg2)
@TODO
Definition: IOUtils.h:66
void VDInit(std::string _filename)
@TODO
Definition: IOUtils.cpp:14
void VDAddTempCfg(const CfgType &_cfg, const bool _valid)
@TODO
Definition: IOUtils.h:84
std::vector< std::string > GetTokens(std::string _s, std::string _delimiters)
Definition: IOUtils.cpp:107
void GoToNext(std::istream &_is)
Definition: IOUtils.cpp:67
bool FileExists(const std::string &_filename)
Definition: IOUtils.cpp:60
void VDAddTempRay(const CfgType &_cfg)
@TODO
Definition: IOUtils.h:93
void VDClearAll()
@TODO
Definition: IOUtils.cpp:38
void VDRemoveNode(const CfgType &_cfg)
@TODO
Definition: IOUtils.h:57
T ReadField(std::istream &_is, CountingStreamBuffer &_cbs, const std::string &_desc)
Definition: IOUtils.h:229
void VDClose()
@TODO
Definition: IOUtils.cpp:21
std::vector< CfgType > ReadPath(const std::string &_filename, Robot *const _robot)
Read a list of Cfgs from a file to path.
Definition: IOUtils.h:164
void VDClearLastTemp()
@TODO
Definition: IOUtils.cpp:45
void VDComment(std::string _s)
@TODO
Definition: IOUtils.cpp:31
std::string GetPathName(const std::string &_filename)
Definition: IOUtils.cpp:90
void VDTrackRoadmap(AbstractRoadmapType *const _r)
Definition: IOUtils.h:112
std::ofstream * vdo
@TODO
Definition: IOUtils.cpp:11
void VDRemoveEdge(const CfgType &_cfg1, const CfgType &_cfg2)
@TODO
Definition: IOUtils.h:75
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
Definition: CountingStreamBuffer.h:20
std::string Where() const
Definition: CountingStreamBuffer.cpp:48
Definition: PMPLExceptions.h:38
Definition: PMPLExceptions.h:62