Example #1
0
static void
cpos (unsigned char *message, int size)
{
  read_objects ((unsigned char *) message, nodata);
  rframe = 1;
  nodata = 0;
}
Example #2
0
void RayTracer::read_open_inventor_scene(std::string iv_file){
	SoDB::init();
	scene = new OSUInventorScene((char *)iv_file.c_str());
	read_objects();
	read_camera();
	read_lights();
	calculate_eye_coordinate_system(camera);
	calculate_image_dimentions();
	return;
}
Example #3
0
void Resources::read_all(const std::string& fdir, ZipReader *fzip, bool base_resource) throw (Exception) {
    read_tilesets(fdir + "tilesets", fzip, base_resource);
    read_objects(fdir + "objects", fzip, base_resource);
    read_charactersets(fdir + "charactersets", fzip, base_resource);
    read_npcs(fdir + "npcs", fzip, base_resource);
    read_animations(fdir + "animations", fzip, base_resource);
    read_maps(fdir + "maps", fzip, base_resource);
    read_backgrounds(fdir + "backgrounds", fzip, base_resource);
    read_fonts(fdir + "fonts", fzip, base_resource);
    read_icons(fdir + "icons", fzip, base_resource);
    read_sounds(fdir + "sounds", fzip, base_resource);
    read_musics(fdir + "music", fzip, base_resource);
    read_game_settings(fdir + "game", fzip, base_resource);
}
Example #4
0
int main(void)
{
	init();
	format();
	test_create_partition();
	create_objects();
	create_collection();
	#ifdef FULL_TEST
		remove_objects();
		write_objects();
		read_objects();
	#endif
	fini();
	return 0;
}
Example #5
0
static GList *
read_objects(xmlNodePtr objects, GHashTable *objects_hash, char *filename)
{
  GList *list;
  ObjectType *type;
  Object *obj;
  ObjectNode obj_node;
  char *typestr;
  char *versionstr;
  char *id;
  int version;

  list = NULL;

  obj_node = objects->childs;
  
  while ( obj_node != NULL) {

    if (strcmp(obj_node->name, "object")==0) {
      typestr = xmlGetProp(obj_node, "type");
      versionstr = xmlGetProp(obj_node, "version");
      id = xmlGetProp(obj_node, "id");
      
      version = 0;
      if (versionstr != NULL) {
	version = atoi(versionstr);
	free(versionstr);
      }
      
      type = object_get_type((char *)typestr);
      if (typestr) free(typestr);
      
      obj = type->ops->load(obj_node, version, filename);
      list = g_list_append(list, obj);
      
      g_hash_table_insert(objects_hash, (char *)id, obj);
   
    } else if (strcmp(obj_node->name, "group")==0) {
      obj = group_create(read_objects(obj_node, objects_hash, filename));
      list = g_list_append(list, obj);
    } else {
      message_error(_("Error reading diagram file\n"));
    }

    obj_node = obj_node->next;
  }
  return list;
}
Example #6
0
Scene::Scene (char *file) : eye(0.0, 1.0, 3.0) {
   std::ifstream in (file, std::ios::in);
   read_objects (in);
}
Example #7
0
/**
 * Recursive function to read objects from a specific level in the xml.
 *
 * Nowadays there are quite a few of them :
 * - Layers : a diagram may have different layers, but this function does *not*
 *   add the created objects to them as it does not know on which nesting level it
 *   is called. So the topmost caller must add the returned objects to the layer.
 * - Groups : groups in itself can have an arbitrary nesting level including other
 *   groups or objects or both of them. A group not containing any objects is by 
 *   definition useless. So it is not created. This is to avoid trouble with some older
 *   diagrams which happen to be saved with empty groups.
 * - Parents : if the parent relations would have been there from the beginning of
 *   Dias file format they probably would have been added as nesting level 
 *   themselves. But to maintain forward compatibility (allow to let older versions
 *   of Dia to see as much as possible) they were added all on the same level and
 *   the parent child relation is reconstructed from additional attributes.
 */
