iMSTK
Interactive Medical Simulation Toolkit
imstkDataTracker.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include <map>
10 #include <vector>
11 #include <iostream>
12 #include <iomanip>
13 #include <fstream>
14 
15 #include "imstkTimer.h"
16 
17 namespace imstk
18 {
25 {
26 public:
27 
31  struct ePhysics
32  {
33  static constexpr int SolverTime_ms = 0;
34  static constexpr int NumConstraints = 1;
35  static constexpr int AverageC = 2;
36  };
40  struct Physics
41  {
42  static constexpr char const* SolverTime_ms = "SolverTime_ms";
43  static constexpr char const* NumConstraints = "NumConstraints";
44  static constexpr char const* AverageC = "AverageC";
45  };
46 
47  DataTracker();
48  ~DataTracker();
52  enum class eDecimalFormat_Type { SystemFormatting = 0, DefaultFloat, FixedMantissa, SignificantDigits };
53 
54  void useTabDelimiter() { m_delimiter = '\t'; }
55  void useCommaDelimiter() { m_delimiter = ','; }
56  void setFilename(const std::string& fn) { m_filename = fn; }
57 
61  StopWatch& getStopWatch(int idx);
62 
68  void probe(int idx, double value);
69 
76  int probe(const std::string& name, double value);
77 
82  void probeElapsedTime_s(int idx);
83 
91  int configureProbe(const std::string& name, std::streamsize precision = 3, eDecimalFormat_Type notation = eDecimalFormat_Type::SystemFormatting);
92 
102  int configureProbe(const std::string& name, int index, std::streamsize precision = 6, eDecimalFormat_Type notation = eDecimalFormat_Type::SystemFormatting);
103 
104  double getValue(int idx);
105  double getValue(const std::string& name);
106  std::string getName(int idx);
107 
111  void streamProbesToFile(double time);
112 
113 protected:
114  struct Element
115  {
116  int index;
117  std::string name;
118  double value = std::numeric_limits<double>::quiet_NaN();
119  std::streamsize precision = 3;
120  eDecimalFormat_Type notation = eDecimalFormat_Type::SystemFormatting;
121  };
122 
123  std::string m_filename;
124  char m_delimiter;
125  std::vector<Element> m_elements;
126  std::ofstream m_file;
127  std::map<int, StopWatch> m_timers;
128  int m_nextIndex;
129 
130  void createFile();
131  Element& getElement(int idx);
132  Element& getElement(std::string const& name);
133 };
134 } // namespace imstk
Header names of the common data values to track.
void streamProbesToFile(double time)
Write the current probe values to a row in the data file.
Compound Geometry.
StopWatch & getStopWatch(int idx)
An available timer for each data item tracked.
Common data values to track.
Stop Watch utility class.
Definition: imstkTimer.h:19
void probe(int idx, double value)
Track a data value associated with a header id.
int configureProbe(const std::string &name, std::streamsize precision=3, eDecimalFormat_Type notation=eDecimalFormat_Type::SystemFormatting)
Create and configure a probe and how it is written to file.
eDecimalFormat_Type
C++ I/O manipulation flags.
Store time based data to write to a file.
void probeElapsedTime_s(int idx)
Track a time duration associated with a header.