From: tbaudier Date: Fri, 9 Mar 2018 10:49:15 +0000 (+0100) Subject: Add saveAs function to save a text file in clitkHistogramImage X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f33eadb6cb9660c3ec2c1a558fe6b59dc145f018;p=clitk.git Add saveAs function to save a text file in clitkHistogramImage --- diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a050ba8..606027e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -62,11 +62,14 @@ if(CLITK_BUILD_TOOLS) target_link_libraries(clitkBinarizeImage clitkBinarizeImageLib clitkCommon) set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBinarizeImage) - add_executable(clitkProfileImage clitkProfileImage.cxx) target_link_libraries(clitkProfileImage clitkProfileImageLib clitkCommon) set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkProfileImage) + add_executable(clitkHistogramImage clitkHistogramImage.cxx) + target_link_libraries(clitkHistogramImage clitkHistogramImageLib clitkCommon) + set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkHistogramImage) + WRAP_GGO(clitkVFResample_GGO_C clitkVFResample.ggo) add_executable(clitkVFResample clitkVFResample.cxx clitkVFResampleGenericFilter.cxx ${clitkVFResample_GGO_C}) target_link_libraries(clitkVFResample clitkCommon) diff --git a/tools/clitkHistogramImage.cxx b/tools/clitkHistogramImage.cxx index 0cb5ac9..d853abf 100644 --- a/tools/clitkHistogramImage.cxx +++ b/tools/clitkHistogramImage.cxx @@ -35,6 +35,7 @@ int main(int argc, char * argv[]) filter->SetArgsInfo(args_info); CLITK_TRY_CATCH_EXIT(filter->Update()); + filter->SaveAs(); return EXIT_SUCCESS; } // This is the end, my friend diff --git a/tools/clitkHistogramImageGenericFilter.cxx b/tools/clitkHistogramImageGenericFilter.cxx index 49e3fa0..f93f213 100644 --- a/tools/clitkHistogramImageGenericFilter.cxx +++ b/tools/clitkHistogramImageGenericFilter.cxx @@ -130,7 +130,10 @@ HistogramImageGenericFilter::UpdateWithInputImageType() //compute bin number typedef typename HistogramFilterType::HistogramSizeType SizeType; SizeType binNumber(1); - mBinSize = std::log(range); + if (!mArgsInfo.size_given) + mBinSize = std::log(range); + if (mBinSize == 0) + mBinSize = 1; binNumber[0] = (int)(range/mBinSize); if (binNumber[0] == 0) binNumber[0] = 1; @@ -159,6 +162,31 @@ HistogramImageGenericFilter::UpdateWithInputImageType() } //-------------------------------------------------------------------- +//------------------------------------------------------------------------------ +void HistogramImageGenericFilter::SaveAs() +{ + // Output + std::string textFileName = GetOutputFilename(); + ofstream fileOpen(textFileName.c_str(), std::ofstream::trunc); + + if(!fileOpen) { + cerr << "Error during saving" << endl; + return; + } + + int i(0); + fileOpen << "Value represents the number of voxels around the corresponding intensity (by default the windows size around intensity is log(range))" << endl; + fileOpen << "Intensity" << "\t" << "Value" << endl; + + while (iGetNumberOfTuples()) { + fileOpen << mArrayX->GetTuple(i)[0] << "\t" << mArrayY->GetTuple(i)[0] << endl; + ++i; + } + + fileOpen.close(); +} +//------------------------------------------------------------------------------ + }//end clitk diff --git a/tools/clitkHistogramImageGenericFilter.h b/tools/clitkHistogramImageGenericFilter.h index d963fbc..999eda9 100644 --- a/tools/clitkHistogramImageGenericFilter.h +++ b/tools/clitkHistogramImageGenericFilter.h @@ -52,6 +52,9 @@ namespace clitk void SetArgsInfo(const args_info_type & a); void SetSizeBin (const double size); + // Save the histogram to txt file + void SaveAs(); + //-------------------------------------------------------------------- // Main function called each time the filter is updated template