Bridges-C++  3.1.1
Bridges(C++API)
SymbolCollection.h
Go to the documentation of this file.
1 #include <cmath>
2 #include <string>
3 #include <vector>
4 #include <unordered_map>
5 
6 using namespace std;
7 
8 #include "DataStructure.h"
9 #include "Symbol.h"
10 
25 #ifndef SYMBOL_COLLECTION_H
26 
27 #define SYMBOL_COLLECTION_H
28 
29 namespace bridges {
30  namespace datastructure {
39  // keep track of the shape elements; useful
40  // to maintain their properties
41  private:
42 
43  unordered_map<int, Symbol*> symbols;
44 
45  // default domain (assuming square coordinate space)
46  // domain emanates in x and y directions, both positive
47  // and negative,
48  // from 0,0
49 
50  protected:
51  mutable float domainxmin = 0.0;
52  mutable float domainxmax = 100.0;
53  mutable float domainymin = 0.0;
54  mutable float domainymax = 100.0;
55  bool autoscaledomain = false;
56 
57  public:
58 
59  void setViewport(float xmin, float xmax, float ymin, float
60  ymax) {
61  autoscaledomain = false;
62  domainxmin = xmin;
63  domainxmax = xmax;
64  domainymin = ymin;
65  domainymax = ymax;
66  }
71  }
72 
78  virtual const string getDStype() const {
79  return "SymbolCollection";
80  }
81 
87  void addSymbol(Symbol *s) {
88  // note: it is the user's responsibility to handle
89  // duplicates where desired
90  symbols[s->getIdentifier()] = s;
91  }
92 
93  private:
94  /*
95  * This method examines whether the axes should be expanded
96  * to ensure all shapes are shown
97  *
98  * @param s Symbol
99  */
100 
101  void updateAxisDomains(const Symbol* s) const {
102  vector<float> dims = s->getDimensions();
103 
104  // check x axis
105  if (dims[0] < domainxmin) {
106  domainxmin = dims[0];
107  }
108  if (dims[1] > domainxmax) {
109  domainxmax = dims[1];
110  }
111 
112  // check y axis
113  if (dims[2] < domainymin) {
114  domainymin = dims[2];
115  }
116  if (dims[3] > domainymax) {
117  domainymax = dims[3];
118  }
119 
120  // TEMP (KRS)
121  // domainxmin = 0;
122  // domainxmax = 100;
123  // domainymin = 0;
124  // domainymax = 100;
125  // TEMP (KRS)
126  }
127 
128  /*
129  * Get the JSON representation of the the data structure
130  * @return JSON string of the symbol representation
131  */
132  virtual const string getDataStructureRepresentation() const {
133 
134  if (autoscaledomain)
135  for (auto& entry : symbols)
136  updateAxisDomains(entry.second);
137 
138 
139  string symbol_json = string();
140  for (auto& entry : symbols) {
141  symbol_json +=
142  entry.second->getSymbolRepresentation() + COMMA;
143  }
144  // remove last comma
145  if (symbols.size()) {
146  symbol_json.erase(symbol_json.size() - 1);
147 
148  symbol_json = QUOTE + "domainX" + QUOTE + COLON +
149  OPEN_BOX +
150  to_string(domainxmin) + COMMA + to_string(domainxmax) +
151  CLOSE_BOX + COMMA +
152  QUOTE + "domainY" + QUOTE + COLON +
153  OPEN_BOX +
154  to_string(domainymin) + COMMA + to_string(domainymax) +
155  CLOSE_BOX + COMMA +
156  QUOTE + "symbols" + QUOTE + COLON +
157  OPEN_BOX + symbol_json + CLOSE_BOX + CLOSE_CURLY;
158  }
159  return symbol_json;
160  }
161  };
162  }
163 } // namespace bridges
164 
165 #endif
void addSymbol(Symbol *s)
This method adds a symbol to the collection.
Definition: SymbolCollection.h:87
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
virtual const string getDStype() const
This method gets the data structure type.
Definition: SymbolCollection.h:78
const string COLON
Definition: DataStructure.h:51
STL namespace.
const string OPEN_BOX
Definition: DataStructure.h:54
const string CLOSE_CURLY
Definition: DataStructure.h:53
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:32
SymbolCollection()
Definition: SymbolCollection.h:70
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string CLOSE_BOX
Definition: DataStructure.h:55
void setViewport(float xmin, float xmax, float ymin, float ymax)
Definition: SymbolCollection.h:59
the ShapeCollection represents a collection of symbols (shapes, polygons, and text) to visualize in B...
Definition: SymbolCollection.h:38
virtual vector< float > getDimensions() const =0
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
int getIdentifier()
Definition: Symbol.h:122