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 ); \ 
   83       m_inputRasterBand = 0;
 
   84       m_inputMaskRasterPtr = 0;
 
   85       m_diffusionThreshold = 0.5;
 
   86       m_diffusionRegularization = 0.5;
 
   87       m_diffusionMaxIterations = 0;
 
   88       m_enableMultiThread = 
true;
 
   89       m_skeletonThreshold = 0.75;
 
   90       m_enableProgress = 
false;
 
  136       m_outputRasterPtr.reset();
 
  165       throw( te::rp::Exception )
 
  175       std::auto_ptr< te::common::TaskProgress > progressPtr;
 
  180         progressPtr->setTotalSteps( 7 );
 
  182         progressPtr->setMessage( 
"Generating the skeleton" );
 
  187       std::auto_ptr< te::rp::Matrix< double > > rasterDataPtr( 
 
  191         "Gradient maps build error" );      
 
  196         progressPtr->pulse();
 
  197         if( ! progressPtr->isActive() ) 
return false;
 
  203         std::auto_ptr< te::rp::Matrix< double > > smoothedRasterDataPtr( 
 
  207           "Raster data smoothing error" );
 
  209         rasterDataPtr.reset( smoothedRasterDataPtr.release() );        
 
  214         progressPtr->pulse();
 
  215         if( ! progressPtr->isActive() ) 
return false;
 
  223         edgeStrengthMap ), 
"Edge strength map build error" ); 
 
  226       rasterDataPtr.reset();
 
  230         progressPtr->pulse();
 
  231         if( ! progressPtr->isActive() ) 
return false;
 
  243         "Vector maps build error" );
 
  255         progressPtr->pulse();
 
  256         if( ! progressPtr->isActive() ) 
return false;
 
  266         progressPtr.get(), diffusedVecXMap, diffusedVecYMap ),
 
  267         "Vector maps build error" ); 
 
  283         progressPtr->pulse();
 
  284         if( ! progressPtr->isActive() ) 
return false;
 
  292         diffusedVecYMap, edgeStrengthMap, skelSMap ),
 
  293         "Skeleton strength map build error" );  
 
  296       diffusedVecXMap.
reset();
 
  297       diffusedVecYMap.
reset();
 
  301         progressPtr->pulse();
 
  302         if( ! progressPtr->isActive() ) 
return false;
 
  308         std::vector< te::rst::BandProperty* > bandsProperties;
 
  312         bandsProperties[ 0 ]->m_noDataValue = 0;
 
  325           "Output raster creation error" );
 
  329         const unsigned int nCols = outParamsPtr->
m_outputRasterPtr->getNumberOfColumns();
 
  330         const unsigned int rowsBound = nRows - 4;
 
  331         const unsigned int colsBound = nCols - 4;
 
  332         unsigned int row = 0;
 
  333         unsigned int col = 0;
 
  335         for( row = 0 ; row < nRows ; ++row )
 
  337           for( col = 0 ; col < nCols ; ++col )
 
  341                 && ( row > 0 ) && ( row < rowsBound )
 
  342                 && ( col > 0 ) && ( col < colsBound )
 
  345               outBand.setValue( col, row, 255 );
 
  349               outBand.setValue( col, row, 0 );
 
  357         progressPtr->pulse();
 
  358         if( ! progressPtr->isActive() ) 
