Skip to content

Commit

Permalink
Merge pull request #517 from dartsim/portable_uri
Browse files Browse the repository at this point in the history
Improving URI to be compatible with Windows
  • Loading branch information
jslee02 committed Oct 14, 2015
2 parents eca6c2a + 78557fd commit 293b8fa
Show file tree
Hide file tree
Showing 50 changed files with 745 additions and 455 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ if(MSVC)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DART_RUNTIME_LIBRARY}d /Zi /Gy /W1 /EHsc")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${DART_RUNTIME_LIBRARY} /Zi /GL /Gy /W1 /EHsc /arch:SSE2")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO")
elseif(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-Wall -msse2 -fPIC")
execute_process(
Expand Down
3 changes: 1 addition & 2 deletions apps/addDeleteSkels/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
int main(int argc, char* argv[]) {
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
DART_DATA_PATH"/skel/ground.skel");
= dart::utils::SkelParser::readWorld(DART_DATA_PATH"/skel/ground.skel");
assert(myWorld != nullptr);
Eigen::Vector3d gravity(0.0, -9.81, 0.0);
myWorld->setGravity(gravity);
Expand Down
6 changes: 3 additions & 3 deletions apps/atlasSimbicon/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

using namespace std;
using namespace Eigen;
using namespace dart::common;
using namespace dart::dynamics;
using namespace dart::simulation;
using namespace dart::utils;
Expand All @@ -59,9 +60,8 @@ int main(int argc, char* argv[])
DART_DATA_PATH"sdf/atlas/ground.urdf");
// SkeletonPtr atlas = SoftSdfParser::readSkeleton(
// DART_DATA_PATH"sdf/atlas/atlas_v3_no_head.sdf");
SkeletonPtr atlas
= SoftSdfParser::readSkeleton(
DART_DATA_PATH"sdf/atlas/atlas_v3_no_head_soft_feet.sdf");
SkeletonPtr atlas = SoftSdfParser::readSkeleton(
DART_DATA_PATH"sdf/atlas/atlas_v3_no_head_soft_feet.sdf");
myWorld->addSkeleton(atlas);
myWorld->addSkeleton(ground);

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

Eigen::Vector3d gravity(0.0, -9.81, 0.0);
Expand Down
2 changes: 1 addition & 1 deletion apps/hybridDynamics/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char* argv[])
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
DART_DATA_PATH"/skel/fullbody1.skel");
DART_DATA_PATH"/skel/fullbody1.skel");
assert(myWorld != nullptr);
Eigen::Vector3d gravity(0.0, -9.81, 0.0);
myWorld->setGravity(gravity);
Expand Down
4 changes: 2 additions & 2 deletions apps/operationalSpaceControl/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ int main(int argc, char* argv[])
// load skeletons
dart::utils::DartLoader dl;
dart::dynamics::SkeletonPtr ground
= dl.parseSkeleton(DART_DATA_PATH"urdf/KR5/ground.urdf");
= dl.parseSkeleton(DART_DATA_PATH"urdf/KR5/ground.urdf");
dart::dynamics::SkeletonPtr robot
= dl.parseSkeleton(DART_DATA_PATH"urdf/KR5/KR5 sixx R650.urdf");
= dl.parseSkeleton(DART_DATA_PATH"urdf/KR5/KR5 sixx R650.urdf");
world->addSkeleton(ground);
world->addSkeleton(robot);

Expand Down
3 changes: 1 addition & 2 deletions apps/rigidCubes/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
int main(int argc, char* argv[]) {
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
DART_DATA_PATH"/skel/cubes.skel");
= dart::utils::SkelParser::readWorld(DART_DATA_PATH"/skel/cubes.skel");
assert(myWorld != nullptr);
Eigen::Vector3d gravity(0.0, -9.81, 0.0);
myWorld->setGravity(gravity);
Expand Down
2 changes: 1 addition & 1 deletion apps/softBodies/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char* argv[])
// create and initialize the world
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
DART_DATA_PATH"skel/softBodies.skel");
DART_DATA_PATH"skel/softBodies.skel");
assert(myWorld != nullptr);

