Ejemplo n.º 1
0
void NumberFileGenerator::descending(std::string fileName, int amount)
{
	std::ofstream myOutputFile(fileName);

	if(myOutputFile.good() && amount > 0)
	{
		myOutputFile << amount << std::endl;
		for(int i = 1; i < amount; i++)
		{
			myOutputFile << amount - i << std::endl;
		}
		myOutputFile.close();
	}
}
Ejemplo n.º 2
0
void NumberFileGenerator::singleValue(std::string fileName, int amount, int value)
{
	std::ofstream myOutputFile(fileName);

	if(myOutputFile.good() && amount > 0)
	{
		myOutputFile << amount << std::endl;
		for(int i = 1; i < amount; i++)
		{
			myOutputFile << value << std::endl;
		}
		myOutputFile.close();
	}

}
Ejemplo n.º 3
0
void QgsRasterTransparencyWidget::pbnExportTransparentPixelValues_clicked()
{
  QgsSettings myQSettings;
  QString myLastDir = myQSettings.value( QStringLiteral( "lastRasterFileFilterDir" ), QDir::homePath() ).toString();
  QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save Pixel Values as File" ), myLastDir, tr( "Textfile" ) + " (*.txt)" );
  if ( !myFileName.isEmpty() )
  {
    if ( !myFileName.endsWith( QLatin1String( ".txt" ), Qt::CaseInsensitive ) )
    {
      myFileName = myFileName + ".txt";
    }

    QFile myOutputFile( myFileName );
    if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
    {
      QTextStream myOutputStream( &myOutputFile );
      myOutputStream << "# " << tr( "QGIS Generated Transparent Pixel Value Export File" ) << '\n';
      if ( rasterIsMultiBandColor() )
      {
        myOutputStream << "#\n#\n# " << tr( "Red" ) << "\t" << tr( "Green" ) << "\t" << tr( "Blue" ) << "\t" << tr( "Percent Transparent" );
        for ( int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
        {
          myOutputStream << '\n' << QString::number( transparencyCellValue( myTableRunner, 0 ) ) << "\t"
                         << QString::number( transparencyCellValue( myTableRunner, 1 ) ) << "\t"
                         << QString::number( transparencyCellValue( myTableRunner, 2 ) ) << "\t"
                         << QString::number( transparencyCellValue( myTableRunner, 3 ) );
        }
      }
      else
      {
        myOutputStream << "#\n#\n# " << tr( "Value" ) << "\t" << tr( "Percent Transparent" );

        for ( int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
        {
          myOutputStream << '\n' << QString::number( transparencyCellValue( myTableRunner, 0 ) ) << "\t"
                         << QString::number( transparencyCellValue( myTableRunner, 1 ) ) << "\t"
                         << QString::number( transparencyCellValue( myTableRunner, 2 ) );
        }
      }
    }
    else
    {
      QMessageBox::warning( this, tr( "Save Pixel Values as File" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
    }
  }
}
Ejemplo n.º 4
0
void NumberFileGenerator::random(std::string fileName, int amount, int min, int max)
{
	std::default_random_engine generator(time(nullptr));
	std::uniform_int_distribution<int> distribution(min, max);
	std::ofstream myOutputFile(fileName);
    int randomNumber;

	if(myOutputFile.good() && amount > 0)
	{
		myOutputFile << amount << std::endl;
		for(int i = 1; i < amount; i++)
		{
			randomNumber = distribution(generator);
			myOutputFile << randomNumber << std::endl;
		}
		myOutputFile.close();
	}
}
Ejemplo n.º 5
0
void SortDriver::run(int argc, char** argv){
    std::string sortName=argv[2];
    std::string inFileName=argv[3];
    std::string outFileName=argv[4];
    std::ifstream input(inFileName);
    if(areParametersValid(sortName, inFileName)){
        std::ofstream myOutputFile(outFileName);
        int size=SortDriver::getFileCount(input);
        int* arr=SortDriver::createArray(input, size);
        double elapsed;
        std::cout << "Calculating sort timing information\n";
        if(sortName=="-bubble"){
            elapsed=Sorts<int>::sortTimer(Sorts<int>::bubbleSort, arr, size);
            myOutputFile << "bubble " << size << " " << elapsed;
        }
        else if(sortName=="-selection"){
            elapsed=Sorts<int>::sortTimer(Sorts<int>::selectionSort, arr, size);
            myOutputFile << "selection " << size << " " << elapsed;
        }
        else if(sortName=="-insertion"){
            elapsed=Sorts<int>::sortTimer(Sorts<int>::insertionSort, arr, size);
            myOutputFile << "insertion " << size << " " << elapsed;
        }
        else if(sortName=="-quick"){
            elapsed=Sorts<int>::sortTimer(Sorts<int>::quickSort, arr, size);
            myOutputFile << "quick " << size << " " << elapsed;
        }
        else if(sortName=="-quick3"){
            elapsed=Sorts<int>::sortTimer(Sorts<int>::quickSortWithMedian, arr, size);
            myOutputFile << "quick3 " << size << " " << elapsed;
        }
        else if(sortName=="-merge"){
            elapsed=Sorts<int>::sortTimer(Sorts<int>::mergeSort, arr, size);
            myOutputFile << "selection " << size << " " << elapsed;
        }
        else if(sortName=="-all"){
            std::cout << "Didn't have time to finish the -all case. Sorry!\n";
        }
        std::cout << "Calculations finished. Results stored in " << outFileName << "\n"
                  << "Exiting...\n";

    }
}