35 , mNodataValue( nodataValue )
57 int nEntries = mColumns * mRows;
58 mData =
new float[nEntries];
59 memcpy( mData, m.mData,
sizeof(
float ) * nEntries );
76 mData = 0; mColumns = 0; mRows = 0;
82 return twoArgumentOperation(
opPLUS, other );
87 return twoArgumentOperation(
opMINUS, other );
92 return twoArgumentOperation(
opMUL, other );
97 return twoArgumentOperation(
opDIV, other );
102 return twoArgumentOperation(
opPOW, other );
107 return twoArgumentOperation(
opEQ, other );
112 return twoArgumentOperation(
opNE, other );
117 return twoArgumentOperation(
opGT, other );
122 return twoArgumentOperation(
opLT, other );
127 return twoArgumentOperation(
opGE, other );
132 return twoArgumentOperation(
opLE, other );
137 return twoArgumentOperation(
opAND, other );
142 return twoArgumentOperation(
opOR, other );
147 return oneArgumentOperation(
opSQRT );
152 return oneArgumentOperation(
opSIN );
157 return oneArgumentOperation(
opASIN );
162 return oneArgumentOperation(
opCOS );
167 return oneArgumentOperation(
opACOS );
172 return oneArgumentOperation(
opTAN );
177 return oneArgumentOperation(
opATAN );
182 return oneArgumentOperation(
opSIGN );
185 bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
192 int nEntries = mColumns * mRows;
194 for (
int i = 0; i < nEntries; ++i )
197 if ( value != mNodataValue )
204 mData[i] =
static_cast<float>( mNodataValue );
208 mData[i] =
static_cast<float>( sqrt( value ) );
212 mData[i] =
static_cast<float>( sin( value ) );
215 mData[i] =
static_cast<float>( cos( value ) );
218 mData[i] =
static_cast<float>( tan( value ) );
221 mData[i] =
static_cast<float>( asin( value ) );
224 mData[i] =
static_cast<float>( acos( value ) );
227 mData[i] =
static_cast<float>( atan( value ) );
230 mData[i] =
static_cast<float>( -value );
237 bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op,
const QgsRasterMatrix& other )
244 mData[0] =
static_cast<float>( mNodataValue );
250 mData[0] =
static_cast<float>(
number() + other.
number() );
253 mData[0] =
static_cast<float>(
number() - other.
number() );
256 mData[0] =
static_cast<float>(
number() * other.
number() );
259 if ( other.
number() == 0 )
261 mData[0] =
static_cast<float>( mNodataValue );
265 mData[0] =
static_cast<float>(
number() / other.
number() );
269 if ( !testPowerValidity( mData[0], (
float ) other.
number() ) )
271 mData[0] =
static_cast<float>( mNodataValue );
275 mData[0] = pow( mData[0], (
float ) other.
number() );
279 mData[0] = mData[0] == other.
number() ? 1.0f : 0.0f;
282 mData[0] = mData[0] == other.
number() ? 0.0f : 1.0f;
285 mData[0] = mData[0] > other.
number() ? 1.0f : 0.0f;
288 mData[0] = mData[0] < other.
number() ? 1.0f : 0.0f;
291 mData[0] = mData[0] >= other.
number() ? 1.0f : 0.0f;
294 mData[0] = mData[0] <= other.
number() ? 1.0f : 0.0f;
297 mData[0] = mData[0] && other.
number() ? 1.0f : 0.0f;
300 mData[0] = mData[0] || other.
number() ? 1.0f : 0.0f;
309 float* matrix = other.mData;
310 int nEntries = mColumns * mRows;
311 double value1, value2;
313 for (
int i = 0; i < nEntries; ++i )
315 value1 = mData[i]; value2 = matrix[i];
316 if ( value1 == mNodataValue || value2 == other.mNodataValue )
318 mData[i] =
static_cast<float>( mNodataValue );
325 mData[i] =
static_cast<float>( value1 + value2 );
328 mData[i] =
static_cast<float>( value1 - value2 );
331 mData[i] =
static_cast<float>( value1 * value2 );
336 mData[i] =
static_cast<float>( mNodataValue );
340 mData[i] =
static_cast<float>( value1 / value2 );
344 if ( !testPowerValidity( value1, value2 ) )
346 mData[i] =
static_cast<float>( mNodataValue );
350 mData[i] =
static_cast<float>( pow( value1, value2 ) );
354 mData[i] = value1 == value2 ? 1.0f : 0.0f;
357 mData[i] = value1 == value2 ? 0.0f : 1.0f;
360 mData[i] = value1 > value2 ? 1.0f : 0.0f;
363 mData[i] = value1 < value2 ? 1.0f : 0.0f;
366 mData[i] = value1 >= value2 ? 1.0f : 0.0f;
369 mData[i] = value1 <= value2 ? 1.0f : 0.0f;
372 mData[i] = value1 && value2 ? 1.0f : 0.0f;
375 mData[i] = value1 || value2 ? 1.0f : 0.0f;
386 float* matrix = other.mData;
388 double value = mData[0];
390 mData =
new float[nEntries]; mColumns = other.
nColumns(); mRows = other.
nRows();
393 if ( value == mNodataValue )
395 for (
int i = 0; i < nEntries; ++i )
397 mData[i] =
static_cast<float>( mNodataValue );
402 for (
int i = 0; i < nEntries; ++i )
404 if ( matrix[i] == other.mNodataValue )
406 mData[i] =
static_cast<float>( mNodataValue );
413 mData[i] =
static_cast<float>( value + matrix[i] );
416 mData[i] =
static_cast<float>( value - matrix[i] );
419 mData[i] =
static_cast<float>( value * matrix[i] );
422 if ( matrix[i] == 0 )
424 mData[i] =
static_cast<float>( mNodataValue );
428 mData[i] =
static_cast<float>( value / matrix[i] );
432 if ( !testPowerValidity( value, matrix[i] ) )
434 mData[i] =
static_cast<float>( mNodataValue );
438 mData[i] = pow( static_cast<float>( value ), matrix[i] );
442 mData[i] = value == matrix[i] ? 1.0f : 0.0f;
445 mData[i] = value == matrix[i] ? 0.0f : 1.0f;
448 mData[i] = value > matrix[i] ? 1.0f : 0.0f;
451 mData[i] = value < matrix[i] ? 1.0f : 0.0f;
454 mData[i] = value >= matrix[i] ? 1.0f : 0.0f;
457 mData[i] = value <= matrix[i] ? 1.0f : 0.0f;
460 mData[i] = value && matrix[i] ? 1.0f : 0.0f;
463 mData[i] = value || matrix[i] ? 1.0f : 0.0f;
471 double value = other.
number();
472 int nEntries = mColumns * mRows;
474 if ( other.
number() == other.mNodataValue )
476 for (
int i = 0; i < nEntries; ++i )
478 mData[i] =
static_cast<float>( mNodataValue );
483 for (
int i = 0; i < nEntries; ++i )
485 if ( mData[i] == mNodataValue )
493 mData[i] =
static_cast<float>( mData[i] + value );
496 mData[i] =
static_cast<float>( mData[i] - value );
499 mData[i] =
static_cast<float>( mData[i] * value );
504 mData[i] =
static_cast<float>( mNodataValue );
508 mData[i] =
static_cast<float>( mData[i] / value );
512 if ( !testPowerValidity( mData[i], value ) )
514 mData[i] =
static_cast<float>( mNodataValue );
518 mData[i] = pow( mData[i], (
float ) value );
522 mData[i] = mData[i] == value ? 1.0f : 0.0f;
525 mData[i] = mData[i] == value ? 0.0f : 1.0f;
528 mData[i] = mData[i] > value ? 1.0f : 0.0f;
531 mData[i] = mData[i] < value ? 1.0f : 0.0f;
534 mData[i] = mData[i] >= value ? 1.0f : 0.0f;
537 mData[i] = mData[i] <= value ? 1.0f : 0.0f;
540 mData[i] = mData[i] && value ? 1.0f : 0.0f;
543 mData[i] = mData[i] || value ? 1.0f : 0.0f;
551 bool QgsRasterMatrix::testPowerValidity(
double base,
double power )
553 if (( base == 0 && power < 0 ) || ( base < 0 && ( power - floor( power ) ) > 0 ) )