Пример #1
0
int main()
{
	SmallSet S1, S2, S3;
	int x,M,N,i;
	/********** Create Set S1 **********/
	S1=CreateSet();
	printf("S1 set is \n");
	Print(S1);
	/********** Create Set S2 **********/
	S2=CreateSet();
	printf("S2 set is \n");
	Print(S2);
	
	printf("Enter the number of Elements in S1 and S2\n");
	scanf("%d%d",&M,&N);
	/********* Add Elements to S1 ******/
	printf("Add Elements to S1\n");
	for(i=0;i<M;i++)
	{
		printf("Enter the Element\n");
		scanf("%d",&x);
		S1=AddElement(x,S1);
	}
	printf("Add Elements to S2\n");
	for(i=0;i<N;i++)
	{
		printf("Enter the Element\n");
		scanf("%d",&x);
		S2=AddElement(x,S2);
	}
	printf("The Set S1 after Addition\n");
	Print(S1);
	printf("The Set S2 after Addition\n");
	Print(S2);
	printf("Enter the Element to Delete from S1\n");
	scanf("%d",&x);
	S1=RemoveElement(x,S1);
	printf("Union of S1 and S2 sets are\n");
	S3=Union(S1,S2);
	Print(S3);
	printf("Intersection of S1 and S2 sets are\n");
	S3=Intersect(S1,S2);
	Print(S3);
	printf("Complement of set S1 is\n");
	S3=Complement(S1);
	Print(S3);
	printf("Is set S1 EQUALS set S2 ?\n");
	if(Equals(S1,S2))
		printf("The Sets are EQUAL\n");
	else
		printf("The Sets are NOT EQUAL\n");
	printf("Enter the value for finding element\n");
	scanf("%d",&x);
	if(isElementOf(x,S1))
		printf("The value %d is AVAILABLE in S1\n",x);
	else
		printf("The value %d is NOT AVAILABLE in S1\n",x);

return 0;
}
Пример #2
0
/* PState: parse state and add all matches in models to ilist */
static void PState(ILink models, ILink *ilist, char *type, HMMSet *hset)
{
   IntSet states;
   int j;
   HMMDef *hmm;
   ILink h;

   states = CreateSet(maxStates);
   PIndex(states);
   SkipSpaces();
   if (ch == '.') {
      ReadCh();
      PStatecomp(models,ilist,type,states,hset);
   } else {
      ChkType('s',type);
      for (h=models; h!=NULL; h=h->next) {
         hmm = h->owner;
         for (j=2; j<hmm->numStates; j++)
            if (IsMember(states,j)) {  /* tie ->info */
               if (trace & T_ITM)
                  printf(" %12s.state[%d]\n",
                         HMMPhysName(hset,hmm),j);
               AddItem(hmm,hmm->svec+j,ilist);
            }
      }
   }
   FreeSet(states);
}
Пример #3
0
static int populate_shaders(Vector *shaders) {

	size_t i;
	size_t n;
	hash *shader;
	set *S;
	char *name, *vshader, *fshader;

	if (!shaders) return -1;
	n = sizeVector(shaders);
	for(i = 0; i < n; i++) {
		S = CreateSet();
		shader = (hash *) atVector(shaders, i);
		name = (char *) FindHashElement(shader, "name");
		vshader = (char *) FindHashElement(shader, "vshader");
		fshader = (char *) FindHashElement(shader, "fshader");
		if (!name) return i;
		if (!vshader) return i;
		if (!fshader) return i;
		InsertSetElement(S, "name");
		InsertSetElement(S, "vshader");
		InsertSetElement(S, "fshader");
		RegisterShaderScene(name, vshader, fshader);
		// clean
		free(name);
		free(vshader);
		free(fshader);
		check_and_destroy("populate_shaders", shader, S);
	}
	DestroyVector(&shaders);
	return -1;
}
Пример #4
0
static int populate_gobjs(Vector *gObjects) {

	size_t i;
	size_t n;
	hash *gobj_hash;
	set *S;
	char *fname, *dirname;

	if (!gObjects) return -1;
	n = sizeVector(gObjects);
	for(i = 0; i < n; i++) {
		S = CreateSet();
		gobj_hash = (hash *) atVector(gObjects, i);
		fname = (char *) FindHashElement(gobj_hash, "fname");
		dirname= (char *) FindHashElement(gobj_hash, "dirname");
		if (!fname) return i;
		if (!dirname) return i;
		InsertSetElement(S, "fname");
		InsertSetElement(S, "dirname");
		SceneRegisterGObject(dirname, fname);
		// clean
		free(fname);
		free(dirname);
		check_and_destroy("populate_gobjs", gobj_hash, S);
	}
	// clean
	DestroyVector(&gObjects);
	return -1;
}
Пример #5
0
int main()
{       
    FILE*in = fopen("input.txt","r");

    int Size, num;
    fscanf(in,"%d %d",&Size, &num);
    CreateSet(in, Size, num);
    
    fclose(in);
    return 0;
}
int numDistinctIslands(int**g, int gridSz, int grid0sz){
    grid = g;
    grid_length = gridSz;
    grid0length = grid0sz;
    Set*visited = CreateSet(1024);
    int t = 0;
    for(int i=0; i<gridSz; ++i) {
        for(int j=0; j< grid0sz; ++j) {
            if(grid[i][j]==1) {
                int c=dfs(i, j);
                if(!isElementInSet(visited, c)) {
                    AddToSet(visited, c);
                    ++t;
                }
            }
        }
    }
    return t;
}
Пример #7
0
static int populate_avatars(Vector *avatars) {

	size_t i;
	size_t n;
	hash *avatar;
	char *name, *camera;
	char *aux;
	set *S;
	float radius;
	int err = 0;
	Avatar *newAvatar;
	Camera *theCamera;

	if(!avatars) return -1;
	n = sizeVector(avatars);
	for(i = 0; i < n; i++) {
		S = CreateSet();
		err = 0;
		radius = 1.0;
		avatar = (hash *) atVector(avatars, i);
		name = (char *) FindHashElement(avatar, "name");
		camera = (char *) FindHashElement(avatar, "camera");
		theCamera = SceneFindCamera(camera);
		err += theCamera == NULL;
		if (!name) return i;
		if (!camera) return i;
		InsertSetElement(S, "name");
		InsertSetElement(S, "camera");
		err += read_hash_f(avatar, S, "radius", &radius);
		if (radius <= 0.0) err++;
		if (!err) {
			newAvatar = SceneRegisterAvatar(name, theCamera, radius);
			if(!newAvatar) {
				err++;
			}
		}
		// clean
		free(name);
		free(camera);
		check_and_destroy("populate_avatars", avatar, S);
	}
	return -1;
}
Пример #8
0
Region *MakeRegions(Graph *g, Image *mask)
{
  Region *r=NULL;
  int L, a, b, h, v, s;
  bool stop;
  Set *set;
  int p, q;
  int i, n;

  set = CreateSet(g->nnodes);
  n   = g->nnodes;
  for (i=0;i<g->nnodes;i++)
    if (mask->val[i])
      MakeSet(set, i);
    else
      n--;

  QuickSort(g->edges, g->nedges, sizeof(Edge), CompareEdge);

  stop = false;
  for (i=0;i<g->nedges && !stop;i++) {
    if (mask->val[g->edges[i].p] && mask->val[g->edges[i].q]) {
      p = FindSet(set,g->edges[i].p);
      q = FindSet(set,g->edges[i].q);
      if (p != q) {
        L = g->nodes[p].L / g->nodes[p].s - g->nodes[q].L / g->nodes[q].s;
        a = g->nodes[p].a / g->nodes[p].s - g->nodes[q].a / g->nodes[q].s;
        b = g->nodes[p].b / g->nodes[p].s - g->nodes[q].b / g->nodes[q].s;
        if (100 * (L * L + a * a + b * b) < MIN_DISTANCE * 195075) {
          L = g->nodes[p].L + g->nodes[q].L;
          a = g->nodes[p].a + g->nodes[q].a;
          b = g->nodes[p].b + g->nodes[q].b;
          h = g->nodes[p].h + g->nodes[q].h;
          v = g->nodes[p].v + g->nodes[q].v;
          s = g->nodes[p].s + g->nodes[q].s;
          Union(set,p,q);
          p = FindSet(set,q);
          g->nodes[p].L = L;
          g->nodes[p].a = a;
          g->nodes[p].b = b;
          g->nodes[p].h = h;
          g->nodes[p].v = v;
          g->nodes[p].s = s;
          n--;
        }
        else
          stop = true;
      }
    }
  }

  for (; i<g->nedges; i++) {
    if (mask->val[g->edges[i].p] && mask->val[g->edges[i].q]) {
      p = FindSet(set,g->edges[i].p);
      q = FindSet(set,g->edges[i].q);
      if (p != q) {
        if (100 * g->nodes[p].s < MIN_AREA * g->nnodes ||
            100 * g->nodes[q].s < MIN_AREA * g->nnodes) {
          L = g->nodes[p].L + g->nodes[q].L;
          a = g->nodes[p].a + g->nodes[q].a;
          b = g->nodes[p].b + g->nodes[q].b;
          h = g->nodes[p].h + g->nodes[q].h;
          v = g->nodes[p].v + g->nodes[q].v;
          s = g->nodes[p].s + g->nodes[q].s;
          Union(set,p,q);
          p = FindSet(set,q);
          g->nodes[p].L = L;
          g->nodes[p].a = a;
          g->nodes[p].b = b;
          g->nodes[p].h = h;
          g->nodes[p].v = v;
          g->nodes[p].s = s;
          n--;
        }
      }
    }
  }

  r = CreateRegion(n);
  i = 0;
  for (p=0; p<set->n; p++)
    if (mask->val[p] && p == FindSet(set,p))
      r->nodes[i++] = g->nodes[p];
  DestroySet(&set);

  return(r);
}
Пример #9
0
/* PStatecomp: parse a statecomp */
static void PStatecomp(ILink models, ILink *ilist, char *type,
                       IntSet states, HMMSet *hset)
{
   HMMDef *hmm;
   ILink h;
   int s,j;
   IntSet streams;
   Keyword kw;

   switch(kw=GetKey()) {
   case MIX_KEY:
   case STREAM_KEY:
      if (hset->hsKind==TIEDHS || hset->hsKind==DISCRETEHS)
         HError(7231,"PStatecomp: Cannot specify streams or mixes unless continuous");
      streams = CreateSet(SMAX);
      if(kw==STREAM_KEY) {
         PIndex(streams);
         SkipSpaces();
         if (ch != '.')
            EdError(". expected after stream spec");
         ReadCh();
         if (GetKey() != MIX_KEY)
            EdError("Mix expected after Stream index");
      } else
         AddMember(streams,1);
      SkipSpaces();
      if (ch=='[')
         PMix(models,ilist,type,states,streams,hset);
      else {
         ChkType('p',type);
         for (h=models; h!=NULL; h=h->next) {
            hmm = h->owner;
            for (j=2; j<hmm->numStates; j++)
               if (IsMember(states,j))
                  for (s=1; s<=hset->swidth[0];s++)
                     if (IsMember(streams,s)) { /* tie -> spdf */
                        if (trace & T_ITM)
                           printf(" %12s.state[%d].stream[%d]\n",
                                  HMMPhysName(hset,hmm),j,s);
                        AddItem(hmm,hmm->svec[j].info->pdf+s,ilist);
                     }
         }
      }
      FreeSet(streams);
      break;
   case DUR_KEY:
      ChkType('d',type);
      for (h=models; h!=NULL; h=h->next) {
         hmm = h->owner;
         for (j=2; j<hmm->numStates; j++)
            if (IsMember(states,j)) {  /* tie ->dur */
               if (trace & T_ITM)
                  printf(" %12s.state[%d].dur\n",
                         HMMPhysName(hset,hmm),j);
               AddItem(hmm,hmm->svec[j].info,ilist);
            }
      }
      break;
   case WEIGHTS_KEY:
      ChkType('w',type);
      for (h=models; h!=NULL; h=h->next) {
         hmm = h->owner;
         for (j=2; j<hmm->numStates; j++)
            if (IsMember(states,j)) { /* tie ->stream weights */
               if (trace & T_ITM)
                  printf(" %12s.state[%d].weights\n",
                         HMMPhysName(hset,hmm),j);
               AddItem(hmm,hmm->svec[j].info,ilist);
            }
      }
      break;
   default:
      EdError("dur, weight, stream or mix expected");
   }
}
Пример #10
0
/* PMix: parse a mixture spec */
static void PMix(ILink models, ILink *ilist, char *type,
                 IntSet states, IntSet streams,HMMSet *hset)
{
   IntSet mixes;
   HMMDef *hmm;
   ILink h;
   int s,j,m;
   MixtureElem *me;
   StreamElem *ste;
   enum {TMIX, TMEAN, TCOV} what;

   mixes = CreateSet(maxMixes);
   PIndex(mixes);
   SkipSpaces();
   what = TMIX;
   if (ch == '.') {
      ReadCh();
      switch(GetKey()) {
      case MEAN_KEY:
         what = TMEAN; ChkType('u',type); break;
      case COV_KEY:
         what = TCOV;
         ChkType('a',type);
         break;
      default:
         EdError("Mean or Cov expected");
      }
   } else
      ChkType('m',type);
   for (h=models; h!=NULL; h=h->next) {
      hmm = h->owner;
      for (j=2; j<hmm->numStates; j++)
         if (IsMember(states,j)) {
            ste = hmm->svec[j].info->pdf+1;
            for (s=1; s<=hset->swidth[0]; s++,ste++)
               if (IsMember(streams,s)) {
                  me = ste->spdf.cpdf+1;
                  for (m=1; m<=ste->nMix; m++,me++)
                     if (me->weight>MINMIX && IsMember(mixes,m)) {
                        switch (what) {
                        case TMIX: /* tie ->mpdf */
                           if (trace & T_ITM)
                              printf(" %12s.state[%d].stream[%d].mix[%d]\n",
                                     HMMPhysName(hset,hmm),j,s,m);
                           AddItem(hmm,me,ilist);
                           break;
                        case TMEAN: /* tie ->mean */
                           ChkType('u',type);
                           if (trace & T_ITM)
                              printf(" %12s.state[%d].stream[%d].mix[%d].mean\n",
                                     HMMPhysName(hset,hmm),j,s,m);
                           AddItem(hmm,me->mpdf,ilist); break;
                        case TCOV: /* tie ->cov  */
                           switch (me->mpdf->ckind) {
                           case INVDIAGC:
                           case DIAGC:
                              ChkType('v',type); break;
                           case FULLC:
                              ChkType('i',type); break;
                           case LLTC:
                              ChkType('c',type); break;
                           case XFORMC:
                              ChkType('x',type); break;
                           }
                           if (trace & T_ITM)
                              printf(" %12s.state[%d].stream[%d].mix[%d].%c\n",
                                     HMMPhysName(hset,hmm),j,s,m,*type);
                           AddItem(hmm,me->mpdf,ilist);
                           break;
                        }
                     }
               }
         }
   }
   FreeSet(mixes);
}
Пример #11
0
int main()
{
	Set S1, S2, S3;
	unsigned int x,M,N,i,Univ;
	printf("Enter the Universal Space\n");
	scanf("%d",&Univ);
	/********** Create Set S1 **********/
	CreateSet(S1,Univ);
	printf("S1 set is \n");
	PrintSet(S1,Univ);
	/********** Create Set S2 **********/
	CreateSet(S2,Univ);
	printf("S2 set is \n");
	PrintSet(S2,Univ);
	/* Create Set S3 *****************/
	CreateSet(S3,Univ);
	printf("S3 set is \n");
	PrintSet(S3,Univ);
	
	printf("Enter the number of Elements in S1 and S2\n");
	scanf("%d%d",&M,&N);
	/********* Add Elements to S1 ******/
	printf("Add Elements to S1\n");
	for(i=0;i<M;i++)
	{
		printf("Enter the Element\n");
		scanf("%d",&x);
		AddElementSet(x,S1,Univ);
	}
	printf("Add Elements to S2\n");
	for(i=0;i<N;i++)
	{
		printf("Enter the Element\n");
		scanf("%d",&x);
		AddElementSet(x,S2,Univ);
	}
	printf("The Set S1 after Addition\n");
	PrintSet(S1,Univ);
	printf("The Set S2 after Addition\n");
	PrintSet(S2,Univ);
	printf("Enter the Element to Delete from S1\n");
	scanf("%d",&x);
	RemoveElementSet(x,S1,Univ);
	printf("The Set S1 after Removal\n");
	PrintSet(S1,Univ);
	printf("Union of S1 and S2 sets are\n");
	UnionSet(S1,S2,S3,Univ);
	PrintSet(S3,Univ);
	printf("Intersection of S1 and S2 sets are\n");
	IntersectSet(S1,S2,S3,Univ);
	PrintSet(S3,Univ);
	printf("Complement of set S1 is\n");
	ComplementSet(S1,S2,Univ);
	PrintSet(S2,Univ);
	printf("Is set S1 EQUALS set S2 ?\n");
	if(EqualsSet(S1,S2,Univ))
		printf("The Sets are EQUAL\n");
	else
		printf("The Sets are NOT EQUAL\n");
	printf("Enter the value for finding element\n");
	scanf("%d",&x);
	if(isElementOfSet(x,S1,Univ))
		printf("The value %d is AVAILABLE in S1\n",x);
	else
		printf("The value %d is NOT AVAILABLE in S1\n",x);

return 0;
}
Пример #12
0
static Node *populate_nodes(hash *nodeH) {

	Vector *v;
	trfm3D *T;
	size_t i, n;
	char *name, *str;
	int has_gobj = 0;
	GObject *gobj;
	set *S;

	Node *myNode;

	S = CreateSet();

	name = FindHashElement(nodeH, "name");
	if (name) InsertSetElement(S, "name");

	myNode = CreateNode();

	v = FindHashElement(nodeH, "trfm");
	if (v) {
		InsertSetElement(S, "trfm");
		T = parse_trfms(v);
		SetTrfmNode(myNode, T);
	}

	str = FindHashElement(nodeH, "shader");
	if (str) {
		InsertSetElement(S, "shader");
		SetShaderNode(myNode, FindShaderScene(str));
		free(str);
	}

	str = FindHashElement(nodeH, "gObj");
	if (str) {
		InsertSetElement(S, "gObj");
		has_gobj = 1;
		gobj = SceneFindNameGObject(str);
		if(!gobj) {
			fprintf(stderr, "[E] populate_node: %s not found\n", str);
			PrintRegisteredGobjs();
			exit(1);
		}
		SetGobjNode(myNode, gobj);
		free(str);
	}

	v = (Vector *) FindHashElement(nodeH, "childs");
	if (v) {
		InsertSetElement(S, "childs");
		if (has_gobj) {
			fprintf(stderr, "[E] populate_nodes: node %s has gObj and children\n", name);
			exit(1);
		}
		n = sizeVector(v);
		for(i = 0; i < n; ++i) {
			AttachNode(myNode, populate_nodes((hash *) atVector(v, i)));
		}
		DestroyVector(&v);
	}
	DestroyTrfm3D(&T);
	check_and_destroy("populate_nodes", nodeH, S);
	return myNode;
}
Пример #13
0
static void apply_trfm(hash *h, trfm3D *T) {

	trfm3D *res;
	Vector *v;
	float aux[7];
	set *S;

	S = CreateSet();
	v = FindHashElement(h, "trans");
	if (v) {
		InsertSetElement(S, "trans");
		read_xyz(v, &aux[0], &aux[1], &aux[2]);
		AddTransTrfm3D(T, aux[0], aux[1], aux[2]);
		goto atr_end;
	}

	v = FindHashElement(h, "rotVec");
	if (v) {
		InsertSetElement(S, "rotVec");
		read_fv(v, 4, &aux[0]);
		AddRotVecTrfm3D(T,
						aux[0], aux[1], aux[2],
						aux[3]);
		goto atr_end;
	}

	v = FindHashElement(h, "rotAxis");
	if (v) {
		InsertSetElement(S, "rotAxis");
		read_fv(v, 7, &aux[0]);
		AddRotAxisTrfm3D(T,
						 aux[0], aux[1], aux[2],
						 aux[3], aux[4], aux[5],
						 aux[6]);
		goto atr_end;
	}

	v = FindHashElement(h, "rotX");
	if (v) {
		InsertSetElement(S, "rotX");
		read_fv(v, 1, &aux[0]);
		AddRot_X_Trfm3D(T, aux[0]);
		goto atr_end;
	}

	v = FindHashElement(h, "rotY");
	if (v) {
		InsertSetElement(S, "rotY");
		read_fv(v, 1, &aux[0]);
		AddRot_Y_Trfm3D(T, aux[0]);
		goto atr_end;
	}

	v = FindHashElement(h, "rotZ");
	if (v) {
		InsertSetElement(S, "rotZ");
		read_fv(v, 1, &aux[0]);
		AddRot_Z_Trfm3D(T, aux[0]);
		goto atr_end;
	}

 atr_end:
	check_and_destroy("apply_trfm", h, S);
	return;
}
Пример #14
0
static int populate_lights(Vector *lights) {

	size_t i;
	size_t n;
	int s;
	hash *light_h;
	char *name, *type, *aux;
	Vector *v;
	set *S;

	float r, g, b, w;
	float rgb[3], pos4[4];
	float cutoff = 30.0;
	float exp = 10.0;

	Light *l;

	if (!lights) return -1;
	n  = sizeVector(lights);
	for(i = 0; i < n; i++) {
		S = CreateSet();
		light_h = (hash *) atVector(lights, i);
		name = (char *) FindHashElement(light_h, "name");
		type = (char *) FindHashElement(light_h, "type");
		if (!check_light_type(type)) {
			fprintf(stderr, "[E] populate_lights: bad light type %s (possible values \"positional\", \"directional\", \"spotlight\")\n", type);
			exit(1);
		}

		if (!name) return i;
		if (!type) return i;
		InsertSetElement(S, "name");
		InsertSetElement(S, "type");
		l = SceneRegisterLight(name);
		v = (Vector *) FindHashElement(light_h, "pos");
		if (v) {
			InsertSetElement(S, "pos");
			read_xyz(v, &pos4[0], &pos4[1], &pos4[2]);
			pos4[3] = 1.0;
			if (!strcmp(type, "directional")) pos4[3] = 0.0;
			SetPositionLight(l, &pos4[0]);
		}

		v = (Vector *) FindHashElement(light_h, "amb");
		if (v) {
			InsertSetElement(S, "amb");
			read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			SetAmbientLight(l, &rgb[0]);
		}

		v = (Vector *) FindHashElement(light_h, "dif");
		if (v) {
			InsertSetElement(S, "dif");
			read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			SetDiffuseLight(l, &rgb[0]);
		}

		v = (Vector *) FindHashElement(light_h, "spec");
		if (v) {
			InsertSetElement(S, "spec");
			read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			SetSpecularLight(l, &rgb[0]);
		}

		if (!strcmp(type, "spotlight")) {
			aux = (char *) FindHashElement(light_h, "exp");
			if (aux) {
				InsertSetElement(S, "exp");
				sscanf(aux, "%f", &exp);
				if (exp < 0) {
					fprintf(stderr, "[E] populate_lights: negative exponent\n");
					exit(1);
				}
				free(aux);
			}
			aux = (char *) FindHashElement(light_h, "cutoff");
			if (aux) {
				InsertSetElement(S, "cutoff");
				sscanf(aux, "%f", &cutoff);
				if (exp < 0) {
					fprintf(stderr, "[E] populate_lights: negative cutoff\n");
					exit(1);
				}
				free(aux);
			}
			rgb[0] = 0.577; rgb[1] = 0.577; rgb[2] = 0.577;
			v = (Vector *) FindHashElement(light_h, "spdir");
			if (v) {
				InsertSetElement(S, "spdir");
				read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			}
			SetSpotLight(l, &rgb[0], cutoff, exp);
		}
		aux = (char *) FindHashElement(light_h, "switched");
		if (aux) {
			InsertSetElement(S, "switched");
			sscanf(aux, "%d", &s);
			if (!s) SwitchLight(l, 0);
			free(aux);
		}
		free(type);
		free(name);
		check_and_destroy("populate_lights", light_h, S);
		//DestroyHash(&light_h);
	}
	DestroyVector(&lights);
	return -1;
}
Пример #15
0
static int populate_cameras(Vector *cameras) {

	size_t i;
	size_t n;
	hash *camera;
	char *name, *type;
	char *aux;
	set *S;
	Vector *vpos, *vlat, *vup;
	float fovy, aspect, near, far;
	float pos[3];
	float lookAt[3];
	float up[3];
	int err = 0;
	Camera *newCamera;

	if(!cameras) return -1;
	n = sizeVector(cameras);
	for(i = 0; i < n; i++) {
		S = CreateSet();
		vpos = vlat = vup = NULL;
		err = 0;
		camera = (hash *) atVector(cameras, i);
		name = (char *) FindHashElement(camera, "name");
		type = (char *) FindHashElement(camera, "type");
		if (!name) return i;
		if (!type) return i;
		InsertSetElement(S, "name");
		InsertSetElement(S, "type");
		err += read_hash_f(camera, S, "fovy", &fovy);
		err += read_hash_f(camera, S, "aspect", &aspect);
		err += read_hash_f(camera, S, "near", &near);
		err += read_hash_f(camera, S, "far", &far);
		if (fovy < 0.0) err++;
		if (aspect < 0.0) err++;
		if (near <= 0.0) err++;
		if (near <= 0.0 || far < near) err++;
		if (strcmp("perspective", type)) {
			err++;
			fprintf(stderr, "[W] populate_cameras: unknown type camera %s. Skipping.\n", name);
		}
		vpos = FindHashElement(camera, "pos");
		if (vpos) {
			InsertSetElement(S, "pos");
			read_xyz(vpos, &pos[0], &pos[1], &pos[2]);
		}
		vlat = FindHashElement(camera, "lookAt");
		if (vlat) {
			InsertSetElement(S, "lookAt");
			read_xyz(vlat, &lookAt[0], &lookAt[1], &lookAt[2]);
		}
		vup = FindHashElement(camera, "up");
		if (vup) {
			InsertSetElement(S, "up");
			read_xyz(vup, &up[0], &up[1], &up[2]);
		}
		if (!err) {
			newCamera = SceneRegisterCamera(name);
			if(newCamera) {
				InitConicCamera(newCamera, fovy, aspect, near, far);
				if (vpos && vlat && vup) {
					SetCamera(newCamera,
							  pos[0], pos[1], pos[2],
							  lookAt[0], lookAt[1], lookAt[2],
							  up[0], up[1], up[2]);
				}
			} else {
				err++;
			}
		}
		// clean
		free(name);
		free(type);
		check_and_destroy("populate_cameras", camera, S);
	}
	return -1;
}