Skip to content

Commit

Permalink
Change URI pattern of sample data (e.g., dart://sample/skel/shapes.skel)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Feb 2, 2017
1 parent c89f707 commit 3cbbbc7
Show file tree
Hide file tree
Showing 42 changed files with 292 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "dart/utils/SampleResourceRetriever.hpp"
#include "dart/utils/DartResourceRetriever.hpp"

#include <iostream>
#include <fstream>
Expand All @@ -40,15 +40,15 @@ namespace dart {
namespace utils {

//==============================================================================
SampleResourceRetriever::SampleResourceRetriever()
DartResourceRetriever::DartResourceRetriever()
: mLocalRetriever(std::make_shared<common::LocalResourceRetriever>())
{
addDataDirectory(DART_DATA_LOCAL_PATH);
addDataDirectory(DART_DATA_GLOBAL_PATH);
}

//==============================================================================
bool SampleResourceRetriever::exists(const common::Uri& uri)
bool DartResourceRetriever::exists(const common::Uri& uri)
{
std::string relativePath;
if (!resolveDataUri(uri, relativePath))
Expand All @@ -75,7 +75,7 @@ bool SampleResourceRetriever::exists(const common::Uri& uri)
}

//==============================================================================
common::ResourcePtr SampleResourceRetriever::retrieve(const common::Uri& uri)
common::ResourcePtr DartResourceRetriever::retrieve(const common::Uri& uri)
{
std::string relativePath;
if (!resolveDataUri(uri, relativePath))
Expand All @@ -102,7 +102,7 @@ common::ResourcePtr SampleResourceRetriever::retrieve(const common::Uri& uri)
}

//==============================================================================
void SampleResourceRetriever::addDataDirectory(
void DartResourceRetriever::addDataDirectory(
const std::string& dataDirectory)
{
// Strip a trailing slash.
Expand All @@ -121,16 +121,16 @@ void SampleResourceRetriever::addDataDirectory(
}

//==============================================================================
bool SampleResourceRetriever::resolveDataUri(
bool DartResourceRetriever::resolveDataUri(
const common::Uri& uri,
std::string& relativePath) const
{
if (uri.mScheme.get_value_or("file") != "file")
if (uri.mScheme.get_value_or("dart") != "dart")
return false;

if (!uri.mPath)
{
dtwarn << "[SampleResourceRetriever::resolveDataUri] Failed extracting"
dtwarn << "[DartResourceRetriever::resolveDataUri] Failed extracting"
" relative path from URI '" << uri.toString() << "'.\n";
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef DART_UTILS_SAMPLERESOURCERETRIEVER_HPP_
#define DART_UTILS_SAMPLERESOURCERETRIEVER_HPP_
#ifndef DART_UTILS_DARTRESOURCERETRIEVER_HPP_
#define DART_UTILS_DARTRESOURCERETRIEVER_HPP_

#include <unordered_map>
#include <vector>
Expand All @@ -44,14 +44,14 @@ namespace utils {
///
/// Example of a sample data URI:
/// @code
/// "file://sample/skel/shapes.skel"
/// "dart://sample/skel/shapes.skel"
/// \______________/
/// |
/// file path with respect to
/// the sample data directory
/// @endcode
///
/// SampleResourceRetriever searches files in the following order:
/// DartResourceRetriever searches files in the following order:
/// 1) DART_DATA_LOCAL_PATH: path to the data directory in source
/// (e.g., [DART_SRC_ROOT]/data/).
/// 2) DART_DATA_GLOBAL_PATH: path to the data directory installed at a system
Expand All @@ -60,21 +60,21 @@ namespace utils {
/// where DART_DATA_LOCAL_PATH and DART_DATA_GLOBAL_PATH are defined in
/// config.hpp that are determined in CMake time.
///
class SampleResourceRetriever : public common::ResourceRetriever
class DartResourceRetriever : public common::ResourceRetriever
{
public:
template <typename... Args>
static std::shared_ptr<SampleResourceRetriever> create(Args&&... args)
static std::shared_ptr<DartResourceRetriever> create(Args&&... args)
{
return std::make_shared<SampleResourceRetriever>(
return std::make_shared<DartResourceRetriever>(
std::forward<Args>(args)...);
}

/// Constructor.
SampleResourceRetriever();
DartResourceRetriever();

/// Destructor.
virtual ~SampleResourceRetriever() = default;
virtual ~DartResourceRetriever() = default;

// Documentation inherited.
bool exists(const common::Uri& uri) override;
Expand All @@ -94,9 +94,9 @@ class SampleResourceRetriever : public common::ResourceRetriever
std::vector<std::string> mDataDirectories;
};

using SampleResourceRetrieverPtr = std::shared_ptr<SampleResourceRetriever>;
using DartResourceRetrieverPtr = std::shared_ptr<DartResourceRetriever>;

} // namespace utils
} // namespace dart

#endif // ifndef DART_UTILS_SAMPLERESOURCERETRIEVER_HPP_
#endif // ifndef DART_UTILS_DARTRESOURCERETRIEVER_HPP_
15 changes: 13 additions & 2 deletions dart/utils/SkelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
#include "dart/dynamics/Skeleton.hpp"
#include "dart/dynamics/Marker.hpp"
#include "dart/utils/XmlHelpers.hpp"
#include "dart/utils/SampleResourceRetriever.hpp"
#include "dart/utils/CompositeResourceRetriever.hpp"
#include "dart/utils/DartResourceRetriever.hpp"

namespace dart {
namespace utils {
Expand Down Expand Up @@ -2407,9 +2408,19 @@ common::ResourceRetrieverPtr getRetriever(
const common::ResourceRetrieverPtr& _retriever)
{
if(_retriever)
{
return _retriever;
}
else
return SampleResourceRetriever::create();
{
auto newRetriever = std::make_shared<utils::CompositeResourceRetriever>();
newRetriever->addSchemaRetriever(
"file", std::make_shared<common::LocalResourceRetriever>());
newRetriever->addSchemaRetriever(
"dart", DartResourceRetriever::create());

return DartResourceRetriever::create();
}
}

} // anonymous namespace
Expand Down
17 changes: 14 additions & 3 deletions dart/utils/VskParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
#include "dart/common/LocalResourceRetriever.hpp"
#include "dart/common/Uri.hpp"
#include "dart/dynamics/dynamics.hpp"
#include "dart/utils/SampleResourceRetriever.hpp"
#include "dart/utils/CompositeResourceRetriever.hpp"
#include "dart/utils/DartResourceRetriever.hpp"
#include "dart/utils/XmlHelpers.hpp"

#define SCALE_VSK 1.0e-3
Expand Down Expand Up @@ -1022,10 +1023,20 @@ void tokenize(const std::string& str,
common::ResourceRetrieverPtr getRetriever(
const common::ResourceRetrieverPtr& retriever)
{
if(retriever)
if (retriever)
{
return retriever;
}
else
return SampleResourceRetriever::create();
{
auto newRetriever = std::make_shared<utils::CompositeResourceRetriever>();
newRetriever->addSchemaRetriever(
"file", std::make_shared<common::LocalResourceRetriever>());
newRetriever->addSchemaRetriever(
"dart", DartResourceRetriever::create());

return DartResourceRetriever::create();
}
}

} // anonymous namespace
Expand Down
17 changes: 14 additions & 3 deletions dart/utils/sdf/SdfParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
#include "dart/simulation/World.hpp"
#include "dart/utils/SkelParser.hpp"
#include "dart/utils/XmlHelpers.hpp"
#include "dart/utils/SampleResourceRetriever.hpp"
#include "dart/utils/CompositeResourceRetriever.hpp"
#include "dart/utils/DartResourceRetriever.hpp"

namespace dart {
namespace utils {
Expand Down Expand Up @@ -1496,10 +1497,20 @@ dynamics::BallJoint::Properties readBallJoint(
common::ResourceRetrieverPtr getRetriever(
const common::ResourceRetrieverPtr& retriever)
{
if(retriever)
if (retriever)
{
return retriever;
}
else
return SampleResourceRetriever::create();
{
auto newRetriever = std::make_shared<utils::CompositeResourceRetriever>();
newRetriever->addSchemaRetriever(
"file", std::make_shared<common::LocalResourceRetriever>());
newRetriever->addSchemaRetriever(
"dart", DartResourceRetriever::create());

return DartResourceRetriever::create();
}
}

} // anonymous namespace
Expand Down
4 changes: 2 additions & 2 deletions dart/utils/urdf/DartLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "dart/dynamics/CylinderShape.hpp"
#include "dart/dynamics/MeshShape.hpp"
#include "dart/simulation/World.hpp"
#include "dart/utils/SampleResourceRetriever.hpp"
#include "dart/utils/DartResourceRetriever.hpp"
#include "dart/utils/urdf/URDFTypes.hpp"
#include "dart/utils/urdf/urdf_world_parser.hpp"

Expand All @@ -68,7 +68,7 @@ DartLoader::DartLoader()
{
mRetriever->addSchemaRetriever("file", mLocalRetriever);
mRetriever->addSchemaRetriever("package", mPackageRetriever);
mRetriever->addSchemaRetriever("file", SampleResourceRetriever::create());
mRetriever->addSchemaRetriever("dart", DartResourceRetriever::create());
}

void DartLoader::addPackageDirectory(const std::string& _packageName,
Expand Down
2 changes: 1 addition & 1 deletion examples/addDeleteSkels/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
int main(int argc, char* argv[]) {
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld("file://sample/skel/ground.skel");
= dart::utils::SkelParser::readWorld("dart://sample/skel/ground.skel");
assert(myWorld != nullptr);
Eigen::Vector3d gravity(0.0, -9.81, 0.0);
myWorld->setGravity(gravity);
Expand Down
4 changes: 2 additions & 2 deletions examples/atlasSimbicon/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ int main(int argc, char* argv[])
// Load ground and Atlas robot and add them to the world
DartLoader urdfLoader;
SkeletonPtr ground = urdfLoader.parseSkeleton(
"file://sample/sdf/atlas/ground.urdf");
"dart://sample/sdf/atlas/ground.urdf");
SkeletonPtr atlas = SdfParser::readSkeleton(
"file://sample/sdf/atlas/atlas_v3_no_head_soft_feet.sdf");
"dart://sample/sdf/atlas/atlas_v3_no_head_soft_feet.sdf");
myWorld->addSkeleton(atlas);
myWorld->addSkeleton(ground);

Expand Down
2 changes: 1 addition & 1 deletion examples/bipedStand/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
int main(int argc, char* argv[]) {
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld("file://sample/skel/fullbody1.skel");
= dart::utils::SkelParser::readWorld("dart://sample/skel/fullbody1.skel");
assert(myWorld != nullptr);

Eigen::Vector3d gravity(0.0, -9.81, 0.0);
Expand Down
2 changes: 1 addition & 1 deletion examples/hybridDynamics/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char* argv[])
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
"file://sample/skel/fullbody1.skel");
"dart://sample/skel/fullbody1.skel");
assert(myWorld != nullptr);
Eigen::Vector3d gravity(0.0, -9.81, 0.0);
myWorld->setGravity(gravity);
Expand Down
2 changes: 1 addition & 1 deletion examples/jointConstraints/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char* argv[])
// load a skeleton file
// create and initialize the world
dart::simulation::WorldPtr myWorld
= utils::SkelParser::readWorld("file://sample/skel/fullbody1.skel");
= utils::SkelParser::readWorld("dart://sample/skel/fullbody1.skel");
assert(myWorld != nullptr);

Eigen::Vector3d gravity(0.0, -9.81, 0.0);
Expand Down
2 changes: 1 addition & 1 deletion examples/mixedChain/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main(int argc, char* argv[])
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
"file://sample/skel/test/test_articulated_bodies_10bodies.skel");
"dart://sample/skel/test/test_articulated_bodies_10bodies.skel");
assert(myWorld != nullptr);

int dof = myWorld->getSkeleton(1)->getNumDofs();
Expand Down
4 changes: 2 additions & 2 deletions examples/operationalSpaceControl/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ int main(int argc, char* argv[])
// load skeletons
dart::utils::DartLoader dl;
dart::dynamics::SkeletonPtr ground
= dl.parseSkeleton("file://sample/urdf/KR5/ground.urdf");
= dl.parseSkeleton("dart://sample/urdf/KR5/ground.urdf");
dart::dynamics::SkeletonPtr robot
= dl.parseSkeleton("file://sample/urdf/KR5/KR5 sixx R650.urdf");
= dl.parseSkeleton("dart://sample/urdf/KR5/KR5 sixx R650.urdf");
world->addSkeleton(ground);
world->addSkeleton(robot);

Expand Down
2 changes: 1 addition & 1 deletion examples/osgExamples/osgAtlasPuppet/osgAtlasPuppet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ SkeletonPtr createAtlas()
// Parse in the atlas model
DartLoader urdf;
SkeletonPtr atlas =
urdf.parseSkeleton("file://sample/sdf/atlas/atlas_v3_no_head.urdf");
urdf.parseSkeleton("dart://sample/sdf/atlas/atlas_v3_no_head.urdf");

// Add a box to the root node to make it easier to click and drag
double scale = 0.25;
Expand Down
4 changes: 2 additions & 2 deletions examples/osgExamples/osgAtlasSimbicon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ int main()

// Load ground and Atlas robot and add them to the world
dart::utils::DartLoader urdfLoader;
auto ground = urdfLoader.parseSkeleton("file://sample/sdf/atlas/ground.urdf");
auto ground = urdfLoader.parseSkeleton("dart://sample/sdf/atlas/ground.urdf");
auto atlas = dart::utils::SdfParser::readSkeleton(
"file://sample/sdf/atlas/atlas_v3_no_head.sdf");
"dart://sample/sdf/atlas/atlas_v3_no_head.sdf");
world->addSkeleton(ground);
world->addSkeleton(atlas);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int main()

// Load the robot
dart::dynamics::SkeletonPtr robot =
loader.parseSkeleton("file://sample/urdf/KR5/KR5 sixx R650.urdf");
loader.parseSkeleton("dart://sample/urdf/KR5/KR5 sixx R650.urdf");
world->addSkeleton(robot);

// Set the colors of the models to obey the shape's color specification
Expand All @@ -275,7 +275,7 @@ int main()

// Load the ground
dart::dynamics::SkeletonPtr ground =
loader.parseSkeleton("file://sample/urdf/KR5/ground.urdf");
loader.parseSkeleton("dart://sample/urdf/KR5/ground.urdf");
world->addSkeleton(ground);

// Rotate and move the ground so that z is upwards
Expand Down
2 changes: 1 addition & 1 deletion examples/osgExamples/osgSoftBodies/osgSoftBodies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ int main()
using namespace dart::dynamics;

dart::simulation::WorldPtr world =
dart::utils::SkelParser::readWorld("file://sample/skel/softBodies.skel");
dart::utils::SkelParser::readWorld("dart://sample/skel/softBodies.skel");

osg::ref_ptr<RecordingWorld> node = new RecordingWorld(world);

Expand Down
2 changes: 1 addition & 1 deletion examples/rigidChain/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
int main(int argc, char* argv[]) {
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld("file://sample/skel/chain.skel");
= dart::utils::SkelParser::readWorld("dart://sample/skel/chain.skel");
assert(myWorld != nullptr);

// create and initialize the world
Expand Down
2 changes: 1 addition & 1 deletion examples/rigidLoop/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char* argv[])
// load a skeleton file
// create and initialize the world
dart::simulation::WorldPtr myWorld
= utils::SkelParser::readWorld("file://sample/skel/chain.skel");
= utils::SkelParser::readWorld("dart://sample/skel/chain.skel");
assert(myWorld != nullptr);

// create and initialize the world
Expand Down
2 changes: 1 addition & 1 deletion examples/rigidShapes/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char* argv[])
// load a skeleton file
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld("file://sample/skel/shapes.skel");
= dart::utils::SkelParser::readWorld("dart://sample/skel/shapes.skel");
assert(myWorld != NULL);

// create a window and link it to the world
Expand Down
2 changes: 1 addition & 1 deletion examples/softBodies/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main(int argc, char* argv[])
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
"file://sample/skel/softBodies.skel");
"dart://sample/skel/softBodies.skel");
assert(myWorld != nullptr);

for(std::size_t i=0; i<myWorld->getNumSkeletons(); ++i)
Expand Down
Loading

0 comments on commit 3cbbbc7

Please sign in to comment.