diff --git a/CMakeLists.txt b/CMakeLists.txt index f7df51814750b746271c8bb54dcd41bc7eccaf67..36f5606877932ecd6d8c5731a6484a09ff4ed3df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,11 @@ SET(PROJECT_DESCRIPTION "Corba server for gepetto-viewer") SET(PROJECT_URL "") SET(${PROJECT_NAME}_HEADERS + include/gepetto/viewer/corba/windows-manager.h + include/gepetto/viewer/corba/server.hh include/gepetto/viewer/corba/client.hh include/gepetto/viewer/corba/se3.hh + include/gepetto/viewer/corba/fwd.hh ) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) @@ -47,6 +50,8 @@ ADD_REQUIRED_DEPENDENCY("urdfdom") ADD_REQUIRED_DEPENDENCY("eigen3 >= v3.0.5") SEARCH_FOR_BOOST() +PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME}) + INCLUDE_DIRECTORIES(SYSTEM ${EIGEN3_INCLUDE_DIRS}) ADD_SUBDIRECTORY(src) diff --git a/idl/gepetto/viewer/graphical-interface.idl b/idl/gepetto/viewer/graphical-interface.idl index 1e5de671a9262b1adbdcf92748ed61f9c62c6cce..9489eaee3dad25240f5c75fd755bc87fb851627c 100644 --- a/idl/gepetto/viewer/graphical-interface.idl +++ b/idl/gepetto/viewer/graphical-interface.idl @@ -17,9 +17,9 @@ module corbaserver { // the "refresh" function each time you want actualize position of the Viewer. // This system is used to synchronize movement of all objects. -typedef double Transform [7]; -typedef double Position [3]; -typedef double Color [4]; +typedef float Transform [7]; +typedef float Position [3]; +typedef float Color [4]; /// Corba exception travelling through the Corba channel interface GraphicalInterface { @@ -36,6 +36,7 @@ typedef double Color [4]; /// \param input name : name of the new window. /// return the ID of the newly create window. unsigned long createWindow(in string name) raises (Error); + unsigned long getWindowID (in string name) raises (Error); /// Print names of nodes on the SceneViewer-corbaserver terminal. @@ -115,6 +116,34 @@ typedef double Color [4]; /// \param input RGBAcolor : color of the face. boolean addTriangleFace(in string faceName, in Position pos1, in Position pos2, in Position pos3, in Color RGBAcolor) raises (Error); + + // Add a sphere with xyz axis + // The colors are x=red, y=green, z=blue (xyz=RGB) + // \param input nodeName : name of the node + // \param input RGBAcolor : color of the sphere + // \param input radius : radius of the sphere + // \param input sizeAxis : size of the axis (proportionnaly to the sphere radius, size axis = 1 -> axis are radius*4 in length and radius/4 in radius) + boolean addXYZaxis(in string nodeName, in Color RGBAcolor,in float radius,in float sizeAxis) raises(Error); + + // Add an empty roadmap to the scene + // \param input nameCorba : name of the roadmap + // \param input RGBAcolorNode : color of the sphere + // \param input radius : radius of the sphere + // \param input sizeAxis :size of the axis (proportionnaly to the sphere radius, size axis = 1 -> axis are radius*4 in length and radius/4 in radius) + // \param input RGBAcolorEdge : color of the edges + boolean createRoadmap(in string nameCorba,in Color RGBAcolorNode, in float radius, in float sizeAxis, in Color RGBAcolorEdge) raises(Error); + + // Add an edge to the roadmap + // \param input nameRoadmap : name of the roadmap + // \param input posFrom : position of the beginning of the edge + // \param input posTo : position of the end of the edge (not oriented edge, order doesn't matter) + boolean addEdgeToRoadmap(in string nameRoadmap, in Position posFrom, in Position posTo)raises(Error); + + // Add a node to the roadmap + // \param input nameRoadmap : name of the roadmap + // \param input configuration : configuration of the node + boolean addNodeToRoadmap(in string nameRoadmap, in Transform configuration)raises(Error); + /// Create a node from an urdf file /// \param robotName Name of the node that will contain the robot geometry, /// each geometric part is prefixed by this name, @@ -128,6 +157,7 @@ typedef double Color [4]; /// a groupNode is created and each link will be child node of this node. /// Links are named "prefix/linkName", linkName is the name of the link /// in the URDF file. + boolean addURDF (in string robotName, in string urdfFilePath, in string meshDataRootDir) raises (Error); @@ -179,9 +209,14 @@ typedef double Color [4]; /// \param input groupName : name of the mother node (=group node). boolean addToGroup(in string nodeName, in string groupName) raises (Error); + /// remove the node from the child list of a group node. + /// \param input nodeName : name of the child node. + /// \param input groupName : name of the mother node (=group node). + boolean removeFromGroup(in string nodeName, in string groupName) raises (Error); + /// Set a new configuration to a node. THIS CONFIGURATION WILL AFFECTIVE ONLY AFTER CALLING REFRESH FUNCTION!!! /// \param input nodeName : name of the node. - /// \param input configuration : Double[7] new configuration. + /// \param input configuration : Float[7] new configuration. boolean applyConfiguration(in string nodeName, in Transform configuration) raises (Error); /// Add Landmark at the center of a node diff --git a/include/gepetto/viewer/corba/client.hh b/include/gepetto/viewer/corba/client.hh index 375e6f95126f93f45460d3e9a9f27b6f7d95a45f..b8f646d43ef5fa4a4ecb7f9dcbb28bff6c80dc48 100644 --- a/include/gepetto/viewer/corba/client.hh +++ b/include/gepetto/viewer/corba/client.hh @@ -24,12 +24,13 @@ private: CORBA::ORB_var orb_; gepetto::corbaserver::GraphicalInterface_var manager_; - static void se3ToCorba(CORBA::Double* corbaPosition, const se3::SE3& se3position); + static void se3ToCorba(CORBA::Float* corbaPosition, const se3::SE3& se3position); protected: public: typedef CORBA::ULong WindowID; + typedef float value_type; // Default constructor ClientCpp(); @@ -52,27 +53,27 @@ public: bool addSceneToWindow(const char* sceneName, const WindowID windowId) ; - bool addBox(const char* boxName, const float boxSize1, const float boxSize2, const float boxSize3, const double* color); + bool addBox(const char* boxName, const float boxSize1, const float boxSize2, const float boxSize3, const value_type* color); //bool addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3) ; //bool addCapsule(const char* capsuleName, float radius, float height) ; - bool addCapsule(const char* capsuleName, const float radius, const float height, const double* color); + bool addCapsule(const char* capsuleName, const float radius, const float height, const value_type* color); bool addMesh(const char* meshName, const char* meshPath) ; //bool addCone(const char* coneName, float radius, float height) ; - bool addCone(const char* coneName, const float radius, const float height, const double* color); + bool addCone(const char* coneName, const float radius, const float height, const value_type* color); //bool addCylinder(const char* cylinderName, float radius, float height) ; - bool addCylinder(const char* cylinderName, const float radius, const float height, const double* color); + bool addCylinder(const char* cylinderName, const float radius, const float height, const value_type* color); //bool addSphere(const char* sphereName, float radius) ; - bool addSphere(const char* sphereName, const float radius, const double* color); + bool addSphere(const char* sphereName, const float radius, const value_type* color); - bool addLine(const char* lineName, const double* pos1, const double* pos2, const double* color); + bool addLine(const char* lineName, const value_type* pos1, const value_type* pos2, const value_type* color); - bool addTriangleFace(const char* lineName, const double* pos1, const double* pos2, const double* pos3, const double* color); - bool addSquareFace(const char* lineName, const double* pos1, const double* pos2, const double* pos3, const double* pos4, const double* color); + bool addTriangleFace(const char* lineName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* color); + bool addSquareFace(const char* lineName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* pos4, const value_type* color); bool addURDF(const char* urdfName, const char* urdfPath, const char* urdfPackagePath); diff --git a/src/fwd.hh b/include/gepetto/viewer/corba/fwd.hh similarity index 100% rename from src/fwd.hh rename to include/gepetto/viewer/corba/fwd.hh diff --git a/include/gepetto/viewer/corba/se3.hh b/include/gepetto/viewer/corba/se3.hh index 7ab1d4bf8c1116bd2588222bd148ccf763b61eee..f9aa02cb7eb695a024fa494e7f3eb4672b30f7ce 100644 --- a/include/gepetto/viewer/corba/se3.hh +++ b/include/gepetto/viewer/corba/se3.hh @@ -124,7 +124,7 @@ private: Matrix3 rot; Vector3 trans; }; -typedef SE3Tpl<double,0> SE3; +typedef SE3Tpl<float,0> SE3; } // namespace se3 #endif // ifndef __se3_se3_hpp__ diff --git a/src/server.hh b/include/gepetto/viewer/corba/server.hh similarity index 87% rename from src/server.hh rename to include/gepetto/viewer/corba/server.hh index 65d418b37e0033d9a74cb054679e89554b3eb42d..8c58df39159fdef0e624aa03f6ec2b600929ab16 100644 --- a/src/server.hh +++ b/include/gepetto/viewer/corba/server.hh @@ -11,13 +11,16 @@ #ifndef SCENEVIEWER_CORBASERVER_SERVER_HH # define SCENEVIEWER_CORBASERVER_SERVER_HH - -#include "fwd.hh" +#include "gepetto/viewer/corba/fwd.hh" +#include <gepetto/viewer/corba/windows-manager.h> namespace graphics { namespace corbaServer { + using graphics::WindowsManager; + using graphics::WindowsManagerPtr_t; + /// Implementation of Hpp module Corba server. /// This class initializes the Corba server and starts the following Corba interface implementations. @@ -50,6 +53,7 @@ namespace graphics { public: /// Constructor + /// \param the object that handles CORBA requests. /// \param argc, argv parameter to feed ORB initialization. /// \param multiThread whether the server may process request using /// multithred policy. @@ -59,7 +63,8 @@ namespace graphics /// \note It is highly recommended not to enable multi-thread policy in /// CORBA request processing if this library is run from an openGL /// based GUI, since OpenGL does not support multithreading. - Server (int argc, const char* argv[], bool multiThread = false); + Server (WindowsManagerPtr_t windowsManager, int argc, + const char* argv[], bool multiThread = false); /// \brief Shutdown CORBA server ~Server (); @@ -74,8 +79,10 @@ namespace graphics /// returns. int processRequest (bool loop); - //core::ProblemSolverPtr_t problemSolver () const; - //core::ProblemSolverPtr_t problemSolver (); + WindowsManagerPtr_t windowsManager () const + { + return windowsManager_; + } private: @@ -92,6 +99,7 @@ namespace graphics impl::Server* private_; + WindowsManagerPtr_t windowsManager_; }; } // end of namespace corbaServer. diff --git a/include/gepetto/viewer/corba/windows-manager.h b/include/gepetto/viewer/corba/windows-manager.h new file mode 100644 index 0000000000000000000000000000000000000000..7fbd51d6e278bf3bc629c5d7707732bd061adb74 --- /dev/null +++ b/include/gepetto/viewer/corba/windows-manager.h @@ -0,0 +1,152 @@ +// Copyright (c) 2014, LAAS-CNRS +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of gepetto-viewer. +// gepetto-viewer is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// gepetto-viewer is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// gepetto-viewer. If not, see <http://www.gnu.org/licenses/>. + +#ifndef SCENEVIEWER_WINDOWMANAGERS_HH +#define SCENEVIEWER_WINDOWMANAGERS_HH + +#include <gepetto/viewer/window-manager.h> +#include <gepetto/viewer/roadmap-viewer.h> +#include <boost/thread/mutex.hpp> + +namespace graphics { + + struct NodeConfiguration { + NodePtr_t node; + osgVector3 position; + osgQuat quat; + }; + + DEF_CLASS_SMART_PTR(WindowsManager) + + class WindowsManager + { + public: + // Typedef for position and color values. + typedef osg::Vec3f::value_type value_type; + typedef unsigned int WindowID; + + typedef std::map <std::string, WindowID> WindowIDMap_t; + WindowIDMap_t windowIDmap_; + + private: + typedef std::vector <WindowManagerPtr_t> WindowManagerVector_t; + WindowManagerVector_t windowManagers_; + std::map<std::string, NodePtr_t> nodes_; + std::map<std::string, GroupNodePtr_t> groupNodes_; + std::map<std::string, RoadmapViewerPtr_t> roadmapNodes_; + boost::mutex mtx_; + int rate_; + std::list<NodeConfiguration> newNodeConfigurations_; + + static osgVector4 getColor(const std::string& colorName); + static osgVector4 getColor(const float* color); + static std::string parentName(const std::string& name); + static VisibilityMode getVisibility(const std::string& visibilityName); + static WireFrameMode getWire(const std::string& wireName); + static LightingMode getLight(const std::string& lightName); + void initParent(const std::string& nodeName, NodePtr_t node); + void addNode(const std::string& nodeName, NodePtr_t node); + void addGroup(const std::string& groupName, GroupNodePtr_t group); + void threadRefreshing(WindowManagerPtr_t window); + static osgQuat corbaConfToOsgQuat(const value_type* configurationCorba); + static osgVector3 corbaConfToOsgVec3(const value_type* configurationCorba); + + protected: + /** + \brief Default constructor + */ + WindowsManager (); + WindowID addWindow (std::string winName, WindowManagerPtr_t newWindow); + + public: + static WindowsManagerPtr_t create (); + + virtual std::vector<std::string> getNodeList(); + virtual std::vector<std::string> getSceneList(); + virtual std::vector<std::string> getWindowList(); + + virtual bool setRate(const int& rate); + virtual void refresh(); + + virtual WindowID createWindow(const char* windowNameCorba); + virtual WindowID getWindowID (const char* windowNameCorba); + + virtual void createScene(const char* sceneNameCorba); + virtual void createSceneWithFloor(const char* sceneNameCorba); + virtual bool addSceneToWindow(const char* sceneNameCorba, const WindowID windowId); + + + virtual bool addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3, const value_type* color); + + virtual bool addCapsule(const char* capsuleName, float radius, float height, const value_type* color); + + virtual bool addMesh(const char* meshNameCorba, const char* meshPathCorba); + + virtual bool addCone(const char* coneName, float radius, float height, const value_type* color); + + virtual bool addCylinder(const char* cylinderName, float radius, float height, const value_type* color); + + virtual bool addSphere(const char* sphereName, float radius, const value_type* color); + + virtual bool addLine(const char* lineName, const value_type* pos1, const value_type* pos2, const value_type* color); + + virtual bool addSquareFace(const char* faceName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* pos4, const value_type* color); + virtual bool addTriangleFace(const char* faceName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* color); + virtual bool addXYZaxis (const char* nodeNameCorba, const value_type* colorCorba, float radius, float sizeAxis); + + virtual bool createRoadmap(const char* nameCorba,const value_type* colorNodeCorba, float radius, float sizeAxis, const value_type* colorEdgeCorba); + + virtual bool addEdgeToRoadmap(const char* nameRoadmapCorba, const value_type* posFromCorba, const value_type* posToCorba); + + virtual bool addNodeToRoadmap(const char* nameRoadmapCorba, const value_type* configuration); + + virtual bool addURDF(const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba); + + virtual bool addUrdfCollision (const char* urdfNameCorba, + const char* urdfPathCorba, + const char* urdfPackagePathCorba) ; + + virtual void addUrdfObjects (const char* urdfNameCorba, + const char* urdfPathCorba, + const char* urdfPackagePathCorba, + bool visual) ; + + virtual bool createGroup(const char* groupNameCorba); + virtual bool addToGroup(const char* nodeNameCorba, const char* groupNameCorba); + virtual bool removeFromGroup (const char* nodeNameCorba, const char* groupNameCorba); + + + virtual bool applyConfiguration(const char* nodeNameCorba, const value_type* configuration); + + virtual bool addLandmark(const char* nodeNameCorba, float size); + virtual bool deleteLandmark(const char* nodeNameCorba); + + virtual bool setVisibility(const char* nodeNameCorba, const char* visibilityModeCorba); + virtual bool setWireFrameMode(const char* nodeNameCorba, const char* wireFrameModeCorba); + virtual bool setLightingMode(const char* nodeNameCorba, const char* lightingModeCorba); + + virtual bool startCapture (const WindowID windowId, const char* filename, + const char* extension); + virtual bool stopCapture (const WindowID windowId); + virtual bool writeNodeFile (const WindowID windowId, const char* filename); + + WindowManagerPtr_t getWindowManager (const WindowID wid); + GroupNodePtr_t getScene (const std::string sceneName); + NodePtr_t getNode (const std::string nodeName); + }; +} /* namespace graphics */ + +#endif /* SCENEVIEWER_WINDOWMANAGERS_HH */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3b2e2c82c996b3be4e546aba34e9ce22bbcb1ef..57afcedce2f034f37a5473d26e3252fd411817c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,7 +32,7 @@ ADD_LIBRARY(${LIBRARY_NAME} graphical-interfaceSK.cc graphical-interface.impl.cpp graphical-interface.impl.hh - server.hh + windows-manager.cpp server.cc server-private.cc server-private.hh diff --git a/src/client-cpp.cc b/src/client-cpp.cc index d862660190fc6ae51160a027e5a8ed1d994dd4c4..cdc9727f4cae078668377c2c60bf6a1f4b4b6659 100644 --- a/src/client-cpp.cc +++ b/src/client-cpp.cc @@ -11,9 +11,9 @@ namespace graphics { namespace corbaServer { -void ClientCpp::se3ToCorba(CORBA::Double* corbaPosition, const se3::SE3& se3position) +void ClientCpp::se3ToCorba(CORBA::Float* corbaPosition, const se3::SE3& se3position) { - Eigen::Quaternion<double> q(se3position.rotation()); + Eigen::Quaternion<value_type> q(se3position.rotation()); corbaPosition[0] = se3position.translation()(0); corbaPosition[1] = se3position.translation()(1); corbaPosition[2] = se3position.translation()(2); @@ -110,7 +110,7 @@ bool ClientCpp::addSceneToWindow(const char* sceneName, const ClientCpp::WindowI return manager_->addBox(boxName, boxSize1, boxSize2, boxSize3); }*/ -bool ClientCpp::addBox(const char* boxName, const float boxSize1, const float boxSize2, const float boxSize3, const double* color) +bool ClientCpp::addBox(const char* boxName, const float boxSize1, const float boxSize2, const float boxSize3, const value_type* color) { return manager_->addBox(boxName, boxSize1, boxSize2, boxSize3, color); } @@ -120,7 +120,7 @@ bool ClientCpp::addBox(const char* boxName, const float boxSize1, const float bo return manager_->addCapsule(capsuleName, radius, height); }*/ -bool ClientCpp::addCapsule(const char* capsuleName, const float radius, const float height, const double* color) +bool ClientCpp::addCapsule(const char* capsuleName, const float radius, const float height, const value_type* color) { return manager_->addCapsule(capsuleName, radius, height, color); } @@ -135,7 +135,7 @@ bool ClientCpp::addMesh(const char* meshName, const char* meshPath) return manager_->addCone(coneName, radius, height); }*/ -bool ClientCpp::addCone(const char* coneName, const float radius, const float height, const double* color) +bool ClientCpp::addCone(const char* coneName, const float radius, const float height, const value_type* color) { return manager_->addCone(coneName, radius, height, color); } @@ -145,7 +145,7 @@ bool ClientCpp::addCone(const char* coneName, const float radius, const float he return manager_->addCylinder(cylinderName, radius, height); }*/ -bool ClientCpp::addCylinder(const char* cylinderName, const float radius, const float height, const double* color) +bool ClientCpp::addCylinder(const char* cylinderName, const float radius, const float height, const value_type* color) { return manager_->addCylinder(cylinderName, radius, height, color); } @@ -155,22 +155,22 @@ bool ClientCpp::addCylinder(const char* cylinderName, const float radius, const return manager_->addSphere(sphereName, radius); }*/ -bool ClientCpp::addSphere(const char* sphereName, const float radius, const double* color) +bool ClientCpp::addSphere(const char* sphereName, const float radius, const value_type* color) { return manager_->addSphere(sphereName, radius, color); } -bool ClientCpp::addLine(const char* lineName, const double* pos1, const double* pos2, const double* color) +bool ClientCpp::addLine(const char* lineName, const value_type* pos1, const value_type* pos2, const value_type* color) { return manager_->addLine(lineName, pos1, pos2, color); } -bool ClientCpp::addTriangleFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* color) +bool ClientCpp::addTriangleFace(const char* faceName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* color) { return manager_->addTriangleFace(faceName, pos1, pos2, pos3, color); } -bool ClientCpp::addSquareFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* pos4, const double* color) +bool ClientCpp::addSquareFace(const char* faceName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* pos4, const value_type* color) { return manager_->addSquareFace(faceName, pos1, pos2, pos3, pos4, color); } @@ -192,7 +192,7 @@ bool ClientCpp::addToGroup(const char* nodeName, const char* groupName) bool ClientCpp::applyConfiguration(const char* nodeName, const se3::SE3& se3position) { - CORBA::Double corbaPosition[7]; + CORBA::Float corbaPosition[7]; ClientCpp::se3ToCorba(corbaPosition, se3position); return manager_->applyConfiguration(nodeName, corbaPosition); } diff --git a/src/corbaserver.cc b/src/corbaserver.cc index d0e33171c684d46e600db8cac7eb4a49ff21b2b5..28f1f37a09c2500f893c418b11ab3aeec8746c4d 100644 --- a/src/corbaserver.cc +++ b/src/corbaserver.cc @@ -9,14 +9,15 @@ // See the COPYING file for more information. #include <iostream> -#include "server.hh" +#include "gepetto/viewer/corba/server.hh" using graphics::corbaServer::Server; int main (int argc, const char* argv[]) { - Server server (argc, argv, true); + graphics::WindowsManagerPtr_t wm = graphics::WindowsManager::create (); + Server server (wm, argc, argv, false); // dernier arg : autorise ou non multithread (original = true) server.startCorbaServer (); server.processRequest(true); diff --git a/src/graphical-interface.impl.cpp b/src/graphical-interface.impl.cpp index 4b42c2eb98a9d61928e89861bfd8a4894bdeecf5..3394473a92d45b57f7ce9f80a85e1b8c1251d94b 100644 --- a/src/graphical-interface.impl.cpp +++ b/src/graphical-interface.impl.cpp @@ -14,160 +14,14 @@ namespace graphics { namespace impl { GraphicalInterface::GraphicalInterface (corbaServer::Server* server) : - windowManagers_ (), nodes_ (), groupNodes_ (), server_ (server), - mtx_ (), rate_ (20), newNodeConfigurations_ () + windowsManager_ (server->windowsManager ()) { } - osgVector4 GraphicalInterface::getColor (const std::string& colorName) - { - if (colorName == "blue") - return osgVector4 (0.f, 0.f, 1.f, 1.f); - else if (colorName == "green") - return osgVector4 (0.f, 1.f, 0.f, 1.f); - else if (colorName == "red") - return osgVector4 (1.f, 0.f, 0.f, 1.f); - else if (colorName == "white") - return osgVector4 (1.f, 1.f, 1.f, 1.f); - else - return osgVector4 (0.f, 0.f, 0.f, 1.f); - } - - osgVector4 GraphicalInterface::getColor (const double* colorCorba) - { - return osgVector4 (colorCorba[0], colorCorba[1], colorCorba[2], - colorCorba[3]); - } - - VisibilityMode GraphicalInterface::getVisibility - (const std::string& visibilityName) - { - if (visibilityName == "OFF") - return VISIBILITY_OFF; - else if (visibilityName == "ALWAYS_ON_TOP") - return ALWAYS_ON_TOP; - else if (visibilityName == "ON") - return VISIBILITY_ON; - else { - std::cout << "Visibility mode not known, visibility mode can be" - " \"ON\",\"OFF\" or \"ALWAYS_ON_TOP\"." << std::endl; - std::cout << "Visibility mode set to default = \"ON\"." << std::endl; - return VISIBILITY_ON; - } - } - - WireFrameMode GraphicalInterface::getWire (const std::string& wireName) - { - if (wireName == "WIREFRAME") - return WIREFRAME; - else if (wireName == "FILL_AND_WIREFRAME") - return FILL_AND_WIREFRAME; - else if (wireName == "FILL") - return FILL; - else { - std::cout << "Wire mode not known, wire mode can be \"FILL\"," - "\"WIREFRAME\" or \"FILL_AND_WIREFRAME\"." << std::endl; - std::cout << "Wire mode set to default = \"FILL\"." << std::endl; - return FILL; - } - } - - LightingMode GraphicalInterface::getLight (const std::string& lightName) - { - if (lightName == "OFF") - return LIGHT_INFLUENCE_OFF; - else if (lightName == "ON") - return LIGHT_INFLUENCE_ON; - else { - std::cout << "Lighting mode not known, lighting mode can be " - "\"ON\" or \"OFF\"." << std::endl; - std::cout << "Lighting mode set to default = \"ON\"." << std::endl; - return LIGHT_INFLUENCE_ON; - } - } - - std::string GraphicalInterface::parentName (const std::string& name) - { - std::string Name (name); - std::string::iterator parentNameIt; - for (std::string::iterator i = Name.end (); (*i) != char ('/') && - i != Name.begin (); i--) { - parentNameIt = i; - } - parentNameIt--; - - std::string parentName; - for (std::string::iterator i = Name.begin (); i != parentNameIt; i++) { - parentName.push_back (*i); - } - - return parentName; - } - - void GraphicalInterface::initParent (const std::string& nodeName, - NodePtr_t node) - { - GroupNodePtr_t groupNode = groupNodes_ - [GraphicalInterface::parentName (nodeName)]; - if (groupNode) { - groupNode->addChild (node); - } - } - - void GraphicalInterface::addNode (const std::string& nodeName, - NodePtr_t node) - { - nodes_[nodeName] = node; - } - - void GraphicalInterface::addGroup (const std::string& groupName, - GroupNodePtr_t group) - { - groupNodes_[groupName] = group; - nodes_[groupName] = group; - } - - void GraphicalInterface::threadRefreshing (WindowManagerPtr_t window) - { - while (!window->done ()) - { - mtx_.lock (); - window->frame (); - mtx_.unlock (); - boost::this_thread::sleep (boost::posix_time::milliseconds (rate_)); - } - } - - osgQuat GraphicalInterface::corbaConfToOsgQuat - (const double* configurationCorba) - { - // configurationCorba = trans (x, y, z), quat (w, x, y, z) - // osgQuat = quat (x, y, z, w) - return osgQuat (configurationCorba[4], configurationCorba[5], - configurationCorba[6], configurationCorba[3]); - } - - osgVector3 GraphicalInterface::corbaConfToOsgVec3 - (const double* configurationCorba) - { - return osgVector3 (configurationCorba[0], configurationCorba[1], - configurationCorba[2]); - } - - - //Public functions - bool GraphicalInterface::setRate (CORBA::Long rate) throw (Error) { try { - if (rate <= 0) { - std::cout << "You should specify a positive rate" << std::endl; - return false; - } - else { - rate_ = rate; - return true; - } + return windowsManager_->setRate (rate); } catch (const std::exception& exc) { throw Error (exc.what ()); } @@ -177,352 +31,217 @@ namespace graphics { throw (Error) { try { - std::string windowName (windowNameCorba); - WindowManagerPtr_t newWindow = WindowManager::create (); - WindowID windowId = windowManagers_.size (); - windowManagers_.push_back (newWindow); - boost::thread refreshThread (boost::bind - (&GraphicalInterface::threadRefreshing, - this, newWindow)); - return windowId; + return windowsManager_->createWindow (windowNameCorba); } catch (const std::exception& exc) { throw Error (exc.what ()); } } - void GraphicalInterface::refresh () throw (Error) + GraphicalInterface::WindowID GraphicalInterface::getWindowID (const char* windowNameCorba) + throw (Error) { try { - mtx_.lock (); - //refresh scene with the new configuration - for (std::list<NodeConfiguration>::iterator it = - newNodeConfigurations_.begin (); - it != newNodeConfigurations_.end (); it++) { - (*it).node->applyConfiguration ( (*it).position, (*it).quat); - } - for (WindowManagers_t::iterator it = windowManagers_.begin (); - it!=windowManagers_.end (); ++it) - (*it)->frame (); - mtx_.unlock (); - newNodeConfigurations_.clear (); + return windowsManager_->getWindowID (windowNameCorba); } catch (const std::exception& exc) { throw Error (exc.what ()); } } - void GraphicalInterface::createScene (const char* sceneNameCorba) - throw (Error) + void GraphicalInterface::refresh () throw (Error) { try { - std::string sceneName (sceneNameCorba); - if (nodes_.find (sceneName) != nodes_.end ()) { - std::ostringstream oss; - oss << "A scene with name, \"" << sceneName << "\" already exists."; - throw std::runtime_error (oss.str ()); - } - else { - GroupNodePtr_t mainNode = GroupNode::create (sceneName); - addGroup (sceneName, mainNode); - } + return windowsManager_->refresh (); } catch (const std::exception& exc) { throw Error (exc.what ()); } } - void GraphicalInterface::createSceneWithFloor - (const char* sceneNameCorba) throw (Error) - + void GraphicalInterface::createScene (const char* sceneNameCorba) + throw (Error) { try { - std::string sceneName (sceneNameCorba); - if (nodes_.find (sceneName) != nodes_.end ()) { - std::ostringstream oss; - oss << "A scene with name, \"" << sceneName << "\" already exists."; - throw std::runtime_error (oss.str ()); - } - else { - GroupNodePtr_t mainNode = GroupNode::create (sceneName); - addGroup (sceneName, mainNode); - std::string floorName = sceneName + "/floor"; - LeafNodeGroundPtr_t floor = LeafNodeGround::create (floorName); - addNode (floorName, floor); - mainNode->addChild (floor); - } + return windowsManager_->createScene (sceneNameCorba); } catch (const std::exception& exc) { throw Error (exc.what ()); } } + void GraphicalInterface::createSceneWithFloor (const char* sceneNameCorba) + throw (Error) + { + try { + return windowsManager_->createSceneWithFloor (sceneNameCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + bool GraphicalInterface::addSceneToWindow (const char* sceneNameCorba, - WindowID windowId) - throw (Error) + WindowID windowId) throw (Error) { - try { - std::string sceneName (sceneNameCorba); - if ((windowId >= 0 || windowId < windowManagers_.size ()) && - groupNodes_.find (sceneName) != groupNodes_.end () ) { - windowManagers_[windowId]->addNode (groupNodes_[sceneName]); - return true; - } - else { - std::cout << "Window ID \"" << windowId - << "\" and/or scene name \"" << sceneName - << "\" doesn't exist." << std::endl; - return false; - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addSceneToWindow (sceneNameCorba, windowId); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addBox (const char* boxNameCorba, const float boxSize1, const float boxSize2, const float boxSize3, - const double* colorCorba) throw (Error) + const value_type* colorCorba) throw (Error) { - try { - std::string boxName (boxNameCorba); - if (nodes_.find (boxName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << boxName - << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeBoxPtr_t box = LeafNodeBox::create - (boxName, osgVector3 (boxSize1, boxSize2, boxSize3), - getColor (colorCorba)); - GraphicalInterface::initParent (boxName, box); - addNode (boxName, box); - return true; - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addBox (boxNameCorba, boxSize1, boxSize2, boxSize3, + colorCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addCapsule (const char* capsuleNameCorba, - const float radius, - const float height, - const double* colorCorba) - throw (Error) + const float radius, + const float height, + const value_type* colorCorba) throw (Error) { - try { - const std::string capsuleName (capsuleNameCorba); - if (nodes_.find (capsuleName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" - << capsuleName << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeCapsulePtr_t capsule = LeafNodeCapsule::create - (capsuleName, radius, height, getColor (colorCorba)); - GraphicalInterface::initParent (capsuleName, capsule); - addNode (capsuleName, capsule); - return true; - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addCapsule (capsuleNameCorba, radius, height, + colorCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addMesh (const char* meshNameCorba, const char* meshPathCorba) throw (Error) { - try { - std::string meshName (meshNameCorba); - std::string meshPath (meshPathCorba); - if (nodes_.find (meshName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << meshName - << "\" already exist." << std::endl; - return false; - } - else { - try { - LeafNodeColladaPtr_t mesh = LeafNodeCollada::create - (meshName, meshPath); - GraphicalInterface::initParent (meshName, mesh); - addNode (meshName, mesh); - return true; - } catch (const std::exception& exc) { - std::cout << "Mesh \"" << meshPath << "\" not found." << std::endl; - return false; - } - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addMesh (meshNameCorba, meshPathCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addCone (const char* coneNameCorba, const float radius, const float height, - const double*) throw (Error) + const value_type* colorCorba) throw (Error) { - try { - std::string coneName (coneNameCorba); - if (nodes_.find (coneName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << coneName - << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeConePtr_t cone = LeafNodeCone::create - (coneName, radius, height); - GraphicalInterface::initParent (coneName, cone); - addNode (coneName, cone); - return true; - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addCone (coneNameCorba, radius, height, + colorCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addCylinder (const char* cylinderNameCorba, const float radius, const float height, - const double* colorCorba) - throw (Error) + const value_type* colorCorba) + throw (Error) { - try { - std::string cylinderName (cylinderNameCorba); - if (nodes_.find (cylinderName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << cylinderName - << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeCylinderPtr_t cylinder = LeafNodeCylinder::create - (cylinderName, radius, height, getColor (colorCorba)); - GraphicalInterface::initParent (cylinderName, cylinder); - addNode (cylinderName, cylinder); - return true; - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addCylinder (cylinderNameCorba, radius, height, + colorCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addSphere (const char* sphereNameCorba, const float radius, - const double* colorCorba) - throw (Error) + const value_type* colorCorba) + throw (Error) { - try { - std::string sphereName (sphereNameCorba); - if (nodes_.find (sphereName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << sphereName - << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeSpherePtr_t sphere = LeafNodeSphere::create - (sphereName, radius, getColor (colorCorba)); - GraphicalInterface::initParent (sphereName, sphere); - addNode (sphereName, sphere); - return true; - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addSphere (sphereNameCorba, radius, colorCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addLine (const char* lineNameCorba, - const double* posCorba1, - const double* posCorba2, - const double* colorCorba) throw (Error) + const value_type* posCorba1, + const value_type* posCorba2, + const value_type* colorCorba) throw (Error) { - try { - std::string lineName (lineNameCorba); - if (nodes_.find (lineName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << lineName - << "\" already exist." << std::endl; - return false; - } - else { - osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]); - osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]); - LeafNodeLinePtr_t line = LeafNodeLine::create - (lineName, pos1, pos2, getColor (colorCorba)); - GraphicalInterface::initParent (lineName, line); - addNode (lineName, line); - return true; - } - } catch (const std::exception& exc) { - throw Error (exc.what ()); - } + try { + return windowsManager_->addLine ( lineNameCorba, posCorba1, posCorba2, colorCorba) ; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } } bool GraphicalInterface::addTriangleFace (const char* faceNameCorba, - const double* posCorba1, - const double* posCorba2, - const double* posCorba3, - const double* colorCorba) - throw (Error) + const value_type* posCorba1, + const value_type* posCorba2, + const value_type* posCorba3, + const value_type* colorCorba) throw (Error) { try { - std::string faceName (faceNameCorba); - if (nodes_.find (faceName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << faceName - << "\" already exist." << std::endl; - return false; - } - else { - osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]); - osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]); - osgVector3 pos3 (posCorba3[0], posCorba3[1], posCorba3[2]); - LeafNodeFacePtr_t face = LeafNodeFace::create - (faceName, pos1, pos2, pos3, getColor (colorCorba)); - GraphicalInterface::initParent (faceName, face); - addNode (faceName, face); - return true; - } + return windowsManager_->addTriangleFace ( faceNameCorba, posCorba1, posCorba2, posCorba3, colorCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } bool GraphicalInterface::addSquareFace (const char* faceNameCorba, - const double* posCorba1, - const double* posCorba2, - const double* posCorba3, - const double* posCorba4, - const double* colorCorba) - throw (Error) + const value_type* posCorba1, + const value_type* posCorba2, + const value_type* posCorba3, + const value_type* posCorba4, + const value_type* colorCorba) throw (Error) { try { - std::string faceName (faceNameCorba); - if (nodes_.find (faceName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << faceName - << "\" already exist." << std::endl; - return false; - } - else { - osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]); - osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]); - osgVector3 pos3 (posCorba3[0], posCorba3[1], posCorba3[2]); - osgVector3 pos4 (posCorba4[0], posCorba4[1], posCorba4[2]); - LeafNodeFacePtr_t face = LeafNodeFace::create - (faceName, pos1, pos2, pos3, pos3, getColor (colorCorba)); - GraphicalInterface::initParent (faceName, face); - addNode (faceName, face); - return true; - } + return windowsManager_->addSquareFace ( faceNameCorba, posCorba1, posCorba2, posCorba3, posCorba4, colorCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } + bool GraphicalInterface::addXYZaxis(const char* nodeNameCorba, const value_type* colorCorba, float radius, float sizeAxis) + throw (Error) + { + try { + return windowsManager_->addXYZaxis (nodeNameCorba,colorCorba,radius,sizeAxis); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + /** initialise the roadmap (graphical roadmap)*/ + bool GraphicalInterface::createRoadmap(const char* nameCorba,const value_type* colorNodeCorba, float radius, float sizeAxis, const value_type* colorEdgeCorba) throw(Error){ + try { + return windowsManager_->createRoadmap (nameCorba,colorNodeCorba,radius,sizeAxis,colorEdgeCorba); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + + bool GraphicalInterface::addEdgeToRoadmap(const char* nameRoadmap, const value_type* posFrom, const value_type* posTo) throw(Error){ + try { + return windowsManager_->addEdgeToRoadmap (nameRoadmap,posFrom,posTo); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addNodeToRoadmap(const char* nameRoadmap, const value_type* configuration) throw(Error){ + try { + return windowsManager_->addNodeToRoadmap (nameRoadmap,configuration); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + + void GraphicalInterface::getNodeList () throw (Error) { - try { - std::cout << "List of Nodes :" << std::endl; - for (std::map<std::string, NodePtr_t>::iterator it=nodes_.begin (); - it!=nodes_.end (); ++it) - std::cout << " " << it->first << std::endl; - std::cout << "List of GroupNodes :" << std::endl; - for (std::map<std::string, GroupNodePtr_t>::iterator it= - groupNodes_.begin (); it!=groupNodes_.end (); ++it) - std::cout << " " << it->first << std::endl; + try { + windowsManager_->getNodeList (); } catch (const std::exception& exc) { throw Error (exc.what ()); } @@ -531,11 +250,7 @@ namespace graphics { void GraphicalInterface::getWindowList () throw (Error) { try { - std::cout << "List of Windows :" << std::endl; - size_t rank = 0; - for (WindowManagers_t::iterator it = windowManagers_.begin (); - it!=windowManagers_.end (); ++it) - std::cout << rank << " - " << (*it)->getViewerClone ()->getSlave (0)._camera->getGraphicsContext ()->getTraits ()->windowName << std::endl; + windowsManager_->getWindowList (); } catch (const std::exception& exc) { throw Error (exc.what ()); } @@ -544,18 +259,7 @@ namespace graphics { bool GraphicalInterface::createGroup (const char* groupNameCorba) throw (Error) { try { - const std::string groupName (groupNameCorba); - if (nodes_.find (groupName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << groupName - << "\" already exist." << std::endl; - return false; - } - else { - GroupNodePtr_t groupNode = GroupNode::create (groupName); - GraphicalInterface::initParent (groupName, groupNode); - addGroup (groupName, groupNode); - return true; - } + return windowsManager_->createGroup ( groupNameCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } @@ -563,60 +267,20 @@ namespace graphics { bool GraphicalInterface::addURDF (const char* urdfNameCorba, const char* urdfPathCorba, - const char* urdfPackagePathCorba) - throw (Error) + const char* urdfPackagePathCorba) throw (Error) { try { - const std::string urdfName (urdfNameCorba); - const std::string urdfPath (urdfPathCorba); - const std::string urdfPackagePath (urdfPackagePathCorba); - if (nodes_.find (urdfName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << urdfName - << "\" already exist." << std::endl; - return false; - } - else { - GroupNodePtr_t urdf = urdfParser::parse - (urdfName, urdfPath, urdfPackagePath); - NodePtr_t link; - for (int i=0; i< urdf->getNumOfChildren (); i++) { - link = urdf->getChild (i); - nodes_[link->getID ()] = link; - } - GraphicalInterface::initParent (urdfName, urdf); - addGroup (urdfName, urdf); - return true; - } + return windowsManager_->addURDF ( urdfNameCorba, urdfPathCorba, urdfPackagePathCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } - bool GraphicalInterface::addUrdfCollision - (const char* urdfNameCorba, const char* urdfPathCorba, + bool GraphicalInterface::addUrdfCollision (const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba) throw (Error) { try { - const std::string urdfName (urdfNameCorba); - const std::string urdfPath (urdfPathCorba); - const std::string urdfPackagePath (urdfPackagePathCorba); - if (nodes_.find (urdfName) != nodes_.end ()) { - std::cout << "You need to chose an other name, \"" << urdfName - << "\" already exist." << std::endl; - return false; - } - else { - GroupNodePtr_t urdf = urdfParser::parse - (urdfName, urdfPath, urdfPackagePath, "collision"); - NodePtr_t link; - for (int i=0; i< urdf->getNumOfChildren (); i++) { - link = urdf->getChild (i); - nodes_[link->getID ()] = link; - } - GraphicalInterface::initParent (urdfName, urdf); - addGroup (urdfName, urdf); - return true; - } + return windowsManager_->addUrdfCollision ( urdfNameCorba, urdfPathCorba, urdfPackagePathCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } @@ -625,88 +289,39 @@ namespace graphics { void GraphicalInterface::addUrdfObjects (const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba, - bool visual) - throw (Error) + bool visual) throw (Error) { try { - const std::string urdfName (urdfNameCorba); - const std::string urdfPath (urdfPathCorba); - const std::string urdfPackagePath (urdfPackagePathCorba); - if (urdfName == "") { - throw std::runtime_error ("Parameter nodeName cannot be empty in " - "idl request addUrdfObjects."); - } - if (nodes_.find (urdfName) != nodes_.end ()) { - std::ostringstream oss; - oss << "You need to chose an other name, \"" << urdfName - << "\" already exist."; - throw std::runtime_error (oss.str ()); - } - GroupNodePtr_t urdf = urdfParser::parse - (urdfName, urdfPath, urdfPackagePath, - visual ? "visual" : "collision", "object"); - NodePtr_t link; - for (int i=0; i< urdf->getNumOfChildren (); i++) { - link = urdf->getChild (i); - nodes_[link->getID ()] = link; - } - GraphicalInterface::initParent (urdfName, urdf); - addGroup (urdfName, urdf); + return windowsManager_->addUrdfObjects ( urdfNameCorba, urdfPathCorba, urdfPackagePathCorba, visual) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } bool GraphicalInterface::addToGroup (const char* nodeNameCorba, - const char* groupNameCorba) - throw (Error) + const char* groupNameCorba) throw (Error) { try { - const std::string nodeName (nodeNameCorba); - const std::string groupName (groupNameCorba); - if (nodes_.find (nodeName) == nodes_.end () || - groupNodes_.find (groupName) == groupNodes_.end ()) { - std::cout << "Node name \"" << nodeName << "\" and/or groupNode \"" - << groupName << "\" doesn't exist." << std::endl; - return false; - } - else { - groupNodes_[groupName]->addChild (nodes_[nodeName]); - return true; - } + return windowsManager_->addToGroup ( nodeNameCorba, groupNameCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } - bool GraphicalInterface::applyConfiguration - (const char* nodeNameCorba, const double* configurationCorba) - throw (Error) + bool GraphicalInterface::removeFromGroup (const char* nodeNameCorba, + const char* groupNameCorba) throw (Error) + { + try { + return windowsManager_->removeFromGroup ( nodeNameCorba, groupNameCorba) ; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::applyConfiguration (const char* nodeNameCorba, const value_type* configurationCorba) throw (Error) { try { - const std::string nodeName (nodeNameCorba); - if (nodes_.find (nodeName) == nodes_.end ()) { - //no node named nodeName - std::cout << "No Node named \"" << nodeName << "\"" << std::endl; - return false; - } - else { - NodeConfiguration newNodeConfiguration; - newNodeConfiguration.node = nodes_[nodeName]; - try { - newNodeConfiguration.position = - GraphicalInterface::corbaConfToOsgVec3 (configurationCorba); - newNodeConfiguration.quat = - GraphicalInterface::corbaConfToOsgQuat (configurationCorba); - } catch (const std::exception& exc) { - std::cout << "Error when converting configuration, configuration " - "should be DOUBLE[7] = [transX, transY, transZ, quatW, quatX," - "quatY, quatZ]" <<std::endl; - return false; - } - newNodeConfigurations_.push_back (newNodeConfiguration); - return true; - } + return windowsManager_->applyConfiguration ( nodeNameCorba, configurationCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } @@ -716,147 +331,75 @@ namespace graphics { float size) throw (Error) { try { - const std::string nodeName (nodeNameCorba); - if (nodes_.find (nodeName) == nodes_.end ()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." - << std::endl; - return false; - } - nodes_[nodeName]->addLandmark (size); - return true; + return windowsManager_->addLandmark ( nodeNameCorba, size) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } - bool GraphicalInterface::deleteLandmark (const char* nodeNameCorba) - throw (Error) + bool GraphicalInterface::deleteLandmark (const char* nodeNameCorba) throw (Error) { try { - const std::string nodeName (nodeNameCorba); - if (nodes_.find (nodeName) == nodes_.end ()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." - << std::endl; - return false; - } - nodes_[nodeName]->deleteLandmark (); - return true; + return windowsManager_->deleteLandmark ( nodeNameCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } bool GraphicalInterface::setVisibility (const char* nodeNameCorba, - const char* visibilityModeCorba) - throw (Error) + const char* visibilityModeCorba) throw (Error) { try { - const std::string nodeName (nodeNameCorba); - const std::string visibilityMode (visibilityModeCorba); - VisibilityMode visibility = getVisibility (visibilityMode); - if (nodes_.find (nodeName) == nodes_.end ()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." - << std::endl; - return false; - } - nodes_[nodeName]->setVisibilityMode (visibility); - return true; + return windowsManager_->setVisibility ( nodeNameCorba, visibilityModeCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } bool GraphicalInterface::setWireFrameMode (const char* nodeNameCorba, - const char* wireFrameModeCorba) - throw (Error) + const char* wireFrameModeCorba) throw (Error) { try { - const std::string nodeName (nodeNameCorba); - const std::string wireFrameMode (wireFrameModeCorba); - WireFrameMode wire = getWire (wireFrameMode); - if (nodes_.find (nodeName) == nodes_.end ()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." - << std::endl; - return false; - } - nodes_[nodeName]->setWireFrameMode (wire); - return true; + return windowsManager_->setWireFrameMode ( nodeNameCorba, wireFrameModeCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } bool GraphicalInterface::setLightingMode (const char* nodeNameCorba, - const char* lightingModeCorba) - throw (Error) + const char* lightingModeCorba) throw (Error) { try { - const std::string nodeName (nodeNameCorba); - const std::string lightingMode (lightingModeCorba); - LightingMode light = getLight (lightingMode); - if (nodes_.find (nodeName) == nodes_.end ()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." - << std::endl; - return false; - } - nodes_[nodeName]->setLightingMode (light); - return true; + return windowsManager_->setLightingMode ( nodeNameCorba, lightingModeCorba) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } bool GraphicalInterface::startCapture (const WindowID windowId, const char* filename, - const char* extension) - throw (Error) + const char* extension) throw (Error) { try { - if (windowId >= 0 || windowId < windowManagers_.size ()) { - windowManagers_[windowId]->startCapture - (std::string (filename), std::string (extension)); - return true; - } - else { - std::cout << "Window ID " << windowId - << " doesn't exist." << std::endl; - return false; - } + return windowsManager_->startCapture ( windowId, filename, extension) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } - bool GraphicalInterface::stopCapture (const WindowID windowId) - throw (Error) + bool GraphicalInterface::stopCapture (const WindowID windowId) throw (Error) { try { - if (windowId >= 0 || windowId < windowManagers_.size ()) { - windowManagers_[windowId]->stopCapture (); - return true; - } - else { - std::cout << "Window ID " << windowId - << " doesn't exist." << std::endl; - return false; - } + return windowsManager_->stopCapture ( windowId) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } } - bool GraphicalInterface::writeNodeFile (const WindowID windowId, const char* filename) - throw (Error) + bool GraphicalInterface::writeNodeFile (const WindowID windowId, const char* filename) throw (Error) { try { - if (windowId >= 0 || windowId < windowManagers_.size ()) { - return windowManagers_[windowId]->writeNodeFile (std::string (filename)); - } - else { - std::cout << "Window ID " << windowId - << " doesn't exist." << std::endl; - return false; - } + return writeNodeFile ( windowId, filename) ; } catch (const std::exception& exc) { throw Error (exc.what ()); } diff --git a/src/graphical-interface.impl.hh b/src/graphical-interface.impl.hh index 628b1e007a96de871c609123a21562ed2c8b2794..5e47276247c1aa04d3821129448b309e2ff1fa5b 100644 --- a/src/graphical-interface.impl.hh +++ b/src/graphical-interface.impl.hh @@ -10,26 +10,8 @@ #define SCENEVIEWER_CORBASERVER_GRAPHICALINTERFACE_HH #include <omniORB4/CORBA.h> -#include <boost/thread.hpp> -#include <boost/thread/mutex.hpp> - -#include <gepetto/viewer/window-manager.h> -#include <gepetto/viewer/node.h> -#include <gepetto/viewer/group-node.h> -#include <gepetto/viewer/leaf-node-box.h> -#include <gepetto/viewer/leaf-node-capsule.h> -#include <gepetto/viewer/leaf-node-cone.h> -#include <gepetto/viewer/leaf-node-cylinder.h> -#include <gepetto/viewer/leaf-node-line.h> -#include <gepetto/viewer/leaf-node-face.h> -#include <gepetto/viewer/leaf-node-sphere.h> -#include <gepetto/viewer/macros.h> -#include <gepetto/viewer/config-osg.h> -#include <gepetto/viewer/leaf-node-ground.h> -#include <gepetto/viewer/leaf-node-collada.h> -#include <gepetto/viewer/urdf-parser.h> - -#include "server.hh" + +#include "gepetto/viewer/corba/server.hh" #include "graphical-interface.hh" namespace graphics { @@ -42,35 +24,15 @@ struct NodeConfiguration { osgQuat quat; }; +using graphics::WindowsManagerPtr_t; class GraphicalInterface : public virtual POA_gepetto::corbaserver::GraphicalInterface { private: + WindowsManagerPtr_t windowsManager_; typedef gepetto::Error Error; typedef CORBA::ULong WindowID; - typedef std::vector <WindowManagerPtr_t> WindowManagers_t; - WindowManagers_t windowManagers_; - std::map<std::string, NodePtr_t> nodes_; - std::map<std::string, GroupNodePtr_t> groupNodes_; - corbaServer::Server* server_; - boost::mutex mtx_; - int rate_; - std::list<NodeConfiguration> newNodeConfigurations_; - - static osgVector4 getColor(const std::string& colorName); - static osgVector4 getColor(const double* color); - static std::string parentName(const std::string& name); - static VisibilityMode getVisibility(const std::string& visibilityName); - static WireFrameMode getWire(const std::string& wireName); - static LightingMode getLight(const std::string& lightName); - void initParent(const std::string& nodeName, NodePtr_t node); - void addNode(const std::string& nodeName, NodePtr_t node); - void addGroup(const std::string& groupName, GroupNodePtr_t group); - void threadRefreshing(WindowManagerPtr_t window); - static osgQuat corbaConfToOsgQuat(const double* configurationCorba); - static osgVector3 corbaConfToOsgVec3(const double* configurationCorba); - -protected: + typedef graphics::WindowsManager::value_type value_type; public: /** @@ -85,28 +47,38 @@ public: virtual void refresh() throw (Error); virtual WindowID createWindow(const char* windowNameCorba) throw (Error); + virtual WindowID getWindowID (const char* windowNameCorba) throw (Error); virtual void createScene(const char* sceneNameCorba) throw (Error); virtual void createSceneWithFloor(const char* sceneNameCorba) throw (Error); virtual bool addSceneToWindow(const char* sceneNameCorba, const WindowID windowId) throw (Error); - virtual bool addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3, const double* color) throw (Error); + virtual bool addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3, const value_type* color) throw (Error); - virtual bool addCapsule(const char* capsuleName, float radius, float height, const double* color) throw (Error); + virtual bool addCapsule(const char* capsuleName, float radius, float height, const value_type* color) throw (Error); virtual bool addMesh(const char* meshNameCorba, const char* meshPathCorba) throw (Error); - virtual bool addCone(const char* coneName, float radius, float height, const double* color) throw (Error); + virtual bool addCone(const char* coneName, float radius, float height, const value_type* color) throw (Error); + + virtual bool addCylinder(const char* cylinderName, float radius, float height, const value_type* color) throw (Error); + + virtual bool addSphere(const char* sphereName, float radius, const value_type* color) throw (Error); + + virtual bool addLine(const char* lineName, const value_type* pos1, const value_type* pos2, const value_type* color) throw (Error); + + virtual bool addSquareFace(const char* faceName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* pos4, const value_type* color) throw (Error); + virtual bool addTriangleFace(const char* faceName, const value_type* pos1, const value_type* pos2, const value_type* pos3, const value_type* color) throw (Error); + + virtual bool addXYZaxis (const char* nodeNameCorba, const value_type* colorCorba, float radius, float sizeAxis) throw (Error); - virtual bool addCylinder(const char* cylinderName, float radius, float height, const double* color) throw (Error); + virtual bool createRoadmap(const char* nameCorba,const value_type* colorNodeCorba, float radius, float sizeAxis, const value_type* colorEdgeCorba) throw(Error); - virtual bool addSphere(const char* sphereName, float radius, const double* color) throw (Error); + virtual bool addEdgeToRoadmap(const char* nameRoadmap, const value_type* posFrom, const value_type* posTo) throw(Error); - virtual bool addLine(const char* lineName, const double* pos1, const double* pos2, const double* color) throw (Error); + virtual bool addNodeToRoadmap(const char* nameRoadmap, const value_type* configuration) throw(Error); - virtual bool addSquareFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* pos4, const double* color) throw (Error); - virtual bool addTriangleFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* color) throw (Error); virtual bool addURDF(const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba) throw (Error); @@ -123,8 +95,9 @@ public: virtual bool createGroup(const char* groupNameCorba) throw (Error); virtual bool addToGroup(const char* nodeNameCorba, const char* groupNameCorba) throw (Error); + virtual bool removeFromGroup (const char* nodeNameCorba,const char* groupNameCorba) throw (Error); - virtual bool applyConfiguration(const char* nodeNameCorba, const double* configuration) throw (Error); + virtual bool applyConfiguration(const char* nodeNameCorba, const value_type* configuration) throw (Error); virtual bool addLandmark(const char* nodeNameCorba, float size) throw (Error); virtual bool deleteLandmark(const char* nodeNameCorba) throw (Error); diff --git a/src/server-private.cc b/src/server-private.cc index e70e97d301f049000d32ae66cfc1f6fb8218f438..ea5db2c16c3474a97a17e749649c7910e4094561 100644 --- a/src/server-private.cc +++ b/src/server-private.cc @@ -13,7 +13,7 @@ #include "graphical-interface.impl.hh" #include "server-private.hh" -#include "fwd.hh" +#include "gepetto/viewer/corba/fwd.hh" namespace graphics { diff --git a/src/server-private.hh b/src/server-private.hh index 396ca6baffb1694260f611b15fb770dad1315570..6961fbe7f417d7ece7348ff1369641c9777a7dd9 100644 --- a/src/server-private.hh +++ b/src/server-private.hh @@ -12,7 +12,7 @@ # define SCENVIEWER_CORBASERVER_SERVER_PRIVATE_HH # include "graphical-interface.impl.hh" -# include "fwd.hh" +# include "gepetto/viewer/corba/fwd.hh" namespace graphics { diff --git a/src/server.cc b/src/server.cc index 783a83afb4b16a56a5938ab050025fdfdd1aedaf..06e1a74eea09426699816079d9127b5cc53672df 100644 --- a/src/server.cc +++ b/src/server.cc @@ -12,11 +12,10 @@ #include <pthread.h> #include <iostream> #include <stdexcept> -#include "server.hh" +#include "gepetto/viewer/corba/server.hh" #include "server-private.hh" - namespace graphics { namespace corbaServer @@ -42,7 +41,8 @@ namespace graphics //} // end of anonymous namespace. - Server::Server(int argc, const char *argv[], bool inMultiThread) + Server::Server(WindowsManagerPtr_t wm, int argc, const char *argv[], + bool inMultiThread) : windowsManager_ (wm) { private_ = new impl::Server; @@ -96,8 +96,12 @@ namespace graphics policyList.length(1); policyList[0] = PortableServer::ThreadPolicy::_duplicate(threadPolicy); - private_->poa_ = rootPoa->create_POA - ("child", PortableServer::POAManager::_nil(), policyList); + try { + private_->poa_ = rootPoa->create_POA + ("child", PortableServer::POAManager::_nil(), policyList); + } catch (PortableServer::POA::AdapterAlreadyExists& /*e*/) { + private_->poa_ = rootPoa->find_POA ("child", false); + } // Destroy policy object threadPolicy->destroy(); private_->createAndActivateServers(this); diff --git a/src/test-client-cpp.cc b/src/test-client-cpp.cc index 8690b2fff61d5521691269984891cb9ef71c6be3..4dfb52e4c154d0d94321b5ec06ea8b149c725791 100644 --- a/src/test-client-cpp.cc +++ b/src/test-client-cpp.cc @@ -29,12 +29,12 @@ int main(int, const char **) sleep(5); - //vector<double> tri01 (3); + //vector<float> tri01 (3); - double pos1[3]= {1.,0.,0.}; - double pos2[3] = {0.,1.,0.}; - double pos3[3]= {0.,1.,1.}; - double color[4] = {1.,1.,1.,1.}; + float pos1[3]= {1.,0.,0.}; + float pos2[3] = {0.,1.,0.}; + float pos3[3]= {0.,1.,1.}; + float color[4] = {1.,1.,1.,1.}; client.addTriangleFace("scene1/triangle", pos1, pos2, pos3, color); sleep(15); diff --git a/src/windows-manager.cpp b/src/windows-manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04c8b852b20a6f9bd7d90ce84c5614e14f13d02a --- /dev/null +++ b/src/windows-manager.cpp @@ -0,0 +1,896 @@ +// Copyright (c) 2015, Joseph Mirabel +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of gepetto-viewer. +// gepetto-viewer is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// gepetto-viewer is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// gepetto-viewer. If not, see <http://www.gnu.org/licenses/>. + +#include "gepetto/viewer/corba/windows-manager.h" + +#include <boost/thread.hpp> + +#include <gepetto/viewer/window-manager.h> +#include <gepetto/viewer/node.h> +#include <gepetto/viewer/group-node.h> +#include <gepetto/viewer/leaf-node-box.h> +#include <gepetto/viewer/leaf-node-capsule.h> +#include <gepetto/viewer/leaf-node-cone.h> +#include <gepetto/viewer/leaf-node-cylinder.h> +#include <gepetto/viewer/leaf-node-line.h> +#include <gepetto/viewer/leaf-node-face.h> +#include <gepetto/viewer/leaf-node-sphere.h> +#include <gepetto/viewer/leaf-node-xyzaxis.h> +#include <gepetto/viewer/roadmap-viewer.h> +#include <gepetto/viewer/macros.h> +#include <gepetto/viewer/config-osg.h> +#include <gepetto/viewer/leaf-node-ground.h> +#include <gepetto/viewer/leaf-node-collada.h> +#include <gepetto/viewer/urdf-parser.h> + +namespace graphics { + WindowsManager::WindowsManager () : + windowManagers_ (), nodes_ (), groupNodes_ (),roadmapNodes_(), + mtx_ (), rate_ (20), newNodeConfigurations_ () + { + } + + WindowsManager::WindowID WindowsManager::addWindow (std::string winName, + WindowManagerPtr_t newWindow) + { + WindowID windowId = windowManagers_.size (); + windowIDmap_ [winName] = windowId; + windowManagers_.push_back (newWindow); + return windowId; + } + + WindowsManagerPtr_t WindowsManager::create () + { + WindowsManagerPtr_t shPtr (new WindowsManager()); + return shPtr; + } + + osgVector4 WindowsManager::getColor (const std::string& colorName) + { + if (colorName == "blue") + return osgVector4 (0.f, 0.f, 1.f, 1.f); + else if (colorName == "green") + return osgVector4 (0.f, 1.f, 0.f, 1.f); + else if (colorName == "red") + return osgVector4 (1.f, 0.f, 0.f, 1.f); + else if (colorName == "white") + return osgVector4 (1.f, 1.f, 1.f, 1.f); + else + return osgVector4 (0.f, 0.f, 0.f, 1.f); + } + + osgVector4 WindowsManager::getColor (const value_type* colorCorba) + { + return osgVector4 (colorCorba[0], colorCorba[1], colorCorba[2], + colorCorba[3]); + } + + VisibilityMode WindowsManager::getVisibility (const std::string& vName) + { + if (vName == "OFF") + return VISIBILITY_OFF; + else if (vName == "ALWAYS_ON_TOP") + return ALWAYS_ON_TOP; + else if (vName == "ON") + return VISIBILITY_ON; + else { + std::cout << "Visibility mode not known, visibility mode can be" + " \"ON\",\"OFF\" or \"ALWAYS_ON_TOP\"." << std::endl; + std::cout << "Visibility mode set to default = \"ON\"." << std::endl; + return VISIBILITY_ON; + } + } + + WireFrameMode WindowsManager::getWire (const std::string& wireName) + { + if (wireName == "WIREFRAME") + return WIREFRAME; + else if (wireName == "FILL_AND_WIREFRAME") + return FILL_AND_WIREFRAME; + else if (wireName == "FILL") + return FILL; + else { + std::cout << "Wire mode not known, wire mode can be \"FILL\"," + "\"WIREFRAME\" or \"FILL_AND_WIREFRAME\"." << std::endl; + std::cout << "Wire mode set to default = \"FILL\"." << std::endl; + return FILL; + } + } + + LightingMode WindowsManager::getLight (const std::string& lightName) + { + if (lightName == "OFF") + return LIGHT_INFLUENCE_OFF; + else if (lightName == "ON") + return LIGHT_INFLUENCE_ON; + else { + std::cout << "Lighting mode not known, lighting mode can be " + "\"ON\" or \"OFF\"." << std::endl; + std::cout << "Lighting mode set to default = \"ON\"." << std::endl; + return LIGHT_INFLUENCE_ON; + } + } + + std::string WindowsManager::parentName (const std::string& name) + { + std::string Name (name); + std::string::iterator parentNameIt; + for (std::string::iterator i = Name.end (); (*i) != char ('/') && + i != Name.begin (); i--) { + parentNameIt = i; + } + parentNameIt--; + + std::string parentName; + for (std::string::iterator i = Name.begin (); i != parentNameIt; i++) { + parentName.push_back (*i); + } + + return parentName; + } + + + void WindowsManager::initParent (const std::string& nodeName, + NodePtr_t node) + { + GroupNodePtr_t groupNode = groupNodes_ + [WindowsManager::parentName (nodeName)]; + if (groupNode) { + groupNode->addChild (node); + } + } + + void WindowsManager::addNode (const std::string& nodeName, NodePtr_t node) + { + nodes_[nodeName] = node; + } + + void WindowsManager::addGroup (const std::string& groupName, + GroupNodePtr_t group) + { + groupNodes_[groupName] = group; + nodes_[groupName] = group; + } + + void WindowsManager::threadRefreshing (WindowManagerPtr_t window) + { + while (!window->done ()) + { + mtx_.lock (); + window->frame (); + mtx_.unlock (); + boost::this_thread::sleep (boost::posix_time::milliseconds (rate_)); + } + } + + + + osgQuat WindowsManager::corbaConfToOsgQuat (const value_type* configCorba) + { + // configurationCorba = trans (x, y, z), quat (w, x, y, z) + // osgQuat = quat (x, y, z, w) + return osgQuat (configCorba[4], configCorba[5], + configCorba[6], configCorba[3]); + } + + osgVector3 WindowsManager::corbaConfToOsgVec3 (const value_type* configCorba) + { + return osgVector3 (configCorba[0], configCorba[1], configCorba[2]); + } + + + //Public functions + + bool WindowsManager::setRate (const int& rate) + { + if (rate <= 0) { + std::cout << "You should specify a positive rate" << std::endl; + return false; + } + else { + rate_ = rate; + return true; + } + } + + WindowsManager::WindowID WindowsManager::createWindow (const char* winName) + { + std::string wn (winName); + WindowManagerPtr_t newWindow = WindowManager::create (); + WindowID windowId = addWindow (wn, newWindow); + boost::thread refreshThread (boost::bind + (&WindowsManager::threadRefreshing, + this, newWindow)); + return windowId; + } + + WindowsManager::WindowID WindowsManager::getWindowID (const char* windowNameCorba) + { + std::string windowName (windowNameCorba); + WindowIDMap_t::iterator it = windowIDmap_.find (windowName); + if (it == windowIDmap_.end ()) + throw std::invalid_argument ("There is no windows with that name"); + return it->second; + } + + void WindowsManager::refresh () + { + mtx_.lock (); + //refresh scene with the new configuration + for (std::list<NodeConfiguration>::iterator it = + newNodeConfigurations_.begin (); + it != newNodeConfigurations_.end (); it++) { + (*it).node->applyConfiguration ( (*it).position, (*it).quat); + } + newNodeConfigurations_.clear (); + mtx_.unlock (); + } + + void WindowsManager::createScene (const char* sceneNameCorba) + { + std::string sceneName (sceneNameCorba); + if (nodes_.find (sceneName) != nodes_.end ()) { + std::ostringstream oss; + oss << "A scene with name, \"" << sceneName << "\" already exists."; + throw std::runtime_error (oss.str ()); + } + else { + GroupNodePtr_t mainNode = GroupNode::create (sceneName); + addGroup (sceneName, mainNode); + } + } + + void WindowsManager::createSceneWithFloor (const char* sceneNameCorba) + { + std::string sceneName (sceneNameCorba); + if (nodes_.find (sceneName) != nodes_.end ()) { + std::ostringstream oss; + oss << "A scene with name, \"" << sceneName << "\" already exists."; + throw std::runtime_error (oss.str ()); + } + else { + GroupNodePtr_t mainNode = GroupNode::create (sceneName); + addGroup (sceneName, mainNode); + std::string floorName = sceneName + "/floor"; + LeafNodeGroundPtr_t floor = LeafNodeGround::create (floorName); + addNode (floorName, floor); + mainNode->addChild (floor); + } + } + + bool WindowsManager::addSceneToWindow (const char* sceneNameCorba, + WindowID windowId) + { + std::string sceneName (sceneNameCorba); + if ((windowId >= 0 || windowId < windowManagers_.size ()) && + groupNodes_.find (sceneName) != groupNodes_.end () ) { + windowManagers_[windowId]->addNode (groupNodes_[sceneName]); + return true; + } + else { + std::cout << "Window ID \"" << windowId + << "\" and/or scene name \"" << sceneName + << "\" doesn't exist." << std::endl; + return false; + } + } + + bool WindowsManager::addBox (const char* boxNameCorba, + const float boxSize1, + const float boxSize2, + const float boxSize3, + const value_type* colorCorba) + { + std::string boxName (boxNameCorba); + if (nodes_.find (boxName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << boxName + << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeBoxPtr_t box = LeafNodeBox::create + (boxName, osgVector3 (boxSize1, boxSize2, boxSize3), + getColor (colorCorba)); + WindowsManager::initParent (boxName, box); + addNode (boxName, box); + return true; + } + } + + bool WindowsManager::addCapsule (const char* capsuleNameCorba, + const float radius, + const float height, + const value_type* colorCorba) + { + const std::string capsuleName (capsuleNameCorba); + if (nodes_.find (capsuleName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" + << capsuleName << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeCapsulePtr_t capsule = LeafNodeCapsule::create + (capsuleName, radius, height, getColor (colorCorba)); + WindowsManager::initParent (capsuleName, capsule); + addNode (capsuleName, capsule); + return true; + } + } + + bool WindowsManager::addMesh (const char* meshNameCorba, + const char* meshPathCorba) + { + std::string meshName (meshNameCorba); + std::string meshPath (meshPathCorba); + if (nodes_.find (meshName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << meshName + << "\" already exist." << std::endl; + return false; + } + else { + try { + LeafNodeColladaPtr_t mesh = LeafNodeCollada::create + (meshName, meshPath); + WindowsManager::initParent (meshName, mesh); + addNode (meshName, mesh); + return true; + } catch (const std::exception& exc) { + std::cout << "Mesh \"" << meshPath << "\" not found." << std::endl; + return false; + } + } + } + + bool WindowsManager::addCone (const char* coneNameCorba, + const float radius, const float height, + const value_type*) + { + std::string coneName (coneNameCorba); + if (nodes_.find (coneName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << coneName + << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeConePtr_t cone = LeafNodeCone::create + (coneName, radius, height); + WindowsManager::initParent (coneName, cone); + addNode (coneName, cone); + return true; + } + } + + bool WindowsManager::addCylinder (const char* cylinderNameCorba, + const float radius, + const float height, + const value_type* colorCorba) + { + std::string cylinderName (cylinderNameCorba); + if (nodes_.find (cylinderName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << cylinderName + << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeCylinderPtr_t cylinder = LeafNodeCylinder::create + (cylinderName, radius, height, getColor (colorCorba)); + WindowsManager::initParent (cylinderName, cylinder); + addNode (cylinderName, cylinder); + return true; + } + } + + bool WindowsManager::addSphere (const char* sphereNameCorba, + const float radius, + const value_type* colorCorba) + { + std::string sphereName (sphereNameCorba); + if (nodes_.find (sphereName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << sphereName + << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeSpherePtr_t sphere = LeafNodeSphere::create + (sphereName, radius, getColor (colorCorba)); + WindowsManager::initParent (sphereName, sphere); + addNode (sphereName, sphere); + return true; + } + } + + bool WindowsManager::addLine (const char* lineNameCorba, + const value_type* posCorba1, + const value_type* posCorba2, + const value_type* colorCorba) + { + std::string lineName (lineNameCorba); + if (nodes_.find (lineName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << lineName + << "\" already exist." << std::endl; + return false; + } + else { + osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]); + osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]); + LeafNodeLinePtr_t line = LeafNodeLine::create + (lineName, pos1, pos2, getColor (colorCorba)); + WindowsManager::initParent (lineName, line); + addNode (lineName, line); + return true; + } + } + + bool WindowsManager::addTriangleFace (const char* faceNameCorba, + const value_type* posCorba1, + const value_type* posCorba2, + const value_type* posCorba3, + const value_type* colorCorba) + { + std::string faceName (faceNameCorba); + if (nodes_.find (faceName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << faceName + << "\" already exist." << std::endl; + return false; + } + else { + osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]); + osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]); + osgVector3 pos3 (posCorba3[0], posCorba3[1], posCorba3[2]); + LeafNodeFacePtr_t face = LeafNodeFace::create + (faceName, pos1, pos2, pos3, getColor (colorCorba)); + WindowsManager::initParent (faceName, face); + addNode (faceName, face); + return true; + } + } + + bool WindowsManager::addSquareFace (const char* faceNameCorba, + const value_type* posCorba1, + const value_type* posCorba2, + const value_type* posCorba3, + const value_type* posCorba4, + const value_type* colorCorba) + { + std::string faceName (faceNameCorba); + if (nodes_.find (faceName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << faceName + << "\" already exist." << std::endl; + return false; + } + else { + osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]); + osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]); + osgVector3 pos3 (posCorba3[0], posCorba3[1], posCorba3[2]); + osgVector3 pos4 (posCorba4[0], posCorba4[1], posCorba4[2]); + LeafNodeFacePtr_t face = LeafNodeFace::create + (faceName, pos1, pos2, pos3, pos3, getColor (colorCorba)); + WindowsManager::initParent (faceName, face); + addNode (faceName, face); + return true; + } + } + + bool WindowsManager::addXYZaxis (const char* nodeNameCorba,const value_type* colorCorba, float radius, float sizeAxis) + { + + std::string nodeName (nodeNameCorba); + if (nodes_.find (nodeName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << nodeName + << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeXYZAxisPtr_t axis = LeafNodeXYZAxis::create + (nodeName,getColor(colorCorba),radius,sizeAxis); + WindowsManager::initParent (nodeName, axis); + addNode (nodeName, axis); + return true; + } + } + + bool WindowsManager::createRoadmap(const char* nameCorba,const value_type* colorNodeCorba, float radius, float sizeAxis, const value_type* colorEdgeCorba){ + const std::string roadmapName (nameCorba); + if (nodes_.find (roadmapName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << roadmapName + << "\" already exist." << std::endl; + return false; + } + else { + RoadmapViewerPtr_t rm = RoadmapViewer::create(roadmapName,getColor(colorNodeCorba),radius,sizeAxis,getColor(colorEdgeCorba)); + WindowsManager::initParent (roadmapName, rm); + addNode (roadmapName, rm); + roadmapNodes_[roadmapName]=rm; + return true; + } + } + + bool WindowsManager::addEdgeToRoadmap(const char* nameRoadmapCorba, const value_type* posFromCorba, const value_type* posToCorba){ + const std::string nameRoadmap (nameRoadmapCorba); + if (roadmapNodes_.find (nameRoadmap) == roadmapNodes_.end ()) { + //no node named nodeName + std::cout << "No roadmap named \"" << nameRoadmap << "\"" << std::endl; + return false; + } + else { + RoadmapViewerPtr_t rm_ptr = roadmapNodes_[nameRoadmap]; + osgVector3 posFrom = osgVector3(posFromCorba[0], posFromCorba[1],posFromCorba[2]); + osgVector3 posTo = osgVector3(posToCorba[0], posToCorba[1],posToCorba[2]); + // mtx_.lock(); mtx is now locked only when required in addEdge + rm_ptr->addEdge(posFrom,posTo,mtx_); + // mtx_.unlock(); + return true; + } + } + + bool WindowsManager::addNodeToRoadmap(const char* nameRoadmapCorba, const value_type* configuration){ + const std::string nameRoadmap (nameRoadmapCorba); + if (roadmapNodes_.find (nameRoadmap) == roadmapNodes_.end ()) { + //no node named nodeName + std::cout << "No roadmap named \"" << nameRoadmap << "\"" << std::endl; + return false; + } + else { + RoadmapViewerPtr_t rm_ptr = roadmapNodes_[nameRoadmap]; + osgVector3 position = WindowsManager::corbaConfToOsgVec3 (configuration); + osgQuat quat = WindowsManager::corbaConfToOsgQuat (configuration); + // mtx_.lock(); + rm_ptr->addNode(position,quat,mtx_); + // mtx_.unlock(); + return true; + } + } + + std::vector<std::string> WindowsManager::getNodeList () + { + std::vector<std::string> l; + std::cout << "List of Nodes :" << std::endl; + for (std::map<std::string, NodePtr_t>::iterator it=nodes_.begin (); + it!=nodes_.end (); ++it) { + std::cout << " " << it->first << std::endl; + l.push_back (it->first); + } + return l; + } + + std::vector<std::string> WindowsManager::getSceneList () + { + std::vector<std::string> l; + std::cout << "List of GroupNodes :" << std::endl; + for (std::map<std::string, GroupNodePtr_t>::iterator it= + groupNodes_.begin (); it!=groupNodes_.end (); ++it) { + std::cout << " " << it->first << std::endl; + l.push_back (it->first); + } + return l; + } + + std::vector<std::string> WindowsManager::getWindowList () + { + std::vector<std::string> l; + std::cout << "List of Windows :" << std::endl; + size_t rank = 0; + for (WindowManagerVector_t::iterator it = windowManagers_.begin (); + it!=windowManagers_.end (); ++it) { + std::cout << rank << " - " << (*it)->getViewerClone ()->getCamera()->getGraphicsContext ()->getTraits ()->windowName << std::endl; + l.push_back ((*it)->getViewerClone ()->getCamera()->getGraphicsContext ()->getTraits ()->windowName); + } + return l; + } + + bool WindowsManager::createGroup (const char* groupNameCorba) + { + const std::string groupName (groupNameCorba); + if (nodes_.find (groupName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << groupName + << "\" already exist." << std::endl; + return false; + } + else { + GroupNodePtr_t groupNode = GroupNode::create (groupName); + WindowsManager::initParent (groupName, groupNode); + addGroup (groupName, groupNode); + return true; + } + } + + bool WindowsManager::addURDF (const char* urdfNameCorba, + const char* urdfPathCorba, + const char* urdfPackagePathCorba) + { + const std::string urdfName (urdfNameCorba); + const std::string urdfPath (urdfPathCorba); + const std::string urdfPackagePath (urdfPackagePathCorba); + if (nodes_.find (urdfName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << urdfName + << "\" already exist." << std::endl; + return false; + } + else { + GroupNodePtr_t urdf = urdfParser::parse + (urdfName, urdfPath, urdfPackagePath); + NodePtr_t link; + for (int i=0; i< urdf->getNumOfChildren (); i++) { + link = urdf->getChild (i); + nodes_[link->getID ()] = link; + } + WindowsManager::initParent (urdfName, urdf); + addGroup (urdfName, urdf); + return true; + } + } + + bool WindowsManager::addUrdfCollision (const char* urdfNameCorba, + const char* urdfPathCorba, const char* urdfPackagePathCorba) + { + const std::string urdfName (urdfNameCorba); + const std::string urdfPath (urdfPathCorba); + const std::string urdfPackagePath (urdfPackagePathCorba); + if (nodes_.find (urdfName) != nodes_.end ()) { + std::cout << "You need to chose an other name, \"" << urdfName + << "\" already exist." << std::endl; + return false; + } + else { + GroupNodePtr_t urdf = urdfParser::parse + (urdfName, urdfPath, urdfPackagePath, "collision"); + NodePtr_t link; + for (int i=0; i< urdf->getNumOfChildren (); i++) { + link = urdf->getChild (i); + nodes_[link->getID ()] = link; + } + WindowsManager::initParent (urdfName, urdf); + addGroup (urdfName, urdf); + return true; + } + } + + void WindowsManager::addUrdfObjects (const char* urdfNameCorba, + const char* urdfPathCorba, + const char* urdfPackagePathCorba, + bool visual) + { + const std::string urdfName (urdfNameCorba); + const std::string urdfPath (urdfPathCorba); + const std::string urdfPackagePath (urdfPackagePathCorba); + if (urdfName == "") { + throw std::runtime_error ("Parameter nodeName cannot be empty in " + "idl request addUrdfObjects."); + } + if (nodes_.find (urdfName) != nodes_.end ()) { + std::ostringstream oss; + oss << "You need to chose an other name, \"" << urdfName + << "\" already exist."; + throw std::runtime_error (oss.str ()); + } + GroupNodePtr_t urdf = urdfParser::parse + (urdfName, urdfPath, urdfPackagePath, + visual ? "visual" : "collision", "object"); + NodePtr_t link; + for (int i=0; i< urdf->getNumOfChildren (); i++) { + link = urdf->getChild (i); + nodes_[link->getID ()] = link; + } + WindowsManager::initParent (urdfName, urdf); + addGroup (urdfName, urdf); + } + + bool WindowsManager::addToGroup (const char* nodeNameCorba, + const char* groupNameCorba) + { + const std::string nodeName (nodeNameCorba); + const std::string groupName (groupNameCorba); + if (nodes_.find (nodeName) == nodes_.end () || + groupNodes_.find (groupName) == groupNodes_.end ()) { + std::cout << "Node name \"" << nodeName << "\" and/or groupNode \"" + << groupName << "\" doesn't exist." << std::endl; + return false; + } + else { + mtx_.lock();// if addChild is called in the same time as osg::frame(), gepetto-viewer crash + groupNodes_[groupName]->addChild (nodes_[nodeName]); + mtx_.unlock(); + return true; + } + } + + bool WindowsManager::removeFromGroup (const char* nodeNameCorba, + const char* groupNameCorba) + { + const std::string nodeName (nodeNameCorba); + const std::string groupName (groupNameCorba); + if (nodes_.find (nodeName) == nodes_.end () || + groupNodes_.find (groupName) == groupNodes_.end ()) { + std::cout << "Node name \"" << nodeName << "\" and/or groupNode \"" + << groupName << "\" doesn't exist." << std::endl; + return false; + } + else { + groupNodes_[groupName]->removeChild(nodes_[nodeName]); + return true; + } + } + + bool WindowsManager::applyConfiguration (const char* nodeNameCorba, + const value_type* configurationCorba) + { + const std::string nodeName (nodeNameCorba); + if (nodes_.find (nodeName) == nodes_.end ()) { + //no node named nodeName + std::cout << "No Node named \"" << nodeName << "\"" << std::endl; + return false; + } + else { + NodeConfiguration newNodeConfiguration; + newNodeConfiguration.node = nodes_[nodeName]; + try { + newNodeConfiguration.position = + WindowsManager::corbaConfToOsgVec3 (configurationCorba); + newNodeConfiguration.quat = + WindowsManager::corbaConfToOsgQuat (configurationCorba); + } catch (const std::exception& exc) { + std::cout << "Error when converting configuration, configuration " + "should be DOUBLE[7] = [transX, transY, transZ, quatW, quatX," + "quatY, quatZ]" <<std::endl; + return false; + } + mtx_.lock(); + newNodeConfigurations_.push_back (newNodeConfiguration); + mtx_.unlock(); + return true; + } + } + + bool WindowsManager::addLandmark (const char* nodeNameCorba, + float size) + { + const std::string nodeName (nodeNameCorba); + if (nodes_.find (nodeName) == nodes_.end ()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." + << std::endl; + return false; + } + nodes_[nodeName]->addLandmark (size); + return true; + } + + bool WindowsManager::deleteLandmark (const char* nodeNameCorba) + { + const std::string nodeName (nodeNameCorba); + if (nodes_.find (nodeName) == nodes_.end ()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." + << std::endl; + return false; + } + nodes_[nodeName]->deleteLandmark (); + return true; + } + + bool WindowsManager::setVisibility (const char* nodeNameCorba, + const char* visibilityModeCorba) + { + const std::string nodeName (nodeNameCorba); + const std::string visibilityMode (visibilityModeCorba); + VisibilityMode visibility = getVisibility (visibilityMode); + if (nodes_.find (nodeName) == nodes_.end ()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." + << std::endl; + return false; + } + nodes_[nodeName]->setVisibilityMode (visibility); + return true; + } + + bool WindowsManager::setWireFrameMode (const char* nodeNameCorba, + const char* wireFrameModeCorba) + { + const std::string nodeName (nodeNameCorba); + const std::string wireFrameMode (wireFrameModeCorba); + WireFrameMode wire = getWire (wireFrameMode); + if (nodes_.find (nodeName) == nodes_.end ()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." + << std::endl; + return false; + } + nodes_[nodeName]->setWireFrameMode (wire); + return true; + } + + bool WindowsManager::setLightingMode (const char* nodeNameCorba, + const char* lightingModeCorba) + { + const std::string nodeName (nodeNameCorba); + const std::string lightingMode (lightingModeCorba); + LightingMode light = getLight (lightingMode); + if (nodes_.find (nodeName) == nodes_.end ()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." + << std::endl; + return false; + } + nodes_[nodeName]->setLightingMode (light); + return true; + } + + bool WindowsManager::startCapture (const WindowID windowId, const char* filename, + const char* extension) + { + if (windowId >= 0 || windowId < windowManagers_.size ()) { + windowManagers_[windowId]->startCapture + (std::string (filename), std::string (extension)); + return true; + } + else { + std::cout << "Window ID " << windowId + << " doesn't exist." << std::endl; + return false; + } + } + + bool WindowsManager::stopCapture (const WindowID windowId) + { + if (windowId >= 0 || windowId < windowManagers_.size ()) { + windowManagers_[windowId]->stopCapture (); + return true; + } + else { + std::cout << "Window ID " << windowId + << " doesn't exist." << std::endl; + return false; + } + } + + bool WindowsManager::writeNodeFile (const WindowID windowId, const char* filename) + { + if (windowId >= 0 || windowId < windowManagers_.size ()) { + return windowManagers_[windowId]->writeNodeFile (std::string (filename)); + } + else { + std::cout << "Window ID " << windowId + << " doesn't exist." << std::endl; + return false; + } + } + + WindowManagerPtr_t WindowsManager::getWindowManager (const WindowID wid) + { + if (wid >= 0 || wid < windowManagers_.size ()) { + return windowManagers_[wid]; + } + else { + std::cout << "Window ID " << wid << " doesn't exist." << std::endl; + return WindowManagerPtr_t (); + } + } + + GroupNodePtr_t WindowsManager::getScene (const std::string sceneName) + { + std::map<std::string, GroupNodePtr_t>::iterator it = + groupNodes_.find (sceneName); + if (it == groupNodes_.end ()) + return GroupNodePtr_t (); + return it->second; + } + + NodePtr_t WindowsManager::getNode (const std::string nodeName) + { + std::map<std::string, NodePtr_t>::iterator it = + nodes_.find (nodeName); + if (it == nodes_.end ()) + return NodePtr_t (); + return it->second; + } + NodePtr_t getNode (const std::string nodeName); +} // namespace graphics