return false;
 
  371       throw( te::rp::Exception )
 
  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;
 
  631       unsigned int nextRow = 0;
 
  632       unsigned int nextCol = 0;
 
  633       unsigned int prevRow = 0;
 
  634       unsigned int prevCol = 0;      
 
  635       double strengthYUp = 0;
 
  636       double strengthYDown = 0;
 
  637       double strengthXLeft = 0;
 
  638       double strengthXRight = 0;
 
  642       double minStrength = DBL_MAX;
 
  643       double maxStrength = -1.0 * DBL_MAX;
 
  645       for( row = 1 ; row < lastRowIdx ; ++row )
 
  650         for( col = 1 ; col < lastColIdx ; ++col )
 
  655           x1 = gradXMap[ prevRow ][ prevCol ];
 
  656           x2 = gradXMap[ prevRow ][ col ];
 
  657           x3 = gradXMap[ prevRow ][ nextCol ];
 
  658           x4 = gradXMap[ row ][ prevCol ];
 
  659           x5 = gradXMap[ row ][ nextCol ];
 
  660           x6 = gradXMap[ nextRow ][ prevCol ];
 
  661           x7 = gradXMap[ nextRow ][ col ];
 
  662           x8 = gradXMap[ nextRow ][ nextCol ];
 
  664           y1 = gradYMap[ prevRow ][ prevCol ];
 
  665           y2 = gradYMap[ prevRow ][ col ];
 
  666           y3 = gradYMap[ prevRow ][ nextCol ];
 
  667           y4 = gradYMap[ row ][ prevCol ];
 
  668           y5 = gradYMap[ row ][ nextCol ];
 
  669           y6 = gradYMap[ nextRow ][ prevCol ];
 
  670           y7 = gradYMap[ nextRow ][ col ];
 
  671           y8 = gradYMap[ nextRow ][ nextCol ];
 
  673           strengthXRight = x1 + x4 + x6;
 
  674           strengthXLeft = x3 + x5 + x8;
 
  675           strengthYUp = y6 + y7 + y8;
 
  676           strengthYDown = y1 + y2 + y3;
 
  678           diffX = std::abs( strengthXRight - strengthXLeft );
 
  679           diffY = std::abs( strengthYUp - strengthYDown );
 
  681           strength = std::max( diffX, diffY );
 
  683           edgeStrengthMap[ row ][ col ] = strength;
 
  685           if( minStrength > strength ) minStrength = strength;
 
  686           if( maxStrength < strength ) maxStrength = strength;
 
  690       const double gain = ( minStrength == maxStrength ) ? 0.0 : 
 
  691         ( 1.0 / ( maxStrength - minStrength ) );
 
  693       for( row = 1 ; row < lastRowIdx ; ++row )
 
  695         for( col = 1 ; col < lastColIdx ; ++col )
 
  697           strength =  edgeStrengthMap[ row ][ col ] - minStrength;
 
  699           edgeStrengthMap[ row ][ col ] = strength;
 
  710       const unsigned int vecPixelStep,
 
  711       const std::string& tifFileName )
 const  
  720       std::map<std::string, std::string> rInfo;
 
  721       rInfo[
"URI"] = tifFileName + 
".tif";
 
  723       std::vector<te::rst::BandProperty*> bandsProperties;
 
  726       bandsProperties[0]->m_noDataValue = -1.0 * DBL_MAX;
 
  735       std::auto_ptr< te::rst::Raster > outputRasterPtr(
 
  739       unsigned int line = 0;
 
  740       unsigned int col = 0;
 
  743       const unsigned int lastLineIdx = inputVecFieldX.
getLinesNumber() - 1;
 
  748       if( backGroundMapPtr )
 
  750         double minBGValue = DBL_MAX;
 
  751         double maxBGValue = -1.0 * DBL_MAX;
 
  754         for( line = 0 ; line < nLines ; ++line )
 
  756           for( col = 0 ; col < nCols ; ++col )
 
  758             bGValue = backGroundMapPtr->operator[]( line )[ col ];
 
  760             if( minBGValue > bGValue )
 
  762               minBGValue = bGValue;
 
  765             if( maxBGValue < bGValue )
 
  767               maxBGValue = bGValue;
 
  772         for( line = 0 ; line < nLines ; ++line )
 
  774           for( col = 0 ; col < nCols ; ++col )
 
  776             bGValue = backGroundMapPtr->operator[]( line )[ col ];
 
  777             bGValue -= minBGValue;
 
  778             bGValue *= ( 128.0 / ( maxBGValue - minBGValue ) );
 
  780             outputRasterPtr->setValue( col, line, bGValue, 0 );
 
  781             outputRasterPtr->setValue( col, line, bGValue, 1 );
 
  782             outputRasterPtr->setValue( col, line, bGValue, 2 );
 
  788         for( line = 0 ; line < nLines ; ++line )
 
  790           for( col = 0 ; col < nCols ; ++col )
 
  792             outputRasterPtr->setValue( col, line, 0, 0 );
 
  793             outputRasterPtr->setValue( col, line, 0, 1 );
 
  794             outputRasterPtr->setValue( col, line, 0, 2 );
 
  799       for( line = 1 ; line < lastLineIdx ; line += vecPixelStep )
 
  801         for( col = 1 ; col < lastColIdx ; col += vecPixelStep )
 
  803           x = inputVecFieldX[ line ][ col ];
 
  804           y = inputVecFieldY[ line ][ col ];
 
  805           outputRasterPtr->setValue( col, line, 255, 0 );
 
  811               outputRasterPtr->setValue( col, line - 1, 255, 1 );
 
  815               outputRasterPtr->setValue( col, line + 1, 255, 1 );
 
  822               outputRasterPtr->setValue( col + 1, line, 255, 1 );
 
  826               outputRasterPtr->setValue( col + 1, line - 1, 255, 1 );
 
  830               outputRasterPtr->setValue( col + 1, line + 1, 255, 1 );
 
  837               outputRasterPtr->setValue( col - 1, line, 255, 1 );
 
  841               outputRasterPtr->setValue( col - 1, line - 1, 255, 1 );
 
  845               outputRasterPtr->setValue( col - 1, line + 1, 255, 1 );
 
  869       const unsigned int rowSizeBytes = 
sizeof( double ) * nCols;
 
  871       if( ! outputX.
reset( nRows,nCols ) )
 
  873       if( ! outputY.
reset( nRows,nCols ) )
 
  876       std::auto_ptr< te::rp::Matrix< double > > xBuf1Ptr;
 
  878       if( ! xBuf1Ptr->reset( nRows,nCols ) )
 
  881       std::auto_ptr< te::rp::Matrix< double > > yBuf1Ptr;
 
  883       if( ! yBuf1Ptr->reset( nRows,nCols ) )
 
  886       std::auto_ptr< te::rp::Matrix< double > > xBuf2Ptr;
 
  888       if( ! xBuf2Ptr->reset( nRows,nCols ) )
 
  891       std::auto_ptr< te::rp::Matrix< double > > yBuf2Ptr;      
 
  893       if( ! yBuf2Ptr->reset( nRows,nCols ) )
 
  896       std::auto_ptr< te::rp::Matrix< double > > magBuf1Ptr;
 
  898       if( ! magBuf1Ptr->reset( nRows,nCols ) )
 
  901       std::auto_ptr< te::rp::Matrix< double > > magBuf2Ptr;
 
  903       if( ! magBuf2Ptr->reset( nRows,nCols ) )
 
  905       if( ! 
getMagnitude( inputX, inputY, *magBuf2Ptr ) ) 
return false;
 
  907       double currentIterationResidue = DBL_MAX;
 
  921         (
const unsigned int)(std::ceil( ((
double)(nRows - 8 )) / ((
double)threadsNumber))) : nRows;
 
  923       unsigned int iteration = 0;
 
  939           if( ! progressPtr->
isActive() ) 
return false;          
 
  942         currentIterationResidue = 0;
 
 1003           threadParams.
m_inputBufXPtr->operator[]( nRows - 4 ), rowSizeBytes );
 
 1005           threadParams.
