-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add level generator Signed-off-by: Ian Chen <[email protected]> * comment and simplify code Signed-off-by: Ian Chen <[email protected]> * Tweaks to the level generator (#423) Signed-off-by: Nate Koenig <[email protected]> Co-authored-by: Nate Koenig <[email protected]> Co-authored-by: Ian Chen <[email protected]> * fix typo Signed-off-by: Ian Chen <[email protected]> Co-authored-by: Nate Koenig <[email protected]> Co-authored-by: Nate Koenig <[email protected]>
- Loading branch information
1 parent
a1837a1
commit e31ae65
Showing
5 changed files
with
486 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (C) 2020 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. | ||
* | ||
*/ | ||
|
||
#include "ConnectionHelper.hh" | ||
#include "SdfParser.hh" | ||
|
||
using namespace ignition; | ||
using namespace subt; | ||
|
||
////////////////////////////////////////////////// | ||
std::string SdfParser::Parse(const std::string &_key, const std::string &_str, | ||
size_t &_endPos) | ||
{ | ||
std::string elemStartStr = "<" + _key + ">"; | ||
std::string elemEndStr = "</" + _key + ">"; | ||
|
||
size_t start = _str.find(elemStartStr); | ||
if (start == std::string::npos) | ||
return std::string(); | ||
size_t startIdx = start + elemStartStr.size(); | ||
size_t end = _str.find(elemEndStr, startIdx); | ||
if (end == std::string::npos) | ||
return std::string(); | ||
|
||
_endPos = end + elemEndStr.size(); | ||
std::string result = _str.substr(startIdx, end - startIdx); | ||
return result; | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
std::string SdfParser::Parse(const std::string &_key, const std::string &_str) | ||
{ | ||
size_t endPos; | ||
return Parse(_key, _str, endPos); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
bool SdfParser::FillVertexData(const std::string &_includeStr, VertexData &_vd, | ||
std::function<bool(const std::string &, const std::string &)> &_filter) | ||
{ | ||
// parse name | ||
std::string name = Parse("name", _includeStr); | ||
|
||
// parse pose | ||
std::string poseStr = Parse("pose", _includeStr); | ||
math::Pose3d pose; | ||
std::stringstream ss(poseStr); | ||
ss >> pose; | ||
|
||
// parse uri and get model type | ||
std::string uri = Parse("uri", _includeStr); | ||
std::string fuelStr = | ||
"https://fuel.ignitionrobotics.org/1.0/openrobotics/models/"; | ||
size_t fuelIdx = uri.find(fuelStr); | ||
std::string modelType; | ||
if (fuelIdx == std::string::npos) | ||
return false; | ||
modelType = uri.substr(fuelIdx + fuelStr.size()); | ||
|
||
// check if model type is recognized | ||
if (_filter && _filter(name, modelType)) | ||
return false; | ||
sdf::Model modelSdf; | ||
modelSdf.SetName(name); | ||
modelSdf.SetPose(pose); | ||
|
||
static int tileId = 0; | ||
// Try getting the tile id from the tile name first. | ||
try | ||
{ | ||
int numIndex = name.rfind("_"); | ||
_vd.id = std::stoi(name.substr(numIndex+1)); | ||
} | ||
catch (...) | ||
{ | ||
_vd.id = tileId++; | ||
} | ||
_vd.tileType = modelType; | ||
_vd.tileName = name; | ||
_vd.model = modelSdf; | ||
|
||
return true; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2020 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. | ||
* | ||
*/ | ||
|
||
#include "ConnectionHelper.hh" | ||
|
||
namespace subt | ||
{ | ||
|
||
class SdfParser | ||
{ | ||
/// \brief Parse contents of an sdf element | ||
/// \param[in] _key SDF element key | ||
/// \param[in] _str String content of the sdf element | ||
/// \param[out] _endPos end position of the sdf element string | ||
/// \return Value for the input key | ||
public: static std::string Parse(const std::string &_key, const std::string &_str, | ||
size_t &_endPos); | ||
|
||
/// \brief Parse contents of an sdf element | ||
/// \param[in] _key SDF element key | ||
/// \param[in] _str String content of the sdf element | ||
/// \return Value for the input key | ||
public: static std::string Parse(const std::string &_key, | ||
const std::string &_str); | ||
|
||
/// \brief Fill VertexData from string | ||
/// \param[in] _includeStr input <include> string | ||
/// \param[out] _vd Vertex data to be filled | ||
/// \return True if vertex data is successfully filled, false otherwise | ||
public: static bool FillVertexData(const std::string &_includeStr, | ||
VertexData &_vd, | ||
std::function<bool(const std::string &, const std::string &)> &_filter); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.