void test_constructors() { cout << "test_constructors" << endl; sc_time t1; cout << t1 << endl; sc_time t2a( 0, SC_SEC ); cout << t2a << endl; sc_time t2b( 1.2345, SC_NS ); cout << t2b << endl; sc_time t2c( 1.2341, SC_NS ); cout << t2c << endl; sc_time t2d( 1, SC_FS ); cout << t2d << endl; sc_time t2e( -1.2345, SC_NS ); cout << t2e << endl; sc_time t2f( -1.2341, SC_NS ); cout << t2f << endl; char v1 = 1; signed char v2 = 2; unsigned char v3 = 3; short v4 = 4; unsigned short v5 = 5; int v6 = 6; unsigned int v7 = 7; long v8 = 8; unsigned long v9 = 9; float v10 = 10; double v11 = 11; sc_time t2g( v1, SC_NS ); cout << t2g << endl; sc_time t2h( v2, SC_NS ); cout << t2h << endl; sc_time t2i( v3, SC_NS ); cout << t2i << endl; sc_time t2j( v4, SC_NS ); cout << t2j << endl; sc_time t2k( v5, SC_NS ); cout << t2k << endl; sc_time t2l( v6, SC_NS ); cout << t2l << endl; sc_time t2m( v7, SC_NS ); cout << t2m << endl; sc_time t2n( v8, SC_NS ); cout << t2n << endl; sc_time t2o( v9, SC_NS ); cout << t2o << endl; sc_time t2p( v10, SC_NS ); cout << t2p << endl; sc_time t2q( v11, SC_NS ); cout << t2q << endl; sc_time t3a( 0, SC_SEC ); cout << t3a << endl; sc_time t3b( 1.2341, true ); cout << t3b << endl; sc_time t3c( 1.2345, true ); cout << t3c << endl; sc_time t3d( -1.2341, true ); cout << t3d << endl; sc_time t3e( -1.2345, true ); cout << t3e << endl; sc_time t3f( 1.2345, false ); cout << t3f << endl; sc_time t3g( 1.5432, false ); cout << t3g << endl; sc_time t3h( -1.2345, false ); cout << t3h << endl; sc_time t3i( -1.5432, false ); cout << t3i << endl; #if !defined( _MSC_VER ) sc_time t4a( 0ull, true ); cout << t4a << endl; sc_time t4b( 25ull, true ); cout << t4b << endl; sc_time t4c( 25ull, false ); cout << t4c << endl; #else sc_time t4a( 0ui64, true ); cout << t4a << endl; sc_time t4b( 25ui64, true ); cout << t4b << endl; sc_time t4c( 25ui64, false ); cout << t4c << endl; #endif sc_time t5( t4c ); cout << t5 << endl; }
/* ==================================== */ int32_t lattribute( struct xvimage *img, /* image de depart */ int32_t connex, /* 4, 8 */ int32_t typregion, /* = <LABMIN | LABMAX | LABPLATEAU> */ int32_t attrib, /* 0: surface, 1: perimetre, 2: circularite, 3: nb. trous, 4: excentricite, 5: orientation, 6: diamètre vertical, 7: diamètre horizontal */ int32_t seuil, /* en dessous (<=) de seuil, l'attribut est mis a 0 */ struct xvimage *lab, /* resultat: image d'attributs */ int32_t *nlabels) /* resultat: nombre de regions traitees */ /* ==================================== */ #undef F_NAME #define F_NAME "lattribute" { int32_t k, l; index_t w, x, y, z; uint8_t *SOURCE = UCHARDATA(img); int32_t *LABEL = SLONGDATA(lab); index_t rs = rowsize(img); index_t cs = colsize(img); index_t d = depth(img); index_t N = rs * cs; /* taille image */ Lifo * LIFO; int32_t label; int32_t area; int32_t perim; int32_t min, max; int32_t val_attrib; double mx1, my1; // cumuls des variables x et y double mx2, my2, mxy2; // cumuls des x^2, y^2 et xy int32_t incr_vois; if (datatype(lab) != VFF_TYP_4_BYTE) { fprintf(stderr, "%s: le resultat doit etre de type VFF_TYP_4_BYTE\n", F_NAME); return 0; } if ((rowsize(lab) != rs) || (colsize(lab) != cs) || (depth(lab) != d)) { fprintf(stderr, "%s: tailles images incompatibles\n", F_NAME); return 0; } if (depth(img) != 1) { fprintf(stderr, "%s: cette version ne traite pas les images volumiques\n", F_NAME); exit(0); } switch (connex) { case 4: incr_vois = 2; break; case 8: incr_vois = 1; break; default: fprintf(stderr, "%s: mauvaise connexite: %d\n", F_NAME, connex); return 0; } /* switch (connex) */ /* le LABEL initialement est mis a NONMARQUE */ for (x = 0; x < N; x++) LABEL[x] = NONMARQUE; LIFO = CreeLifoVide(N); if (LIFO == NULL) { fprintf(stderr, "%s: CreeLifoVide failed\n", F_NAME); return(0); } *nlabels = 0; if ((typregion == LABMIN) || (typregion == LABMAX)) { for (x = 0; x < N; x++) { if (LABEL[x] == NONMARQUE) /* on trouve un point x non etiquete */ { *nlabels += 1; LABEL[x] = MARQUE; #ifdef DEBUGTROU printf("AMORCE p=%d,%d h=%d set LABEL = %d\n", x%rs, x/rs, SOURCE[x], LABEL[x]); #endif switch (attrib) /* on initialise les attributs de cette composante */ { case AREA: val_attrib = 0; break; case PERIM: val_attrib = 0; break; case TROUS: val_attrib = 0; break; case CIRC: area = perim = 0; break; case EXCEN: case ORIEN: area = 0; mx1 = my1 = mx2 = my2 = mxy2 = 0.0; break; case VDIAM: min = cs-1; max = 0; break; case HDIAM: min = rs-1; max = 0; break; default: fprintf(stderr, "%s: mauvais attribut: %d\n", F_NAME, attrib); return 0; } /* switch (attrib) */ LifoPush(LIFO, x); /* on va parcourir le plateau auquel appartient x */ while (! LifoVide(LIFO)) { w = LifoPop(LIFO); label = LABEL[w]; if (label == MARQUE) /* c'est une propagation de "marquage" : pour l'instant, */ { /* on croit qu'on est dans un extremum */ switch (attrib) { case AREA: val_attrib++; break; case VDIAM: if (w/rs < min) min = w/rs; else if (w/rs > max) max = w/rs; break; case HDIAM: if (w%rs < min) min = w%rs; else if (w%rs > max) max = w%rs; break; case EXCEN: case ORIEN: area++; mx1 += w%rs; my1 += w/rs; mxy2 += (w%rs) * (w/rs); mx2 += (w%rs) * (w%rs); my2 += (w/rs) * (w/rs); break; case PERIM: if (w%rs==rs-1) val_attrib++; /* point de bord */ if (w<rs) val_attrib++; /* point de bord */ if (w%rs==0) val_attrib++; /* point de bord */ if (w>=N-rs) val_attrib++; /* point de bord */ for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */ { y = voisin(w, k, rs, N); if ((y != -1) && (SOURCE[y] != SOURCE[w])) val_attrib++; } /* for k */ break; case CIRC: area++; if (w%rs==rs-1) perim++; /* point de bord */ if (w<rs) perim++; /* point de bord */ if (w%rs==0) perim++; /* point de bord */ if (w>=N-rs) perim++; /* point de bord */ for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */ { y = voisin(w, k, rs, N); if ((y != -1) && (SOURCE[y] != SOURCE[w])) perim++; } /* for k */ break; } /* switch (attrib) */ for (k = 0; k < 8; k += incr_vois) { y = voisin(w, k, rs, N); if (y != -1) { if (((typregion == LABMIN) && (SOURCE[y] < SOURCE[w])) || ((typregion == LABMAX) && (SOURCE[y] > SOURCE[w]))) { /* w non dans un minimum (resp. maximum) */ if (label == MARQUE) { label = NONEXTREM; *nlabels -= 1; LABEL[w] = label; LifoPush(LIFO, w); } } else if ((SOURCE[y] == SOURCE[w]) && (LABEL[y] == NONMARQUE)) { LABEL[y] = label; #ifdef DEBUGTROU printf(" p=%d,%d h=%d set LABEL = %d\n", y%rs, y/rs, SOURCE[y], LABEL[y]); #endif LifoPush(LIFO, y); if (attrib == TROUS) { int32_t masque = 0, imasque = 1; /* fabrique le masque des voisins de y MARQUES */ for (l = 0; l < 8; l += 1) { z = voisin(y, l, rs, N); if ((z != -1) && (LABEL[z] == MARQUE)) masque |= imasque; imasque = imasque << 1; } /* for k ... */ #ifdef DEBUGTROU printf(" p=%d,%d h=%d masque=%x t4m=%d t8b=%d\n", y%rs, y/rs, SOURCE[y], masque, t4(masque), t8b(masque)); #endif if (connex == 4) { val_attrib += (t4(masque) - 1); if (t8b(masque) == 0) val_attrib--; } else { val_attrib += (t8(masque) - 1); if (t4b(masque) == 0) val_attrib--; } } /* if (attrib == TROUS) */ } /* if ((SOURCE[y] == SOURCE[w]) && (LABEL[y] == NONMARQUE)) */ } /* if (y != -1) */ } /* for k ... */ } /* if (label == MARQUE) */ else /* propagation de "demarquage" */ { for (k = 0; k < 8; k += incr_vois) { y = voisin(w, k, rs, N); if (y != -1) { if ((SOURCE[y] == SOURCE[w]) && (LABEL[y] != NONEXTREM)) { LABEL[y] = NONEXTREM; LifoPush(LIFO, y); } /* if .. */ } /* if (y != -1) */ } /* for k ... */ } /* else if (label == MARQUE) */ } /* while (! LifoVide(LIFO)) */ if (label == MARQUE) { if (attrib == CIRC) { val_attrib = (int32_t)(256 * 4 * M_PI * (double)area / (double)(perim * perim)); if (val_attrib > 255) { fprintf(stderr, "WARNING: indice de circularite > 255 : %d, a=%d, p=%d\n", val_attrib, area, perim); val_attrib = 255; } } if (attrib == EXCEN) val_attrib = excentricity(mx1, my1, mx2, my2, mxy2, area); if (attrib == ORIEN) val_attrib = orientation(mx1, my1, mx2, my2, mxy2, area); if (attrib == VDIAM) val_attrib = max - min + 1; if (attrib == HDIAM) val_attrib = max - min + 1; if (val_attrib <= seuil) val_attrib = 0; #ifdef VERBOSE printf("valeur attribut = %d\n", val_attrib); #endif LifoPush(LIFO, x); /* on re-parcourt le plateau pour propager l'attribut */ LABEL[x] = val_attrib; while (! LifoVide(LIFO)) { w = LifoPop(LIFO); for (k = 0; k < 8; k += incr_vois) { y = voisin(w, k, rs, N); if ((y != -1) && (LABEL[y] == MARQUE)) { LABEL[y] = val_attrib; LifoPush(LIFO, y); } } /* for k ... */ } /* while (! LifoVide(LIFO)) */ } /* if (label == MARQUE) */ } /* if (LABEL[x] != -1) */ } /* for (x = 0; x < N; x++) */ } /* if ((typregion == LABMIN) || (typregion == LABMAX)) */ else { if (attrib == TROUS) { fprintf(stderr, "%s: attribut TROUS non compatible avec typreg = PLA\n", F_NAME); return 0; } for (x = 0; x < N; x++) { if (LABEL[x] == NONMARQUE) { *nlabels += 1; LABEL[x] = *nlabels; switch (attrib) /* on initialise les attributs de cette composante */ { case AREA: val_attrib = 0; break; case VDIAM: min = cs-1; max = 0; break; case HDIAM: min = rs-1; max = 0; break; case PERIM: val_attrib = 0; break; case CIRC: area = perim = 0; break; case EXCEN: case ORIEN: area = 0; mx1 = my1 = mx2 = my2 = mxy2 = 0.0; break; default: fprintf(stderr, "%s: mauvais attribut: %d\n", F_NAME, attrib); return 0; } /* switch (attrib) */ LifoPush(LIFO, x); while (! LifoVide(LIFO)) { w = LifoPop(LIFO); switch (attrib) { case AREA: val_attrib++; break; case VDIAM: if (w/rs < min) min = w/rs; else if (w/rs > max) max = w/rs; break; case HDIAM: if (w%rs < min) min = w%rs; else if (w%rs > max) max = w%rs; break; case EXCEN: case ORIEN: area++; mx1 += w%rs; my1 += w/rs; mxy2 += (w%rs) * (w/rs); mx2 += (w%rs) * (w%rs); my2 += (w/rs) * (w/rs); break; case PERIM: if (w%rs==rs-1) val_attrib++; /* point de bord */ if (w<rs) val_attrib++; /* point de bord */ if (w%rs==0) val_attrib++; /* point de bord */ if (w>=N-rs) val_attrib++; /* point de bord */ for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */ { y = voisin(w, k, rs, N); if ((y != -1) && (SOURCE[y] != SOURCE[w])) val_attrib++; } /* for k */ break; case CIRC: area++; if (w%rs==rs-1) perim++; /* point de bord */ if (w<rs) perim++; /* point de bord */ if (w%rs==0) perim++; /* point de bord */ if (w>=N-rs) perim++; /* point de bord */ for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */ { y = voisin(w, k, rs, N); if ((y != -1) && (SOURCE[y] != SOURCE[w])) perim++; } /* for k */ break; } /* switch (attrib) */ for (k = 0; k < 8; k += incr_vois) { y = voisin(w, k, rs, N); if ((y != -1) && (LABEL[y] == NONMARQUE) && (SOURCE[y] == SOURCE[w])) { LABEL[y] = MARQUE; LifoPush(LIFO, y); } /* if y ... */ } /* for k ... */ } /* while (! LifoVide(LIFO)) */ if (attrib == CIRC) { val_attrib = (int32_t)(256 * 4 * M_PI * (double)area / (double)(perim * perim)); if (val_attrib > 255) { fprintf(stderr, "WARNING: indice de circularite > 255 : %d, a=%d, p=%d\n", val_attrib, area, perim); val_attrib = 255; } } if (attrib == EXCEN) val_attrib = excentricity(mx1, my1, mx2, my2, mxy2, area); if (attrib == ORIEN) val_attrib = orientation(mx1, my1, mx2, my2, mxy2, area); if (attrib == VDIAM) val_attrib = max - min + 1; if (attrib == HDIAM) val_attrib = max - min + 1; if (val_attrib <= seuil) val_attrib = 0; LifoPush(LIFO, x); /* on re-parcourt le plateau pour propager l'attribut */ LABEL[x] = val_attrib; while (! LifoVide(LIFO)) { w = LifoPop(LIFO); for (k = 0; k < 8; k += incr_vois) { y = voisin(w, k, rs, N); if ((y != -1) && (LABEL[y] == MARQUE)) { LABEL[y] = val_attrib; LifoPush(LIFO, y); } } /* for k ... */ } /* while (! LifoVide(LIFO)) */ } /* if (LABEL[x] == NONMARQUE) */ } /* for (x = 0; x < N; x++) */ } /* else if ((typregion == LABMIN) || (typregion == LABMAX)) */ LifoTermine(LIFO); *nlabels += 1; /* pour le niveau 0 */ return(1); } // lattribute()