static GList *
read_objects(xmlNodePtr objects, 
             GHashTable *objects_hash,
	     DiaContext *ctx, 
	     DiaObject *parent,
	     GHashTable *unknown_objects_hash)
{
  GList *list;
  DiaObjectType *type;
  DiaObject *obj;
  ObjectNode obj_node;
  char *typestr;
  char *versionstr;
  char *id;
  int version;
  xmlNodePtr child_node;

  list = NULL;

  obj_node = objects->xmlChildrenNode;

  while ( obj_node != NULL) {
    if (xmlIsBlankNode(obj_node)) {
      obj_node = obj_node->next;
      continue;
    }

    if (!obj_node) break;

    if (xmlStrcmp(obj_node->name, (const xmlChar *)"object")==0) {
      typestr = (char *) xmlGetProp(obj_node, (const xmlChar *)"type");
      versionstr = (char *) xmlGetProp(obj_node, (const xmlChar *)"version");
      id = (char *) xmlGetProp(obj_node, (const xmlChar *)"id");
      
      version = 0;
      if (versionstr != NULL) {
	version = atoi(versionstr);
	xmlFree(versionstr);
      }

      type = object_get_type((char *)typestr);
      
      if (!type) {
	if (g_utf8_validate (typestr, -1, NULL) &&
	    NULL == g_hash_table_lookup(unknown_objects_hash, typestr))
	    g_hash_table_insert(unknown_objects_hash, g_strdup(typestr), 0);
      }
      else
      {
        obj = type->ops->load(obj_node, version, ctx);
        list = g_list_append(list, obj);

        if (parent)
        {
          obj->parent = parent;
          parent->children = g_list_append(parent->children, obj);
        }

        g_hash_table_insert(objects_hash, g_strdup((char *)id), obj);

        child_node = obj_node->children;

        while(child_node)
        {
          if (xmlStrcmp(child_node->name, (const xmlChar *)"children") == 0)
          {
	    GList *children_read = read_objects(child_node, objects_hash, ctx, obj, unknown_objects_hash);
            list = g_list_concat(list, children_read);
            break;
          }
          child_node = child_node->next;
        }
      }
      if (typestr) xmlFree(typestr);
      if (id) xmlFree (id);
    } else if (xmlStrcmp(obj_node->name, (const xmlChar *)"group")==0
               && obj_node->children) {
      /* don't create empty groups */
      GList *inner_objects = read_objects(obj_node, objects_hash, ctx, NULL, unknown_objects_hash);

      if (inner_objects) {
        obj = group_create(inner_objects);
	object_load_props(obj, obj_node, ctx);
	list = g_list_append(list, obj);
      }
    } else {
      /* silently ignore other nodes */
    }

    obj_node = obj_node->next;
  }
  return list;
}
Example #8
0
File: xymatch.c Project: krzul/dia
/*--------------------------------------------------------*/
int main(int argc, char *argv[])
{
        char    *inp1name, *inp2name, *parfname, *outfname,
                *corrname;
        short   *sat1, *sat2;
        int     i,
                nobj1, nobj2,
                nsub1, nsub2,
                nmatch,
                maxobj,
                *index;
        float   *x1, *y1, *x2, *y2,
                *mag1, *mag2,
                *xs1, *ys1, *xs2, *ys2,
                *xm1, *ym1, *xm2, *ym2,
                coeffx[3], coeffy[3];
        FILE    *outf;
        PARAMS  par;

/* IO stuff */
  if (argc != 6) usage();

  parfname = argv[1];
  inp1name = argv[2];
  inp2name = argv[3];
  outfname = argv[4];
  corrname = argv[5];

  read_params(parfname, &par);

  nobj1=read_objects(inp1name, &x1, &y1, &mag1, &sat1);
  if (par.verbose) printf("%d objects read from %s\n", nobj1, inp1name);
  if (par.nsub > nobj1) par.nsub = nobj1;
  nsub1=bright_end(nobj1, x1, y1, mag1, par.nsub, &xs1, &ys1, par.verbose);

  nobj2=read_objects(inp2name, &x2, &y2, &mag2, &sat2);
  if (par.verbose) printf("%d objects read from %s\n", nobj2, inp2name);
  if (par.nsub > nobj2) par.nsub = nobj2;
  nsub2=bright_end(nobj2, x2, y2, mag2, par.nsub, &xs2, &ys2, par.verbose);

printf("nsub1= %d\n", nsub1);
printf("nsub2= %d\n", nsub2);

  par.nsub=(nsub1 < nsub2 ? nsub1 : nsub2);
  if (par.verbose > 1) printf("par.nsub= %d\n", par.nsub);

  free(mag1);
  free(mag2);

  if (par.verbose > 2)
  {
    printf("Coordinates of the brighest objects:\n");
    printf("  X1    Y1      X2    Y2\n");
    printf("--------------------------\n");
    for (i=0; i<par.nsub; i++)
      printf("%8.2f %8.2f    %8.2f %8.2f\n", xs1[i], ys1[i], xs2[i], ys2[i]);
    printf("--------------------------\n\n");
  }

/* match nsub brightest stars for approximate transformation */
  maxobj=(nobj1 > nobj2 ? nobj1 : nobj2);
  if (par.verbose > 2) printf("maxobj= %d\n", maxobj);

  if (!(index=(int *)calloc(maxobj, sizeof(int)))) errmess("calloc(index)");

  triangles(xs1, ys1, xs2, ys2, par.nsub, par.nsub, index, par);

  if (!(xm1=(float *)malloc(sizeof(float)))) errmess("malloc(xm1)");
  if (!(ym1=(float *)malloc(sizeof(float)))) errmess("malloc(ym1)");
  if (!(xm2=(float *)malloc(sizeof(float)))) errmess("malloc(xm2)");
  if (!(ym2=(float *)malloc(sizeof(float)))) errmess("malloc(ym2)");

  nmatch=0;
  for (i=0; i<par.nsub; i++)
  {
    if (index[i] != -1)
    {
      if (!(xm1=(float *)realloc(xm1, (nmatch+1)*sizeof(float))))
        errmess("realloc(xm1)");
      if (!(ym1=(float *)realloc(ym1, (nmatch+1)*sizeof(float))))
        errmess("realloc(ym1)");
      if (!(xm2=(float *)realloc(xm2, (nmatch+1)*sizeof(float))))
        errmess("realloc(xm2)");
      if (!(ym2=(float *)realloc(ym2, (nmatch+1)*sizeof(float))))
        errmess("realloc(ym2)");

      xm1[nmatch]=xs1[i];
      ym1[nmatch]=ys1[i];
      xm2[nmatch]=xs2[index[i]];
      ym2[nmatch]=ys2[index[i]];
      nmatch++;
    }
  }

  free(xs1);
  free(ys1);
  free(xs2);
  free(ys2);

  if (nmatch < 2)
  {
    printf("ERROR: nmatch < 2\n");
    exit(2);
  }
  if (par.verbose) printf("%d objects matched by triangles()\n", nmatch);

/* linear fit to nmatch stars indentified by triangles */
  xy_lin(xm1, ym1, xm2, ym2, nmatch, coeffx, coeffy);

  free(xm1);
  free(ym1);
  free(xm2);
  free(ym2);

  if (par.verbose > 1)
  {
    printf("Linear transformation data:\n");
    printf("----------------------\n");
    for (i=0; i<3; i++)
      printf("coeffx[%d]= %12g   coeffy[%d]= %12g\n",
        i, coeffx[i], i, coeffy[i]);
    printf("----------------------\n");
  }

  nobj1=reject_saturated(nobj1, &x1, &y1, sat1);
  nobj2=reject_saturated(nobj2, &x2, &y2, sat2);
  if (par.verbose > 1)
  {
    printf("%d objects from %s left after reject_saturated()\n",
      nobj1, inp1name);
    printf("%d objects from %s left after reject_saturated()\n",
      nobj2, inp2name);
  }

  free(sat1);
  free(sat2);

/* using linear fit transform one list and look for close neighbors */
  for (i=0; i<nobj1; i++)
    maxobj=refine(coeffx, coeffy, x1, y1, x2, y2, nobj1, nobj2, index,
      par.ptol);
  if (par.verbose)
  {
    printf("%d objects left in the template list after refine()\n", maxobj);
    printf("Writing matched list to %s\n\n", outfname);
  }

  if (!(outf=fopen(outfname, "w"))) errmess("outfname");
  for (i=0; i<nobj1; i++)
    if (index[i] != -1)
      fprintf(outf, "%9.3f %10.3f %10.3f %10.3f\n",
                    x1[i], y1[i], x2[index[i]], y2[index[i]]);
  fclose(outf);

  free(index);
  free(x1); free(y1);
  free(x2); free(y2);

  if (!(outf=fopen(corrname, "w"))) errmess(corrname);

  fprintf(outf, "%d  %d  %s",
          (int)(coeffx[2]+0.5), (int)(coeffy[2]+0.5), inp2name);

  fclose(outf);

  return(0);
}
Example #9
0
/**
 * Recursive function to read objects from a specific level in the xml.
 *
 * Nowadays there are quite a few of them :
 * - Layers : a diagram may have different layers, but this function does *not*
 *   add the created objects to them as it does not know on which nesting level it
 *   is called. So the topmost caller must add the returned objects to the layer.
 * - Groups : groups in itself can have an arbitrary nesting level including other
 *   groups or objects or both of them. A group not containing any objects is by 
 *   definition useless. So it is not created. This is to avoid trouble with some older
 *   diagrams which happen to be saved with empty groups.
 * - Parents : if the parent relations would have been there from the beginning of
 *   Dias file format they probably would have been added as nesting level 
 *   themselves. But to maintain forward compatibility (allow to let older versions
 *   of Dia to see as much as possible) they were added all on the same level and
 *   the parent child relation is reconstructed from additional attributes.
 */
