//============================================================== tensor EightNode_Brick_u_p::getGaussPts(void) { int dimensions1[] = {Num_TotalGaussPts,Num_Dim}; tensor Gs(2, dimensions1, 0.0); int dimensions2[] = {Num_Nodes}; tensor shp(1, dimensions2, 0.0); double r = 0.0; double s = 0.0; double t = 0.0; int i, j, where; int GP_c_r, GP_c_s, GP_c_t; for( GP_c_r = 0 ; GP_c_r < Num_IntegrationPts; GP_c_r++ ) { r = pts[GP_c_r]; for( GP_c_s = 0 ; GP_c_s < Num_IntegrationPts; GP_c_s++ ) { s = pts[GP_c_s]; for( GP_c_t = 0 ; GP_c_t < Num_IntegrationPts; GP_c_t++ ) { t = pts[GP_c_t]; where = (GP_c_r*Num_IntegrationPts+GP_c_s)*Num_IntegrationPts+GP_c_t; shp = shapeFunction(r,s,t); for (i=0; i<Num_Nodes; i++) { const Vector& T_Crds = theNodes[i]->getCrds(); for (j=0; j<Num_Dim; j++) { Gs.val(where+1, j+1) += shp.cval(i+1) * T_Crds(j); } } } } } return Gs; }
void MainWindow::on_actionBrightness_quantization_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } std::vector<int> grays(width * height); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int gray = qPow( 0.2126 * qPow(qRed(oldColor), 2.2) + 0.7152 * qPow(qGreen(oldColor), 2.2) + 0.0722 * qPow(qBlue(oldColor), 2.2), 1/2.2 ); grays[x + y * width] = gray; } std::vector<unsigned int> Rs(256, 0); std::vector<unsigned int> Gs(256, 0); std::vector<unsigned int> Bs(256, 0); std::vector<int> hist(256, 0); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int num = grays[x + y * width]; Rs[num] += qRed( image.pixel(x, y) ); Gs[num] += qGreen( image.pixel(x, y) ); Bs[num] += qBlue( image.pixel(x, y) ); ++hist[num]; } int quantsCountMaximum = 0; std::map<int, QRgb> colors; for (int i = 0; i < 256; ++i) { if (hist[i] == 0) continue; Rs[i] /= hist[i]; Gs[i] /= hist[i]; Bs[i] /= hist[i]; colors[i] = qRgb(Rs[i], Gs[i], Bs[i]); ++quantsCountMaximum; } DialogQuantization dialog; dialog.setQuantCountMaximum(quantsCountMaximum); if (dialog.exec() == QDialog::Rejected) return; int quantsCount = dialog.quantsCount(); double shift = 256 / quantsCount; double cur = 0.0; double next = 0.0; for (int i = 0; i < quantsCount; ++i) { next += shift; int c = qFloor(cur); int n = qFloor(next); int minC = 256; for (std::map<int, QRgb>::iterator it = colors.begin(); it != colors.end(); ++it) if (c <= (it->first) && (it->first) < n) if (it->first < minC) minC = it->first; QRgb newColor = colors[minC]; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int num = grays[x + y * width]; if (c <= num && num < n) image.setPixel(x, y, newColor); else continue; } cur = next; } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); //ui->graphicsView_2->fitInView(scene_2->itemsBoundingRect(), Qt::KeepAspectRatio); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }