Skip to content

Commit

Permalink
Merge pull request #504 from dartsim/tutorials
Browse files Browse the repository at this point in the history
Tutorials
  • Loading branch information
jslee02 committed Oct 1, 2015
2 parents e8b7dce + 12be7a1 commit 7c744b6
Show file tree
Hide file tree
Showing 36 changed files with 7,395 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -5,7 +5,6 @@ syntax: glob
CPack*
CTest*
Testing/
docs/
TAGS
.DS_Store
.cproject
Expand All @@ -23,3 +22,4 @@ TAGS
*~
/nbproject/
/doxygen/html/
docs/readthedocs/site
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -66,6 +66,7 @@ else()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
option(DART_BUILD_EXAMPLES "Build examples" ON)
option(DART_BUILD_TUTORIALS "Build tutorials" ON)
option(DART_BUILD_UNITTESTS "Build unit tests" ON)

#===============================================================================
Expand Down Expand Up @@ -315,6 +316,7 @@ endif()
if(BULLET_FOUND)
message(STATUS "Looking for BulletCollision - ${BULLET_VERSION} found")
set(HAVE_BULLET_COLLISION TRUE)
add_definitions(-DHAVE_BULLET_COLLISION)
else()
message(STATUS "Looking for BulletCollision - NOT found, please install libbullet-dev")
set(HAVE_BULLET_COLLISION FALSE)
Expand Down Expand Up @@ -482,6 +484,7 @@ message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
message(STATUS "ENABLE_OPENMP : ${ENABLE_OPENMP}")
message(STATUS "Build core only : ${BUILD_CORE_ONLY}")
message(STATUS "Build examples : ${DART_BUILD_EXAMPLES}")
message(STATUS "Build tutorials : ${DART_BUILD_TUTORIALS}")
message(STATUS "Build unit tests : ${DART_BUILD_UNITTESTS}")
message(STATUS "Install path : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "CXX_FLAGS : ${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -558,6 +561,10 @@ if(NOT BUILD_CORE_ONLY)
add_subdirectory(apps)
endif()

if(DART_BUILD_TUTORIALS)
add_subdirectory(tutorials)
endif()

endif()

#===============================================================================
Expand Down
1 change: 1 addition & 0 deletions README.md
@@ -1,2 +1,3 @@
[![Build Status](https://travis-ci.org/dartsim/dart.png?branch=master)](https://travis-ci.org/dartsim/dart)
[![Build status](https://ci.appveyor.com/api/projects/status/6rta8olo95bpu84r?svg=true)](https://ci.appveyor.com/project/jslee02/dart)
[![Documentation Status](https://readthedocs.org/projects/dart/badge/?version=latest)](https://readthedocs.org/projects/dart/?badge=latest)
3 changes: 2 additions & 1 deletion apps/softBodies/Main.cpp
Expand Up @@ -61,10 +61,11 @@ int main(int argc, char* argv[])
for(size_t j=0; j<skel->getNumBodyNodes(); ++j)
{
dart::dynamics::BodyNode* bn = skel->getBodyNode(j);
Eigen::Vector3d color = dart::Color::Random();
for(size_t k=0; k<bn->getNumVisualizationShapes(); ++k)
{
dart::dynamics::ShapePtr vs = bn->getVisualizationShape(k);
vs->setColor(dart::Color::Random());
vs->setColor(color);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions dart/collision/CollisionDetector.cpp
Expand Up @@ -300,6 +300,9 @@ bool CollisionDetector::getPairCollidable(const CollisionNode* _node1,
if (!isValidIndex(mCollidablePairs, index1, index2))
return false;

if (index1 == index2)
return false;

return mCollidablePairs[index1][index2];
}

Expand Down
12 changes: 12 additions & 0 deletions dart/constraint/JointConstraint.cpp
Expand Up @@ -173,5 +173,17 @@ double JointConstraint::getConstraintForceMixing()
return mConstraintForceMixing;
}

//==============================================================================
dynamics::BodyNode* JointConstraint::getBodyNode1() const
{
return mBodyNode1;
}

//==============================================================================
dynamics::BodyNode* JointConstraint::getBodyNode2() const
{
return mBodyNode2;
}

} // namespace constraint
} // namespace dart
6 changes: 6 additions & 0 deletions dart/constraint/JointConstraint.h
Expand Up @@ -88,6 +88,12 @@ class JointConstraint : public ConstraintBase
/// Get global constraint force mixing parameter
static double getConstraintForceMixing();

/// Get the first BodyNode that this constraint is associated with
dynamics::BodyNode* getBodyNode1() const;

/// Get the second BodyNode that this constraint is associated with
dynamics::BodyNode* getBodyNode2() const;

protected:
/// First body node
dynamics::BodyNode* mBodyNode1;
Expand Down
4 changes: 2 additions & 2 deletions dart/dynamics/BodyNode.cpp
Expand Up @@ -461,7 +461,7 @@ double BodyNode::getRestitutionCoeff() const
}

//==============================================================================
void BodyNode::addCollisionShape(ShapePtr _shape)
void BodyNode::addCollisionShape(const ShapePtr& _shape)
{
if(nullptr == _shape)
{
Expand Down Expand Up @@ -491,7 +491,7 @@ void BodyNode::addCollisionShape(ShapePtr _shape)
}

//==============================================================================
void BodyNode::removeCollisionShape(ShapePtr _shape)
void BodyNode::removeCollisionShape(const ShapePtr& _shape)
{
if (nullptr == _shape)
return;
Expand Down
4 changes: 2 additions & 2 deletions dart/dynamics/BodyNode.h
Expand Up @@ -274,10 +274,10 @@ class BodyNode : public Frame, public SkeletonRefCountingBase
//--------------------------------------------------------------------------

/// Add a collision Shape into the BodyNode
void addCollisionShape(ShapePtr _shape);
void addCollisionShape(const ShapePtr& _shape);

/// Remove a collision Shape from this BodyNode
void removeCollisionShape(ShapePtr _shape);
void removeCollisionShape(const ShapePtr& _shape);

/// Remove all collision Shapes from this BodyNode
void removeAllCollisionShapes();
Expand Down
4 changes: 2 additions & 2 deletions dart/dynamics/Entity.cpp
Expand Up @@ -160,7 +160,7 @@ const std::string& Entity::getName() const
}

//==============================================================================
void Entity::addVisualizationShape(ShapePtr _shape)
void Entity::addVisualizationShape(const ShapePtr& _shape)
{
if (nullptr == _shape)
return;
Expand All @@ -179,7 +179,7 @@ void Entity::addVisualizationShape(ShapePtr _shape)
}

//==============================================================================
void Entity::removeVisualizationShape(ShapePtr _shape)
void Entity::removeVisualizationShape(const ShapePtr& _shape)
{
if (nullptr == _shape)
return;
Expand Down
5 changes: 3 additions & 2 deletions dart/dynamics/Entity.h
Expand Up @@ -44,6 +44,7 @@
#include "dart/common/Subject.h"
#include "dart/common/Signal.h"
#include "dart/dynamics/Shape.h"
#include "dart/dynamics/SmartPointer.h"

namespace dart {
namespace renderer {
Expand Down Expand Up @@ -129,10 +130,10 @@ class Entity : public virtual common::Subject
virtual const std::string& getName() const;

/// Add a visualization Shape for this Entity
virtual void addVisualizationShape(ShapePtr _shape);
virtual void addVisualizationShape(const ShapePtr& _shape);

/// Remove a visualization Shape from this Entity
virtual void removeVisualizationShape(ShapePtr _shape);
virtual void removeVisualizationShape(const ShapePtr& _shape);

/// Remove all visualization Shapes from this Entity
virtual void removeAllVisualizationShapes();
Expand Down
4 changes: 1 addition & 3 deletions dart/dynamics/Shape.h
Expand Up @@ -44,6 +44,7 @@

#include "dart/math/Geometry.h"
#include "dart/common/Subject.h"
#include "dart/dynamics/SmartPointer.h"

namespace dart {
namespace renderer {
Expand Down Expand Up @@ -176,9 +177,6 @@ class Shape : public virtual common::Subject
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

typedef std::shared_ptr<Shape> ShapePtr;
typedef std::shared_ptr<const Shape> ConstShapePtr;

} // namespace dynamics
} // namespace dart

Expand Down
35 changes: 27 additions & 8 deletions dart/dynamics/SoftBodyNode.cpp
Expand Up @@ -131,23 +131,32 @@ SoftBodyNode::~SoftBodyNode()
}

//==============================================================================
void SoftBodyNode::removeSoftBodyShapes()
ShapePtr SoftBodyNode::removeSoftBodyShapes()
{
for(size_t i=0; i<mEntityP.mVizShapes.size(); )
ShapePtr oldShape;
for(size_t i=0; i<mBodyP.mColShapes.size(); )
{
if(dynamic_cast<dynamics::SoftMeshShape*>(mEntityP.mVizShapes[i].get()))
removeVisualizationShape(mEntityP.mVizShapes[i]);
if(dynamic_cast<dynamics::SoftMeshShape*>(mBodyP.mColShapes[i].get()))
{
oldShape = mBodyP.mColShapes[i];
removeCollisionShape(oldShape);
}
else
++i;
}

for(size_t i=0; i<mBodyP.mColShapes.size(); )
for(size_t i=0; i<mEntityP.mVizShapes.size(); )
{
if(dynamic_cast<dynamics::SoftMeshShape*>(mBodyP.mColShapes[i].get()))
removeCollisionShape(mBodyP.mColShapes[i]);
if(dynamic_cast<dynamics::SoftMeshShape*>(mEntityP.mVizShapes[i].get()))
{
oldShape = mEntityP.mVizShapes[i];
removeVisualizationShape(oldShape);
}
else
++i;
}

return oldShape;
}

//==============================================================================
Expand All @@ -163,7 +172,7 @@ void SoftBodyNode::setProperties(const Properties& _properties)
void SoftBodyNode::setProperties(const UniqueProperties& _properties)
{
// SoftMeshShape pointers should not be copied between bodies
removeSoftBodyShapes();
ShapePtr oldShape = removeSoftBodyShapes();

size_t newCount = _properties.mPointProps.size();
size_t oldCount = mPointMasses.size();
Expand Down Expand Up @@ -207,6 +216,12 @@ void SoftBodyNode::setProperties(const UniqueProperties& _properties)
mSoftShape = std::shared_ptr<SoftMeshShape>(new SoftMeshShape(this));
addVisualizationShape(mSoftShape);
addCollisionShape(mSoftShape);

if(oldShape) // Copy the properties of the previous soft shape, if it exists
{
mSoftShape->setColor(oldShape->getRGBA());
mSoftShape->setLocalTransform(oldShape->getLocalTransform());
}
}

//==============================================================================
Expand Down Expand Up @@ -1175,6 +1190,10 @@ void SoftBodyNode::draw(renderer::RenderInterface* _ri,
// _ri->setPenColor(fleshColor);
// if (_showMeshs)
{
_ri->setPenColor(mSoftShape->getRGBA());
glEnable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

Eigen::Vector3d pos;
Eigen::Vector3d pos_normalized;
for (size_t i = 0; i < mSoftP.mFaces.size(); ++i)
Expand Down
4 changes: 2 additions & 2 deletions dart/dynamics/SoftBodyNode.h
Expand Up @@ -127,10 +127,10 @@ class SoftBodyNode : public BodyNode
/// Set the Properties of this SoftBodyNode
void setProperties(const UniqueProperties& _properties);

/// Remove any unwarranted SoftBodyShapes
/// Remove all SoftBodyShapes and return the last one that was encountered
/// Note: This will be deprecated once VisualizationNodes and CollisionNodes
/// are implemented. Please see #394.
void removeSoftBodyShapes();
ShapePtr removeSoftBodyShapes();


/// Get the Properties of this SoftBodyNode
Expand Down
20 changes: 20 additions & 0 deletions dart/math/Helpers.h
Expand Up @@ -268,6 +268,26 @@ inline Eigen::Vector3d Red()
return Eigen::Vector3d(0.9, 0.1, 0.1);
}

inline Eigen::Vector3d Fuschia()
{
return Eigen::Vector3d(1.0, 0.0, 0.5);
}

inline Eigen::Vector4d Fuschia(double alpha)
{
return Eigen::Vector4d(1.0, 0.0, 0.5, alpha);
}

inline Eigen::Vector4d Orange(double alpha)
{
return Eigen::Vector4d(1.0, 0.63, 0.0, alpha);
}

inline Eigen::Vector3d Orange()
{
return Eigen::Vector3d(1.0, 0.63, 0.0);
}

inline Eigen::Vector4d Green(double alpha)
{
return Eigen::Vector4d(0.1, 0.9, 0.1, alpha);
Expand Down

0 comments on commit 7c744b6

Please sign in to comment.