34 , mNodataValue( nodataValue )
56 int nEntries = mColumns * mRows;
57 mData =
new double[nEntries];
58 memcpy( mData, m.mData,
sizeof(
double ) * nEntries );
83 return twoArgumentOperation(
opPLUS, other );
88 return twoArgumentOperation(
opMINUS, other );
93 return twoArgumentOperation(
opMUL, other );
98 return twoArgumentOperation(
opDIV, other );
103 return twoArgumentOperation(
opPOW, other );
108 return twoArgumentOperation(
opEQ, other );
113 return twoArgumentOperation(
opNE, other );
118 return twoArgumentOperation(
opGT, other );
123 return twoArgumentOperation(
opLT, other );
128 return twoArgumentOperation(
opGE, other );
133 return twoArgumentOperation(
opLE, other );
138 return twoArgumentOperation(
opAND, other );
143 return twoArgumentOperation(
opOR, other );
148 return oneArgumentOperation(
opSQRT );
153 return oneArgumentOperation(
opSIN );
158 return oneArgumentOperation(
opASIN );
163 return oneArgumentOperation(
opCOS );
168 return oneArgumentOperation(
opACOS );
173 return oneArgumentOperation(
opTAN );
178 return oneArgumentOperation(
opATAN );
183 return oneArgumentOperation(
opSIGN );
188 return oneArgumentOperation(
opLOG );
193 return oneArgumentOperation(
opLOG10 );
203 int nEntries = mColumns * mRows;
205 for (
int i = 0; i < nEntries; ++i )
208 if ( value != mNodataValue )
215 mData[i] = mNodataValue;
219 mData[i] = sqrt( value );
223 mData[i] = sin( value );
226 mData[i] = cos( value );
229 mData[i] = tan( value );
232 mData[i] = asin( value );
235 mData[i] = acos( value );
238 mData[i] = atan( value );
246 mData[i] = mNodataValue;
250 mData[i] =
::log( value );
256 mData[i] = mNodataValue;
269 double QgsRasterMatrix::calculateTwoArgumentOp(
TwoArgOperator op,
double arg1,
double arg2 )
const 289 if ( !testPowerValidity( arg1, arg2 ) )
295 return qPow( arg1, arg2 );
298 return ( arg1 == arg2 ? 1.0 : 0.0 );
300 return ( arg1 == arg2 ? 0.0 : 1.0 );
302 return ( arg1 > arg2 ? 1.0 : 0.0 );
304 return ( arg1 < arg2 ? 1.0 : 0.0 );
306 return ( arg1 >= arg2 ? 1.0 : 0.0 );
308 return ( arg1 <= arg2 ? 1.0 : 0.0 );
310 return ( arg1 && arg2 ? 1.0 : 0.0 );
312 return ( arg1 || arg2 ? 1.0 : 0.0 );
324 mData[0] = mNodataValue;
328 mData[0] = calculateTwoArgumentOp( op, mData[0], other.
number() );
336 double* matrix = other.mData;
337 int nEntries = mColumns * mRows;
338 double value1, value2;
340 for (
int i = 0; i < nEntries; ++i )
344 if ( value1 == mNodataValue || value2 == other.mNodataValue )
346 mData[i] = mNodataValue;
350 mData[i] = calculateTwoArgumentOp( op, value1, value2 );
359 double* matrix = other.mData;
361 double value = mData[0];
363 mData =
new double[nEntries];
365 mRows = other.
nRows();
368 if ( value == mNodataValue )
370 for (
int i = 0; i < nEntries; ++i )
372 mData[i] = mNodataValue;
377 for (
int i = 0; i < nEntries; ++i )
379 if ( matrix[i] == other.mNodataValue )
381 mData[i] = mNodataValue;
385 mData[i] = calculateTwoArgumentOp( op, value, matrix[i] );
391 double value = other.
number();
392 int nEntries = mColumns * mRows;
394 if ( other.
number() == other.mNodataValue )
396 for (
int i = 0; i < nEntries; ++i )
398 mData[i] = mNodataValue;
403 for (
int i = 0; i < nEntries; ++i )
405 if ( mData[i] == mNodataValue )
410 mData[i] = calculateTwoArgumentOp( op, mData[i], value );
416 bool QgsRasterMatrix::testPowerValidity(
double base,
double power )
const 418 if (( base == 0 && power < 0 ) || ( base < 0 && ( power - floor( power ) ) > 0 ) )
double * takeData()
Returns data and ownership.
bool isNumber() const
Returns true if matrix is 1x1 (=scalar number)
QgsRasterMatrix & operator=(const QgsRasterMatrix &m)
bool add(const QgsRasterMatrix &other)
Adds another matrix to this one.
double nodataValue() const
bool power(const QgsRasterMatrix &other)
QgsRasterMatrix()
Takes ownership of data array.
bool greaterThan(const QgsRasterMatrix &other)
bool notEqual(const QgsRasterMatrix &other)
bool equal(const QgsRasterMatrix &other)
bool logicalOr(const QgsRasterMatrix &other)
void setData(int cols, int rows, double *data, double nodataValue)
bool subtract(const QgsRasterMatrix &other)
Subtracts another matrix from this one.
bool multiply(const QgsRasterMatrix &other)
bool lesserEqual(const QgsRasterMatrix &other)
bool divide(const QgsRasterMatrix &other)
bool greaterEqual(const QgsRasterMatrix &other)
double * data()
Returns data array (but not ownership)
bool lesserThan(const QgsRasterMatrix &other)
bool logicalAnd(const QgsRasterMatrix &other)