for(size_t i=0; i<myWorld->getNumSkeletons(); ++i)
Expand Down
2 changes: 0 additions & 2 deletions apps/speedTest/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ std::vector<dart::simulation::WorldPtr> getWorlds()
std::vector<std::string> sceneFiles = getSceneFiles();
std::vector<dart::simulation::WorldPtr> worlds;
for(size_t i=0; i<sceneFiles.size(); ++i)
{
worlds.push_back(dart::utils::SkelParser::readWorld(sceneFiles[i]));
}

return worlds;
}
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ build:
verbosity: quiet # MSBuild verbosity level (quiet|minimal|normal|detailed)

test_script:
- cmd: ctest --build-config %configuration% --extra-verbose --output-on-failure
- cmd: ctest --build-config %configuration% --parallel 4 --output-on-failure
34 changes: 10 additions & 24 deletions dart/common/LocalResourceRetriever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,43 +45,29 @@ namespace dart {
namespace common {

//==============================================================================
bool LocalResourceRetriever::exists(const std::string& _uri)
bool LocalResourceRetriever::exists(const Uri& _uri) const
{
common::Uri uri;
if(!uri.fromString(_uri))
{
dtwarn << "[LocalResourceRetriever::exists] Failed parsing URI '"
<< _uri << "'.\n";
return false;
}

// Open and close the file to check if it exists. It would be more efficient
// to stat() it, but that is not portable.
if(uri.mScheme.get_value_or("file") != "file")
if(_uri.mScheme.get_value_or("file") != "file")
return false;
else if (!uri.mPath)
else if (!_uri.mPath)
return false;

return std::ifstream(*uri.mPath, std::ios::binary).good();
return std::ifstream(_uri.getFilesystemPath(), std::ios::binary).good();
}

//==============================================================================
common::ResourcePtr LocalResourceRetriever::retrieve(const std::string& _uri)
common::ResourcePtr LocalResourceRetriever::retrieve(const Uri& _uri) const
{
common::Uri uri;
if(!uri.fromString(_uri))
{
dtwarn << "[LocalResourceRetriever::retrieve] Failed parsing URI '"
<< _uri << "'.\n";
if(_uri.mScheme.get_value_or("file") != "file")
return nullptr;
}

if(uri.mScheme.get_value_or("file") != "file")
return nullptr;
else if (!uri.mPath)
else if (!_uri.mPath)
return nullptr;

const auto resource = std::make_shared<LocalResource>(*uri.mPath);
const auto resource
= std::make_shared<LocalResource>(_uri.getFilesystemPath());

if(resource->isGood())
return resource;
else
Expand Down
4 changes: 2 additions & 2 deletions dart/common/LocalResourceRetriever.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class LocalResourceRetriever : public virtual ResourceRetriever
virtual ~LocalResourceRetriever() = default;

// Documentation inherited.
bool exists(const std::string& _uri) override;
bool exists(const Uri& _uri) const override;

// Documentation inherited.
ResourcePtr retrieve(const std::string& _uri) override;
ResourcePtr retrieve(const Uri& _uri) const override;
};

using LocalResourceRetrieverPtr = std::shared_ptr<LocalResourceRetriever>;
Expand Down
8 changes: 5 additions & 3 deletions dart/common/ResourceRetriever.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

#include <memory>
#include <string>
#include "Resource.h"
#include "dart/common/Deprecated.h"
#include "dart/common/Resource.h"
#include "dart/common/Uri.h"

namespace dart {
namespace common {
Expand All @@ -52,10 +54,10 @@ class ResourceRetriever
virtual ~ResourceRetriever() = default;

/// \brief Return whether the resource specified by a URI exists.
virtual bool exists(const std::string& _uri) = 0;
virtual bool exists(const Uri& _uri) const = 0;

/// \brief Return the resource specified by a URI or nullptr on failure.
virtual ResourcePtr retrieve(const std::string& _uri) = 0;
virtual ResourcePtr retrieve(const Uri& _uri) const = 0;
};

using ResourceRetrieverPtr = std::shared_ptr<ResourceRetriever>;
Expand Down
Loading

0 comments on commit 293b8fa

Please sign in to comment.