Bridges-C++  3.2.0
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 
69  void setViewport(float xmin, float xmax, float ymin, float
70  ymax) {
71  autoscaledomain = false;
72  domainxmin = xmin;
73  domainxmax = xmax;
74  domainymin = ymin;
75  domainymax = ymax;
76  }
81  }
82 
88  virtual const string getDStype() const {
89  return "SymbolCollection";
90  }
91 
97  void addSymbol(Symbol *s) {
98  // note: it is the user's responsibility to handle
99  // duplicates where desired
100  symbols[s->getIdentifier()] = s;
101  }
102 
103  private:
104  /*
105  * This method examines whether the axes should be expanded
106  * to ensure all shapes are shown
107  *
108  * @param s Symbol
109  */
110 
111  void updateAxisDomains(const Symbol* s) const {
112  vector<float> dims = s->getDimensions();
113 
114  // check x axis
115  if (dims[0] < domainxmin) {
116  domainxmin = dims[0];
117  }
118  if (dims[1] > domainxmax) {
119  domainxmax = dims[1];
120  }
121 
122  // check y axis
123  if (dims[2] < domainymin) {
124  domainymin = dims[2];
125  }
126  if (dims[3] > domainymax) {
127  domainymax = dims[3];
128  }
129 
130  // TEMP (KRS)
131  // domainxmin = 0;
132  // domainxmax = 100;
133  // domainymin = 0;
134  // domainymax = 100;
135  // TEMP (KRS)
136  }
137 
138  /*
139  * @brief Get the JSON representation of the the data structure
140  * @return JSON string of the symbol representation
141  */
142  virtual const string getDataStructureRepresentation() const {
143 
144  if (autoscaledomain)
145  for (auto& entry : symbols)
146  updateAxisDomains(entry.second);
147 
148 
149  string symbol_json = string();
150  for (auto& entry : symbols) {
151  symbol_json +=
152  entry.second->getSymbolRepresentation() + COMMA;
153  }
154  // remove last comma
155  if (symbols.size()) {
156  symbol_json.erase(symbol_json.size() - 1);
157 
158  symbol_json = QUOTE + "domainX" + QUOTE + COLON +
159  OPEN_BOX +
160  to_string(domainxmin) + COMMA + to_string(domainxmax) +
161  CLOSE_BOX + COMMA +
162  QUOTE + "domainY" + QUOTE + COLON +
163  OPEN_BOX +
164  to_string(domainymin) + COMMA + to_string(domainymax) +
165  CLOSE_BOX + COMMA +
166  QUOTE + "symbols" + QUOTE + COLON +
167  OPEN_BOX + symbol_json + CLOSE_BOX + CLOSE_CURLY;
168  }
169  return symbol_json;
170  }
171  };
172  }
173 } // namespace bridges
174 
175 #endif
void addSymbol(Symbol *s)
This method adds a symbol to the collection.
Definition: SymbolCollection.h:97
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:88
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:33
SymbolCollection()
Definition: SymbolCollection.h:80
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)
set the dimensions of the view
Definition: SymbolCollection.h:69
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
Virtual method to get the bounding box (dimensions) of the shape.
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
int getIdentifier()
return the symbol identifier.
Definition: Symbol.h:131