示例#1
0
cPolyPolygon *cTankWars2005::LoadPoly(const char filename[])
{
	cPolyPolygon *pp = new cPolyPolygon();

	// temp
	char inChar, chpt[256];
	int i, j;
	int num_polypoly = 0, w = 0, h = 0;
	int num_pts, color[3];
	float offset[2], pts[2];
	cPolygon *ppolygon = NULL;


   ifstream inFs(filename, ios::in );
   if( inFs.fail() )
   {
      cerr << "File could not be opened\n";
      return pp;
   }

   inFs.get(inChar);
   if( !inFs.fail() )
   {
      inFs.putback(inChar);

      inFs >> num_polypoly;
      inFs >> w;
      inFs >> h;
		//pp->setCenter( cVector(w/2, h/2) );

      i = 0;
      while( !inFs.fail() )
      {
         inFs.get(inChar);
         while(inChar == '#')
         {
            inFs.getline(chpt, 255);
            inFs.get(inChar);
         }

         if( (inChar != '\n') && (inChar != '\r') )
         {
            inFs.putback(inChar);
				// number of point in poly
            inFs >> num_pts;
				ppolygon = new cPolygon(num_pts);

				// color
					inFs >> color[0]; // R
					inFs >> color[1]; // G
					inFs >> color[2]; // B
				ppolygon->setFillColor( RGB(color[0], color[1], color[2]) );
				//
            
				// Off Set
					inFs >> offset[0]; // X
					inFs >> offset[1]; // Y
			   //

            for(j = 0; j < num_pts; j++)
            {
					inFs >> pts[0];
					inFs >> pts[1];

					pts[0] += offset[0];
					pts[1] += offset[1];
					ppolygon->setVertex(j, cVector(pts[0], pts[1]));
            }

				pp->add(ppolygon);
            i++;
         }
      }
示例#2
0
文件: IO.cpp 项目: cran/rtk
void reassembleTmpMat(vector<string> inF, vector< string > rowNames, vector< string > colNames, string outF){
    // takes the vectors from printSimpleMap and constrcust a mat from them
    // first open all inF streams
    // iterate through and write line for line
    if(inF.size() == 0){
#ifdef notRpackage
        std::exit(99);
#endif
    }

    vector<std::ifstream*> inFs(inF.size());
    for(uint i = 0; i < inFs.size(); i++){
        std::ifstream* f = new std::ifstream(inF[i].c_str(), std::ios::in | std::ios::binary); // create in free store
        inFs[i] = f;
        inFs[i]->close();
    }

    ofstream out(outF.c_str());
    if (!out){
#ifdef notRpackage
        cerr << "Couldn't open tmpvec file " << outF << endl; std::exit(99);
#endif
    }
    out << "Rarefied";
    for(uint i = 0; i < colNames.size(); i++){
        out << '\t' << colNames[i];
    }
    out << '\n';

    string a;
    uint j = 0;
    // bufer for 1000 rows
    uint bj = 0;
    const uint bn = 1000;
    std::vector<vector< uint > > inBuff(bn, std::vector<uint>(inFs.size() ) );

    while(j < rowNames.size()){
        // fill buffer:
        for(uint i = 0; i < inFs.size(); i++){
            uint value;
            inFs[i]->open(inF[i].c_str(), std::ios::in | std::ios::binary);
            long int offset = j * sizeof(value);
            inFs[i]->seekg(offset, ios_base::beg );

            bj = 0;
            while((*inFs[i]) && bj < bn ){
                inFs[i]->read(reinterpret_cast<char*>(&value), sizeof(value));
                inBuff[bj][i] = value;
                bj++;
            }

            inFs[i]->close();
        }
        // write buffers to file
        for(uint ij = 0; ij < bj && j+ij < rowNames.size(); ij++){
            out <<  rowNames[j + ij];
            for(uint i = 0; i < inFs.size(); i++){
                out << '\t' << inBuff[ij][i];
            }
            out << '\n';
        }
        j = j + bj;

    }
    out.close();

}