Skip to content
Snippets Groups Projects
Commit 48056a4e authored by Marina Bertolino's avatar Marina Bertolino
Browse files

ENH: move up the exception

parent d79c7366
No related branches found
No related tags found
No related merge requests found
...@@ -272,43 +272,42 @@ void ClassKMeansBase::CreateOutMeansFile(FloatVectorImageType *image, ...@@ -272,43 +272,42 @@ void ClassKMeansBase::CreateOutMeansFile(FloatVectorImageType *image,
unsigned int nbElements = nbClasses * nbBands; unsigned int nbElements = nbClasses * nbBands;
// get the line in model file that contains the centroids positions // get the line in model file that contains the centroids positions
std::ifstream infile(modelFileName); std::ifstream infile(modelFileName);
if(infile) if(!infile)
{ {
// get the end line with the centroids itkExceptionMacro(<< "File : " << modelFileName << " couldn't be opened");
std::string line, centroidLine; }
while(!infile.eof())
{ // get the end line with the centroids
std::getline(infile,line); std::string line, centroidLine;
if (!line.empty()) while(!infile.eof())
centroidLine = line; {
} std::getline(infile,line);
if (!line.empty())
centroidLine = line;
}
std::vector<std::string> centroidElm; std::vector<std::string> centroidElm;
boost::split(centroidElm,centroidLine,boost::is_any_of(" ")); boost::split(centroidElm,centroidLine,boost::is_any_of(" "));
// remove the first elements, not the centroids positions // remove the first elements, not the centroids positions
int nbWord = centroidElm.size(); int nbWord = centroidElm.size();
int beginCentroid = nbWord-nbElements; int beginCentroid = nbWord-nbElements;
centroidElm.erase(centroidElm.begin(), centroidElm.begin()+beginCentroid); centroidElm.erase(centroidElm.begin(), centroidElm.begin()+beginCentroid);
// write in the output file // write in the output file
std::ofstream outfile; std::ofstream outfile;
outfile.open(GetParameterString("outmeans")); outfile.open(GetParameterString("outmeans"));
for (unsigned int i = 0; i < nbClasses; i++) for (unsigned int i = 0; i < nbClasses; i++)
{
for (unsigned int j = 0; j < nbBands; j++)
{ {
for (unsigned int j = 0; j < nbBands; j++) outfile << std::setw(8) << centroidElm[i * nbBands + j] << " ";
{
outfile << std::setw(8) << centroidElm[i * nbBands + j] << " ";
}
outfile << std::endl;
} }
outfile.close(); outfile << std::endl;
}
else
{
itkExceptionMacro(<< "File : " << modelFileName << " couldn't be opened");
} }
outfile.close();
infile.close(); infile.close();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment