Example #1
0
void RTreeClassifier::train(std::vector<BaseKeypoint> const& base_set,
                            Rng &rng, int num_trees, int depth,
                            int views, size_t reduced_num_dim,
                            int num_quant_bits)
{
  PatchGenerator make_patch(NULL, rng);
  train(base_set, rng, make_patch, num_trees, depth, views, reduced_num_dim, num_quant_bits);
}
Example #2
0
int
main (int argc, char *argv[])
{
  if (argc != 3)
    abort ();

  setlocale (LC_ALL, "C");

  int exit_code = 1;

  const char *db_file = argv[1];
  const char *nameslist_file = argv[2];

  uninm_names_db db = uninm_names_db_open (db_file);
  if (db != NULL)
    {
      char nameslist[2000000];
      memset (nameslist, 0, sizeof nameslist);
      FILE *f = fopen (nameslist_file, "rb");
      (void) fread (nameslist, 1, sizeof nameslist, f);
      fclose (f);

      int failure_count = 0;

      // Test the codepoints up to 0x10FFFF.
      for (int codepoint = 0; codepoint <= 0x10FFFF; codepoint++)
	{
	  char *patch = make_patch (db, codepoint);
	  if (patch != NULL)
	    {
	      if (strstr (nameslist, patch) == NULL)
		{
		  (void) printf ("Failure: codepoint = %X\n", codepoint);
		  failure_count++;
		}
	      free (patch);
	    }
	}

      if (failure_count == 0)
	exit_code = 0;

      uninm_names_db_close (db);
    }

  return exit_code;
}
Example #3
0
void push_changes(lua_State *l, const char *base_path, const char *full_path) {
    struct dirent **dir_list = NULL;
    struct dirent *dir = NULL;
    int results;
    int i;
    int rv;
    char *path;

    if (strncmp(base_path, full_path, strlen(base_path)) != 0)
        die("wtf? %s != %s len %li", base_path, full_path, strlen(base_path));

    gettimeofday(&now, NULL);

    path = strdup(full_path + strlen(base_path) + 1); /* Skip trailing slash in full_path */
    log_debug("relative path is %s", path);

    scandir_baton_t baton;
    baton.ig = root_ignores;
    baton.base_path = base_path;
    baton.level = 0;

    results = ds_scandir(full_path, &dir_list, &changed_filter, &baton);
    if (results == -1) {
        log_debug("Error scanning directory %s: %s", full_path, strerror(errno));
        return;
    } else if (results == 0) {
        log_debug("No results found in directory %s", full_path);
        return;
    }

    char *file_path;
    char *file_path_rel;
    for (i = 0; i < results; i++) {
        dir = dir_list[i];
        ds_asprintf(&file_path, "%s%s", full_path, dir->d_name);
        ds_asprintf(&file_path_rel, "%s%s", path, dir->d_name);
        if (is_ignored(file_path)) {
            /* we triggered this event */
            unignore_change(file_path);
            goto cleanup;
        }

        if (is_directory(full_path, dir)) {
            /* TODO: figure out if we need to recurse */
            goto cleanup;
        }

        buf_t *buf = get_buf(file_path_rel);
        if (buf == NULL) {
            log_err("buf not found for path %s", file_path_rel);
            goto cleanup;
        }

        const char *f2 = file_path;

        mmapped_file_t *mf;
        struct stat file_stats;
        off_t f2_size;

        rv = lstat(f2, &file_stats);
        if (rv) {
            die("Error lstat()ing file %s.", f2);
        }
        f2_size = file_stats.st_size;

        if (f2_size == 0) {
            log_debug("%s is empty");
            goto cleanup;
        }
        mf = mmap_file(f2, f2_size, 0, 0);
        if (is_binary(mf->buf, mf->len)) {
            log_debug("%s is binary. skipping", file_path);
            goto diff_cleanup;
        }

        char *new_text = strndup(mf->buf, mf->len);
        char *patch_text = make_patch(l, buf->buf, new_text);

        free(new_text);

        if (strlen(patch_text) == 0) {
            log_debug("no change. not sending patch");
            goto diff_cleanup;
        }

        char *md5_after = md5(mf->buf, mf->len);

        send_json(
            "{s:s s:i s:s s:s s:s s:s}",
            "name", "patch",
            "id", buf->id,
            "patch", patch_text,
            "path", buf->path,
            "md5_before", buf->md5,
            "md5_after", md5_after
        );

        free(md5_after);
        free(patch_text);

        buf->buf = realloc(buf->buf, mf->len + 1);
        buf->len = mf->len;
        memcpy(buf->buf, mf->buf, buf->len);

        diff_cleanup:;
        munmap_file(mf);
        free(mf);
        cleanup:;
        free(file_path);
        free(file_path_rel);
        free(dir);
    }
    free(dir_list);
    free(path);
}
Example #4
0
/// Draw the entire boundary network, mapping disorientations
vtkPolyData* Dataset::boundary_network()
{
	int i,j,k = 0;
	int num_quads = 0, new_quads = 0, buffer_count = 1;
	int num_vertices = 0;
	
	AdjGrain* adj_grain;
	Quad *quads;
	XYZ p;
	Point *d = data;
	
	// Allocate buffer for quads (faces)
	// We will expand this as required
	quads = (Quad*) malloc(sizeof(Quad)*QUAD_BUFFER);
	if (quads == NULL) { return 0; }


	// Cycle through each 					
	//--------------------------------------------------
	for(i=0;i<nv;i++){
		d++;	
		
		if (d->grain>=0) {

			// Calcuate the x,y,z coordinates from the voxel index					
			//--------------------------------------------------		
			p.x = (i/dx) % tx;
			p.y = (i/dy) % ty;
			p.z = (i/dz) % tz;
	
			// Check if we need to increase the size of the quad buffer					
			//--------------------------------------------------
			if(num_quads+24 > buffer_count*QUAD_BUFFER) {
				quads = (Quad*) realloc(quads, sizeof(Quad)*(++buffer_count)*QUAD_BUFFER);
				if (quads == NULL) { return 0; }
			}
			
			// Check adjacent voxels in the positive x,y,z directions 
			// and add a quad if they're not in the same grain
			//--------------------------------------------------
			if(p.x<tx-1 && (d+dx)->grain>=0 && (d+dx)->grain != d->grain){
				make_patch(p,X,+1,quads+num_quads, steps,(d+dx)->grain,d->grain);
				num_quads++;
			}
	
			if(p.y<ty-1 && (d+dy)->grain>=0 && (d+dy)->grain != d->grain){
				make_patch(p,Y,+1,quads+num_quads, steps,(d+dy)->grain,d->grain);
				num_quads++;
			}
			
			if(p.z<tz-1 && (d+dz)->grain>=0 && (d+dz)->grain != d->grain){
				make_patch(p,Z,+1,quads+num_quads, steps,(d+dz)->grain,d->grain);
				num_quads++;
			}		
			
		}	
	}

	printf("Number of quads: %i\n",num_quads);

	// Create a symmetric matrix of disorientations between all (adjacent) grains 
	// for fast access - we'll be doing lots of these lookups. 
	//--------------------------------------------------
	float *dis = NULL;
	dis = (float*) malloc(num_grains*num_grains*sizeof(float));
	if (dis == NULL) { return 0; }
	
	// initialise the disorientations to invalid value for debugging
	// this can be safely removed in implementation
	for(i=0;i<num_grains;i++){
	for(j=0;j<num_grains;j++){
		dis[j+i*num_grains] = 100;
	}}
	
	for(i=0;i<num_grains;i++){
		for(j=0;j<grains[i].num_adj_grains;j++){
			
			adj_grain = grains[i].adj_grains+j;
			dis[i+num_grains*adj_grain->grain] = adj_grain->disorientation;
			dis[adj_grain->grain+num_grains*i] = adj_grain->disorientation;
						
		}
	}
	//--------------------------------------------------
	
	
	// Set up the VTK objects
	//--------------------------------------------------
	vtkPoints* pts=vtkPoints::New();
	pts->SetNumberOfPoints(num_quads*4);
	
	vtkCellArray* gquads = vtkCellArray::New();
	int size = gquads->EstimateSize(num_quads,4);
	gquads->Allocate(10, 5);

	// ptr is direct pointer to underlying gquads representation,
	// see VTK documentation for details
	int *ptr = (int*) gquads->WritePointer(num_quads,size);
	
	// colors is VTK array storing the disorientation value for each face
	vtkFloatArray* colours = vtkFloatArray::New();
	colours->SetName("disorientations");
	colours->SetNumberOfComponents(1);
	colours->SetNumberOfTuples(num_quads);

	// Fill the VTK objects
	//--------------------------------------------------
	for(i=0;i<num_quads;i++){
		colours->InsertValue( i, dis[quads[i].grain1+quads[i].grain2*num_grains] );

		*(ptr++) = 4;		
		for(j=0;j<4;j++){
			*(ptr++) = k;
			pts->SetPoint(k, (double)quads[i].p[j].x,
			   				 (double)quads[i].p[j].y,
							 (double)quads[i].p[j].z);
			k++;
		}	
	}
			
	vtkPolyData* surface = vtkPolyData::New();
	surface->SetPoints(pts);
	surface->SetPolys(gquads);
	surface->GetCellData()->SetScalars(colours);
	
	
	// Clean up
	//--------------------------------------------------
	free(quads);	
	pts->Delete();
	gquads->Delete();
	free(dis);
	
	return surface;

}