Bridges-C++ 3.5.0-dev2-1-ge3e57bf
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
6using namespace std;
7
8#include "DataStructure.h"
9#include "Symbol.h"
10
25#ifndef SYMBOL_COLLECTION_H
26
27#define SYMBOL_COLLECTION_H
28
29namespace bridges {
30 namespace datastructure {
39 // keep track of the shape elements; useful
40 // to maintain their properties
41 private:
42
43 std::vector<std::shared_ptr<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 = -100.0;
52 mutable float domainxmax = 100.0;
53 mutable float domainymin = -100.0;
54 mutable float domainymax = 100.0;
55
56 public:
57
68 void setViewport(float xmin, float xmax, float ymin, float
69 ymax) {
70 domainxmin = xmin;
71 domainxmax = xmax;
72 domainymin = ymin;
73 domainymax = ymax;
74 }
79 }
80
86 virtual const string getDStype() const override {
87 return "SymbolCollectionV2";
88 }
89
96 void addSymbolPtr(std::shared_ptr<Symbol> s) {
97 symbols.push_back(s);
98 }
99
100 template <typename T>
101 void addSymbol(T s) {
102 std::shared_ptr<T> pt = std::make_shared<T>(s);
103 addSymbolPtr ((std::shared_ptr<Symbol>)pt);
104 }
105
106 private:
107
108 /*
109 * @brief Get the JSON representation of the the data structure
110 * @return JSON string of the symbol representation
111 */
112 virtual const string getDataStructureRepresentation() const override {
113
114 string symbol_json = string();
115 for (auto& entry : symbols) {
116 symbol_json +=
117 entry->getSymbolRepresentation() + COMMA;
118 }
119 // remove last comma
120 if (symbols.size()) {
121 symbol_json.erase(symbol_json.size() - 1);
122
123 symbol_json = QUOTE + "domainX" + QUOTE + COLON +
124 OPEN_BOX +
125 to_string(domainxmin) + COMMA + to_string(domainxmax) +
126 CLOSE_BOX + COMMA +
127 QUOTE + "domainY" + QUOTE + COLON +
128 OPEN_BOX +
129 to_string(domainymin) + COMMA + to_string(domainymax) +
130 CLOSE_BOX + COMMA +
131 QUOTE + "symbols" + QUOTE + COLON +
132 OPEN_BOX + symbol_json + CLOSE_BOX + CLOSE_CURLY;
133 }
134 return symbol_json;
135 }
136 };
137 }
138} // namespace bridges
139
140#endif
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:74
the ShapeCollection represents a collection of symbols (shapes, polygons, and text) to visualize in B...
Definition: SymbolCollection.h:38
float domainymin
Definition: SymbolCollection.h:53
void addSymbol(T s)
Definition: SymbolCollection.h:101
virtual const string getDStype() const override
This method gets the data structure type.
Definition: SymbolCollection.h:86
float domainxmin
Definition: SymbolCollection.h:51
float domainxmax
Definition: SymbolCollection.h:52
float domainymax
Definition: SymbolCollection.h:54
void setViewport(float xmin, float xmax, float ymin, float ymax)
set the dimensions of the view
Definition: SymbolCollection.h:68
SymbolCollection()
Definition: SymbolCollection.h:78
void addSymbolPtr(std::shared_ptr< Symbol > s)
This method adds a symbol to the collection.
Definition: SymbolCollection.h:96
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 COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50