Commit bb65d2e0 authored by remicres's avatar remicres
Browse files

REFAC: functions use ProcesingTiles instead of many numeric and string variables

Showing with 121 additions and 399 deletions
+121 -399
......@@ -49,13 +49,12 @@ public:
typename LabelImageType::Pointer GetLabeledClusteredOutput();
itkGetMacro(Margin, unsigned int);
itkGetMacro(TemporaryFilesList, std::vector<std::string>);
itkGetMacro(CleanTemporaryDirectory, bool);
itkSetMacro(CleanTemporaryDirectory, bool);
itkGetMacro(CleanTemporaryFiles, bool);
itkSetMacro(CleanTemporaryFiles, bool);
itkGetMacro(TemporaryDirectory, std::string);
itkSetMacro(TemporaryDirectory, std::string);
itkGetMacro(TemporaryFilesPrefix, std::string);
itkSetMacro(TemporaryFilesPrefix, std::string);
itkGetMacro(Threshold, float);
itkSetMacro(Threshold, float);
......@@ -94,8 +93,8 @@ private:
long unsigned int GetMaximumNumberOfNodesInMemory();
/* Parameters given by the user */
std::string m_TemporaryDirectory; // Directory used to store intermediate files during the process.
bool m_CleanTemporaryDirectory; // Clean the temporary directory.
std::string m_TemporaryFilesPrefix; // Path used to store intermediate files during the process.
bool m_CleanTemporaryFiles; // Clean temporary files
ImageType * m_InputImage; // Input image
/* Segmentation parameters */
......@@ -117,7 +116,6 @@ private:
LSGRMTilingMode m_TilingMode; // tiling mode (none/user/auto)
unsigned int m_Margin; // stability margin related to m_NumberOfFirstIterations
std::vector<ProcessingTile> m_Tiles; // list of tiles
std::vector<std::string> m_TemporaryFilesList; // list of temporary files
typename LabelImageType::Pointer m_LabelImage; // output label image
};
} // end of namespace lsgrm
......
......@@ -14,7 +14,7 @@ Controller<TSegmenter>::Controller()
m_TileWidth = 0;
m_NbTilesX = 0;
m_NbTilesY = 0;
m_CleanTemporaryDirectory = true;
m_CleanTemporaryFiles = true;
m_Threshold = 75;
m_Memory = 0;
}
......@@ -53,8 +53,8 @@ void Controller<TSegmenter>::RunSegmentation()
"\n\tTiling layout: " << m_NbTilesX << " x " << m_NbTilesY << std::endl;
// Compute the splitting scheme
SplitOTBImage<ImageType>(m_InputImage, m_TileWidth, m_TileHeight, m_Margin,
m_NbTilesX, m_NbTilesY, m_Tiles);
m_Tiles = SplitOTBImage<ImageType>(m_InputImage, m_TileWidth, m_TileHeight, m_Margin,
m_NbTilesX, m_NbTilesY, m_TemporaryFilesPrefix);
// Boolean indicating if there are remaining fusions
bool isFusion = false;
......@@ -72,9 +72,7 @@ void Controller<TSegmenter>::RunSegmentation()
m_NbTilesY,
m_TileWidth,
m_TileHeight,
m_TemporaryDirectory,
isFusion);
// long long unsigned int accumulatedMemory = 19373051714;
// Update the given number of iterations
numberOfIterationsRemaining -= m_NumberOfFirstIterations;
......@@ -96,7 +94,6 @@ void Controller<TSegmenter>::RunSegmentation()
m_Threshold,
numberOfIterationsForPartialSegmentations,
m_Tiles,
m_TemporaryDirectory,
m_NbTilesX,
m_NbTilesY,
m_InputImage->GetLargestPossibleRegion().GetSize()[0],
......@@ -127,7 +124,6 @@ void Controller<TSegmenter>::RunSegmentation()
m_SpecificParameters,
m_Threshold,
m_Tiles,
m_TemporaryDirectory,
m_NbTilesX,
m_NbTilesY,
m_InputImage->GetLargestPossibleRegion().GetSize()[0],
......@@ -176,7 +172,7 @@ unsigned int Controller<TSegmenter>::GetNodeMemory()
lsrm::GraphOperations<TSegmenter>::InitNodes(onePixelImage,segmenter,FOUR);
unsigned int memory = segmenter.GetGraphMemory() / (n*n);
itkWarningMacro(<<"Size of a node is " << memory);
itkDebugMacro(<<"Size of a node is " << memory);
return memory;
}
......@@ -198,7 +194,8 @@ long unsigned int Controller<TSegmenter>::GetMaximumNumberOfNodesInMemory()
}
template<class TSegmenter>
void Controller<TSegmenter>::ComputeMaximumStabilityMargin(unsigned int width,
void
Controller<TSegmenter>::ComputeMaximumStabilityMargin(unsigned int width,
unsigned int height, unsigned int &niter, unsigned int &margin)
{
itkDebugMacro(<< "Computing maximum stability margin");
......@@ -331,7 +328,7 @@ void Controller<TSegmenter>::GetAutomaticConfiguration()
long long unsigned int memoryUsed = GetNodeMemory();
memoryUsed *= static_cast<long long unsigned int>(m_TileHeight + 2*m_Margin);
memoryUsed *= static_cast<long long unsigned int>(m_TileWidth + 2*m_Margin);
itkWarningMacro(<< "An amount of " << memoryUsed/(1024.0*1024.0) << " Mbytes of RAM will be used for regular tiles of size "
itkDebugMacro(<< "An amount of " << memoryUsed/(1024.0*1024.0) << " Mbytes of RAM will be used for regular tiles of size "
<< (m_TileWidth + 2*m_Margin) << "x" << (m_TileHeight + 2*m_Margin) );
}
......
......@@ -16,6 +16,12 @@ struct ProcessingTile
long int tileNeighbors[8]; // tile Neighbors at (top, top right, right, bottom right, bottom, bottom left, left, top left)
long int margin[4]; // Is there a margin at top, left, bottom or right
otb::VectorImage<double>::RegionType region; // The image region
// Temporary files
std::string nodeFileName;
std::string edgeFileName;
std::string nodeMarginFileName;
std::string edgeMarginFileName;
};
// Read an image region
......@@ -30,7 +36,6 @@ MergeAllGraphsAndAchieveSegmentation(
const typename TSegmenter::ParameterType& params,
const float& threshold,
std::vector<ProcessingTile>& tiles,
const std::string& tmpDir,
const unsigned int nbTilesX,
const unsigned int nbTilesY,
const unsigned int imageWidth,
......@@ -50,7 +55,6 @@ long long unsigned int RunFirstPartialSegmentation(
const unsigned int nbTilesY,
const unsigned int tileWidth,
const unsigned int tileHeight,
const std::string& tmpDir,
bool& isFusion);
template<class TSegmenter>
......@@ -59,7 +63,6 @@ long long unsigned int RunPartialSegmentation(
const float& threshold,
const unsigned int niter,
std::vector<ProcessingTile>& tiles,
const std::string& tmpDir,
const unsigned int nbTilesX,
const unsigned int nbTilesY,
const unsigned int imageWidth,
......@@ -101,9 +104,13 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap,
const unsigned int imageWidth);
template<class TSegmenter>
void InsertNodesFromTile(typename TSegmenter::GraphType& graph,
ProcessingTile& tile, bool margin = true);
template<class TSegmenter>
void AddStabilityMargin(typename TSegmenter::GraphType& graph,
const std::string& tmpDir,
std::vector<ProcessingTile>& tiles,
const unsigned int row,
const unsigned int col,
const unsigned int nbTilesX,
......@@ -134,18 +141,19 @@ void DetectBorderNodes(typename TSegmenter::GraphType& graph,
const unsigned int imageHeight);
template<class TSegmenter>
void ReadGraph(typename TSegmenter::GraphType& graph,
void ReadGraph(TSegmenter& segmenter,
const std::string& nodesPath,
const std::string& edgesPath);
template<class TSegmenter>
void WriteGraph(typename TSegmenter::GraphType& graph,
const std::string& tmpDir,
const unsigned int row,
const unsigned int col);
void ReadGraph(typename TSegmenter::GraphType& graph,
const std::string& nodesPath,
const std::string& edgesPath);
template<class TSegmenter>
long long unsigned int GetGraphMemory(TSegmenter segmenter);
void WriteGraph(typename TSegmenter::GraphType& graph,
const std::string& nodesFile,
const std::string& edgesFile);
template<class TSegmenter>
void RemoveUnstableSegments(typename TSegmenter::GraphType& graph,
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment