From 9599dbe3b9d5594153288a4e567eb3b46afee116 Mon Sep 17 00:00:00 2001 From: Seb James Date: Wed, 24 Apr 2024 17:17:41 +0100 Subject: [PATCH] Manage memory with unique_ptr in sg.cpp. Also couple of fixes. --- examples/SimpsonGoodhill/sg.cpp | 12 ++++++++---- examples/SimpsonGoodhill/sg.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/SimpsonGoodhill/sg.cpp b/examples/SimpsonGoodhill/sg.cpp index 5e8be350..1d114f99 100644 --- a/examples/SimpsonGoodhill/sg.cpp +++ b/examples/SimpsonGoodhill/sg.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,6 @@ struct SimpsonGoodhill this->conf = cfg; this->init(); } - ~SimpsonGoodhill() { delete this->retina; } void run() { @@ -94,7 +94,7 @@ struct SimpsonGoodhill T gr_denom = rgcside-1; T gr = T{1}/gr_denom; std::cout << "Grid element length " << gr << std::endl; - this->retina = new morph::CartGrid(gr, gr, 0.0f, 0.0f, 0.95f, 0.95f); + this->retina = std::make_unique(gr, gr, 0.0f, 0.0f, 0.95f, 0.95f); this->retina->setBoundaryOnOuterEdge(); std::cout << "Retina has " << this->retina->num() << " cells\n"; this->branches.resize(this->retina->num() * bpa); @@ -166,13 +166,14 @@ struct SimpsonGoodhill // Show a vis of the retina, to compare positions/colours offset[0] += 1.3f; - auto cgv = std::make_unique>(retina, offset); + auto cgv = std::make_unique>(this->retina.get(), offset); v->bindmodel (cgv); cgv->cartVisMode = morph::CartVisMode::RectInterp; std::vector> points = this->retina->getCoordinates3(); cgv->setVectorData (&points); cgv->cm.setType (morph::ColourMapType::Duochrome); cgv->cm.setHueRG(); + cgv->zScale.setParams (0.0f, 0.0f); // make retina visual flat cgv->addLabel ("Retina", {0.0f, 1.1f, 0.0f}); cgv->finalize(); v->addVisualModel (cgv); @@ -193,7 +194,7 @@ struct SimpsonGoodhill // Access to a parameter configuration object morph::Config* conf; // rgcside^2 RGCs, each with bpa axon branches growing. - morph::CartGrid* retina; + std::unique_ptr retina; // Parameters vecto (See Table 2 in the paper) morph::vec m = { T{0.02}, T{0.2}, T{0.15}, T{0.1} }; // The centre coordinate @@ -227,6 +228,9 @@ int main (int argc, char **argv) std::cerr << "Failed to read config " << paramsfile << ". Exiting.\n"; return 1; } + if (conf.getBool ("movie", false) == true) { + std::filesystem::create_directories ("./frames"); + } SimpsonGoodhill model (&conf); model.run(); diff --git a/examples/SimpsonGoodhill/sg.json b/examples/SimpsonGoodhill/sg.json index e9f783bc..d68d057d 100644 --- a/examples/SimpsonGoodhill/sg.json +++ b/examples/SimpsonGoodhill/sg.json @@ -1,5 +1,5 @@ { - "desc_movie" : "If true, then save images to make a movie", + "desc_movie" : "If true, then save images (into ./frames/) to make a movie", "movie" : true, "win_width" : 1920, "desc_goslow" : "If true, then slow down the visualisation to make it watchable",