void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) { KstMatrixList matrices = KST::matrixList; KstMatrixPtr matrix = *matrices.findTag(_strMatrix); QString str; double value; painter->eraseRect( 0, 0, cr.width(), cr.height() ); if (selected) { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.highlight() ); painter->setPen(cg.highlightedText()); } else { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.base() ); painter->setPen(cg.text()); } if (matrix) { bool ok; value = matrix->valueRaw(col, row, &ok); if (ok) { str.setNum(value, 'g', 16); } } painter->drawText(0, 0, cr.width(), cr.height(), AlignLeft, str); }
void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QPalette &palette ) { KstMatrixPtr matrix = *KST::matrixList.findTag(_strMatrix); QString str; double value; painter->eraseRect( 0, 0, cr.width(), cr.height() ); if (selected) { painter->fillRect( 0, 0, cr.width(), cr.height(), palette.highlight() ); painter->setPen(palette.highlightedText().color()); } else { painter->fillRect( 0, 0, cr.width(), cr.height(), palette.base() ); painter->setPen(palette.text().color()); } if (matrix) { bool ok; value = matrix->valueRaw(col, row, &ok); if (ok) { str.setNum(value, 'g', 16); } else { str = "-"; } } painter->drawText(0, 0, cr.width(), cr.height(), Qt::AlignLeft, str); }
void BinnedMap::binnedmap() { KstVectorPtr x = *_inputVectors.find(VECTOR_X); KstVectorPtr y = *_inputVectors.find(VECTOR_Y); KstVectorPtr z = *_inputVectors.find(VECTOR_Z); KstMatrixPtr map = *_outputMatrices.find(MAP); KstMatrixPtr hitsMap = *_outputMatrices.find(HITSMAP); if (autoBin()) { AutoSize(X(),Y(), &_nx, &_xMin, &_xMax, &_ny, &_yMin, &_yMax); } bool needsresize = false; if (_nx<2) { _nx = 2; needsresize = true; } if (_ny<2) { _ny = 2; needsresize = true; } if ((map->xNumSteps() != _nx) || (map->yNumSteps() != _ny) || (map->minX() != _xMin) || (map->minY() != _yMin)) { needsresize = true; } if (map->xStepSize() != (_xMax - _xMin)/double(_nx-1)) { needsresize = true; } if (map->yStepSize() != (_yMax - _yMin)/double(_ny-1)) { needsresize = true; } if (needsresize) { map->change(map->tag(), _nx, _ny, _xMin, _yMin, (_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1)); map->resize(_nx, _ny); hitsMap->change(hitsMap->tag(), _nx, _ny, _xMin, _yMin, (_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1)); hitsMap->resize(_nx, _ny); } map->zero(); hitsMap->zero(); int ns = z->length(); // the z vector defines the number of points. double n,p, x0, y0, z0; for (int i=0; i<ns; i++) { x0 = x->interpolate(i, ns); y0 = y->interpolate(i, ns); z0 = z->interpolate(i, ns); p = map->value(x0, y0)+z0; map->setValue(x0, y0, p); n = hitsMap->value(x0, y0)+1; hitsMap->setValue(x0, y0, n); } for (int i=0; i<_nx; i++) { for (int j=0; j<_ny; j++) { p = map->valueRaw(i,j); n = hitsMap->valueRaw(i,j); if (n>0) { map->setValueRaw(i,j,p/n); } else { map->setValueRaw(i,j,KST::NOPOINT); } } } //calculate here... }
void BinnedMap::binnedmap() { KstVectorPtr x = *_inputVectors.find(VECTOR_X); KstVectorPtr y = *_inputVectors.find(VECTOR_Y); KstVectorPtr z = *_inputVectors.find(VECTOR_Z); KstMatrixPtr map = *_outputMatrices.find(MAP); KstMatrixPtr hitsMap = *_outputMatrices.find(HITSMAP); KstScalarPtr autobin = *_inputScalars.find(AUTOBIN); if (autobin) { if (autobin->value() != 0.0) { _autoBin = true; } else { _autoBin = false; } } if (_autoBin) { double minx, miny, maxx, maxy; int nx, ny; autoSize(X(), Y(), &nx, &minx, &maxx, &ny, &miny, &maxy); setNX(nx); setNY(ny); setXMin(minx); setXMax(maxx); setYMin(miny); setYMax(maxy); } else { KstScalarPtr xmin = *_inputScalars.find(XMIN); KstScalarPtr xmax = *_inputScalars.find(XMAX); KstScalarPtr ymin = *_inputScalars.find(YMIN); KstScalarPtr ymax = *_inputScalars.find(YMAX); KstScalarPtr nx = *_inputScalars.find(NX); KstScalarPtr ny = *_inputScalars.find(NY); if (xmin) { _xMin = xmin->value(); } if (xmax) { _xMax = xmax->value(); } if (ymin) { _yMin = ymin->value(); } if (ymax) { _yMax = ymax->value(); } if (nx) { _nx = (int)nx->value(); } if (ny) { _ny = (int)ny->value(); } } bool needsresize = false; if (_nx < 2) { _nx = 2; needsresize = true; } if (_ny < 2) { _ny = 2; needsresize = true; } if ((map->xNumSteps() != _nx) || (map->yNumSteps() != _ny) || (map->minX() != _xMin) || (map->minY() != _yMin)) { needsresize = true; } if (map->xStepSize() != (_xMax - _xMin)/double(_nx-1)) { needsresize = true; } if (map->yStepSize() != (_yMax - _yMin)/double(_ny-1)) { needsresize = true; } if (needsresize) { map->change(map->tag(), _nx, _ny, _xMin, _yMin, (_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1)); map->resize(_nx, _ny); hitsMap->change(hitsMap->tag(), _nx, _ny, _xMin, _yMin, (_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1)); hitsMap->resize(_nx, _ny); } map->zero(); hitsMap->zero(); int ns = z->length(); // the z vector defines the number of points. double n,p, x0, y0, z0; for (int i=0; i<ns; i++) { x0 = x->interpolate(i, ns); y0 = y->interpolate(i, ns); z0 = z->interpolate(i, ns); p = map->value(x0, y0)+z0; map->setValue(x0, y0, p); n = hitsMap->value(x0, y0)+1; hitsMap->setValue(x0, y0, n); } for (int i=0; i<_nx; i++) { for (int j=0; j<_ny; j++) { p = map->valueRaw(i, j); n = hitsMap->valueRaw(i, j); if (n>0) { map->setValueRaw(i, j, p/n); } else { map->setValueRaw(i, j, KST::NOPOINT); } } } }