Urdf2Inventor.h
Go to the documentation of this file.
00001 
00031 #ifndef URDF2INVENTOR_URDF2INVENTOR_H
00032 #define URDF2INVENTOR_URDF2INVENTOR_H
00033 // Copyright Jennifer Buehler
00034 
00035 //-----------------------------------------------------
00036 #include <urdf2inventor/ConversionResult.h>
00037 #include <urdf2inventor/MeshConvertRecursionParams.h>
00038 
00039 #include <urdf_traverser/UrdfTraverser.h>
00040 
00041 #include <baselib_binding/SharedPtr.h>
00042 
00043 #include <iostream>
00044 #include <string>
00045 #include <map>
00046 #include <vector>
00047 
00048 #include <Eigen/Core>
00049 #include <Eigen/Geometry>
00050 
00051 #include <Inventor/nodes/SoSeparator.h>
00052 
00053 
00054 namespace urdf2inventor
00055 {
00056 
00063 class Urdf2Inventor
00064 {
00065 public:
00066     // the .iv files are represented as strings
00067     typedef std::string MeshFormat;
00068     typedef ConversionResult<MeshFormat> ConversionResultT;
00069     typedef baselib_binding::shared_ptr<ConversionResultT>::type ConversionResultPtr;
00070     typedef baselib_binding::shared_ptr<ConversionParameters>::type ConversionParametersPtr;
00071 
00072     typedef MeshConvertRecursionParams<MeshFormat> MeshConvertRecursionParamsT;
00073     typedef baselib_binding::shared_ptr<MeshConvertRecursionParamsT>::type MeshConvertRecursionParamsPtr;
00074 
00075     typedef baselib_binding::shared_ptr<urdf_traverser::UrdfTraverser>::type UrdfTraverserPtr;
00076     typedef baselib_binding::shared_ptr<const urdf_traverser::UrdfTraverser>::type UrdfTraverserConstPtr;
00077 
00078     typedef urdf_traverser::EigenTransform EigenTransform;
00079     typedef urdf_traverser::LinkPtr LinkPtr;
00080     typedef urdf_traverser::LinkConstPtr LinkConstPtr;
00081     typedef urdf_traverser::JointPtr JointPtr;
00082     typedef urdf_traverser::JointConstPtr JointConstPtr;
00083     //typedef urdf_traverser::;
00084 
00085     // output file format to convert the meshes to
00086     static std::string OUTPUT_EXTENSION;
00087 
00088     // within the output directory specified in the node, another directory is going to be created
00089     // to contain the mesh files. The name of this directory can be specified here.
00090     static std::string MESH_OUTPUT_DIRECTORY_NAME;
00091     // within the output directory specified in the node, another directory is going to be created
00092     // to contain the texture files. The name of this directory can be specified here.
00093     static std::string TEX_OUTPUT_DIRECTORY_NAME;
00094 
00102     explicit Urdf2Inventor(const UrdfTraverserPtr& traverser,
00103                            float _scaleFactor = 1):
00104         urdf_traverser(traverser),
00105         scaleFactor(_scaleFactor),
00106         isScaled(false)
00107     {
00108         assert(urdf_traverser.get());
00109     }
00110 
00111     ~Urdf2Inventor()
00112     {
00113     }
00114 
00119     bool joinFixedLinks(const std::string& from_link);
00120 
00124     bool allRotationsToAxis(const std::string& fromLinkName, const Eigen::Vector3d& axis);
00125 
00126 
00135     // SoNode * loadAndGetAsInventor(const std::string& filename, const std::string fromLink="", bool useScaleFactor = true);
00136 
00157     SoNode * getAsInventor(const std::string& fromLink, bool useScaleFactor,
00158                            bool addAxes, float axesRadius, float axesLength,
00159                            const EigenTransform& addVisualTransform,
00160                            std::set<std::string> * textureFiles);
00161 
00179     bool writeAsInventor(const std::string& outputFilename,  const std::string& fromLink /*= ""*/,
00180                          bool useScaleFactor /*= true*/, const EigenTransform& addVisualTransform,
00181                          bool _addAxes = false, float _axesRadius = 0.003, float _axesLength = 0.015);
00182 
00188     ConversionResultPtr loadAndConvert(const std::string& urdfFilename,
00189                                        bool joinFixed,
00190                                        const ConversionParametersPtr& params);
00191 
00192 
00196     bool loadModelFromFile(const std::string& urdfFilename);
00197 
00203     ConversionParametersPtr getBasicConversionParams(const std::string& rootLink,
00204             const std::string& material,
00205             const EigenTransform& addVisualTransform)
00206     {
00207         return ConversionParametersPtr(new ConversionParameters(rootLink, material, addVisualTransform));
00208     }
00209 
00223     virtual ConversionResultPtr convert(const ConversionParametersPtr& params,
00224                                         const MeshConvertRecursionParamsPtr& meshParams=MeshConvertRecursionParamsPtr());
00225 
00229     bool printModel();
00230 
00234     bool printModel(const std::string& fromLink);
00235 
00240     void printJointNames(const std::string& fromLink);
00241 
00246     bool getJointNames(const std::string& fromLink, const bool skipFixed, std::vector<std::string>& result);
00247 
00251     void cleanup();
00252 
00253 protected:
00254 
00255     UrdfTraverserPtr getTraverser()
00256     {
00257         return urdf_traverser;
00258     }
00259 
00260     UrdfTraverserConstPtr readTraverser() const
00261     {
00262         return urdf_traverser;
00263     }
00264 
00265 
00273     virtual ConversionResultPtr preConvert(const ConversionParametersPtr& params);
00274 
00285     virtual ConversionResultPtr postConvert(const ConversionParametersPtr& params, ConversionResultPtr& result);
00286 
00290     bool scale();
00291 
00292     inline float getScaleFactor() const
00293     {
00294         return scaleFactor;
00295     }
00296 
00297     void addLocalAxes(const LinkConstPtr& link, SoSeparator * addToNode, bool useScaleFactor,
00298                       float _axesRadius, float _axesLength) const;
00299 
00300     EigenTransform getTransform(const LinkPtr& from_link,  const JointPtr& to_joint);
00301 
00302 private:
00303 
00308     SoNode * getAsInventor(const LinkPtr& from_link, bool useScaleFactor,
00309                            bool _addAxes, float _axesRadius, float _axesLength,
00310                            const EigenTransform& addTransform,
00311                            std::set<std::string> * textureFiles);
00312 
00316     bool writeInventorFile(SoNode * node, const std::string& filename);
00317 
00322     bool writeAsInventor(const std::string& outFilename, const LinkPtr& from_link,
00323                          bool useScaleFactor /*= true*/, const EigenTransform& addTransform,
00324                          bool _addAxes = false, float _axesRadius = 0.003, float _axesLength = 0.015);
00325 
00326 
00327     UrdfTraverserPtr urdf_traverser;
00328 
00329     // The graspit model might ahve to be scaled compared to the urdf model, this is the scale factor which does that.
00330     float scaleFactor;
00331     bool isScaled;
00332 };
00333 
00334 }  //  namespace urdf2inventor
00335 #endif   // URDF2INVENTOR_URDF2INVENTOR_H


urdf2inventor
Author(s): Jennifer Buehler
autogenerated on Fri Mar 1 2019 03:38:11