8 #include "PlusConfigure.h" 20 #include <vtksys/CommandLineArguments.hxx> 21 #include <vtkXMLDataElement.h> 22 #include <vtkXMLUtilities.h> 25 #include "itkLandmarkSpatialObject.h" 28 void WriteFiducialPositions(std::ofstream& outFile,
const std::string& inputTestcaseName,
const std::string& inputImageSequenceFileName,
const std::string& fiducialPosFileName)
30 vtkSmartPointer<vtkFcsvReader> readerf = vtkSmartPointer<vtkFcsvReader>::New();
31 readerf->SetFileName(fiducialPosFileName);
33 auto fcsvData = readerf->GetFcsvDataObject();
35 double sumFiducialNum = 0;
37 LOG_DEBUG(
"Number Of Points: " << fcsvData.points.size());
38 if (fcsvData.points.size() == 0)
40 LOG_ERROR(
"No fiducial points.");
44 std::vector<FcsvPoint>::iterator it = fcsvData.points.begin();
46 int firstFrameIndex = std::numeric_limits<int>::max();
47 int lastFrameIndex = -1;
48 while (it != fcsvData.points.end())
50 int frameIndex = (*it).position[2];
51 if (firstFrameIndex > frameIndex)
53 firstFrameIndex = frameIndex;
55 if (lastFrameIndex < frameIndex)
57 lastFrameIndex = frameIndex;
61 int numberOfFrames = lastFrameIndex - firstFrameIndex + 1;
63 for (
int currentFrameIndex = firstFrameIndex; currentFrameIndex <= lastFrameIndex; currentFrameIndex++)
65 std::vector<FcsvPoint>::iterator it = fcsvData.points.begin();
66 std::vector<std::vector<double>> foundDotsCoordinateValue;
68 while (it != fcsvData.points.end())
70 if (currentFrameIndex == (*it).position[2])
73 std::vector<double> fiducial(4, 0);
74 fiducial[0] = (*it).position[0];
75 fiducial[1] = (*it).position[1];
78 if ((*it).position[0] != 0.0 || (*it).position[1] != 0.0)
83 foundDotsCoordinateValue.push_back(fiducial);
92 sumFiducialNum = sumFiducialNum + validFidNum;
103 double meanFid = sumFiducialNum / numberOfFrames;
108 int main(
int argc,
char** argv)
110 std::string inputTestDataDir;
111 std::string inputFcsvFileName;
112 std::string inputImageSequenceFileName;
113 std::string inputTestcaseName;
114 std::string outputXmlFileName;
116 int verboseLevel(vtkPlusLogger::LOG_LEVEL_UNDEFINED);
118 vtksys::CommandLineArguments args;
119 args.Initialize(argc, argv);
121 args.AddArgument(
"--test-data-dir", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTestDataDir,
"Test data directory");
122 args.AddArgument(
"--fcsv-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputFcsvFileName,
"Name of file storing fiducial point coordinates");
123 args.AddArgument(
"--img-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputImageSequenceFileName,
"Filename of the input image sequence. Segmentation will be performed for all frames of the sequence.");
124 args.AddArgument(
"--testcase", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTestcaseName,
"Name of the test case that will be printed to the output");
125 args.AddArgument(
"--output-xml-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputXmlFileName,
"Name of file storing results of a new segmentation (fiducial coordinates, intensity, angle)");
126 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
130 std::cerr <<
"Problem parsing arguments" << std::endl;
131 std::cout <<
"Help: " << args.GetHelp() << std::endl;
137 if (inputImageSequenceFileName.empty() || inputFcsvFileName.empty() || inputTestcaseName.empty() || outputXmlFileName.empty())
139 std::cerr <<
"--img-seq-file, --input-fcsv-file, --input-testcase-name, and --output-xml-file parameters are required" << std::endl;
143 std::ofstream outputXmlFile;
144 outputXmlFile.open(outputXmlFileName.c_str());
150 std::string inputFcsvFilePath = inputTestDataDir +
"/" + inputFcsvFileName;
153 outputXmlFile.close();
static void WriteSegmentationResultsFooter(std::ostream &outFile)
void SetDotsFound(bool value)
static void WriteSegmentationResultsParameters(std::ostream &outFile, PlusFidPatternRecognition &patternRcognitionObject, const std::string &trueFidFileName)
static void WriteSegmentationResults(std::ostream &outFile, PlusPatternRecognitionResult &segResults, const std::string &inputTestcaseName, int currentFrameIndex, const std::string &inputImageSequenceFileName)
void SetFoundDotsCoordinateValue(std::vector< std::vector< double > > value)
static vtkIGSIOLogger * Instance()
int main(int argc, char **argv)
void WriteFiducialPositions(std::ofstream &outFile, const std::string &inputTestcaseName, const std::string &inputImageSequenceFileName, const std::string &fiducialPosFileName)
static void WriteSegmentationResultsStats(std::ostream &outFile, double meanFid, double meanFidCandidate=-1)
static void WriteSegmentationResultsHeader(std::ostream &outFile)