コード例 #1
0
ファイル: grain_filter.c プロジェクト: DavidMercier/gwyddion
static void
gfilter_process(GwyDataField *mfield, GFilterArgs *args)
{
    GwyInventory *inventory;
    GrainLogical logical;
    const gdouble *v[NQUANTITIES];
    const guint *grains;
    const RangeRecord *ranges;
    gboolean *keep_grain;
    guint i, k, n, ngrains;

    inventory = gwy_grain_values();
    for (i = 0; i < NQUANTITIES; i++) {
        k = gwy_inventory_get_item_position(inventory,
                                            args->ranges[i].quantity);
        v[i] = g_ptr_array_index(args->valuedata, k);
    }

    ngrains = args->ngrains;
    grains = args->grains;
    logical = args->logical;
    ranges = &args->ranges[0];

    keep_grain = g_new(gboolean, ngrains+1);
    keep_grain[0] = FALSE;
    for (k = 1; k <= ngrains; k++) {
        gboolean is_ok[NQUANTITIES];

        for (i = 0; i < NQUANTITIES; i++) {
             is_ok[i] = check_threshold(v[i][k],
                                        ranges[i].lower,
                                        ranges[i].upper);
        }
        if (logical == GRAIN_LOGICAL_A)
            keep_grain[k] = is_ok[0];
        else if (logical == GRAIN_LOGICAL_A_AND_B)
            keep_grain[k] = is_ok[0] && is_ok[1];
        else if (logical == GRAIN_LOGICAL_A_OR_B)
            keep_grain[k] = is_ok[0] || is_ok[1];
        else if (logical == GRAIN_LOGICAL_A_AND_B_AND_C)
            keep_grain[k] = is_ok[0] && is_ok[1] && is_ok[2];
        else if (logical == GRAIN_LOGICAL_A_OR_B_OR_C)
            keep_grain[k] = is_ok[0] || is_ok[1] || is_ok[2];
        else if (logical == GRAIN_LOGICAL_A_AND_B_OR_C)
            keep_grain[k] = (is_ok[0] && is_ok[1]) || is_ok[2];
        else if (logical == GRAIN_LOGICAL_A_OR_B_AND_C)
            keep_grain[k] = (is_ok[0] || is_ok[1]) && is_ok[2];
        else {
            g_assert_not_reached();
        }
    }

    n = mfield->xres * mfield->yres;
    for (k = 0; k < n; k++)
        mfield->data[k] = keep_grain[grains[k]];
    gwy_data_field_invalidate(mfield);

    g_free(keep_grain);
}
コード例 #2
0
static int sm_metadata_new_block(struct dm_space_map *sm, dm_block_t *b)
{
	dm_block_t count;
	struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);

	int r = sm_metadata_new_block_(sm, b);
	if (r) {
		DMERR("unable to allocate new metadata block");
		return r;
	}

	r = sm_metadata_get_nr_free(sm, &count);
	if (r) {
		DMERR("couldn't get free block count");
		return r;
	}

	check_threshold(&smm->threshold, count);

	return r;
}
コード例 #3
0
ファイル: regiontbl.cpp プロジェクト: prabhat246/QArtist
//Function  adds good neigbhours to the same region and also adds the neighbours to queue for further search
//good neighbours means which are in threshold and are free
void add_goodn(int h,int w, int REG ,float R,float G,float B)
{
        if( (w-1 >=0)  && (h-1 >= 0) )  //checking boundary conditions
        {
            int currw = w-1 ; int currh = h-1;
                    //check threshhold and if free and not bound already
            if( check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                            // add to curr region
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }
         }

         if( (w-1 >=0))
        {
            int currw = w-1 ; int currh = h;
            if( check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }

         }

         if( (w-1 >=0)  && (h+1 < img_height ) )
        {
            int currw = w-1 ; int currh = h+1;
            if( check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }
         }

         if( (h-1 >= 0) )

        {
            int currw = w ; int currh = h-1;
            if(check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }
         }

         if((h+1 < img_height) )
        {
            int currw = w ; int currh = h+1;
            if(check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }
         }

         if( (w+1 < img_width)  && (h-1 >= 0) )
        {
            int currw = w+1 ; int currh = h-1;
            if(check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }
         }
         if( (w+1 < img_width))
        {
            int currw = w+1 ; int currh = h;
            if(check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }
         }
         if( (w+1 < img_width)  && (h+1 < img_height) )
        {
            int currw = w+1 ; int currh = h+1;
            if(check_threshold(R,G,B,img_data[currh][currw].r,img_data[currh][currw].g,img_data[currh][currw].b) == true && (img_data[currh][currw].region < 0))
                {
                    img_data[currh][currw].region = REG;
                    img_region[REG][RED] += img_data[currh][currw].r;
                    img_region[REG][GREEN] += img_data[currh][currw].g;
                    img_region[REG][BLUE] += img_data[currh][currw].b;
                    img_region[REG][NUM_PIXEL]++;
                            //add to queue and add to region
                    QUE.insert(currh,currw);
                }
         }

}