diff --git a/app/otbLSGRM.cxx b/app/otbLSGRM.cxx index ce21bc7787ba2554765b0421de316cef28f04e5f..72d45406ffff434fedc33997ef6a0cb4fd3766c3 100644 --- a/app/otbLSGRM.cxx +++ b/app/otbLSGRM.cxx @@ -112,8 +112,17 @@ private: AddChoice("tiling.none", "No tiling layout"); AddParameter(ParameterType_Int, "memory", "Restrict memory use (mb)"); - MandatoryOff("memory"); + + AddParameter(ParameterType_Bool, "resume", "Activate resume mode"); + SetDefaultParameterBool("resume", false); + AddParameter(ParameterType_Int, "resume.tilerow", "Starting tile row in resume mode"); + AddParameter(ParameterType_Int, "resume.tilecol", "Starting tile column in resume mode"); + SetDefaultParameterInt("resume.tilerow", 0); + SetDefaultParameterInt("resume.tilecol", 0); + //MandatoryOff("resume"); + //MandatoryOff("resume.tilex"); + //MandatoryOff("resume.tiley"); } void DoUpdateParameters() @@ -224,6 +233,12 @@ private: otbAppLogINFO("Setting maximum memory to " << GetParameterInt("memory") << " MBytes"); controller->SetInternalMemoryAvailable(GetParameterInt("memory")); } + + // Resume mode? + if (GetParameterBool("resume")) + { + controller.SetResumingMode(GetParameterInt("resume.tilerow"),GetParameterInt("resume.tilecol")); + } // Run the segmentation controller->RunSegmentation(); diff --git a/include/lsgrmController.h b/include/lsgrmController.h index e538cbe9a596e2fc20c6075db87077d1453b2da9..85bdec77eaaa2a0c8414067d15eb6a621cc309bb 100644 --- a/include/lsgrmController.h +++ b/include/lsgrmController.h @@ -44,6 +44,9 @@ public: void SetSpecificParameters(const SegmentationParameterType& params); void SetInputImage(ImageType * inputImage); void SetInternalMemoryAvailable(long long unsigned int v); // expecting a value in Mbytes. + + void SetResumingMode(unsigned int rRow, unsigned int rCol); + void StopResumingMode(); /* Accessors */ void SetTilingModeNone(){m_TilingMode = LSGRM_TILING_NONE; Modified();}; @@ -114,6 +117,10 @@ private: unsigned int m_NumberOfFirstIterations; // number of iterations in the first step unsigned int m_TileWidth; // regular tile width (i.e. not left tiles) unsigned int m_TileHeight; // regular tile height (i.e. not bottom tiles) + bool m_Resuming; // True if in resuming mode + unsigned int m_ResumeTileRow; // X index of starting tile in resume mode + unsigned int m_ResumeTileCol; // Y index of starting tile in resume mode + /* read-only variables */ LSGRMTilingMode m_TilingMode; // tiling mode (none/user/auto) diff --git a/include/lsgrmController.txx b/include/lsgrmController.txx index aa645f79cb84d21d1e82d6750d754d082ecca8cb..bfd630edc554bc1f60c3884ccf3d6dc18fc5920b 100644 --- a/include/lsgrmController.txx +++ b/include/lsgrmController.txx @@ -18,6 +18,9 @@ Controller<TSegmenter>::Controller() m_NbTilesY = 0; m_Threshold = 75; m_Memory = 0; + m_Resuming = false; + m_ResumeTileRow = 0; + m_ResumeTileCol = 0; } @@ -122,7 +125,12 @@ void Controller<TSegmenter>::RunSegmentation() m_InputImage->GetLargestPossibleRegion().GetSize()[0], m_InputImage->GetLargestPossibleRegion().GetSize()[1], m_InputImage->GetNumberOfComponentsPerPixel(), - isFusion); + isFusion, + m_Resuming, + m_ResumeTileRow, + m_ResumeTileCol); + + if (m_Resuming) StopResumingMode(); #ifdef OTB_USE_MPI GatherUsefulVariables(accumulatedMemory, isFusion); @@ -461,5 +469,13 @@ std::vector<std::string> Controller<TSegmenter>::GetTemporaryFilesList() return list; } +template<class TSegmenter> +void Controller<TSegmenter>::SetResumingMode(unsigned int rX, unsigned int rY) +{ + m_Resuming = true; + m_ResumeTileX = rx; + m_ResumeTileY = ry; +} + } // end of namespace lsgrm #endif diff --git a/include/lsgrmGraphOperations.h b/include/lsgrmGraphOperations.h index 3ce66f2d87d3ce5589f312e41a1ceb68fa43926f..c8faa4d45b85238bd9d469547cfe748b785fc124 100644 --- a/include/lsgrmGraphOperations.h +++ b/include/lsgrmGraphOperations.h @@ -68,7 +68,10 @@ long long unsigned int RunPartialSegmentation( const unsigned int imageWidth, const unsigned int imageHeight, const unsigned int imageBands, - bool& isFusion); + bool& isFusion, + bool resume = false, + unsigned int rRow = 0, + unsigned int rCol = 0); template<class TSegmenter> void RemoveUselessNodes(ProcessingTile& tile, diff --git a/include/lsgrmGraphOperations.txx b/include/lsgrmGraphOperations.txx index d2094771191aa3a9c7811ea4cbb7979b59c2a7fc..71fd3e89a23e6277e096d7d2ab5aa8fda40badbe 100644 --- a/include/lsgrmGraphOperations.txx +++ b/include/lsgrmGraphOperations.txx @@ -138,7 +138,10 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::ParamTy const unsigned int imageWidth, const unsigned int imageHeight, const unsigned int imageBands, - bool& isFusion) + bool& isFusion, + bool resume, + unsigned int rRow, + unsigned int rCol) { long long unsigned int accumulatedMemory = 0; isFusion = false; @@ -155,6 +158,18 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::ParamTy if (MyTurn(row*nbTilesX + col)) #endif { + // If resume mode, get accumulated memory on previous tiles + if (resume && (row*nbTilesX+col) < (rRow*nbTilesX+rCol) ) { + // Load the graph + std::cout << "\tResuming graph..." << std::endl; + TSegmenter segmenter; + ReadGraph<TSegmenter>(segmenter.m_Graph, currentTile.nodeFileName, currentTile.edgeFileName); + // Retrieve the amount of memory to store this graph + std::cout << "\tGet graph memory..." << std::endl; + accumulatedMemory += segmenter.GetGraphMemory(); + continue; + } + // Get the current tile std::cout << "Processing tile " << row << ", " << col << std::endl; ProcessingTile currentTile = tiles[row*nbTilesX + col];