void PlotMatrix::alignAxes( int rowOrColumn, int axis ) { if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) { double maxExtent = 0; for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); QwtScaleDraw *sd = scaleWidget->scaleDraw(); sd->setMinimumExtent( 0.0 ); const double extent = sd->extent( scaleWidget->font() ); if ( extent > maxExtent ) maxExtent = extent; } } for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } } else { double maxExtent = 0; for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); QwtScaleDraw *sd = scaleWidget->scaleDraw(); sd->setMinimumExtent( 0.0 ); const double extent = sd->extent( scaleWidget->font() ); if ( extent > maxExtent ) maxExtent = extent; } } for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } } }
QBrush QWellArray::cellBrush(int row, int col) { if (d && row >= 0 && row < numRows() && col >= 0 && col < numCols()) return d->brush[row*numCols()+col]; return Qt::NoBrush; }
void PlotMatrix::scaleDivChanged() { if ( d_data->inScaleSync ) return; d_data->inScaleSync = true; QwtPlot *plt = NULL; int axisId = -1; int rowOrColumn = -1; // find the changed axis for ( int row = 0; row < numRows(); row++ ) { for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( row, col ); if ( p ) { for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( p->axisWidget( axis ) == sender() ) { plt = p; axisId = axis; if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop ) rowOrColumn = col; else rowOrColumn = row; } } } } } if ( plt ) { const QwtScaleDiv scaleDiv = plt->axisScaleDiv( axisId ); // synchronize the axes if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop ) { for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p != plt ) { p->setAxisScaleDiv( axisId, scaleDiv ); } } } else { for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p != plt ) { p->setAxisScaleDiv( axisId, scaleDiv ); } } } updateLayout(); } d_data->inScaleSync = false; }
//return types are void since any internal error will be handled by quitting //no point in returning error codes... //returns a pointer to an RGBA version of the input image //and a pointer to the single channel grey-scale output //on both the host and device void preProcess(uchar4 **h_inputImageRGBA, uchar4 **h_outputImageRGBA, uchar4 **d_inputImageRGBA, uchar4 **d_outputImageRGBA, unsigned char **d_redBlurred, unsigned char **d_greenBlurred, unsigned char **d_blueBlurred, float **h_filter, int *filterWidth, const std::string &filename) { //make sure the context initializes ok checkCudaErrors(cudaFree(0)); cv::Mat image = cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR); if (image.empty()) { std::cerr << "Couldn't open file: " << filename << std::endl; exit(1); } cv::cvtColor(image, imageInputRGBA, CV_BGR2RGBA); //allocate memory for the output imageOutputRGBA.create(image.rows, image.cols, CV_8UC4); //This shouldn't ever happen given the way the images are created //at least based upon my limited understanding of OpenCV, but better to check if (!imageInputRGBA.isContinuous() || !imageOutputRGBA.isContinuous()) { std::cerr << "Images aren't continuous!! Exiting." << std::endl; exit(1); } *h_inputImageRGBA = (uchar4 *)imageInputRGBA.ptr<unsigned char>(0); *h_outputImageRGBA = (uchar4 *)imageOutputRGBA.ptr<unsigned char>(0); const size_t numPixels = numRows() * numCols(); //allocate memory on the device for both input and output checkCudaErrors(cudaMalloc(d_inputImageRGBA, sizeof(uchar4) * numPixels)); checkCudaErrors(cudaMalloc(d_outputImageRGBA, sizeof(uchar4) * numPixels)); checkCudaErrors(cudaMemset(*d_outputImageRGBA, 0, numPixels * sizeof(uchar4))); //make sure no memory is left laying around //copy input array to the GPU checkCudaErrors(cudaMemcpy(*d_inputImageRGBA, *h_inputImageRGBA, sizeof(uchar4) * numPixels, cudaMemcpyHostToDevice)); d_inputImageRGBA__ = *d_inputImageRGBA; d_outputImageRGBA__ = *d_outputImageRGBA; //now create the filter that they will use const int blurKernelWidth = 9; const float blurKernelSigma = 2.; *filterWidth = blurKernelWidth; //create and fill the filter we will convolve with *h_filter = new float[blurKernelWidth * blurKernelWidth]; h_filter__ = *h_filter; float filterSum = 0.f; //for normalization for (int r = -blurKernelWidth/2; r <= blurKernelWidth/2; ++r) { for (int c = -blurKernelWidth/2; c <= blurKernelWidth/2; ++c) { float filterValue = expf( -(float)(c * c + r * r) / (2.f * blurKernelSigma * blurKernelSigma)); (*h_filter)[(r + blurKernelWidth/2) * blurKernelWidth + c + blurKernelWidth/2] = filterValue; filterSum += filterValue; } } float normalizationFactor = 1.f / filterSum; for (int r = -blurKernelWidth/2; r <= blurKernelWidth/2; ++r) { for (int c = -blurKernelWidth/2; c <= blurKernelWidth/2; ++c) { (*h_filter)[(r + blurKernelWidth/2) * blurKernelWidth + c + blurKernelWidth/2] *= normalizationFactor; } } //blurred checkCudaErrors(cudaMalloc(d_redBlurred, sizeof(unsigned char) * numPixels)); checkCudaErrors(cudaMalloc(d_greenBlurred, sizeof(unsigned char) * numPixels)); checkCudaErrors(cudaMalloc(d_blueBlurred, sizeof(unsigned char) * numPixels)); checkCudaErrors(cudaMemset(*d_redBlurred, 0, sizeof(unsigned char) * numPixels)); checkCudaErrors(cudaMemset(*d_greenBlurred, 0, sizeof(unsigned char) * numPixels)); checkCudaErrors(cudaMemset(*d_blueBlurred, 0, sizeof(unsigned char) * numPixels)); }
void KColorCells::resizeEvent( TQResizeEvent * ) { setCellWidth( width() / numCols() ); setCellHeight( height() / numRows() ); }
void CustomPalette::slotRemoveColor() { int i, j; if ( sel_row == -1 || sel_col == -1 ) { //do nothing } else { if ( cur_col == 0 ) { cur_col = numCols() - 1; cur_row--; } else cur_col--; color_matrix[sel_row][sel_col] = invalid_color; color_names[sel_row][sel_col] = ""; alpha_matrix[sel_row][sel_col] = -1; updateCell( sel_row, sel_col ); QPtrList<Color> cl = k_toon -> document() -> getPalette() -> getColors(); cl.setAutoDelete( true ); cl.remove( map2Dto1D( sel_row, sel_col ) ); cl.setAutoDelete( false ); k_toon -> document() -> getPalette() -> setColors( cl ); for ( i = sel_row; i < numRows(); i++ ) { if ( i == sel_row ) { for ( j = sel_col; j < numCols(); j++ ) { if ( j == numCols() - 1 && i < numRows() - 1 ) { color_matrix[i][j] = color_matrix[i + 1][0]; color_names[i][j] = color_names[i + 1][0]; alpha_matrix[i][j] = alpha_matrix[i + 1][0]; updateCell( i, j ); } else if ( j < numCols() - 1 ) { color_matrix[i][j] = color_matrix[i][j + 1]; color_names[i][j] = color_names[i][j + 1]; alpha_matrix[i][j] = alpha_matrix[i][j + 1]; updateCell( i, j ); } else if ( j == numCols() - 1 && i < numRows() - 1 ) { color_matrix[i][j] = invalid_color; color_names[i][j] = ""; alpha_matrix[i][j] = -1; updateCell( i, j ); } } } else { for ( j = 0; j < numCols(); j++ ) { if ( j == numCols() - 1 && i < numRows() - 1 ) { color_matrix[i][j] = color_matrix[i + 1][0]; color_names[i][j] = color_names[i + 1][0]; alpha_matrix[i][j] = alpha_matrix[i + 1][0]; updateCell( i, j ); } else if ( j < numCols() - 1 ) { color_matrix[i][j] = color_matrix[i][j + 1]; color_names[i][j] = color_names[i][j + 1]; alpha_matrix[i][j] = alpha_matrix[i][j + 1]; updateCell( i, j ); } else if ( j == numCols() - 1 && i < numRows() - 1 ) { color_matrix[i][j] = invalid_color; color_names[i][j] = ""; alpha_matrix[i][j] = -1; updateCell( i, j ); } } } } if ( cur_col == sel_col && cur_row == sel_row ) { sel_row = -1; sel_col = -1; updateCell( cur_row, cur_col ); } } }
void WTable::clear() { while (numRows() > 0) deleteRow(numRows() - 1); }
void Matrix::forgetSavedCells() { freeMatrixData(dMatrix, numRows()); dMatrix = 0; }
bool Matrix::calculate(int startRow, int endRow, int startCol, int endCol) { allow_modification_signals = false; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); Script *script = scriptEnv->newScript(formula_str, this, QString("<%1>").arg(name())); connect(script, SIGNAL(error(const QString&,const QString&,int)), scriptEnv, SIGNAL(error(const QString&,const QString&,int))); connect(script, SIGNAL(print(const QString&)), scriptEnv, SIGNAL(print(const QString&))); if (!script->compile()) { allow_modification_signals = true; QApplication::restoreOverrideCursor(); return false; } int rows = numRows(); int cols = numCols(); if (endRow < 0) endRow = rows - 1; if (endCol < 0) endCol = cols - 1; if (endCol >= cols) d_table->setColumnCount(endCol+1); if (endRow >= rows) d_table->setRowCount(endRow+1); QVariant ret; saveCellsToMemory(); double dx = fabs(x_end-x_start)/(double)(numRows()-1); double dy = fabs(y_end-y_start)/(double)(numCols()-1); for(int row = startRow; row <= endRow; row++) for(int col = startCol; col <= endCol; col++) { script->setInt(row+1, "i"); script->setInt(row+1, "row"); script->setDouble(y_start+row*dy, "y"); script->setInt(col+1, "j"); script->setInt(col+1, "col"); script->setDouble(x_start+col*dx, "x"); ret = script->eval(); if (ret.type()==QVariant::Int || ret.type()==QVariant::UInt || ret.type()==QVariant::LongLong || ret.type()==QVariant::ULongLong) setText(row, col, ret.toString()); else if (ret.canConvert(QVariant::Double)) setText(row, col, QLocale().toString(ret.toDouble(), txt_format.toAscii(), num_precision)); else { setText(row, col, ""); allow_modification_signals = true; QApplication::restoreOverrideCursor(); return false; } } forgetSavedCells(); allow_modification_signals = true; emit modifiedWindow(this); QApplication::restoreOverrideCursor(); return true; }
ConstIterator columnEnd(size_t col) const { return ConstIterator(array() + col + numRows() * numColumns(), numColumns()); }
const ElementType& entry(size_t row, size_t column) const { assert(row < numRows()); assert(column < numColumns()); return *fmpq_mat_entry(mArray, row, column); }
void Matrix::print(QPrinter *printer) { if (!printer) return; QPainter p; if ( !p.begin(printer)) return; // paint on printer int dpiy = printer->logicalDpiY(); const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins if (d_view_type == ImageView){ p.drawImage (printer->pageRect(), d_matrix_model->renderImage()); return; } QHeaderView *vHeader = d_table_view->verticalHeader(); int rows = numRows(); int cols = numCols(); int height = margin; int i, vertHeaderWidth = vHeader->width(); int right = margin + vertHeaderWidth; // print header p.setFont(QFont()); QString header_label = d_matrix_model->headerData(0, Qt::Horizontal).toString(); QRect br = p.boundingRect(br, Qt::AlignCenter, header_label); p.drawLine(right, height, right, height+br.height()); QRect tr(br); for(i=0; i<cols; i++){ int w = d_table_view->columnWidth(i); tr.setTopLeft(QPoint(right,height)); tr.setWidth(w); tr.setHeight(br.height()); header_label = d_matrix_model->headerData(i, Qt::Horizontal).toString(); p.drawText(tr, Qt::AlignCenter, header_label,-1); right += w; p.drawLine(right, height, right, height+tr.height()); if (right >= printer->width()-2*margin ) break; } p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line height += tr.height(); p.drawLine(margin, height, right-1, height); // print table values for(i=0;i<rows;i++){ right = margin; QString cell_text = d_matrix_model->headerData(i, Qt::Horizontal).toString()+"\t"; tr = p.boundingRect(tr, Qt::AlignCenter, cell_text); p.drawLine(right, height, right, height+tr.height()); br.setTopLeft(QPoint(right,height)); br.setWidth(vertHeaderWidth); br.setHeight(tr.height()); p.drawText(br,Qt::AlignCenter,cell_text,-1); right += vertHeaderWidth; p.drawLine(right, height, right, height+tr.height()); for(int j=0; j<cols; j++){ int w = d_table_view->columnWidth (j); cell_text = text(i,j)+"\t"; tr = p.boundingRect(tr,Qt::AlignCenter,cell_text); br.setTopLeft(QPoint(right,height)); br.setWidth(w); br.setHeight(tr.height()); p.drawText(br, Qt::AlignCenter, cell_text, -1); right += w; p.drawLine(right, height, right, height+tr.height()); if (right >= printer->width()-2*margin ) break; } height += br.height(); p.drawLine(margin, height, right-1, height); if (height >= printer->height()-margin ){ printer->newPage(); height = margin; p.drawLine(margin, height, right, height); } } p.end(); }
void Matrix::pasteSelection() { if (d_view_type == ImageView) return; QString text = QApplication::clipboard()->text(); if (text.isEmpty()) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QStringList linesList = text.split(ApplicationWindow::guessEndOfLine(text)); int rows = linesList.size(); if (!rows) return; int cols = linesList[0].split("\t").count(); for (int i = 1; i < rows; i++){ int aux = linesList[i].split("\t").count(); if (aux > cols) cols = aux; } int topRow = 0, leftCol = 0; QItemSelectionModel *selModel = d_table_view->selectionModel(); if (selModel->hasSelection()){ QItemSelectionRange sel = selModel->selection()[0]; topRow = sel.top(); leftCol = sel.left(); } int oldRows = numRows(); int bottomRow = topRow + rows - 1; if (bottomRow > oldRows - 1) bottomRow = oldRows - 1; int oldCols = numCols(); int rightCol = leftCol + cols - 1; if (rightCol > oldCols - 1) rightCol = oldCols - 1; double *clipboardBuffer = (double *)malloc(rows*cols*sizeof(double)); if (!clipboardBuffer){ QMessageBox::critical(this, tr("QtiPlot") + " - " + tr("Memory Allocation Error"), tr("Not enough memory, operation aborted!")); QApplication::restoreOverrideCursor(); return; } QLocale locale = applicationWindow()->clipboardLocale(); int cell = 0; for(int i = 0; i < rows; i++){ QStringList cells = linesList[i].split("\t"); int size = cells.count(); for(int j = 0; j<cols; j++){ if (j >= size){ clipboardBuffer[cell++] = GSL_NAN; continue; } bool numeric = true; double value = locale.toDouble(cells[j], &numeric); if (numeric) clipboardBuffer[cell++] = value; else clipboardBuffer[cell++] = GSL_NAN; } } QApplication::restoreOverrideCursor(); double *backupBuffer = d_matrix_model->dataCopy(topRow, bottomRow, leftCol, rightCol); if (backupBuffer){ d_undo_stack->push(new MatrixPasteCommand(d_matrix_model, topRow, bottomRow, leftCol, rightCol, clipboardBuffer, rows, cols, backupBuffer, oldRows, oldCols, tr("Paste"))); emit modifiedWindow(this); modifiedData(this); } else if (ignoreUndo()){ d_matrix_model->pasteData(clipboardBuffer, topRow, leftCol, rows, cols); emit modifiedWindow(this); modifiedData(this); } }
void Matrix::save(const QString &fn, const QString &info, bool saveAsTemplate) { QFile f(fn); if (!f.isOpen()){ if (!f.open(QIODevice::Append)) return; } bool notTemplate = !saveAsTemplate; QTextStream t( &f ); t.setEncoding(QTextStream::UnicodeUTF8); t << "<matrix>\n"; if (notTemplate) t << QString(objectName()) + "\t"; t << QString::number(numRows())+"\t"; t << QString::number(numCols())+"\t"; if (notTemplate) t << birthDate() + "\n"; t << info; t << "ColWidth\t" + QString::number(d_column_width)+"\n"; t << "<formula>\n" + formula_str + "\n</formula>\n"; t << "TextFormat\t" + QString(txt_format) + "\t" + QString::number(num_precision) + "\n"; if (notTemplate) t << "WindowLabel\t" + windowLabel() + "\t" + QString::number(captionPolicy()) + "\n"; t << "Coordinates\t" + QString::number(x_start,'g',15) + "\t" +QString::number(x_end,'g',15) + "\t"; t << QString::number(y_start,'g',15) + "\t" + QString::number(y_end,'g',15) + "\n"; t << "ViewType\t" + QString::number((int)d_view_type) + "\n"; t << "HeaderViewType\t" + QString::number((int)d_header_view_type) + "\n"; if (d_color_map_type != Custom) t << "ColorPolicy\t" + QString::number(d_color_map_type) + "\n"; else t << ColorMapEditor::saveToXmlString(d_color_map); if (notTemplate){//save data t << "<data>\n"; double* d_data = d_matrix_model->dataVector(); int d_rows = numRows(); int d_cols = numCols(); int cols = d_cols - 1; for(int i = 0; i < d_rows; i++){ int aux = d_cols*i; bool emptyRow = true; for(int j = 0; j < d_cols; j++){ if (gsl_finite(d_data[aux + j])){ emptyRow = false; break; } } if (emptyRow) continue; t << QString::number(i) + "\t"; for(int j = 0; j < cols; j++){ double val = d_data[aux + j]; if (gsl_finite(val)) t << QString::number(val, 'e', 16); t << "\t"; } double val = d_data[aux + cols]; if (gsl_finite(val)) t << QString::number(val, 'e', 16); t << "\n"; } t << "</data>\n"; } t << "</matrix>\n"; }
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; }
void Matrix::pasteSelection() { QString the_text = QApplication::clipboard()->text(); if (the_text.isEmpty()) return; allow_modification_signals = false; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QTextStream ts( &the_text, QIODevice::ReadOnly ); QString s = ts.readLine(); QStringList cellTexts = s.split("\t"); int cols = cellTexts.count(); int rows = 1; while(!ts.atEnd()) { rows++; s = ts.readLine(); } ts.reset(); int i, j, top, bottom, right, left, firstCol; QList<QTableWidgetSelectionRange> sel = d_table->selectedRanges(); QListIterator<QTableWidgetSelectionRange> it(sel); QTableWidgetSelectionRange cur; if (!sel.isEmpty()) { cur = it.next(); top = cur.topRow(); bottom = cur.bottomRow(); left = cur.leftColumn(); right = cur.rightColumn(); } else { top = 0; bottom = numRows() - 1; left = 0; right = numCols() - 1; firstCol = firstSelectedColumn(); if (firstCol >= 0) { // columns are selected left = firstCol; int selectedColsNumber = 0; for(i=0; i<numCols(); i++) { if (isColumnSelected(i, true)) selectedColsNumber++; } right = firstCol + selectedColsNumber - 1; } } QTextStream ts2( &the_text, QIODevice::ReadOnly ); int r = bottom-top+1; int c = right-left+1; QApplication::restoreOverrideCursor(); if (rows>r || cols>c) { // TODO: I find the insert cells option awkward // I would prefer the behavior of OpenOffice Calc // here - thzs switch( QMessageBox::information(0,"QtiPlot", tr("The text in the clipboard is larger than your current selection!\ \nDo you want to insert cells?"), tr("Yes"), tr("No"), tr("Cancel"), 0, 0) ) { case 0: if(cols > c ) for(int i=0; i<(cols-c); i++) d_table->insertColumn(left); if(rows > r) { if (firstCol >= 0) for(int i=0; i<(rows-r); i++) d_table->insertRow(top); else for(int i=0; i<(rows-r+1); i++) d_table->insertRow(top); } break; case 1: rows = r; cols = c; break; case 2: allow_modification_signals = true; return; break; } } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); bool numeric; double value; QLocale system_locale = QLocale::system(); for(i=top; i<top+rows; i++) { s = ts2.readLine(); cellTexts=s.split("\t"); for(j=left; j<left+cols; j++) { value = system_locale.toDouble(cellTexts[j-left], &numeric); if (numeric) setText(i, j, QLocale().toString(value, txt_format.toAscii(), num_precision)); else setText(i, j, cellTexts[j-left]); } } allow_modification_signals = true; emit modifiedWindow(this); QApplication::restoreOverrideCursor(); }
int Q3ListBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = Q3ScrollView::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: highlighted((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: selected((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: highlighted((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 3: selected((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 4: highlighted((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 5: selected((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 6: selectionChanged(); break; case 7: selectionChanged((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 8: currentChanged((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 9: clicked((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 10: clicked((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1])),(*reinterpret_cast< const QPoint(*)>(_a[2]))); break; case 11: pressed((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 12: pressed((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1])),(*reinterpret_cast< const QPoint(*)>(_a[2]))); break; case 13: doubleClicked((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 14: returnPressed((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 15: rightButtonClicked((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1])),(*reinterpret_cast< const QPoint(*)>(_a[2]))); break; case 16: rightButtonPressed((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1])),(*reinterpret_cast< const QPoint(*)>(_a[2]))); break; case 17: mouseButtonPressed((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< Q3ListBoxItem*(*)>(_a[2])),(*reinterpret_cast< const QPoint(*)>(_a[3]))); break; case 18: mouseButtonClicked((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< Q3ListBoxItem*(*)>(_a[2])),(*reinterpret_cast< const QPoint(*)>(_a[3]))); break; case 19: contextMenuRequested((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1])),(*reinterpret_cast< const QPoint(*)>(_a[2]))); break; case 20: onItem((*reinterpret_cast< Q3ListBoxItem*(*)>(_a[1]))); break; case 21: onViewport(); break; case 22: clear(); break; case 23: ensureCurrentVisible(); break; case 24: clearSelection(); break; case 25: selectAll((*reinterpret_cast< bool(*)>(_a[1]))); break; case 26: invertSelection(); break; case 27: clearInputString(); break; case 28: refreshSlot(); break; case 29: doAutoScroll(); break; case 30: adjustItems(); break; } _id -= 31; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< uint*>(_v) = count(); break; case 1: *reinterpret_cast< int*>(_v) = numItemsVisible(); break; case 2: *reinterpret_cast< int*>(_v) = currentItem(); break; case 3: *reinterpret_cast< QString*>(_v) = currentText(); break; case 4: *reinterpret_cast< int*>(_v) = topItem(); break; case 5: *reinterpret_cast< SelectionMode*>(_v) = selectionMode(); break; case 6: *reinterpret_cast< bool*>(_v) = isMultiSelection(); break; case 7: *reinterpret_cast< LayoutMode*>(_v) = columnMode(); break; case 8: *reinterpret_cast< LayoutMode*>(_v) = rowMode(); break; case 9: *reinterpret_cast< int*>(_v) = numColumns(); break; case 10: *reinterpret_cast< int*>(_v) = numRows(); break; case 11: *reinterpret_cast< bool*>(_v) = variableWidth(); break; case 12: *reinterpret_cast< bool*>(_v) = variableHeight(); break; } _id -= 13; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 2: setCurrentItem(*reinterpret_cast< int*>(_v)); break; case 4: setTopItem(*reinterpret_cast< int*>(_v)); break; case 5: setSelectionMode(*reinterpret_cast< SelectionMode*>(_v)); break; case 6: setMultiSelection(*reinterpret_cast< bool*>(_v)); break; case 7: setColumnMode(*reinterpret_cast< LayoutMode*>(_v)); break; case 8: setRowMode(*reinterpret_cast< LayoutMode*>(_v)); break; case 11: setVariableWidth(*reinterpret_cast< bool*>(_v)); break; case 12: setVariableHeight(*reinterpret_cast< bool*>(_v)); break; } _id -= 13; } else if (_c == QMetaObject::ResetProperty) { _id -= 13; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 13; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 13; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 13; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 13; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 13; } #endif // QT_NO_PROPERTIES return _id; }
void Matrix::print(const QString& fileName) { QPrinter printer; printer.setColorMode (QPrinter::GrayScale); if (!fileName.isEmpty()) { printer.setCreator("QtiPlot"); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); } else { QPrintDialog printDialog(&printer); if (printDialog.exec() != QDialog::Accepted) return; } printer.setFullPage( true ); QPainter p; if ( !p.begin(&printer ) ) return; // paint on printer int dpiy = printer.logicalDpiY(); const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins QHeaderView *vHeader = d_table->verticalHeader(); int rows = numRows(); int cols = numCols(); int height = margin; int i, vertHeaderWidth = vHeader->width(); int right = margin + vertHeaderWidth; // print header p.setFont(QFont()); QString header_label = d_table->model()->headerData(0, Qt::Horizontal).toString(); QRect br = p.boundingRect(br, Qt::AlignCenter, header_label); p.drawLine(right, height, right, height+br.height()); QRect tr(br); for(i=0;i<cols;i++) { int w = d_table->columnWidth(i); tr.setTopLeft(QPoint(right,height)); tr.setWidth(w); tr.setHeight(br.height()); header_label = d_table->model()->headerData(i, Qt::Horizontal).toString(); p.drawText(tr, Qt::AlignCenter, header_label,-1); right += w; p.drawLine(right, height, right, height+tr.height()); if (right >= printer.width()-2*margin ) break; } p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line height += tr.height(); p.drawLine(margin, height, right-1, height); // print table values for(i=0;i<rows;i++) { right = margin; QString cell_text = d_table->model()->headerData(i, Qt::Horizontal).toString()+"\t"; tr = p.boundingRect(tr, Qt::AlignCenter, cell_text); p.drawLine(right, height, right, height+tr.height()); br.setTopLeft(QPoint(right,height)); br.setWidth(vertHeaderWidth); br.setHeight(tr.height()); p.drawText(br,Qt::AlignCenter,cell_text,-1); right += vertHeaderWidth; p.drawLine(right, height, right, height+tr.height()); for(int j=0;j<cols;j++) { int w = d_table->columnWidth (j); cell_text = text(i,j)+"\t"; tr = p.boundingRect(tr,Qt::AlignCenter,cell_text); br.setTopLeft(QPoint(right,height)); br.setWidth(w); br.setHeight(tr.height()); p.drawText(br, Qt::AlignCenter, cell_text, -1); right += w; p.drawLine(right, height, right, height+tr.height()); if (right >= printer.width()-2*margin ) break; } height += br.height(); p.drawLine(margin, height, right-1, height); if (height >= printer.height()-margin ) { printer.newPage(); height = margin; p.drawLine(margin, height, right, height); } } }
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; std::string blur_impl = "hw"; 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 5: input_file = std::string(argv[1]); output_file = std::string(argv[2]); reference_file = std::string(argv[3]); blur_impl = std::string(argv[4]); break; default: std::cerr << "Usage: ./HW2 input_file [output_filename] " "[reference_filename] [blur_impl]]" << 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); GpuTimer timer; timer.Start(); // call the students' code if (blur_impl == "hw") { your_gaussian_blur(h_inputImageRGBA, d_inputImageRGBA, d_outputImageRGBA, numRows(), numCols(), d_redBlurred, d_greenBlurred, d_blueBlurred, filterWidth); } else if (blur_impl == "shared") { gaussian_blur_shared(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)); std::cerr << "postProcess output...\n"; postProcess(output_file, h_outputImageRGBA); timer.Start(); referenceCalculation(h_inputImageRGBA, h_outputImageRGBA, numRows(), numCols(), h_filter, filterWidth); timer.Stop(); std::cerr << "referenceCalculation elapsed: " << timer.Elapsed() << " ms\n"; std::cerr << "postProcess reference...\n"; 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; }
void CQueryTable::save() { if (isBlocked()) return; tmpFileName = getSaveFileName(tmpFileName, "txt", tr("Text Files (*.txt);;All Files(*.*)")); if (tmpFileName.isEmpty()) return; QFile file( tmpFileName ); if (file.exists() && myApp()->confirmCritical()) if ((QMessageBox::warning(0, tr("Replace File"), tr("The specified file name already exists.\nDo you want to replace it ?"), QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)) return; if ( !file.open( IO_WriteOnly ) ) { if (mysql()->messagePanel()) mysql()->messagePanel()->critical(tr("An error occurred while saving the file")); return; } setBlocked(true); QString line_terminator = mysql()->lineTerminator(true); QString title = caption() + line_terminator; title += tr("Connection") + ": " + mysql()->connectionName() + line_terminator; title += tr("Host") + ": " + mysql()->hostName() + line_terminator; title += tr("Saved") + ": " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") + line_terminator; title = CApplication::commentText(title, line_terminator) + line_terminator; QTextStream ts( &file ); ts << title; QString tmp = tr("Query") + ":" + line_terminator; tmp += query()->lastQuery().replace(QRegExp("\n"), line_terminator) + line_terminator; ts << CApplication::commentText(tmp, line_terminator) << line_terminator; query()->dataSeek(0); uint num_fields = query()->numFields(); QString encl = mysql()->fieldEncloser(true); QString sep = mysql()->fieldSeparator(true); uint j; bool add_sep = false; for (j = 0; j < num_fields; j++) { if (horizontalHeader()->sectionSize(j) != 0) { if (add_sep) ts << sep; ts << encl << query()->fields(j).name << encl; if (!add_sep) add_sep = true; } } ts << line_terminator; if (numRows() <= 0 || numCols() <= 0) return; QString repl_empty = mysql()->replaceEmpty(true); while (query()->next(!hasProcessEvents())) { add_sep = false; for (j = 0; j < num_fields; j++) if (horizontalHeader()->sectionSize(j) != 0) { const char* r = query()->row(j); if (!r) r = "[NULL]"; if (!*r) r = (const char*)repl_empty; if (add_sep) ts << sep; ts << encl << r << encl; if (!add_sep) add_sep = true; } ts << line_terminator; } file.close(); if (mysql()->messagePanel()) mysql()->messagePanel()->information(tr("Successfully saved") + ": " + tmpFileName); setBlocked(false); }
void PreviewTable::importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols, bool stripSpaces, bool simplifySpaces, bool importComments, const QString& commentString, int importMode, int endLine, int maxRows) { int rows; QString name = MdiSubWindow::parseAsciiFile(fname, commentString, endLine, ignoredLines, maxRows, rows); if (name.isEmpty()) return; QFile f(name); if (!f.open(QIODevice::ReadOnly)) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QTextStream t(&f); QString s = t.readLine();//read first line if (simplifySpaces) s = s.simplifyWhiteSpace(); else if (stripSpaces) s = s.stripWhiteSpace(); QStringList line = s.split(sep); int cols = line.size(); bool allNumbers = true; for (int i=0; i<cols; i++) {//verify if the strings in the line used to rename the columns are not all numbers locale().toDouble(line[i], &allNumbers); if (!allNumbers) break; } if (renameCols && !allNumbers) rows--; if (importComments) rows--; int startRow = 0, startCol = 0; int c = numCols(); int r = numRows(); switch(importMode){ case Table::Overwrite: if (numRows() != rows) setNumRows(rows); if (c != cols){ if (c < cols) addColumns(cols - c); else setNumCols(cols); } break; case Table::NewColumns: startCol = c; addColumns(cols); if (r < rows) setNumRows(rows); break; case Table::NewRows: startRow = r; if (c < cols) addColumns(cols - c); setNumRows(r + rows); break; } if (renameCols && !allNumbers){//use first line to set the table header for (int i = 0; i<cols; i++){ int aux = i + startCol; col_label[aux] = QString::null; if (!importComments) comments[aux] = line[i]; s = line[i].replace("-","_").remove(QRegExp("\\W")).replace("_","-"); int n = col_label.count(s); if(n){//avoid identical col names while (col_label.contains(s + QString::number(n))) n++; s += QString::number(n); } col_label[aux] = s; } } if (importComments){//import comments if (renameCols && !allNumbers) s = t.readLine();//read 2nd line if (simplifySpaces) s = s.simplifyWhiteSpace(); else if (stripSpaces) s = s.stripWhiteSpace(); line = s.split(sep, QString::SkipEmptyParts); for (int i=0; i<line.size(); i++){ int aux = startCol + i; if (aux < comments.size()) comments[aux] = line[i]; } qApp->processEvents(QEventLoop::ExcludeUserInput); } if ((!renameCols || allNumbers)&& !importComments && rows > 0){ //put values in the first line of the table for (int i = 0; i<cols; i++) setText(startRow, startCol + i, line[i]); startRow++; } blockSignals(true); setHeader(); QApplication::restoreOverrideCursor(); int row = startRow; rows = numRows(); while (!t.atEnd() && row < rows){ s = t.readLine(); if (simplifySpaces) s = s.simplifyWhiteSpace(); else if (stripSpaces) s = s.stripWhiteSpace(); line = s.split(sep); int lc = line.size(); if (lc > cols) { addColumns(lc - cols); cols = lc; } for (int j=0; j<cols && j<lc; j++) setText(row, startCol + j, line[j]); row++; qApp->processEvents(QEventLoop::ExcludeUserInput); } blockSignals(false); f.remove(); }
QString CQueryTable::copy_data(int row, int col) { #ifdef DEBUG qDebug("CQueryTable::copy_data(int, int)"); #endif if (!query()) return QString::null; if (query()->isResultNull() || isBlocked()) return QString::null; if (currentSelection() == -1 && !forceCopyAll()) return copy_current_selection_func(row, col); else { QTableSelection sel; if (currentSelection() == -1 || forceCopyAll()) { sel.init(0, 0); sel.expandTo(numRows() -1, numCols() - 1); } else sel = selection(currentSelection()); if (sel.topRow() == sel.bottomRow() && sel.leftCol() == sel.rightCol() && !forceCopyAll()) return copy_current_selection_func(row, col); setBlocked(true); QString cpy; QString separator = "+"; int current_col; uint length; QMap<uint, ulong> max_length_map; QString tmp; for (current_col = sel.leftCol(); current_col <= sel.rightCol(); current_col++) { if (horizontalHeader()->sectionSize(current_col) <= 0) continue; length = strlen(query()->fields(current_col).name); length = max(length, query()->fields(current_col).max_length); if (length < strlen(NULL_TEXT) && !IS_NOT_NULL(query()->fields(current_col).flags)) length = strlen(NULL_TEXT); max_length_map.insert(current_col, length + 1); for (uint i = 0; i < min(max_length_map[current_col] - 1, MAX_COLUMN_LENGTH) + 2; i++) separator += "-"; separator += "+"; } separator += "\n"; cpy = separator + "|"; for (current_col = sel.leftCol(); current_col <= sel.rightCol(); current_col++) { if (horizontalHeader()->sectionSize(current_col) <= 0) continue; tmp.sprintf(" %-*s|",min((int) max_length_map[current_col], MAX_COLUMN_LENGTH), query()->fields(current_col).name); cpy += tmp; } cpy += "\n" + separator; copy_data_func(&cpy, query(), &sel, &max_length_map); setBlocked(false); return cpy + separator; } }
void TableBody::mousePressEvent(QMouseEvent *e) { if (numRows() == 0) return; // *** prevent out of range // printf("mousePressEvent() 1\n"); static int last_row = -1; int row = findRow(e->y()); if (row == -1) { // printf("mousePressEvent\n"); htable->clearAllSelections(); if (e->y() >= 0) row = numRows(); // if SHIFT+click outside ~ first_drag_row = prev_drag_row = row; return; } if (!(htable->options & HTBL_ROW_SELECTION)) return; if (e->button() == Qt::LeftButton) { // folding if (htable->treemode && htable->folding && e->x() < htable->gadget_space + htable->treestep * htable->rowDepth(row) && htable->folded(row) != HeadedTable::Leaf) { emit htable->foldSubTree(row); gadget_click = true; last_row = row; // clearCache(); // dont use cache return; } if (e->modifiers() & Qt::ShiftModifier) { if (row < last_row) for (int i = row; i < last_row; i++) htable->setSelected(i, true); // virtual else for (int i = last_row; i <= row; i++) htable->setSelected(i, true); // virtual } else if (e->modifiers() & Qt::ControlModifier) { htable->setSelected(row, !htable->isSelected(row)); } else htable->selectOnlyOne(row); first_drag_row = prev_drag_row = row; emit htable->selectionChanged(); } else if (e->button() == Qt::RightButton) { if (!htable->isSelected(row)) htable->selectOnlyOne(row); emit htable->selectionChanged(); // better? emit htable->rightClicked(e->globalPos()); } last_row = row; // htable->repaint_changed(); repaintChanged(); // repaint // view->update(); // fast but use more CPU }
const ElementType& entry(size_t row, size_t column) const { M2_ASSERT(row < numRows()); M2_ASSERT(column < numColumns()); return * fmpz_mat_entry(mArray, row, column); }