| 1 | // Affichage d'image R. Ansari 05/95
|
|---|
| 2 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
|---|
| 3 | // Refonte Reza 10/95
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | #include <stdlib.h>
|
|---|
| 7 | #include <stdio.h>
|
|---|
| 8 | #include <string>
|
|---|
| 9 | #include <string.h>
|
|---|
| 10 |
|
|---|
| 11 | #include "piimage.h"
|
|---|
| 12 |
|
|---|
| 13 | #include "imageop.h"
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | /* --Methode-- */
|
|---|
| 17 | PIImage::PIImage(PIContainerGen *par, char *nom,
|
|---|
| 18 | int sx, int sy, int px, int py) :
|
|---|
| 19 | PIPixmap(par, nom, sx, sy, px, py)
|
|---|
| 20 | {
|
|---|
| 21 |
|
|---|
| 22 | img = NULL;
|
|---|
| 23 | aisup = false;
|
|---|
| 24 | curshow = true;
|
|---|
| 25 | winovis = true; // $CHECK$ Reza A enlever si possible 17/6/96
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | zow = NULL;
|
|---|
| 29 | gvw = NULL;
|
|---|
| 30 | trtw = NULL;
|
|---|
| 31 | trtlb = txw = NULL;
|
|---|
| 32 | SetTextWin(NULL);
|
|---|
| 33 | gpixm = zpixm = pixm = NULL;
|
|---|
| 34 | xsgpxm = xszpxm = xspxm = 0;
|
|---|
| 35 | ysgpxm = yszpxm = yspxm = 0;
|
|---|
| 36 | lut = NULL;
|
|---|
| 37 | offx = offy = 0;
|
|---|
| 38 | xpav = ypav = 0;
|
|---|
| 39 | xpv0 = ypv0 = 0;
|
|---|
| 40 | xszpav = yszpav = 1;
|
|---|
| 41 | xmv0 = ymv0 = -1;
|
|---|
| 42 | dxmv = dymv = 0;
|
|---|
| 43 | xcurs = ycurs = -1;
|
|---|
| 44 | zoom = 1;
|
|---|
| 45 | zmgv = 1;
|
|---|
| 46 |
|
|---|
| 47 | SetColMap(CMAP_COLRJ32);
|
|---|
| 48 |
|
|---|
| 49 | SetBackgroundColor(PI_Black);
|
|---|
| 50 |
|
|---|
| 51 | ActivateButton(1);
|
|---|
| 52 | ActivateMove(1);
|
|---|
| 53 | ActivateButton(2);
|
|---|
| 54 | ActivateMove(2);
|
|---|
| 55 | ActivateButton(3);
|
|---|
| 56 | ActivateMove(3);
|
|---|
| 57 |
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | /* --Methode-- */
|
|---|
| 61 | PIImage::~PIImage()
|
|---|
| 62 | {
|
|---|
| 63 | if (pixm) delete pixm;
|
|---|
| 64 | if (zpixm) delete zpixm;
|
|---|
| 65 | if (txw) txw->SetLabel("");
|
|---|
| 66 | if (zow)
|
|---|
| 67 | {
|
|---|
| 68 | zow->SetPixmap(NULL,0,0);
|
|---|
| 69 | zow->EraseWindow();
|
|---|
| 70 | }
|
|---|
| 71 | if (gpixm) delete gpixm;
|
|---|
| 72 | if (gvw)
|
|---|
| 73 | {
|
|---|
| 74 | gvw->SetPixmap(NULL,0,0);
|
|---|
| 75 | gvw->EraseWindow();
|
|---|
| 76 | gvw->SetMsg(0); gvw->SetMsgParent(NULL);
|
|---|
| 77 | gvw->SetUserData(NULL, 0);
|
|---|
| 78 | }
|
|---|
| 79 | if (lut) delete lut;
|
|---|
| 80 | if (aisup) delete img; // Suppression automatique d'image
|
|---|
| 81 | if (trtw) delete trtw;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /* --Methode-- */
|
|---|
| 85 | void PIImage::Process(PIMessage msg, PIMsgHandler* sender, void* data)
|
|---|
| 86 | {
|
|---|
| 87 | if (UserMsg(msg) == (Msg()+626))
|
|---|
| 88 | {
|
|---|
| 89 | if (ModMsg(msg) == PIMsg_Click)
|
|---|
| 90 | { int* pxy=(int *)data; SetPave(pxy[0]*zmgv, pxy[1]*zmgv); }
|
|---|
| 91 | if (ModMsg(msg) == PIMsg_Resize)
|
|---|
| 92 | { ComputeGloVPixmap(); SetGloVPixmap(); }
|
|---|
| 93 | }
|
|---|
| 94 | else ReSend(msg, sender, data);
|
|---|
| 95 | return;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /* --Methode-- */
|
|---|
| 99 | void PIImage::SetImage(P2DArrayAdapter *pim, bool ad, bool refr)
|
|---|
| 100 | {
|
|---|
| 101 |
|
|---|
| 102 | offx = offy = 0;
|
|---|
| 103 | xpav = ypav = 0;
|
|---|
| 104 | xszpav = yszpav = 1;
|
|---|
| 105 | img = pim;
|
|---|
| 106 | if (gpixm) delete gpixm;
|
|---|
| 107 | gpixm = NULL;
|
|---|
| 108 | xsgpxm = ysgpxm = 0;
|
|---|
| 109 | zmgv = 1;
|
|---|
| 110 |
|
|---|
| 111 | if (img) {
|
|---|
| 112 | // SetSize(img->XSize(), img->YSize());
|
|---|
| 113 | CenterPave();
|
|---|
| 114 | float min=1., max=-1., moy, sig;
|
|---|
| 115 | int nbnul, nbsat;
|
|---|
| 116 | img->CheckDyn(min, max, moy, sig, nbnul, nbsat);
|
|---|
| 117 | SetLut(min, max, kLutType_Lin, 1, refr);
|
|---|
| 118 | aisup = ad;
|
|---|
| 119 | }
|
|---|
| 120 | else aisup = false;
|
|---|
| 121 | return;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | /* --Methode-- */
|
|---|
| 126 | void PIImage::SetZoomWin(PIPixmap * zw, bool refr)
|
|---|
| 127 | {
|
|---|
| 128 | zow = zw;
|
|---|
| 129 | if (zow && refr && img)
|
|---|
| 130 | ComputeZoomPixmap();
|
|---|
| 131 | return;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | /* --Methode-- */
|
|---|
| 135 | void PIImage::SetGloVWin(PIPixmap * zw, bool refr)
|
|---|
| 136 | {
|
|---|
| 137 | gvw = zw;
|
|---|
| 138 | if (gvw && img)
|
|---|
| 139 | { ComputeGloVPixmap();
|
|---|
| 140 | if (refr) SetGloVPixmap(); }
|
|---|
| 141 | return;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | /* --Methode-- */
|
|---|
| 146 | void PIImage::SetTextWin(PILabel * tw, bool trw, int tx, int ty)
|
|---|
| 147 | {
|
|---|
| 148 | txw = tw;
|
|---|
| 149 | if (trw)
|
|---|
| 150 | {
|
|---|
| 151 | if (trtw) trtw->SetSize(tx, ty);
|
|---|
| 152 | else
|
|---|
| 153 | {
|
|---|
| 154 | trtw = new PIWindow(this, "PixVal", PIWK_transient, tx, ty, 0, 0);
|
|---|
| 155 | trtw->SetAutoDelChilds(true);
|
|---|
| 156 | trtlb = new PILabel(trtw, "PixVal", tx, ty, 0, 0);
|
|---|
| 157 | trtlb->SetBinding(PIBK_fixed,PIBK_fixed, PIBK_fixed,PIBK_fixed);
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 | else
|
|---|
| 161 | if (trtw) { delete trtw; trtw = NULL; trtlb = NULL; }
|
|---|
| 162 |
|
|---|
| 163 | return;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /* --Methode-- */
|
|---|
| 167 | void PIImage::ShowCursor(bool sc)
|
|---|
| 168 | {
|
|---|
| 169 | if (curshow == sc) return;
|
|---|
| 170 | curshow = sc;
|
|---|
| 171 | if (curshow) DrawCursor(mWGrC);
|
|---|
| 172 | else DrawCursor(mWGrC, -1, -1);
|
|---|
| 173 | return;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | /* --Methode-- */
|
|---|
| 177 | void PIImage::SetLut(float min, float max, int typlut, int lauto, bool refr)
|
|---|
| 178 | {
|
|---|
| 179 | if (lut) delete(lut);
|
|---|
| 180 | if (lauto && img)
|
|---|
| 181 | {
|
|---|
| 182 | int nbsig = lauto;
|
|---|
| 183 | float fracmax = 1. - 0.05*nbsig;
|
|---|
| 184 | img->ComputeLut_PicHisto(min, max, nbsig, fracmax);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | lut = new LUT(min, max, NbCol(), typlut);
|
|---|
| 188 |
|
|---|
| 189 | ComputeGloVPixmap();
|
|---|
| 190 | if (refr) Apply();
|
|---|
| 191 | return;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 | /* --Methode-- */
|
|---|
| 196 | void PIImage::SetLut(LUT *clut, bool refr)
|
|---|
| 197 | {
|
|---|
| 198 | LUT * olut = lut;
|
|---|
| 199 | lut = new LUT(clut->Min(), clut->Max(), NbCol(), clut->Type());
|
|---|
| 200 | if (olut) delete olut;
|
|---|
| 201 |
|
|---|
| 202 | ComputeGloVPixmap();
|
|---|
| 203 | if (refr) Apply();
|
|---|
| 204 | return;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | /* --Methode-- */
|
|---|
| 208 | void PIImage::SetZoomF(float fzm, bool refr)
|
|---|
| 209 | {
|
|---|
| 210 | int zm;
|
|---|
| 211 |
|
|---|
| 212 | if (fzm < 0.01) return;
|
|---|
| 213 | if (fzm < 1.) zm = (int)(-(1./fzm));
|
|---|
| 214 | else zm = (int)(fzm+0.25);
|
|---|
| 215 | SetZoom(zm, refr);
|
|---|
| 216 | return;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | /* --Methode-- */
|
|---|
| 220 | void PIImage::SetZoom(int zm, bool refr)
|
|---|
| 221 | {
|
|---|
| 222 | if ((zm == 0) || (zm == -1) ) zoom = 1;
|
|---|
| 223 | else if (zm > 20) zoom = 20;
|
|---|
| 224 | else if (zm < -20) zoom = -20;
|
|---|
| 225 | else zoom = zm;
|
|---|
| 226 | if (img)
|
|---|
| 227 | { SetOffsetFromPave();
|
|---|
| 228 | if (refr) Apply(); }
|
|---|
| 229 | return;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | /* --Methode-- */
|
|---|
| 233 | float PIImage::GetZoomF()
|
|---|
| 234 | {
|
|---|
| 235 | if (zoom >= 1) return((float)zoom);
|
|---|
| 236 | else return(-1./(float)zoom);
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | /* --Methode-- */
|
|---|
| 241 | void PIImage::SetOffset(int ox, int oy, bool refr)
|
|---|
| 242 | {
|
|---|
| 243 | if (img == NULL) {offx = offy = 0; return; }
|
|---|
| 244 | if (ox < 0) ox = 0;
|
|---|
| 245 | if (ox >= (img->XSize()-1)) ox = img->XSize()-2;
|
|---|
| 246 | if (oy < 0) oy = 0;
|
|---|
| 247 | if (oy >= (img->YSize()-1)) oy = img->YSize()-2;
|
|---|
| 248 | offx = ox; offy = oy;
|
|---|
| 249 | CenterPave();
|
|---|
| 250 | if (refr) Apply();
|
|---|
| 251 | return;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 | /* --Methode-- */
|
|---|
| 256 | void PIImage::SetPave(int x, int y, bool refr, bool cent)
|
|---|
| 257 | {
|
|---|
| 258 | int xc, yc;
|
|---|
| 259 |
|
|---|
| 260 | if (img == NULL)
|
|---|
| 261 | { offx = offy = 0;
|
|---|
| 262 | xpav = ypav = 0;
|
|---|
| 263 | return; }
|
|---|
| 264 |
|
|---|
| 265 | if ( (x >= (img->XSize()-1)) || ( x < 0) ||
|
|---|
| 266 | (y >= (img->YSize()-1)) || ( y < 0) ) return;
|
|---|
| 267 |
|
|---|
| 268 | if ( (x == xpav) && (y == ypav) ) return;
|
|---|
| 269 | xpav = x; ypav = y;
|
|---|
| 270 |
|
|---|
| 271 | if ( PosImg2W(xpav,ypav,&xc, &yc) || cent) // Il faut recenter l'image
|
|---|
| 272 | { SetOffsetFromPave();
|
|---|
| 273 | if (refr) Apply(true); }
|
|---|
| 274 | else if (refr)
|
|---|
| 275 | { Apply(false); if (curshow) DrawCursor(mWGrC); }
|
|---|
| 276 |
|
|---|
| 277 | return;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 | /* --Methode-- */
|
|---|
| 282 | void PIImage::SetColMap(CMapId cmap, bool refr)
|
|---|
| 283 | {
|
|---|
| 284 | PIPixmap::SetColMap(cmap, refr);
|
|---|
| 285 | if (zow) zow->SetColMap(cmap, refr);
|
|---|
| 286 | if (gvw) gvw->SetColMap(cmap, refr);
|
|---|
| 287 | return;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 | /* --Methode-- */
|
|---|
| 292 | void PIImage::Apply(bool mw)
|
|---|
| 293 | {
|
|---|
| 294 | if (img == NULL) return;
|
|---|
| 295 | if (mw)
|
|---|
| 296 | {
|
|---|
| 297 | ComputePixmap();
|
|---|
| 298 | Send(Msg(), PIMsg_Active);
|
|---|
| 299 | }
|
|---|
| 300 | if (zow != NULL) ComputeZoomPixmap();
|
|---|
| 301 | if (gvw != NULL)
|
|---|
| 302 | if ( (gvw->UserData() != this) || (mw) ) SetGloVPixmap();
|
|---|
| 303 |
|
|---|
| 304 | if (txw || trtlb)
|
|---|
| 305 | {
|
|---|
| 306 | char buff[256];
|
|---|
| 307 | float x,y;
|
|---|
| 308 | img->XYCoord(xpav, ypav, x, y);
|
|---|
| 309 | sprintf(buff,"X= %g , Y= %g PixVal= %g (%d,%d)",
|
|---|
| 310 | x, y , (*img)(xpav, ypav), xpav, ypav );
|
|---|
| 311 | if (txw) txw->SetLabel((string)buff);
|
|---|
| 312 | if (trtlb) trtlb->SetLabel((string)buff);
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | return;
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | /* --Methode-- */
|
|---|
| 319 | void PIImage::Resize()
|
|---|
| 320 | {
|
|---|
| 321 | // printf("PIImage::Resize\n");
|
|---|
| 322 | PIPixmap::Resize();
|
|---|
| 323 | CenterPave();
|
|---|
| 324 | Apply();
|
|---|
| 325 | return;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | /* --Methode-- */
|
|---|
| 329 | void PIImage::Draw(PIGraphic* g, int x0, int y0, int dx, int dy)
|
|---|
| 330 | {
|
|---|
| 331 | PIPixmap::Draw(g, x0, y0, dx, dy);
|
|---|
| 332 | winovis = false; // $CHECK$ Reza A enlever si possible 17/6/96
|
|---|
| 333 | if (curshow)
|
|---|
| 334 | {
|
|---|
| 335 | int xc,yc;
|
|---|
| 336 | PosImg2W(xpav, ypav, &xc, &yc);
|
|---|
| 337 | if ((xc >= x0) && (xc < x0+dx) &&
|
|---|
| 338 | (yc >= y0) && (yc < y0+dy) ) DrawCursor(g, xc, yc);
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | return;
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | /* --Methode-- */
|
|---|
| 345 | void PIImage::But1Press(int x, int y)
|
|---|
| 346 | {
|
|---|
| 347 | int xp, yp;
|
|---|
| 348 |
|
|---|
| 349 | Send(Msg(), PIMsg_Active);
|
|---|
| 350 | if (img == NULL) return;
|
|---|
| 351 | if ( PosW2Img(x, y, &xp, &yp) ) return;
|
|---|
| 352 | SelPointerShape(PI_CrossPointer);
|
|---|
| 353 | xpav = xp; ypav = yp;
|
|---|
| 354 | ShowTrTxW();
|
|---|
| 355 | Apply(false);
|
|---|
| 356 | if (curshow) DrawCursor(mWGrC, -1,-1);
|
|---|
| 357 | return;
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 | /* --Methode-- */
|
|---|
| 362 | void PIImage::Ptr1Move(int x, int y)
|
|---|
| 363 | {
|
|---|
| 364 | int xp, yp;
|
|---|
| 365 | if (img == NULL) return;
|
|---|
| 366 | if ( PosW2Img(x, y, &xp, &yp) ) return;
|
|---|
| 367 | xpav = xp; ypav = yp;
|
|---|
| 368 | Apply(false);
|
|---|
| 369 | return;
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 | /* --Methode-- */
|
|---|
| 374 | void PIImage::But1Release(int /*x*/, int /*y*/)
|
|---|
| 375 | {
|
|---|
| 376 | SelPointerShape(PI_ArrowPointer);
|
|---|
| 377 | if (curshow) DrawCursor(mWGrC);
|
|---|
| 378 | if (trtw) trtw->Hide();
|
|---|
| 379 | return;
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 | /* --Methode-- */
|
|---|
| 384 | void PIImage::But2Press(int x, int y)
|
|---|
| 385 | {
|
|---|
| 386 |
|
|---|
| 387 | Send(Msg(), PIMsg_Active);
|
|---|
| 388 | if (img == NULL) return;
|
|---|
| 389 | if ( PosW2Img(x, y, &xpv0, &ypv0) ) { xmv0 = -1; return; }
|
|---|
| 390 | xmv0 = x; ymv0 = y; dxmv = dymv = 0;
|
|---|
| 391 | if (curshow) DrawCursor(mWGrC,-1,-1);
|
|---|
| 392 | mWGrC->SelGOMode(PI_GOXOR);
|
|---|
| 393 | if (GetColMapId() == CMAP_COLRJ32)
|
|---|
| 394 | mWGrC->SelForeground(PI_Yellow);
|
|---|
| 395 | else mWGrC->SelForeground(PI_Magenta);
|
|---|
| 396 | mWGrC->SelLine(PI_NormalLine);
|
|---|
| 397 | ShowTrTxW();
|
|---|
| 398 | return;
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | /* --Methode-- */
|
|---|
| 402 | void PIImage::Ptr2Move(int x, int y)
|
|---|
| 403 | {
|
|---|
| 404 | int xp, yp;
|
|---|
| 405 | if (img == NULL) return;
|
|---|
| 406 | if (xmv0 < 0) return;
|
|---|
| 407 | if ( PosW2Img(x, y, &xp, &yp) ) return;
|
|---|
| 408 | mWGrC->DrawBox(xmv0, ymv0, dxmv, dymv);
|
|---|
| 409 | dxmv = x-xmv0; dymv = y-ymv0;
|
|---|
| 410 | mWGrC->DrawBox(xmv0, ymv0, dxmv, dymv);
|
|---|
| 411 | if (txw || trtlb)
|
|---|
| 412 | {
|
|---|
| 413 | char buff[256];
|
|---|
| 414 | float x,y;
|
|---|
| 415 | img->XYCoord(xp, yp, x, y);
|
|---|
| 416 | sprintf(buff,"X= %g , Y= %g PixVal= %g (C= %d,%d)",
|
|---|
| 417 | x, y , (*img)(xp, yp), (xp+xpv0)/2, (yp+ypv0)/2 );
|
|---|
| 418 | if (txw) txw->SetLabel((string)buff);
|
|---|
| 419 | if (trtlb) trtlb->SetLabel((string)buff);
|
|---|
| 420 | }
|
|---|
| 421 | return;
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | /* --Methode-- */
|
|---|
| 425 | void PIImage::But2Release(int x, int y)
|
|---|
| 426 | {
|
|---|
| 427 | int xp2, yp2;
|
|---|
| 428 |
|
|---|
| 429 | if (img == NULL) return;
|
|---|
| 430 | if (xmv0 < 0) return;
|
|---|
| 431 | mWGrC->DrawBox(xmv0, ymv0, dxmv, dymv);
|
|---|
| 432 | mWGrC->SelGOMode(PI_GOCopy);
|
|---|
| 433 | mWGrC->SelForeground(PI_White);
|
|---|
| 434 | if ( PosW2Img(x, y, &xp2, &yp2) )
|
|---|
| 435 | PosW2Img(xmv0+dxmv, ymv0+dymv, &xp2, &yp2);
|
|---|
| 436 | xpav = (xpv0+xp2)/2;
|
|---|
| 437 | ypav = (ypv0+yp2)/2;
|
|---|
| 438 | xszpav = ((xp2-xpv0) > 0) ? (xp2-xpv0) : 1;
|
|---|
| 439 | yszpav = ((yp2-ypv0) > 0) ? (yp2-ypv0) : 1;
|
|---|
| 440 |
|
|---|
| 441 | Apply(false);
|
|---|
| 442 | if (curshow) DrawCursor(mWGrC);
|
|---|
| 443 | if (trtw) trtw->Hide();
|
|---|
| 444 | return;
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 | /* --Methode-- */
|
|---|
| 449 | void PIImage::But3Press(int x, int y)
|
|---|
| 450 | {
|
|---|
| 451 | int xp, yp;
|
|---|
| 452 |
|
|---|
| 453 | Send(Msg(), PIMsg_Active);
|
|---|
| 454 | if (img == NULL) return;
|
|---|
| 455 | if ( PosW2Img(x, y, &xp, &yp) ) { xmv0 = -1; return; }
|
|---|
| 456 | if (curshow) DrawCursor(mWGrC,-1,-1);
|
|---|
| 457 | ShowTrTxW();
|
|---|
| 458 | SelPointerShape(PI_TDLRArrowPointer);
|
|---|
| 459 | xmv0 = xp;
|
|---|
| 460 | ymv0 = yp;
|
|---|
| 461 | return;
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 | /* --Methode-- */
|
|---|
| 466 | void PIImage::Ptr3Move(int x, int y)
|
|---|
| 467 | {
|
|---|
| 468 | int xp, yp;
|
|---|
| 469 | if (img == NULL) return;
|
|---|
| 470 | if (xmv0 < 0) return;
|
|---|
| 471 | if ( PosW2Img(x, y, &xp, &yp) ) return;
|
|---|
| 472 | if (txw || trtlb)
|
|---|
| 473 | {
|
|---|
| 474 | char buff[256];
|
|---|
| 475 | sprintf(buff,"DelX= %d , DelY= %d ", xp-xmv0, yp-ymv0);
|
|---|
| 476 | if (txw) txw->SetLabel((string)buff);
|
|---|
| 477 | if (trtlb) trtlb->SetLabel((string)buff);
|
|---|
| 478 | }
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | /* --Methode-- */
|
|---|
| 482 | void PIImage::But3Release(int x, int y)
|
|---|
| 483 | {
|
|---|
| 484 | int xp, yp;
|
|---|
| 485 |
|
|---|
| 486 | SelPointerShape(PI_ArrowPointer);
|
|---|
| 487 | if (trtw) trtw->Hide();
|
|---|
| 488 | if (img == NULL) return;
|
|---|
| 489 | if (xmv0 < 0) return;
|
|---|
| 490 | if ( PosW2Img(x, y, &xp, &yp) ) return;
|
|---|
| 491 |
|
|---|
| 492 | offx -= (xp-xmv0);
|
|---|
| 493 | offy -= (yp-ymv0);
|
|---|
| 494 |
|
|---|
| 495 | if (offx < 0) offx = 0;
|
|---|
| 496 | if (offy < 0) offy = 0;
|
|---|
| 497 | if (offx >= img->XSize()) offx = img->XSize();
|
|---|
| 498 | if (offy >= img->YSize()) offy = img->YSize();
|
|---|
| 499 | xpav = xmv0; ypav = ymv0;
|
|---|
| 500 | xmv0 = ymv0 = -1;
|
|---|
| 501 | Apply();
|
|---|
| 502 | return;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 | /* --Methode-- */
|
|---|
| 507 | void PIImage::ComputePixmap()
|
|---|
| 508 | {
|
|---|
| 509 | unsigned int xwsz, ywsz;
|
|---|
| 510 |
|
|---|
| 511 | if (img == NULL) return;
|
|---|
| 512 | xwsz = this->XSize();
|
|---|
| 513 | ywsz = this->YSize();
|
|---|
| 514 |
|
|---|
| 515 | pixm = img->ComputePixmap(lut, offx, offy, zoom, xwsz, ywsz, pixm, &xspxm, &yspxm);
|
|---|
| 516 | SetPixmap(pixm, xspxm, yspxm);
|
|---|
| 517 | // Refresh();
|
|---|
| 518 | return;
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 | /* --Methode-- */
|
|---|
| 523 | void PIImage::ComputeZoomPixmap()
|
|---|
| 524 | {
|
|---|
| 525 | unsigned int xwsz, ywsz;
|
|---|
| 526 | int ofx, ofy;
|
|---|
| 527 | int zm;
|
|---|
| 528 |
|
|---|
| 529 | if (zow == NULL) return;
|
|---|
| 530 | if (img == NULL) return;
|
|---|
| 531 |
|
|---|
| 532 | xwsz = zow->XSize();
|
|---|
| 533 | ywsz = zow->YSize();
|
|---|
| 534 |
|
|---|
| 535 | zm = zoom+4;
|
|---|
| 536 | if ( (zm==-1) || (zm == 0) ) zm = 1;
|
|---|
| 537 | if (zm > 0)
|
|---|
| 538 | {
|
|---|
| 539 | ofx = xpav-(xwsz/2/zm);
|
|---|
| 540 | ofy = ypav-(ywsz/2/zm);
|
|---|
| 541 | }
|
|---|
| 542 | else
|
|---|
| 543 | {
|
|---|
| 544 | ofx = xpav+(xwsz*zm/2);
|
|---|
| 545 | ofy = ypav+(ywsz*zm/2);
|
|---|
| 546 | }
|
|---|
| 547 | if (ofx < 0) ofx = 0;
|
|---|
| 548 | if (ofy < 0) ofy = 0;
|
|---|
| 549 |
|
|---|
| 550 | zpixm = img->ComputePixmap(lut, ofx, ofy, zm, xwsz, ywsz, zpixm, &xszpxm, &yszpxm);
|
|---|
| 551 | zow->SetColMap(GetColMapId(), false);
|
|---|
| 552 | zow->SetPixmap(zpixm, xszpxm, yszpxm);
|
|---|
| 553 | zow->SetUserData((void *)this, 0);
|
|---|
| 554 | // zow->Refresh();
|
|---|
| 555 | return;
|
|---|
| 556 |
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 | /* --Methode-- */
|
|---|
| 561 | void PIImage::ComputeGloVPixmap()
|
|---|
| 562 | {
|
|---|
| 563 | unsigned int xwsz, ywsz;
|
|---|
| 564 | int zmx,zmy;
|
|---|
| 565 |
|
|---|
| 566 | if (gvw == NULL) return;
|
|---|
| 567 | if (img == NULL) return;
|
|---|
| 568 |
|
|---|
| 569 | xwsz = gvw->XSize();
|
|---|
| 570 | ywsz = gvw->YSize();
|
|---|
| 571 |
|
|---|
| 572 | zmx = img->XSize()/xwsz;
|
|---|
| 573 | zmy = img->YSize()/ywsz;
|
|---|
| 574 |
|
|---|
| 575 | if (zmx < zmy) zmx = zmy;
|
|---|
| 576 | if (zmx < 1) zmx = 1;
|
|---|
| 577 | zmgv = zmx;
|
|---|
| 578 | if (zmx > 1) zmx = -zmx;
|
|---|
| 579 | gpixm = img->ComputePixmap(lut, 0, 0, zmx, xwsz, ywsz, gpixm, &xsgpxm, &ysgpxm);
|
|---|
| 580 | printf("DEBUG-ComputeGloVPixmap() %d-%d , (%d,%d) , %d-%d \n", xwsz, ywsz, zmx, zmy, xsgpxm, ysgpxm);
|
|---|
| 581 | return;
|
|---|
| 582 | }
|
|---|
| 583 |
|
|---|
| 584 | /* --Methode-- */
|
|---|
| 585 | void PIImage::SetGloVPixmap()
|
|---|
| 586 | {
|
|---|
| 587 | float zm;
|
|---|
| 588 | int x,y, dx,dy;
|
|---|
| 589 |
|
|---|
| 590 | if (zoom > 0) zm = zmgv*zoom;
|
|---|
| 591 | else zm = (float)zmgv/(float)(-zoom);
|
|---|
| 592 | x = offx/zmgv+1;
|
|---|
| 593 | y = offy/zmgv+1;
|
|---|
| 594 | dx = (int) ( (float)XSize()/zm-1. );
|
|---|
| 595 | dy = (int) ( (float)YSize()/zm-1. );
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 | gvw->ElDelAll();
|
|---|
| 599 | gvw->WindowGraphic()->SelForeground(PI_Yellow);
|
|---|
| 600 | gvw->WindowGraphic()->SelLine(PI_NormalLine);
|
|---|
| 601 | gvw->ElAddRect(x,y,dx,dy);
|
|---|
| 602 | gvw->SetColMap(GetColMapId(), false);
|
|---|
| 603 | gvw->SetPixmap(gpixm, xsgpxm, ysgpxm);
|
|---|
| 604 | gvw->SetUserData((void *)this, 0);
|
|---|
| 605 | gvw->SetMsg(Msg()+626);
|
|---|
| 606 | gvw->SetMsgParent(this);
|
|---|
| 607 |
|
|---|
| 608 | return;
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | /* --Methode-- */
|
|---|
| 612 | void PIImage::DrawCursor(PIGraphicGen* g)
|
|---|
| 613 | {
|
|---|
| 614 | int xc, yc;
|
|---|
| 615 | if (PosImg2W(xpav, ypav, &xc, &yc)) DrawCursor(g, -1, -1);
|
|---|
| 616 | else DrawCursor(g, xc, yc);
|
|---|
| 617 | return;
|
|---|
| 618 | }
|
|---|
| 619 |
|
|---|
| 620 | #define CURSHSIZE 25
|
|---|
| 621 |
|
|---|
| 622 | /* --Methode-- */
|
|---|
| 623 | void PIImage::DrawCursor(PIGraphicGen* g, int xc, int yc)
|
|---|
| 624 | {
|
|---|
| 625 |
|
|---|
| 626 | if ((xcurs>=0) && (ycurs>=0))
|
|---|
| 627 | PIPixmap::Draw(g, xcurs-CURSHSIZE, ycurs-CURSHSIZE, CURSHSIZE*2, CURSHSIZE*2);
|
|---|
| 628 |
|
|---|
| 629 | if ((xc >= 0) && (yc >= 0))
|
|---|
| 630 | {
|
|---|
| 631 | xcurs = xc; ycurs = yc;
|
|---|
| 632 | if (winovis) return; // $CHECK$ Reza A enlever si possible 17/6/96
|
|---|
| 633 | if (zoom < 3) g->SelLine(PI_NormalLine);
|
|---|
| 634 | else g->SelLine(PI_ThickLine);
|
|---|
| 635 | if ( (GetColMapId() == CMAP_GREY32) || (GetColMapId() == CMAP_GREYINV32) )
|
|---|
| 636 | g->SelForeground(PI_Red);
|
|---|
| 637 | else g->SelForeground(PI_White);
|
|---|
| 638 | g->SelGOMode(PI_GOCopy);
|
|---|
| 639 | g->DrawLine(xcurs-CURSHSIZE, ycurs, xcurs-4, ycurs);
|
|---|
| 640 | g->DrawLine(xcurs+4, ycurs, xcurs+CURSHSIZE, ycurs);
|
|---|
| 641 | g->DrawLine(xcurs, ycurs-CURSHSIZE, xcurs, ycurs-4);
|
|---|
| 642 | g->DrawLine(xcurs, ycurs+4, xcurs, ycurs+CURSHSIZE);
|
|---|
| 643 | }
|
|---|
| 644 | else { xcurs = ycurs = -1; }
|
|---|
| 645 |
|
|---|
| 646 | return;
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 | /* --Methode-- */
|
|---|
| 651 | void PIImage::ShowTrTxW()
|
|---|
| 652 | {
|
|---|
| 653 | if (trtw)
|
|---|
| 654 | {
|
|---|
| 655 | int tpx, tpy;
|
|---|
| 656 | GetScreenPos(tpx, tpy);
|
|---|
| 657 | tpy -= (trtw->YSize()+5);
|
|---|
| 658 | if (tpy < 0) tpy = 0;
|
|---|
| 659 | trtw->SetPos(tpx, tpy);
|
|---|
| 660 | trtw->Show();
|
|---|
| 661 | }
|
|---|
| 662 |
|
|---|
| 663 | return;
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | /* --Methode-- */
|
|---|
| 667 | int PIImage::PosW2Img(int xiw, int yiw, int * xp, int * yp)
|
|---|
| 668 | {
|
|---|
| 669 |
|
|---|
| 670 | if (zoom > 0)
|
|---|
| 671 | {
|
|---|
| 672 | *xp = xiw/zoom+offx;
|
|---|
| 673 | *yp = yiw/zoom+offy;
|
|---|
| 674 | }
|
|---|
| 675 | else
|
|---|
| 676 | {
|
|---|
| 677 | *xp = offx-xiw*zoom;
|
|---|
| 678 | *yp = offy-yiw*zoom;
|
|---|
| 679 | }
|
|---|
| 680 |
|
|---|
| 681 | if ( (*xp >= 0) && (*xp < img->XSize() ) &&
|
|---|
| 682 | (*yp >= 0) && (*yp < img->YSize() ) ) return(0);
|
|---|
| 683 | else return(1);
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 |
|
|---|
| 687 | /* --Methode-- */
|
|---|
| 688 | int PIImage::PosImg2W(int xp, int yp, int * xiw, int * yiw)
|
|---|
| 689 | {
|
|---|
| 690 | if (zoom > 0)
|
|---|
| 691 | {
|
|---|
| 692 | *xiw = (xp-offx)*zoom+(zoom/2);
|
|---|
| 693 | *yiw = (yp-offy)*zoom+(zoom/2);
|
|---|
| 694 | }
|
|---|
| 695 | else
|
|---|
| 696 | {
|
|---|
| 697 | *xiw = (offx-xp)/zoom;
|
|---|
| 698 | *yiw = (offy-yp)/zoom;
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | if (*xiw > XSize()) *xiw = -1;
|
|---|
| 702 | if (*yiw > YSize()) *yiw = -1;
|
|---|
| 703 |
|
|---|
| 704 | if ((*xiw < 0) || (*yiw < 0)) return(1);
|
|---|
| 705 | else return(0);
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 | /* --Methode-- */
|
|---|
| 710 | void PIImage::SetOffsetFromPave()
|
|---|
| 711 | {
|
|---|
| 712 | if (zoom > 0)
|
|---|
| 713 | {
|
|---|
| 714 | offx = xpav-XSize()/2/zoom;
|
|---|
| 715 | offy = ypav-YSize()/2/zoom;
|
|---|
| 716 | }
|
|---|
| 717 | else
|
|---|
| 718 | {
|
|---|
| 719 | offx = xpav+XSize()/2*zoom;
|
|---|
| 720 | offy = ypav+YSize()/2*zoom;
|
|---|
| 721 | }
|
|---|
| 722 |
|
|---|
| 723 | if (offx < 0) offx = 0;
|
|---|
| 724 | if (offx >= (img->XSize()-1)) offx = img->XSize()-2;
|
|---|
| 725 | if (offy < 0) offy = 0;
|
|---|
| 726 | if (offy >= (img->YSize()-1)) offy = img->YSize()-2;
|
|---|
| 727 |
|
|---|
| 728 | return;
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| 731 | /* --Methode-- */
|
|---|
| 732 | void PIImage::CenterPave()
|
|---|
| 733 | {
|
|---|
| 734 | int xwsz, ywsz;
|
|---|
| 735 |
|
|---|
| 736 | if (zoom > 0)
|
|---|
| 737 | { xwsz = XSize()/zoom;
|
|---|
| 738 | ywsz = YSize()/zoom; }
|
|---|
| 739 | else
|
|---|
| 740 | { xwsz = -(XSize()*zoom);
|
|---|
| 741 | ywsz = -(YSize()*zoom); }
|
|---|
| 742 |
|
|---|
| 743 | if (xwsz > (img->XSize()-offx)) xwsz = (img->XSize()-offx);
|
|---|
| 744 | if (ywsz > (img->YSize()-offy)) ywsz = (img->YSize()-offy);
|
|---|
| 745 | xpav = offx+xwsz/2;
|
|---|
| 746 | ypav = offx+ywsz/2;
|
|---|
| 747 | xszpav = ((xwsz+ywsz)/20) ;
|
|---|
| 748 | if (xszpav < 1) xszpav = 1;
|
|---|
| 749 | yszpav = xszpav;
|
|---|
| 750 |
|
|---|
| 751 | return;
|
|---|
| 752 | }
|
|---|