Changeset 821 for soft/giet_vm/applications/rosenfeld/src/ecc_features.c
- Timestamp:
- May 6, 2016, 3:06:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src/ecc_features.c
r798 r821 10 10 // Caracteristiques d'une region / label 11 11 12 //#pragma message("------------------")13 //#pragma message("--- Features.c ---")14 //#pragma message("------------------")15 16 12 #include <stdio.h> 17 13 #include <stddef.h> 18 14 #include <stdlib.h> 19 15 #include <malloc.h> 20 21 22 #ifdef CLI 16 #include <string.h> 17 18 23 19 #include "nrc_os_config.h" 20 #include "config.h" 24 21 #include "nrc.h" 25 #endif26 27 22 28 23 … … 31 26 #include <sys/stat.h> 32 27 #include <fcntl.h> 28 #include <unistd.h> 33 29 #endif 34 30 35 31 36 #ifdef OPENMP37 #include <omp.h>38 #endif39 40 32 #include "ecc_features.h" 41 //#include "label.h" 33 34 #define BUFF_SIZE 1024 // for snprintf 35 36 37 // ------------------------------------------------------------- 38 void RegionStats_Constructor(RegionStats ** Stats, uint32 nemax) 39 // ------------------------------------------------------------- 40 { 41 *Stats = RegionStats_pConstructor(nemax); 42 } 43 44 45 // ------------------------------------------------- 46 RegionStats * RegionStats_pConstructor(uint32 nemax) 47 // ------------------------------------------------- 48 { 49 RegionStats * Stats; 50 51 Stats = (RegionStats *) malloc((nemax) * sizeof(RegionStats)); 52 if (Stats == NULL) { 53 nrerror("allocation failed in RegionStats_pConstructor"); 54 } 55 56 RegionStats_Clear(Stats, nemax); 57 58 return Stats; 59 } 60 42 61 43 62 // ------------------------------------------------------------ 44 void RegionStats_ Constructor(RegionStats **Stats, uint32 nemax)63 void RegionStats_Destructor(RegionStats ** Stats, uint32 nemax) 45 64 // ------------------------------------------------------------ 46 65 { 47 *Stats = RegionStats_pConstructor(nemax);48 }49 // ------------------------------------------------50 RegionStats* RegionStats_pConstructor(uint32 nemax)51 // ------------------------------------------------52 {53 RegionStats *Stats;54 55 Stats = (RegionStats*) malloc((nemax)*sizeof(RegionStats));56 if(Stats == NULL) nrerror("allocation failed in RegionStats_pConstructor");57 58 RegionStats_Clear(Stats, nemax);59 60 return Stats;61 }62 // -----------------------------------------------------------63 void RegionStats_Destructor(RegionStats **Stats, uint32 nemax)64 // -----------------------------------------------------------65 {66 66 RegionStats_pDestructor(*Stats, nemax); 67 67 } 68 // ----------------------------------------------------------- 69 void RegionStats_pDestructor(RegionStats *Stats, uint32 nemax) 70 // ----------------------------------------------------------- 68 69 70 // ------------------------------------------------------------ 71 void RegionStats_pDestructor(RegionStats * Stats, uint32 nemax) 72 // ------------------------------------------------------------ 71 73 { 72 74 RegionStats_Clear(Stats, nemax); 73 75 free(Stats); 74 76 } 75 // ----------------------------------------------------- 76 void RegionStats_Clear(RegionStats *Stats, uint32 nemax) 77 // ----------------------------------------------------- 78 { 79 int i; 80 for (i = 0; i < (int) nemax; i++) { 77 78 79 // ------------------------------------------------------ 80 void RegionStats_Clear(RegionStats * Stats, uint32 nemax) 81 // ------------------------------------------------------ 82 { 83 for (int i = 0; i < (int) nemax; i++) { 81 84 Stats[i].xmin = 65535; 82 85 Stats[i].xmax = 0; … … 86 89 Stats[i].S = 0; 87 90 88 Stats[i].x = 0;89 Stats[i].y = 0;90 91 91 Stats[i].Sx = 0; 92 92 Stats[i].Sy = 0; 93 94 #ifdef REGION_STATS2 95 Stats[i].Sx2 = 0; 96 Stats[i].Sxy = 0; 97 Stats[i].Sy2 = 0; 93 #if PARMERGE 94 pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE); 98 95 #endif 99 96 } 100 97 } 101 // ---------------------------------------- 102 void RegionStats_Clear1(RegionStats *stats) 103 // ---------------------------------------- 98 99 100 // ----------------------------------------- 101 void RegionStats_Clear1(RegionStats * stats) 102 // ----------------------------------------- 104 103 { 105 104 stats->xmin = 0; … … 110 109 stats->S = 0; 111 110 112 stats->x = 0;113 stats->y = 0;114 115 111 stats->Sx = 0; 116 112 stats->Sy = 0; 117 #ifdef REGION_STATS2 118 stats->Sx2 = 0; 119 stats->Sxy = 0; 120 stats->Sy2 = 0; 121 #endif 122 } 123 // ------------------------------------------ 124 int RegionStats_Create_File(char *filename) 125 // ------------------------------------------ 113 } 114 115 116 // ----------------------------------------- 117 int RegionStats_Create_File(char * filename) 118 // ----------------------------------------- 126 119 { 127 120 int fd; … … 130 123 if (fd < 0) { 131 124 printf("RegionStats_Open_File : can't create file %s\n", filename); 132 giet_pthread_exit("");125 exit(1); 133 126 } 134 127 return fd; 135 128 } 136 // ---------------------------------------- 137 int RegionStats_Open_File(char *filename) 138 // ---------------------------------------- 129 130 131 // --------------------------------------- 132 int RegionStats_Open_File(char * filename) 133 // --------------------------------------- 139 134 { 140 135 int fd; … … 143 138 if (fd < 0) { 144 139 printf("RegionStats_Open_File : can't open file %s\n", filename); 145 giet_pthread_exit("");140 exit(1); 146 141 } 147 142 return fd; 148 143 } 149 // --------------------------------- 144 145 146 // -------------------------------- 150 147 void RegionStats_Close_File(int fd) 151 // -------------------------------- -148 // -------------------------------- 152 149 { 153 150 close(fd); 154 151 } 155 // --------------------------------- 152 153 154 #if 0 // pb : fscanf requires manipulating FILE * 155 // -------------------------------- 156 156 int RegionStats_Read_Header(int fd) 157 // -------------------------------- -157 // -------------------------------- 158 158 { 159 159 int ne = 0; 160 // @QM giet161 160 fscanf(fd, "%d", &ne); 162 161 return ne; 163 162 } 164 // ------------------------------------------- 163 #endif 164 165 166 // ------------------------------------------ 165 167 void RegionStats_Write_Header(int ne, int fd) 166 // ------------------------------------------- 167 { 168 fprintf(fd, "%d\n", ne); 169 } 168 // ------------------------------------------ 169 { 170 char buff[BUFF_SIZE]; 171 snprintf(buff, BUFF_SIZE, "%d\n", ne); 172 write(fd, buff, strlen(buff) + 1); 173 } 174 175 176 #if 0 170 177 // -------------------------------------------------------------- 171 void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats)178 void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats) 172 179 // -------------------------------------------------------------- 173 180 { … … 184 191 &(Stats[i].Sx), 185 192 &(Stats[i].Sy)); 186 187 Stats[i].x = Stats[i].Sx / Stats[i].S; 188 Stats[i].y = Stats[i].Sy / Stats[i].S; 189 190 } 191 } 192 // -------------------------------------------------------------- 193 void RegionStats_Read_Stats2(int fd, int ne, RegionStats *Stats) 194 // -------------------------------------------------------------- 195 { 196 #ifdef REGION_STATS2 197 int i, t; 198 199 int32 Sx2, Sxy, Sy2; 200 201 for (i = 1; i <= ne; i++) { 202 fscanf(f, "%d%d%d%d%d%d%d%d%d%d%d\n", 203 &t, 204 &(Stats[i].xmin), 205 &(Stats[i].xmax), 206 &(Stats[i].ymin), 207 &(Stats[i].ymax), 208 &(Stats[i].S), 209 &(Stats[i].Sx), 210 &(Stats[i].Sy), 211 &(Sx2), 212 &(Sxy), 213 &(Sy2)); 214 215 Stats[i].Sx2 = Sx2; 216 Stats[i].Sxy = Sxy; 217 Stats[i].Sy2 = Sy2; 218 219 Stats[i].x = Stats[i].Sx / Stats[i].S; 220 Stats[i].y = Stats[i].Sy / Stats[i].S; 221 } 222 #else 223 nrerror("RegionStats_Read_Stats2 REGION_STAT2 not defined"); 193 } 194 } 224 195 #endif 225 } 196 197 226 198 // --------------------------------------------------------------- 227 void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd)199 void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd) 228 200 // --------------------------------------------------------------- 229 201 { 230 int i;231 232 for (i = 1; i <= ne; i++) {233 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",202 char buff[BUFF_SIZE]; 203 204 for (int i = 1; i <= ne; i++) { 205 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 234 206 i, 235 207 Stats[i].xmin, … … 241 213 Stats[i].Sx, 242 214 Stats[i].Sy); 243 } 244 } 245 // -------------------------------------------------------------------------------------------------- 246 void RegionStats_Write_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, int fd) 247 // -------------------------------------------------------------------------------------------------- 215 write(fd, buff, strlen(buff) + 1); 216 } 217 } 218 219 220 // --------------------------------------------------------------------------------------------------- 221 void RegionStats_Write_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, int fd) 222 // --------------------------------------------------------------------------------------------------- 248 223 { 249 224 uint32 e; 225 char buff[BUFF_SIZE]; 250 226 251 227 for (e = ne0; e <= ne1; e++) { 252 228 if ((e == EQ[e]) && (Stats[e].S > 0)) { 253 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",229 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 254 230 e, 255 231 Stats[e].xmin, … … 261 237 Stats[e].Sx, 262 238 Stats[e].Sy); 263 } 264 } 265 } 266 // --------------------------------------------------------------- 267 void RegionStats_Write_Stats2(RegionStats *Stats, int ne, int fd) 268 // --------------------------------------------------------------- 269 { 270 #ifdef REGION_STATS2 271 int i; 272 for (i = 1; i <= ne; i++) { 273 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 274 i, 275 Stats[i].xmin, 276 Stats[i].xmax, 277 Stats[i].ymin, 278 Stats[i].ymax, 279 280 Stats[i].S, 281 Stats[i].Sx, 282 Stats[i].Sy, 283 284 (int32) Stats[i].Sx2, 285 (int32) Stats[i].Sxy, 286 (int32) Stats[i].Sy2); 287 } 288 #else 289 nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined"); 290 #endif 291 } 239 write(fd, buff, strlen(buff) + 1); 240 } 241 } 242 } 243 244 292 245 // ----------------------------------------------------------------- 293 void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd)246 void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd) 294 247 // ----------------------------------------------------------------- 295 248 { 296 int i;297 298 for (i = 1; i <= ne; i++) {299 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",249 char buff[BUFF_SIZE]; 250 251 for (int i = 1; i <= ne; i++) { 252 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 300 253 i, 301 254 Stats[i]->xmin, … … 306 259 Stats[i]->Sx, 307 260 Stats[i]->Sy); 308 } 309 } 310 // ----------------------------------------------------------------- 311 void RegionStats_Write_pStats2(RegionStats **Stats, int ne, int fd) 312 // ----------------------------------------------------------------- 313 { 314 #ifdef REGION_STATS2 315 int i; 316 for (i = 1; i <= ne; i++) { 317 fprintf(fd, "%3d %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 318 i, 319 Stats[i]->xmin, 320 Stats[i]->xmax, 321 Stats[i]->ymin, 322 Stats[i]->ymax, 323 Stats[i]->S, 324 Stats[i]->Sx, 325 Stats[i]->Sy, 326 327 (int32) Stats[i]->Sx2, 328 (int32) Stats[i]->Sxy, 329 (int32) Stats[i]->Sy2); 330 } 331 #else 332 nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined"); 333 #endif 334 } 335 // ----------------------------------------------------------------------- 336 void RegionStats_Load_Stats1(char *filename, int *ne, RegionStats **Stats) 337 // ----------------------------------------------------------------------- 261 write(fd, buff, strlen(buff) + 1); 262 } 263 } 264 265 266 #if 0 267 // -------------------------------------------------------------------------- 268 void RegionStats_Load_Stats1(char * filename, int * ne, RegionStats ** Stats) 269 // -------------------------------------------------------------------------- 338 270 { 339 271 int fd; … … 347 279 RegionStats_Close_File(fd); 348 280 } 349 // ----------------------------------------------------------------------- 350 void RegionStats_Load_Stats2(char *filename, int *ne, RegionStats **Stats) 351 // ----------------------------------------------------------------------- 352 { 353 #ifdef REGION_STATS2 354 int fd; 355 356 fd = RegionStats_Open_File(filename); 357 358 *ne = RegionStats_Read_Header(fd); 359 360 RegionStats_Constructor(Stats, *ne); 361 RegionStats_Read_Stats2(fd, *ne, *Stats); 362 RegionStats_Close_File(fd); 363 #else 364 nrerror("RegionStats_Load_Stats2 : REGION_STATS2 not defined"); 365 #endif 366 } 367 // ----------------------------------------------------------------------- 368 void RegionStats_MLoad_Stats1(char *filename, int *ne, RegionStats *Stats) 369 // ----------------------------------------------------------------------- 281 282 283 // -------------------------------------------------------------------------- 284 void RegionStats_MLoad_Stats1(char * filename, int * ne, RegionStats * Stats) 285 // -------------------------------------------------------------------------- 370 286 { 371 287 int fd; … … 377 293 RegionStats_Close_File(fd); 378 294 } 295 #endif 296 379 297 // ----------------------------------------------------------------------- 380 void RegionStats_ MLoad_Stats2(char *filename, int *ne, RegionStats *Stats)298 void RegionStats_Save_Stats1(RegionStats * Stats, int ne, char * filename) 381 299 // ----------------------------------------------------------------------- 382 {383 #ifdef REGION_STATS2384 int fd385 386 fd = RegionStats_Open_File(filename);387 388 *ne = RegionStats_Read_Header(fd);389 RegionStats_Read_Stats2(fd, *ne, Stats);390 RegionStats_Close_File(fd);391 #else392 nrerror("RegionStats_MLoad_Stats2 : REGION_STATS2 not defined");393 #endif394 }395 // ---------------------------------------------------------------------396 void RegionStats_Save_Stats1(RegionStats *Stats, int ne, char *filename)397 // ---------------------------------------------------------------------398 300 { 399 301 int fd; … … 405 307 RegionStats_Close_File(fd); 406 308 } 407 // --------------------------------------------------------------------- 408 void RegionStats_Save_Stats2(RegionStats *Stats, int ne, char *filename) 409 // --------------------------------------------------------------------- 410 { 411 #ifdef REGION_STATS2 412 int fd; 413 414 fd = RegionStats_Create_File(filename); 415 416 RegionStats_Write_Header(ne, fd); 417 RegionStats_Write_Stats2(Stats, ne, fd); 418 RegionStats_Close_File(fd); 419 #else 420 nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined"); 421 #endif 422 } 423 // ----------------------------------------------------------------------- 424 void RegionStats_Save_pStats1(RegionStats **Stats, int ne, char *filename) 425 // ----------------------------------------------------------------------- 309 310 311 // ------------------------------------------------------------------------- 312 void RegionStats_Save_pStats1(RegionStats ** Stats, int ne, char * filename) 313 // ------------------------------------------------------------------------- 426 314 { 427 315 int fd; … … 433 321 RegionStats_Close_File(fd); 434 322 } 435 // ----------------------------------------------------------------------- 436 void RegionStats_Save_pStats2(RegionStats **Stats, int ne, char *filename) 437 // ----------------------------------------------------------------------- 438 { 439 #ifdef REGION_STATS2 440 int fd; 441 442 fd = RegionStats_Create_File(filename); 443 444 RegionStats_Write_Header(ne, fd); 445 RegionStats_Write_pStats2(Stats, ne, fd); 446 RegionStats_Close_File(fd); 447 #else 448 nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined"); 449 #endif 450 } 451 // -------------------------------------------------------------------- 452 void RegionStats_Display_Stats1(RegionStats *Stats, int ne, char *name) 453 // -------------------------------------------------------------------- 454 { 455 int i; 456 323 324 325 // ---------------------------------------------------------------------- 326 void RegionStats_Display_Stats1(RegionStats * Stats, int ne, char * name) 327 // ---------------------------------------------------------------------- 328 { 457 329 if (name != NULL) { 458 330 printf("%s : %d\n", name, ne); … … 461 333 printf("RegionStats : %d\n", ne); 462 334 } 463 for (i = 1; i <= ne; i++) {335 for (int i = 1; i <= ne; i++) { 464 336 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n", 465 337 i, … … 473 345 } 474 346 } 475 // -------------------------------------------------------------------- 476 void RegionStats_Display_Stats2(RegionStats *Stats, int ne, char *name) 477 // -------------------------------------------------------------------- 478 { 479 #ifdef REGION_STATS2 480 int i; 481 347 348 349 // ------------------------------------------------------------------------ 350 void RegionStats_Display_pStats1(RegionStats ** Stats, int ne, char * name) 351 // ------------------------------------------------------------------------ 352 { 482 353 if (name != NULL) { 483 354 printf("%s : %d\n", name, ne); … … 486 357 printf("RegionStats : %d\n", ne); 487 358 } 488 489 for (i = 1; i <= ne; i++) { 490 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 491 i, 492 Stats[i].xmin, 493 Stats[i].xmax, 494 Stats[i].ymin, 495 Stats[i].ymax, 496 Stats[i].S, 497 Stats[i].Sx, 498 Stats[i].Sy, 499 500 (int32) Stats[i].Sx2, 501 (int32) Stats[i].Sxy, 502 (int32) Stats[i].Sy2); 503 504 } 505 #else 506 nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined"); 507 #endif 508 } 509 // ---------------------------------------------------------------------- 510 void RegionStats_Display_pStats1(RegionStats **Stats, int ne, char *name) 511 // ---------------------------------------------------------------------- 512 { 513 int i; 514 515 if (name != NULL) { 516 printf("%s : %d\n", name, ne); 517 } 518 else { 519 printf("RegionStats : %d\n", ne); 520 } 521 for (i = 1; i <= ne; i++) { 359 for (int i = 1; i <= ne; i++) { 522 360 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n", 523 361 i, … … 531 369 } 532 370 } 533 // ---------------------------------------------------------------------- 534 void RegionStats_Display_pStats2(RegionStats **Stats, int ne, char *name) 535 // ---------------------------------------------------------------------- 536 { 537 #ifdef REGION_STATS2 538 int i; 539 540 if (name != NULL) { 541 printf("%s : %d\n", name, ne); 542 } 543 else { 544 printf("RegionStats : %d\n", ne); 545 } 546 for (i = 1; i <= ne; i++) { 547 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 548 i, 549 Stats[i]->xmin, 550 Stats[i]->xmax, 551 Stats[i]->ymin, 552 Stats[i]->ymax, 553 Stats[i]->S, 554 Stats[i]->Sx, 555 Stats[i]->Sy, 556 557 (int32) Stats[i]->Sx2, 558 (int32) Stats[i]->Sxy, 559 (int32) Stats[i]->Sy2); 560 561 } 562 #else 563 nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined"); 564 #endif 565 } 566 // --------------------------------------------------------------------------------------------- 567 void RegionStats_SetRectangle(RegionStats *Stats, int e, int ymin, int ymax, int xmin, int xmax) 568 // --------------------------------------------------------------------------------------------- 371 372 373 // ---------------------------------------------------------------------------------------------- 374 void RegionStats_SetRectangle(RegionStats * Stats, int e, int ymin, int ymax, int xmin, int xmax) 375 // ---------------------------------------------------------------------------------------------- 569 376 { 570 377 Stats[e].ymin = ymin; … … 573 380 Stats[e].xmax = xmax; 574 381 } 575 // ------------------------------------------------------- 576 void RegionStats_Copy1(RegionStats *src, RegionStats *dst) 577 // ------------------------------------------------------- 382 383 384 // --------------------------------------------------------- 385 void RegionStats_Copy1(RegionStats * src, RegionStats * dst) 386 // --------------------------------------------------------- 578 387 { 579 388 dst->xmin = src->xmin; … … 584 393 dst->S = src->S; 585 394 586 dst->x = src->x;587 dst->y = src->y;588 589 395 dst->Sx = src->Sx; 590 396 dst->Sy = src->Sy; 591 592 #ifdef REGION_STATS2 593 dst->Sx2 = src->Sx2; 594 dst->Sxy = src->Sxy; 595 dst->Sy2 = src->Sy2; 596 dst->teta = src->teta; 597 #endif 598 599 #ifdef REGION_STATS3 600 dst->Sx3 = src->Sx3; 601 dst->Sx2y = src->Sx2y; 602 dst->Sxy2 = src->Sxy2; 603 dst->Sy3 = src->Sy3; 604 605 dst->Mx2 = src->Mx2; 606 dst->Mxy = src->Mxy; 607 dst->My2 = src->My2; 608 609 dst->Mx3 = src->Mx3; 610 dst->Mx2y = src->Mx2y; 611 dst->Mxy2 = src->Mxy2; 612 dst->My3 = src->My3; 613 #endif 614 } 397 } 398 399 615 400 // =============================== 616 401 // === nouvelles versions 2009 === 617 402 // =============================== 618 403 619 // ------------------------------------------- 620 RegionStats * RegionStatsVector(int i0, int i1)621 // ------------------------------------------- 404 // -------------------------------------------- 405 RegionStats * RegionStatsVector(int i0, int i1) 406 // -------------------------------------------- 622 407 // allocate a float vector with subscript range v[i0..i1] 623 408 { … … 625 410 626 411 v = (RegionStats *) malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats))); 627 if (!v) nrerror("allocation failure in RegionStatsVector()"); 628 if (!v) return NULL; 412 if (!v) { 413 nrerror("allocation failure in %s()", __func__); 414 return NULL; 415 } 416 RegionStats_Clear(v, i1 - i0 + 1 + NR_END); 629 417 return v - i0 + NR_END; 630 418 } 631 // ---------------------------------------------------------- 632 RegionStats* RegionStatsVector0(int i0, int i1) 633 // ---------------------------------------------------------- 419 420 421 #if TARGET_OS == GIETVM 422 // ----------------------------------------------------------------- 423 RegionStats * remote_RegionStatsVector(int i0, int i1, int x, int y) 424 // ----------------------------------------------------------------- 634 425 // allocate a float vector with subscript range v[i0..i1] 635 426 { 636 RegionStats *v; 427 RegionStats * v; 428 429 v = (RegionStats *) remote_malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats)), x, y); 430 if (!v) { 431 nrerror("allocation failure in %s()", __func__); 432 return NULL; 433 } 434 RegionStats_Clear(v, i1 - i0 + 1 + NR_END); 435 return v - i0 + NR_END; 436 } 437 #endif 438 439 440 // --------------------------------------------- 441 RegionStats * RegionStatsVector0(int i0, int i1) 442 // --------------------------------------------- 443 // allocate a float vector with subscript range v[i0..i1] 444 { 445 RegionStats * v; 637 446 638 447 v = (RegionStats *) calloc((size_t) (i1 - i0 + 1 + NR_END), sizeof(RegionStats)); 639 if (!v) nrerror("allocation failure in RegionStatsVector0()"); 640 if (!v) return NULL; 448 if (!v) { 449 nrerror("allocation failure in RegionStatsVector0()"); 450 return NULL; 451 } 641 452 return v - i0 + NR_END; 642 453 } 643 // ---------------------------------------------------------------------- 644 void free_RegionStatsVector(RegionStats *v, int i0, int i1) 645 // ---------------------------------------------------------- 454 455 456 // --------------------------------------------------------- 457 void free_RegionStatsVector(RegionStats * v, int i0, int i1) 458 // --------------------------------------------------------- 646 459 // free a RegionStats vector allocated with vector() 647 460 { 648 free((FREE_ARG) (v + i0 - NR_END)); 649 } 650 // ------------------------------------------------------------ 651 RegionStats** RegionStatsMatrix(int i0, int i1, int j0, int j1) 652 // ------------------------------------------------------------ 461 free(v + i0 - NR_END); 462 } 463 464 465 // ------------------------------------------------------------- 466 RegionStats ** RegionStatsMatrix(int i0, int i1, int j0, int j1) 467 // ------------------------------------------------------------- 653 468 654 469 // allocate a RegionStats matrix with subscript range m[nrl..nrh][ncl..nch] 470 { 471 long nrow = i1 - i0 + 1; 472 long ncol = j1 - j0 + 1; 473 RegionStats ** m; 474 475 // allocate pointers to rows 476 m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *))); 477 if (!m) { 478 nrerror("allocation failure 1 in RegionStatsMatrix()"); 479 } 480 m += NR_END; 481 m -= i0; 482 483 // allocate rows and set pointers to them 484 m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats))); 485 if (!m[i0]) { 486 nrerror("allocation failure 2 in RegionStatsMatrix()"); 487 } 488 m[i0] += NR_END; 489 m[i0] -= j0; 490 491 for (int i = i0 + 1; i <= i1; i++) { 492 m[i] = m[i - 1] + ncol; 493 } 494 495 // return pointer to array of pointers to rows 496 return m; 497 } 498 499 500 // -------------------------------------------------------------- 501 RegionStats ** RegionStatsMatrix0(int i0, int i1, int j0, int j1) 502 // -------------------------------------------------------------- 503 // allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] 655 504 { 656 505 long i; 657 506 long nrow = i1 - i0 + 1; 658 507 long ncol = j1 - j0 + 1; 659 RegionStats ** m;508 RegionStats ** m; 660 509 661 510 // allocate pointers to rows 662 m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *))); 663 if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()"); 511 m= (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats*))); 512 if (!m) { 513 nrerror("allocation failure 1 in RegionStatsMatrix()"); 514 } 664 515 m += NR_END; 665 516 m -= i0; 666 517 667 518 // allocate rows and set pointers to them 668 m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats))); 669 if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()"); 519 m[i0] = (RegionStats *) calloc((size_t) (nrow * ncol + NR_END), sizeof(RegionStats)); 520 if (!m[i0]) { 521 nrerror("allocation failure 2 in RegionStatsMatrix()"); 522 } 670 523 m[i0] += NR_END; 671 524 m[i0] -= j0; 672 525 673 for (i = i0 + 1; i <= i1; i++) {526 for (i = i0 + 1; i <= i1; i++) { 674 527 m[i] = m[i - 1] + ncol; 675 528 } … … 678 531 return m; 679 532 } 680 // ------------------------------------------------------------- 681 RegionStats** RegionStatsMatrix0(int i0, int i1, int j0, int j1) 682 // ------------------------------------------------------------- 683 684 // allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] 685 { 686 long i, nrow=i1-i0+1,ncol=j1-j0+1; 687 RegionStats **m; 688 689 // allocate pointers to rows 690 m=(RegionStats**) malloc((size_t)((nrow+NR_END)*sizeof(RegionStats*))); 691 if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()"); 692 m += NR_END; 693 m -= i0; 694 695 // allocate rows and set pointers to them 696 m[i0]=(RegionStats*) calloc((size_t)(nrow*ncol+NR_END), sizeof(RegionStats)); 697 if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()"); 698 m[i0] += NR_END; 699 m[i0] -= j0; 700 701 for(i=i0+1;i<=i1;i++) m[i]=m[i-1]+ncol; 702 703 // return pointer to array of pointers to rows 704 return m; 705 } 706 // ------------------------------------------------------------------------- 707 void free_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1) 708 // ------------------------------------------------------------------------- 709 { 710 free((FREE_ARG) (m[i0]+j0-NR_END)); 711 free((FREE_ARG) (m+i0-NR_END)); 712 } 713 // ---------------------------------- 714 void zero_RegionStats(RegionStats *x) 715 // ---------------------------------- 533 534 535 // -------------------------------------------------------------------------- 536 void free_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1) 537 // -------------------------------------------------------------------------- 538 { 539 free(m[i0] + j0 - NR_END); 540 free(m + i0 - NR_END); 541 } 542 543 544 // ----------------------------------- 545 void zero_RegionStats(RegionStats * x) 546 // ----------------------------------- 716 547 { 717 548 x->xmin = 32767; … … 723 554 x->Sx = 0; 724 555 x->Sy = 0; 725 726 #ifdef REGION_STATS2 727 x->Sx2 = 0; 728 x->Sxy = 0; 729 x->Sy2 = 0; 730 #endif 731 } 732 // -------------------------------------------------------- 733 void zero_RegionStatsVector(RegionStats *v, int i0, int i1) 734 // -------------------------------------------------------- 735 { 736 int i; 737 for(i=i0; i<=i1; i++) { 556 } 557 558 559 // --------------------------------------------------------- 560 void zero_RegionStatsVector(RegionStats * v, int i0, int i1) 561 // --------------------------------------------------------- 562 { 563 for (int i = i0; i <= i1; i++) { 738 564 zero_RegionStats(&v[i]); 739 565 } 740 566 } 741 // ------------------------------------------------------------------------- 742 void zero_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1) 743 // ------------------------------------------------------------------------- 744 { 745 int i, j; 746 for(i=i0; i<=i1; i++) { 747 for(j=j0; j<=j1; j++) { 567 568 569 // -------------------------------------------------------------------------- 570 void zero_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1) 571 // -------------------------------------------------------------------------- 572 { 573 for (int i = i0; i <= i1; i++) { 574 for (int j = j0; j <= j1; j++) { 748 575 zero_RegionStats(&(m[i][j])); 749 576 } 750 577 } 751 578 } 752 // ------------------------------------------------- 753 void display_RegionStats(RegionStats *x, char *name) 754 // ------------------------------------------------- 755 { 756 if(name != NULL) printf("%s : \n", name); 757 758 #ifndef REGION_STATS2 579 580 581 // --------------------------------------------------- 582 void display_RegionStats(RegionStats * x, char * name) 583 // --------------------------------------------------- 584 { 585 if (name != NULL) { 586 printf("%s : \n", name); 587 } 588 759 589 printf("%4d %4d %4d %4d %6d %8d %8d\n", 760 590 x->xmin, … … 766 596 x->Sx, 767 597 x->Sy); 768 #else 769 printf("%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 770 x->xmin, 771 x->xmax, 772 x->ymin, 773 x->ymax, 774 775 x->S, 776 x->Sx, 777 x->Sy, 778 779 x->Sx2, 780 x->Sxy, 781 x->Sy2); 782 #endif 783 } 784 // ----------------------------------------------------------------------- 785 void display_RegionStatsVector(RegionStats *v, int i0, int i1, char *name) 786 // ----------------------------------------------------------------------- 787 { 788 int i; 789 790 if(name != NULL) printf("%s : [%d..%d]\n", name, i0, i1); else printf("RegionStats : [%d..%d]\n", i0, i1); 791 for(i=i0; i<=i1; i++) { 598 } 599 600 601 // ------------------------------------------------------------------------ 602 void display_RegionStatsVector(RegionStats * v, int i0, int i1, char *name) 603 // ------------------------------------------------------------------------ 604 { 605 if (name != NULL) { 606 printf("%s : [%d..%d]\n", name, i0, i1); 607 } 608 else { 609 printf("RegionStats : [%d..%d]\n", i0, i1); 610 } 611 for (int i = i0; i <= i1; i++) { 792 612 printf("#%3d: ", i); 793 613 display_RegionStats(&(v[i]), NULL); 794 //puts(""); 795 } 796 } 797 // ---------------------------------------------------------------------------------------- 798 void display_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name) 799 // ---------------------------------------------------------------------------------------- 800 { 801 int i, j; 802 803 if (name != NULL) printf("%s : [%d..%d][%d..%d]\n", name, i0, i1, j0, j1); else printf("RegionStats : [%d..%d][%d..%d]\n", i0, i1, j0, j1); 804 for (i = i0; i <= i1; i++) { 805 for (j = j0; j <= j1; j++) { 614 } 615 } 616 617 618 // ------------------------------------------------------------------------------------------ 619 void display_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name) 620 // ------------------------------------------------------------------------------------------ 621 { 622 623 if (name != NULL) { 624 printf("%s : [%d..%d][%d..%d]\n", name, i0, i1, j0, j1); 625 } 626 else { 627 printf("RegionStats : [%d..%d][%d..%d]\n", i0, i1, j0, j1); 628 } 629 for (int i = i0; i <= i1; i++) { 630 for (int j = j0; j <= j1; j++) { 806 631 printf("#%3d: ", i); 807 632 display_RegionStats(&(m[i][j]), NULL); … … 809 634 } 810 635 } 811 // ---------------------------------------------- 812 void save_RegionStats(RegionStats *x, char *name) 813 // ---------------------------------------------- 636 637 638 // ------------------------------------------------ 639 void save_RegionStats(RegionStats * x, char * name) 640 // ------------------------------------------------ 814 641 { 815 642 int fd = -1; 643 char buff[BUFF_SIZE]; 816 644 817 645 if (name == NULL) { … … 824 652 printf("*** Erreur : ouverture du fichier %s dans %s\n", name, __func__); 825 653 } 826 fprintf(fd, "%s: ", name); 827 828 #ifndef REGION_STATS2 829 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d\n", 830 654 snprintf(buff, BUFF_SIZE, "%s: %4d %4d %4d %4d %6d %8d %8d\n", 655 name, 831 656 x->xmin, 832 657 x->xmax, … … 837 662 x->Sx, 838 663 x->Sy); 839 #else 840 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 841 842 x->xmin, 843 x->xmax, 844 x->ymin, 845 x->ymax, 846 847 x->S, 848 x->Sx, 849 x->Sy, 850 851 x->Sx2, 852 x->Sxy, 853 x->Sy2); 854 #endif 664 write(fd, buff, strlen(buff) + 1); 855 665 856 666 if (name) { … … 858 668 } 859 669 } 860 // -------------------------------------------------------------------- 861 void save_RegionStatsVector(RegionStats *v, int i0, int i1, char *name) 862 // -------------------------------------------------------------------- 863 { 864 int i; 670 671 672 // ---------------------------------------------------------------------- 673 void save_RegionStatsVector(RegionStats * v, int i0, int i1, char * name) 674 // ---------------------------------------------------------------------- 675 { 865 676 int fd; 677 char buff[BUFF_SIZE]; 866 678 867 679 if (name == NULL) { … … 870 682 fd = RegionStats_Create_File(name); 871 683 872 fprintf(fd, "%s : [%d..%d]\n", name, i0, i1); 873 874 for (i = i0; i <= i1; i++) { 684 snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1); 685 write(fd, buff, strlen(buff) + 1); 686 687 for (int i = i0; i <= i1; i++) { 875 688 printf("#%3d: ", i); 876 689 save_RegionStats(&v[i], NULL); 877 printf("");878 690 } 879 691 RegionStats_Close_File(fd); 880 692 } 881 // ------------------------------------------------------------------------------------- 882 void save_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name) 883 // ------------------------------------------------------------------------------------- 884 { 885 int i, j; 693 694 695 // --------------------------------------------------------------------------------------- 696 void save_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name) 697 // --------------------------------------------------------------------------------------- 698 { 886 699 int fd; 700 char buff[BUFF_SIZE]; 887 701 888 702 if (name == NULL) { … … 891 705 fd = RegionStats_Create_File(name); 892 706 893 fprintf(fd, "%s : [%d..%d]\n", name, i0, i1); 894 895 for (i = i0; i <= i1; i++) { 896 for (j = j0; j <= j1; j++) { 897 fprintf(fd, "#%3d: ", i); 707 snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1); 708 write(fd, buff, strlen(buff) + 1); 709 710 for (int i = i0; i <= i1; i++) { 711 for (int j = j0; j <= j1; j++) { 712 snprintf(buff, BUFF_SIZE, "#%3d: ", i); 713 write(fd, buff, strlen(buff) + 1); 898 714 save_RegionStats(&m[i][j], NULL); 899 715 } 900 printf("");901 716 } 902 717 RegionStats_Close_File(fd); 903 718 } 904 // ------------------------------------------------------------------------------ 905 void RegionStats_Calc1_Features_1Pass(RegionStats *Stats, uint32 e, int i, int j) 906 // ------------------------------------------------------------------------------ 719 720 721 // ------------------------------------------------------------------------------- 722 void RegionStats_Calc1_Features_1Pass(RegionStats * Stats, uint32 e, int i, int j) 723 // ------------------------------------------------------------------------------- 907 724 { 908 725 // calcul sur 1 point et non sur toute l'image 909 726 // Rectangle 910 727 911 if (i < Stats[e].ymin) Stats[e].ymin = i; 912 if (i > Stats[e].ymax) Stats[e].ymax = i; 913 914 if (j < Stats[e].xmin) Stats[e].xmin = j; 915 if (j > Stats[e].xmax) Stats[e].xmax = j; 728 if (i < Stats[e].ymin) { 729 Stats[e].ymin = i; 730 } 731 if (i > Stats[e].ymax) { 732 Stats[e].ymax = i; 733 } 734 735 if (j < Stats[e].xmin) { 736 Stats[e].xmin = j; 737 } 738 if (j > Stats[e].xmax) { 739 Stats[e].xmax = j; 740 } 916 741 917 742 // Moment1 … … 922 747 return; 923 748 } 749 750 924 751 // -------------------------------- 925 752 // --- fonctions de 2013 ---------- 926 753 // -------------------------------- 927 // ------------------------------------------------------------------------------------------- 928 void RegionStats_Calc_Rectangle_Moment1(uint32 **E, int height, int width, RegionStats *Stats) 929 // ------------------------------------------------------------------------------------------- 930 { 931 int i, j; 754 // --------------------------------------------------------------------------------------------- 755 void RegionStats_Calc_Rectangle_Moment1(uint32 ** E, int height, int width, RegionStats * Stats) 756 // --------------------------------------------------------------------------------------------- 757 { 932 758 uint32 x, y; 933 759 uint32 e; 934 760 935 for (i = 0; i < height; i++) {936 for ( j = 0; j < width; j++) {761 for (int i = 0; i < height; i++) { 762 for (int j = 0; j < width; j++) { 937 763 938 764 e = E[i][j]; 939 765 if (e) { 940 941 766 x = j; 942 767 y = i; 943 768 944 if (i<Stats[e].ymin) Stats[e].ymin = y; 945 if (i>Stats[e].ymax) Stats[e].ymax = y; 769 if (i < Stats[e].ymin) { 770 Stats[e].ymin = y; 771 } 772 if (i > Stats[e].ymax) { 773 Stats[e].ymax = y; 774 } 946 775 947 if (j<Stats[e].xmin) Stats[e].xmin = x; 948 if (j>Stats[e].xmax) Stats[e].xmax = x; 776 if (j < Stats[e].xmin) { 777 Stats[e].xmin = x; 778 } 779 if (j > Stats[e].xmax) { 780 Stats[e].xmax = x; 781 } 949 782 950 783 Stats[e].S += 1; … … 955 788 } 956 789 } 957 // ----------------------------------------------------------------------------------------------------------------------------- 958 void RegionStats_calc_Status(RegionStats *Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 *status) 959 // ----------------------------------------------------------------------------------------------------------------------------- 790 791 792 // ------------------------------------------------------------------------------------------------------------------------------- 793 void RegionStats_calc_Status(RegionStats * Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 * status) 794 // ------------------------------------------------------------------------------------------------------------------------------- 960 795 { 961 796 uint16 xmin, xmax, ymin, ymax, xsize, ysize; … … 983 818 } 984 819 } 985 // -------------------------------------------------------------------------- 986 uint32 RegionStats_UpdateEQ_with_Status(uint8 *status, uint32 ne, uint32 *EQ) 987 // -------------------------------------------------------------------------- 820 821 822 // ---------------------------------------------------------------------------- 823 uint32 RegionStats_UpdateEQ_with_Status(uint8 * status, uint32 ne, uint32 * EQ) 824 // ---------------------------------------------------------------------------- 988 825 { 989 826 uint32 e; … … 999 836 return na; 1000 837 } 1001 // ---------------------------------------------------------------------------- 1002 void RegionStats_UpdateStats_with_EQ(uint32 *EQ, uint32 ne, RegionStats *Stats) 1003 // ---------------------------------------------------------------------------- 838 839 840 // ------------------------------------------------------------------------------ 841 void RegionStats_UpdateStats_with_EQ(uint32 * EQ, uint32 ne, RegionStats * Stats) 842 // ------------------------------------------------------------------------------ 1004 843 { 1005 844 uint32 e, a; … … 1015 854 } 1016 855 } 1017 // --------------------------------------------------------------------------- 1018 void featuresComputation(uint32 **E, int height,int width, RegionStats *Stats) 1019 // --------------------------------------------------------------------------- 856 857 858 // ----------------------------------------------------------------------------- 859 void featuresComputation(uint32 ** E, int height,int width, RegionStats * Stats) 860 // ----------------------------------------------------------------------------- 1020 861 { 1021 862 //uint32 nemax = height * width /2; 1022 863 RegionStats_Calc_Rectangle_Moment1(E, height, width, Stats); 1023 864 } 1024 // ------------------------------------------------------------------------------ 1025 void pointFeaturesComputation_Dummy(uint32 **E, int i, int j, RegionStats *Stats) 1026 // ------------------------------------------------------------------------------ 1027 { 1028 // pour pointeur de fonction 1029 return; 1030 } 1031 // ------------------------------------------------------------------------- 1032 void pointFeaturesComputation( uint32 **E, int i, int j, RegionStats *Stats) 1033 // ------------------------------------------------------------------------- 865 866 867 // --------------------------------------------------------------------------- 868 void pointFeaturesComputation( uint32 ** E, int i, int j, RegionStats * Stats) 869 // --------------------------------------------------------------------------- 1034 870 { 1035 871 uint32 x, y; … … 1042 878 y = i; 1043 879 1044 if (i<Stats[e].ymin) Stats[e].ymin = y; 1045 if (i>Stats[e].ymax) Stats[e].ymax = y; 1046 1047 if (j<Stats[e].xmin) Stats[e].xmin = x; 1048 if (j>Stats[e].xmax) Stats[e].xmax = x; 880 if (i < Stats[e].ymin) { 881 Stats[e].ymin = y; 882 } 883 if (i > Stats[e].ymax) { 884 Stats[e].ymax = y; 885 } 886 887 if (j < Stats[e].xmin) { 888 Stats[e].xmin = x; 889 } 890 if (j > Stats[e].xmax) { 891 Stats[e].xmax = x; 892 } 1049 893 1050 894 Stats[e].S += 1; … … 1053 897 } 1054 898 } 1055 // ---------------------------------------------------------------------------------- 1056 void lineFeaturesComputation_Dummy( uint32 **E, int i, int width, RegionStats *Stats) 1057 // ---------------------------------------------------------------------------------- 1058 { 1059 // pour pointeur de fonction 1060 return; 1061 } 1062 // ---------------------------------------------------------------------------- 1063 void lineFeaturesComputation( uint32 **E, int i, int width, RegionStats *Stats) 1064 // ---------------------------------------------------------------------------- 899 900 901 // ----------------------------------------------------------------------------- 902 void lineFeaturesComputation(uint32 ** E, int i, int width, RegionStats * Stats) 903 // ----------------------------------------------------------------------------- 1065 904 { 1066 905 // line RegionStats_Calc_Rectangle_Moment1 1067 int j;1068 906 1069 907 uint32 x, y; 1070 908 uint32 e; 1071 909 1072 for ( j = 0; j < width; j++) {910 for (int j = 0; j < width; j++) { 1073 911 1074 912 e = E[i][j]; … … 1078 916 y = i; 1079 917 1080 if (i<Stats[e].ymin) Stats[e].ymin = y; 1081 if (i>Stats[e].ymax) Stats[e].ymax = y; 918 if (i < Stats[e].ymin) { 919 Stats[e].ymin = y; 920 } 921 if (i > Stats[e].ymax) { 922 Stats[e].ymax = y; 923 } 1082 924 1083 if (j<Stats[e].xmin) Stats[e].xmin = x; 1084 if (j>Stats[e].xmax) Stats[e].xmax = x; 925 if (j < Stats[e].xmin) { 926 Stats[e].xmin = x; 927 } 928 if (j > Stats[e].xmax) { 929 Stats[e].xmax = x; 930 } 1085 931 1086 932 Stats[e].S += 1; … … 1090 936 } 1091 937 } 1092 // ------------------------------------------------------------------------------------------ 1093 void bandFeaturesComputation_Dummy(uint32 **E, int i0, int i1, int width, RegionStats *Stats) 1094 // ------------------------------------------------------------------------------------------ 1095 { 1096 return; 1097 } 1098 // ------------------------------------------------------------------------------------ 1099 void bandFeaturesComputation(uint32 **E, int i0, int i1, int width, RegionStats *Stats) 1100 // ------------------------------------------------------------------------------------ 1101 { 1102 int i; 1103 for (i = i0; i <= i1; i++) { 938 939 940 // -------------------------------------------------------------------------------------- 941 void bandFeaturesComputation(uint32 ** E, int i0, int i1, int width, RegionStats * Stats) 942 // -------------------------------------------------------------------------------------- 943 { 944 for (int i = i0; i <= i1; i++) { 1104 945 lineFeaturesComputation(E, i, width, Stats); 1105 946 } 1106 947 } 1107 // --------------------------------------------------------------------------------------- 1108 void imageFeaturesComputation_Dummy(uint32 **E, int height, int width, RegionStats *Stats) 1109 // --------------------------------------------------------------------------------------- 1110 { 1111 // pour pointeur de fonction 1112 return; 1113 } 1114 // --------------------------------------------------------------------------------- 1115 void imageFeaturesComputation(uint32 **E, int height, int width, RegionStats *Stats) 1116 // --------------------------------------------------------------------------------- 948 949 950 // ----------------------------------------------------------------------------------- 951 void imageFeaturesComputation(uint32 ** E, int height, int width, RegionStats * Stats) 952 // ----------------------------------------------------------------------------------- 1117 953 { 1118 954 // image RegionStats_Calc_Rectangle_Moment1 1119 int i; 1120 for (i = 0; i < height; i++) { 955 for (int i = 0; i < height; i++) { 1121 956 lineFeaturesComputation(E, i, width, Stats); 1122 957 } 1123 958 } 959 960 1124 961 // --------------------------------------- 1125 962 // --- Fonctions 2014 -------------------- 1126 963 // --------------------------------------- 1127 964 1128 // -------------------------------------------------------------------------------------- 1129 void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index)1130 // -------------------------------------------------------------------------------------- 965 // --------------------------------------------------------------------------------------- 966 void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index) 967 // --------------------------------------------------------------------------------------- 1131 968 { 1132 969 // R[dst] = R[src] 1133 970 RegionStats_Copy1(&Stats[src_index], &Stats[dst_index]); 1134 971 } 1135 // -------------------------------------------------------------------------------------------- 1136 void RegionStats_Accumulate_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index) 1137 // -------------------------------------------------------------------------------------------- 972 973 974 // --------------------------------------------------------------------------------------------- 975 void RegionStats_Accumulate_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index) 976 // --------------------------------------------------------------------------------------------- 1138 977 { 1139 978 // R[dst] += R[src] … … 1147 986 Stats[dst_index].Sy += Stats[src_index].Sy; 1148 987 } 1149 // ----------------------------------------------------------------------------------------------------- 1150 void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name) 1151 // ----------------------------------------------------------------------------------------------------- 988 989 990 // --------------------------------------------------------------------------------------------------------------------------- 991 void RegionStats_DisplayStats_Sparse(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name, int * start_index) 992 // --------------------------------------------------------------------------------------------------------------------------- 1152 993 { 1153 994 // n'affiche que les racines. … … 1156 997 uint32 na; // compteur 1157 998 1158 if (name) printf(name); 1159 1160 na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1); 1161 printf("%d\n", na); 999 if (name) { 1000 printf(name); 1001 } 1002 1003 //na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1); 1004 //printf("%d\n", na); 1162 1005 1163 1006 for (e = ne0; e <= ne1; e++) { 1164 if ((e == EQ[e]) && (Stats[e].S > 0)) { 1165 printf("%5d ", e); 1007 if (e == EQ[e] && Stats[e].S > 0) { 1008 if (start_index != NULL) { 1009 printf("%5d ", *start_index); 1010 *start_index = *start_index + 1; 1011 } 1012 else { 1013 printf("%5d ", e); 1014 } 1166 1015 display_RegionStats(&Stats[e], NULL); 1167 1016 } 1168 1017 } 1169 1018 } 1170 // ---------------------------------------------------------------------------------------------------- 1171 void RegionStats_DisplayStats_Range(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name) 1172 // ---------------------------------------------------------------------------------------------------- 1019 1020 1021 // ------------------------------------------------------------------------------------------------------- 1022 void RegionStats_DisplayStats_Range(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name) 1023 // ------------------------------------------------------------------------------------------------------- 1173 1024 { 1174 1025 // affichage dense (apres un pack) … … 1176 1027 uint32 e; 1177 1028 1178 if (name) printf(name); 1029 if (name) { 1030 printf(name); 1031 } 1179 1032 1180 1033 for (e = ne0; e <= ne1; e++) { … … 1183 1036 } 1184 1037 } 1185 // -------------------------------------------------------------------------------------------------------- 1186 void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename) 1187 // -------------------------------------------------------------------------------------------------------- 1038 1039 1040 // ----------------------------------------------------------------------------------------------------------- 1041 void RegionStats_Save_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, char * filename) 1042 // ----------------------------------------------------------------------------------------------------------- 1188 1043 { 1189 1044 int fd; … … 1197 1052 RegionStats_Close_File(fd); 1198 1053 } 1199 // ------------------------------------------------------------------------------------------ 1200 uint32 RegionStats_Count_Roots_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1) 1201 // ------------------------------------------------------------------------------------------ 1054 1055 1056 // -------------------------------------------------------------------------------------------- 1057 uint32 RegionStats_Count_Roots_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1) 1058 // -------------------------------------------------------------------------------------------- 1202 1059 { 1203 1060 uint32 e, c = 0; // compteur … … 1210 1067 return c; 1211 1068 } 1212 // --------------------------------------------------------------------------------- 1213 uint32 RegionStats_Count_Roots_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax) 1214 // --------------------------------------------------------------------------------- 1069 1070 1071 // ----------------------------------------------------------------------------------- 1072 uint32 RegionStats_Count_Roots_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax) 1073 // ----------------------------------------------------------------------------------- 1215 1074 { 1216 1075 return RegionStats_Count_Roots_Sparse(Stats, EQ, 1, nemax); 1217 1076 } 1218 // ------------------------------------------------------------------------------------------- 1219 uint32 RegionStats_Count_Labels_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1) 1220 // ------------------------------------------------------------------------------------------- 1077 1078 1079 // --------------------------------------------------------------------------------------------- 1080 uint32 RegionStats_Count_Labels_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1) 1081 // --------------------------------------------------------------------------------------------- 1221 1082 { 1222 1083 uint32 e, c = 0; // compteur … … 1229 1090 return c; 1230 1091 } 1231 // ----------------------------*----------------------------------------------------- 1232 uint32 RegionStats_Count_Labels_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax) 1233 // ---------------------------*------------------------------------------------------ 1092 1093 1094 // ------------------------------------------------------------------------------------ 1095 uint32 RegionStats_Count_Labels_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax) 1096 // ------------------------------------------------------------------------------------ 1234 1097 { 1235 1098 return RegionStats_Count_Labels_Sparse(Stats, EQ, 1, nemax); 1236 1099 } 1237 // --------------------------------------------------------------------- 1238 void copy_features_ui32matrix(RegionStats *Stats, uint32 ne, uint32 **m) 1239 // --------------------------------------------------------------------- 1240 { 1241 int i; 1242 for (i = 0; i <= (int) ne; i++) { 1100 1101 1102 // ----------------------------------------------------------------------- 1103 void copy_features_ui32matrix(RegionStats * Stats, uint32 ne, uint32 ** m) 1104 // ----------------------------------------------------------------------- 1105 { 1106 for (int i = 0; i <= (int) ne; i++) { 1243 1107 1244 1108 m[i][0] = i; … … 1260 1124 } 1261 1125 } 1262 // --------------------------------------------------------------------- 1263 void copy_ui32matrix_features(uint32 **m, uint32 ne, RegionStats *Stats) 1264 // --------------------------------------------------------------------- 1265 { 1266 int i; 1267 for (i = 0; i <= (int) ne; i++) { 1126 1127 1128 // ----------------------------------------------------------------------- 1129 void copy_ui32matrix_features(uint32 ** m, uint32 ne, RegionStats * Stats) 1130 // ----------------------------------------------------------------------- 1131 { 1132 for (int i = 0; i <= (int) ne; i++) { 1268 1133 1269 1134 Stats[i].xmin = m[i][2] >> 16; … … 1277 1142 } 1278 1143 } 1279 // --------------------------------------------------------------------------- 1280 void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col) 1281 // --------------------------------------------------------------------------- 1144 1145 1146 // ---------------------------------------------------------------------------- 1147 void sortv_ui32matrix_col(uint32 ** m, int i0, int i1, int j0, int j1, int col) 1148 // ---------------------------------------------------------------------------- 1282 1149 { 1283 1150 // nrsort2 for NRC2 … … 1294 1161 * instead of copying the lines. 1295 1162 */ 1296 int i, j;1297 1163 1298 1164 uint32 x, min, pos; 1299 1165 uint32 * ptr; 1300 1166 1301 for (i = nrl; i < nrh; i++) {1167 for (int i = nrl; i < nrh; i++) { 1302 1168 min = m[i][nc]; 1303 1169 pos = i; 1304 for ( j = i + 1; j <= nrh; j++) {1170 for (int j = i + 1; j <= nrh; j++) { 1305 1171 x = m[j][nc]; 1306 1172 if (x < min) { … … 1314 1180 m[i] = m[pos]; 1315 1181 m[pos] = ptr; 1316 1317 1182 } // i 1318 1319 } 1320 // ------------------------------------------------------------ 1321 void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax) 1322 // ------------------------------------------------------------ 1183 } 1184 1185 1186 // ------------------------------------------------------------- 1187 void RegionStats_SortFeatures(RegionStats * Stats, uint32 nemax) 1188 // ------------------------------------------------------------- 1323 1189 { 1324 1190 uint32 ** m = NULL; … … 1330 1196 copy_ui32matrix_features(m, nemax, Stats); 1331 1197 } 1332 // -------------------------------------------------------------------------------------- 1333 void imageFeaturesComputation_omp0(uint32 **E, int height, int width, RegionStats *Stats) 1334 // -------------------------------------------------------------------------------------- 1335 { 1336 // version OpenMP 2.0 fausse (sans serialisation de la section critique) 1337 // pour evaluer l'impact de la synchro 1338 int i, j; 1339 1340 uint32 x, y; 1341 uint32 e; 1342 1343 #ifdef OPENMP 1344 #pragma omp parallel for private(height, width, i, j, x, y, e) shared (E, Stats) 1345 #endif 1346 for (i = 0; i < height; i++) { 1347 for (j = 0; j < width; j++) { 1348 1349 e = E[i][j]; 1350 if (e) { 1351 1352 x = j; 1353 y = i; 1354 1355 // min max reduction 1356 if (y < Stats[e].ymin) Stats[e].ymin = y; 1357 if (y > Stats[e].ymax) Stats[e].ymax = y; 1358 1359 if (x < Stats[e].xmin) Stats[e].xmin = x; 1360 if (x > Stats[e].xmax) Stats[e].xmax = x; 1361 1362 // + reduction 1363 Stats[e].S += 1; 1364 Stats[e].Sx += x; 1365 Stats[e].Sy += y; 1366 } 1367 } 1368 } 1369 } 1370 // -------------------------------------------------------------------------------------- 1371 void imageFeaturesComputation_omp2(uint32** E, int height, int width, RegionStats* Stats) 1372 // -------------------------------------------------------------------------------------- 1373 { 1374 // version OpenMP 2.0 classique avec "critical" 1375 1376 int i, j; 1377 1378 uint32 x, y; 1379 uint32 e; 1380 1381 1382 #ifdef OPENMP 1383 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1384 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1385 //#pragma omp for private (j) 1386 #endif 1387 for (i = 0; i < height; i++) { 1388 //printf("i = %d\n", i); 1389 //printf("omp_get_num_threads = %d\n", omp_get_num_threads()); 1390 1391 for (j = 0; j < width; j++) { 1392 1393 e = E[i][j]; 1394 if (e) { 1395 1396 x = j; 1397 y = i; 1398 1399 #ifdef OPENMP 1400 #pragma omp critical 1401 #endif 1402 { 1403 // min max reduction 1404 if (y < Stats[e].ymin) Stats[e].ymin = y; 1405 if (y > Stats[e].ymax) Stats[e].ymax = y; 1406 1407 if (x < Stats[e].xmin) Stats[e].xmin = x; 1408 if (x > Stats[e].xmax) Stats[e].xmax = x; 1409 1410 // + reduction 1411 Stats[e].S += 1; 1412 Stats[e].Sx += x; 1413 Stats[e].Sy += y; 1414 } // omp critical 1415 } // if e 1416 } // j 1417 } // i 1418 } 1419 // -------------------------------------------------------------------------------------- 1420 void imageFeaturesComputation_omp3(uint32** E, int height, int width, RegionStats* Stats) 1421 // -------------------------------------------------------------------------------------- 1422 { 1423 // version OpenMP 2.0 classique avec "critical" (from Laurent Cabaret with optimal use of critical and atomic) 1424 1425 int i, j; 1426 1427 uint32 x, y; 1428 uint32 e; 1429 1430 1431 #ifdef OPENMP 1432 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1433 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1434 #endif 1435 for (i = 0; i < height; i++) { 1436 1437 for (j = 0; j < width; j++) { 1438 1439 e = E[i][j]; 1440 if (e) { 1441 1442 x = j; 1443 y = i; 1444 1445 #ifdef OPENMP 1446 #pragma omp critical 1447 #endif 1448 { 1449 // min max reduction 1450 if (y < Stats[e].ymin) Stats[e].ymin = y; 1451 if (y > Stats[e].ymax) Stats[e].ymax = y; 1452 } 1453 #ifdef OPENMP 1454 #pragma omp critical 1455 #endif 1456 { 1457 if (x < Stats[e].xmin) Stats[e].xmin = x; 1458 if (x > Stats[e].xmax) Stats[e].xmax = x; 1459 } 1460 // + reduction 1461 #ifdef OPENMP 1462 #pragma omp atomic 1463 #endif 1464 Stats[e].S += 1; 1465 1466 #ifdef OPENMP 1467 #pragma omp atomic 1468 #endif 1469 Stats[e].Sx += x; 1470 1471 #ifdef OPENMP 1472 #pragma omp atomic 1473 Stats[e].Sy += y; 1474 #endif 1475 } // if e 1476 } // j 1477 } // i 1478 } 1479 // -------------------------------------------------------------------------------------------- 1480 void imageFeaturesComputation_range_omp2(uint32** E, int height, int width, RegionStats* Stats) 1481 // -------------------------------------------------------------------------------------------- 1482 { 1483 // version OpenMP 2.0 1484 1485 int i, j; 1486 1487 uint32 x, y; 1488 uint32 e; 1489 1490 1491 #ifdef OPENMP 1492 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1493 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1494 //#pragma omp for private (j) 1495 #endif 1496 for (i = 0; i < height; i++) { 1497 //printf("i = %d\n", i); 1498 //printf("omp_get_num_threads = %d\n", omp_get_num_threads()); 1499 1500 for (j = 0; j < width; j++) { 1501 1502 e = E[i][j]; 1503 if (e) { 1504 1505 x = j; 1506 y = i; 1507 1508 #ifdef OPENMP 1509 #pragma omp critical 1510 #endif 1511 { 1512 // min max reduction 1513 if (y < Stats[e].ymin) Stats[e].ymin = y; 1514 if (y > Stats[e].ymax) Stats[e].ymax = y; 1515 1516 if (x < Stats[e].xmin) Stats[e].xmin = x; 1517 if (x > Stats[e].xmax) Stats[e].xmax = x; 1518 1519 // + reduction 1520 Stats[e].S += 1; 1521 Stats[e].Sx += x; 1522 Stats[e].Sy += y; 1523 } // omp critical 1524 } // if e 1525 } // j 1526 } // i 1527 } 1528 // -------------------------------------------------------------------------------------------------------- 1529 void imageFeaturesComputation_omp4(uint32** restrict E, int height, int width, RegionStats* restrict Stats) 1530 // -------------------------------------------------------------------------------------------------------- 1531 { 1532 // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0) 1533 #ifdef OPENMP 1534 #pragma omp parallel private(height,width) shared(E,Stats) 1535 { 1536 #endif // OPENMP 1537 int i, j; 1538 1539 uint32 x, y; 1540 uint32 e; 1541 1542 #ifdef OPENMP4 1543 //#pragma omp task depend ( in:E[0:height-1][0:width-1]) depend( inout: E[1:height*width/4]) 1544 #pragma omp task depend( inout: E[1:height*width/4]) 1545 #endif 1546 for (i = 0; i < height; i++) { 1547 for (j = 0; j < width; j++) { 1548 1549 e = E[i][j]; 1550 if (e) { 1551 1552 x = j; 1553 y = i; 1554 1555 1556 // min max reduction 1557 if (y < Stats[e].ymin) Stats[e].ymin = y; 1558 if (y > Stats[e].ymax) Stats[e].ymax = y; 1559 1560 if (x < Stats[e].xmin) Stats[e].xmin = x; 1561 if (x > Stats[e].xmax) Stats[e].xmax = x; 1562 1563 // + reduction 1564 Stats[e].S += 1; 1565 Stats[e].Sx += x; 1566 Stats[e].Sy += y; 1567 } 1568 } 1569 } 1570 #ifdef OPENMP 1571 } 1572 #endif // OPENMP 1573 } 1574 // ------------------------------------------------------------------------------ 1575 void calc_xmin(uint32** restrict E, int height, int width, uint16* restrict Xmin) 1576 // ------------------------------------------------------------------------------ 1577 { 1578 int i, j; 1198 1199 1200 // -------------------------------------------------------------------------------- 1201 void calc_xmin(uint32 ** restrict E, int height, int width, uint16 * restrict Xmin) 1202 // -------------------------------------------------------------------------------- 1203 { 1579 1204 uint32 x; 1580 1205 uint32 e; 1581 /* 1582 #ifdef OPENMP 1583 #pragma omp critical 1584 #endif 1585 { printf("calc xmin %d x %d\n", width, height); } 1586 */ 1587 for (i = 0; i < height; i++) { 1588 for (j = 0; j < width; j++) { 1206 for (int i = 0; i < height; i++) { 1207 for (int j = 0; j < width; j++) { 1589 1208 e = E[i][j]; 1590 1209 if (e) { 1591 1210 x = j; 1592 if (x < Xmin[e]) Xmin[e] = x; 1593 } 1594 } 1595 } 1596 } 1597 // ------------------------------------------------------------------------------ 1598 void calc_xmax(uint32** restrict E, int height, int width, uint16* restrict Xmax) 1599 // ------------------------------------------------------------------------------ 1600 { 1601 int i, j; 1211 if (x < Xmin[e]) { 1212 Xmin[e] = x; 1213 } 1214 } 1215 } 1216 } 1217 } 1218 1219 1220 // -------------------------------------------------------------------------------- 1221 void calc_xmax(uint32 ** restrict E, int height, int width, uint16 * restrict Xmax) 1222 // -------------------------------------------------------------------------------- 1223 { 1602 1224 uint32 x; 1603 1225 uint32 e; 1604 /* 1605 #ifdef OPENMP 1606 #pragma omp critical 1607 #endif 1608 { printf("calc xmax %d x %d\n", width, height); } 1609 */ 1610 for (i = 0; i < height; i++) { 1611 for (j = 0; j < width; j++) { 1226 for (int i = 0; i < height; i++) { 1227 for (int j = 0; j < width; j++) { 1612 1228 e = E[i][j]; 1613 1229 if (e) { … … 1618 1234 } 1619 1235 } 1620 // ------------------------------------------------------------------------------ 1621 void calc_ymin(uint32** restrict E, int height, int width, uint16* restrict Ymin) 1622 // ------------------------------------------------------------------------------ 1623 { 1624 int i, j; 1236 1237 1238 // -------------------------------------------------------------------------------- 1239 void calc_ymin(uint32 ** restrict E, int height, int width, uint16 * restrict Ymin) 1240 // -------------------------------------------------------------------------------- 1241 { 1625 1242 uint32 y; 1626 1243 uint32 e; 1627 /* 1628 #ifdef OPENMP 1629 #pragma omp critical 1630 #endif 1631 { printf("calc ymin %d x %d\n", width, height); } 1632 */ 1633 for(i=0; i<height; i++) { 1634 for(j=0; j<width; j++) { 1244 for (int i = 0; i < height; i++) { 1245 for (int j = 0; j < width; j++) { 1635 1246 e = E[i][j]; 1636 if (e) {1247 if (e) { 1637 1248 y = i; 1638 if(y < Ymin[e]) Ymin[e] = y; 1639 } 1640 } 1641 } 1642 } 1643 // ------------------------------------------------------------------------------ 1644 void calc_ymax(uint32** restrict E, int height, int width, uint16* restrict Ymax) 1645 // ------------------------------------------------------------------------------ 1646 { 1647 int i, j; 1249 if (y < Ymin[e]) { 1250 Ymin[e] = y; 1251 } 1252 } 1253 } 1254 } 1255 } 1256 1257 1258 // -------------------------------------------------------------------------------- 1259 void calc_ymax(uint32 ** restrict E, int height, int width, uint16 * restrict Ymax) 1260 // -------------------------------------------------------------------------------- 1261 { 1648 1262 uint32 y; 1649 1263 uint32 e; 1650 /* 1651 #ifdef OPENMP 1652 #pragma omp critical 1653 #endif 1654 { printf("calc ymax %d x %d\n", width, height); } 1655 */ 1656 for(i=0; i<height; i++) { 1657 for(j=0; j<width; j++) { 1264 for (int i = 0; i < height; i++) { 1265 for (int j = 0; j < width; j++) { 1658 1266 e = E[i][j]; 1659 if (e) {1267 if (e) { 1660 1268 y = i; 1661 if(y > Ymax[e]) Ymax[e] = y; 1662 } 1663 } 1664 } 1665 } 1666 // ------------------------------------------------------------------------ 1667 void calc_s(uint32** restrict E, int height, int width, uint32* restrict S) 1668 // ------------------------------------------------------------------------ 1669 { 1670 int i, j; 1269 if (y > Ymax[e]) { 1270 Ymax[e] = y; 1271 } 1272 } 1273 } 1274 } 1275 } 1276 1277 1278 // -------------------------------------------------------------------------- 1279 void calc_s(uint32 ** restrict E, int height, int width, uint32 * restrict S) 1280 // -------------------------------------------------------------------------- 1281 { 1671 1282 uint32 e; 1672 /* 1673 #ifdef OPENMP 1674 #pragma omp critical 1675 #endif 1676 { printf("calc s %d x %d\n", width, height); } 1677 */ 1678 for(i=0; i<height; i++) { 1679 for(j=0; j<width; j++) { 1283 for (int i = 0; i < height; i++) { 1284 for (int j = 0; j < width; j++) { 1680 1285 e = E[i][j]; 1681 if (e) {1286 if (e) { 1682 1287 S[e] += 1; 1683 1288 } … … 1685 1290 } 1686 1291 } 1687 // -------------------------------------------------------------------------- 1688 void calc_sx(uint32** restrict E, int height, int width, uint32* restrict Sx) 1689 // -------------------------------------------------------------------------- 1690 { 1691 int i, j; 1292 1293 1294 // ---------------------------------------------------------------------------- 1295 void calc_sx(uint32 ** restrict E, int height, int width, uint32 * restrict Sx) 1296 // ---------------------------------------------------------------------------- 1297 { 1692 1298 uint32 e; 1693 /* 1694 #ifdef OPENMP 1695 #pragma omp critical 1696 #endif 1697 { printf("calc sx %d x %d\n", width, height); } 1698 */ 1699 for(i=0; i<height; i++) { 1700 for(j=0; j<width; j++) { 1299 for (int i = 0; i < height; i++) { 1300 for (int j = 0; j < width; j++) { 1701 1301 e = E[i][j]; 1702 if (e) {1302 if (e) { 1703 1303 Sx[e] += j; 1704 1304 } … … 1706 1306 } 1707 1307 } 1708 // -------------------------------------------------------------------------- 1709 void calc_sy(uint32** restrict E, int height, int width, uint32* restrict Sy) 1710 // -------------------------------------------------------------------------- 1711 { 1712 int i, j; 1308 1309 1310 // ---------------------------------------------------------------------------- 1311 void calc_sy(uint32 ** restrict E, int height, int width, uint32 * restrict Sy) 1312 // ---------------------------------------------------------------------------- 1313 { 1713 1314 uint32 e; 1714 /* 1715 #ifdef OPENMP 1716 #pragma omp critical 1717 #endif 1718 { printf("calc sy %d x %d\n", width, height); } 1719 */ 1720 for (i = 0; i < height; i++) { 1721 for (j = 0; j < width; j++) { 1315 for (int i = 0; i < height; i++) { 1316 for (int j = 0; j < width; j++) { 1722 1317 e = E[i][j]; 1723 1318 if (e) { … … 1727 1322 } 1728 1323 } 1729 // --------------------------------------------------------------------------------------------------------------------------------------------------------------- 1730 void imageFeaturesComputation_omp5(uint32** E, int height, int width, uint16* Xmin, uint16* Xmax, uint16* Ymin, uint16* Ymax, uint32* S, uint32* Sx, uint32* Sy) 1731 // --------------------------------------------------------------------------------------------------------------------------------------------------------------- 1732 { 1733 // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0) 1734 #ifdef OPENMP 1735 #pragma omp parallel shared(E,Xmin,Xmax,Ymin,Ymax,S,Sx,Sy) 1736 // ne sourtout pas mettre height et width en private 1737 { 1738 #endif // OPENMP 1739 1740 int id; // thread number 1741 1742 #ifdef OPENMP 1743 id = omp_get_thread_num(); 1744 #else 1745 id = 1; 1746 #endif 1747 1748 //printf("thread id = %d h = %d w = %d\n", id, height, width); 1749 1750 if (id == 0) { calc_xmin(E, height, width, Xmin); } 1751 if (id == 1) { calc_xmax(E, height, width, Xmax); } 1752 if (id == 2) { calc_ymin(E, height, width, Ymin); } 1753 if (id == 3) { calc_ymax(E, height, width, Ymax); } 1754 1755 if (id == 4) { calc_s (E, height, width, S); } 1756 if (id == 5) { calc_sx(E, height, width, Sx); } 1757 if (id == 6) { calc_sy(E, height, width, Sy); } 1758 #ifdef OPENMP 1759 } 1760 #endif // OPENMP 1761 } 1762 // ------------------------------------------------------ 1763 int RegionStats_Compare(RegionStats *S1, RegionStats *S2) 1764 // ------------------------------------------------------ 1324 1325 1326 // -------------------------------------------------------- 1327 int RegionStats_Compare(RegionStats * S1, RegionStats * S2) 1328 // -------------------------------------------------------- 1765 1329 { 1766 1330 //puts("----------------------------------------"); 1767 1331 //display_RegionStats(S1, "S1"); 1768 1332 //display_RegionStats(S2, "S2"); 1769 if ((S1->xmin == S2->xmin) &&1333 if ((S1->xmin == S2->xmin) && 1770 1334 (S1->xmax == S2->xmax) && 1771 1335 (S1->ymin == S2->ymin) && 1772 1336 (S1->ymax == S2->ymax) && 1773 (S1->S == S2->S) &&1774 (S1->Sx == S2->Sx) &&1775 (S1->Sy == S2->Sy ))1337 (S1->S == S2->S) && 1338 (S1->Sx == S2->Sx) && 1339 (S1->Sy == S2->Sy)) { 1776 1340 return 1; 1777 else 1341 } 1342 else { 1778 1343 return 0; 1779 } 1780 // ---------------------------------------------------------------------------- 1781 int RegionStatsVector_Compare(RegionStats *S1, int i0, int i1, RegionStats *S2) 1782 // ---------------------------------------------------------------------------- 1783 { 1784 int i; 1344 } 1345 } 1346 1347 1348 // ------------------------------------------------------------------------------ 1349 int RegionStatsVector_Compare(RegionStats * S1, int i0, int i1, RegionStats * S2) 1350 // ------------------------------------------------------------------------------ 1351 { 1785 1352 int c; // resultat de la comparaison 0 = identique, 1 = different 1786 1353 int s = 0; // somme 1787 1354 1788 for (i=i0; i<=i1; i++) {1355 for (int i = i0; i <= i1; i++) { 1789 1356 c = RegionStats_Compare(&S1[i], &S2[i]); 1790 1357 s += c; 1791 1792 /*if(c) {1793 puts("---------------------------------------------------");1794 printf("e = %d\n", i);1795 display_RegionStats(&S1[i], NULL);1796 display_RegionStats(&S2[i], NULL);1797 }*/1798 1799 1358 } 1800 1359 return s; 1801 1360 } 1802 // ------------------------------------------------------------------------------------------ 1803 int RegionStatsVector_Match(RegionStats *S1, int i0, int i1, RegionStats *S2, int j0, int j1) 1804 // ------------------------------------------------------------------------------------------ 1805 { 1806 int i, j, pos; 1361 1362 1363 // -------------------------------------------------------------------------------------------- 1364 int RegionStatsVector_Match(RegionStats * S1, int i0, int i1, RegionStats * S2, int j0, int j1) 1365 // -------------------------------------------------------------------------------------------- 1366 { 1367 int j, pos; 1807 1368 int c; // resultat de la comparaison 1 = identique, 0 = different 1808 1369 int a; // accumulateur de c 1809 1370 int s = 0; // somme 1810 1371 int perm = 0; // permutation de numero de features 1811 int n1 = i1 -i0+1;1812 int n2 = j1 -j0+1;1372 int n1 = i1 - i0 + 1; 1373 int n2 = j1 - j0 + 1; 1813 1374 1814 1375 //printf("[RegionStatsVector_Match]: [%d..%d]=%d vs [%d..%d]=%d\n", i0, i1, n1, j0,j1,n2); … … 1818 1379 } 1819 1380 1820 for (i = i0; i <= i1; i++) {1381 for (int i = i0; i <= i1; i++) { 1821 1382 a = 0; 1822 1383 pos = -1; … … 1825 1386 c = RegionStats_Compare(&S1[i], &S2[j]); 1826 1387 a = a + c; 1827 if (c) pos = j; 1388 if (c) { 1389 pos = j; 1390 } 1828 1391 } 1829 1392 s += a; … … 1833 1396 for (j = j0; j <= j1; j++) { 1834 1397 c = RegionStats_Compare(&S1[i], &S2[j]); 1835 if (c) printf("S2[%d] ", j); 1836 } 1837 printf(""); 1838 giet_pthread_exit(""); 1398 if (c) { 1399 printf("S2[%d] ", j); 1400 } 1401 } 1402 printf("\n"); 1403 exit(1); 1839 1404 } 1840 1405 … … 1855 1420 return n1 - s; 1856 1421 } 1422 1423 // Local Variables: 1424 // tab-width: 4 1425 // c-basic-offset: 4 1426 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 1427 // indent-tabs-mode: nil 1428 // End: 1429 1430 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 1431
Note: See TracChangeset
for help on using the changeset viewer.