00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
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 
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   
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   
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   
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   
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; 
00095   mutable array< osg::ref_ptr<osg::Switch> > testManipSwitches; 
00096 
00097   
00098   
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 } 
00109 } 
00110 
00111 #endif