Go to the documentation of this file.00001
00019 #ifndef URDF2GRASPIT_MARKERSELECTOR_H
00020 #define URDF2GRASPIT_MARKERSELECTOR_H
00021
00022
00023 #include <urdf_viewer/InventorViewer.h>
00024
00025 #include <Eigen/Geometry>
00026
00027 #include <vector>
00028 #include <map>
00029 #include <fstream>
00030 #include <iostream>
00031 #include <sstream>
00032 #include <string>
00033
00034 namespace urdf2graspit
00035 {
00036 namespace markerselector
00037 {
00043 class MarkerSelector: public urdf_viewer::InventorViewer
00044 {
00045 public:
00049 class Marker
00050 {
00051 public:
00052 Marker(int id): markerID(id) {}
00053 Marker(const Marker& m):
00054 linkName(m.linkName),
00055 visualNum(m.visualNum),
00056 coords(m.coords),
00057 normal(m.normal),
00058 markerID(m.markerID) {}
00059
00060 ~Marker() {}
00061
00062
00063 friend std::ostream& operator<<(std::ostream& o, const Marker& m)
00064 {
00065 o << m.linkName << "; visual " << m.visualNum << "; Coords " << m.coords
00066 << "; normal " << m.normal;
00067 return o;
00068 }
00069
00070 void setCoords(const double x, const double y, const double z)
00071 {
00072 coords = Eigen::Vector3d(x, y, z);
00073 }
00074 void setNormal(const double x, const double y, const double z)
00075 {
00076 normal = Eigen::Vector3d(x, y, z);
00077 }
00078
00079 static std::string toSoBaseName(const std::string& name);
00080
00081
00082 Eigen::Vector3d coords;
00083
00084
00085 Eigen::Vector3d normal;
00086
00087
00088
00089
00090
00091
00092
00093
00094 std::string linkName;
00095
00096 int visualNum;
00097
00098
00099 int markerID;
00100 };
00101
00102 typedef std::map<std::string, std::vector<Marker> > MarkerMap;
00103
00104
00109 explicit MarkerSelector(float _marker_size, bool _faces_ccw):
00110 urdf_viewer::InventorViewer(_faces_ccw),
00111 marker_size(_marker_size) {}
00112
00113 MarkerSelector(const MarkerSelector& o):
00114 marker_size(o.marker_size), markers(o.markers) {}
00115 ~MarkerSelector() {}
00116
00124 bool writeResults(const std::string& outputFile);
00125
00130 MarkerMap getMarkers();
00131
00132 std::string toString();
00133
00134 protected:
00135 virtual void onClickModel(const SoPickedPoint * pickPoint);
00136 virtual void onMouseBtnClick(SoEventCallback *pNode){}
00137
00138 private:
00139
00140 static bool sortMarker(const Marker& i, const Marker& j);
00141
00142 static bool writeToFile(const std::string& content, const std::string& filename);
00143
00144 std::vector<Marker> markers;
00145
00146
00147 typedef std::map<int, SoNode*> MarkerNodeMap;
00148
00149 MarkerNodeMap markerParentNodes;
00150
00151
00152 float marker_size;
00153 };
00154
00155 }
00156 }
00157 #endif // URDF2GRASPIT_MARKERSELECTOR_H