static GList *
read_objects(xmlNodePtr objects, 
             GHashTable *objects_hash,const char *filename, DiaObject *parent,
	     GHashTable *unknown_objects_hash)
{
  GList *list;
  DiaObjectType *type;
  DiaObject *obj;
  ObjectNode obj_node;
  char *typestr;
  char *versionstr;
  char *id;
  int version;
  xmlNodePtr child_node;

  list = NULL;

  obj_node = objects->xmlChildrenNode;

  while ( obj_node != NULL) {
    if (xmlIsBlankNode(obj_node)) {
      obj_node = obj_node->next;
      continue;
    }

    if (!obj_node) break;

    if (xmlStrcmp(obj_node->name, (const xmlChar *)"object")==0) {
      typestr = (char *) xmlGetProp(obj_node, (const xmlChar *)"type");
      versionstr = (char *) xmlGetProp(obj_node, (const xmlChar *)"version");
      id = (char *) xmlGetProp(obj_node, (const xmlChar *)"id");
      
      version = 0;
      if (versionstr != NULL) {
	version = atoi(versionstr);
	xmlFree(versionstr);
      }

      type = object_get_type((char *)typestr);
      
      if (!type) {
	if (g_utf8_validate (typestr, -1, NULL) &&
	    NULL == g_hash_table_lookup(unknown_objects_hash, typestr))
	    g_hash_table_insert(unknown_objects_hash, g_strdup(typestr), 0);
      }
      else
      {
        obj = type->ops->load(obj_node, version, filename);
        list = g_list_append(list, obj);

        if (parent)
        {
          obj->parent = parent;
          parent->children = g_list_append(parent->children, obj);
        }

        g_hash_table_insert(objects_hash, g_strdup((char *)id), obj);

        child_node = obj_node->children;

        while(child_node)
        {
          if (xmlStrcmp(child_node->name, (const xmlChar *)"children") == 0)
          {
	    GList *children_read = read_objects(child_node, objects_hash, filename, obj, unknown_objects_hash);
            list = g_list_concat(list, children_read);
            break;
          }
          child_node = child_node->next;
        }
      }
      if (typestr) xmlFree(typestr);
      if (id) xmlFree (id);
    } else if (xmlStrcmp(obj_node->name, (const xmlChar *)"group")==0
               && obj_node->children) {
      /* don't create empty groups */
      obj = group_create(read_objects(obj_node, objects_hash, filename, NULL, unknown_objects_hash));
#ifdef USE_NEWGROUP
      /* Old group objects had objects recursively inside them.  Since
       * objects are now done with parenting, we need to extract those objects,
       * make a newgroup object, set parent-child relationships, and add
       * all of them to the diagram.
       */
      {
	DiaObject *newgroup;
	GList *objects;
	Point lower_right;
	type = object_get_type("Misc - NewGroup");
	lower_right = obj->position;
	newgroup = type->ops->create(&lower_right,
				     NULL,
				     NULL,
				     NULL);
	list = g_list_append(list, newgroup);
	
	for (objects = group_objects(obj); objects != NULL; objects = g_list_next(objects)) {
	  DiaObject *subobj = (DiaObject *) objects->data;
	  list = g_list_append(list, subobj);
	  subobj->parent = newgroup;
          newgroup->children = g_list_append(newgroup->children, subobj);
	  if (subobj->bounding_box.right > lower_right.x) {
	    lower_right.x = subobj->bounding_box.right;
	  }
	  if (subobj->bounding_box.bottom > lower_right.y) {
	    lower_right.y = subobj->bounding_box.bottom;
	  }
	}
	newgroup->ops->move_handle(newgroup, newgroup->handles[7],
			       &lower_right, NULL,
			       HANDLE_MOVE_CREATE_FINAL, 0);
	/* We've used the info from the old group, destroy it */
	group_destroy_shallow(obj);
      }
#else
      list = g_list_append(list, obj);
#endif
    } else {
      /* silently ignore other nodes */
    }

    obj_node = obj_node->next;
  }
  return list;
}