Commit 5db80c2ee592f88f4f6b008b781adc7354724ed4
1 parent
e37ce7bf
add cells to a cell set
Showing
1 changed file
with
41 additions
and
0 deletions
Show diff stats
stim/biomodels/cellset.h
@@ -20,6 +20,22 @@ protected: | @@ -20,6 +20,22 @@ protected: | ||
20 | void init(){ | 20 | void init(){ |
21 | 21 | ||
22 | } | 22 | } |
23 | + | ||
24 | + /// Initialize fields for a standard cell set containing three points and a radius | ||
25 | + void init_p3(){ | ||
26 | + fields.insert(std::pair<std::string, size_t>("x", 0)); | ||
27 | + ip[0] = 0; | ||
28 | + fields.insert(std::pair<std::string, size_t>("y", 1)); | ||
29 | + ip[1] = 1; | ||
30 | + fields.insert(std::pair<std::string, size_t>("z", 2)); | ||
31 | + ip[2] = 2; | ||
32 | + } | ||
33 | + | ||
34 | + void init_p3r(){ | ||
35 | + init_p3(); | ||
36 | + fields.insert(std::pair<std::string, size_t>("radius", 3)); | ||
37 | + ip[0] = 3; | ||
38 | + } | ||
23 | public: | 39 | public: |
24 | /// Constructor - create an empty cell set | 40 | /// Constructor - create an empty cell set |
25 | cellset(){ | 41 | cellset(){ |
@@ -126,6 +142,31 @@ public: | @@ -126,6 +142,31 @@ public: | ||
126 | return minval; | 142 | return minval; |
127 | } | 143 | } |
128 | 144 | ||
145 | + /// adds a cell to the cell set | ||
146 | + void add(double x, double y, double z, double r = 0){ | ||
147 | + | ||
148 | + if(cells.size() == 0){ //if the cell set is empty | ||
149 | + if(r == 0) //if the radius is zero | ||
150 | + init_p3(); //initialize without a radius | ||
151 | + else | ||
152 | + init_p3r(); //otherwise initialize with a radius | ||
153 | + } | ||
154 | + | ||
155 | + size_t nf = fields.size(); //get the number of fields | ||
156 | + size_t bytes = sizeof(double) * nf; //get the size of a cell field | ||
157 | + double* newcell = (double*) malloc(bytes); //allocate memory for the new cell | ||
158 | + memset(newcell, 0, bytes); //initialize all fields to zero | ||
159 | + newcell[ip[0]] = x; | ||
160 | + newcell[ip[1]] = y; | ||
161 | + newcell[ip[2]] = z; | ||
162 | + | ||
163 | + if(r != 0){ //if the user specifies a radius | ||
164 | + size_t ir = fields["radius"]; //get the index for the radius field | ||
165 | + newcell[ir] = r; //add the radius to the field | ||
166 | + } | ||
167 | + cells.push_back(newcell); //push the new memory entry into the cell array | ||
168 | + } | ||
169 | + | ||
129 | 170 | ||
130 | }; //end class cellset | 171 | }; //end class cellset |
131 | }; //end namespace stim | 172 | }; //end namespace stim |