00001 #ifndef Impala_Visualization_View_h
00002 #define Impala_Visualization_View_h
00003
00004 #include "Core/Array/Arrays.h"
00005 #include "Core/Array/GetRgbPixels.h"
00006 #include "OglGui/View.h"
00007 #include "Core/Geometry/Rectangle.h"
00008
00009 namespace Impala
00010 {
00011 namespace Visualization
00012 {
00013
00014
00015 class View : public OglGui::View
00016 {
00017 public:
00018 typedef Core::Array::Array2dVec3UInt8 Array2dVec3UInt8;
00019
00020
00021 View(OGLWND* oglWnd, int x, int y, int imW, int imH,
00022 double scale, bool texturing, bool noTexScaling, bool keepDispImage,
00023 OglGui::ViewListener* listener = 0) :
00024 OglGui::View(oglWnd, InitOGLIMAGE(imW, imH, texturing, noTexScaling,
00025 keepDispImage), x, y, scale*imW,
00026 scale*imH, listener)
00027 {
00028
00029
00030
00031
00032
00033
00034 viewSys.SetZoom(mView2D, scale, scale);
00035 viewSys.SetTags(mView2D, sTags);
00036
00037 if (mTexturing)
00038 viewSys.SetTexturing(mView2D, 1);
00039
00040 oglSys.ReleaseOglImage(mOglIm);
00041 mOglIm = 0;
00042
00043 mPointerX = -1;
00044 mPointerDrag = false;
00045 }
00046
00047
00048 View(OGLWND* oglWnd, float x, float y, float z, int imW, int imH,
00049 double scaleX, double scaleY, bool noTexScaling,
00050 bool keepDispImage, OglGui::ViewListener* listener = 0) :
00051 OglGui::View(oglWnd, InitOGLIMAGE(imW, imH, true, noTexScaling,
00052 keepDispImage), x, y, z,
00053 scaleX, scaleY, 1.0f, listener)
00054 {
00055 view3DSys.SetZoom(mView3D, scaleX, scaleY);
00056 view3DSys.SetTags(mView3D, sTags );
00057
00058 oglSys.ReleaseOglImage(mOglIm);
00059 mOglIm = 0;
00060
00061 mPointerX = -1;
00062 mPointerDrag = false;
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 void
00076 SetText(std::string text)
00077 {
00078 if (mIs2D)
00079 {
00080 viewSys.SetStr(mView2D, OGL_TEXT, (char*) text.c_str());
00081 viewSys.SetTags(mView2D, showTextTag);
00082 }
00083 }
00084
00085
00086
00087 void
00088 SetTagsTo(int tags, bool mode)
00089 {
00090 if (mIs2D)
00091 {
00092 if (mode)
00093 viewSys.SetTags(mView2D, tags);
00094 else
00095 viewSys.ClearTags(mView2D, tags);
00096 }
00097 else
00098 {
00099 if (mode)
00100 view3DSys.SetTags(mView3D, tags);
00101 else
00102 view3DSys.ClearTags(mView3D, tags);
00103 }
00104 }
00105
00106 bool
00107 AreTagsOn(int tags)
00108 {
00109 if (mIs2D)
00110 return viewSys.HasTags(mView2D, tags) ? true : false;
00111 else
00112 return view3DSys.HasTags(mView3D, tags) ? true : false;
00113 }
00114
00115 void
00116 SetVisible(bool mode)
00117 {
00118 SetTagsTo(visibleTag, mode);
00119 }
00120
00121 bool
00122 GetVisible()
00123 {
00124 return AreTagsOn(visibleTag);
00125 }
00126
00127 void
00128 SetBorderCol(ULONG color)
00129 {
00130 if (mIs2D)
00131 viewSys.SetColor(mView2D, OGL_BORDER, color);
00132 }
00133
00134 void
00135 UpdateImage(unsigned char* dataPtr)
00136 {
00137 OGLIMAGE* oglIm = GetImage();
00138
00139 ReleaseOglImage(oglIm);
00140 Array2dVec3UInt8* dispIm = (Array2dVec3UInt8*) oglIm->imageHandle;
00141 if (!dispIm)
00142 return;
00143 int nBytes = dispIm->CW() * dispIm->CH() * 3;
00144 memcpy(dispIm->CPB(0, 0), dataPtr, nBytes);
00145 DoUpdateDispImage(oglIm);
00146 }
00147
00148 template <class ArrayT>
00149 void
00150 UpdateImage(ArrayT* im, std::string displayMode)
00151 {
00152 OGLIMAGE* oglIm = GetImage();
00153
00154 ReleaseOglImage(oglIm);
00155 Array2dVec3UInt8* dispIm = (Array2dVec3UInt8*) oglIm->imageHandle;
00156 if (!dispIm)
00157 return;
00158 if ((dispIm->CW() != im->CW()) || (dispIm->CH() != im->CH()))
00159 {
00160 delete dispIm;
00161 dispIm = Core::Array::ArrayCreate<Array2dVec3UInt8>(im->CW(),
00162 im->CH(), 0, 0);
00163 oglIm->imageHandle = dispIm;
00164 }
00165 Core::Array::GetRgbPixels(im, dispIm->CPB(0, 0), displayMode);
00166 DoUpdateDispImage(oglIm);
00167 }
00168
00169 void
00170 SetUpdateOglImage()
00171 {
00172 OGLIMAGE* oglIm = GetImage();
00173
00174 ReleaseOglImage(oglIm);
00175 if (!oglIm)
00176 return;
00177 oglIm->changed = 1;
00178 }
00179
00180 Array2dVec3UInt8*
00181 GetDispImage()
00182 {
00183 OGLIMAGE* oglIm = GetImage();
00184
00185 ReleaseOglImage(oglIm);
00186 if (!oglIm)
00187 return 0;
00188 return (Array2dVec3UInt8*) oglIm->imageHandle;
00189 }
00190
00191 static void
00192 SetTags(unsigned int tags)
00193 {
00194 sTags = tags;
00195 }
00196
00197 int
00198 GetPointerX() const
00199 {
00200 return mPointerX;
00201 }
00202
00203 int
00204 GetPointerY() const
00205 {
00206 return mPointerY;
00207 }
00208
00209 Core::Geometry::Rectangle
00210 GetPointerDragRect() const
00211 {
00212 return Core::Geometry::Rectangle(mPointerX, mPointerY, mPointerDragX,
00213 mPointerDragY);
00214 }
00215
00216 virtual void
00217 OnMouse(int msg, int btn, int state, float x, float y)
00218 {
00219 OglGui::View::OnMouse(msg, btn, state, x, y);
00220 if (msg == oglMouseUp)
00221 mPointerDrag = false;
00222 ViewToIm(x, y, mPointerX, mPointerY);
00223 if ((msg == oglMouseDown) && (btn == oglLeftButton))
00224 {
00225 mPointerDrag = true;
00226 mPointerDragX = mPointerX;
00227 mPointerDragY = mPointerY;
00228 }
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 int
00249 W()
00250 {
00251 int x,y,w,h;
00252 GetDimensions2D(&x, &y, &w, &h);
00253 return w;
00254 }
00255
00256 int
00257 H()
00258 {
00259 int x,y,w,h;
00260 GetDimensions2D(&x, &y, &w, &h);
00261 return h;
00262 }
00263
00264 protected:
00265
00266 OGLIMAGE*
00267 InitOGLIMAGE(int imW, int imH, bool texturing, bool noTexScaling,
00268 bool keepDispImage)
00269 {
00270 mTexturing = texturing;
00271 mNoTexScaling = noTexScaling;
00272 mKeepDispImage = keepDispImage;
00273
00274 mOglIm = oglSys.OglImage(GL_RGB, imW, imH);
00275 mOglIm->imDataFunc = MyOglImdataFunc;
00276 mOglIm->onDestroy = MyOglImdataDestroyFunc;
00277 if (mNoTexScaling)
00278 mOglIm->noTexScaling = 1;
00279 Array2dVec3UInt8* ar =
00280 Core::Array::ArrayCreate<Array2dVec3UInt8>(imW, imH, 0, 0);
00281 mOglIm->imageHandle = ar;
00282 return mOglIm;
00283
00284 }
00285
00286
00287
00288 void
00289 DoUpdateDispImage(OGLIMAGE* oglIm)
00290 {
00291 oglIm->changed = 1;
00292 if (!mKeepDispImage)
00293 {
00294 oglSys.LoadGLTexture(oglIm);
00295 oglIm->changed = 0;
00296 Array2dVec3UInt8* dispIm = (Array2dVec3UInt8*) oglIm->imageHandle;
00297 delete dispIm;
00298 oglIm->imageHandle = 0;
00299 }
00300 }
00301
00302
00303
00304 static void*
00305 MyOglImdataFunc(OGLIMAGE* oglIm)
00306 {
00307
00308 Array2dVec3UInt8* ar = (Array2dVec3UInt8 *) oglIm->imageHandle;
00309
00310
00311 oglIm->w = ar->CW();
00312 oglIm->h = ar->CH();
00313 oglIm->changed = 0;
00314
00315 return (void *) ar->CPB(0, 0);
00316 }
00317
00318 static void
00319 MyOglImdataDestroyFunc(OGLIMAGE* oglIm)
00320 {
00321 if (!oglIm)
00322 return;
00323 Array2dVec3UInt8* ar = (Array2dVec3UInt8 *) oglIm->imageHandle;
00324 if (ar)
00325 delete ar;
00326 }
00327
00328 private:
00329
00330 OGLIMAGE* mOglIm;
00331 bool mTexturing;
00332 bool mNoTexScaling;
00333 bool mKeepDispImage;
00334
00335
00336 int mPointerX;
00337 int mPointerY;
00338 int mPointerDragX;
00339 int mPointerDragY;
00340 bool mPointerDrag;
00341
00342 static unsigned int sTags;
00343
00344 };
00345
00346 unsigned int View::sTags =
00347 selectableTag | showBgTag | showBorderTag | movableTag | sizableTag |
00348 showBorderTag | panableTag | zoomableTag | showTitleTag | rotatableTag;
00349
00350 }
00351 }
00352
00353 #endif