diff --git a/stim/biomodels/cellset.h b/stim/biomodels/cellset.h index b09935d..e922a0d 100644 --- a/stim/biomodels/cellset.h +++ b/stim/biomodels/cellset.h @@ -20,6 +20,22 @@ protected: void init(){ } + + /// Initialize fields for a standard cell set containing three points and a radius + void init_p3(){ + fields.insert(std::pair("x", 0)); + ip[0] = 0; + fields.insert(std::pair("y", 1)); + ip[1] = 1; + fields.insert(std::pair("z", 2)); + ip[2] = 2; + } + + void init_p3r(){ + init_p3(); + fields.insert(std::pair("radius", 3)); + ip[0] = 3; + } public: /// Constructor - create an empty cell set cellset(){ @@ -126,6 +142,31 @@ public: return minval; } + /// adds a cell to the cell set + void add(double x, double y, double z, double r = 0){ + + if(cells.size() == 0){ //if the cell set is empty + if(r == 0) //if the radius is zero + init_p3(); //initialize without a radius + else + init_p3r(); //otherwise initialize with a radius + } + + size_t nf = fields.size(); //get the number of fields + size_t bytes = sizeof(double) * nf; //get the size of a cell field + double* newcell = (double*) malloc(bytes); //allocate memory for the new cell + memset(newcell, 0, bytes); //initialize all fields to zero + newcell[ip[0]] = x; + newcell[ip[1]] = y; + newcell[ip[2]] = z; + + if(r != 0){ //if the user specifies a radius + size_t ir = fields["radius"]; //get the index for the radius field + newcell[ir] = r; //add the radius to the field + } + cells.push_back(newcell); //push the new memory entry into the cell array + } + }; //end class cellset }; //end namespace stim -- libgit2 0.21.4