PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Library/VisItLib/avt/DBAtts/MetaData/avtScalarMetaData.C

https://github.com/robertmaynard/VisIt-Bridge
C | 1134 lines | 537 code | 121 blank | 476 comment | 77 complexity | 6550c3688af59657f7f4aee1d9b221d0 MD5 | raw file
  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
  4. * Produced at the Lawrence Livermore National Laboratory
  5. * LLNL-CODE-442911
  6. * All rights reserved.
  7. *
  8. * This file is part of VisIt. For details, see https://visit.llnl.gov/. The
  9. * full copyright notice is contained in the file COPYRIGHT located at the root
  10. * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the disclaimer below.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the disclaimer (as noted below) in the
  19. * documentation and/or other materials provided with the distribution.
  20. * - Neither the name of the LLNS/LLNL nor the names of its contributors may
  21. * be used to endorse or promote products derived from this software without
  22. * specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
  28. * LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
  29. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  35. * DAMAGE.
  36. *
  37. *****************************************************************************/
  38. #include <avtScalarMetaData.h>
  39. #include <DataNode.h>
  40. #include <ImproperUseException.h>
  41. //
  42. // Enum conversion methods for avtScalarMetaData::PartialCellModes
  43. //
  44. static const char *PartialCellModes_strings[] = {
  45. "Include", "Exclude", "Dissect"
  46. };
  47. std::string
  48. avtScalarMetaData::PartialCellModes_ToString(avtScalarMetaData::PartialCellModes t)
  49. {
  50. int index = int(t);
  51. if(index < 0 || index >= 3) index = 0;
  52. return PartialCellModes_strings[index];
  53. }
  54. std::string
  55. avtScalarMetaData::PartialCellModes_ToString(int t)
  56. {
  57. int index = (t < 0 || t >= 3) ? 0 : t;
  58. return PartialCellModes_strings[index];
  59. }
  60. bool
  61. avtScalarMetaData::PartialCellModes_FromString(const std::string &s, avtScalarMetaData::PartialCellModes &val)
  62. {
  63. val = avtScalarMetaData::Include;
  64. for(int i = 0; i < 3; ++i)
  65. {
  66. if(s == PartialCellModes_strings[i])
  67. {
  68. val = (PartialCellModes)i;
  69. return true;
  70. }
  71. }
  72. return false;
  73. }
  74. //
  75. // Enum conversion methods for avtScalarMetaData::EnumTypes
  76. //
  77. static const char *EnumTypes_strings[] = {
  78. "None", "ByValue", "ByRange",
  79. "ByBitMask", "ByNChooseR"};
  80. std::string
  81. avtScalarMetaData::EnumTypes_ToString(avtScalarMetaData::EnumTypes t)
  82. {
  83. int index = int(t);
  84. if(index < 0 || index >= 5) index = 0;
  85. return EnumTypes_strings[index];
  86. }
  87. std::string
  88. avtScalarMetaData::EnumTypes_ToString(int t)
  89. {
  90. int index = (t < 0 || t >= 5) ? 0 : t;
  91. return EnumTypes_strings[index];
  92. }
  93. bool
  94. avtScalarMetaData::EnumTypes_FromString(const std::string &s, avtScalarMetaData::EnumTypes &val)
  95. {
  96. val = avtScalarMetaData::None;
  97. for(int i = 0; i < 5; ++i)
  98. {
  99. if(s == EnumTypes_strings[i])
  100. {
  101. val = (EnumTypes)i;
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. //
  108. // Enum conversion methods for avtScalarMetaData::MissingData
  109. //
  110. static const char *MissingData_strings[] = {
  111. "MissingData_None", "MissingData_Value", "MissingData_Valid_Min",
  112. "MissingData_Valid_Max", "MissingData_Valid_Range"};
  113. std::string
  114. avtScalarMetaData::MissingData_ToString(avtScalarMetaData::MissingData t)
  115. {
  116. int index = int(t);
  117. if(index < 0 || index >= 5) index = 0;
  118. return MissingData_strings[index];
  119. }
  120. std::string
  121. avtScalarMetaData::MissingData_ToString(int t)
  122. {
  123. int index = (t < 0 || t >= 5) ? 0 : t;
  124. return MissingData_strings[index];
  125. }
  126. bool
  127. avtScalarMetaData::MissingData_FromString(const std::string &s, avtScalarMetaData::MissingData &val)
  128. {
  129. val = avtScalarMetaData::MissingData_None;
  130. for(int i = 0; i < 5; ++i)
  131. {
  132. if(s == MissingData_strings[i])
  133. {
  134. val = (MissingData)i;
  135. return true;
  136. }
  137. }
  138. return false;
  139. }
  140. // ****************************************************************************
  141. // Method: avtScalarMetaData::avtScalarMetaData
  142. //
  143. // Purpose:
  144. // Init utility for the avtScalarMetaData class.
  145. //
  146. // Note: Autogenerated by xml2atts.
  147. //
  148. // Programmer: xml2atts
  149. // Creation: omitted
  150. //
  151. // Modifications:
  152. //
  153. // ****************************************************************************
  154. void avtScalarMetaData::Init()
  155. {
  156. treatAsASCII = false;
  157. enumerationType = None;
  158. enumAlwaysExclude[0] = +DBL_MAX;
  159. enumAlwaysExclude[1] = -DBL_MAX;
  160. enumAlwaysInclude[0] = +DBL_MAX;
  161. enumAlwaysInclude[1] = -DBL_MAX;
  162. enumPartialCellMode = Exclude;
  163. enumNChooseRN = 0;
  164. enumNChooseRMaxR = 0;
  165. missingDataType = MissingData_None;
  166. missingData[0] = 0;
  167. missingData[1] = 0;
  168. avtScalarMetaData::SelectAll();
  169. }
  170. // ****************************************************************************
  171. // Method: avtScalarMetaData::avtScalarMetaData
  172. //
  173. // Purpose:
  174. // Copy utility for the avtScalarMetaData class.
  175. //
  176. // Note: Autogenerated by xml2atts.
  177. //
  178. // Programmer: xml2atts
  179. // Creation: omitted
  180. //
  181. // Modifications:
  182. //
  183. // ****************************************************************************
  184. void avtScalarMetaData::Copy(const avtScalarMetaData &obj)
  185. {
  186. treatAsASCII = obj.treatAsASCII;
  187. enumerationType = obj.enumerationType;
  188. enumNames = obj.enumNames;
  189. enumRanges = obj.enumRanges;
  190. enumAlwaysExclude[0] = obj.enumAlwaysExclude[0];
  191. enumAlwaysExclude[1] = obj.enumAlwaysExclude[1];
  192. enumAlwaysInclude[0] = obj.enumAlwaysInclude[0];
  193. enumAlwaysInclude[1] = obj.enumAlwaysInclude[1];
  194. enumPartialCellMode = obj.enumPartialCellMode;
  195. enumGraphEdges = obj.enumGraphEdges;
  196. enumNChooseRN = obj.enumNChooseRN;
  197. enumNChooseRMaxR = obj.enumNChooseRMaxR;
  198. missingDataType = obj.missingDataType;
  199. missingData[0] = obj.missingData[0];
  200. missingData[1] = obj.missingData[1];
  201. avtScalarMetaData::SelectAll();
  202. }
  203. // Type map format string
  204. const char *avtScalarMetaData::TypeMapFormatString = AVTSCALARMETADATA_TMFS;
  205. const AttributeGroup::private_tmfs_t avtScalarMetaData::TmfsStruct = {AVTSCALARMETADATA_TMFS};
  206. // ****************************************************************************
  207. // Method: avtScalarMetaData::avtScalarMetaData
  208. //
  209. // Purpose:
  210. // Default constructor for the avtScalarMetaData class.
  211. //
  212. // Note: Autogenerated by xml2atts.
  213. //
  214. // Programmer: xml2atts
  215. // Creation: omitted
  216. //
  217. // Modifications:
  218. //
  219. // ****************************************************************************
  220. avtScalarMetaData::avtScalarMetaData() :
  221. avtVarMetaData(avtScalarMetaData::TmfsStruct)
  222. {
  223. avtScalarMetaData::Init();
  224. }
  225. // ****************************************************************************
  226. // Method: avtScalarMetaData::avtScalarMetaData
  227. //
  228. // Purpose:
  229. // Constructor for the derived classes of avtScalarMetaData class.
  230. //
  231. // Note: Autogenerated by xml2atts.
  232. //
  233. // Programmer: xml2atts
  234. // Creation: omitted
  235. //
  236. // Modifications:
  237. //
  238. // ****************************************************************************
  239. avtScalarMetaData::avtScalarMetaData(private_tmfs_t tmfs) :
  240. avtVarMetaData(tmfs)
  241. {
  242. avtScalarMetaData::Init();
  243. }
  244. // ****************************************************************************
  245. // Method: avtScalarMetaData::avtScalarMetaData
  246. //
  247. // Purpose:
  248. // Copy constructor for the avtScalarMetaData class.
  249. //
  250. // Note: Autogenerated by xml2atts.
  251. //
  252. // Programmer: xml2atts
  253. // Creation: omitted
  254. //
  255. // Modifications:
  256. //
  257. // ****************************************************************************
  258. avtScalarMetaData::avtScalarMetaData(const avtScalarMetaData &obj) :
  259. avtVarMetaData(obj,avtScalarMetaData::TmfsStruct)
  260. {
  261. avtScalarMetaData::Copy(obj);
  262. }
  263. // ****************************************************************************
  264. // Method: avtScalarMetaData::avtScalarMetaData
  265. //
  266. // Purpose:
  267. // Copy constructor for derived classes of the avtScalarMetaData class.
  268. //
  269. // Note: Autogenerated by xml2atts.
  270. //
  271. // Programmer: xml2atts
  272. // Creation: omitted
  273. //
  274. // Modifications:
  275. //
  276. // ****************************************************************************
  277. avtScalarMetaData::avtScalarMetaData(const avtScalarMetaData &obj, private_tmfs_t tmfs) :
  278. avtVarMetaData(obj,tmfs)
  279. {
  280. avtScalarMetaData::Copy(obj);
  281. }
  282. // ****************************************************************************
  283. // Method: avtScalarMetaData::~avtScalarMetaData
  284. //
  285. // Purpose:
  286. // Destructor for the avtScalarMetaData class.
  287. //
  288. // Note: Autogenerated by xml2atts.
  289. //
  290. // Programmer: xml2atts
  291. // Creation: omitted
  292. //
  293. // Modifications:
  294. //
  295. // ****************************************************************************
  296. avtScalarMetaData::~avtScalarMetaData()
  297. {
  298. // nothing here
  299. }
  300. // ****************************************************************************
  301. // Method: avtScalarMetaData::operator =
  302. //
  303. // Purpose:
  304. // Assignment operator for the avtScalarMetaData class.
  305. //
  306. // Note: Autogenerated by xml2atts.
  307. //
  308. // Programmer: xml2atts
  309. // Creation: omitted
  310. //
  311. // Modifications:
  312. //
  313. // ****************************************************************************
  314. avtScalarMetaData&
  315. avtScalarMetaData::operator = (const avtScalarMetaData &obj)
  316. {
  317. if (this == &obj) return *this;
  318. // call the base class' assignment operator first
  319. avtVarMetaData::operator=(obj);
  320. avtScalarMetaData::Copy(obj);
  321. return *this;
  322. }
  323. // ****************************************************************************
  324. // Method: avtScalarMetaData::operator ==
  325. //
  326. // Purpose:
  327. // Comparison operator == for the avtScalarMetaData class.
  328. //
  329. // Note: Autogenerated by xml2atts.
  330. //
  331. // Programmer: xml2atts
  332. // Creation: omitted
  333. //
  334. // Modifications:
  335. //
  336. // ****************************************************************************
  337. bool
  338. avtScalarMetaData::operator == (const avtScalarMetaData &obj) const
  339. {
  340. // Compare the enumAlwaysExclude arrays.
  341. bool enumAlwaysExclude_equal = true;
  342. for(int i = 0; i < 2 && enumAlwaysExclude_equal; ++i)
  343. enumAlwaysExclude_equal = (enumAlwaysExclude[i] == obj.enumAlwaysExclude[i]);
  344. // Compare the enumAlwaysInclude arrays.
  345. bool enumAlwaysInclude_equal = true;
  346. for(int i = 0; i < 2 && enumAlwaysInclude_equal; ++i)
  347. enumAlwaysInclude_equal = (enumAlwaysInclude[i] == obj.enumAlwaysInclude[i]);
  348. // Compare the missingData arrays.
  349. bool missingData_equal = true;
  350. for(int i = 0; i < 2 && missingData_equal; ++i)
  351. missingData_equal = (missingData[i] == obj.missingData[i]);
  352. // Create the return value
  353. return ((treatAsASCII == obj.treatAsASCII) &&
  354. (enumerationType == obj.enumerationType) &&
  355. (enumNames == obj.enumNames) &&
  356. (enumRanges == obj.enumRanges) &&
  357. enumAlwaysExclude_equal &&
  358. enumAlwaysInclude_equal &&
  359. (enumPartialCellMode == obj.enumPartialCellMode) &&
  360. (enumGraphEdges == obj.enumGraphEdges) &&
  361. (enumNChooseRN == obj.enumNChooseRN) &&
  362. (enumNChooseRMaxR == obj.enumNChooseRMaxR) &&
  363. (missingDataType == obj.missingDataType) &&
  364. missingData_equal &&
  365. avtVarMetaData::operator==(obj));
  366. }
  367. // ****************************************************************************
  368. // Method: avtScalarMetaData::operator !=
  369. //
  370. // Purpose:
  371. // Comparison operator != for the avtScalarMetaData class.
  372. //
  373. // Note: Autogenerated by xml2atts.
  374. //
  375. // Programmer: xml2atts
  376. // Creation: omitted
  377. //
  378. // Modifications:
  379. //
  380. // ****************************************************************************
  381. bool
  382. avtScalarMetaData::operator != (const avtScalarMetaData &obj) const
  383. {
  384. return !(this->operator == (obj));
  385. }
  386. // ****************************************************************************
  387. // Method: avtScalarMetaData::TypeName
  388. //
  389. // Purpose:
  390. // Type name method for the avtScalarMetaData class.
  391. //
  392. // Note: Autogenerated by xml2atts.
  393. //
  394. // Programmer: xml2atts
  395. // Creation: omitted
  396. //
  397. // Modifications:
  398. //
  399. // ****************************************************************************
  400. const std::string
  401. avtScalarMetaData::TypeName() const
  402. {
  403. return "avtScalarMetaData";
  404. }
  405. // ****************************************************************************
  406. // Method: avtScalarMetaData::CopyAttributes
  407. //
  408. // Purpose:
  409. // CopyAttributes method for the avtScalarMetaData class.
  410. //
  411. // Note: Autogenerated by xml2atts.
  412. //
  413. // Programmer: xml2atts
  414. // Creation: omitted
  415. //
  416. // Modifications:
  417. //
  418. // ****************************************************************************
  419. bool
  420. avtScalarMetaData::CopyAttributes(const AttributeGroup *atts)
  421. {
  422. if(TypeName() != atts->TypeName())
  423. return false;
  424. // Call assignment operator.
  425. const avtScalarMetaData *tmp = (const avtScalarMetaData *)atts;
  426. *this = *tmp;
  427. return true;
  428. }
  429. // ****************************************************************************
  430. // Method: avtScalarMetaData::CreateCompatible
  431. //
  432. // Purpose:
  433. // CreateCompatible method for the avtScalarMetaData class.
  434. //
  435. // Note: Autogenerated by xml2atts.
  436. //
  437. // Programmer: xml2atts
  438. // Creation: omitted
  439. //
  440. // Modifications:
  441. //
  442. // ****************************************************************************
  443. AttributeSubject *
  444. avtScalarMetaData::CreateCompatible(const std::string &tname) const
  445. {
  446. AttributeSubject *retval = 0;
  447. if(TypeName() == tname)
  448. retval = new avtScalarMetaData(*this);
  449. // Other cases could go here too.
  450. return retval;
  451. }
  452. // ****************************************************************************
  453. // Method: avtScalarMetaData::NewInstance
  454. //
  455. // Purpose:
  456. // NewInstance method for the avtScalarMetaData class.
  457. //
  458. // Note: Autogenerated by xml2atts.
  459. //
  460. // Programmer: xml2atts
  461. // Creation: omitted
  462. //
  463. // Modifications:
  464. //
  465. // ****************************************************************************
  466. AttributeSubject *
  467. avtScalarMetaData::NewInstance(bool copy) const
  468. {
  469. AttributeSubject *retval = 0;
  470. if(copy)
  471. retval = new avtScalarMetaData(*this);
  472. else
  473. retval = new avtScalarMetaData;
  474. return retval;
  475. }
  476. // ****************************************************************************
  477. // Method: avtScalarMetaData::SelectAll
  478. //
  479. // Purpose:
  480. // Selects all attributes.
  481. //
  482. // Note: Autogenerated by xml2atts.
  483. //
  484. // Programmer: xml2atts
  485. // Creation: omitted
  486. //
  487. // Modifications:
  488. //
  489. // ****************************************************************************
  490. void
  491. avtScalarMetaData::SelectAll()
  492. {
  493. // call the base class' SelectAll() first
  494. avtVarMetaData::SelectAll();
  495. Select(ID_treatAsASCII, (void *)&treatAsASCII);
  496. Select(ID_enumerationType, (void *)&enumerationType);
  497. Select(ID_enumNames, (void *)&enumNames);
  498. Select(ID_enumRanges, (void *)&enumRanges);
  499. Select(ID_enumAlwaysExclude, (void *)enumAlwaysExclude, 2);
  500. Select(ID_enumAlwaysInclude, (void *)enumAlwaysInclude, 2);
  501. Select(ID_enumPartialCellMode, (void *)&enumPartialCellMode);
  502. Select(ID_enumGraphEdges, (void *)&enumGraphEdges);
  503. Select(ID_enumNChooseRN, (void *)&enumNChooseRN);
  504. Select(ID_enumNChooseRMaxR, (void *)&enumNChooseRMaxR);
  505. Select(ID_missingDataType, (void *)&missingDataType);
  506. Select(ID_missingData, (void *)missingData, 2);
  507. }
  508. ///////////////////////////////////////////////////////////////////////////////
  509. // Set property methods
  510. ///////////////////////////////////////////////////////////////////////////////
  511. void
  512. avtScalarMetaData::SetEnumerationType(avtScalarMetaData::EnumTypes enumerationType_)
  513. {
  514. enumerationType = enumerationType_;
  515. Select(ID_enumerationType, (void *)&enumerationType);
  516. }
  517. void
  518. avtScalarMetaData::SetEnumPartialCellMode(avtScalarMetaData::PartialCellModes enumPartialCellMode_)
  519. {
  520. enumPartialCellMode = enumPartialCellMode_;
  521. Select(ID_enumPartialCellMode, (void *)&enumPartialCellMode);
  522. }
  523. void
  524. avtScalarMetaData::SetEnumNChooseRN(int enumNChooseRN_)
  525. {
  526. enumNChooseRN = enumNChooseRN_;
  527. Select(ID_enumNChooseRN, (void *)&enumNChooseRN);
  528. }
  529. void
  530. avtScalarMetaData::SetEnumNChooseRMaxR(int enumNChooseRMaxR_)
  531. {
  532. enumNChooseRMaxR = enumNChooseRMaxR_;
  533. Select(ID_enumNChooseRMaxR, (void *)&enumNChooseRMaxR);
  534. }
  535. void
  536. avtScalarMetaData::SetMissingDataType(avtScalarMetaData::MissingData missingDataType_)
  537. {
  538. missingDataType = missingDataType_;
  539. Select(ID_missingDataType, (void *)&missingDataType);
  540. }
  541. void
  542. avtScalarMetaData::SetMissingData(const double *missingData_)
  543. {
  544. missingData[0] = missingData_[0];
  545. missingData[1] = missingData_[1];
  546. Select(ID_missingData, (void *)missingData, 2);
  547. }
  548. ///////////////////////////////////////////////////////////////////////////////
  549. // Get property methods
  550. ///////////////////////////////////////////////////////////////////////////////
  551. avtScalarMetaData::EnumTypes
  552. avtScalarMetaData::GetEnumerationType() const
  553. {
  554. return EnumTypes(enumerationType);
  555. }
  556. avtScalarMetaData::PartialCellModes
  557. avtScalarMetaData::GetEnumPartialCellMode() const
  558. {
  559. return PartialCellModes(enumPartialCellMode);
  560. }
  561. int
  562. avtScalarMetaData::GetEnumNChooseRN() const
  563. {
  564. return enumNChooseRN;
  565. }
  566. int
  567. avtScalarMetaData::GetEnumNChooseRMaxR() const
  568. {
  569. return enumNChooseRMaxR;
  570. }
  571. avtScalarMetaData::MissingData
  572. avtScalarMetaData::GetMissingDataType() const
  573. {
  574. return MissingData(missingDataType);
  575. }
  576. const double *
  577. avtScalarMetaData::GetMissingData() const
  578. {
  579. return missingData;
  580. }
  581. double *
  582. avtScalarMetaData::GetMissingData()
  583. {
  584. return missingData;
  585. }
  586. ///////////////////////////////////////////////////////////////////////////////
  587. // Select property methods
  588. ///////////////////////////////////////////////////////////////////////////////
  589. void
  590. avtScalarMetaData::SelectMissingData()
  591. {
  592. Select(ID_missingData, (void *)missingData, 2);
  593. }
  594. ///////////////////////////////////////////////////////////////////////////////
  595. // User-defined methods.
  596. ///////////////////////////////////////////////////////////////////////////////
  597. // ****************************************************************************
  598. // Method: avtScalarMetaData constructor
  599. //
  600. // Arguments:
  601. // n The name of the scalar variable.
  602. // mn The name of the mesh the scalar var is defined on.
  603. // c The centering of the variable.
  604. //
  605. // Programmer: Hank Childs
  606. // Creation: August 25, 2000
  607. //
  608. // Modifications:
  609. // Hank Childs, Mon Dec 9 17:04:39 PST 2002
  610. // Initialized validVariable.
  611. //
  612. // Brad Whitlock, Tue Jul 20 13:44:42 PST 2004
  613. // Added units.
  614. //
  615. // Kathleen Bonnell, Thu Jul 22 12:10:19 PDT 2004
  616. // Initialized treatAsASCII.
  617. //
  618. // Hank Childs, Mon Feb 14 14:16:49 PST 2005
  619. // Added original name.
  620. //
  621. // Jeremy Meredith, Fri Aug 25 17:16:38 EDT 2006
  622. // Added enumerated scalars.
  623. //
  624. // Mark C. Miller, Wed Mar 26 10:11:46 PDT 2008
  625. // Added initialization for other enumerated scalar options
  626. // and hideFromGUI.
  627. //
  628. // ****************************************************************************
  629. avtScalarMetaData::avtScalarMetaData(std::string n, std::string mn,
  630. avtCentering c)
  631. : avtVarMetaData(avtScalarMetaData::TmfsStruct, n, mn, c)
  632. {
  633. avtScalarMetaData::Init();
  634. }
  635. // ****************************************************************************
  636. // Method: avtScalarMetaData constructor
  637. //
  638. // Arguments:
  639. // n The name of the scalar variable.
  640. // mn The name of the mesh the scalar var is defined on.
  641. // c The centering of the variable.
  642. // min The minimum value of the scalar variable.
  643. // max The maximum value of the scalar variable.
  644. //
  645. // Programmer: Hank Childs
  646. // Creation: August 25, 2000
  647. //
  648. // Modifications:
  649. // Hank Childs, Mon Dec 9 17:04:39 PST 2002
  650. // Initialized validVariable.
  651. //
  652. // Brad Whitlock, Tue Jul 20 13:45:12 PST 2004
  653. // Added units.
  654. //
  655. // Kathleen Bonnell, Thu Jul 22 12:10:19 PDT 2004
  656. // Initialized treatAsASCII.
  657. //
  658. // Hank Childs, Mon Feb 14 14:16:49 PST 2005
  659. // Added original name.
  660. //
  661. // Jeremy Meredith, Fri Aug 25 17:16:38 EDT 2006
  662. // Added enumerated scalars.
  663. //
  664. // Mark C. Miller, Wed Mar 26 10:11:46 PDT 2008
  665. // Added initialization for other enumerated scalar options
  666. // and hideFromGUI.
  667. //
  668. // ****************************************************************************
  669. avtScalarMetaData::avtScalarMetaData(std::string n, std::string mn,
  670. avtCentering c, double min, double max)
  671. : avtVarMetaData(avtScalarMetaData::TmfsStruct, n, mn, c, min, max)
  672. {
  673. avtScalarMetaData::Init();
  674. }
  675. // ****************************************************************************
  676. // Method: avtScalarMetaData::Print
  677. //
  678. // Purpose:
  679. // Print statement for debugging.
  680. //
  681. // Arguments:
  682. // out The stream to output to.
  683. // indent The number of tabs to indent each line with.
  684. //
  685. // Programmer: Hank Childs
  686. // Creation: August 28, 2000
  687. //
  688. // Modifications:
  689. // Hank Childs, Mon Dec 9 17:04:39 PST 2002
  690. // Print out validVariable.
  691. //
  692. // Kathleen Bonnell, Thu Jul 22 12:10:19 PDT 2004
  693. // Print out treatAsASCII.
  694. //
  695. // Brad Whitlock, Tue Jul 20 13:47:04 PST 2004
  696. // Added units.
  697. //
  698. // Hank Childs, Mon Feb 14 14:16:49 PST 2005
  699. // Added original name.
  700. //
  701. // Jeremy Meredith, Fri Aug 25 17:16:38 EDT 2006
  702. // Added enumerated scalars.
  703. //
  704. // Brad Whitlock, Wed Jan 4 14:58:08 PST 2012
  705. // Added missing data values.
  706. //
  707. // ****************************************************************************
  708. inline void
  709. Indent(ostream &out, int indent)
  710. {
  711. for (int i = 0 ; i < indent ; i++)
  712. {
  713. out << "\t";
  714. }
  715. }
  716. void
  717. avtScalarMetaData::Print(ostream &out, int indent) const
  718. {
  719. avtVarMetaData::Print(out, indent);
  720. if (treatAsASCII)
  721. {
  722. Indent(out, indent);
  723. out << "This variable should be treated as ASCII." << endl;
  724. }
  725. if (enumerationType != None)
  726. {
  727. Indent(out, indent);
  728. out << "This variable contains enumerated values." << endl;
  729. }
  730. else
  731. {
  732. Indent(out, indent);
  733. out << "This variable does not contain enumerated values." << endl;
  734. }
  735. switch(missingDataType)
  736. {
  737. case MissingData_Value:
  738. Indent(out, indent);
  739. out << "Missing value: " << missingData[0] << endl;
  740. break;
  741. case MissingData_Valid_Min:
  742. Indent(out, indent);
  743. out << "Missing value less than: " << missingData[0] << endl;
  744. break;
  745. case MissingData_Valid_Max:
  746. Indent(out, indent);
  747. out << "Missing value greater than: " << missingData[0] << endl;
  748. break;
  749. case MissingData_Valid_Range:
  750. Indent(out, indent);
  751. out << "Missing value outside range: ["
  752. << missingData[0] << ", " << missingData[1] << "]" << endl;
  753. break;
  754. default:
  755. break;
  756. }
  757. }
  758. void
  759. avtScalarMetaData::AddEnumGraphEdge(int head, int tail)
  760. {
  761. enumGraphEdges.push_back(head);
  762. enumGraphEdges.push_back(tail);
  763. }
  764. // ****************************************************************************
  765. // Method: AddEnumNameValue
  766. //
  767. // Purpose: Add name/value pair to an enumeration
  768. //
  769. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  770. // ****************************************************************************
  771. int
  772. avtScalarMetaData::AddEnumNameValue(std::string name, double val)
  773. {
  774. enumNames.push_back(name);
  775. enumRanges.push_back(val);
  776. enumRanges.push_back(val);
  777. return (int)enumNames.size() - 1;
  778. }
  779. // ****************************************************************************
  780. // Method: AddEnumNameRange
  781. //
  782. // Purpose: Add name/range pair to an enumeration
  783. //
  784. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  785. // ****************************************************************************
  786. int
  787. avtScalarMetaData::AddEnumNameRange(std::string name, double min, double max)
  788. {
  789. if (min > max)
  790. {
  791. EXCEPTION1(ImproperUseException, name);
  792. }
  793. enumNames.push_back(name);
  794. enumRanges.push_back(min);
  795. enumRanges.push_back(max);
  796. return (int)enumNames.size() - 1;
  797. }
  798. // ****************************************************************************
  799. // Method: SetEnumAlwaysExcludeValue
  800. //
  801. // Purpose: sets value to be used for always excluded in the selection
  802. //
  803. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  804. // ****************************************************************************
  805. void
  806. avtScalarMetaData::SetEnumAlwaysExcludeValue(double val)
  807. {
  808. enumAlwaysExclude[0] = val;
  809. enumAlwaysExclude[1] = val;
  810. }
  811. // ****************************************************************************
  812. // Method: SetEnumAlwaysExcludeRange
  813. //
  814. // Purpose: sets range to be used for always excluded in the selection
  815. //
  816. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  817. // ****************************************************************************
  818. void
  819. avtScalarMetaData::SetEnumAlwaysExcludeRange(double min, double max)
  820. {
  821. enumAlwaysExclude[0] = min;
  822. enumAlwaysExclude[1] = max;
  823. }
  824. // ****************************************************************************
  825. // Method: SetEnumAlwaysIncludeValue
  826. //
  827. // Purpose: sets value to be used for always included in the selection
  828. //
  829. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  830. // ****************************************************************************
  831. void
  832. avtScalarMetaData::SetEnumAlwaysIncludeValue(double val)
  833. {
  834. enumAlwaysInclude[0] = val;
  835. enumAlwaysInclude[1] = val;
  836. }
  837. // ****************************************************************************
  838. // Method: SetEnumAlwaysIncludeRange
  839. //
  840. // Purpose: sets range to be used for always included in the selection
  841. //
  842. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  843. // ****************************************************************************
  844. void
  845. avtScalarMetaData::SetEnumAlwaysIncludeRange(double min, double max)
  846. {
  847. enumAlwaysInclude[0] = min;
  848. enumAlwaysInclude[1] = max;
  849. }
  850. // ****************************************************************************
  851. // Method: BuildEnumNChooseRMap
  852. //
  853. // Purpose: convenience method for caller to build a pascal's triangle map
  854. // for given N/MaxR
  855. //
  856. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  857. // ****************************************************************************
  858. void
  859. avtScalarMetaData::BuildEnumNChooseRMap(int n, int maxr, std::vector<std::vector<int> > &ptMap)
  860. {
  861. for (size_t row = 0; row < ptMap.size(); row++)
  862. ptMap[row].clear();
  863. ptMap.clear();
  864. for (int row = 0; row < n; row++)
  865. {
  866. std::vector<int> tmpRow;
  867. for (int col = 0; col <= maxr; col++)
  868. tmpRow.push_back(0);
  869. ptMap.push_back(tmpRow);
  870. }
  871. for (int row = 0; row < n; row++)
  872. for (int col = 0; col <= maxr; col++)
  873. ptMap[row][col] = int(NChooseR(n-row-1,col));
  874. }
  875. // ****************************************************************************
  876. // Function: Bi-nomial coefficient (n-choose-r)
  877. //
  878. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  879. //
  880. // Modifications:
  881. // Jeremy Meredith, Thu Aug 7 14:24:38 EDT 2008
  882. // Made it member function so that we got the static namespace benefits
  883. // without the warnings that static functions in headers tend to generate.
  884. //
  885. // ****************************************************************************
  886. double avtScalarMetaData::NChooseR(int n, int r)
  887. {
  888. if (n == 0)
  889. {
  890. if (r == 0)
  891. return 1;
  892. else
  893. return 0;
  894. }
  895. double result = 1;
  896. int k = 1;
  897. for (int i = r+1; i <=n; i++)
  898. {
  899. result *= (double) i;
  900. if (k <= n-r)
  901. {
  902. result /= (double) k;
  903. k++;
  904. }
  905. }
  906. return result;
  907. }
  908. // ****************************************************************************
  909. // Function: ComboValFromDigits
  910. //
  911. // Purpose: Internal function to compute NChooseR value from list of
  912. // ids (digits representing enum set membership)
  913. //
  914. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  915. //
  916. // Modifications:
  917. // Jeremy Meredith, Thu Aug 7 14:24:38 EDT 2008
  918. // Made it member function so that we got the static namespace benefits
  919. // without the warnings that static functions in headers tend to generate.
  920. //
  921. // ****************************************************************************
  922. void
  923. avtScalarMetaData::ComboValFromDigits(const std::vector<std::vector<int> > &ptMap,
  924. const std::list<int> &digits, double *id)
  925. {
  926. int row, col;
  927. *id = 0.0;
  928. std::list<int>::const_reverse_iterator it;
  929. for (col = (int)digits.size()-1, it = digits.rbegin(); col >= 0; col--, it++)
  930. {
  931. for (row = 0; row <= *it; row++)
  932. *id += ptMap[row][col];
  933. }
  934. *id -= 1;
  935. }
  936. // ****************************************************************************
  937. // Function: ComboDigitsFromVal
  938. //
  939. // Purpose: Internal function to compute list of ids (digits representing enum
  940. // set membership) to single numerical value.
  941. //
  942. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  943. //
  944. // Modifications:
  945. // Jeremy Meredith, Thu Aug 7 14:24:38 EDT 2008
  946. // Made it member function so that we got the static namespace benefits
  947. // without the warnings that static functions in headers tend to generate.
  948. //
  949. // ****************************************************************************
  950. void
  951. avtScalarMetaData::ComboDigitsFromVal(double id, int n, int maxr,
  952. const std::vector<std::vector<int> > &ptMap, std::list<int> &digits)
  953. {
  954. int row, col, grp;
  955. for (grp = 1; grp <= maxr; grp++)
  956. {
  957. double grpc = NChooseR(n,grp);
  958. if (id < grpc)
  959. break;
  960. else
  961. id -= grpc;
  962. }
  963. if (grp == maxr+1)
  964. return;
  965. int rowmin = 0;
  966. for (col = grp-1; col >= 0; col--)
  967. {
  968. for (row = rowmin; row < n; row++)
  969. {
  970. int seglen = ptMap[row][col];
  971. if (id < seglen)
  972. {
  973. rowmin = row+1;
  974. digits.push_front(row);
  975. break;
  976. }
  977. id -= seglen;
  978. }
  979. }
  980. }
  981. // ****************************************************************************
  982. // Method: UpdateValByInsertingDigit
  983. //
  984. // Purpose: convenience method for callers to, given a current numerical value
  985. // reprsenting a list of set ids, compute a new numerical value by adding the
  986. // new set id.
  987. //
  988. // Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
  989. // ****************************************************************************
  990. void avtScalarMetaData::UpdateValByInsertingDigit(double *id, int n, int maxr,
  991. const std::vector<std::vector<int> > &ptMap, int newDigit)
  992. {
  993. std::list<int> currentDigits;
  994. ComboDigitsFromVal(*id, n, maxr, ptMap, currentDigits);
  995. std::list<int>::iterator it = currentDigits.begin();
  996. while (it != currentDigits.end() && *it < newDigit)
  997. it++;
  998. if (it == currentDigits.end())
  999. {
  1000. currentDigits.push_front(newDigit);
  1001. ComboValFromDigits(ptMap, currentDigits, id);
  1002. }
  1003. else
  1004. {
  1005. // only update if we actually adding a new digit
  1006. if (newDigit < *it)
  1007. {
  1008. it++;
  1009. currentDigits.insert(it, newDigit);
  1010. ComboValFromDigits(ptMap, currentDigits, id);
  1011. }
  1012. }
  1013. }