29 #include "../raster/Band.h" 30 #include "../raster/Utils.h" 31 #include "../common/PlatformUtils.h" 33 #include <boost/lexical_cast.hpp> 34 #include <boost/scoped_array.hpp> 40 #define DIFFUSENEIGHBOR( neighborRow, neighborCol ) \ 41 if( bufferMag[ neighborRow ][ neighborCol ] >= centerMag ) \ 43 ++validNeigborsNumber; \ 44 newCenterX += bufferX[ neighborRow ][ neighborCol ]; \ 45 newCenterY += bufferY[ neighborRow ][ neighborCol ]; \ 48 #define SKELSTRENGTHNEIGHBOR( neighborRow, neighborCol ) \ 49 neiX = inputX[ neighborRow ][ neighborCol ]; \ 50 neiY = inputY[ neighborRow ][ neighborCol ]; \ 51 diffX = neiX - centerX; \ 52 diffY = neiY - centerY; \ 53 diffMag = std::sqrt( ( diffX * diffX ) + ( diffY * diffY ) ); \ 54 if( diffMag != 0.0 ) \ 56 strength += ( ( ( diffX * neiX ) + ( diffY * neiY ) ) / diffMag ); \ 136 m_outputRasterPtr.reset();
173 std::unique_ptr< te::common::TaskProgress > progressPtr;
178 progressPtr->setTotalSteps( 7 );
180 progressPtr->setMessage(
"Generating the skeleton" );
185 std::unique_ptr< te::rp::Matrix< double > > rasterDataPtr(
189 "Gradient maps build error" );
194 progressPtr->pulse();
195 if( ! progressPtr->isActive() )
return false;
201 std::unique_ptr< te::rp::Matrix< double > > smoothedRasterDataPtr(
205 "Raster data smoothing error" );
207 rasterDataPtr.reset( smoothedRasterDataPtr.release() );
212 progressPtr->pulse();
213 if( ! progressPtr->isActive() )
return false;
221 edgeStrengthMap ),
"Edge strength map build error" );
224 rasterDataPtr.reset();
228 progressPtr->pulse();
229 if( ! progressPtr->isActive() )
return false;
241 "Vector maps build error" );
253 progressPtr->pulse();
254 if( ! progressPtr->isActive() )
return false;
264 progressPtr.get(), diffusedVecXMap, diffusedVecYMap ),
265 "Vector maps build error" );
281 progressPtr->pulse();
282 if( ! progressPtr->isActive() )
return false;
290 diffusedVecYMap, edgeStrengthMap, skelSMap ),
291 "Skeleton strength map build error" );
294 diffusedVecXMap.
reset();
295 diffusedVecYMap.
reset();
299 progressPtr->pulse();
300 if( ! progressPtr->isActive() )
return false;
306 std::vector< te::rst::BandProperty* > bandsProperties;
310 bandsProperties[ 0 ]->m_noDataValue = 0;
323 "Output raster creation error" );
328 const unsigned int rowsBound = nRows - 4;
329 const unsigned int colsBound = nCols - 4;
330 unsigned int row = 0;
331 unsigned int col = 0;
333 for( row = 0 ; row < nRows ; ++row )
335 for( col = 0 ; col <
nCols ; ++
col )
339 && ( row > 0 ) && ( row < rowsBound )
340 && ( col > 0 ) && ( col < colsBound )
343 outBand.setValue( col, row, 255 );
347 outBand.setValue( col, row, 0 );
355 progressPtr->pulse();
356 if( ! progressPtr->isActive() )
return false;
384 "Invalid m_inputRasterPtr" )
393 "Invalid raster band" );
399 "Invalid mask raster" );
403 "Invalid mask raster band" );
408 "Invalid mask raster number of rows" );
413 "Invalid mask raster number of columns" );
419 "Invalid diffusion threshold" );
424 "Invalid diffusion regularization" );
429 "Invalid diffusion regularization" );
446 if( ! rasterData.
reset( nRows,nCols ) )
449 unsigned int row = 0;
450 unsigned int col = 0;
455 double maskValue = 0;
457 for( row = 0 ; row < nRows ; ++row )
459 for( col = 0 ; col <
nCols ; ++
col )
463 maskBandPtr->
getValue( col, row, maskValue );
464 if( maskValue == 0.0 )
466 rasterData[ row ][
col ] = 0;
471 band.
getValue( col, row , rasterData[ row ][ col ] );
479 const bool unitVectors,
489 const unsigned int lastRowIdx = nRows - 1;
490 const unsigned int lastColIdx = nCols - 1;
492 if( ! gradXMap.
reset( nRows,nCols ) )
494 if( ! gradYMap.
reset( nRows,nCols ) )
497 unsigned int row = 0;
498 unsigned int col = 0;
500 for( row = 0 ; row < nRows ; ++row )
502 for( col = 0 ; col <
nCols ; ++
col )
504 gradXMap[ row ][
col ] = 0;
505 gradYMap[ row ][
col ] = 0;
517 unsigned int nextRow = 0;
518 unsigned int nextCol = 0;
519 unsigned int prevRow = 0;
520 unsigned int prevCol = 0;
525 for( row = 1 ; row < lastRowIdx ; ++row )
530 for( col = 1 ; col < lastColIdx ; ++
col )
535 value1 = inputData[ prevRow ][ prevCol ];
536 value2 = inputData[ prevRow ][
col ];
537 value3 = inputData[ prevRow ][ nextCol ];
538 value4 = inputData[ row ][ prevCol ];
539 value5 = inputData[ row ][ nextCol ];
540 value6 = inputData[ nextRow ][ prevCol ];
541 value7 = inputData[ nextRow ][
col ];
542 value8 = inputData[ nextRow ][ nextCol ];
545 ( inputData[ row ][ col ] == DBL_MAX ) ||
546 ( value1 == DBL_MAX ) || ( value2 == DBL_MAX ) ||
547 ( value3 == DBL_MAX ) || ( value4 == DBL_MAX ) ||
548 ( value5 == DBL_MAX ) || ( value6 == DBL_MAX ) ||
549 ( value7 == DBL_MAX ) || ( value8 == DBL_MAX )
556 gradX = ( ( value3 + value5 + value8 ) -
557 ( value1 + value4 + value6 ) );
558 gradY = ( ( value1 + value2 + value3 ) -
559 ( value6 + value7 + value8 ) );
561 if( unitVectors && ( gradX != 0.0 ) && ( gradY != 0.0 ) )
563 mag = std::sqrt( ( gradX * gradX ) + ( gradY * gradY ) );
568 gradXMap[ row ][
col ] = gradX;
569 gradYMap[ row ][
col ] = gradY;
587 const unsigned int lastRowIdx = nRows - 1;
588 const unsigned int lastColIdx = nCols - 1;
590 if( ! edgeStrengthMap.
reset( nRows,nCols ) )
598 "Gradient maps build error" );
600 unsigned int row = 0;
601 unsigned int col = 0;
603 for( row = 0 ; row < nRows ; ++row )
605 edgeStrengthMap[ row ][ 0 ] = 0;
606 edgeStrengthMap[ row ][ lastColIdx ] = 0;
609 for( col = 0 ; col <
nCols ; ++
col )
611 edgeStrengthMap[ 0 ][
col ] = 0;
612 edgeStrengthMap[ lastRowIdx ][
col ] = 0;
627 unsigned int nextRow = 0;
628 unsigned int nextCol = 0;
629 unsigned int prevRow = 0;
630 unsigned int prevCol = 0;
631 double strengthYUp = 0;
632 double strengthYDown = 0;
633 double strengthXLeft = 0;
634 double strengthXRight = 0;
638 double minStrength = DBL_MAX;
639 double maxStrength = -1.0 * DBL_MAX;
641 for( row = 1 ; row < lastRowIdx ; ++row )
646 for( col = 1 ; col < lastColIdx ; ++
col )
651 x1 = gradXMap[ prevRow ][ prevCol ];
652 x3 = gradXMap[ prevRow ][ nextCol ];
653 x4 = gradXMap[ row ][ prevCol ];
654 x5 = gradXMap[ row ][ nextCol ];
655 x6 = gradXMap[ nextRow ][ prevCol ];
656 x8 = gradXMap[ nextRow ][ nextCol ];
658 y1 = gradYMap[ prevRow ][ prevCol ];
659 y2 = gradYMap[ prevRow ][
col ];
660 y3 = gradYMap[ prevRow ][ nextCol ];
661 y6 = gradYMap[ nextRow ][ prevCol ];
662 y7 = gradYMap[ nextRow ][
col ];
663 y8 = gradYMap[ nextRow ][ nextCol ];
665 strengthXRight = x1 + x4 + x6;
666 strengthXLeft = x3 + x5 + x8;
667 strengthYUp = y6 + y7 + y8;
668 strengthYDown = y1 + y2 + y3;
670 diffX = std::abs( strengthXRight - strengthXLeft );
671 diffY = std::abs( strengthYUp - strengthYDown );
673 strength = std::max( diffX, diffY );
675 edgeStrengthMap[ row ][
col ] = strength;
677 if( minStrength > strength ) minStrength = strength;
678 if( maxStrength < strength ) maxStrength = strength;
682 const double gain = ( minStrength == maxStrength ) ? 0.0 :
683 ( 1.0 / ( maxStrength - minStrength ) );
685 for( row = 1 ; row < lastRowIdx ; ++row )
687 for( col = 1 ; col < lastColIdx ; ++
col )
689 strength = edgeStrengthMap[ row ][
col ] - minStrength;
691 edgeStrengthMap[ row ][
col ] = strength;
702 const unsigned int vecPixelStep,
703 const std::string& tifFileName )
const 712 std::map<std::string, std::string> rInfo;
713 rInfo[
"URI"] = tifFileName +
".tif";
715 std::vector<te::rst::BandProperty*> bandsProperties;
718 bandsProperties[0]->m_noDataValue = -1.0 * DBL_MAX;
727 std::unique_ptr< te::rst::Raster > outputRasterPtr(
731 unsigned int line = 0;
732 unsigned int col = 0;
735 const unsigned int lastLineIdx = inputVecFieldX.
getLinesNumber() - 1;
740 if( backGroundMapPtr )
742 double minBGValue = DBL_MAX;
743 double maxBGValue = -1.0 * DBL_MAX;
748 for( col = 0 ; col <
nCols ; ++
col )
750 bGValue = backGroundMapPtr->operator[](
line )[ col ];
752 if( minBGValue > bGValue )
754 minBGValue = bGValue;
757 if( maxBGValue < bGValue )
759 maxBGValue = bGValue;
766 for( col = 0 ; col <
nCols ; ++
col )
768 bGValue = backGroundMapPtr->operator[](
line )[ col ];
769 bGValue -= minBGValue;
770 bGValue *= ( 128.0 / ( maxBGValue - minBGValue ) );
772 outputRasterPtr->setValue( col, line, bGValue, 0 );
773 outputRasterPtr->setValue( col, line, bGValue, 1 );
774 outputRasterPtr->setValue( col, line, bGValue, 2 );
782 for( col = 0 ; col <
nCols ; ++
col )
784 outputRasterPtr->setValue( col, line, 0, 0 );
785 outputRasterPtr->setValue( col, line, 0, 1 );
786 outputRasterPtr->setValue( col, line, 0, 2 );
791 for( line = 1 ; line < lastLineIdx ; line += vecPixelStep )
793 for( col = 1 ; col < lastColIdx ; col += vecPixelStep )
795 x = inputVecFieldX[
line ][
col ];
796 y = inputVecFieldY[
line ][
col ];
797 outputRasterPtr->setValue( col, line, 255, 0 );
803 outputRasterPtr->setValue( col, line - 1, 255, 1 );
807 outputRasterPtr->setValue( col, line + 1, 255, 1 );
814 outputRasterPtr->setValue( col + 1, line, 255, 1 );
818 outputRasterPtr->setValue( col + 1, line - 1, 255, 1 );
822 outputRasterPtr->setValue( col + 1, line + 1, 255, 1 );
829 outputRasterPtr->setValue( col - 1, line, 255, 1 );
833 outputRasterPtr->setValue( col - 1, line - 1, 255, 1 );
837 outputRasterPtr->setValue( col - 1, line + 1, 255, 1 );
861 const unsigned int rowSizeBytes =
sizeof( double ) * nCols;
863 if( ! outputX.
reset( nRows,nCols ) )
865 if( ! outputY.
reset( nRows,nCols ) )
868 std::unique_ptr< te::rp::Matrix< double > > xBuf1Ptr;
870 if( ! xBuf1Ptr->reset( nRows,nCols ) )
873 std::unique_ptr< te::rp::Matrix< double > > yBuf1Ptr;
875 if( ! yBuf1Ptr->reset( nRows,nCols ) )
878 std::unique_ptr< te::rp::Matrix< double > > xBuf2Ptr;
880 if( ! xBuf2Ptr->reset( nRows,nCols ) )
883 std::unique_ptr< te::rp::Matrix< double > > yBuf2Ptr;
885 if( ! yBuf2Ptr->reset( nRows,nCols ) )
888 std::unique_ptr< te::rp::Matrix< double > > magBuf1Ptr;
890 if( ! magBuf1Ptr->reset( nRows,nCols ) )
893 std::unique_ptr< te::rp::Matrix< double > > magBuf2Ptr;
895 if( ! magBuf2Ptr->reset( nRows,nCols ) )
897 if( !
getMagnitude( inputX, inputY, *magBuf2Ptr ) )
return false;
899 double currentIterationResidue = DBL_MAX;
913 static_cast<const unsigned int>(std::ceil( (static_cast<double>(nRows - 8 )) / (static_cast<double>(threadsNumber)))) : nRows;
915 unsigned int iteration = 0;
931 if( ! progressPtr->
isActive() )
return false;
934 currentIterationResidue = 0;
995 threadParams.
m_inputBufXPtr->operator[]( nRows - 4 ), rowSizeBytes );
997 threadParams.
m_inputBufXPtr->operator[]( nRows - 3 ), rowSizeBytes );
999 threadParams.
m_inputBufXPtr->operator[]( nRows - 2 ), rowSizeBytes );
1001 threadParams.
m_inputBufXPtr->operator[]( nRows - 1 ), rowSizeBytes );
1013 threadParams.
m_inputBufYPtr->operator[]( nRows - 4 ), rowSizeBytes );
1015 threadParams.
m_inputBufYPtr->operator[]( nRows - 3 ), rowSizeBytes );
1017 threadParams.
m_inputBufYPtr->operator[]( nRows - 2 ), rowSizeBytes );
1019 threadParams.
m_inputBufYPtr->operator[]( nRows - 1 ), rowSizeBytes );
1023 unsigned int startingRow = 4;
1024 std::vector< ApplyVecDiffusionThreadParams > threadsParamesVec;
1025 threadsParamesVec.resize( threadsNumber, threadParams );
1026 boost::thread_group threads;
1028 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
1031 threadsParamesVec[ threadIdx ].m_firstRowIdx = startingRow;
1032 threadsParamesVec[ threadIdx ].m_lastRowIdx = std::min( nRows - 5,
1033 startingRow + rowsPerThread - 1 );
1035 &threadsParamesVec[ threadIdx ] ) );
1036 startingRow += rowsPerThread;
1077 for(
unsigned int row = 0 ; row < nRows ; ++row )
1079 memcpy( outputX[ row ], threadParams.
m_outputBufXPtr->operator[]( row ),
1081 memcpy( outputY[ row ], threadParams.
m_outputBufYPtr->operator[]( row ),
1099 const double complementDiffReg = 1.0 - diffusionRegularization;
1101 const unsigned int rowSizeBytes =
sizeof( double ) * nCols;
1102 unsigned int row = 0;
1103 unsigned int col = 0;
1105 boost::scoped_array< double > bufMagRow0Handler(
new double[ nCols ] );
1106 boost::scoped_array< double > bufMagRow1Handler(
new double[ nCols ] );
1107 boost::scoped_array< double > bufMagRow2Handler(
new double[ nCols ] );
1108 boost::scoped_array< double > bufXRow0Handler(
new double[ nCols ] );
1109 boost::scoped_array< double > bufXRow1Handler(
new double[ nCols ] );
1110 boost::scoped_array< double > bufXRow2Handler(
new double[ nCols ] );
1111 boost::scoped_array< double > bufYRow0Handler(
new double[ nCols ] );
1112 boost::scoped_array< double > bufYRow1Handler(
new double[ nCols ] );
1113 boost::scoped_array< double > bufYRow2Handler(
new double[ nCols ] );
1122 double* bufferMag[ 3 ];
1123 double* bufferX[ 3 ];
1124 double* bufferY[ 3 ];
1125 bufferMag[ 0 ] = bufMagRow0Handler.get();
1126 bufferMag[ 1 ] = bufMagRow1Handler.get();
1127 bufferMag[ 2 ] = bufMagRow2Handler.get();
1134 bufferX[ 0 ] = bufXRow0Handler.get();
1135 bufferX[ 1 ] = bufXRow1Handler.get();
1136 bufferX[ 2 ] = bufXRow2Handler.get();
1137 bufferY[ 0 ] = bufYRow0Handler.get();
1138 bufferY[ 1 ] = bufYRow1Handler.get();
1139 bufferY[ 2 ] = bufYRow2Handler.get();
1145 memcpy( bufferMag[ 1 ], iBufMag[ paramsPtr->
m_firstRowIdx - 1 ],
1147 memcpy( bufferMag[ 2 ], iBufMag[ paramsPtr->
m_firstRowIdx ],
1160 memcpy( bufferX[ 1 ], iBufX[ paramsPtr->
m_firstRowIdx - 1 ],
1165 memcpy( bufferY[ 1 ], iBufY[ paramsPtr->
m_firstRowIdx - 1 ],
1172 const unsigned int rowsBound = paramsPtr->
m_lastRowIdx + 2;
1173 const unsigned int colsBound = nCols - 4;
1176 double centerDiffX = 0;
1177 double centerDiffY = 0;
1180 double centerMag = 0;
1181 double newCenterX = 0;
1182 double newCenterY = 0;
1183 double* rowPtr =
nullptr;
1184 unsigned int prevRow = 0;
1185 unsigned int prevCol = 0;
1186 unsigned int nextCol = 0;
1187 double currentIterationResidue = 0;
1188 double validNeigborsNumber = 0.0;
1190 boost::scoped_array< double > outRowMagBuffHandler(
new double[ nCols ] );
1191 double* outRowMagBuff = outRowMagBuffHandler.get();
1193 boost::scoped_array< double > outRowXBuffHandler(
new double[ nCols ] );
1194 double* outRowXBuff = outRowXBuffHandler.get();
1196 boost::scoped_array< double > outRowYBuffHandler(
new double[ nCols ] );
1197 double* outRowYBuff = outRowYBuffHandler.get();
1199 for( row = ( paramsPtr->
m_firstRowIdx + 1 ) ; row < rowsBound ; ++row )
1215 rowPtr = bufferMag[ 0 ];
1216 bufferMag[ 0 ] = bufferMag[ 1 ];
1217 bufferMag[ 1 ] = bufferMag[ 2 ];
1218 bufferMag[ 2 ] = rowPtr;
1220 rowPtr = bufferX[ 0 ];
1221 bufferX[ 0 ] = bufferX[ 1 ];
1222 bufferX[ 1 ] = bufferX[ 2 ];
1223 bufferX[ 2 ] = rowPtr;
1225 rowPtr = bufferY[ 0 ];
1226 bufferY[ 0 ] = bufferY[ 1 ];
1227 bufferY[ 1 ] = bufferY[ 2 ];
1228 bufferY[ 2 ] = rowPtr;
1235 memcpy( bufferMag[ 2 ], iBufMag[ row ], rowSizeBytes );
1236 memcpy( bufferX[ 2 ], iBufX[ row ], rowSizeBytes );
1237 memcpy( bufferY[ 2 ], iBufY[ row ], rowSizeBytes );
1242 for( col = 4 ; col < colsBound ; ++
col )
1250 centerMag = bufferMag[ 1 ][
col ];
1251 centerX = bufferX[ 1 ][
col ];
1252 centerY = bufferY[ 1 ][
col ];
1254 validNeigborsNumber = 0.0;
1267 if( validNeigborsNumber != 0.0 )
1269 newCenterX /= validNeigborsNumber;
1270 newCenterY /= validNeigborsNumber;
1272 newCenterX = ( newCenterX * diffusionRegularization ) +
1273 ( centerX * complementDiffReg );
1274 newCenterY = ( newCenterY * diffusionRegularization ) +
1275 ( centerY * complementDiffReg );
1277 centerDiffX = centerX - newCenterX;
1278 centerDiffY = centerY - newCenterY;
1280 if( centerDiffX != 0.0 )
1282 if( centerX == 0.0 )
1284 currentIterationResidue = std::max( currentIterationResidue, 1.0 );
1288 currentIterationResidue =
1290 currentIterationResidue
1292 std::abs( centerDiffX / centerX )
1297 if( centerDiffY != 0.0 )
1299 if( centerY == 0.0 )
1301 currentIterationResidue = std::max( currentIterationResidue, 1.0 );
1305 currentIterationResidue =
1307 currentIterationResidue
1309 std::abs( centerDiffY / centerY )
1314 outRowXBuff[
col ] = newCenterX;
1315 outRowYBuff[
col ] = newCenterY;
1316 outRowMagBuff[
col ] = std::sqrt( ( newCenterX * newCenterX ) + ( newCenterY *
1321 outRowXBuff[
col ] = centerX;
1322 outRowYBuff[
col ] = centerY;
1323 outRowMagBuff[
col ] = centerMag;
1331 memcpy( oMagBuf[ prevRow ], outRowMagBuff, rowSizeBytes );
1332 memcpy( oBufX[ prevRow ], outRowXBuff, rowSizeBytes );
1333 memcpy( oBufY[ prevRow ], outRowYBuff, rowSizeBytes );
1335 oMagBuf[ prevRow ][ 0 ] = iBufMag[ 1 ][ 0 ];
1336 oMagBuf[ prevRow ][ 1 ] = iBufMag[ 1 ][ 1 ];
1337 oMagBuf[ prevRow ][ 2 ] = iBufMag[ 1 ][ 2 ];
1338 oMagBuf[ prevRow ][ 3 ] = iBufMag[ 1 ][ 3 ];
1339 oMagBuf[ prevRow ][ colsBound ] = iBufMag[ 1 ][ colsBound ];
1340 oMagBuf[ prevRow ][ colsBound + 1 ] = iBufMag[ 1 ][ colsBound + 1 ];
1341 oMagBuf[ prevRow ][ colsBound + 2 ] = iBufMag[ 1 ][ colsBound + 2 ];
1342 oMagBuf[ prevRow ][ colsBound + 3 ] = iBufMag[ 1 ][ colsBound + 3 ];
1344 oBufX[ prevRow ][ 0 ] = bufferX[ 1 ][ 0 ];
1345 oBufX[ prevRow ][ 1 ] = bufferX[ 1 ][ 1 ];
1346 oBufX[ prevRow ][ 2 ] = bufferX[ 1 ][ 2 ];
1347 oBufX[ prevRow ][ 3 ] = bufferX[ 1 ][ 3 ];
1348 oBufX[ prevRow ][ colsBound ] = bufferX[ 1 ][ colsBound ];
1349 oBufX[ prevRow ][ colsBound + 1 ] = bufferX[ 1 ][ colsBound + 1 ];
1350 oBufX[ prevRow ][ colsBound + 2 ] = bufferX[ 1 ][ colsBound + 2 ];
1351 oBufX[ prevRow ][ colsBound + 3 ] = bufferX[ 1 ][ colsBound + 3 ];
1353 oBufY[ prevRow ][ 0 ] = bufferY[ 1 ][ 0 ];
1354 oBufY[ prevRow ][ 1 ] = bufferY[ 1 ][ 1 ];
1355 oBufY[ prevRow ][ 2 ] = bufferY[ 1 ][ 2 ];
1356 oBufY[ prevRow ][ 3 ] = bufferY[ 1 ][ 3 ];
1357 oBufY[ prevRow ][ colsBound ] = bufferY[ 1 ][ colsBound ];
1358 oBufY[ prevRow ][ colsBound + 1 ] = bufferY[ 1 ][ colsBound + 1 ];
1359 oBufY[ prevRow ][ colsBound + 2 ] = bufferY[ 1 ][ colsBound + 2 ];
1360 oBufY[ prevRow ][ colsBound + 3 ] = bufferY[ 1 ][ colsBound + 3 ];
1364 currentIterationResidue );
1385 if( ! skelMap.
reset( nRows,nCols ) )
1388 const unsigned int lastRowIdx = nRows - 1;
1389 const unsigned int lastColIdx = nCols - 1;
1390 unsigned int row = 0;
1391 unsigned int col = 0;
1392 unsigned int nextRow = 0;
1393 unsigned int nextCol = 0;
1394 unsigned int prevRow = 0;
1395 unsigned int prevCol = 0;
1403 double strength = 0;
1404 double minStrength = DBL_MAX;
1405 double maxStrength = -1.0 * DBL_MAX;
1407 for( row = 0 ; row < nRows ; ++row )
1409 skelMap[ row ][ 0 ] = 0;
1410 skelMap[ row ][ lastColIdx ] = 0;
1413 for( col = 0 ; col <
nCols ; ++
col )
1415 skelMap[ 0 ][
col ] = 0;
1416 skelMap[ lastRowIdx ][
col ] = 0;
1419 for( row = 1 ; row < lastRowIdx ; ++row )
1424 for( col = 1 ; col < lastColIdx ; ++
col )
1429 centerX = inputX[ row ][
col ];
1430 centerY = inputY[ row ][
col ];
1444 strength = std::max( 0.0, strength );
1446 skelMap[ row ][
col ] = strength;
1448 if( minStrength > strength ) minStrength = strength;
1449 if( maxStrength < strength ) maxStrength = strength;
1453 const double gain = ( minStrength == maxStrength ) ? 0.0 :
1454 ( 1.0 / ( maxStrength - minStrength ) );
1456 for( row = 1 ; row < lastRowIdx ; ++row )
1458 for( col = 1 ; col < lastColIdx ; ++
col )
1460 strength = skelMap[ row ][
col ];
1461 strength -= minStrength;
1463 strength = ( strength + ( 1.0 - edgeStrengthMap[ row ][
col ] ) ) / 2.0;
1464 skelMap[ row ][
col ] = strength;
bool getMagnitude(const te::rp::Matrix< double > &xMap, const te::rp::Matrix< double > &yMap, te::rp::Matrix< MatrixElementT > &magnitude) const
Generate the magnitude map from the input vectors.
te::rp::Matrix< double > const * m_initialYBufPtr
A pointer to the input buffer initial Y component.
Index into a lookup table.
#define SKELSTRENGTHNEIGHBOR(neighborRow, neighborCol)
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output registered raster.
double * m_currentIterationResiduePtr
A pointer the the current iteration residue;.
A raster band description.
Skeleton::InputParameters m_inputParameters
Input execution parameters.
Skeleton output parameters.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
te::rp::Matrix< double > const * m_inputMagBufPtr
A pointer to the input magnitude buffer.
bool m_isInitialized
Tells if this instance is initialized.
This class can be used to inform the progress of a task.
Raster Processing algorithm output parameters base interface.
bool loadData(te::rp::Matrix< double > &rasterData) const
Load data from the input raster.
Red channel color interpretation.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
#define DIFFUSENEIGHBOR(neighborRow, neighborCol)
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
double m_diffusionRegularization
The diffusion regularization parameter.
bool isActive() const
Verify if the task is active.
te::rp::Matrix< double > const * m_initialXBufPtr
A pointer to the input buffer initial X component.
boost::mutex * m_mutexPtr
A pointer to the sync mutex.
bool applyMeanSmooth(const te::rp::Matrix< MatrixElementT > &input, te::rp::Matrix< MatrixElementT > &output) const
Apply a mean filter.
#define TERP_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged and a return of context wi...
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
unsigned int unsigned int nCols
TECOMMONEXPORT unsigned int GetPhysProcNumber()
Returns the number of physical processors.
bool createSkeletonStrengthMap(const te::rp::Matrix< double > &inputX, const te::rp::Matrix< double > &inputY, const te::rp::Matrix< double > &edgeStrengthMap, te::rp::Matrix< double > &skelMap) const
Create a skeleton strength map.
bool getEdgeStrengthMap(const te::rp::Matrix< double > &inputMap, te::rp::Matrix< double > &edgeStrengthMap) const
Create an Edge strenght Map from the input data.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
unsigned int getColumnsNumber() const
The number of current matrix columns.
unsigned int m_firstRowIdx
First row to process.
bool applyVecDiffusion(const te::rp::Matrix< double > &inputX, const te::rp::Matrix< double > &inputY, te::rp::Matrix< double > const *const, te::common::TaskProgress *progressPtr, te::rp::Matrix< double > &outputX, te::rp::Matrix< double > &outputY) const
Apply a vector diffusion over the given vector field.
BandProperty * getProperty()
Returns the band property.
AbstractParameters * clone() const
Create a clone copy of this instance.
te::rp::Matrix< double > const * m_inputBufXPtr
A pointer to the input buffer X component.
te::rp::Matrix< double > * m_outputBufXPtr
A pointer to the output buffer X component.
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
te::rp::Matrix< double > const * m_inputBufYPtr
A pointer to the input buffer Y component.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Grid * getGrid()
It returns the raster grid.
unsigned int m_lastRowIdx
Last row to process.
bool getGradientMaps(const te::rp::Matrix< double > &inputData, const bool unitVectors, te::rp::Matrix< double > &gradXMap, te::rp::Matrix< double > &gradYMap) const
Create an gradient maps from the input image.
const OutputParameters & operator=(const OutputParameters ¶ms)
void reset()
Reset (clear) the active instance data.
static void applyVecDiffusionThreadEntry(ApplyVecDiffusionThreadParams *paramsPtr)
Vector diffusion thread entry.
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
Abstract parameters base interface.
te::rp::Matrix< double > * m_outputMagBufPtr
A pointer to the output magnitude buffer.
static Raster * make()
It creates and returns an empty raster with default raster driver.
void createTifFromVecField(const te::rp::Matrix< double > &inputVecFieldX, const te::rp::Matrix< double > &inputVecFieldY, te::rp::Matrix< double > const *const backGroundMapPtr, const unsigned int vecPixelStep, const std::string &tifFileName) const
Create a tiff file from a vector field.
Raster Processing functions.
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
virtual void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
Blue channel color interpretation.
A rectified grid is the spatial support for raster data.
Green channel color interpretation.
#define TERP_INSTANCE_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged, the current instance erro...
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state...
unsigned int getLinesNumber() const
The number of current matrix lines.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Creation of skeleton imagems.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
te::rp::Matrix< double > * m_outputBufYPtr
A pointer to the output buffer X component.