00001 #ifndef Impala_Visualisation_Plot_Markers_h
00002 #define Impala_Visualisation_Plot_Markers_h
00003
00004 #include "Visualization/Plot/Plottable.h"
00005 #include "Visualization/Plot/Plot.h"
00006 #include <vector>
00007
00008 namespace Impala
00009 {
00010 namespace Visualization
00011 {
00012 namespace Plot
00013 {
00014
00015 class Markers : public Plottable
00016 {
00017 public:
00018 Markers()
00019 {
00020 mSelection = 0;
00021 }
00022
00023 void
00024 Draw(Plot* plot)
00025 {
00026 if(mSelection < mData.size()/7)
00027 {
00028 int i=mSelection*7;
00029 double size = mData[i+6];
00030 glPointSize(size+4);
00031 glBegin(GL_POINTS);
00032 glColor3d(mData[i+3], mData[i+4], mData[i+5]);
00033 glVertex3d(mData[i], mData[i+1], mData[i+2]);
00034 glEnd();
00035
00036 glPointSize(size+2);
00037 glBegin(GL_POINTS);
00038 glColor3d(1,1,1);
00039 glVertex3d(mData[i], mData[i+1], mData[i+2]);
00040 glEnd();
00041
00042 glPointSize(size);
00043 glBegin(GL_POINTS);
00044 glColor3d(mData[i+3], mData[i+4], mData[i+5]);
00045 glVertex3d(mData[i], mData[i+1], mData[i+2]);
00046 glEnd();
00047 }
00048
00049 for (int i=0 ; i<mData.size() ; i+=7)
00050 {
00051 glColor3d(mData[i+3], mData[i+4], mData[i+5]);
00052
00053 double size = mData[i+6];
00054 glPointSize(size);
00055 glBegin(GL_POINTS);
00056 glVertex3d(mData[i], mData[i+1], mData[i+2]);
00057 glEnd();
00058
00059 char id[2] = "a";
00060 glColor3d(1,1,1);
00061 glRasterPos2d(mData[i], mData[i+1]);
00062 id[0] = mID[i/7];
00063 oglSys.PrintFont(1, id);
00064 }
00065 }
00066
00067 void
00068 AddMarker(double x, double y, double z, double r, double g, double b,
00069 double size)
00070 {
00071 int i = mData.size();
00072 mData.resize(i + 7);
00073 mData[i++] = x;
00074 mData[i++] = y;
00075 mData[i++] = z;
00076 mData[i++] = r;
00077 mData[i++] = g;
00078 mData[i++] = b;
00079 mData[i++] = size;
00080 }
00081
00082 void
00083 AddID(char name)
00084 {
00085 mID.push_back(name);
00086 }
00087
00088 void
00089 Clear()
00090 {
00091 mData.clear();
00092 mID.clear();
00093 }
00094
00095 virtual void
00096 OnMouse(double x, double y, int msg, int but, int state)
00097 {
00098 if(mData.size()==0)
00099 return;
00100 if((msg == oglMouseMove || msg == oglMouseDown) && (state & oglLeftButton))
00101 {
00102 int best = 0;
00103 double d, dx, dy, dist;
00104 dx = x-mData[0];
00105 dy = y-mData[1];
00106 dist = dx*dx + dy*dy;
00107 for(int i=7 ; i<mData.size() ; i+=7)
00108 {
00109 dx = x-mData[i+0];
00110 dy = y-mData[i+1];
00111 d = dx*dx + dy*dy;
00112 if(d < dist)
00113 {
00114 best = i/7;
00115 dist = d;
00116 }
00117 }
00118
00119 mSelection = best;
00120 }
00121 }
00122
00123 int mSelection;
00124 protected:
00125 std::vector<double> mData;
00126 std::vector<char> mID;
00127 };
00128
00129 }
00130 }
00131 }
00132
00133 #endif Impala_Visualisation_Plot_Markers_h