Ejemplo n.º 1
0
/** \brief Pointwise distance matrix: \f$ d_{ij} = d( s1_i, s2_j ) \f$

	 \param f the distance function between individual points in signals s1,s2
	 \param s1 a 2D (N1xp) array holding the (multivariate) time-series 1
	 \param s1 a 2D (N2xp) array holding the (multivariate) time-series 2
	 \param out either an NxN matrix, or NULL (allocated in function)
	 \param optargs may contain many different arguments which are passed 
	        to the VectorDistanceFunction (see details there):
    \return a NxN matrix containing the distances (allocated in function, or out)
 */
Array* distmatrix_signaldist( VectorDistanceFunction f, const Array *s1, 
										const Array *s2, Array *out,	OptArgList *optargs ){
  bool ismatrix;
  int i,j;

  if( s1->dtype!=DOUBLE || s2->dtype!=DOUBLE ){
	 errprintf("Input signals must be double-arrays\n");
	 return NULL;
  }
  if( s1->ndim>2 || s2->ndim>2 || s1->ndim != s2->ndim ){
	 warnprintf("Input signals should be 1D or 2D... continue at your own risk (%i,%i)\n",
					s1->ndim, s2->ndim );
  }

  /* thin matrix-wrapper (in case of 1D data */
  Array *s1m, *s2m;
  s1m = array_fromptr2( DOUBLE, 2, s1->data, s1->size[0], (s1->ndim>1)?(s1->size[1]):1 );
  s2m = array_fromptr2( DOUBLE, 2, s2->data, s2->size[0], (s2->ndim>1)?(s2->size[1]):1 );

  if( s1m->size[1] != s2m->size[1] ){
	 errprintf("Signals must have the same dimension 2\n");
	 array_free( s1m );
	 array_free( s2m );
	 return NULL; 
  }

  int N1 = s1m->size[0];
  int N2 = s2m->size[0];
  int p = s1m->size[1];
  if( out ){
	 matrix_CHECK( ismatrix, out );
	 if( !ismatrix ) return NULL;
	 if( out->size[0] < N1 || out->size[1] < N2 ){
		errprintf("output matrix is not %ix%i: %i,%i\n",
					 N1,N2,out->size[0],out->size[1]);
		array_free( s1m );
		array_free( s2m );
		return NULL;
	 }
  } else {
	 out = array_new2( DOUBLE, 2, N1, N2 );
  }

  /* --------------------- computation ------------------------*/
  for( i=0; i<N1; i++ ){
	 for( j=0; j<N2; j++ ){
		mat_IDX( out, i, j ) = f( (double*)array_INDEXMEM2( s1m, i, 0 ),
										  (double*)array_INDEXMEM2( s2m, j, 0 ), p, optargs );
	 }
  }
  /* --------------------- /computation ------------------------*/

  array_free( s1m );
  array_free( s2m );
  return out; 
}
Ejemplo n.º 2
0
/** \brief computes the distance between two warping-functions. 

	 It is assumed that both pathes have the same starting and endpoint.

	 \todo fix this! work with new warppath-arrays!

	 Algorithm:
	 \code
	 1. compute distance transform for p1
	 2. line-integral of p2 through DT(p1) 
	 \endcode
 */
