KstAMatrix::KstAMatrix(const QDomElement &e) : KstMatrix() { _editable = true; double in_xMin = 0, in_yMin = 0, in_xStep = 1, in_yStep = 1; int in_nX = 2, in_nY = 2; QString in_tag = QString::null; // must get the grid dimensions before the data QDomNode n = e.firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { if (e.tagName() == "tag") { setTagName(KstObjectTag::fromString(e.text())); } else if (e.tagName() == "nx") { in_nX = e.text().toInt(); } else if (e.tagName() == "ny") { in_nY = e.text().toInt(); } else if (e.tagName() == "xmin") { in_xMin = e.text().toDouble(); } else if (e.tagName() == "ymin") { in_yMin = e.text().toDouble(); } else if (e.tagName() == "xstep") { in_xStep = e.text().toDouble(); } else if (e.tagName() == "ystep") { in_yStep = e.text().toDouble(); } } n = n.nextSibling(); } _saveable = true; resizeZ(in_nX*in_nY, true); // now get the z data if (in_nX*in_nY > 0) { QDomNode n = e.firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { if (e.tagName() == "data") { QCString qcs(e.text().latin1()); QByteArray qbca; KCodecs::base64Decode(qcs, qbca); QByteArray qba = qUncompress(qbca); QDataStream qds(qba, IO_ReadOnly); int i; // fill in the raw array with the data for (i = 0; i < in_nX*in_nY && !qds.atEnd(); i++) { qds >> _z[i]; // stored in the same order as it was saved } if (i < in_nX*in_nY) { KstDebug::self()->log(i18n("Saved matrix contains less data than it claims."), KstDebug::Warning); resizeZ(i, false); } } } n = n.nextSibling(); }
void GeneratedMatrix::change(uint nX, uint nY, double minX, double minY, double stepX, double stepY, double gradZMin, double gradZMax, bool xDirection) { // some checks on parameters if (nX < 1) { nX = 1; } if (nY < 1) { nY = 1; } if (stepX <= 0) { stepX = 0.1; } if (stepY <= 0) { stepY = 0.1; } _nX = nX; _nY = nY; _minX = minX; _minY = minY; _stepX = stepX; _stepY = stepY; _gradZMin = gradZMin; _gradZMax = gradZMax; _xDirection = xDirection; if (_nX*_nY != _zSize) { resizeZ(_nX*_nY, false); } // zIncrement can be negative, to reverse gradient direction double zIncrement; if (_xDirection) { if (_nX > 1) { zIncrement = (_gradZMax - _gradZMin) / (_nX - 1); } else { zIncrement = 0; } } else { if (_nY > 1) { zIncrement = (_gradZMax - _gradZMin) / (_nY - 1); } else { zIncrement = 0; } } // fill in the matrix with the gradient for (int i = 0; i < _nX; i++) { for (int j = 0; j < _nY; j++) { if (_xDirection) { _z[i*nY + j] = _gradZMin + i*zIncrement; } else { _z[i*nY + j] = _gradZMin + j*zIncrement; } } } setDirty(true); }
bool KstRMatrix::doUpdateNoSkip(int realXStart, int realYStart, bool force) { // unless we are forced to, don't update if the range is the same if (realXStart == _lastXStart && realYStart == _lastYStart && _nX == _lastNX && _nY == _lastNY && _doAve == _lastDoAve && _doSkip == _lastDoSkip && _skip == _lastSkip && !force) { return false; } // resize _z if necessary int requiredSize = _nX*_nY*_samplesPerFrameCache*_samplesPerFrameCache; if (requiredSize != _zSize) { bool resizeOK = resizeZ(requiredSize); if (!resizeOK) { abort(); // FIXME: what to do? } } // read new data from file KstMatrixData matData; matData.z=_z; _NS = _file->readMatrix(&matData, _field, realXStart, realYStart, _nX, _nY); // set the recommended translate and scaling _minX = matData.xMin; _minY = matData.yMin; _stepX = matData.xStepSize; _stepY = matData.yStepSize; return true; }
void KstRMatrix::reset() { // must be called with a lock if (_file) { _samplesPerFrameCache = _file->samplesPerFrame(_field); } resizeZ(0); _NS = 0; _nX = 1; _nY = 0; setDirty(); }
void DataMatrix::reset() { // must be called with a lock Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); if (file()) { _samplesPerFrameCache = file()->matrix().optional(_field).samplesPerFrame; } resizeZ(0); _NS = 0; _nX = 1; _nY = 0; }
void DataMatrix::reset() { // must be called with a lock Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); if (dataSource()) { const DataInfo info = dataSource()->matrix().dataInfo(_field); _samplesPerFrameCache = info.samplesPerFrame; _invertXHint = info.invertXHint; _invertYHint = info.invertYHint; } resizeZ(0); _NS = 0; _nX = 1; _nY = 0; _resetFieldMetadata(); }
void DataMatrix::doUpdateNoSkip(int realXStart, int realYStart) { // resize _z if necessary int requiredSize = _nX*_nY*_samplesPerFrameCache*_samplesPerFrameCache; if (requiredSize != _zSize) { bool resizeOK = resizeZ(requiredSize); if (!resizeOK) { abort(); // FIXME: what to do? } } // read new data from file MatrixData matData; matData.z=_z; _NS = readMatrix(&matData, _field, realXStart, realYStart, _nX, _nY, -1); // set the recommended translate and scaling _minX = matData.xMin; _minY = matData.yMin; _stepX = matData.xStepSize; _stepY = matData.yStepSize; }
void DataMatrix::doUpdateNoSkip(int realXStart, int realYStart) { // resize _z if necessary int requiredSize = _nX*_nY*_samplesPerFrameCache*_samplesPerFrameCache; if (requiredSize != _zSize) { bool resizeOK = resizeZ(requiredSize); if (!resizeOK) { // TODO: Is aborting all we can do? fatalError("Not enough memory for matrix data"); return; } } // read new data from file MatrixData matData; matData.z=_z; _NS = readMatrix(&matData, _field, realXStart, realYStart, _nX, _nY, -1); // set the recommended translate and scaling _minX = matData.xMin; _minY = matData.yMin; _stepX = matData.xStepSize; _stepY = matData.yStepSize; }
void DataMatrix::doUpdateSkip(int realXStart, int realYStart) { // since we are skipping, we don't need all the pixels // also, samples per frame is always 1 with skipping _nX = _nX / _skip; _nY = _nY / _skip; // resize the array if necessary int requiredSize = _nX * _nY; if (requiredSize != _zSize) { bool resizeOK = resizeZ(requiredSize); if (!resizeOK) { abort(); // FIXME: what to do? } } // return data from readMatrix MatrixData matData; if (!_doAve) { // try to use the datasource's read with skip function - it will automatically // enlarge each pixel to correct for the skipping matData.z=_z; _NS = readMatrix(&matData, _field, realXStart, realYStart, _nX, _nY, _skip); // -9999 means the skipping function is not supported by datasource if (_NS != -9999) { // set the recommended translate and scaling, and return _minX = matData.xMin; _minY = matData.yMin; _stepX = matData.xStepSize; _stepY = matData.yStepSize; } } // the skipping function is not supported by datasource; we need to manually skip if (_doAve) { // boxcar filtering is not supported by datasources currently; need to manually average if (_aveReadBufferSize < _samplesPerFrameCache*_skip*_samplesPerFrameCache*_skip) { _aveReadBufferSize = _samplesPerFrameCache*_skip*_samplesPerFrameCache*_skip; _aveReadBuffer = static_cast<double*>(realloc(_aveReadBuffer, _aveReadBufferSize*sizeof(double))); } _NS = 0; bool first = true; matData.z = _aveReadBuffer; double* zPos = _z; for (int i = 0; i < _nX; i++) { for (int j = 0; j < _nY; j++) { // read one buffer size in readMatrix(&matData, _field, realXStart + _skip*i, realYStart + _skip*j, _skip, _skip, -1); // take average of the buffer double bufferAverage = 0; for (int k = 0; k < _samplesPerFrameCache*_skip*_samplesPerFrameCache*_skip; k++) { bufferAverage += _aveReadBuffer[k]; } bufferAverage = bufferAverage / _aveReadBufferSize; // insert the average into the matrix *zPos = bufferAverage; zPos++; _NS++; if (first) { _minX = matData.xMin; _minY = matData.yMin; _stepX = matData.xStepSize * _skip * _samplesPerFrameCache; _stepY = matData.yStepSize * _skip * _samplesPerFrameCache; first = false; } } } } else { _NS = 0; bool first = true; for (int i = 0; i < _nX; i++) { for (int j = 0; j < _nY; j++) { // read one sample int samples = readMatrix(&matData, _field, realXStart + _skip*i, realYStart + _skip*j, -1, -1, -1); matData.z += samples; _NS += samples; if (first) { _minX = matData.xMin; _minY = matData.yMin; _stepX = matData.xStepSize * _skip * _samplesPerFrameCache; _stepY = matData.yStepSize * _skip * _samplesPerFrameCache; first = false; } } } } }
EditableMatrix::EditableMatrix(ObjectStore *store) : Matrix(store) { _editable = true; _saveable = true; resizeZ(1, true); }