00001
00002 #ifndef OglGui_ViewerPointCloudNavigator_h
00003 #define OglGui_ViewerPointCloudNavigator_h
00004
00005 #ifndef OglGui_ViewerPointCloud_h
00006 #include "OglGui/ViewerPointCloud.h"
00007 #endif
00008
00009 namespace OglGui
00010 {
00011
00012 class ViewerPointCloudNavigator : public Window
00013 {
00014 public:
00015 ViewerPointCloudNavigator(Window* parent, int x, int y, int w, int h) :
00016 Window(parent, x, y, w, h)
00017 {
00018 Init(w, h);
00019 }
00020
00021 void SetTarget(ViewerPointCloud* vpc)
00022 {
00023 mViewerPointCloud = vpc;
00024 }
00025
00026 void SetMinMax(float minX, float minY, float maxX, float maxY)
00027 {
00028 mMinX = minX;
00029 mMinY = minY;
00030 mMaxX = maxX;
00031 mMaxY = maxY;
00032 }
00033
00034 void PointSize(float ptSize)
00035 {
00036 mPtSize = ptSize < 1.f ? 1.f : ptSize;
00037 }
00038
00039 void ShowVisiblePart()
00040 {
00041 float vpcW = mViewerPointCloud->W();
00042 float vpcH = mViewerPointCloud->H();
00043 float virtX1 = mMinX, virtY1 = mMinY;
00044 float virtX2 = mMaxX, virtY2 = mMaxY;
00045
00046 mViewerPointCloud->Point2Wnd(virtX1, virtY1);
00047 mViewerPointCloud->Point2Wnd(virtX2, virtY2);
00048
00049 float x1 = (-virtX1/(virtX2-virtX1)) * W();
00050 float y1 = (-virtY1/(virtY2-virtY1)) * H();
00051 float x2 = ((-virtX1+vpcW)/(virtX2-virtX1)) * W();
00052 float y2 = ((-virtY1+vpcH)/(virtY2-virtY1)) * H();
00053
00054 SetSolidFillColor(mVisiblePartColor);
00055 int bInfo[3];
00056 oglSys.StartBlend(bInfo);
00057 FillRectangle(x1, y1, x2-x1, y2-y1);
00058 SetSolidLineColor(oglBLACK);
00059 DrawRectangle(x1, y1, x2-x1, y2-y1);
00060 oglSys.EndBlend(bInfo);
00061 }
00062
00063 virtual void DisplayFunc()
00064 {
00065 OGC myOGC;
00066
00067 OGCSave(&myOGC);
00068 int motion = oglSys.GetAllMouseMotion(mViewerPointCloud->GetOGLWND());
00069 oglSys.SetAllMouseMotion(mOglWnd, motion);
00070
00071 Window::DisplayFunc();
00072
00073 if (!mViewerPointCloud)
00074 return;
00075
00076 if (mObtainMinMax)
00077 mViewerPointCloud->GetMinMax(mMinX, mMinY, mMaxX, mMaxY);
00078 if (mDoShow)
00079 mViewerPointCloud->DrawPointsEx(0.f, 0.f, -mMinX, -mMinY, mPtSize,
00080 W()/(mMaxX-mMinX),H()/(mMaxY-mMinY),
00081 W(), H());
00082 ShowVisiblePart();
00083 OGCRestore(&myOGC);
00084 }
00085
00086 void ToViewerPointCloudMouse(int msg, int btn, int state, int x, int y)
00087 {
00088 float virtX1 = mMinX, virtX2 = mMaxX;
00089 float virtY1 = mMinY, virtY2 = mMaxY;
00090
00091 mViewerPointCloud->Point2Wnd(virtX1, virtY1);
00092 mViewerPointCloud->Point2Wnd(virtX2, virtY2);
00093
00094 int vpcX = virtX1 + (x/(float)W()) * (virtX2-virtX1);
00095 int vpcY = virtY1 + (y/(float)H()) * (virtY2-virtY1);
00096
00097 mViewerPointCloud->MouseFunc(msg, btn, state, vpcX, vpcY);
00098 }
00099
00100 virtual void KeyboardFunc(int c, int state)
00101 {
00102 if (c=='P') PointSize(mPtSize+0.5f);
00103 if (c=='p') PointSize(mPtSize-0.5f);
00104 if (c=='S') mDoShow = !mDoShow;
00105
00106 mViewerPointCloud->KeyboardFunc(c, state);
00107 }
00108
00109 virtual void MouseFunc(int msg, int btn, int state, int x, int y)
00110 {
00111 static bool isDragging = false;
00112 static int lastX;
00113
00114 Window::MouseFunc(msg, btn, state, x, y);
00115 if (msg == oglMouseDown && btn == oglRightButton)
00116 {
00117 isDragging = true;
00118 lastX = x;
00119 }
00120
00121 if (msg == oglMouseUp)
00122 isDragging = false;
00123
00124 if (!isDragging)
00125 {
00126 ToViewerPointCloudMouse(msg, btn, state, x, y);
00127 return;
00128 }
00129
00130 if (state&oglShift)
00131 {
00132 float scale = mViewerPointCloud->Scale();
00133 mViewerPointCloud->Scale(scale * (1.f+((x - lastX)/50.f)));
00134 }
00135 else
00136 {
00137 float vpcW = mViewerPointCloud->W();
00138 float vpcH = mViewerPointCloud->H();
00139 float xFact = x / (float) W();
00140 float yFact = y / (float) H();
00141 float pX = (vpcW/2) - (mMinX+(xFact * (mMaxX-mMinX)));
00142 float pY = (vpcH/2) - (mMinY+(yFact * (mMaxY-mMinY)));
00143 mViewerPointCloud->SetPtDocXY(pX, pY);
00144 }
00145 lastX = x;
00146 }
00147
00148 private:
00149 void Init(int w, int h)
00150 {
00151 mViewerPointCloud = 0;
00152 mDoShow = true;
00153 mPtSize = 1.f;
00154 mObtainMinMax = true;
00155 mMinX = 0;
00156 mMaxX = w;
00157 mMinY = 0;
00158 mMaxY = h;
00159 mVisiblePartColor = oglTrWHITE;
00160 }
00161
00162 ViewerPointCloud* mViewerPointCloud;
00163
00164 bool mDoShow;
00165 ULONG mVisiblePartColor;
00166 float mPtSize;
00167 bool mObtainMinMax;
00168 float mMinX, mMaxX;
00169 float mMinY, mMaxY;
00170 };
00171
00172 }
00173 #endif
00174