26 , mNodataValue( nodataValue )
45 int nEntries = mColumns * mRows;
46 mData =
new double[nEntries];
47 memcpy( mData, m.mData,
sizeof(
double ) * nEntries );
72 return twoArgumentOperation(
opPLUS, other );
77 return twoArgumentOperation(
opMINUS, other );
82 return twoArgumentOperation(
opMUL, other );
87 return twoArgumentOperation(
opDIV, other );
92 return twoArgumentOperation(
opPOW, other );
97 return twoArgumentOperation(
opEQ, other );
102 return twoArgumentOperation(
opNE, other );
107 return twoArgumentOperation(
opGT, other );
112 return twoArgumentOperation(
opLT, other );
117 return twoArgumentOperation(
opGE, other );
122 return twoArgumentOperation(
opLE, other );
127 return twoArgumentOperation(
opAND, other );
132 return twoArgumentOperation(
opOR, other );
137 return oneArgumentOperation(
opSQRT );
142 return oneArgumentOperation(
opSIN );
147 return oneArgumentOperation(
opASIN );
152 return oneArgumentOperation(
opCOS );
157 return oneArgumentOperation(
opACOS );
162 return oneArgumentOperation(
opTAN );
167 return oneArgumentOperation(
opATAN );
172 return oneArgumentOperation(
opSIGN );
177 return oneArgumentOperation(
opLOG );
182 return oneArgumentOperation(
opLOG10 );
192 int nEntries = mColumns * mRows;
194 for (
int i = 0; i < nEntries; ++i )
197 if ( value != mNodataValue )
204 mData[i] = mNodataValue;
208 mData[i] = std::sqrt( value );
212 mData[i] = std::sin( value );
215 mData[i] = std::cos( value );
218 mData[i] = std::tan( value );
221 mData[i] = std::asin( value );
224 mData[i] = std::acos( value );
227 mData[i] = std::atan( value );
235 mData[i] = mNodataValue;
239 mData[i] =
::log( value );
245 mData[i] = mNodataValue;
258 double QgsRasterMatrix::calculateTwoArgumentOp(
TwoArgOperator op,
double arg1,
double arg2 )
const 278 if ( !testPowerValidity( arg1, arg2 ) )
284 return std::pow( arg1, arg2 );
287 return ( arg1 == arg2 ? 1.0 : 0.0 );
289 return ( arg1 == arg2 ? 0.0 : 1.0 );
291 return ( arg1 > arg2 ? 1.0 : 0.0 );
293 return ( arg1 < arg2 ? 1.0 : 0.0 );
295 return ( arg1 >= arg2 ? 1.0 : 0.0 );
297 return ( arg1 <= arg2 ? 1.0 : 0.0 );
299 return ( arg1 && arg2 ? 1.0 : 0.0 );
301 return ( arg1 || arg2 ? 1.0 : 0.0 );
313 mData[0] = mNodataValue;
317 mData[0] = calculateTwoArgumentOp( op, mData[0], other.
number() );
325 double *matrix = other.mData;
326 int nEntries = mColumns * mRows;
327 double value1, value2;
329 for (
int i = 0; i < nEntries; ++i )
333 if ( value1 == mNodataValue || value2 == other.mNodataValue )
335 mData[i] = mNodataValue;
339 mData[i] = calculateTwoArgumentOp( op, value1, value2 );
348 double *matrix = other.mData;
350 double value = mData[0];
352 mData =
new double[nEntries];
354 mRows = other.
nRows();
357 if ( value == mNodataValue )
359 for (
int i = 0; i < nEntries; ++i )
361 mData[i] = mNodataValue;
366 for (
int i = 0; i < nEntries; ++i )
368 if ( matrix[i] == other.mNodataValue )
370 mData[i] = mNodataValue;
374 mData[i] = calculateTwoArgumentOp( op, value, matrix[i] );
380 double value = other.
number();
381 int nEntries = mColumns * mRows;
383 if ( other.
number() == other.mNodataValue )
385 for (
int i = 0; i < nEntries; ++i )
387 mData[i] = mNodataValue;
392 for (
int i = 0; i < nEntries; ++i )
394 if ( mData[i] == mNodataValue )
399 mData[i] = calculateTwoArgumentOp( op, mData[i], value );
405 bool QgsRasterMatrix::testPowerValidity(
double base,
double power )
const 407 return !( ( base == 0 && power < 0 ) || ( base < 0 && ( power - std::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)
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)
QgsRasterMatrix()=default
Takes ownership of data array.
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)