27 , mNodataValue( nodataValue )
48 int nEntries = mColumns * mRows;
49 mData =
new double[nEntries];
50 memcpy( mData, m.mData,
sizeof(
double ) * nEntries );
76 return twoArgumentOperation(
opPLUS, other );
81 return twoArgumentOperation(
opMINUS, other );
86 return twoArgumentOperation(
opMUL, other );
91 return twoArgumentOperation(
opDIV, other );
96 return twoArgumentOperation(
opPOW, other );
101 return twoArgumentOperation(
opEQ, other );
106 return twoArgumentOperation(
opNE, other );
111 return twoArgumentOperation(
opGT, other );
116 return twoArgumentOperation(
opLT, other );
121 return twoArgumentOperation(
opGE, other );
126 return twoArgumentOperation(
opLE, other );
131 return twoArgumentOperation(
opAND, other );
136 return twoArgumentOperation(
opOR, other );
141 return twoArgumentOperation(
opMAX, other );
146 return twoArgumentOperation(
opMIN, other );
151 return oneArgumentOperation(
opSQRT );
156 return oneArgumentOperation(
opSIN );
161 return oneArgumentOperation(
opASIN );
166 return oneArgumentOperation(
opCOS );
171 return oneArgumentOperation(
opACOS );
176 return oneArgumentOperation(
opTAN );
181 return oneArgumentOperation(
opATAN );
186 return oneArgumentOperation(
opSIGN );
191 return oneArgumentOperation(
opLOG );
196 return oneArgumentOperation(
opLOG10 );
201 return oneArgumentOperation(
opABS );
204 bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
211 int nEntries = mColumns * mRows;
213 for (
int i = 0; i < nEntries; ++i )
216 if ( value != mNodataValue )
223 mData[i] = mNodataValue;
227 mData[i] = std::sqrt( value );
231 mData[i] = std::sin( value );
234 mData[i] = std::cos( value );
237 mData[i] = std::tan( value );
240 mData[i] = std::asin( value );
243 mData[i] = std::acos( value );
246 mData[i] = std::atan( value );
254 mData[i] = mNodataValue;
258 mData[i] =
::log( value );
264 mData[i] = mNodataValue;
272 mData[i] = ::fabs( value );
280 double QgsRasterMatrix::calculateTwoArgumentOp( TwoArgOperator op,
double arg1,
double arg2 )
const
300 if ( !testPowerValidity( arg1, arg2 ) )
306 return std::pow( arg1, arg2 );
309 return ( arg1 == arg2 ? 1.0 : 0.0 );
311 return ( arg1 == arg2 ? 0.0 : 1.0 );
313 return ( arg1 > arg2 ? 1.0 : 0.0 );
315 return ( arg1 < arg2 ? 1.0 : 0.0 );
317 return ( arg1 >= arg2 ? 1.0 : 0.0 );
319 return ( arg1 <= arg2 ? 1.0 : 0.0 );
321 return ( arg1 && arg2 ? 1.0 : 0.0 );
323 return ( arg1 || arg2 ? 1.0 : 0.0 );
325 return std::max( arg1, arg2 );
327 return std::min( arg1, arg2 );
332 bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op,
const QgsRasterMatrix &other )
339 mData[0] = mNodataValue;
343 mData[0] = calculateTwoArgumentOp( op, mData[0], other.
number() );
351 double *matrix = other.mData;
352 int nEntries = mColumns * mRows;
353 double value1, value2;
355 for (
int i = 0; i < nEntries; ++i )
359 if ( value1 == mNodataValue || value2 == other.mNodataValue )
361 mData[i] = mNodataValue;
365 mData[i] = calculateTwoArgumentOp( op, value1, value2 );
374 double *matrix = other.mData;
376 double value = mData[0];
378 mData =
new double[nEntries];
380 mRows = other.
nRows();
383 if ( value == mNodataValue )
385 for (
int i = 0; i < nEntries; ++i )
387 mData[i] = mNodataValue;
392 for (
int i = 0; i < nEntries; ++i )
394 if ( matrix[i] == other.mNodataValue )
396 mData[i] = mNodataValue;
400 mData[i] = calculateTwoArgumentOp( op, value, matrix[i] );
406 double value = other.
number();
407 int nEntries = mColumns * mRows;
409 if ( other.
number() == other.mNodataValue )
411 for (
int i = 0; i < nEntries; ++i )
413 mData[i] = mNodataValue;
418 for (
int i = 0; i < nEntries; ++i )
420 if ( mData[i] == mNodataValue )
425 mData[i] = calculateTwoArgumentOp( op, mData[i], value );
431 bool QgsRasterMatrix::testPowerValidity(
double base,
double power )
const
433 return !( ( base == 0 &&
power < 0 ) || ( base < 0 && (
power - std::floor(
power ) ) > 0 ) );
Represents a matrix in a raster calculator operation.
bool equal(const QgsRasterMatrix &other)
bool max(const QgsRasterMatrix &other)
Calculates the maximum value between two matrices.
bool greaterEqual(const QgsRasterMatrix &other)
double * data()
Returns data array (but not ownership)
double * takeData()
Returns data and ownership.
bool notEqual(const QgsRasterMatrix &other)
bool greaterThan(const QgsRasterMatrix &other)
QgsRasterMatrix()=default
Takes ownership of data array.
bool logicalOr(const QgsRasterMatrix &other)
bool lesserEqual(const QgsRasterMatrix &other)
bool absoluteValue()
Calculates the absolute value.
bool logicalAnd(const QgsRasterMatrix &other)
bool isNumber() const
Returns true if matrix is 1x1 (=scalar number)
bool lesserThan(const QgsRasterMatrix &other)
bool add(const QgsRasterMatrix &other)
Adds another matrix to this one.
bool multiply(const QgsRasterMatrix &other)
QgsRasterMatrix & operator=(const QgsRasterMatrix &m)
bool power(const QgsRasterMatrix &other)
double nodataValue() const
bool min(const QgsRasterMatrix &other)
Calculates the minimum value between two matrices.
bool divide(const QgsRasterMatrix &other)
void setData(int cols, int rows, double *data, double nodataValue)
bool subtract(const QgsRasterMatrix &other)
Subtracts another matrix from this one.