From c37ff5ca9b772a2bf141ab09cfeb80af237fb119 Mon Sep 17 00:00:00 2001 From: "M.X. Grey" Date: Thu, 19 Mar 2015 00:03:37 -0400 Subject: [PATCH 1/3] added alpha channel for Shape color --- dart/dynamics/Shape.cpp | 27 ++++++++++++++++++++++++--- dart/dynamics/Shape.h | 22 +++++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/dart/dynamics/Shape.cpp b/dart/dynamics/Shape.cpp index 686af8d8eea86..1bdc39b1d8780 100644 --- a/dart/dynamics/Shape.cpp +++ b/dart/dynamics/Shape.cpp @@ -46,7 +46,7 @@ Shape::Shape(ShapeType _type) : mBoundingBoxDim(0, 0, 0), mVolume(0.0), mID(mCounter++), - mColor(0.5, 0.5, 1.0), + mColor(0.5, 0.5, 1.0, 1.0), mTransform(Eigen::Isometry3d::Identity()), mType(_type) { @@ -56,10 +56,31 @@ Shape::~Shape() { } void Shape::setColor(const Eigen::Vector3d& _color) { - mColor = _color; + setRGB(_color); } -const Eigen::Vector3d& Shape::getColor() const { +void Shape::setColor(const Eigen::Vector4d &_color) { + setRGBA(_color); +} + +void Shape::setRGB(const Eigen::Vector3d& _rgb) { + mColor << _rgb, mColor[3]; + setRGBA(mColor); +} + +void Shape::setRGBA(const Eigen::Vector4d& _rgba) { + mColor = _rgba; +} + +Eigen::Vector3d Shape::getColor() const { + return getRGB(); +} + +Eigen::Vector3d Shape::getRGB() const { + return Eigen::Vector3d(mColor[0], mColor[1], mColor[2]); +} + +const Eigen::Vector4d& Shape::getRGBA() const { return mColor; } diff --git a/dart/dynamics/Shape.h b/dart/dynamics/Shape.h index 833aec11b61ec..d1ce192ae7549 100644 --- a/dart/dynamics/Shape.h +++ b/dart/dynamics/Shape.h @@ -72,11 +72,27 @@ class Shape { /// \brief Destructor virtual ~Shape(); - /// \brief Set color. + /// \brief Set RGB color components (leave alpha alone). Identical to + /// setRGB(const Eigen::Vector3d&) void setColor(const Eigen::Vector3d& _color); + /// \brief Set RGBA color components + void setColor(const Eigen::Vector4d& _color); + + /// \brief Set RGB color components (leave alpha alone) + void setRGB(const Eigen::Vector3d& _rgb); + + /// \brief Set RGBA color components + virtual void setRGBA(const Eigen::Vector4d& _rgba); + /// \brief Get color. - const Eigen::Vector3d& getColor() const; + Eigen::Vector3d getColor() const; + + /// \brief Get RGB color components + Eigen::Vector3d getRGB() const; + + /// \brief Get RGBA color components + const Eigen::Vector4d& getRGBA() const; /// \brief Get dimensions of bounding box. /// The dimension will be automatically determined by the sub-classes @@ -139,7 +155,7 @@ class Shape { int mID; /// \brief Color for the primitive. - Eigen::Vector3d mColor; + Eigen::Vector4d mColor; /// \brief Local geometric transformation of the Shape w.r.t. parent frame. Eigen::Isometry3d mTransform; From 55cbd381c05db26b880884bbef4a6c248911cd9d Mon Sep 17 00:00:00 2001 From: "M.X. Grey" Date: Thu, 19 Mar 2015 00:52:07 -0400 Subject: [PATCH 2/3] added Color functions --- apps/softBodies/Main.cpp | 14 +++++++ dart/math/Helpers.h | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/apps/softBodies/Main.cpp b/apps/softBodies/Main.cpp index 3e6b4d2fa0590..d798a78751045 100644 --- a/apps/softBodies/Main.cpp +++ b/apps/softBodies/Main.cpp @@ -55,6 +55,20 @@ int main(int argc, char* argv[]) DART_DATA_PATH"skel/softBodies.skel"); assert(myWorld != NULL); + for(size_t i=0; igetNumSkeletons(); ++i) + { + dart::dynamics::Skeleton* skel = myWorld->getSkeleton(i); + for(size_t j=0; jgetNumBodyNodes(); ++j) + { + dart::dynamics::BodyNode* bn = skel->getBodyNode(j); + for(size_t k=0; kgetNumVisualizationShapes(); ++k) + { + dart::dynamics::Shape* vs = bn->getVisualizationShape(k); + vs->setColor(dart::Color::Random()); + } + } + } + // create a window and link it to the world MyWindow window; window.setWorld(myWorld); diff --git a/dart/math/Helpers.h b/dart/math/Helpers.h index 5b4b91daa767b..1ef3ac739df00 100644 --- a/dart/math/Helpers.h +++ b/dart/math/Helpers.h @@ -255,6 +255,87 @@ inline int castUIntToInt(size_t _x) } } // namespace math + +namespace Color +{ + +inline Eigen::Vector4d Red(double alpha) +{ + return Eigen::Vector4d(0.9, 0.1, 0.1, alpha); +} + +inline Eigen::Vector3d Red() +{ + return Eigen::Vector3d(0.9, 0.1, 0.1); +} + +inline Eigen::Vector4d Green(double alpha) +{ + return Eigen::Vector4d(0.1, 0.9, 0.1, alpha); +} + +inline Eigen::Vector3d Green() +{ + return Eigen::Vector3d(0.1, 0.9, 0.1); +} + +inline Eigen::Vector4d Blue(double alpha) +{ + return Eigen::Vector4d(0.1, 0.1, 0.9, alpha); +} + +inline Eigen::Vector3d Blue() +{ + return Eigen::Vector3d(0.1, 0.1, 0.9); +} + +inline Eigen::Vector4d White(double alpha) +{ + return Eigen::Vector4d(1.0, 1.0, 1.0, alpha); +} + +inline Eigen::Vector3d White() +{ + return Eigen::Vector3d(1.0, 1.0, 1.0); +} + +inline Eigen::Vector4d Black(double alpha) +{ + return Eigen::Vector4d(0.05, 0.05, 0.05, alpha); +} + +inline Eigen::Vector3d Black() +{ + return Eigen::Vector3d(0.05, 0.05, 0.05); +} + +inline Eigen::Vector4d Gray(double alpha) +{ + return Eigen::Vector4d(0.6, 0.6, 0.6, alpha); +} + +inline Eigen::Vector3d Gray() +{ + return Eigen::Vector3d(0.6, 0.6, 0.6); +} + +inline Eigen::Vector4d Random(double alpha) +{ + return Eigen::Vector4d(math::random(0.0, 1.0), + math::random(0.0, 1.0), + math::random(0.0, 1.0), + alpha); +} + +inline Eigen::Vector3d Random() +{ + return Eigen::Vector3d(math::random(0.0, 1.0), + math::random(0.0, 1.0), + math::random(0.0, 1.0)); +} + +} // namespace Color + } // namespace dart #endif // DART_MATH_HELPERS_H_ From 8275988f1de8624edbb7f7ec9b80f7a4e7ab8618 Mon Sep 17 00:00:00 2001 From: "M.X. Grey" Date: Sat, 21 Mar 2015 17:26:03 -0400 Subject: [PATCH 3/3] updated ArrowShape class --- apps/simpleFrames/Main.cpp | 9 +++++---- dart/dynamics/ArrowShape.cpp | 7 ++++--- dart/dynamics/ArrowShape.h | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/simpleFrames/Main.cpp b/apps/simpleFrames/Main.cpp index 9ada3809886ec..2b797ddb910e9 100644 --- a/apps/simpleFrames/Main.cpp +++ b/apps/simpleFrames/Main.cpp @@ -78,10 +78,11 @@ int main(int argc, char* argv[]) myWorld.addEntity(&A); SimpleFrame arrow(Frame::World(), "arrow"); - arrow.addVisualizationShape(new ArrowShape(Eigen::Vector3d(0.1,-0.1, 0.0), - Eigen::Vector3d(0.1, 0.0, 0.0), - ArrowShape::Properties(0.002, 1.8), - Eigen::Vector3d(1.0, 0.5, 0.5))); + arrow.addVisualizationShape( + new ArrowShape(Eigen::Vector3d(0.1,-0.1, 0.0), + Eigen::Vector3d(0.1, 0.0, 0.0), + ArrowShape::Properties(0.002, 1.8), + Eigen::Vector4d(1.0, 0.5, 0.5, 1.0))); myWorld.addEntity(&arrow); // CAREFUL: For an Entity (or Frame) that gets added to the world to be diff --git a/dart/dynamics/ArrowShape.cpp b/dart/dynamics/ArrowShape.cpp index 3e7696a782f39..10713e5d3f1a9 100644 --- a/dart/dynamics/ArrowShape.cpp +++ b/dart/dynamics/ArrowShape.cpp @@ -58,7 +58,7 @@ ArrowShape::Properties::Properties(double _radius, double _headRadiusScale, ArrowShape::ArrowShape(const Eigen::Vector3d& _tail, const Eigen::Vector3d& _head, const Properties& _properties, - const Eigen::Vector3d& _color, + const Eigen::Vector4d& _color, size_t _resolution) : MeshShape(Eigen::Vector3d::Ones(), nullptr), mTail(_tail), @@ -96,7 +96,7 @@ void ArrowShape::setProperties(const Properties& _properties) } //============================================================================== -void ArrowShape::setColor(const Eigen::Vector3d& _color) +void ArrowShape::setRGBA(const Eigen::Vector4d& _color) { mColor = _color; for(size_t i=0; imNumMeshes; ++i) @@ -104,7 +104,8 @@ void ArrowShape::setColor(const Eigen::Vector3d& _color) aiMesh* mesh = mMesh->mMeshes[i]; for(size_t j=0; jmNumVertices; ++j) { - mesh->mColors[0][j] = aiColor4D(_color.x(), _color.y(), _color.z(), 1.0f); + mesh->mColors[0][j] = aiColor4D(_color[0], _color[1], + _color[2], _color[3]); } } } diff --git a/dart/dynamics/ArrowShape.h b/dart/dynamics/ArrowShape.h index a8a69bcb2cc0e..dc94ddd865684 100644 --- a/dart/dynamics/ArrowShape.h +++ b/dart/dynamics/ArrowShape.h @@ -73,7 +73,7 @@ class ArrowShape : public MeshShape /// properties. ArrowShape(const Eigen::Vector3d& _tail, const Eigen::Vector3d& _head, const Properties& _properties = Properties(), - const Eigen::Vector3d& _color=Eigen::Vector3d(0.5,0.5,1.0), + const Eigen::Vector4d& _color=Eigen::Vector4d(0.5,0.5,1.0,1.0), size_t _resolution=10); /// Set the positions of the tail and head of the arrow without changing any @@ -90,7 +90,7 @@ class ArrowShape : public MeshShape void setProperties(const Properties& _properties); /// Set the color of this arrow - void setColor(const Eigen::Vector3d& _color) override; + void setRGBA(const Eigen::Vector4d& _color) override; /// Get the properties of this arrow const Properties& getProperties() const;