Changeset 4081 for trunk/MagicSoft/Mars/mbase/MGMap.cc
- Timestamp:
- 05/15/04 20:05:18 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MGMap.cc
r4078 r4081 217 217 // Convert root colors to arbitrary bitmap coordinates 218 218 // 219 Int_t MGMap::Color(int col)219 UChar_t MGMap::Color(int col) 220 220 { 221 221 switch (col) … … 234 234 // -------------------------------------------------------------------------- 235 235 // 236 // Draw a line into the buffer (size w*h) from (x1, y1) to (x2, y2) with 237 // the color col and the line style style (default: solid) 238 // 239 void MGMap::DrawLine(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style) 240 { 241 const Int_t step = style==kSolid?1:3; 242 const Double_t len = TMath::Hypot(x2-x1, y2-y1); 243 const Double_t dx = (x2-x1)/len*step; 244 const Double_t dy = (y2-y1)/len*step; 245 246 Double_t x = x1; 247 Double_t y = y1; 248 249 for (int i=0; i<len; i+=step) 250 { 251 x+= dx; 252 y+= dy; 253 254 const Int_t iy = (int)rint(y); 255 if (iy<0 || iy>=h) 256 continue; 257 258 const Int_t ix = (int)rint(x); 259 if (ix<0 || ix>=w) 260 continue; 261 262 buf[ix+iy*w] = col; 263 } 264 } 265 266 // -------------------------------------------------------------------------- 267 // 268 // Draw a box into the buffer (size w*h) from (x1, y1) to (x2, y2) with 269 // the color col and the line style style (default: solid) 270 // 271 void MGMap::DrawBox(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style) 272 { 273 DrawLine(buf, w, h, x1, y1, x2, y1, col, style); 274 DrawLine(buf, w, h, x1, y2, x2, y1, col, style); 275 DrawLine(buf, w, h, x1, y1, x1, y2, col, style); 276 DrawLine(buf, w, h, x2, y1, x2, y2, col, style); 277 } 278 279 // -------------------------------------------------------------------------- 280 // 281 // Draw a circle into the buffer (size w*h) around (x, y) with radius r and 282 // the color col. 283 // 284 void MGMap::DrawCircle(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col) 285 { 286 const Int_t n = (int)rint(sqrt(2.)*r*TMath::Pi()/2); 287 for (int i=0; i<n-1; i++) 288 { 289 const Double_t angle = TMath::TwoPi()*i/n; 290 291 const Double_t dx = r*cos(angle); 292 const Double_t dy = r*sin(angle); 293 294 const Int_t x1 = (int)rint(x+dx); 295 const Int_t x2 = (int)rint(x-dx); 296 297 const Int_t y1 = (int)rint(y+dy); 298 if (y1>=0 && y1<h) 299 { 300 if (x1>=0 && x1<w) 301 buf[x1+y1*w] = col; 302 303 if (x2>=0 && x2<w) 304 buf[x2+y1*w] = col; 305 } 306 307 const Int_t y2 = (int)rint(y-dy); 308 if (y2>=0 && y2<h) 309 { 310 if (x1>=0 && x1<w) 311 buf[x1+y2*w] = col; 312 313 if (x2>=0 && x2<w) 314 buf[x2+y2*w] = col; 315 } 316 } 317 } 318 319 // -------------------------------------------------------------------------- 320 // 321 // Draw a dot into the buffer (size w*h) at (x, y) with color col. 322 // 323 void MGMap::DrawDot(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, UChar_t col) 324 { 325 const Int_t x1 = (int)rint(cx); 326 const Int_t y1 = (int)rint(cy); 327 328 if (x1>=0 && y1>=0 && x1<w && y1<h) 329 buf[x1+y1*w] = col; 330 } 331 332 // -------------------------------------------------------------------------- 333 // 236 334 // Draw a line into the buffer. The TObject must be a TLine. 237 335 // Currently only solid and non sloid line are supported. 238 336 // 239 void MGMap::DrawLine(TObject *o, unsigned char*buf, int w, int h, Double_t scale)337 void MGMap::DrawLine(TObject *o, UChar_t *buf, int w, int h, Double_t scale) 240 338 { 241 339 TLine *l = dynamic_cast<TLine*>(o); … … 243 341 return; 244 342 245 Double_t x1 = 0.5*w-(l->GetX1()/scale); 246 Double_t x2 = 0.5*w-(l->GetX2()/scale); 247 Double_t y1 = 0.5*h-(l->GetY1()/scale); 248 Double_t y2 = 0.5*h-(l->GetY2()/scale); 249 250 Double_t len = TMath::Hypot(x2-x1, y2-y1); 251 252 Double_t x = x1; 253 Double_t y = y1; 254 255 Int_t step = l->GetLineStyle()==kSolid?1:3; 256 257 Double_t dx = (x2-x1)/len*step; 258 Double_t dy = (y2-y1)/len*step; 259 260 for (int i=0; i<len; i+=step) 261 { 262 x+= dx; 263 y+= dy; 264 265 if (x<0 || y<0 || x>w-1 || y>h-1) 266 continue; 267 268 buf[(int)x+(int)y*w] = Color(l->GetLineColor()); 269 } 343 const Double_t x1 = 0.5*w-(l->GetX1()/scale); 344 const Double_t x2 = 0.5*w-(l->GetX2()/scale); 345 const Double_t y1 = 0.5*h-(l->GetY1()/scale); 346 const Double_t y2 = 0.5*h-(l->GetY2()/scale); 347 348 const Int_t col = Color(l->GetLineColor()); 349 DrawLine(buf, w, h, x1, y1, x2, y2, col, l->GetLineStyle()); 350 } 351 352 void MGMap::DrawMultiply(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col) 353 { 354 DrawLine(buf, w, h, cx-size, cy-size, cx+size, cy+size, col); 355 DrawLine(buf, w, h, cx+size, cy-size, cx-size, cy+size, col); 356 } 357 358 void MGMap::DrawCross(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col) 359 { 360 DrawLine(buf, w, h, cx-size, cy, cx+size, cy, col); 361 DrawLine(buf, w, h, cx, cy-size, cx, cy+size, col); 270 362 } 271 363 … … 275 367 // Currently kCircle, kMultiply and KDot are supported. 276 368 // 277 void MGMap::DrawMarker(TObject *o, unsigned char*buf, int w, int h, Double_t scale)369 void MGMap::DrawMarker(TObject *o, UChar_t *buf, int w, int h, Double_t scale) 278 370 { 279 371 TMarker *m = dynamic_cast<TMarker*>(o); … … 289 381 { 290 382 case kCircle: 291 { 292 Int_t step = 32; 293 294 const Float_t l = (m->GetMarkerSize()*2)+1; 295 for (int i=0; i<step; i++) 296 { 297 const Double_t angle = i*TMath::TwoPi()/step; 298 299 const Double_t x1 = x+l*cos(angle); 300 const Double_t y1 = y+l*sin(angle); 301 302 if (x1<0 || y1<0 || x1>w-1 || y1>h-1) 303 continue; 304 305 buf[(int)x1+(int)y1*w] = col; 306 } 307 } 383 DrawCircle(buf, w, h, x, y, m->GetMarkerSize()*2+1, col); 308 384 break; 309 385 case kDot: 310 if (x>=0 && y>=0 && x<w && y<h) 311 buf[(int)x+(int)y*w] = col; 312 break; 313 386 DrawDot(buf, w, h, x, y, col); 387 break; 314 388 case kMultiply: 315 { 316 const Int_t l = (int)(m->GetMarkerSize()+1); 317 318 for (int i=-l; i<l+1; i++) 319 { 320 Double_t x1 = x+i; 321 Double_t y1 = y+i; 322 if (x1>=0 && y>=0 && x1<w && y<h) 323 buf[(int)x1+(int)y*w] = col; 324 if (x>=0 && y1>=0 && x<w && y1<h) 325 buf[(int)x+(int)y1*w] = col; 326 } 327 } 328 break; 329 389 DrawMultiply(buf, w, h, x, y, m->GetMarkerSize()*2+1, col); 390 break; 391 case kCross: 392 DrawCross(buf, w, h, x, y, m->GetMarkerSize()*2+1, col); 393 break; 330 394 } 331 395 } … … 345 409 // -------------------------------------------------------------------------- 346 410 // 347 // Paint all objects into a buffer of w*h unsigned chars. The scale411 // Paint all objects into a buffer of w*h UChar_ts. The scale 348 412 // gives you the conversio factor to convert pad coordinates into 349 413 // buffer pixels - it is the distance from the center of the buffer 350 414 // to one of its edges. 351 415 // 352 void MGMap::Paint( unsigned char*buf, int w, int h, Float_t scale)416 void MGMap::Paint(UChar_t *buf, int w, int h, Float_t scale) 353 417 { 354 418 scale /= TMath::Hypot((float)w, (float)h)/2;
Note:
See TracChangeset
for help on using the changeset viewer.