Пример #1
0
void Cell::initPixmaps()
{
  typedef QMap<int, QString> NamesMap;
  NamesMap names;
  names[L]     = "0001";
  names[D]     = "0010";
  names[D|L]   = "0011";
  names[R]     = "0100";
  names[R|L]   = "0101";
  names[R|D]   = "0110";
  names[R|D|L] = "0111";
  names[U]     = "1000";
  names[U|L]   = "1001";
  names[U|D]   = "1010";
  names[U|D|L] = "1011";
  names[U|R]   = "1100";
  names[U|R|L] = "1101";
  names[U|R|D] = "1110";

  NamesMap::ConstIterator it;
  for(it = names.constBegin(); it != names.constEnd(); ++it)
  {
    connectedpixmap[it.key()] = new QPixmap(":/cable" + it.value() + ".png");

    QImage image = connectedpixmap[it.key()]->toImage();
    for(int y = 0; y < image.height(); y++)
    {
      QRgb* line = (QRgb*)image.scanLine(y);
      for(int x = 0; x < image.width(); x++)
      {
        QRgb pix = line[x];
        if(qAlpha(pix) == 255)
        {
          int g = (255 + 4 * qGreen(pix)) / 5;
          int b = (255 + 4 * qBlue(pix)) / 5;
          int r = (255 + 4 * qRed(pix)) / 5;
          line[x] = qRgb(r, g, b);
        }
      }
    }

    disconnectedpixmap[it.key()] = new QPixmap(QPixmap::fromImage(image));
  }
}
Пример #2
0
void Cell::initPixmaps()
{
    typedef QMap<int, QString> NamesMap;
    NamesMap names;
    names[L]     = "0001";
    names[D]     = "0010";
    names[D|L]   = "0011";
    names[R]     = "0100";
    names[R|L]   = "0101";
    names[R|D]   = "0110";
    names[R|D|L] = "0111";
    names[U]     = "1000";
    names[U|L]   = "1001";
    names[U|D]   = "1010";
    names[U|D|L] = "1011";
    names[U|R]   = "1100";
    names[U|R|L] = "1101";
    names[U|R|D] = "1110";

    NamesMap::ConstIterator it;
    for(it = names.constBegin(); it != names.constEnd(); ++it)
    {
	connectedpixmap[it.key()] =
	    new QPixmap(QPixmap(":/pics/cable" + it.value() + ".png"));
	disconnectedpixmap[it.key()] =
	    new QPixmap(fadedPixmap(* connectedpixmap[it.key()]));
    }

    const int w = QPixmap(":/pics/background.png").width();
    QPixmap pixmap(":/pics/shadow.png");
    const int x1 = (pixmap.width() - w) / 2;
    const int x2 = pixmap.width() - w;
    shadowpixmap[NoShadow] = new QPixmap();
    shadowpixmap[TopLeftShadow]  = new QPixmap(pixmap.copy(0,  0,  w, w));
    shadowpixmap[TopShadow]      = new QPixmap(pixmap.copy(x1, 0,  w, w));
    shadowpixmap[TopRightShadow] = new QPixmap(pixmap.copy(x2, 0,  w, w));
    shadowpixmap[LeftShadow]     = new QPixmap(pixmap.copy(0,  x1, w, w));
    shadowpixmap[RightShadow]    = new QPixmap(pixmap.copy(x2, x1, w, w));
    shadowpixmap[BottomLeftShadow]  = new QPixmap(pixmap.copy(0,  x2, w, w));
    shadowpixmap[BottomShadow]      = new QPixmap(pixmap.copy(x1, x2, w, w));
    shadowpixmap[BottomRightShadow] = new QPixmap(pixmap.copy(x2, x2, w, w));

}
Пример #3
0
void createDataStructures(){
	ifstream myfile;
	myfile.open ("../../iv04/additional/tableform_data/articles_by_author_dupcorrect.txt");
	string article_id, author_id, authorname;
	int num_author;
	
	if (!myfile){
		printf("createDataStructures:: Error in openening file \n");
	}
	else {
		while (!myfile.eof( )){ 
			myfile >> article_id >> num_author >> author_id;
			getline(myfile, authorname);
			
			if ( author_id_name.count(author_id)>0 ) { 
			}
			else{
				author_id_name[author_id] = authorname;
				author_by_id[author_id] = new Author(author_id);
				authors.push_back(author_by_id[author_id]);
			}
			
			/*
			
			if( article_id_art.count(article_id) > 0) {
			}
			else {
				article_id_art[article_id] = new Article(article_id, num_author);
				articles.push_back(article_id_art[article_id]);
			}
			
			*/
			//Article * a = article_id_art[article_id];
			//Author * auth = author_by_id[author_id]; 
			
			//a-> addAuthor(author_id);
			//auth -> addPub(article_id);
		}
	}
	myfile.close();
	
}
Пример #4
0
void testDataStructures(){
	printf("number of unique authors: %d \n", (int)author_id_name.size());
	printf("number of unique articles: %d \n", (int)article_id_art.size());
	
	printf("created authors: %d \n", (int) authors.size());
	
	Article * lastarticle = articles.back();
	vector<string> lastauthors = lastarticle->authorsList();
	
	for (int s=0; s < lastauthors.size(); s++) {
		printf("author %d is: %s \n", s+1, lastauthors.at(s).c_str());
	}
	
	Author * lastauthor = authors.back();
	vector<string> lastauthpubs = lastauthor->pubsList();
	
	for (int p=0; p < lastauthpubs.size(); p++) {
		printf("pubs %d is: %s \n", p+1, lastauthpubs.at(p).c_str());
	}
	
}
Пример #5
0
void createGraphDataStructures(){
	//create graph nodes
	map<string, string>::iterator auth;
	
	for(auth = author_id_name.begin(); auth != author_id_name.end(); auth++) {
		string idd = auth->first;
		string authorname = auth->second;
		int idpos = nodes.size();
		GraphNode * anewnode = new GraphNode (idpos, idd, authorname);
		gnode_by_id[idd] = anewnode;
		nodes.push_back(anewnode);
	}
	
	//now create edges
	map<string, Article*>::iterator art;
	for(art = article_id_art.begin(); art != article_id_art.end(); art++) {
		string articleid = art->first;
		Article* thearticle = art->second;
		
		vector<string> auths = thearticle->authorsList();
		//for each author in an article, create an edge connecting that to the rest
		
		for (int s= 0; s<auths.size(); s++) {
			string auth1 = auths.at(s);
			
			for (int rest=s+1; rest<auths.size(); rest++) {
				string auth2 = auths.at(rest);
				
				if (auth1 == auth2) {
					printf("ERROR: author duplicate %s \n", auth1.c_str());
				}
				
				
				//create an edge between aut1 and aut2
				//but...
				//need to prevent duplicates
				
				string edgekey1 = auth1+auth2;
				string edgekey2 = auth2+auth1;  //whichever encountered before, we don't know
				
				
				if (edges_by_ids.count(edgekey1) > 0 || edges_by_ids.count(edgekey2) > 0 ) {
					//this edge exists
				}
				else{
					int posid = edges.size();
					GraphEdge * anewedge = new GraphEdge(posid, auth1, auth2);
					edges.push_back(anewedge);
					
					edges_by_ids[edgekey1] = anewedge;
					edges_by_ids[edgekey2] = anewedge;
					
				}
				
				
			}
			
		}
	}
	
	//now print all edges
	//printf("all number of edges created % d \n ", (int)edges.size());
	
	//edges sanity check
	/*
	for (int e=0; e<edges.size(); e++) {
		GraphEdge * edg = edges.at(e);
		string efrom =  edg->from;
		string eto =  edg->to;
		for (int c=0; c<edges.size(); c++) {
			GraphEdge * compare = edges.at(c);
			if (compare->from == efrom && compare->to == eto) {
				if (e != c) {
					printf("duplicate at: %d, %d \n", e, c);
				}
				
			}
		}
		
		//printf("edge id: %d, from: %s, to: %s \n", edg->getEdgeid(), edg->from.c_str(), edg->to.c_str());
	}
	 */
	
}