Esempio n. 1
0
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;
}
Esempio n. 2
0
void
VROIpaired_ttest(VImage *src1, VImage *src2, VImage *mask, int n, int nmask, FILE *fp) {
    VString str;
    int i, j, id, b, r, c, c0, c1, nROI = 0;
    float ave1 = 0, ave2 = 0, var1 = 0, var2 = 0;
    float sum1 = 0, sum2 = 0, u, mx;
    float t, z, p, df, sd, cov, *data1 = NULL, *data2 = NULL;
    float tiny = 1.0e-8;
    float xa, ya, za, xx, yy, zz, voxelsize = 1;
    double mean[3];
    Volumes *volumes;
    Volume vol;
    VTrack tc;
    VBoolean found = FALSE;
    gsl_set_error_handler_off();
    /*
    ** get ROIs from mask
    */
    fprintf(stderr, "\n List of ROIs:\n");
    fprintf(fp, "\n List of ROIs:\n");
    volumes = (Volumes *) VCalloc(nmask, sizeof(Volumes));
    nROI = 0;
    for(i = 0; i < nmask; i++) {
        fprintf(stderr, "\n Mask %2d:\n", i + 1);
        fprintf(fp, "\n Mask %2d:\n", i + 1);
        volumes[i] = VImage2Volumes(mask[i]);
        voxelsize = 1;
        if(VGetAttr(VImageAttrList(mask[i]), "voxel", NULL,
                    VStringRepn, (VPointer) & str) == VAttrFound) {
            sscanf(str, "%f %f %f", &xa, &ya, &za);
            voxelsize = xa * ya * za;
        }
        fprintf(stderr, " ROI              addr               size(mm^3)\n");
        fprintf(stderr, "-----------------------------------------------\n");
        fprintf(fp, " ROI              addr               size(mm^3)\n");
        fprintf(fp, "-----------------------------------------------\n");
        for(vol = volumes[i]->first; vol != NULL; vol = vol->next) {
            VolumeCentroid(vol, mean);
            if(nROI < vol->label)
                nROI = vol->label;
            b = mean[0];
            r = mean[1];
            c = mean[2];
            xx = mean[2];
            yy = mean[1];
            zz = mean[0];
            VGetTalCoord(src1[0], zz, yy, xx, &xa, &ya, &za);
            id = vol->label;
            fprintf(stderr, " %2d    %7.2f  %7.2f  %7.2f    %7.0f\n",
                    id, xa, ya, za, voxelsize *(double)VolumeSize(vol));
            fprintf(fp, " %2d    %7.2f  %7.2f  %7.2f    %7.0f\n",
                    id, xa, ya, za, voxelsize *(double)VolumeSize(vol));
        }
    }
    fprintf(stderr, "\n\n");
    fprintf(fp, "\n\n");
    /* check consistency */
    if(nROI < 1)
        VError(" no ROIs found");
    CheckROI(volumes, nmask, nROI);
    /*
    ** process each ROI
    */
    fprintf(stderr, "\n");
    fprintf(stderr, "  ROI          mean          t        z       p   \n");
    fprintf(stderr, " --------------------------------------------------\n");
    if(fp) {
        fprintf(fp, "\n");
        fprintf(fp, "  ROI          mean          t        z       p   \n");
        fprintf(fp, " --------------------------------------------------\n");
    }
    df = n - 1;
    data1 = (float *) VCalloc(n, sizeof(float));
    data2 = (float *) VCalloc(n, sizeof(float));
    for(id = 1; id <= nROI; id++) {
        for(i = 0; i < n; i++) {
            j = 0;
            if(nmask > 1)
                j = i;
            found = FALSE;
            for(vol = volumes[j]->first; vol != NULL; vol = vol->next) {
                if(vol->label != id)
                    continue;
                found = TRUE;
                sum1 = sum2 = mx = 0;
                for(j = 0; j < VolumeNBuckets(vol); j++) {
                    for(tc = VFirstTrack(vol, j); VTrackExists(tc); tc = VNextTrack(tc)) {
                        b  = tc->band;
                        r  = tc->row;
                        c0 = tc->col;
                        c1 = c0 + tc->length;
                        for(c = c0; c < c1; c++) {
                            u = VPixel(src1[i], b, r, c, VFloat);
                            if(ABS(u) < tiny)
                                continue;
                            sum1 += u;
                            u = VPixel(src2[i], b, r, c, VFloat);
                            if(ABS(u) < tiny)
                                continue;
                            sum2 += u;
                            mx++;
                        }
                    }
                }
                if(mx < 1) {
                    VWarning(" no voxels in ROI %d of mask %d", id, i);
                    data1[i] = data2[i] = 0;
                    continue;
                }
                data1[i] = sum1 / mx;
                data2[i] = sum2 / mx;
            }
            if(!found)
                goto next;
        }
        avevar(data1, n, &ave1, &var1);
        avevar(data2, n, &ave2, &var2);
        if(var1 < tiny || var2 < tiny) {
            VWarning(" no variance in ROI %d", id);
            continue;
        }
        z = t = p = 0;
        cov = 0;
        for(j = 0; j < n; j++)
            cov += (data1[j] - ave1) * (data2[j] - ave2);
        cov /= df;
        sd = sqrt((var1 + var2 - 2.0 * cov) / (df + 1.0));
        if(sd < tiny)
            continue;
        t = (ave1 - ave2) / sd;
        if(ABS(t) < tiny)
            p = z = 0;
        else {
            p = t2p((double)t, (double)df);
            z = t2z((double)t, (double)df);
            if(t < 0)
                z = -z;
        }
        fprintf(stderr, " %3d   %8.4f (%.3f)  %7.3f  %7.3f  %7.4f\n",
                id, (ave1 - ave2), sd, t, z, p);
        if(fp)
            fprintf(fp, " %3d  %8.4f (%.3f)  %7.3f  %7.3f  %7.4f\n",
                    id, (ave1 - ave2), sd, t, z, p);
next:
        ;
    }
    fprintf(stderr, "\n");
    if(fp) {
        fprintf(fp, "\n");
        fclose(fp);
    }
}