double   pathdist_euclidean_dt(WarpPath *p1, WarpPath *p2){
#ifdef LIBEEGTOOLS_FIXME
  int **I;
  int n,m,
	 i,j;
  double dist;
  double **d;
  
  n = p1->t1[p1->n-1]+1;
  m = p1->t2[p1->n-1]+1;

  dprintf("calculate distance with (%i x %i) points\n", n, m );

  I = (int**)malloc( n*sizeof(int*) );
  for( i=0; i<n; i++){
	 I[i] = (int*)malloc( m*sizeof(int) );
	 for( j=0; j<m; j++ ){
		I[i][j] = 0;
	 }
  }

  for( i=0; i<p1->n; i++ ){
	 //dprintf(" (%i , %i)\n", p1->t1[i], p1->t2[i] );
	 I[p1->t1[i]][p1->t2[i]]=1;
  }
  
  dprintf(" init done \n");
	 
  d = disttransform_deadreckoning( I, n, m, ALLOC_IN_FCT );
  dblpp_divide_scalar( d, n, m, dblpp_max( (const double**)d, n, m, NULL, NULL ) );
  dprintf(" dt done \n");

  dist = 0.0;
  for( i=0; i<p2->n; i++ ){
	 //	 dprintf(" (%i , %i)\n", p2->t1[i], p2->t2[i] );
	 if(  p2->t1[i]>=n ||  p2->t2[i]>=n ){
		warnprintf("points in P2 do not fall in P1,  (%i , %i) -> ignored\n", p2->t1[i], p2->t2[i] );
	 } else {
		dist += d[p2->t1[i]][p2->t2[i]];
	 }
  }
  
  //  dist /= (double)n*m;
  dprintf(" dist=%f compute done \n", dist);
 
  for( i=0; i<n; i++ ){
	 free( I[i] );
  }
  free(I); 
  //dblpp_free( d, m );

  return dist;
#endif
}
Ejemplo n.º 3
0
static void
print_icon_list()
{
	GList* icon_list = gtk_icon_theme_list_icons(icon_theme, "MimeTypes");
	if(icon_list){
		dbg(0, "%s----------------------------------", theme_name);
		for(;icon_list;icon_list=icon_list->next){
			char* icon = icon_list->data;
			printf("%s\n", icon);
			g_free(icon);
		}
		g_list_free(icon_list);
		printf("-------------------------------------------------\n");
	}
	else warnprintf("icon_theme has no mimetype icons?\n");

}
Ejemplo n.º 4
0
bool
check_default_theme(gpointer data)
{
	// The default gtk icon theme "hi-color" does not contain any mimetype icons.

	static char* names[] = {"audio-x-wav", "audio-x-generic", "gnome-mime-audio"};

	if(!theme_name[0]){
		GtkIconInfo* info;
		int i = 0;
		while(i++ < G_N_ELEMENTS(names) && !(info = gtk_icon_theme_lookup_icon(icon_theme, names[i], ICON_HEIGHT, 0)));
		if(info){
			gtk_icon_info_free(info);
		}else{
			warnprintf("default icon theme appears not to contain audio mime-type icons\n");

			// TODO use a random fallback theme
		}
	}
	return G_SOURCE_REMOVE;
}
Ejemplo n.º 5
0
gboolean
mysql__connect()
{
	g_return_val_if_fail(model, false);

	if(!mysql.host){
		if(!mysql_init(&mysql)){
			printf("Failed to initiate MySQL connection.\n");
			return 0;
		}
	}
	dbg (1, "MySQL Client Version is %s", mysql_get_client_info());
	mysql.reconnect = true;

	if(!mysql_real_connect(&mysql, config->host, config->user, config->pass, config->name, 0, NULL, 0)){
		if(mysql_errno(&mysql) == CR_CONNECTION_ERROR){
			warnprintf("cannot connect to database: MYSQL server not online.\n");
		}else{
			warnprintf("cannot connect to mysql database: %s\n", mysql_error(&mysql));
		}
		return false;
	}
	if(_debug_) printf("MySQL Server Version is %s\n", mysql_get_server_info(&mysql));

	if(mysql_select_db(&mysql, config->name)){
		errprintf("Failed to connect to Database: %s\n", mysql_error(&mysql));
		return false;
	}
	// check if table exists
	gboolean table_exists = false;
	int64_t colflag = 0;

	MYSQL_ESCAPE(dbname, config->name);
	char* sql = g_malloc((100/*query string*/ + strlen(dbname)) * sizeof(char));
	sprintf(sql, "SELECT column_name from INFORMATION_SCHEMA.COLUMNS where table_schema='%s' AND table_name='samples';", config->name);
	if(mysql_query(&mysql, sql)){
		// probably out of disc space.
		errprintf("Failed to get column_name: %s\n", mysql_error(&mysql));
		free(dbname);
		g_free(sql);
		return false;
	}else{
		MYSQL_RES* sr = mysql_store_result(&mysql);
		if (sr) {
			if (mysql_num_rows(sr) == COLCOUNT) {
				table_exists = true;
				colflag = (1 << (COLCOUNT)) - 1;
			}
			else if (mysql_num_rows(sr) != 0) {
				table_exists = true;
				/* ALTER TABLE */
				MYSQL_ROW row;
				while ((row = mysql_fetch_row(sr))) {
					int i; for (i=0;i<COLCOUNT;i++) {
						if (!strcmp(row[0], sct[i].key)) { colflag|=1<<i; break; }
					}
				}
			}
			mysql_free_result(sr);
		}
	}
	free(dbname); g_free(sql);

	if (!table_exists) {
		/* CREATE Table */
		int off=0; int i;
		sql = g_malloc(4096 * sizeof(char)); // XXX current length is 643 chars
		off=sprintf(sql, "CREATE TABLE `samples` (");
		for (i=0;i<COLCOUNT;i++)
			off += sprintf(sql + off, "%s, ", sct[i].def);
		sprintf(sql+off, "PRIMARY KEY  (`id`));");
		dbg(0, "%d: %s", off, sql);

		if (mysql_real_query(&mysql, sql, strlen(sql))) {
			warnprintf("cannot create database-table: %s\n", mysql_error(&mysql));
			mysql_close(&mysql);
			g_free(sql);
			return false;
		}
		g_free(sql);
	} else {
		/* Alter Table if neccesary */
		int i;
		sql = g_malloc(1024*sizeof(char));
		for (i=0;i<COLCOUNT;i++) if ((colflag&(1<<i))==0) {
			sprintf(sql, "ALTER TABLE samples ADD %s;", sct[i].def);
			dbg(0, "%s", sql);
			if (mysql_real_query(&mysql, sql, strlen(sql))) {
				warnprintf("cannot update database-table to new model: %s\n", mysql_error(&mysql));
				mysql_close(&mysql);
				g_free(sql);
				return false;
			}
		}
		g_free(sql);
	}

	memset(&result, 0, sizeof(Sample));

	is_connected = true;
	return true;
}