Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

robot/sim/VisualIKORTest

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)2003 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: VisualIKORTest 1033 2004-02-11 20:47:52Z jungd $
00019   $Revision: 1.3 $
00020   $Date: 2004-02-11 15:47:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_SIM_VISUALIKORTEST_
00026 #define _ROBOT_SIM_VISUALIKORTEST_
00027 
00028 #include <robot/sim/sim>
00029 
00030 #include <robot/sim/IKORTest>
00031 
00032 #include <base/DOM>
00033 #include <gfx/Visual>
00034 #include <gfx/Segment3>
00035 #include <gfx/Color4>
00036 #include <robot/sim/BasicEnvironment>
00037 
00038 #include <osg/Switch>
00039 #include <osg/Array>
00040 #include <osg/Geometry>
00041 
00042 
00043 namespace robot {
00044 namespace sim {
00045 
00046 
00047 /// provides a Visual to display IKORTest results
00048 class VisualIKORTest :  public IKORTest, public gfx::Visual
00049 {
00050 public:
00051   VisualIKORTest(ref<base::VFile> testSpecification,
00052                  ref<base::VFileSystem> fs, ref<base::Cache> cache);
00053 
00054   virtual String className() const { return String("VisualIKORTest"); }
00055 
00056   
00057   // Visual
00058   virtual bool visualTypeSupported(VisualType type) const { return (type==OSGVisual); }
00059   virtual osg::Node* createOSGVisual(Attributes visualAttributes=0) const;
00060   
00061   virtual void updateVisuals() const;
00062   
00063   
00064   // Externalizable
00065   virtual bool formatSupported(const String format, Real version = 1.0, ExternalizationType type = IO) const
00066     { return (    ((format=="svg") && (version==1.0) && (type==Externalizable::Output))
00067                || IKORTest::formatSupported(format,version,type)); }
00068 
00069   virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0);
00070 
00071 
00072 protected:
00073 
00074   typedef base::array<gfx::Segment3> LineSegArray;
00075 
00076   // helpers for rendering line diagram of test results
00077   static LineSegArray manipToolAsLines(const KinematicChain& chain, const Vector& q, Int numPlatformLinks);
00078   static LineSegArray platformAsLines(ref<const PlatformDescription> platfDescr, const KinematicChain& platfChain, const Vector& q, Real steerAngle);
00079   static LineSegArray obstaclesAsLines(ref<const BasicEnvironment> env);
00080   static LineSegArray trajectoryAsLines(const array<base::Vector>& xs);
00081   
00082   // cached OSGVisual & construction helpers
00083   mutable Visual::Attributes attributes;
00084   mutable osg::ref_ptr<osg::Switch> node;
00085 
00086   static osg::Vec3Array* newVertexArrayFromLines(const LineSegArray& lines);
00087   static osg::Geometry* newGeometryFromLines(const LineSegArray& lines, const gfx::Color4& color);
00088   
00089   osg::Node* osgCreateAxes() const;
00090   osg::Node* osgCreateObstacles() const;
00091   osg::Node* osgCreateManipulator() const;
00092   osg::Node* osgCreateTrajectory() const;
00093   
00094   mutable array< osg::ref_ptr<osg::Switch> > testPlatfSwitches; ///< one Switch per test, where children are joint space configurations of platform
00095   mutable array< osg::ref_ptr<osg::Switch> > testManipSwitches; ///< one Switch per test, where children are joint space configurations of manipulator
00096 
00097   
00098   // helpers for SVG output
00099   base::Matrix4 svgTransform;
00100   void svgLine(base::Externalizer& e, base::dom::DOMElement* svgElem, const gfx::Segment3& line) const;
00101   void svgLines(base::Externalizer& e, base::dom::DOMElement* svgElem, const LineSegArray& lines) const;
00102   void svgText(base::Externalizer& e, base::dom::DOMElement* svgElem, const Point3& pos, const String& text, Real size=11) const;
00103   void svgOutputAxes(base::Externalizer& e, base::dom::DOMElement* svgElem) const;
00104   
00105 };
00106 
00107 
00108 } // namespace sim
00109 } // namespace robot
00110 
00111 #endif

Generated on Thu Jul 29 15:56:44 2004 for OpenSim by doxygen 1.3.6