Beispiel #1
0
void adddirtoscene(Scene *s,DirRec *dr,V3d pos,V3d up) {
//  printf("Adding directory %s\n",dr->fname);
    s->add(new Cylinder(pos+0.0*up,pos+1.0*up,0.05*up.mod()));
    pos=pos+up;
//  s->add(new TextRend(dr->fname,10,pos,0.3));
    OrderedList<FileRec> ol;
    for (int i=1; i<=dr->fs.len; i++) {
        FileRec *r=dr->fs.num(i);
        ol.add(r,ordering(r));
    }
    V3d x=V3d::normcross(up,V3d::k)*up.mod()*0.8;  // Actually, want y=closest to real z
    V3d y=V3d::normcross(up,x)*up.mod()*0.8;
    for (int i=1; i<=ol.len; i++) {
        FileRec *r=ol.p2num(i);
//    printf("  %s\n",r->fname);
        float ang=((i%2)==0?1:-1)*(pi*(float)(i-1)/(float)(ol.len-1));
        V3d d=up+x*mysin(ang)+y*mycos(ang); // Bad, should do rotation instead.
        if (Seq(r->type(),"file")) {
            //s->add(new Cylinder(pos+0.0*d,pos+0.2*d,0.05*up.mod()));
            s->add(new Sphere(pos+0.1*d,0.02*up.mod()));
//      s->add(new TextRend(r->fname,10,pos+d,0.1));
        } else {
            DirRec *dr2=(DirRec *)r;
            adddirtoscene(s,dr2,pos,d.norm()*up.mod()*0.9);
        }
    }
}
Beispiel #2
0
int main(){
	List x;
	OrderedList y;

	x.insert(5);
	x.insert(1);
	x.insert(3);

	cout << x << endl; //should print 5, 1, 3,
	x.replace(2, 6);
	cout << x << endl; //should print 5, 6, 3,
	x.insert(2);
	cout << x << endl; //should print 5, 6, 3, 2,

	y.insert(5);
	y.insert(1);
	y.insert(3);
	cout << y << endl; //should print 1, 3, 5,

	y.replace(2, 6);
	cout << y << endl; //should print 1, 5, 6,
	y.insert(2);
	cout << y << endl; //should print 1, 2, 5, 6,

	return 1;
}
Beispiel #3
0
int main (int argc, char const *argv[])
{
	OrderedList<int>* ol = new OrderedList<int>();
		
	
	//*******************************************************************
	//*                         Testing At
	//*******************************************************************
	cout<<"testing at:\n";
	ol->insert(new int(45)); cout<<"\tinsert";
	ol->insert(new int(35)); cout<<"\tinsert";
	ol->insert(new int(25)); cout<<"\tinsert";
	ol->insert(new int(60)); cout<<"\tinsert";
	cout<<endl;

	print_list(ol);

	int* c = ol->at(0);
	cout<<"\tindex 0 is: "<<*c<<endl;
	c = ol->at(2);
	cout<<"\tindex 2 is: "<<*c<<endl;
	c = ol->at(ol->size()-1);
	cout<<"\tindex at the end is: "<<*c<<endl;
	
	cout <<"Scan in reverse:\n";
	vector<int*> v = ol->scan_rev();
	for (int i = 0; i < v.size(); ++i) { //olist->scan() returns a vector of pointers
		int* p = v[i];
		cout << *p << endl;        //to ints
	}
	cout<<endl;
	
	
}
Beispiel #4
0
void testOrderedList() {
    OrderedList<int> mycontainer;

    cout << "\n\n Begin test function for the List<T> class\n";

    // Testing the insert, isEmpty, length, toString functions
    cout << "Testing size of new empty container: " << mycontainer.length() << endl;
    cout << "List contains: " << mycontainer.toString() << "\n";

    cout << "Testing insert(1), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.insert(1);
    cout << "List contains: " << mycontainer.toString() << "\n";
    cout << "Size is " << mycontainer.length() << endl;

    cout << "Testing insert(2), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.insert(2);
    cout << "List contains: " << mycontainer.toString() << "\n";
    cout << "Size is " << mycontainer.length() << endl;

    cout << "Testing insert(4), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.insert(4);
    cout << "List contains: " << mycontainer.toString() << "\n";
    cout << "Size is " << mycontainer.length() << endl;

    cout << "Testing insert(2), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.insert(2);
    cout << "List contains: " << mycontainer.toString() << "\n";
    cout << "Size is " << mycontainer.length() << endl;

    cout << "Testing insert(3), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.insert(3);
    cout << "List contains: " << mycontainer.toString() << "\n";
    cout << "Size is " << mycontainer.length() << endl;

    cout << "Testing insert(7), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.insert(7);
    cout << "List contains: " << mycontainer.toString() << "\n";
    cout << "Size is " << mycontainer.length() << endl << endl;


    int size = mycontainer.length();

    cout << "Testing extract(int), first(), last(), length() and isEmpty() functions \n"
            << "in a for loop with iterations greater than container size.";

    for (int i = 0; i < size + 1; i++) {
        cout << "\nIteration: " << i + 1 << "\n";
        if (!mycontainer.isEmpty()) {
            cout << "\tmycontainer is empty? " << (mycontainer.isEmpty() ? " true\n" : "false\n");
            cout << "\tList size before remove is " << mycontainer.length() << endl;
            cout << "\tFirst of container is " << mycontainer.first() << endl;
            cout << "\tLast of container is " << mycontainer.last() << endl;
            cout << "\tExtracting: " << i + 1 << endl << endl;
            mycontainer.extract(i + 1);
            cout << "\tmycontiner has: " << mycontainer.toString() << "\n";
        } else {
            cout << "\tmycontainer is empty.\n";
        }

        cout << "\tList size is now: " << mycontainer.length() << endl;
    }
    cout << "\nFinished for loop\n";

    cout<<"\nClearing container and filling it with int starting with 5 up to 10\n";
    mycontainer.clear();
    for (int i = 1; i < 7; i++)
        mycontainer.insert(i + 4);
    cout<<"mycontainer has: "<<mycontainer.toString()<<"\n";

    cout << "\nTesting removeFirst(),removeLast(), first(), last(), length() and isEmpty() functions \n"
            << "in a for loop with iterations greater than container size.";

    for (int i = 0; i < size + 1; i++) {
        cout << "\nIteration: " << i + 1 << "\n";
        if (!mycontainer.isEmpty()) {
            cout << "\tmycontainer is empty? " << (mycontainer.isEmpty() ? " true\n" : "false\n");
            cout << "\tList size before remove is " << mycontainer.length() << endl;
            cout << "\tFirst of container is " << mycontainer.first() << endl;
            cout << "\tLast of container is " << mycontainer.last() << endl;
            cout << "\tRemoving First: \n";
            mycontainer.removeFirst();
            cout << "\tmycontainer has: " << mycontainer.toString() << "\n";
            cout << "\tRemoving Last: \n";
            mycontainer.removeLast();
            cout << "\tmycontainer has: " << mycontainer.toString() << "\n";
        } else {
            cout << "\tmycontainer is empty.\n";
        }

        cout << "\tList size is now: " << mycontainer.length() << endl;
    }
    cout << "\nFinished for loop\n";

    cout << "\nTesting the reference for first() and last() functions.\n";
    cout << "Start with int test = 7. mycontainer.insert(test)\n";
    int test = 7;
    mycontainer.insert(test);
    cout << "Testing with test = 8. test=mycontainer.front(). mycontainer.front() = 13 \n";
    test = 8;
    test = mycontainer.first();
    mycontainer.first() = 13;
    cout << "Test is now " << test << " front of container is " << mycontainer.first()
            << " back of container is " << mycontainer.last() << endl;
    test = 11;
    mycontainer.insert(test);
    cout << "Back of container is: " << mycontainer.last() << endl;
    cout << "Test is now " << test << " front of container is " << mycontainer.first()
            << " back of container is " << mycontainer.last() << endl;
    mycontainer.last() = test;
    cout << "Test is now " << test << " front of container is " << mycontainer.first()
            << " back of container is " << mycontainer.last() << endl;

    cout << "mycontainer size is " << mycontainer.length() << endl;

    cout << "\nTesting the clear() function: \n";
    mycontainer.clear();
    cout << "mycontainer size now is " << mycontainer.length()
            << " mycontainer is empty: "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");


    cout << "\n\nTesting insertBefore and insertAfter fucntions.\n";
    cout << "\nBegin by inserting ints starting at 13\n";
    for (int i = 0; i < 5; i++) {
        mycontainer.insert(i + 13);
    }

    cout << "\n\nTesting contains(400): " << (mycontainer.contains(400) ? " true\n" : "false\n");
    cout << "\n\nTesting contains(711): " << (mycontainer.contains(711) ? " true\n" : "false\n");

    cout << "\nTesting assignment operator: container2 = mycontainer\n";
    cout << "Filling mycontainer with ints starting at 42\n";
    size = 5;
    // Fill mycontainer with ints to test copy constructor
    for (int i = 0; i < size; i++) {
        mycontainer.insert(i + 42);
    }


    cout << "mycontainer size now is " << mycontainer.length()
            << " mycontainer is empty: "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    cout << "mycontainer has: " << mycontainer.toString() << "\n";

    OrderedList<int> container2;
    container2 = mycontainer;
    cout << "mycontainer size is: " << mycontainer.length() << endl;
    cout << "container2 size is: " << container2.length() << endl;
    cout << "Testing the contents of container2 and mycontainer:\n";
    cout << "mycontainer has: " << mycontainer.toString() << "\n";
    cout << "container2 has: " << container2.toString() << "\n";

    cout << "\nTesting the copy constructor.\n";

    cout << "mycontainer size now is " << mycontainer.length()
            << " mycontainer is empty: "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");

    OrderedList<int> container3(mycontainer);

    cout << "container3 size is: " << container3.length();
    cout << "\nTesting the contents of mycontainer and container3:\n";
    cout << "mycontainer has: " << mycontainer.toString() << "\n";
    cout << "container3 has: " << container2.toString() << "\n";

    cout << "\nEnd of test function for the List<T> class\n\n";
}
Beispiel #5
0
int main(int argc,String *argv) {
  ArgParser a=ArgParser(argc,argv);
  String imagefile=a.getarg("Image file");
  String boolfile=a.getarg("Binary file");
  a.done();
  
  RGBmp *p=RGBmp::readfile(imagefile);
  Map2d<float> *b=Map2d<float>::readfile(boolfile);
//  rad=0;
//  Map2d<float> *gs=p->getgreyscale();
//  gs=gs->smoothed(rad);

  printf("Picture %i %i clipped mask %i %i\n",p->width,p->height,b->width,b->height);
  
  // Find regions, keep largest region, and split
  List< Region * > *l=b->getrealregions();
  printf("Got %i regions.\n",l->len);

/*  int larea=-1;
  int largest=-1;
  for (int i=1;i<=l->len;i++) {
    printf("*");
    if (l->num(i)->area()>larea) {
      larea=l->num(i)->area();
      largest=i;
    }
  }*/

  OrderedList< Region * > ol;
  for (int i=1;i<=l->len;i++)
    ol.add(l->p2num(i),l->num(i)->area());
  
  pos=V3d(1,1,0);
  ori=Ori::indir(V3d(0,0,1)-V3d(1,1,0));

  for (int i=ol.len;i>=1;i--) {

  Region *vs=ol.num(i);
  printf("Recovered largest.\n");

  printf("Generating points...\n");
  octree->clear();
    List<V2d> ps=*vs->getlist();
    for (int i=1;i<=ps.len;i++) {
      int x=ps.num(i).x;
      int y=ps.num(i).y;
      myRGB r=p->getpos(x,y);
      octree->add(V3d((float)r.r/128.0,(float)r.g/128.0,(float)r.b/128.0));
    }

  for (int i=0;i<=100;i++) {
    octree->add(V3d((float)i*255.0/100.0/128.0,0,0));
    octree->add(V3d(0,(float)i*255.0/100.0/128.0,0));
    octree->add(V3d(0,0,(float)i*255.0/100.0/128.0));
  }

  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  PPsetup(scrwid,scrhei,2.0);

  visengfly();

  if (key[KEY_ESC])
    break;

  }

  allegroexit();
  
}
Beispiel #6
0
int main(int argc, char** argv) {
    NodeList<int> llista;
    OrderedList<int> llistaOrd;
    cout << "Vols introduir les dades per consola o per fitxer (C/F)?" << endl;
    if(cin.get() == 'F') {
        FILE * pFile;
        pFile = fopen("fitxer.txt" , "r");
        
        int n;
        ifstream fe("fitxer.txt");
        while (scanf("%d", &n) == 1) {
            llista.insert(n);
            llistaOrd.insert(n);
        }
    }
    else {
        cout << "Introdueix una seqüència de nombres acabada per 99:" << endl;
        int aux;
        cin >> aux;
        while(aux != 99) {
            llista.insert(aux);
            llistaOrd.insert(aux);
            cin >> aux;
        }
    }
    cout << "Llista: ";
    llista.show();
    cout << "Llista Ordenada: ";
    llistaOrd.show();
    cout << endl << "Introdueix un nombre a cercar:" << endl;
    cin >> aux;
    cout << "Nombres posteriors a " << aux << " a la llista:" << endl;
    llista.begin();
    bool trobat = false;
    while(!llista.end()) {
        if(trobat) {
            cout << llista.get() << "  " ; 
        }
        else {
            if(llista.get() == aux) trobat = true;
        }
        llista.next();
    }
    cout << endl << "Nombres posteriors a " << aux << " a la llista ordenada:" <<endl;  
    trobat = false;
    llistaOrd.begin();
    while(!llistaOrd.end()) {
        if(trobat) {
            cout << llistaOrd.get() << "  " ; 
        }
        else {
            if(llistaOrd.get() == aux) trobat = true;
        }
        llistaOrd.next();
    }    
    cout << endl << "Llista esborrada i recursos alliberats" << endl;
    llista.begin();
    while(!llista.end()) {
        llista.remove();
    }
    cout << "Llista ordenada esborrada i recursos alliberats:" << endl;
    llistaOrd.begin();
    while(!llistaOrd.end()) {
        
        llistaOrd.remove();
    }
    cout << "Llista:" << endl;
    llista.show();
    cout << "Llista ordenada:" << endl;
    llistaOrd.show();
    return 0;
}
int main() {
  OrderedList* ol = new OrderedList();

  ol->insert(5);
  ol->print();

  ol->insert(7);
  ol->print();

  ol->insert(6);
  ol->print();

  ol->insert(10);
  ol->print();

  ol->insert(8);
  ol->print();

  return 0;
}