diff --git a/app/otbLSGRM.cxx b/app/otbLSGRM.cxx index c1601ae051046bdb2941837fcb72e793097619ee..af745e7791f0c6bca2f501174ab7bd56e8147818 100644 --- a/app/otbLSGRM.cxx +++ b/app/otbLSGRM.cxx @@ -120,9 +120,9 @@ private: AddParameter(ParameterType_Int, "resumetilecol", "Starting tile column in resume mode"); SetDefaultParameterInt("resumetilerow", 0); SetDefaultParameterInt("resumetilecol", 0); - //MandatoryOff("resume"); - //MandatoryOff("resume.tilex"); - //MandatoryOff("resume.tiley"); + MandatoryOff("resume"); + MandatoryOff("resumetilerow"); + MandatoryOff("resumetilecol"); } void DoUpdateParameters() diff --git a/include/lsgrmController.txx b/include/lsgrmController.txx index aabbae23b1b581b799f6d1dcc78bb29c78f69641..e1c46ef9c3df178c91300efbe377a82827a5fdca 100644 --- a/include/lsgrmController.txx +++ b/include/lsgrmController.txx @@ -95,7 +95,6 @@ void Controller<TSegmenter>::RunSegmentation() // temp. patch, maybe calculate real current memory after resuming graphs. long long unsigned int accumulatedMemory = 2 * m_Memory; - if (!m_Resuming) { accumulatedMemory = RunFirstPartialSegmentation<TSegmenter>( m_InputImage, m_SpecificParameters, @@ -107,10 +106,8 @@ void Controller<TSegmenter>::RunSegmentation() m_NbTilesY, m_TileWidth, m_TileHeight, - isFusion); - } else { - isFusion = true; - } + isFusion, + m_Resuming); #ifdef OTB_USE_MPI GatherUsefulVariables(accumulatedMemory, isFusion); diff --git a/include/lsgrmGraphOperations.txx b/include/lsgrmGraphOperations.txx index 9bbb6a7e5de3799066b8901da9b1b62369428c27..15e8afcd2670445cee1aecf6e5f5be6a27e08470 100644 --- a/include/lsgrmGraphOperations.txx +++ b/include/lsgrmGraphOperations.txx @@ -2,11 +2,18 @@ #define __LSGRM_GRAPH_OPERATIONS_TXX //#include "lsgrmGraphOperations.h" //#include <unistd.h> +#include <fstream> #include <cstdio> namespace lsgrm { +bool file_exists(const std::string& fileName) +{ + std::ifstream infile(fileName.c_str()); + return infile.good(); +} + template<class TSegmenter> typename TSegmenter::ImageType::Pointer ReadImageRegion( typename TSegmenter::ImageType * inputPtr, @@ -640,7 +647,8 @@ long long unsigned int RunFirstPartialSegmentation( const unsigned int nbTilesY, const unsigned int tileWidth, const unsigned int tileHeight, - bool& isFusion) + bool& isFusion, + bool resume) { using ImageType = typename TSegmenter::ImageType; @@ -664,6 +672,19 @@ long long unsigned int RunFirstPartialSegmentation( { // Reading images ProcessingTile currentTile = tiles[row*nbTilesX + col]; + + if (resume && file_exists(currentTile.nodeFileName) && file_exists(currentTile.edgeFileName)) + { + 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(); + if(segmenter.GetComplete() == false) + isFusion = true; + continue; + } std::cout << "Processing tile " << (row*nbTilesX + col) << " / " << (nbTilesX*nbTilesY) << " (" << col << ", " << row << ")" <<