Skip to content

Commit

Permalink
cmd parser remove pass by ref
Browse files Browse the repository at this point in the history
  • Loading branch information
eidelen committed Oct 12, 2024
1 parent b032589 commit 2971078
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 80 deletions.
2 changes: 1 addition & 1 deletion dicom2mesh/inc/dicom2mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Dicom2Mesh
~Dicom2Mesh();

int doMesh();
static bool parseCmdLineParameters( const int &argc, const char **argv, Dicom2MeshParameters &param );
static std::tuple<bool, Dicom2MeshParameters> parseCmdLineParameters( const int &argc, const char **argv);
static void showUsageText();
static void showVersionText();

Expand Down
25 changes: 14 additions & 11 deletions dicom2mesh/src/dicom2mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ int Dicom2Mesh::doMesh()
{
if( m_params.showAsVolume )
{
std::cout << "Show volume..." << std::endl;
VTKVolumeVisualizer::displayVolume(volume, m_params.volumenRenderingColoring);
}
else
{
std::cout << "Show mesh..." << std::endl;
VTKMeshVisualizer::displayMesh(mesh);
}
}
Expand All @@ -193,8 +195,9 @@ std::string Dicom2Mesh::trim(const std::string& str)
return trimedStr;
}

bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dicom2MeshParameters &param)
std::tuple<bool, Dicom2Mesh::Dicom2MeshParameters> Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv)
{
Dicom2Mesh::Dicom2MeshParameters param;
for( int a = 0; a < argc; a++ )
{
std::string cArg( argv[a] );
Expand All @@ -210,7 +213,7 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
else
{
showUsageText();
return false;
return {false, param};
}
}
else if( cArg.compare("-ipng") == 0 )
Expand All @@ -228,7 +231,7 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
else
{
showUsageText();
return false;
return {false, param};
}
}
else if( cArg.compare("-b") == 0 )
Expand All @@ -246,7 +249,7 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
else
{
showUsageText();
return false;
return {false, param};
}
}
else if( cArg.compare("-tu") == 0 )
Expand All @@ -260,13 +263,13 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
else
{
showUsageText();
return false;
return {false, param};
}
}
else if( cArg.compare("-h") == 0 )
{
showUsageText();
return false;
return {false, param};
}
else if( cArg.compare("-r") == 0 )
{
Expand Down Expand Up @@ -331,7 +334,7 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
else
{
std::cerr << "Incomplete volume rendering color entry" << std::endl;
return false;
return {false, param};
}
}
else if( cArg.at(0) == '[' )
Expand Down Expand Up @@ -364,7 +367,7 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
else
{
std::cerr << "No image files specified" << std::endl;
return false;
return {false, param};
}
}
else if( cArg.compare("-z") == 0 )
Expand All @@ -374,7 +377,7 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
else if( cArg.compare("--version") == 0 )
{
showVersionText();
return false;
return {false, param};
}
else if( cArg.compare("-sxyz") == 0 )
{
Expand All @@ -394,10 +397,10 @@ bool Dicom2Mesh::parseCmdLineParameters(const int &argc, const char **argv, Dico
cerr << "or" << endl;
cerr << "No input images defined" << endl << "> dicom2mesh -ipng [path1, path2, ...]" << endl;
cerr << "For help, run" << endl << "> dicom2mesh -h" << endl;
return false;
return {false, param};
}

return true;
return {true, param};
}

void Dicom2Mesh::showUsageText()
Expand Down
4 changes: 2 additions & 2 deletions dicom2mesh/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

int main(int argc, char *argv[])
{
Dicom2Mesh::Dicom2MeshParameters settings;
if( !Dicom2Mesh::parseCmdLineParameters(argc, (const char**)( argv ), settings) )
auto[parseOk, settings] = Dicom2Mesh::parseCmdLineParameters(argc, (const char**)( argv ));
if( !parseOk )
return -1;

auto d2m = std::shared_ptr<Dicom2Mesh>(new Dicom2Mesh(settings));
Expand Down
Loading

0 comments on commit 2971078

Please sign in to comment.