Commits
Ville Suoranta authored b9bb70c8da8 Merge
44 44 | |
45 45 | |
46 46 | |
47 47 | |
48 48 | using namespace casacore; |
49 49 | namespace casa { //# NAMESPACE CASA - BEGIN |
50 50 | |
51 51 | // statics |
52 52 | String ColormapDefinition::ourDefaultColormap(""); |
53 53 | String ColormapDefinition::ourTableVersion("1.0"); |
54 - | Table ColormapDefinition::ourDefaultColormapTable = Table(); |
55 - | Table ColormapDefinition::ourUserColormapTable = Table(); |
54 + | std::shared_ptr<Table> ColormapDefinition::ourDefaultColormapTable; |
55 + | std::shared_ptr<Table> ColormapDefinition::ourUserColormapTable; |
56 56 | |
57 57 | ColormapDefinition::ColormapDefinition() : |
58 58 | itsReds(1u,0.0), |
59 59 | itsGreens(1u,0.0), |
60 60 | itsBlues(1u,0.0) { |
61 61 | } |
62 62 | |
63 63 | ColormapDefinition::ColormapDefinition(const String & mapName) : |
64 64 | itsName(mapName), |
65 65 | itsReds(1u,0.0), |
70 70 | if (ourDefaultColormap.empty()) { |
71 71 | Aipsrc::find(ColormapDefinition::ourDefaultColormap, |
72 72 | "display.colormaps.defaultcolormap","Greyscale 1"); |
73 73 | } |
74 74 | |
75 75 | if (itsName == "<default>") { |
76 76 | itsName = ourDefaultColormap; |
77 77 | } |
78 78 | Bool ok = loadBuiltinColormap(itsName); |
79 79 | // if colormap tables haven't been read yet, do this |
80 - | if (ourDefaultColormapTable.isNull() && ourUserColormapTable.isNull()) { |
80 + | if ( ! ourDefaultColormapTable && ! ourUserColormapTable ) { |
81 81 | loadColormapTable(); |
82 82 | } |
83 83 | |
84 84 | if (!ok) { |
85 85 | // not the buitlin colormap |
86 86 | ok = loadColormap(itsName); |
87 87 | } |
88 88 | if ( !ok ) { |
89 89 | // .aipsrc has wrong entry set everything to builtin |
90 90 | ourDefaultColormap = "Greyscale 1"; |
163 163 | String root = Aipsrc::aipsRoot(); |
164 164 | defaultpath = root+"/data/gui/colormaps/default.tbl"; |
165 165 | } |
166 166 | String useSystemCmap; |
167 167 | String altpath,userpath; |
168 168 | Aipsrc::find(useSystemCmap,"display.colormaps.usedefault","yes"); |
169 169 | Aipsrc::find(userpath,"display.colormaps.usertable",""); |
170 170 | try { |
171 171 | if (!useSystemCmap.matches(Regex("[ \t]*(([nN]o)|([fF]alse))[ \t\n]*"))) { |
172 172 | // default cmaps |
173 - | ourDefaultColormapTable = Table(defaultpath); |
173 + | ourDefaultColormapTable.reset(new Table(defaultpath)); |
174 174 | if (!userpath.empty()) { |
175 175 | // default and user cmaps |
176 - | ourUserColormapTable = Table(userpath); |
176 + | ourUserColormapTable.reset(new Table(userpath)); |
177 177 | } |
178 178 | } else { |
179 179 | if (!userpath.empty()) { |
180 180 | // user cmaps only |
181 - | ourUserColormapTable = Table(userpath); |
181 + | ourUserColormapTable.reset(new Table(userpath)); |
182 182 | } |
183 183 | } |
184 184 | } catch (const AipsError &x) { |
185 185 | fprintf( stderr, "fatal error, could not read default colormaps: %s\n", x.what() ); |
186 186 | exit(1); |
187 187 | } catch (...) { |
188 188 | fprintf( stderr, "fatal error, could not read default colormaps...\n" ); |
189 189 | exit(1); |
190 190 | } |
191 191 | } |
255 255 | itsReds = Vector<Float>(rCol(rowNumber)); |
256 256 | itsGreens = Vector<Float>(gCol(rowNumber)); |
257 257 | itsBlues = Vector<Float>(bCol(rowNumber)); |
258 258 | return true; |
259 259 | } |
260 260 | return false; |
261 261 | } |
262 262 | |
263 263 | Bool ColormapDefinition::loadColormap(const String& name) { |
264 264 | Bool foundName = false; |
265 - | if (!ourDefaultColormapTable.isNull()) { |
266 - | foundName = queryColormapTable(ourDefaultColormapTable, name); |
265 + | if ( ourDefaultColormapTable ) { |
266 + | foundName = queryColormapTable(*ourDefaultColormapTable, name); |
267 267 | } |
268 - | if (!foundName && !ourUserColormapTable.isNull()) { |
269 - | foundName = queryColormapTable(ourUserColormapTable, name); |
268 + | if ( ! foundName && ourUserColormapTable ) { |
269 + | foundName = queryColormapTable(*ourUserColormapTable, name); |
270 270 | } |
271 271 | return foundName; |
272 272 | } |
273 273 | |
274 274 | Bool ColormapDefinition::save(const String &fullPathName, |
275 275 | const Vector<String> &synonyms, |
276 276 | const Bool &/*overwrite*/) const { |
277 277 | Table *tbl = 0; |
278 278 | try { |
279 279 | tbl = new Table(fullPathName, Table::Update); |
344 344 | } |
345 345 | |
346 346 | |
347 347 | std::map<String,bool> ColormapDefinition::builtinColormapNames(Bool /*uniqueonly*/) { |
348 348 | // uniqueonly is not used at the moment |
349 349 | // static data members |
350 350 | if (ourDefaultColormap.empty()) { |
351 351 | Aipsrc::find(ColormapDefinition::ourDefaultColormap, |
352 352 | "display.colormaps.defaultcolormap","Greyscale 1"); |
353 353 | } |
354 - | if (ourDefaultColormapTable.isNull() && ourUserColormapTable.isNull()) { |
354 + | if ( ! ourDefaultColormapTable && ! ourUserColormapTable ) { |
355 355 | loadColormapTable(); |
356 356 | } |
357 357 | // |
358 358 | uInt defaultLength = 0; |
359 359 | uInt userLength = 0; |
360 360 | |
361 361 | colormapnamemap vec; |
362 362 | ScalarColumn<String>* name1Col(0); |
363 363 | ScalarColumn<String>* name2Col(0); |
364 - | if (!ourDefaultColormapTable.isNull()) { |
365 - | name1Col = new ScalarColumn<String>(ourDefaultColormapTable, "CMAP_NAME"); |
366 - | defaultLength = ourDefaultColormapTable.nrow(); |
364 + | if ( ourDefaultColormapTable ) { |
365 + | name1Col = new ScalarColumn<String>(*ourDefaultColormapTable, "CMAP_NAME"); |
366 + | defaultLength = ourDefaultColormapTable->nrow(); |
367 367 | } |
368 - | if (!ourUserColormapTable.isNull()) { |
369 - | name2Col = new ScalarColumn<String>(ourUserColormapTable, "CMAP_NAME"); |
370 - | userLength = ourUserColormapTable.nrow(); |
368 + | if ( ourUserColormapTable ) { |
369 + | name2Col = new ScalarColumn<String>(*ourUserColormapTable, "CMAP_NAME"); |
370 + | userLength = ourUserColormapTable->nrow(); |
371 371 | } |
372 372 | |
373 373 | vec.insert(colormapnamemap::value_type("Greyscale 1",true)); |
374 374 | |
375 375 | // add colormap table entries |
376 376 | for (uInt i=0; i <defaultLength; i++) { |
377 377 | vec.insert(colormapnamemap::value_type(name1Col->operator()(i),true)); |
378 378 | } |
379 379 | for (uInt i=0; i <userLength; i++) { |
380 380 | vec.insert(colormapnamemap::value_type(name2Col->operator()(i),true)); |