bool QgsCompositionChecker::testComposition( QString &report, int page ) { if ( !mComposition ) { return false; } #if 0 //fake mode to generate expected image //assume 300 dpi and size of the control image 3507 * 2480 QImage outputImage( QSize( 3507, 2480 ), QImage::Format_ARGB32 ); mComposition->setPlotStyle( QgsComposition::Print ); outputImage.setDotsPerMeterX( 300 / 25.4 * 1000 ); outputImage.setDotsPerMeterY( 300 / 25.4 * 1000 ); outputImage.fill( 0 ); QPainter p( &outputImage ); //QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() ); //QRectF targetArea( 0, 0, 3507, 2480 ); mComposition->renderPage( &p, page ); p.end(); outputImage.save( "/tmp/composerhtml_table_control.png", "PNG" ); return false; #endif //0 //load expected image setControlName( "expected_" + mTestName ); QImage expectedImage( mExpectedImageFile ); //get width/height, create image and render the composition to it int width = expectedImage.width(); int height = expectedImage.height(); QImage outputImage( QSize( width, height ), QImage::Format_ARGB32 ); mComposition->setPlotStyle( QgsComposition::Print ); outputImage.setDotsPerMeterX( expectedImage.dotsPerMeterX() ); outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() ); outputImage.fill( 0 ); QPainter p( &outputImage ); mComposition->renderPage( &p, page ); p.end(); QString renderedFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mTestName ).baseName() + "_rendered.png"; outputImage.save( renderedFilePath, "PNG" ); QString diffFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mTestName ).baseName() + "_result_diff.png"; bool testResult = compareImages( mTestName, 0, renderedFilePath ); QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + mTestName + "\"" " type=\"image/png\">" + renderedFilePath + "</DartMeasurementFile>" "<DartMeasurementFile name=\"Expected Image " + mTestName + "\" type=\"image/png\">" + mExpectedImageFile + "</DartMeasurementFile>" "<DartMeasurementFile name=\"Difference Image " + mTestName + "\" type=\"image/png\">" + diffFilePath + "</DartMeasurementFile>"; qDebug( ) << myDashMessage; report += mReport; return testResult; }
void TestGuiPixmaps::testEntryIcons() { Database* db = new Database(); Entry* entry = new Entry(); entry->setGroup(db->rootGroup()); QImage icon; QImage image; QPixmap pixmap; QPixmap pixmapCached1; QPixmap pixmapCached2; icon = databaseIcons()->icon(10); entry->setIcon(10); image = entry->icon(); pixmap = entry->iconPixmap(); QCOMPARE(image, icon); compareImages(pixmap, icon); pixmapCached1 = entry->iconPixmap(); pixmapCached2 = databaseIcons()->iconPixmap(10); compareImages(pixmapCached1, icon); compareImages(pixmapCached2, icon); QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey()); Uuid iconUuid = Uuid::random(); icon = QImage(2, 1, QImage::Format_RGB32); icon.setPixel(0, 0, qRgb(0, 0, 0)); icon.setPixel(1, 0, qRgb(0, 0, 50)); db->metadata()->addCustomIcon(iconUuid, icon); entry->setIcon(iconUuid); image = entry->icon(); pixmap = entry->iconPixmap(); QCOMPARE(image, icon); compareImages(pixmap, icon); pixmapCached1 = entry->iconPixmap(); compareImages(pixmapCached1, icon); QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); delete db; }
void TestGuiPixmaps::testDatabaseIcons() { QImage image; QPixmap pixmap; QPixmap pixmapCached; image = databaseIcons()->icon(0); pixmap = databaseIcons()->iconPixmap(0); compareImages(pixmap, image); // check if the cache works correctly pixmapCached = databaseIcons()->iconPixmap(0); compareImages(pixmapCached, image); QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey()); pixmap = databaseIcons()->iconPixmap(1); image = databaseIcons()->icon(1); compareImages(pixmap, image); pixmapCached = databaseIcons()->iconPixmap(1); compareImages(pixmapCached, image); QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey()); }
int main(int argc, char* argv[]) { char parallelFileName[80],sequentialFileName[80]; int scale, octave; /* Parameters */ int noOfOctaves = 2; int noOfScales = 5; int numDiffPixels; for (octave = 0; octave < noOfOctaves; octave++) { for (scale = 0; scale < noOfScales; scale++) { sprintf(parallelFileName, "../data/gauss_%d_%d_out.pgm", octave, scale); sprintf(sequentialFileName, "../data/gauss_%d_%d_ref.pgm", octave, scale); printf("Comparing image %s ...",parallelFileName); numDiffPixels = compareImages(sequentialFileName,parallelFileName); if(numDiffPixels==0) printf(" Test passed!!\n"); else printf(" Test failed!! (%d pixels differs)\n",numDiffPixels); } for (scale = 0; scale < noOfScales - 1; scale++) { sprintf(parallelFileName, "../data/dog_%d_%d_out.pgm", octave, scale); sprintf(sequentialFileName, "../data/dog_%d_%d_ref.pgm", octave, scale); printf("Comparing image %s ...",parallelFileName); numDiffPixels = compareImages(sequentialFileName,parallelFileName); if(numDiffPixels==0) printf(" Test passed!!\n"); else printf(" Test failed!! (%d pixels differs)\n",numDiffPixels); } } }
int main(int argc, char *argv[]) { if (argc != 3) { qDebug() << "Invalid params. Need two image paths to comapre."; return (1); } if (compareImages(argv[1], argv[2])) { qDebug() << "The images are the same. =]"; } else qDebug() << "The images are not the same. ='["; return 0; }
void paperRegistration::setCameraImg(cv::Mat &camImg) { cv::Mat rawImage; cvtColor(camImg, rawImage, CV_BGR2GRAY); //warp image if (status == -1 || compareImages(rawImage, lastDeviceImage) > 1.6) { warpImage(rawImage, currentDeviceImg, false); computeLocation = true; } else computeLocation = false; lastDeviceImage = rawImage.clone(); }
void paperRegistration::setCameraImg() { cv::Mat rawImage; loadCameraImage(rawImage); //warp image if (status == -1 || compareImages(rawImage, lastDeviceImage) > 1.6) { warpImage(rawImage, currentDeviceImg, true); computeLocation = true; } else computeLocation = false; lastDeviceImage = rawImage.clone(); }
bool QgsRenderChecker::runTest( QString theTestName, unsigned int theMismatchCount ) { if ( mExpectedImageFile.isEmpty() ) { qDebug( "QgsRenderChecker::runTest failed - Expected Image File not set." ); mReport = "<table>" "<tr><td>Test Result:</td><td>Expected Result:</td></tr>\n" "<tr><td>Nothing rendered</td>\n<td>Failed because Expected " "Image File not set.</td></tr></table>\n"; return false; } // // Load the expected result pixmap // QImage myExpectedImage( mExpectedImageFile ); mMatchTarget = myExpectedImage.width() * myExpectedImage.height(); // // Now render our layers onto a pixmap // QImage myImage( myExpectedImage.width(), myExpectedImage.height(), QImage::Format_RGB32 ); myImage.setDotsPerMeterX( myExpectedImage.dotsPerMeterX() ); myImage.setDotsPerMeterY( myExpectedImage.dotsPerMeterY() ); myImage.fill( qRgb( 152, 219, 249 ) ); QPainter myPainter( &myImage ); myPainter.setRenderHint( QPainter::Antialiasing ); mpMapRenderer->setOutputSize( QSize( myExpectedImage.width(), myExpectedImage.height() ), myExpectedImage.logicalDpiX() ); QTime myTime; myTime.start(); mpMapRenderer->render( &myPainter ); mElapsedTime = myTime.elapsed(); myPainter.end(); // // Save the pixmap to disk so the user can make a // visual assessment if needed // mRenderedImageFile = QDir::tempPath() + QDir::separator() + theTestName + "_result.png"; myImage.save( mRenderedImageFile, "PNG", 100 ); return compareImages( theTestName, theMismatchCount ); }
void TestDds::readImage() { QFETCH(QString, fileName); QFETCH(QSize, size); const QString path = QStringLiteral(":/data/") + fileName + QStringLiteral(".dds"); const QString sourcePath = QStringLiteral(":/data/") + fileName + QStringLiteral(".png"); ImageIO reader(path); // QVERIFY(reader.canRead()); const auto result = reader.read(); const auto &status = result.first; const auto &contents = result.second; const auto header = contents.header(); QVERIFY2(status, qPrintable(status.toString())); QCOMPARE(header.size(), size); QVERIFY2(status, qPrintable(status.toString())); QVERIFY(compareImages(contents.image(), QImage(sourcePath)) == true); }
//-------------------------------------------------------------- void testApp::draw(){ ofSetColor(0xffffff); //vidGrabber.draw(20,20); //videoTexture.draw(20+camWidth,20,camWidth,camHeight); videoImage->draw(20, 20); if (backgroundImage != NULL) { compareImages(videoImage, backgroundImage, imageBW); imageBW->draw(20+camWidth, 20); setAxes(imageBW); char theThresh[255]; sprintf(theThresh, "Threshold: %i", threshold); ofDrawBitmapString(theThresh, 840, 450); ofSetColor(255, 0, 0); // ofCircle(center[0], center[1], 5); ofPushMatrix(); ofTranslate(20+camWidth, 20); ofCircle(center[0], center[1], 5); ofLine(center[0]+(100*cos(major) ), center[1] + (100*sin(major)), center[0]-(100*cos(major) ), center[1] - (100*sin(major))); ofSetColor(0, 255, 0); ofLine(center[0]+(100*sin(minor) ), center[1] + (100*cos(minor)), center[0]-(100*sin(minor) ), center[1] - (100*cos(minor))); ofPopMatrix(); ofSetColor(0, 0, 0); char centroid[255]; sprintf(centroid, "Centroid: x: %i y: %i, Major: %f, Minor: %f", center[0], center[1], major, minor); ofDrawBitmapString(centroid, 840, 460); } }
void TestDds::testMipmaps() { QFETCH(QString, fileName); QFETCH(QSize, size); QFETCH(int, mipmapCount); const QString path = QStringLiteral(":/data/") + fileName + QStringLiteral(".dds"); ImageIO reader(path); // QVERIFY(reader.canRead()); const auto result = reader.read(); const auto &status = result.first; const auto &contents = result.second; const auto header = contents.header(); QVERIFY2(status, qPrintable(status.toString())); QCOMPARE(header.mipmapCount(), mipmapCount); for (int i = 0; i < header.mipmapCount(); ++i) { QImage image = contents.image(0, i); QVERIFY(!image.isNull()); QCOMPARE(image.size(), size / (1 << i)); QString sourcePath = QString(":/data/%1 %2.png").arg(fileName).arg(i); QVERIFY(compareImages(image, QImage(sourcePath)) == true); } }
bool QgsRenderChecker::runTest( QString theTestName, unsigned int theMismatchCount ) { if ( mExpectedImageFile.isEmpty() ) { qDebug( "QgsRenderChecker::runTest failed - Expected Image File not set." ); mReport = "<table>" "<tr><td>Test Result:</td><td>Expected Result:</td></tr>\n" "<tr><td>Nothing rendered</td>\n<td>Failed because Expected " "Image File not set.</td></tr></table>\n"; return false; } // // Load the expected result pixmap // QImage myExpectedImage( mExpectedImageFile ); mMatchTarget = myExpectedImage.width() * myExpectedImage.height(); // // Now render our layers onto a pixmap // mMapSettings.setBackgroundColor( qRgb( 152, 219, 249 ) ); mMapSettings.setFlag( QgsMapSettings::Antialiasing ); mMapSettings.setOutputSize( QSize( myExpectedImage.width(), myExpectedImage.height() ) ); QTime myTime; myTime.start(); QgsMapRendererSequentialJob job( mMapSettings ); job.start(); job.waitForFinished(); mElapsedTime = myTime.elapsed(); QImage myImage = job.renderedImage(); // // Save the pixmap to disk so the user can make a // visual assessment if needed // mRenderedImageFile = QDir::tempPath() + QDir::separator() + theTestName + "_result.png"; myImage.setDotsPerMeterX( myExpectedImage.dotsPerMeterX() ); myImage.setDotsPerMeterY( myExpectedImage.dotsPerMeterY() ); myImage.save( mRenderedImageFile, "PNG", 100 ); //create a world file to go with the image... QFile wldFile( QDir::tempPath() + QDir::separator() + theTestName + "_result.wld" ); if ( wldFile.open( QIODevice::WriteOnly ) ) { QgsRectangle r = mMapSettings.extent(); QTextStream stream( &wldFile ); stream << QString( "%1\r\n0 \r\n0 \r\n%2\r\n%3\r\n%4\r\n" ) .arg( qgsDoubleToString( mMapSettings.mapUnitsPerPixel() ) ) .arg( qgsDoubleToString( -mMapSettings.mapUnitsPerPixel() ) ) .arg( qgsDoubleToString( r.xMinimum() + mMapSettings.mapUnitsPerPixel() / 2.0 ) ) .arg( qgsDoubleToString( r.yMaximum() - mMapSettings.mapUnitsPerPixel() / 2.0 ) ); } return compareImages( theTestName, theMismatchCount ); }
int main(int argc, char **argv) { float *d_luminance; unsigned int *d_cdf; size_t numRows, numCols; unsigned int numBins; std::string input_file; std::string output_file; std::string reference_file; double perPixelError = 0.0; double globalError = 0.0; bool useEpsCheck = false; switch (argc) { case 2: input_file = std::string(argv[1]); output_file = "HW3_output.png"; reference_file = "HW3_reference.png"; break; case 3: input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = "HW3_reference.png"; break; case 4: input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = std::string(argv[3]); break; case 6: useEpsCheck=true; input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = std::string(argv[3]); perPixelError = atof(argv[4]); globalError = atof(argv[5]); break; default: std::cerr << "Usage: ./HW3 input_file [output_filename] [reference_filename] [perPixelError] [globalError]" << std::endl; system("Pause"); exit(1); } //load the image and give us our input and output pointers preProcess(&d_luminance, &d_cdf, &numRows, &numCols, &numBins, input_file); GpuTimer timer; float min_logLum, max_logLum; min_logLum = 0.f; max_logLum = 1.f; timer.Start(); //call the students' code your_histogram_and_prefixsum(d_luminance, d_cdf, min_logLum, max_logLum, numRows, numCols, numBins); timer.Stop(); cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError()); int err = printf("Your code ran in: %f msecs.\n", timer.Elapsed()); if (err < 0) { //Couldn't print! Probably the student closed stdout - bad news std::cerr << "Couldn't print timing information! STDOUT Closed!" << std::endl; system("Pause"); exit(1); } float *h_luminance = (float *) malloc(sizeof(float)*numRows*numCols); unsigned int *h_cdf = (unsigned int *) malloc(sizeof(unsigned int)*numBins); checkCudaErrors(cudaMemcpy(h_luminance, d_luminance, numRows*numCols*sizeof(float), cudaMemcpyDeviceToHost)); //check results and output the tone-mapped image postProcess(output_file, numRows, numCols, min_logLum, max_logLum); for (size_t i = 1; i < numCols * numRows; ++i) { min_logLum = std::min(h_luminance[i], min_logLum); max_logLum = std::max(h_luminance[i], max_logLum); } referenceCalculation(h_luminance, h_cdf, numRows, numCols, numBins, min_logLum, max_logLum); checkCudaErrors(cudaMemcpy(d_cdf, h_cdf, sizeof(unsigned int) * numBins, cudaMemcpyHostToDevice)); //check results and output the tone-mapped image postProcess(reference_file, numRows, numCols, min_logLum, max_logLum); cleanupGlobalMemory(); compareImages(reference_file, output_file, useEpsCheck, perPixelError, globalError); system("pause"); return 0; }
int main(int argc, char **argv) { uchar4 *h_inputImageRGBA, *d_inputImageRGBA; uchar4 *h_outputImageRGBA, *d_outputImageRGBA; unsigned char *d_redBlurred, *d_greenBlurred, *d_blueBlurred; float *h_filter; int filterWidth; std::string input_file; std::string output_file; std::string reference_file; double perPixelError = 0.0; double globalError = 0.0; bool useEpsCheck = false; switch (argc) { case 2: input_file = std::string(argv[1]); output_file = "HW2_output.png"; reference_file = "HW2_reference.png"; break; case 3: input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = "HW2_reference.png"; break; case 4: input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = std::string(argv[3]); break; case 6: useEpsCheck=true; input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = std::string(argv[3]); perPixelError = atof(argv[4]); globalError = atof(argv[5]); break; default: std::cerr << "Usage: ./HW2 input_file [output_filename] [reference_filename] [perPixelError] [globalError]" << std::endl; exit(1); } //load the image and give us our input and output pointers preProcess(&h_inputImageRGBA, &h_outputImageRGBA, &d_inputImageRGBA, &d_outputImageRGBA, &d_redBlurred, &d_greenBlurred, &d_blueBlurred, &h_filter, &filterWidth, input_file); allocateMemoryAndCopyToGPU(numRows(), numCols(), h_filter, filterWidth); /* for(int i=0;i<filterWidth; ++i) { for(int j=0;j<filterWidth; ++j) { std::cerr<<h_filter[i*filterWidth + j]<<" "; } std::cerr<<std::endl; } */ GpuTimer timer; timer.Start(); //call the students' code your_gaussian_blur(h_inputImageRGBA, d_inputImageRGBA, d_outputImageRGBA, numRows(), numCols(), d_redBlurred, d_greenBlurred, d_blueBlurred, filterWidth); timer.Stop(); cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError()); int err = printf("Your code ran in: %f msecs.\n", timer.Elapsed()); if (err < 0) { //Couldn't print! Probably the student closed stdout - bad news std::cerr << "Couldn't print timing information! STDOUT Closed!" << std::endl; exit(1); } //check results and output the blurred image size_t numPixels = numRows()*numCols(); //copy the output back to the host checkCudaErrors(cudaMemcpy(h_outputImageRGBA, d_outputImageRGBA__, sizeof(uchar4) * numPixels, cudaMemcpyDeviceToHost)); postProcess(output_file, h_outputImageRGBA); referenceCalculation(h_inputImageRGBA, h_outputImageRGBA, numRows(), numCols(), h_filter, filterWidth); postProcess(reference_file, h_outputImageRGBA); // Cheater easy way with OpenCV //generateReferenceImage(input_file, reference_file, filterWidth); compareImages(reference_file, output_file, useEpsCheck, perPixelError, globalError); checkCudaErrors(cudaFree(d_redBlurred)); checkCudaErrors(cudaFree(d_greenBlurred)); checkCudaErrors(cudaFree(d_blueBlurred)); cleanUp(); return 0; }
int main(int argc, char **argv) { uchar4 *h_rgbaImage, *d_rgbaImage; unsigned char *h_greyImage, *d_greyImage; std::string input_file; std::string output_file; std::string reference_file; double perPixelError = 0.0; double globalError = 0.0; bool useEpsCheck = false; switch (argc) { case 2: input_file = std::string(argv[1]); output_file = "HW1_output.png"; reference_file = "HW1_reference.png"; break; case 3: input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = "HW1_reference.png"; break; case 4: input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = std::string(argv[3]); break; case 6: useEpsCheck=true; input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = std::string(argv[3]); perPixelError = atof(argv[4]); globalError = atof(argv[5]); break; default: std::cerr << "Usage: ./HW1 input_file [output_filename] [reference_filename] [perPixelError] [globalError]" << std::endl; exit(1); } //load the image and give us our input and output pointers preProcess(&h_rgbaImage, &h_greyImage, &d_rgbaImage, &d_greyImage, input_file); GpuTimer timer; timer.Start(); //call the students' code your_rgba_to_greyscale(h_rgbaImage, d_rgbaImage, d_greyImage, numRows(), numCols()); timer.Stop(); cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError()); int err = printf("Your code ran in: %f msecs.\n", timer.Elapsed()); if (err < 0) { //Couldn't print! Probably the student closed stdout - bad news std::cerr << "Couldn't print timing information! STDOUT Closed!" << std::endl; exit(1); } size_t numPixels = numRows()*numCols(); checkCudaErrors(cudaMemcpy(h_greyImage, d_greyImage, sizeof(unsigned char) * numPixels, cudaMemcpyDeviceToHost)); //check results and output the grey image postProcess(output_file, h_greyImage); referenceCalculation(h_rgbaImage, h_greyImage, numRows(), numCols()); postProcess(reference_file, h_greyImage); //generateReferenceImage(input_file, reference_file); compareImages(reference_file, output_file, useEpsCheck, perPixelError, globalError); cleanup(); return 0; }
int main(int argc, char **argv) { unsigned int *inputVals; unsigned int *inputPos; unsigned int *outputVals; unsigned int *outputPos; size_t numElems; std::string input_file; std::string template_file; std::string output_file; std::string reference_file; double perPixelError = 0.0; double globalError = 0.0; bool useEpsCheck = false; switch (argc) { case 3: input_file = std::string(argv[1]); template_file = std::string(argv[2]); output_file = "HW4_output.png"; break; case 4: input_file = std::string(argv[1]); template_file = std::string(argv[2]); output_file = std::string(argv[3]); break; default: std::cerr << "Usage: ./HW4 input_file template_file [output_filename]" << std::endl; exit(1); } //load the image and give us our input and output pointers preProcess(&inputVals, &inputPos, &outputVals, &outputPos, numElems, input_file, template_file); GpuTimer timer; timer.Start(); //call the students' code your_sort(inputVals, inputPos, outputVals, outputPos, numElems); timer.Stop(); cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError()); printf("\n"); int err = printf("Your code ran in: %f msecs.\n", timer.Elapsed()); if (err < 0) { //Couldn't print! Probably the student closed stdout - bad news std::cerr << "Couldn't print timing information! STDOUT Closed!" << std::endl; exit(1); } //check results and output the red-eye corrected image postProcess(outputVals, outputPos, numElems, output_file); // check code moved from HW4.cu /**************************************************************************** * You can use the code below to help with debugging, but make sure to * * comment it out again before submitting your assignment for grading, * * otherwise this code will take too much time and make it seem like your * * GPU implementation isn't fast enough. * * * * This code MUST RUN BEFORE YOUR CODE in case you accidentally change * * the input values when implementing your radix sort. * * * * This code performs the reference radix sort on the host and compares your * * sorted values to the reference. * * * * Thrust containers are used for copying memory from the GPU * * ************************************************************************* */ thrust::device_ptr<unsigned int> d_inputVals(inputVals); thrust::device_ptr<unsigned int> d_inputPos(inputPos); thrust::host_vector<unsigned int> h_inputVals(d_inputVals, d_inputVals+numElems); thrust::host_vector<unsigned int> h_inputPos(d_inputPos, d_inputPos + numElems); thrust::host_vector<unsigned int> h_outputVals(numElems); thrust::host_vector<unsigned int> h_outputPos(numElems); reference_calculation(&h_inputVals[0], &h_inputPos[0], &h_outputVals[0], &h_outputPos[0], numElems); //postProcess(&h_outputVals[0], &h_outputPos[0], numElems, reference_file); compareImages(reference_file, output_file, useEpsCheck, perPixelError, globalError); thrust::device_ptr<unsigned int> d_outputVals(outputVals); thrust::device_ptr<unsigned int> d_outputPos(outputPos); thrust::host_vector<unsigned int> h_yourOutputVals(d_outputVals, d_outputVals + numElems); thrust::host_vector<unsigned int> h_yourOutputPos(d_outputPos, d_outputPos + numElems); checkResultsExact(&h_outputVals[0], &h_yourOutputVals[0], numElems); checkResultsExact(&h_outputPos[0], &h_yourOutputPos[0], numElems); checkCudaErrors(cudaFree(inputVals)); checkCudaErrors(cudaFree(inputPos)); checkCudaErrors(cudaFree(outputVals)); checkCudaErrors(cudaFree(outputPos)); return 0; }
//pack images, return list of positions QList<QPoint> ImagePacker::pack(QList<packedImage> *im, int heur, uint w, uint h) { int i, j, x, y; QList<packedImage*> images; for(i = 0; i < im->size(); i++) images << &im->operator [](i); crop(&images); QList<QPoint> out; // int maxRepeats = 30; // if(bruteForce == false) // maxRepeats = 1; //repeat trying to find best solution // for (int repeat = 0; repeat < maxRepeats; ++repeat) { sort(&images); out.clear(); missingChars = 0; area = 0; mergedChars = 0; neededArea = 0; MaxRects rects; MaxRectsNode mrn; mrn.r = QRect(0, 0, w, h); mrn.i = NULL; rects.F << mrn; rects.heuristic = heur; rects.leftToRight = ltr; rects.w = w; rects.h = h; QPoint pt; bool t; for(i = 0; i < images.size(); i++) { images.at(i)->merged = false; t = false; for(j = 0; j < out.size(); j++) { if(compareImages(&images.at(j)->img, &images.at(i)->img, &x, &y)) { pt = out.at(j)+QPoint(x, y); t = true; images.at(i)->merged = true; mergedChars++; break; } } if(!t) pt = rects.insertNode(&images.operator [](i)->img); if(pt != QPoint(999999,999999)) { if(!t) area += images.at(i)->img.width() * images.at(i)->img.height(); } else missingChars++; if(!t) neededArea += images.at(i)->img.width() * images.at(i)->img.height(); out << pt; images.operator [](i)->rc = QRect(pt.x(), pt.y(), images.at(i)->rc.width(), images.at(i)->rc.height()); } // if(missingChars == 0) break; } return out; }