diff --git a/CCSeg/CCsegtool.cxx b/CCSeg/CCsegtool.cxx index e0edd4b..12c45a6 100644 --- a/CCSeg/CCsegtool.cxx +++ b/CCSeg/CCsegtool.cxx @@ -54,12 +54,13 @@ int main(int argc, char *argv[]) /* Preview */ if(debug) std::cout<<"INITIALIZE"<SetFileName(segFile.c_str()) ; + binaryImageReader->SetFileName(segFileName.c_str()) ; binaryImageReader->Update(); m_loadMask=binaryImageReader->GetOutput(); } @@ -235,7 +235,7 @@ void CCsegtool_initialization::loadinginputimage(std::string inputFileName, std: /*************************************************************************** * Do a vesselremoval ***************************************************************************/ -void CCsegtool_initialization::vesselremoval(bool segLabel) +void CCsegtool_initialization::vesselremoval(int segLabel) { try { @@ -253,13 +253,10 @@ void CCsegtool_initialization::vesselremoval(bool segLabel) try { //Vessel removal - int seglabel=1; - if(segLabel) - seglabel=0; VesselRemover::Pointer VesselFilter = VesselRemover::New(); VesselFilter->SetImage(m_loadImage); VesselFilter->SetEMSseg(m_castfilter->GetOutput()); - VesselFilter->SetWMlabel(seglabel); + VesselFilter->SetWMlabel(segLabel); VesselFilter->RemoveVessels(); m_preProcImage = VesselFilter->GetResultImage(); } @@ -506,17 +503,14 @@ void CCsegtool_initialization::reflectY() /*************************************************************************** * Extract the Label ***************************************************************************/ -void CCsegtool_initialization::extractLabel(bool segLabel) +void CCsegtool_initialization::extractLabel(int segLabel) { try { - int seglabel=1; - if(segLabel) - seglabel=0; m_threshFilter = BinaryThresholdFilterType::New(); m_threshFilter->SetInput(m_mask); - m_threshFilter->SetUpperThreshold(seglabel); - m_threshFilter->SetLowerThreshold(seglabel); + m_threshFilter->SetUpperThreshold(segLabel); + m_threshFilter->SetLowerThreshold(segLabel); m_threshFilter->SetOutsideValue(BG_VALUE); m_threshFilter->SetInsideValue(LABEL_VALUE); m_threshFilter->Update(); diff --git a/CCSeg/CCsegtool_initialization.h b/CCSeg/CCsegtool_initialization.h index c0a7550..a38a6e3 100644 --- a/CCSeg/CCsegtool_initialization.h +++ b/CCSeg/CCsegtool_initialization.h @@ -127,9 +127,9 @@ class CCsegtool_initialization static const int LABEL_VALUE = 1; static const int NUM_COMPONENTS = 5; - int compute_initialization(std::string inputFileName, std::string segFile, bool vesselRemoveOn, - bool segLabel, int averageNum, bool permute_x_y, bool reflectXOn, - bool reflectYOn, bool openOn, bool doubleOn, int sliceDir, + int compute_initialization(std::string inputFileName, std::string segFileName, bool vesselRemoveOn, + int segLabel, int averageNum, bool permute_x_y, bool reflectXOn, + bool reflectYOn, bool openOn, bool doubleOn, int sliceDir, std::string outfilebase, std::string nameofproject, std::string MidPlaneSliceNumber, bool othercompo, int angle, bool debug=false); void SetLambdaMax(int lambdaMax){m_LambdaMax=lambdaMax;} @@ -151,20 +151,19 @@ class CCsegtool_initialization ImagePointer Get3DImage(); protected: - void loadinginputimage(std::string inputFileName, std::string segFile); - void vesselremoval(bool segLabel); + void loadinginputimage(std::string inputFileName, std::string segFileName); + void vesselremoval(int segLabel); void extract_Midsagittal_planes(int sliceDir, std::string MidPlaneSliceNumber); void averaging(int averageNum, int sliceDir, std::string MidPlaneSliceNumber); void dopermute_x_y(); void reflectX(); void reflectY(); - void extractLabel(bool segLabel); + void extractLabel(int segLabel); void closingop(); void dodoubleOn(); void writeInput(std::string outfilebase, std::string nameofproject); void writeoutput(std::string outfilebase, std::string nameofproject); - private: /** Use in compute_parameters **/ typedef itk::Image CCLOutputImageType; diff --git a/CCSeg/CCsegtool_parameters.cxx b/CCSeg/CCsegtool_parameters.cxx index 8c63d96..aa38947 100644 --- a/CCSeg/CCsegtool_parameters.cxx +++ b/CCSeg/CCsegtool_parameters.cxx @@ -40,17 +40,17 @@ CCsegtool_parameters::CCsegtool_parameters (ExtractImageConstPointer Image, //fi //load the Image SetImage(Image); - //Each files have a number + //Each file has a number //SSMean - readf4(Way,1); + if (!readf4(Way,1)) throw std::runtime_error("Could not read model file"); //Eigenvectors - readf4(Way,2); + if (!readf4(Way,2)) throw std::runtime_error("Could not read model file"); //Bounds - readf(Way,3); + if (!readf(Way,3)) throw std::runtime_error("Could not read model file"); //PMMean - readf(Way,4); + if (!readf(Way,4)) throw std::runtime_error("Could not read model file"); //PMSigmaInv - readf(Way,5); + if (!readf(Way,5)) throw std::runtime_error("Could not read model file"); if(debug) { @@ -95,9 +95,9 @@ CCsegtool_parameters::CCsegtool_parameters (ExtractImageConstPointer Image, //fi /********************************************************************************* - * Fill a vector with the CC atlas directory + * Fill a vector with model data from the CC atlas directory ********************************************************************************/ -void CCsegtool_parameters::readf(std::string way, int nbfile) +bool CCsegtool_parameters::readf(std::string way, int nbfile) { int i[3]; float j; @@ -115,6 +115,9 @@ void CCsegtool_parameters::readf(std::string way, int nbfile) case 5: filename=way + "/Profile_sigmainv.asc"; break; + default: + cerr << "Error (readf): Wrong file number" << endl; + return false; } std::ifstream file(filename.c_str() , ios::in); // open in reading @@ -164,8 +167,12 @@ void CCsegtool_parameters::readf(std::string way, int nbfile) } file.close(); + return true; + } + else { + cerr << "Error: The opening of the file failed" << endl; + return false; } - else cerr << "Error: The opening of the file failed" << endl; } @@ -173,7 +180,7 @@ void CCsegtool_parameters::readf(std::string way, int nbfile) * Fill a vector with the data of a file where there are 4 value on a line * like in CC atlas directory ********************************************************************************/ -void CCsegtool_parameters::readf4(std::string way, int nbfile) +bool CCsegtool_parameters::readf4(std::string way, int nbfile) { char c; int i[2]; @@ -188,6 +195,9 @@ void CCsegtool_parameters::readf4(std::string way, int nbfile) case 2: filename = way + "/Shape_eigvecs.asc"; break; + default: + cerr << "Error (readf4): Wrong file number" << endl; + return false; } std::ifstream file(filename.c_str() , ios::in); // open in reading @@ -228,9 +238,13 @@ void CCsegtool_parameters::readf4(std::string way, int nbfile) } file.close(); + return true; } - else cerr << "Error: The opening of the file failed" << endl; + else { + cerr << "Error: The opening of the file failed" << endl; + return false; + } } diff --git a/CCSeg/CCsegtool_parameters.h b/CCSeg/CCsegtool_parameters.h index 948d16b..de9471e 100644 --- a/CCSeg/CCsegtool_parameters.h +++ b/CCSeg/CCsegtool_parameters.h @@ -48,10 +48,10 @@ class CCsegtool_parameters int numSlice, int X, int Y,float Rotation, float Scale, bool FSXForm, double PSDistance, int WMIntensity,int MPSDisplacement, int OSteps, SizeType ImageSize, bool Debug=false); - //to accede to the private attributs - //Methods for Parameter Specifications - void readf(std::string way, int nbfile); - void readf4(std::string way, int nbfile); + //to access the private attributes + //Methods for parameter specifications + bool readf(std::string way, int nbfile); + bool readf4(std::string way, int nbfile); void getsizeof(int *i, int nbfile); void writeoutput(std::string path_output, std::string _nameofproject); void setparam(double X, double Y, double Scale, double Rot); diff --git a/CCSeg/Globalfunc.cxx b/CCSeg/Globalfunc.cxx index 32c505a..e6689bb 100644 --- a/CCSeg/Globalfunc.cxx +++ b/CCSeg/Globalfunc.cxx @@ -131,13 +131,18 @@ int initialize( std::string Image_filename, std::string Seg_filename, std::strin int numslice = initialization->GetImageSSize(); if(MidPlaneSliceNumber.compare("default")==0) numslice = (numslice-1)/2; - - CCsegtool_parameters* parameters = new CCsegtool_parameters(initialization->GetOutputImage(), CCAtlasDirectory, - initialization->Get3DImage(), permute_x_y, reflectXOn, reflectYOn, doubleOn, - sliceDir, numslice ,initialization->GetCenterX(),initialization->GetCenterY(), - initialization->GetRotation(),initialization->GetScale(), FSXForm, PSDistance, - WMvalue1,10,50,initialization->Get3DImageSize(), debug); - + CCsegtool_parameters* parameters; + try { + parameters = new CCsegtool_parameters(initialization->GetOutputImage(), CCAtlasDirectory, + initialization->Get3DImage(), permute_x_y, reflectXOn, reflectYOn, doubleOn, + sliceDir, numslice ,initialization->GetCenterX(),initialization->GetCenterY(), + initialization->GetRotation(),initialization->GetScale(), FSXForm, PSDistance, + WMvalue1,10,50,initialization->Get3DImageSize(), debug); + } + catch (std::exception &ex) { + std::cerr << ex.what() << std::endl; + return 0; + } // Save the value from the initialization in parameters parameters->SetGlobalvalue(initialization->GetWMvalue(), initialization->GetvoxelsizeX(), initialization->GetvoxelsizeY());