m_inputBufXPtr->operator[]( nRows - 3 ), rowSizeBytes );
 
 1007           threadParams.
m_inputBufXPtr->operator[]( nRows - 2 ), rowSizeBytes );
 
 1009           threadParams.
m_inputBufXPtr->operator[]( nRows - 1 ), rowSizeBytes );
 
 1021           threadParams.
m_inputBufYPtr->operator[]( nRows - 4 ), rowSizeBytes );          
 
 1023           threadParams.
m_inputBufYPtr->operator[]( nRows - 3 ), rowSizeBytes );          
 
 1025           threadParams.
m_inputBufYPtr->operator[]( nRows - 2 ), rowSizeBytes );          
 
 1027           threadParams.
m_inputBufYPtr->operator[]( nRows - 1 ), rowSizeBytes );          
 
 1031           unsigned int startingRow = 4;
 
 1032           std::vector< ApplyVecDiffusionThreadParams > threadsParamesVec;
 
 1033           threadsParamesVec.resize( threadsNumber, threadParams );
 
 1034           boost::thread_group threads;
 
 1036           for( 
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
 
 1039             threadsParamesVec[ threadIdx ].m_firstRowIdx = startingRow;
 
 1040             threadsParamesVec[ threadIdx ].m_lastRowIdx = std::min( nRows - 5,
 
 1041               startingRow + rowsPerThread - 1 );
 
 1043               &threadsParamesVec[ threadIdx ] ) );
 
 1044             startingRow += rowsPerThread;
 
 1085       for( 
unsigned int row = 0 ; row < nRows ; ++row )
 
 1087         memcpy( outputX[ row ], threadParams.
m_outputBufXPtr->operator[]( row ),
 
 1089         memcpy( outputY[ row ], threadParams.
m_outputBufYPtr->operator[]( row ),
 
 1107       const double complementDiffReg = 1.0 - diffusionRegularization;
 
 1109       const unsigned int rowSizeBytes = 
sizeof( double ) * nCols;
 
 1110       unsigned int row = 0;
 
 1111       unsigned int col = 0;      
 
 1113       boost::scoped_array< double > bufMagRow0Handler( 
new double[ nCols ] );
 
 1114       boost::scoped_array< double > bufMagRow1Handler( 
new double[ nCols ] );
 
 1115       boost::scoped_array< double > bufMagRow2Handler( 
new double[ nCols ] );
 
 1116       boost::scoped_array< double > bufXRow0Handler( 
new double[ nCols ] );
 
 1117       boost::scoped_array< double > bufXRow1Handler( 
new double[ nCols ] );
 
 1118       boost::scoped_array< double > bufXRow2Handler( 
new double[ nCols ] );
 
 1119       boost::scoped_array< double > bufYRow0Handler( 
new double[ nCols ] );
 
 1120       boost::scoped_array< double > bufYRow1Handler( 
new double[ nCols ] );
 
 1121       boost::scoped_array< double > bufYRow2Handler( 
new double[ nCols ] );
 
 1130       double* bufferMag[ 3 ];
 
 1131       double* bufferX[ 3 ];
 
 1132       double* bufferY[ 3 ];
 
 1133       bufferMag[ 0 ] = bufMagRow0Handler.get();
 
 1134       bufferMag[ 1 ] = bufMagRow1Handler.get();
 
 1135       bufferMag[ 2 ] = bufMagRow2Handler.get();
 
 1142       bufferX[ 0 ] = bufXRow0Handler.get();
 
 1143       bufferX[ 1 ] = bufXRow1Handler.get();
 
 1144       bufferX[ 2 ] = bufXRow2Handler.get();
 
 1145       bufferY[ 0 ] = bufYRow0Handler.get();
 
 1146       bufferY[ 1 ] = bufYRow1Handler.get();
 
 1147       bufferY[ 2 ] = bufYRow2Handler.get();
 
 1153       memcpy( bufferMag[ 1 ], iBufMag[ paramsPtr->
m_firstRowIdx - 1 ], 
 
 1155       memcpy( bufferMag[ 2 ], iBufMag[ paramsPtr->
m_firstRowIdx ], 
 
 1168       memcpy( bufferX[ 1 ], iBufX[ paramsPtr->
m_firstRowIdx - 1 ], 
 
 1173       memcpy( bufferY[ 1 ], iBufY[ paramsPtr->
m_firstRowIdx - 1 ], 
 
 1180       const unsigned int rowsBound = paramsPtr->
m_lastRowIdx + 2;
 
 1181       const unsigned int colsBound = nCols - 4;
 
 1184       double centerDiffX = 0;
 
 1185       double centerDiffY = 0;
 
 1188       double centerMag = 0;
 
 1189       double newCenterX = 0;
 
 1190       double newCenterY = 0;
 
 1192       unsigned int prevRow = 0;
 
 1193       unsigned int prevCol = 0;
 
 1194       unsigned int nextCol = 0;
 
 1195       double currentIterationResidue = 0;
 
 1196       double validNeigborsNumber = 0.0;
 
 1198       boost::scoped_array< double > outRowMagBuffHandler( 
new double[ nCols ] );
 
 1199       double* outRowMagBuff = outRowMagBuffHandler.get();      
 
 1201       boost::scoped_array< double > outRowXBuffHandler( 
new double[ nCols ] );
 
 1202       double* outRowXBuff = outRowXBuffHandler.get();
 
 1204       boost::scoped_array< double > outRowYBuffHandler( 
new double[ nCols ] );
 
 1205       double* outRowYBuff = outRowYBuffHandler.get();
 
 1207       for( row = ( paramsPtr->
m_firstRowIdx + 1 ) ; row < rowsBound ; ++row )
 
 1223         rowPtr = bufferMag[ 0 ];
 
 1224         bufferMag[ 0 ] = bufferMag[ 1 ];
 
 1225         bufferMag[ 1 ] = bufferMag[ 2 ];
 
 1226         bufferMag[ 2 ] = rowPtr;        
 
 1228         rowPtr = bufferX[ 0 ];
 
 1229         bufferX[ 0 ] = bufferX[ 1 ];
 
 1230         bufferX[ 1 ] = bufferX[ 2 ];
 
 1231         bufferX[ 2 ] = rowPtr;
 
 1233         rowPtr = bufferY[ 0 ];
 
 1234         bufferY[ 0 ] = bufferY[ 1 ];
 
 1235         bufferY[ 1 ] = bufferY[ 2 ];
 
 1236         bufferY[ 2 ] = rowPtr;       
 
 1243         memcpy( bufferMag[ 2 ], iBufMag[ row ], rowSizeBytes );
 
 1244         memcpy( bufferX[ 2 ], iBufX[ row ], rowSizeBytes );
 
 1245         memcpy( bufferY[ 2 ], iBufY[ row ], rowSizeBytes );        
 
 1250         for( col = 4 ; col < colsBound ; ++col )
 
 1258           centerMag = bufferMag[ 1 ][ col ];
 
 1259           centerX = bufferX[ 1 ][ col ];
 
 1260           centerY = bufferY[ 1 ][ col ];
 
 1262           validNeigborsNumber = 0.0;
 
 1275           if( validNeigborsNumber != 0.0 )
 
 1277             newCenterX /= validNeigborsNumber;
 
 1278             newCenterY /= validNeigborsNumber;
 
 1280             newCenterX = ( newCenterX * diffusionRegularization ) +
 
 1281               ( centerX * complementDiffReg );
 
 1282             newCenterY = ( newCenterY * diffusionRegularization ) +
 
 1283               ( centerY * complementDiffReg );
 
 1285             centerDiffX = centerX - newCenterX;
 
 1286             centerDiffY = centerY - newCenterY;
 
 1288             if( centerDiffX != 0.0 )
 
 1290               if( centerX == 0.0 )
 
 1292                 currentIterationResidue = std::max( currentIterationResidue, 1.0 );
 
 1296                 currentIterationResidue = 
 
 1298                     currentIterationResidue
 
 1300                     std::abs( centerDiffX / centerX )
 
 1305             if( centerDiffY != 0.0 )
 
 1307               if( centerY == 0.0 )
 
 1309                 currentIterationResidue = std::max( currentIterationResidue, 1.0 );
 
 1313                 currentIterationResidue = 
 
 1315                     currentIterationResidue
 
 1317                     std::abs( centerDiffY / centerY )
 
 1322             outRowXBuff[ col ] = newCenterX;
 
 1323             outRowYBuff[ col ] = newCenterY;    
 
 1324             outRowMagBuff[ col ] = std::sqrt( ( newCenterX * newCenterX ) + ( newCenterY *
 
 1329             outRowXBuff[ col ] = centerX;
 
 1330             outRowYBuff[ col ] = centerY;    
 
 1331             outRowMagBuff[ col ] = centerMag;
 
 1339         memcpy( oMagBuf[ prevRow ], outRowMagBuff, rowSizeBytes );
 
 1340         memcpy( oBufX[ prevRow ], outRowXBuff, rowSizeBytes );
 
 1341         memcpy( oBufY[ prevRow ], outRowYBuff, rowSizeBytes );
 
 1343         oMagBuf[ prevRow ][ 0 ] = iBufMag[ 1 ][ 0 ];
 
 1344         oMagBuf[ prevRow ][ 1 ] = iBufMag[ 1 ][ 1 ];
 
 1345         oMagBuf[ prevRow ][ 2 ] = iBufMag[ 1 ][ 2 ];
 
 1346         oMagBuf[ prevRow ][ 3 ] = iBufMag[ 1 ][ 3 ];
 
 1347         oMagBuf[ prevRow ][ colsBound ] = iBufMag[ 1 ][ colsBound ];
 
 1348         oMagBuf[ prevRow ][ colsBound + 1 ] = iBufMag[ 1 ][ colsBound + 1 ];
 
 1349         oMagBuf[ prevRow ][ colsBound + 2 ] = iBufMag[ 1 ][ colsBound + 2 ];
 
 1350         oMagBuf[ prevRow ][ colsBound + 3 ] = iBufMag[ 1 ][ colsBound + 3 ];        
 
 1352         oBufX[ prevRow ][ 0 ] = bufferX[ 1 ][ 0 ];
 
 1353         oBufX[ prevRow ][ 1 ] = bufferX[ 1 ][ 1 ];
 
 1354         oBufX[ prevRow ][ 2 ] = bufferX[ 1 ][ 2 ];
 
 1355         oBufX[ prevRow ][ 3 ] = bufferX[ 1 ][ 3 ];
 
 1356         oBufX[ prevRow ][ colsBound ] = bufferX[ 1 ][ colsBound ];
 
 1357         oBufX[ prevRow ][ colsBound + 1 ] = bufferX[ 1 ][ colsBound + 1 ];
 
 1358         oBufX[ prevRow ][ colsBound + 2 ] = bufferX[ 1 ][ colsBound + 2 ];
 
 1359         oBufX[ prevRow ][ colsBound + 3 ] = bufferX[ 1 ][ colsBound + 3 ];
 
 1361         oBufY[ prevRow ][ 0 ] = bufferY[ 1 ][ 0 ];
 
 1362         oBufY[ prevRow ][ 1 ] = bufferY[ 1 ][ 1 ];
 
 1363         oBufY[ prevRow ][ 2 ] = bufferY[ 1 ][ 2 ];
 
 1364         oBufY[ prevRow ][ 3 ] = bufferY[ 1 ][ 3 ];
 
 1365         oBufY[ prevRow ][ colsBound ] = bufferY[ 1 ][ colsBound ];
 
 1366         oBufY[ prevRow ][ colsBound + 1 ] = bufferY[ 1 ][ colsBound + 1 ];
 
 1367         oBufY[ prevRow ][ colsBound + 2 ] = bufferY[ 1 ][ colsBound + 2 ];
 
 1368         oBufY[ prevRow ][ colsBound + 3 ] = bufferY[ 1 ][ colsBound + 3 ];
 
 1372           currentIterationResidue );
 
 1393       if( ! skelMap.
reset( nRows,nCols ) )
 
 1396       const unsigned int lastRowIdx = nRows - 1;
 
 1397       const unsigned int lastColIdx = nCols - 1;        
 
 1398       unsigned int row = 0;
 
 1399       unsigned int col = 0;  
 
 1400       unsigned int nextRow = 0;
 
 1401       unsigned int nextCol = 0;
 
 1402       unsigned int prevRow = 0;
 
 1403       unsigned int prevCol = 0;       
 
 1411       double strength = 0;
 
 1412       double minStrength = DBL_MAX;
 
 1413       double maxStrength = -1.0 * DBL_MAX;
 
 1415       for( row = 0 ; row < nRows ; ++row )
 
 1417         skelMap[ row ][ 0 ] = 0;
 
 1418         skelMap[ row ][ lastColIdx ] = 0;        
 
 1421       for( col = 0 ; col < nCols ; ++col )
 
 1423         skelMap[ 0 ][ col ] = 0;
 
 1424         skelMap[ lastRowIdx ][ col ] = 0;
 
 1427       for( row = 1 ; row < lastRowIdx ; ++row )
 
 1432         for( col = 1 ; col < lastColIdx ; ++col )
 
 1437           centerX = inputX[ row ][ col ];
 
 1438           centerY = inputY[ row ][ col ];
 
 1452           strength = std::max( 0.0, strength );
 
 1454           skelMap[ row ][ col ] = strength;
 
 1456           if( minStrength > strength ) minStrength = strength;
 
 1457           if( maxStrength < strength ) maxStrength = strength;
 
 1461       const double gain = ( minStrength == maxStrength ) ? 0.0 : 
 
 1462         ( 1.0 / ( maxStrength - minStrength ) );
 
 1464       for( row = 1 ; row < lastRowIdx ; ++row )
 
 1466         for( col = 1 ; col < lastColIdx ; ++col )
 
 1468           strength = skelMap[ row ][ col ];
 
 1469           strength -= minStrength;
 
 1471           strength = ( strength + ( 1.0 - edgeStrengthMap[ row ][ col ] ) ) / 2.0;
 
 1472           skelMap[ row ][ col ] = strength;
 
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. 
 
const OutputParameters & operator=(const OutputParameters ¶ms)
 
Skeleton::InputParameters m_inputParameters
Input execution parameters. 
 
#define DIFFUSENEIGHBOR(neighborRow, neighborCol)
 
bool applyVecDiffusion(const te::rp::Matrix< double > &inputX, const te::rp::Matrix< double > &inputY, te::rp::Matrix< double > const *const backgroundDataPtr, te::common::TaskProgress *progressPtr, te::rp::Matrix< double > &outputX, te::rp::Matrix< double > &outputY) const 
Apply a vector diffusion over the given vector field. 
 
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
The generated output registered raster. 
 
double m_diffusionRegularization
The diffusion regularization parameter. 
 
AbstractParameters * clone() const 
Create a clone copy of this instance. 
 
unsigned int m_firstRowIdx
First row to process. 
 
static void applyVecDiffusionThreadEntry(ApplyVecDiffusionThreadParams *paramsPtr)
Vector diffusion thread entry. 
 
te::rst::Raster const * m_inputMaskRasterPtr
A pointer to an input raster (where pixels with zero velues will be ignored) or an null pointer if no...
 
Blue channel color interpretation. 
 
unsigned int getNumberOfRows() const 
Returns the raster number of rows. 
 
unsigned int m_lastRowIdx
Last row to process. 
 
bool applyMeanSmooth(const te::rp::Matrix< MatrixElementT > &input, te::rp::Matrix< MatrixElementT > &output) const 
Apply a mean filter. 
 
double m_diffusionRegularization
A regularization parameter to control the variation from one iteration to the next one (higher values...
 
Raster Processing functions. 
 
AbstractParameters * clone() const 
Create a clone copy of this instance. 
 
te::rp::Matrix< double > const * m_inputMagBufPtr
A pointer to the input magnitude buffer. 
 
void clear()
Clear all allocated resources and go back to the initial default parameters. 
 
const InputParameters & operator=(const InputParameters ¶ms)
 
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
 
te::rp::Matrix< double > * m_outputMagBufPtr
A pointer to the output magnitude buffer. 
 
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state. 
 
Grid * getGrid()
It returns the raster grid. 
 
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. 
 
double * m_currentIterationResiduePtr
A pointer the the current iteration residue;. 
 
static Raster * make()
It creates and returns an empty raster with default raster driver. 
 
unsigned int getLinesNumber() const 
The number of current matrix lines. 
 
te::rp::Matrix< double > const * m_inputBufYPtr
A pointer to the input buffer Y component. 
 
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value. 
 
unsigned int GetPhysProcNumber()
Returns the number of physical processors. 
 
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
#define SKELSTRENGTHNEIGHBOR(neighborRow, neighborCol)
 
Skeleton output parameters. 
 
bool m_enableMultiThread
Enable (true) the use of threads. 
 
#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...
 
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. 
 
Red channel color interpretation. 
 
Abstract parameters base interface. 
 
A raster band description. 
 
A rectified grid is the spatial support for raster data. 
 
te::rst::Raster const * m_inputRasterPtr
Input raster. 
 
boost::mutex * m_mutexPtr
A pointer to the sync mutex. 
 
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ). 
 
te::rp::Matrix< double > * m_outputBufXPtr
A pointer to the output buffer X component. 
 
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. 
 
te::rp::Matrix< double > const * m_initialYBufPtr
A pointer to the input buffer initial Y component. 
 
te::rp::Matrix< double > const * m_inputBufXPtr
A pointer to the input buffer X component. 
 
bool isInitialized() const 
Returns true if the algorithm instance is initialized and ready for execution. 
 
bool m_enableProgress
Enable/Disable the progress interface (default:false). 
 
unsigned int getNumberOfColumns() const 
Returns the raster number of columns. 
 
const Algorithm & operator=(const Algorithm &)
 
unsigned int m_diffusionMaxIterations
The maximum number of iterations to perform (zero: no iterations limit). 
 
Skeleton input parameters. 
 
A raster band description. 
 
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not. 
 
unsigned int getColumnsNumber() const 
The number of current matrix columns. 
 
double m_skeletonThreshold
A threshold to select those pixels as being part of the final skeleton - valid range [0...
 
Raster Processing algorithm output parameters base interface. 
 
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution. 
 
void reset()
Reset (clear) the active instance data. 
 
bool m_isInitialized
Tells if this instance is initialized. 
 
Creation of skeleton imagems. 
 
BandProperty * getProperty()
Returns the band property. 
 
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band. 
 
This class can be used to inform the progress of a task. 
 
unsigned int m_inputRasterBand
Bands to process from the input raster. 
 
bool loadData(te::rp::Matrix< double > &rasterData) const 
Load data from the input raster. 
 
te::rp::Matrix< double > * m_outputBufYPtr
A pointer to the output buffer X component. 
 
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters. 
 
Index into a lookup table. 
 
Green channel color interpretation. 
 
double m_diffusionThreshold
A threshold over the residue from one iteration to another, if the residue drops below this value the...
 
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory). 
 
te::common::AccessPolicy getAccessPolicy() const 
Returns the raster access policy. 
 
Raster Processing algorithm input parameters base interface. 
 
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. 
 
bool getEdgeStrengthMap(const te::rp::Matrix< double > &inputMap, te::rp::Matrix< double > &edgeStrengthMap) const 
Create an Edge strenght Map from the input data.