Ignore:
Timestamp:
May 6, 2016, 3:06:29 PM (8 years ago)
Author:
meunier
Message:
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/src/ecc_features.c

    r798 r821  
    1010// Caracteristiques d'une region / label
    1111
    12 //#pragma message("------------------")
    13 //#pragma message("--- Features.c ---")
    14 //#pragma message("------------------")
    15 
    1612#include <stdio.h>
    1713#include <stddef.h>
    1814#include <stdlib.h>
    1915#include <malloc.h>
    20 
    21 
    22 #ifdef CLI
     16#include <string.h>
     17
     18
    2319#include "nrc_os_config.h"
     20#include "config.h"
    2421#include "nrc.h"
    25 #endif
    26 
    2722
    2823
     
    3126    #include <sys/stat.h>
    3227    #include <fcntl.h>
     28    #include <unistd.h>
    3329#endif
    3430
    3531
    36 #ifdef OPENMP
    37 #include <omp.h>
    38 #endif
    39 
    4032#include "ecc_features.h"
    41 //#include "label.h"
     33
     34#define BUFF_SIZE 1024 // for snprintf
     35
     36
     37// -------------------------------------------------------------
     38void RegionStats_Constructor(RegionStats ** Stats, uint32 nemax)
     39// -------------------------------------------------------------
     40{
     41    *Stats = RegionStats_pConstructor(nemax);
     42}
     43
     44
     45// -------------------------------------------------
     46RegionStats * 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
    4261
    4362// ------------------------------------------------------------
    44 void RegionStats_Constructor(RegionStats **Stats, uint32 nemax)
     63void RegionStats_Destructor(RegionStats ** Stats, uint32 nemax)
    4564// ------------------------------------------------------------
    4665{
    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 {
    6666    RegionStats_pDestructor(*Stats, nemax);
    6767}
    68 // -----------------------------------------------------------
    69 void RegionStats_pDestructor(RegionStats *Stats, uint32 nemax)
    70 // -----------------------------------------------------------
     68
     69
     70// ------------------------------------------------------------
     71void RegionStats_pDestructor(RegionStats * Stats, uint32 nemax)
     72// ------------------------------------------------------------
    7173{
    7274    RegionStats_Clear(Stats, nemax);
    7375    free(Stats);
    7476}
    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// ------------------------------------------------------
     80void RegionStats_Clear(RegionStats * Stats, uint32 nemax)
     81// ------------------------------------------------------
     82{
     83    for (int i = 0; i < (int) nemax; i++) {
    8184        Stats[i].xmin = 65535;
    8285        Stats[i].xmax = 0;
     
    8689        Stats[i].S = 0;
    8790       
    88         Stats[i].x = 0;
    89         Stats[i].y = 0;
    90        
    9191        Stats[i].Sx = 0;
    9292        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);
    9895#endif
    9996    }
    10097}
    101 // ----------------------------------------
    102 void RegionStats_Clear1(RegionStats *stats)
    103 // ----------------------------------------
     98
     99
     100// -----------------------------------------
     101void RegionStats_Clear1(RegionStats * stats)
     102// -----------------------------------------
    104103{
    105104    stats->xmin = 0;
     
    110109    stats->S = 0;
    111110   
    112     stats->x = 0;
    113     stats->y = 0;
    114    
    115111    stats->Sx = 0;
    116112    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// -----------------------------------------
     117int RegionStats_Create_File(char * filename)
     118// -----------------------------------------
    126119{
    127120    int fd;
     
    130123    if (fd < 0) {
    131124        printf("RegionStats_Open_File : can't create file %s\n", filename);
    132         giet_pthread_exit("");
     125        exit(1);
    133126    }
    134127    return fd;
    135128}
    136 // ----------------------------------------
    137 int RegionStats_Open_File(char *filename)
    138 // ----------------------------------------
     129
     130
     131// ---------------------------------------
     132int RegionStats_Open_File(char * filename)
     133// ---------------------------------------
    139134{
    140135    int fd;
     
    143138    if (fd < 0) {
    144139        printf("RegionStats_Open_File : can't open file %s\n", filename);
    145         giet_pthread_exit("");
     140        exit(1);
    146141    }
    147142    return fd;
    148143}
    149 // ---------------------------------
     144
     145
     146// --------------------------------
    150147void RegionStats_Close_File(int fd)
    151 // ---------------------------------
     148// --------------------------------
    152149{
    153150    close(fd);
    154151}
    155 // ---------------------------------
     152
     153
     154#if 0 // pb : fscanf requires manipulating FILE *
     155// --------------------------------
    156156int RegionStats_Read_Header(int fd)
    157 // ---------------------------------
     157// --------------------------------
    158158{
    159159    int ne = 0;
    160     // @QM giet
    161160    fscanf(fd, "%d", &ne);
    162161    return ne;
    163162}
    164 // -------------------------------------------
     163#endif
     164
     165
     166// ------------------------------------------
    165167void 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
    170177// --------------------------------------------------------------
    171 void RegionStats_Read_Stats1(int fd, int ne, RegionStats *Stats)
     178void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats)
    172179// --------------------------------------------------------------
    173180{
     
    184191               &(Stats[i].Sx),
    185192               &(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}
    224195#endif
    225 }
     196
     197
    226198// ---------------------------------------------------------------
    227 void RegionStats_Write_Stats1(RegionStats *Stats, int ne, int fd)
     199void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd)
    228200// ---------------------------------------------------------------
    229201{
    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",
    234206                i,
    235207                Stats[i].xmin,
     
    241213                Stats[i].Sx,
    242214                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// ---------------------------------------------------------------------------------------------------
     221void RegionStats_Write_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, int fd)
     222// ---------------------------------------------------------------------------------------------------
    248223{
    249224    uint32 e;
     225    char buff[BUFF_SIZE];
    250226   
    251227    for (e = ne0; e <= ne1; e++) {
    252228        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",
    254230                    e,
    255231                    Stats[e].xmin,
     
    261237                    Stats[e].Sx,
    262238                    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
    292245// -----------------------------------------------------------------
    293 void RegionStats_Write_pStats1(RegionStats **Stats, int ne, int fd)
     246void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd)
    294247// -----------------------------------------------------------------
    295248{
    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",
    300253                i,
    301254                Stats[i]->xmin,
     
    306259                Stats[i]->Sx,
    307260                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// --------------------------------------------------------------------------
     268void RegionStats_Load_Stats1(char * filename, int * ne, RegionStats ** Stats)
     269// --------------------------------------------------------------------------
    338270{
    339271    int fd;
     
    347279    RegionStats_Close_File(fd);
    348280}
    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// --------------------------------------------------------------------------
     284void RegionStats_MLoad_Stats1(char * filename, int * ne, RegionStats * Stats)
     285// --------------------------------------------------------------------------
    370286{
    371287    int fd;
     
    377293    RegionStats_Close_File(fd);
    378294}
     295#endif
     296
    379297// -----------------------------------------------------------------------
    380 void RegionStats_MLoad_Stats2(char *filename, int *ne, RegionStats *Stats)
     298void RegionStats_Save_Stats1(RegionStats * Stats, int ne, char * filename)
    381299// -----------------------------------------------------------------------
    382 {
    383 #ifdef REGION_STATS2
    384     int fd
    385    
    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 #else
    392     nrerror("RegionStats_MLoad_Stats2 : REGION_STATS2 not defined");
    393 #endif
    394 }
    395 // ---------------------------------------------------------------------
    396 void RegionStats_Save_Stats1(RegionStats *Stats, int ne, char *filename)
    397 // ---------------------------------------------------------------------
    398300{
    399301    int fd;
     
    405307    RegionStats_Close_File(fd);
    406308}
    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// -------------------------------------------------------------------------
     312void RegionStats_Save_pStats1(RegionStats ** Stats, int ne, char * filename)
     313// -------------------------------------------------------------------------
    426314{
    427315    int fd;
     
    433321    RegionStats_Close_File(fd);
    434322}
    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// ----------------------------------------------------------------------
     326void RegionStats_Display_Stats1(RegionStats * Stats, int ne, char * name)
     327// ----------------------------------------------------------------------
     328{
    457329    if (name != NULL) {
    458330        printf("%s : %d\n", name, ne);
     
    461333        printf("RegionStats : %d\n", ne);
    462334    }
    463     for (i = 1; i <= ne; i++) {
     335    for (int i = 1; i <= ne; i++) {
    464336        printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n",
    465337               i,
     
    473345    }
    474346}
    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// ------------------------------------------------------------------------
     350void RegionStats_Display_pStats1(RegionStats ** Stats, int ne, char * name)
     351// ------------------------------------------------------------------------
     352{
    482353    if (name != NULL) {
    483354        printf("%s : %d\n", name, ne);
     
    486357        printf("RegionStats : %d\n", ne);
    487358    }
    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++) {
    522360        printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n",
    523361               i,
     
    531369    }
    532370}
    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// ----------------------------------------------------------------------------------------------
     374void RegionStats_SetRectangle(RegionStats * Stats, int e, int ymin, int ymax, int xmin, int xmax)
     375// ----------------------------------------------------------------------------------------------
    569376{
    570377    Stats[e].ymin = ymin;
     
    573380    Stats[e].xmax = xmax;
    574381}
    575 // -------------------------------------------------------
    576 void RegionStats_Copy1(RegionStats *src, RegionStats *dst)
    577 // -------------------------------------------------------
     382
     383
     384// ---------------------------------------------------------
     385void RegionStats_Copy1(RegionStats * src, RegionStats * dst)
     386// ---------------------------------------------------------
    578387{
    579388    dst->xmin = src->xmin;
     
    584393    dst->S    = src->S;
    585394   
    586     dst->x    = src->x;
    587     dst->y    = src->y;
    588    
    589395    dst->Sx   = src->Sx;
    590396    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
    615400// ===============================
    616401// === nouvelles versions 2009 ===
    617402// ===============================
    618403
    619 // -------------------------------------------
    620 RegionStats* RegionStatsVector(int i0, int i1)
    621 // -------------------------------------------
     404// --------------------------------------------
     405RegionStats * RegionStatsVector(int i0, int i1)
     406// --------------------------------------------
    622407// allocate a float vector with subscript range v[i0..i1]
    623408{
     
    625410   
    626411    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);
    629417    return v - i0 + NR_END;
    630418}
    631 // ----------------------------------------------------------
    632 RegionStats* RegionStatsVector0(int i0, int i1)
    633 // ----------------------------------------------------------
     419
     420
     421#if TARGET_OS == GIETVM
     422// -----------------------------------------------------------------
     423RegionStats * remote_RegionStatsVector(int i0, int i1, int x, int y)
     424// -----------------------------------------------------------------
    634425// allocate a float vector with subscript range v[i0..i1]
    635426{
    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// ---------------------------------------------
     441RegionStats * RegionStatsVector0(int i0, int i1)
     442// ---------------------------------------------
     443// allocate a float vector with subscript range v[i0..i1]
     444{
     445    RegionStats * v;
    637446   
    638447    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    }
    641452    return v - i0 + NR_END;
    642453}
    643 // ----------------------------------------------------------------------
    644 void free_RegionStatsVector(RegionStats *v, int i0, int i1)
    645 // ----------------------------------------------------------
     454
     455
     456// ---------------------------------------------------------
     457void free_RegionStatsVector(RegionStats * v, int i0, int i1)
     458// ---------------------------------------------------------
    646459// free a RegionStats vector allocated with vector()
    647460{
    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// -------------------------------------------------------------
     466RegionStats ** RegionStatsMatrix(int i0, int i1, int j0, int j1)
     467// -------------------------------------------------------------
    653468
    654469// 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// --------------------------------------------------------------
     501RegionStats ** RegionStatsMatrix0(int i0, int i1, int j0, int j1)
     502// --------------------------------------------------------------
     503// allocate a float matrix with subscript range m[nrl..nrh][ncl..nch]
    655504{
    656505    long i;
    657506    long nrow = i1 - i0 + 1;
    658507    long ncol = j1 - j0 + 1;
    659     RegionStats **m;
     508    RegionStats ** m;
    660509   
    661510    // 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    }
    664515    m += NR_END;
    665516    m -= i0;
    666517   
    667518    // 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    }
    670523    m[i0] += NR_END;
    671524    m[i0] -= j0;
    672525   
    673     for(i = i0 + 1; i <= i1; i++) {
     526    for (i = i0 + 1; i <= i1; i++) {
    674527        m[i] = m[i - 1] + ncol;
    675528    }
     
    678531    return m;
    679532}
    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// --------------------------------------------------------------------------
     536void 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// -----------------------------------
     545void zero_RegionStats(RegionStats * x)
     546// -----------------------------------
    716547{
    717548    x->xmin = 32767;
     
    723554    x->Sx = 0;
    724555    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// ---------------------------------------------------------
     560void zero_RegionStatsVector(RegionStats * v, int i0, int i1)
     561// ---------------------------------------------------------
     562{
     563    for (int i = i0; i <= i1; i++) {
    738564        zero_RegionStats(&v[i]);
    739565    }
    740566}
    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// --------------------------------------------------------------------------
     570void 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++) {         
    748575            zero_RegionStats(&(m[i][j]));
    749576        }
    750577    }
    751578}
    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// ---------------------------------------------------
     582void display_RegionStats(RegionStats * x, char * name)
     583// ---------------------------------------------------
     584{
     585    if (name != NULL) {
     586        printf("%s : \n", name);
     587    }
     588 
    759589    printf("%4d %4d %4d %4d %6d %8d %8d\n",
    760590           x->xmin,
     
    766596           x->Sx,
    767597           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// ------------------------------------------------------------------------
     602void 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++) {
    792612        printf("#%3d: ", i);
    793613        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// ------------------------------------------------------------------------------------------
     619void 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++) {
    806631            printf("#%3d: ", i);
    807632            display_RegionStats(&(m[i][j]), NULL);
     
    809634    }
    810635}
    811 // ----------------------------------------------
    812 void save_RegionStats(RegionStats *x, char *name)
    813 // ----------------------------------------------
     636
     637
     638// ------------------------------------------------
     639void save_RegionStats(RegionStats * x, char * name)
     640// ------------------------------------------------
    814641{
    815642    int fd = -1;
     643    char buff[BUFF_SIZE];
    816644   
    817645    if (name == NULL) {
     
    824652        printf("*** Erreur : ouverture du fichier %s dans %s\n", name, __func__);
    825653    }
    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,
    831656            x->xmin,
    832657            x->xmax,
     
    837662            x->Sx,
    838663            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);
    855665   
    856666    if (name) {
     
    858668    }   
    859669}
    860 // --------------------------------------------------------------------
    861 void save_RegionStatsVector(RegionStats *v, int i0, int i1, char *name)
    862 // --------------------------------------------------------------------
    863 {
    864     int i;
     670
     671
     672// ----------------------------------------------------------------------
     673void save_RegionStatsVector(RegionStats * v, int i0, int i1, char * name)
     674// ----------------------------------------------------------------------
     675{
    865676    int fd;
     677    char buff[BUFF_SIZE];
    866678   
    867679    if (name == NULL) {
     
    870682    fd = RegionStats_Create_File(name);
    871683   
    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++) {
    875688        printf("#%3d: ", i);
    876689        save_RegionStats(&v[i], NULL);
    877         printf("");
    878690    }
    879691    RegionStats_Close_File(fd);
    880692}
    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// ---------------------------------------------------------------------------------------
     696void save_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name)
     697// ---------------------------------------------------------------------------------------
     698{
    886699    int fd;
     700    char buff[BUFF_SIZE];
    887701   
    888702    if (name == NULL) {
     
    891705    fd = RegionStats_Create_File(name);
    892706   
    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);
    898714            save_RegionStats(&m[i][j], NULL);
    899715        }
    900         printf("");
    901716    }
    902717    RegionStats_Close_File(fd);
    903718}
    904 // ------------------------------------------------------------------------------
    905 void RegionStats_Calc1_Features_1Pass(RegionStats *Stats, uint32 e, int i, int j)
    906 // ------------------------------------------------------------------------------
     719
     720
     721// -------------------------------------------------------------------------------
     722void RegionStats_Calc1_Features_1Pass(RegionStats * Stats, uint32 e, int i, int j)
     723// -------------------------------------------------------------------------------
    907724{
    908725    // calcul sur 1 point et non sur toute l'image
    909726        // Rectangle
    910727       
    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    }
    916741   
    917742        // Moment1
     
    922747        return;
    923748}
     749
     750
    924751// --------------------------------
    925752// --- fonctions de 2013 ----------
    926753// --------------------------------
    927 // -------------------------------------------------------------------------------------------
    928 void RegionStats_Calc_Rectangle_Moment1(uint32 **E, int height, int width, RegionStats *Stats)
    929 // -------------------------------------------------------------------------------------------
    930 {
    931     int i, j;
     754// ---------------------------------------------------------------------------------------------
     755void RegionStats_Calc_Rectangle_Moment1(uint32 ** E, int height, int width, RegionStats * Stats)
     756// ---------------------------------------------------------------------------------------------
     757{
    932758    uint32 x, y;
    933759    uint32 e;
    934760   
    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++) {
    937763           
    938764            e = E[i][j];
    939765            if (e) {
    940                
    941766                x = j;
    942767                y = i;
    943768               
    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                }
    946775               
    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                }
    949782               
    950783                Stats[e].S  += 1;
     
    955788    }
    956789}
    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// -------------------------------------------------------------------------------------------------------------------------------
     793void RegionStats_calc_Status(RegionStats * Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 * status)
     794// -------------------------------------------------------------------------------------------------------------------------------
    960795{
    961796    uint16 xmin, xmax, ymin, ymax, xsize, ysize;
     
    983818    }
    984819}
    985 // --------------------------------------------------------------------------
    986 uint32 RegionStats_UpdateEQ_with_Status(uint8 *status, uint32 ne, uint32 *EQ)
    987 // --------------------------------------------------------------------------
     820
     821
     822// ----------------------------------------------------------------------------
     823uint32 RegionStats_UpdateEQ_with_Status(uint8 * status, uint32 ne, uint32 * EQ)
     824// ----------------------------------------------------------------------------
    988825{
    989826    uint32 e;
     
    999836    return na;
    1000837}
    1001 // ----------------------------------------------------------------------------
    1002 void RegionStats_UpdateStats_with_EQ(uint32 *EQ, uint32 ne, RegionStats *Stats)
    1003 // ----------------------------------------------------------------------------
     838
     839
     840// ------------------------------------------------------------------------------
     841void RegionStats_UpdateStats_with_EQ(uint32 * EQ, uint32 ne, RegionStats * Stats)
     842// ------------------------------------------------------------------------------
    1004843{
    1005844    uint32 e, a;
     
    1015854    }
    1016855}
    1017 // ---------------------------------------------------------------------------
    1018 void featuresComputation(uint32 **E, int height,int width, RegionStats *Stats)
    1019 // ---------------------------------------------------------------------------
     856
     857
     858// -----------------------------------------------------------------------------
     859void featuresComputation(uint32 ** E, int height,int width, RegionStats * Stats)
     860// -----------------------------------------------------------------------------
    1020861{
    1021862    //uint32 nemax = height * width /2;   
    1022863    RegionStats_Calc_Rectangle_Moment1(E, height, width, Stats);   
    1023864}
    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// ---------------------------------------------------------------------------
     868void pointFeaturesComputation( uint32 ** E, int i, int j, RegionStats * Stats)
     869// ---------------------------------------------------------------------------
    1034870{
    1035871    uint32 x, y;
     
    1042878        y = i;
    1043879       
    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        }
    1049893       
    1050894        Stats[e].S  += 1;
     
    1053897    }
    1054898}
    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// -----------------------------------------------------------------------------
     902void lineFeaturesComputation(uint32 ** E, int i, int width, RegionStats * Stats)
     903// -----------------------------------------------------------------------------
    1065904{
    1066905    // line RegionStats_Calc_Rectangle_Moment1
    1067     int j;
    1068906   
    1069907    uint32 x, y;
    1070908    uint32 e;
    1071909   
    1072     for (j = 0; j < width; j++) {
     910    for (int j = 0; j < width; j++) {
    1073911       
    1074912        e = E[i][j];
     
    1078916            y = i;
    1079917           
    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            }
    1082924           
    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            }
    1085931           
    1086932            Stats[e].S  += 1;
     
    1090936    }
    1091937}
    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// --------------------------------------------------------------------------------------
     941void bandFeaturesComputation(uint32 ** E, int i0, int i1, int width, RegionStats * Stats)
     942// --------------------------------------------------------------------------------------
     943{
     944    for (int i = i0; i <= i1; i++) {
    1104945        lineFeaturesComputation(E, i, width, Stats);
    1105946    }
    1106947}
    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// -----------------------------------------------------------------------------------
     951void imageFeaturesComputation(uint32 ** E, int height, int width, RegionStats * Stats)
     952// -----------------------------------------------------------------------------------
    1117953{
    1118954    // image RegionStats_Calc_Rectangle_Moment1
    1119     int i;
    1120     for (i = 0; i < height; i++) {
     955    for (int i = 0; i < height; i++) {
    1121956        lineFeaturesComputation(E, i, width, Stats);
    1122957    }
    1123958}
     959
     960
    1124961// ---------------------------------------
    1125962// --- Fonctions 2014 --------------------
    1126963// ---------------------------------------
    1127964
    1128 // --------------------------------------------------------------------------------------
    1129 void RegionStats_Copy_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index)
    1130 // --------------------------------------------------------------------------------------                                 
     965// ---------------------------------------------------------------------------------------
     966void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index)
     967// ---------------------------------------------------------------------------------------                                 
    1131968{
    1132969    // R[dst] = R[src]
    1133970    RegionStats_Copy1(&Stats[src_index], &Stats[dst_index]);
    1134971}
    1135 // --------------------------------------------------------------------------------------------
    1136 void RegionStats_Accumulate_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index)
    1137 // --------------------------------------------------------------------------------------------                                 
     972
     973
     974// ---------------------------------------------------------------------------------------------
     975void RegionStats_Accumulate_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index)
     976// ---------------------------------------------------------------------------------------------                                 
    1138977{
    1139978    // R[dst] += R[src]
     
    1147986    Stats[dst_index].Sy += Stats[src_index].Sy;   
    1148987}
    1149 // -----------------------------------------------------------------------------------------------------
    1150 void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name)
    1151 // -----------------------------------------------------------------------------------------------------
     988
     989
     990// ---------------------------------------------------------------------------------------------------------------------------
     991void RegionStats_DisplayStats_Sparse(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name, int * start_index)
     992// ---------------------------------------------------------------------------------------------------------------------------
    1152993{
    1153994    // n'affiche que les racines.
     
    1156997    uint32 na; // compteur
    1157998   
    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);
    11621005   
    11631006    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            }
    11661015            display_RegionStats(&Stats[e], NULL);
    11671016        }
    11681017    }
    11691018}
    1170 // ----------------------------------------------------------------------------------------------------
    1171 void RegionStats_DisplayStats_Range(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name)
    1172 // ----------------------------------------------------------------------------------------------------
     1019
     1020
     1021// -------------------------------------------------------------------------------------------------------
     1022void RegionStats_DisplayStats_Range(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name)
     1023// -------------------------------------------------------------------------------------------------------
    11731024{
    11741025    // affichage dense (apres un pack)
     
    11761027    uint32 e;
    11771028   
    1178     if (name) printf(name);
     1029    if (name) {
     1030        printf(name);
     1031    }
    11791032   
    11801033    for (e = ne0; e <= ne1; e++) {
     
    11831036    }
    11841037}
    1185 // --------------------------------------------------------------------------------------------------------
    1186 void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename)
    1187 // --------------------------------------------------------------------------------------------------------
     1038
     1039
     1040// -----------------------------------------------------------------------------------------------------------
     1041void RegionStats_Save_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, char * filename)
     1042// -----------------------------------------------------------------------------------------------------------
    11881043{
    11891044    int fd;
     
    11971052    RegionStats_Close_File(fd);
    11981053}
    1199 // ------------------------------------------------------------------------------------------
    1200 uint32 RegionStats_Count_Roots_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1)
    1201 // ------------------------------------------------------------------------------------------
     1054
     1055
     1056// --------------------------------------------------------------------------------------------
     1057uint32 RegionStats_Count_Roots_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1)
     1058// --------------------------------------------------------------------------------------------
    12021059{
    12031060    uint32 e, c = 0; // compteur
     
    12101067    return c;
    12111068}
    1212 // ---------------------------------------------------------------------------------
    1213 uint32 RegionStats_Count_Roots_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax)
    1214 // ---------------------------------------------------------------------------------
     1069
     1070
     1071// -----------------------------------------------------------------------------------
     1072uint32 RegionStats_Count_Roots_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax)
     1073// -----------------------------------------------------------------------------------
    12151074{
    12161075    return RegionStats_Count_Roots_Sparse(Stats, EQ, 1, nemax);
    12171076}
    1218 // -------------------------------------------------------------------------------------------
    1219 uint32 RegionStats_Count_Labels_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1)
    1220 // -------------------------------------------------------------------------------------------
     1077
     1078
     1079// ---------------------------------------------------------------------------------------------
     1080uint32 RegionStats_Count_Labels_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1)
     1081// ---------------------------------------------------------------------------------------------
    12211082{
    12221083    uint32 e, c = 0; // compteur
     
    12291090    return c;
    12301091}
    1231 // ----------------------------*-----------------------------------------------------
    1232 uint32 RegionStats_Count_Labels_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax)
    1233 // ---------------------------*------------------------------------------------------
     1092
     1093
     1094// ------------------------------------------------------------------------------------
     1095uint32 RegionStats_Count_Labels_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax)
     1096// ------------------------------------------------------------------------------------
    12341097{
    12351098    return RegionStats_Count_Labels_Sparse(Stats, EQ, 1, nemax);
    12361099}
    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// -----------------------------------------------------------------------
     1103void copy_features_ui32matrix(RegionStats * Stats, uint32 ne, uint32 ** m)
     1104// -----------------------------------------------------------------------
     1105{
     1106    for (int i = 0; i <= (int) ne; i++) {
    12431107       
    12441108        m[i][0] = i;
     
    12601124    }
    12611125}
    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// -----------------------------------------------------------------------
     1129void copy_ui32matrix_features(uint32 ** m, uint32 ne, RegionStats * Stats)
     1130// -----------------------------------------------------------------------
     1131{
     1132    for (int i = 0; i <= (int) ne; i++) {
    12681133       
    12691134        Stats[i].xmin = m[i][2] >> 16;
     
    12771142    }
    12781143}
    1279 // ---------------------------------------------------------------------------
    1280 void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col)
    1281 // ---------------------------------------------------------------------------
     1144
     1145
     1146// ----------------------------------------------------------------------------
     1147void sortv_ui32matrix_col(uint32 ** m, int i0, int i1, int j0, int j1, int col)
     1148// ----------------------------------------------------------------------------
    12821149{
    12831150    // nrsort2 for NRC2
     
    12941161     * instead of copying the lines.
    12951162     */
    1296         int i, j;
    12971163       
    12981164    uint32 x, min, pos;
    12991165        uint32 * ptr;
    13001166       
    1301         for (i = nrl; i < nrh; i++) {
     1167        for (int i = nrl; i < nrh; i++) {
    13021168                min = m[i][nc];
    13031169                pos = i;
    1304                 for (j = i + 1; j <= nrh; j++) {
     1170                for (int j = i + 1; j <= nrh; j++) {
    13051171                        x = m[j][nc];
    13061172                        if (x < min) {
     
    13141180                m[i]   = m[pos];
    13151181                m[pos] = ptr;
    1316                
    13171182        } // i
    1318    
    1319 }
    1320 // ------------------------------------------------------------
    1321 void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax)
    1322 // ------------------------------------------------------------
     1183}
     1184
     1185
     1186// -------------------------------------------------------------
     1187void RegionStats_SortFeatures(RegionStats * Stats, uint32 nemax)
     1188// -------------------------------------------------------------
    13231189{
    13241190    uint32 ** m = NULL;
     
    13301196    copy_ui32matrix_features(m, nemax, Stats);
    13311197}
    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// --------------------------------------------------------------------------------
     1201void calc_xmin(uint32 ** restrict E, int height, int width, uint16 * restrict Xmin)
     1202// --------------------------------------------------------------------------------
     1203{
    15791204    uint32 x;
    15801205    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++) {
    15891208            e = E[i][j];
    15901209            if (e) {
    15911210                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// --------------------------------------------------------------------------------
     1221void calc_xmax(uint32 ** restrict E, int height, int width, uint16 * restrict Xmax)
     1222// --------------------------------------------------------------------------------
     1223{
    16021224    uint32 x;
    16031225    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++) {
    16121228            e = E[i][j];
    16131229            if (e) {
     
    16181234    }
    16191235}
    1620 // ------------------------------------------------------------------------------
    1621 void calc_ymin(uint32** restrict E, int height, int width, uint16* restrict Ymin)
    1622 // ------------------------------------------------------------------------------
    1623 {
    1624     int i, j;
     1236
     1237
     1238// --------------------------------------------------------------------------------
     1239void calc_ymin(uint32 ** restrict E, int height, int width, uint16 * restrict Ymin)
     1240// --------------------------------------------------------------------------------
     1241{
    16251242    uint32 y;
    16261243    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++) {
    16351246            e = E[i][j];
    1636             if(e) {
     1247            if (e) {
    16371248                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// --------------------------------------------------------------------------------
     1259void calc_ymax(uint32 ** restrict E, int height, int width, uint16 * restrict Ymax)
     1260// --------------------------------------------------------------------------------
     1261{
    16481262    uint32 y;
    16491263    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++) {
    16581266            e = E[i][j];
    1659             if(e) {
     1267            if (e) {
    16601268                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// --------------------------------------------------------------------------
     1279void calc_s(uint32 ** restrict E, int height, int width, uint32 * restrict S)
     1280// --------------------------------------------------------------------------
     1281{
    16711282    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++) {
    16801285            e = E[i][j];
    1681             if(e) {
     1286            if (e) {
    16821287                S[e] += 1;
    16831288            }
     
    16851290    }
    16861291}
    1687 // --------------------------------------------------------------------------
    1688 void calc_sx(uint32** restrict E, int height, int width, uint32* restrict Sx)
    1689 // --------------------------------------------------------------------------
    1690 {
    1691     int i, j;
     1292
     1293
     1294// ----------------------------------------------------------------------------
     1295void calc_sx(uint32 ** restrict E, int height, int width, uint32 * restrict Sx)
     1296// ----------------------------------------------------------------------------
     1297{
    16921298    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++) {
    17011301            e = E[i][j];
    1702             if(e) {
     1302            if (e) {
    17031303                Sx[e] += j;
    17041304            }
     
    17061306    }
    17071307}
    1708 // --------------------------------------------------------------------------
    1709 void calc_sy(uint32** restrict E, int height, int width, uint32* restrict Sy)
    1710 // --------------------------------------------------------------------------
    1711 {
    1712     int i, j;
     1308
     1309
     1310// ----------------------------------------------------------------------------
     1311void calc_sy(uint32 ** restrict E, int height, int width, uint32 * restrict Sy)
     1312// ----------------------------------------------------------------------------
     1313{
    17131314    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++) {
    17221317            e = E[i][j];
    17231318            if (e) {
     
    17271322    }
    17281323}
    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// --------------------------------------------------------
     1327int RegionStats_Compare(RegionStats * S1, RegionStats * S2)
     1328// --------------------------------------------------------
    17651329{
    17661330    //puts("----------------------------------------");
    17671331    //display_RegionStats(S1, "S1");
    17681332    //display_RegionStats(S2, "S2");
    1769     if((S1->xmin == S2->xmin) &&
     1333    if ((S1->xmin == S2->xmin) &&
    17701334       (S1->xmax == S2->xmax) &&
    17711335       (S1->ymin == S2->ymin) &&
    17721336       (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)) {
    17761340        return 1;
    1777     else
     1341    }
     1342    else {
    17781343        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// ------------------------------------------------------------------------------
     1349int RegionStatsVector_Compare(RegionStats * S1, int i0, int i1, RegionStats * S2)
     1350// ------------------------------------------------------------------------------
     1351{
    17851352    int c; // resultat de la comparaison 0 = identique, 1 = different
    17861353    int s = 0; // somme
    17871354   
    1788     for(i=i0; i<=i1; i++) {
     1355    for (int i = i0; i <= i1; i++) {
    17891356        c = RegionStats_Compare(&S1[i], &S2[i]);
    17901357        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            
    17991358    }
    18001359    return s;
    18011360}
    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// --------------------------------------------------------------------------------------------
     1364int RegionStatsVector_Match(RegionStats * S1, int i0, int i1, RegionStats * S2, int j0, int j1)
     1365// --------------------------------------------------------------------------------------------
     1366{
     1367    int j, pos;
    18071368    int c; // resultat de la comparaison 1 = identique, 0 = different
    18081369    int a; // accumulateur de c
    18091370    int s = 0; // somme
    18101371    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;
    18131374   
    18141375    //printf("[RegionStatsVector_Match]: [%d..%d]=%d vs [%d..%d]=%d\n", i0, i1, n1, j0,j1,n2);
     
    18181379    }
    18191380   
    1820     for (i = i0; i <= i1; i++) {
     1381    for (int i = i0; i <= i1; i++) {
    18211382        a   =  0;
    18221383        pos = -1;
     
    18251386            c = RegionStats_Compare(&S1[i], &S2[j]);
    18261387            a = a + c;
    1827             if (c) pos = j;
     1388            if (c) {
     1389                pos = j;
     1390            }
    18281391        }
    18291392        s += a;
     
    18331396            for (j = j0; j <= j1; j++) {
    18341397                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);
    18391404        }
    18401405       
     
    18551420    return n1 - s;
    18561421}
     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.