<commit_before>/*
 * MassFind: A Diamond application for exploration of breast tumors
 *
 * Copyright (c) 2006 Intel Corporation. All rights reserved.
 * Additional copyrights may be listed below.
 *
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0 which accompanies this
 * distribution in the file named LICENSE.
 *
 */
 
/*
 * fil_visual.c - filtering based on visual features
 */
 
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <stdio.h>
#include <glib.h>

#include "lib_filter.h"
#include "upmc_features.h"
#include "roi_features.h"
#include "fil_visual.h"

#define MAX_ATTR_NAME           128
#define MAX_ATTR_VALUE          4096

int f_init_visual(int numarg, const char * const *args, int blob_len,
                    const void *blob, const char *fname, void **data)
{
	visual_config_t *fconfig;
	int i;

	/*
	 * save the features for the source object
	 */
	fconfig = (visual_config_t *)malloc(sizeof(*fconfig));
	assert(fconfig);

    /* Hardcoded value???  */
	fconfig->numFeatures = numarg-6;
	fconfig->features = (float *) malloc(sizeof(float) * fconfig->numFeatures);
    for (i = 0; i < fconfig->numFeatures; i++) {
    	fconfig->features[i] = atof(args[i]);
    }
    fconfig->size_mult_lower = atof(args[numarg-6]);
    fconfig->size_mult_upper = atof(args[numarg-5]);
    fconfig->circ_mult_lower = atof(args[numarg-4]);
    fconfig->circ_mult_upper = atof(args[numarg-3]);
    fconfig->sfr_mult_lower = atof(args[numarg-2]);
    fconfig->sfr_mult_upper = atof(args[numarg-1]);

	/*
	 * save the data pointer 
	 */
	*data = (void *) fconfig;
	
	return (0);
}

int f_fini_visual(void *data)
{
	visual_config_t *fconfig = (visual_config_t *) data;
	free(fconfig->features);
	free(fconfig);
	
	return (0);
}


int f_eval_visual(lf_obj_handle_t ohandle, void *f_data)
{
	int err;
	int i;
	visual_config_t *fconfig = (visual_config_t *) f_data;
	size_t featureLen = MAX_ATTR_VALUE;
	unsigned char featureStr[MAX_ATTR_VALUE];
	float size, circularity, shapefactor;
	float r_min, r_max;
	char fname[MAX_ATTR_NAME];
	int inRange;
	
	lf_log(LOGL_TRACE, "f_eval_visual: enter");
	
	if (fconfig->size_mult_lower > 0) {
		// read the object's region size
		sprintf(fname, "%s%02d", UPMC_PREFIX, UPMC_REGION_SIZE);
		err = lf_read_attr(ohandle, fname, &featureLen, featureStr);
		assert(err == 0);
		size = atof((char *)featureStr);
		<commit_msg>Remove unused variables<commit_after>/*
 * MassFind: A Diamond application for exploration of breast tumors
 *
 * Copyright (c) 2006 Intel Corporation. All rights reserved.
 * Additional copyrights may be listed below.
 *
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0 which accompanies this
 * distribution in the file named LICENSE.
 *
 */
 
/*
 * fil_visual.c - filtering based on visual features
 */
 
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <stdio.h>
#include <glib.h>

#include "lib_filter.h"
#include "upmc_features.h"
#include "roi_features.h"
#include "fil_visual.h"

#define MAX_ATTR_NAME           128
#define MAX_ATTR_VALUE          4096

int f_init_visual(int numarg, const char * const *args, int blob_len,
                    const void *blob, const char *fname, void **data)
{
	visual_config_t *fconfig;
	int i;

	/*
	 * save the features for the source object
	 */
	fconfig = (visual_config_t *)malloc(sizeof(*fconfig));
	assert(fconfig);

    /* Hardcoded value???  */
	fconfig->numFeatures = numarg-6;
	fconfig->features = (float *) malloc(sizeof(float) * fconfig->numFeatures);
    for (i = 0; i < fconfig->numFeatures; i++) {
    	fconfig->features[i] = atof(args[i]);
    }
    fconfig->size_mult_lower = atof(args[numarg-6]);
    fconfig->size_mult_upper = atof(args[numarg-5]);
    fconfig->circ_mult_lower = atof(args[numarg-4]);
    fconfig->circ_mult_upper = atof(args[numarg-3]);
    fconfig->sfr_mult_lower = atof(args[numarg-2]);
    fconfig->sfr_mult_upper = atof(args[numarg-1]);

	/*
	 * save the data pointer 
	 */
	*data = (void *) fconfig;
	
	return (0);
}

int f_fini_visual(void *data)
{
	visual_config_t *fconfig = (visual_config_t *) data;
	free(fconfig->features);
	free(fconfig);
	
	return (0);
}


int f_eval_visual(lf_obj_handle_t ohandle, void *f_data)
{
	int err;
	visual_config_t *fconfig = (visual_config_t *) f_data;
	size_t featureLen = MAX_ATTR_VALUE;
	unsigned char featureStr[MAX_ATTR_VALUE];
	float size, circularity, shapefactor;
	float r_min, r_max;
	char fname[MAX_ATTR_NAME];
	
	lf_log(LOGL_TRACE, "f_eval_visual: enter");
	
	if (fconfig->size_mult_lower > 0) {
		// read the object's region size
		sprintf(fname, "%s%02d", UPMC_PREFIX, UPMC_REGION_SIZE);
		err = lf_read_attr(ohandle, fname, &featureLen, featureStr);
		assert(err == 0);
		size = atof((char *)featureStr);
		
{'fraction_non_alphanumeric': 0.12967479674796747, 'fraction_numerical': 0.01097560975609756, 'mean_word_length': 4.099481865284974, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6664244', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1736, 'n_words': 434}