1 #include "PlusConfigure.h" 3 #include "vtksys/CommandLineArguments.hxx" 17 #define NUM_BACKGROUND_FRAMES 100 18 #define DEFAULT_NUM_DATA_FRAMES 100 19 #define ATRACSYS_MAX_FIDUCIALS 6 22 #define ATR_SUCCESS AtracsysTracker::ATRACSYS_RESULT::SUCCESS 37 std::string description;
50 int main(
int argc,
char** argv)
53 bool printHelp(
false);
54 bool backgroundSubtraction(
false);
55 std::string markerName;
56 std::string description;
57 std::string destinationPath;
59 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
62 vtksys::CommandLineArguments args;
63 args.Initialize(argc, argv);
65 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
66 args.AddArgument(
"--background-subtraction", vtksys::CommandLineArguments::NO_ARGUMENT, &backgroundSubtraction,
"Remove background fiducials from data considered by the creator.");
67 args.AddArgument(
"--marker-name", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &markerName,
"Name of marker.");
68 args.AddArgument(
"--description", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &description,
"Decsription of marker (i.e. purpose, color, size, and any other desired metadata).");
69 args.AddArgument(
"--geometryId", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &geometryId,
"Id of the geometry we are creating. Must be unique.");
70 args.AddArgument(
"--destination-path", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &destinationPath,
"Where the generated marker geometry ini file will be written to.");
71 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace).");
72 args.AddArgument(
"--num-frames", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &numFrames,
"Number of frames to use in generating marker geometry ini file.");
76 std::cerr <<
"Problem parsing arguments." << std::endl;
77 std::cout <<
"Help: " << args.GetHelp() << std::endl;
83 std::cout << args.GetHelp() << std::endl;
89 if (markerName.empty())
91 LOG_ERROR(
"--marker-name argument is required!");
92 std::cout <<
"Help: " << args.GetHelp() << std::endl;
96 if (description.empty())
98 LOG_ERROR(
"--description argument is required!");
99 std::cout <<
"Help: " << args.GetHelp() << std::endl;
103 if (geometryId == -1)
105 LOG_ERROR(
"--geometryId argument is required!");
106 std::cout <<
"Help: " << args.GetHelp() << std::endl;
114 if (result !=
ATR_SUCCESS && result != AtracsysTracker::ATRACSYS_RESULT::WARNING_CONNECTED_IN_USB2)
119 else if (result == AtracsysTracker::ATRACSYS_RESULT::WARNING_CONNECTED_IN_USB2)
128 if (
DeviceType == AtracsysTracker::DEVICE_TYPE::SPRYTRACK_180)
139 if (backgroundSubtraction)
143 LOG_ERROR(
"Failed to collect background noise fiducial frames.");
150 LOG_INFO(
"Background collection successful. Place marker in FOV of camera." << std::endl <<
"Press <ENTER> to continue.");
154 LOG_INFO(
"Collecting data frames.");
162 LOG_ERROR(
"Failed to collect data fiducial frames.");
177 geom.name = markerName;
178 geom.description = description;
179 geom.destPath = destinationPath;
180 geom.geometryId = geometryId;
182 geom.fids = dataFids;
187 LOG_ERROR(
"Too many fiducials in frame (there were " << geom.fids.size() <<
" marker fids visible). Unable to create Atracsys marker with this many fiducials.");
190 else if (geom.fids.size() < 3)
192 LOG_ERROR(
"Too few fiducials in frame. Ensure marker is fully visible and try again.");
209 std::vector<Marker> markerFrame;
210 std::map<std::string, std::string> events;
211 while (m < numFrames)
220 fidFrameList.push_back(fid3dFrame);
242 for (fidsFrameList::size_type frameNum = 0; frameNum < fidFrameList.size(); frameNum++)
244 frame = fidFrameList[frameNum];
246 std::copy(frame.begin(), frame.end(), std::inserter(fids, fids.end()));
250 std::sort(fids.begin(), fids.end());
251 fidsFrame::iterator it = std::unique(fids.begin(), fids.end());
261 fidsFrame::iterator backgroundIt, dataIt;
262 for (dataIt = begin(dataFids); dataIt != end(dataFids); dataIt++)
264 bool equalityFound =
false;
265 for (backgroundIt = begin(backgroundFids); backgroundIt != end(backgroundFids); backgroundIt++)
267 if (*dataIt == *backgroundIt)
269 equalityFound =
true;
275 filteredDataFids.push_back(*dataIt);
280 for (fidsFrame::size_type
i = 0;
i < filteredDataFids.size();
i++)
282 if (filteredDataFids[
i].probability != 1)
284 LOG_ERROR(
"Fiducial with non 1 probability in data fiducials. Please retry marker creation ensuring that the marker is not moving and is in a good view position for the camera.");
291 dataFids = filteredDataFids;
300 float cumulativeXmm = 0, cumulativeYmm = 0, cumulativeZmm = 0;
301 fidsFrame::const_iterator it;
302 for (it = begin(dataFids); it != end(dataFids); it++)
304 cumulativeXmm += it->xMm;
305 cumulativeYmm += it->yMm;
306 cumulativeZmm += it->zMm;
308 float aveXmm = cumulativeXmm /= dataFids.size();
309 float aveYmm = cumulativeYmm /= dataFids.size();
310 float aveZmm = cumulativeZmm /= dataFids.size();
311 for (it = begin(dataFids); it != end(dataFids); it++)
313 zeroMeanFids.emplace_back();
314 zeroMeanFids.back().xMm = it->xMm - aveXmm;
315 zeroMeanFids.back().yMm = it->yMm - aveYmm;
316 zeroMeanFids.back().zMm = it->zMm - aveZmm;
317 zeroMeanFids.back().probability = it->probability;
319 dataFids = zeroMeanFids;
327 std::string fileName;
328 if (geom.destPath.empty())
330 fileName =
"./" + geom.name +
".ini";
334 fileName = geom.destPath +
'/' + geom.name +
".ini";
336 LOG_INFO(
"Writing marker geometry to: " << fileName);
341 file <<
";; " << geom.name << std::endl;
342 file <<
";; " << geom.description << std::endl;
344 auto tm = *std::localtime(&
t);
345 file <<
";; " << std::put_time(&tm,
"%Y-%m-%d %H:%M:%S") << std::endl;
348 file <<
"[geometry]" << std::endl;
349 file <<
"count=" << geom.fids.size() << std::endl;
350 file <<
"id=" << geom.geometryId << std::endl;
352 for (fidsFrame::size_type
i = 0;
i < geom.fids.size();
i++)
354 file <<
"[fiducial" <<
i <<
"]" << std::endl;
355 file <<
"x=" << geom.fids[
i].xMm << std::endl;
356 file <<
"y=" << geom.fids[
i].yMm << std::endl;
357 file <<
"z=" << geom.fids[
i].zMm << std::endl;
360 file <<
"[pivot]" << std::endl;
361 file <<
"x=0.0000" << std::endl;
362 file <<
"y=0.0000" << std::endl;
363 file <<
"z=0.0000" << std::endl;
ATRACSYS_RESULT SetUserLEDState(int red, int green, int blue, int frequency, bool enabled=true)
PlusStatus ProcessFiducials(fidsFrameList &fidFrameList, fidsFrame &backgroundFids)
AtracsysTracker::ATRACSYS_RESULT ATRACSYS_RESULT
std::vector< fidsFrame > fidsFrameList
PlusStatus ZeroMeanFids(fidsFrame &dataFids)
ATRACSYS_RESULT EnableUserLED(bool enabled)
#define ATRACSYS_MAX_FIDUCIALS
ATRACSYS_RESULT GetDeviceType(DEVICE_TYPE &deviceType)
#define NUM_BACKGROUND_FRAMES
AtracsysTracker::Fiducial Fiducial
std::vector< Fiducial > fidsFrame
ATRACSYS_RESULT GetMarkersInFrame(std::vector< Marker > &markers, std::map< std::string, std::string > &events, uint64_t &sdkTimestamp)
std::string ResultToString(ATRACSYS_RESULT result)
PlusStatus PerformBackgroundSubtraction(fidsFrame &backgroundFids, fidsFrame &dataFids)
#define DEFAULT_NUM_DATA_FRAMES
PlusStatus CollectFiducials(fidsFrameList &fidFrameList, int numFrames)
static vtkIGSIOLogger * Instance()
AtracsysTracker::Marker Marker
int main(int argc, char **argv)
ATRACSYS_RESULT SetSpryTrackProcessingType(SPRYTRACK_IMAGE_PROCESSING_TYPE processingType)
ATRACSYS_RESULT Connect()
AtracsysTracker::DEVICE_TYPE DeviceType
PlusStatus WriteGeometryIniFile(const MarkerGeometry geom)