コード例 #1
0
ファイル: beamtest.cpp プロジェクト: jf---/openshapefactory
void beamtest::writebinarytochunkswithcolor()
	{
QFileInfo fileInfo;

QString filename = QFileDialog::getOpenFileName ( this,tr("Import File"),
												 "",tr( "All point cloud formats (*.ptx);;"
												 "XYZ (*.xyz *XYZ);;"
												 "PTX (*.ptx *.PTX)"));



	
		 int chunk = 2000000;
		 //int numfiles = floor((double) shapecount / (double) chunk);
		 int shapecounter=0;
		 int filecounter = 0;

double chunksize= 2000000;
int count =0;
int debugcount = 0;
char buf[1024];
QFile file(filename);
qint64 lineLength=0;
QStringList linelist;

QString filename2 = QFileDialog::getSaveFileName(this, tr("SaveBinary"), " ",tr("dat (*.dat "));
QFile file2(filename2);
 file2.open(QIODevice::WriteOnly);
 QDataStream out(&file2);   // we will serialize the data into the file

 	fileInfo.setFile(filename2);

	QString dirname = fileInfo.absoluteDir().absolutePath();
	filename = fileInfo.fileName();
	QString basename = fileInfo.baseName();
	QString bundlename = fileInfo.bundleName();

 if (file.open(QFile::ReadOnly)) {
        do {

    lineLength = file.readLine(buf, sizeof(buf));
    if (lineLength != -1) {
        QString line(buf);

        linelist = line.split(tr(" "));

        if (linelist.size() == 4)
        {
			
			double x = linelist.at(0).toDouble();
            double y = linelist.at(1).toDouble();
            double z = linelist.at(2).toDouble();
			double intensity= linelist.at(3).toDouble();
			if(x != 0 && y != 0 && z != 0 )
			{
			count++;
			shapecounter++;
				if(shapecounter == chunk)
					{
					
					shapecounter = 0;
					filecounter++;
					QString curfilename = dirname + tr("/") + basename + QString::number(filecounter) + tr(".data");
					file2.close();
					file2.setFileName(curfilename);
					file2.open(QFile::WriteOnly);
					
			
					}


			if (count % 100000 == 0) qDebug() << count;

			out << x << y << z << intensity;
			}

        }

   //if (count > 10000) break;


    }
        }while (lineLength != -1);
 }


if(file2.isOpen()) file2.close();






	}