avtScalarMetaData.C 30.4 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
/*****************************************************************************
*
brugger's avatar
   
brugger committed
3
* Copyright (c) 2000 - 2009, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
   
brugger committed
5
* LLNL-CODE-400124
hrchilds's avatar
hrchilds committed
6
7
* All rights reserved.
*
brugger's avatar
   
brugger committed
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9
10
11
12
13
14
15
16
17
18
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
brugger's avatar
   
brugger committed
19
20
21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22
23
24
25
26
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
brugger's avatar
   
brugger committed
27
28
29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30
31
32
33
34
35
36
37
38
39
40
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

#include <avtScalarMetaData.h>
#include <DataNode.h>
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <ImproperUseException.h>

//
// Enum conversion methods for avtScalarMetaData::PartialCellModes
//

static const char *PartialCellModes_strings[] = {
"Include", "Exclude", "Dissect"
};

std::string
avtScalarMetaData::PartialCellModes_ToString(avtScalarMetaData::PartialCellModes t)
{
    int index = int(t);
    if(index < 0 || index >= 3) index = 0;
    return PartialCellModes_strings[index];
}

std::string
avtScalarMetaData::PartialCellModes_ToString(int t)
{
    int index = (t < 0 || t >= 3) ? 0 : t;
    return PartialCellModes_strings[index];
}

bool
avtScalarMetaData::PartialCellModes_FromString(const std::string &s, avtScalarMetaData::PartialCellModes &val)
{
    val = avtScalarMetaData::Include;
    for(int i = 0; i < 3; ++i)
    {
        if(s == PartialCellModes_strings[i])
        {
            val = (PartialCellModes)i;
            return true;
        }
    }
    return false;
}

//
// Enum conversion methods for avtScalarMetaData::EnumTypes
//

static const char *EnumTypes_strings[] = {
"None", "ByValue", "ByRange", 
"ByBitMask", "ByNChooseR"};

std::string
avtScalarMetaData::EnumTypes_ToString(avtScalarMetaData::EnumTypes t)
{
    int index = int(t);
    if(index < 0 || index >= 5) index = 0;
    return EnumTypes_strings[index];
}

std::string
avtScalarMetaData::EnumTypes_ToString(int t)
{
    int index = (t < 0 || t >= 5) ? 0 : t;
    return EnumTypes_strings[index];
}

bool
avtScalarMetaData::EnumTypes_FromString(const std::string &s, avtScalarMetaData::EnumTypes &val)
{
    val = avtScalarMetaData::None;
    for(int i = 0; i < 5; ++i)
    {
        if(s == EnumTypes_strings[i])
        {
            val = (EnumTypes)i;
            return true;
        }
    }
    return false;
}
hrchilds's avatar
hrchilds committed
118
119
120
121
122

// ****************************************************************************
// Method: avtScalarMetaData::avtScalarMetaData
//
// Purpose: 
123
//   Init utility for the avtScalarMetaData class.
hrchilds's avatar
hrchilds committed
124
125
126
127
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
128
// Creation:   omitted
hrchilds's avatar
hrchilds committed
129
130
131
132
133
//
// Modifications:
//   
// ****************************************************************************

134
void avtScalarMetaData::Init()
hrchilds's avatar
hrchilds committed
135
136
{
    treatAsASCII = false;
137
138
139
140
141
142
    enumerationType = None;
    enumAlwaysExclude[0] = +DBL_MAX;
    enumAlwaysExclude[1] = -DBL_MAX;
    enumAlwaysInclude[0] = +DBL_MAX;
    enumAlwaysInclude[1] = -DBL_MAX;
    enumPartialCellMode = Exclude;
143
144
    enumNChooseRN = 0;
    enumNChooseRMaxR = 0;
145
146

    avtScalarMetaData::SelectAll();
hrchilds's avatar
hrchilds committed
147
148
149
150
151
152
}

// ****************************************************************************
// Method: avtScalarMetaData::avtScalarMetaData
//
// Purpose: 
153
//   Copy utility for the avtScalarMetaData class.
hrchilds's avatar
hrchilds committed
154
155
156
157
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
158
// Creation:   omitted
hrchilds's avatar
hrchilds committed
159
160
161
162
163
//
// Modifications:
//   
// ****************************************************************************

164
165
void avtScalarMetaData::Copy(const avtScalarMetaData &obj)
{
hrchilds's avatar
hrchilds committed
166
    treatAsASCII = obj.treatAsASCII;
167
    enumerationType = obj.enumerationType;
hrchilds's avatar
hrchilds committed
168
    enumNames = obj.enumNames;
169
170
171
172
173
174
175
176
177
178
179
    enumRanges = obj.enumRanges;
    enumAlwaysExclude[0] = obj.enumAlwaysExclude[0];
    enumAlwaysExclude[1] = obj.enumAlwaysExclude[1];

    enumAlwaysInclude[0] = obj.enumAlwaysInclude[0];
    enumAlwaysInclude[1] = obj.enumAlwaysInclude[1];

    enumPartialCellMode = obj.enumPartialCellMode;
    enumGraphEdges = obj.enumGraphEdges;
    enumNChooseRN = obj.enumNChooseRN;
    enumNChooseRMaxR = obj.enumNChooseRMaxR;
hrchilds's avatar
hrchilds committed
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
    avtScalarMetaData::SelectAll();
}

// Type map format string
const char *avtScalarMetaData::TypeMapFormatString = AVTSCALARMETADATA_TMFS;
const AttributeGroup::private_tmfs_t avtScalarMetaData::TmfsStruct = {AVTSCALARMETADATA_TMFS};


// ****************************************************************************
// Method: avtScalarMetaData::avtScalarMetaData
//
// Purpose: 
//   Default constructor for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

avtScalarMetaData::avtScalarMetaData() : 
    avtVarMetaData(avtScalarMetaData::TmfsStruct)
{
    avtScalarMetaData::Init();
}

// ****************************************************************************
// Method: avtScalarMetaData::avtScalarMetaData
//
// Purpose: 
//   Constructor for the derived classes of avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

avtScalarMetaData::avtScalarMetaData(private_tmfs_t tmfs) : 
    avtVarMetaData(tmfs)
{
    avtScalarMetaData::Init();
}

// ****************************************************************************
// Method: avtScalarMetaData::avtScalarMetaData
//
// Purpose: 
//   Copy constructor for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

avtScalarMetaData::avtScalarMetaData(const avtScalarMetaData &obj) : 
    avtVarMetaData(obj,avtScalarMetaData::TmfsStruct)
{
    avtScalarMetaData::Copy(obj);
}

// ****************************************************************************
// Method: avtScalarMetaData::avtScalarMetaData
//
// Purpose: 
//   Copy constructor for derived classes of the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

avtScalarMetaData::avtScalarMetaData(const avtScalarMetaData &obj, private_tmfs_t tmfs) : 
    avtVarMetaData(obj,tmfs)
{
    avtScalarMetaData::Copy(obj);
hrchilds's avatar
hrchilds committed
271
272
273
274
275
276
277
278
279
280
281
}

// ****************************************************************************
// Method: avtScalarMetaData::~avtScalarMetaData
//
// Purpose: 
//   Destructor for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
282
// Creation:   omitted
hrchilds's avatar
hrchilds committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//
// Modifications:
//   
// ****************************************************************************

avtScalarMetaData::~avtScalarMetaData()
{
    // nothing here
}

// ****************************************************************************
// Method: avtScalarMetaData::operator = 
//
// Purpose: 
//   Assignment operator for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
302
// Creation:   omitted
hrchilds's avatar
hrchilds committed
303
304
305
306
307
308
309
310
311
//
// Modifications:
//   
// ****************************************************************************

avtScalarMetaData& 
avtScalarMetaData::operator = (const avtScalarMetaData &obj)
{
    if (this == &obj) return *this;
312
313
314
315

    // call the base class' assignment operator first
    avtVarMetaData::operator=(obj);

hrchilds's avatar
hrchilds committed
316
    treatAsASCII = obj.treatAsASCII;
317
    enumerationType = obj.enumerationType;
hrchilds's avatar
hrchilds committed
318
    enumNames = obj.enumNames;
319
320
321
322
323
324
325
326
327
328
329
    enumRanges = obj.enumRanges;
    enumAlwaysExclude[0] = obj.enumAlwaysExclude[0];
    enumAlwaysExclude[1] = obj.enumAlwaysExclude[1];

    enumAlwaysInclude[0] = obj.enumAlwaysInclude[0];
    enumAlwaysInclude[1] = obj.enumAlwaysInclude[1];

    enumPartialCellMode = obj.enumPartialCellMode;
    enumGraphEdges = obj.enumGraphEdges;
    enumNChooseRN = obj.enumNChooseRN;
    enumNChooseRMaxR = obj.enumNChooseRMaxR;
hrchilds's avatar
hrchilds committed
330

331
332
    avtScalarMetaData::SelectAll();

hrchilds's avatar
hrchilds committed
333
334
335
336
337
338
339
340
341
342
343
344
    return *this;
}

// ****************************************************************************
// Method: avtScalarMetaData::operator == 
//
// Purpose: 
//   Comparison operator == for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
345
// Creation:   omitted
hrchilds's avatar
hrchilds committed
346
347
348
349
350
351
352
353
//
// Modifications:
//   
// ****************************************************************************

bool
avtScalarMetaData::operator == (const avtScalarMetaData &obj) const
{
354
355
    // Compare the enumAlwaysExclude arrays.
    bool enumAlwaysExclude_equal = true;
356
    for(int i = 0; i < 2 && enumAlwaysExclude_equal; ++i)
357
358
359
360
        enumAlwaysExclude_equal = (enumAlwaysExclude[i] == obj.enumAlwaysExclude[i]);

    // Compare the enumAlwaysInclude arrays.
    bool enumAlwaysInclude_equal = true;
361
    for(int i = 0; i < 2 && enumAlwaysInclude_equal; ++i)
362
363
        enumAlwaysInclude_equal = (enumAlwaysInclude[i] == obj.enumAlwaysInclude[i]);

hrchilds's avatar
hrchilds committed
364
    // Create the return value
365
    return ((treatAsASCII == obj.treatAsASCII) &&
366
            (enumerationType == obj.enumerationType) &&
hrchilds's avatar
hrchilds committed
367
            (enumNames == obj.enumNames) &&
368
369
370
371
372
373
            (enumRanges == obj.enumRanges) &&
            enumAlwaysExclude_equal &&
            enumAlwaysInclude_equal &&
            (enumPartialCellMode == obj.enumPartialCellMode) &&
            (enumGraphEdges == obj.enumGraphEdges) &&
            (enumNChooseRN == obj.enumNChooseRN) &&
374
375
            (enumNChooseRMaxR == obj.enumNChooseRMaxR) &&
            avtVarMetaData::operator==(obj));
hrchilds's avatar
hrchilds committed
376
377
378
379
380
381
382
383
384
385
386
}

// ****************************************************************************
// Method: avtScalarMetaData::operator != 
//
// Purpose: 
//   Comparison operator != for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
387
// Creation:   omitted
hrchilds's avatar
hrchilds committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//
// Modifications:
//   
// ****************************************************************************

bool
avtScalarMetaData::operator != (const avtScalarMetaData &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: avtScalarMetaData::TypeName
//
// Purpose: 
//   Type name method for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
408
// Creation:   omitted
hrchilds's avatar
hrchilds committed
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
//
// Modifications:
//   
// ****************************************************************************

const std::string
avtScalarMetaData::TypeName() const
{
    return "avtScalarMetaData";
}

// ****************************************************************************
// Method: avtScalarMetaData::CopyAttributes
//
// Purpose: 
//   CopyAttributes method for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
429
// Creation:   omitted
hrchilds's avatar
hrchilds committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
//
// Modifications:
//   
// ****************************************************************************

bool
avtScalarMetaData::CopyAttributes(const AttributeGroup *atts)
{
    if(TypeName() != atts->TypeName())
        return false;

    // Call assignment operator.
    const avtScalarMetaData *tmp = (const avtScalarMetaData *)atts;
    *this = *tmp;

    return true;
}

// ****************************************************************************
// Method: avtScalarMetaData::CreateCompatible
//
// Purpose: 
//   CreateCompatible method for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
457
// Creation:   omitted
hrchilds's avatar
hrchilds committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
//
// Modifications:
//   
// ****************************************************************************

AttributeSubject *
avtScalarMetaData::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;
    if(TypeName() == tname)
        retval = new avtScalarMetaData(*this);
    // Other cases could go here too. 

    return retval;
}

// ****************************************************************************
// Method: avtScalarMetaData::NewInstance
//
// Purpose: 
//   NewInstance method for the avtScalarMetaData class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
483
// Creation:   omitted
hrchilds's avatar
hrchilds committed
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
//
// Modifications:
//   
// ****************************************************************************

AttributeSubject *
avtScalarMetaData::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new avtScalarMetaData(*this);
    else
        retval = new avtScalarMetaData;

    return retval;
}

// ****************************************************************************
// Method: avtScalarMetaData::SelectAll
//
// Purpose: 
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
510
// Creation:   omitted
hrchilds's avatar
hrchilds committed
511
512
513
514
515
516
517
518
//
// Modifications:
//   
// ****************************************************************************

void
avtScalarMetaData::SelectAll()
{
519
520
    // call the base class' SelectAll() first
    avtVarMetaData::SelectAll();
521
522
523
524
525
526
527
528
529
530
    Select(ID_treatAsASCII,        (void *)&treatAsASCII);
    Select(ID_enumerationType,     (void *)&enumerationType);
    Select(ID_enumNames,           (void *)&enumNames);
    Select(ID_enumRanges,          (void *)&enumRanges);
    Select(ID_enumAlwaysExclude,   (void *)enumAlwaysExclude, 2);
    Select(ID_enumAlwaysInclude,   (void *)enumAlwaysInclude, 2);
    Select(ID_enumPartialCellMode, (void *)&enumPartialCellMode);
    Select(ID_enumGraphEdges,      (void *)&enumGraphEdges);
    Select(ID_enumNChooseRN,       (void *)&enumNChooseRN);
    Select(ID_enumNChooseRMaxR,    (void *)&enumNChooseRMaxR);
hrchilds's avatar
hrchilds committed
531
532
533
534
535
536
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
void
avtScalarMetaData::SetEnumerationType(avtScalarMetaData::EnumTypes enumerationType_)
{
    enumerationType = enumerationType_;
    Select(ID_enumerationType, (void *)&enumerationType);
}

void
avtScalarMetaData::SetEnumPartialCellMode(avtScalarMetaData::PartialCellModes enumPartialCellMode_)
{
    enumPartialCellMode = enumPartialCellMode_;
    Select(ID_enumPartialCellMode, (void *)&enumPartialCellMode);
}

void
avtScalarMetaData::SetEnumNChooseRN(int enumNChooseRN_)
{
    enumNChooseRN = enumNChooseRN_;
    Select(ID_enumNChooseRN, (void *)&enumNChooseRN);
}

void
avtScalarMetaData::SetEnumNChooseRMaxR(int enumNChooseRMaxR_)
{
    enumNChooseRMaxR = enumNChooseRMaxR_;
    Select(ID_enumNChooseRMaxR, (void *)&enumNChooseRMaxR);
}

hrchilds's avatar
hrchilds committed
565
566
567
568
///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
avtScalarMetaData::EnumTypes
avtScalarMetaData::GetEnumerationType() const
{
    return EnumTypes(enumerationType);
}

avtScalarMetaData::PartialCellModes
avtScalarMetaData::GetEnumPartialCellMode() const
{
    return PartialCellModes(enumPartialCellMode);
}

int
avtScalarMetaData::GetEnumNChooseRN() const
{
    return enumNChooseRN;
}

int
avtScalarMetaData::GetEnumNChooseRMaxR() const
{
    return enumNChooseRMaxR;
}

hrchilds's avatar
hrchilds committed
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
//  Method: avtScalarMetaData constructor
//
//  Arguments:
//      n           The name of the scalar variable.
//      mn          The name of the mesh the scalar var is defined on.
//      c           The centering of the variable.
//
//  Programmer: Hank Childs
//  Creation:   August 25, 2000
//
//  Modifications:
//    Hank Childs, Mon Dec  9 17:04:39 PST 2002
//    Initialized validVariable.
//
//    Brad Whitlock, Tue Jul 20 13:44:42 PST 2004
//    Added units.
//
//    Kathleen Bonnell, Thu Jul 22 12:10:19 PDT 2004 
//    Initialized treatAsASCII.
//
//    Hank Childs, Mon Feb 14 14:16:49 PST 2005
//    Added original name.
//
//    Jeremy Meredith, Fri Aug 25 17:16:38 EDT 2006
//    Added enumerated scalars.
//
624
625
626
627
//    Mark C. Miller, Wed Mar 26 10:11:46 PDT 2008
//    Added initialization for other enumerated scalar options
//    and hideFromGUI.
//
hrchilds's avatar
hrchilds committed
628
629
630
631
// ****************************************************************************

avtScalarMetaData::avtScalarMetaData(std::string n, std::string mn, 
                                     avtCentering c)
632
    : avtVarMetaData(avtScalarMetaData::TmfsStruct)
hrchilds's avatar
hrchilds committed
633
634
{
    // Initialize all values.
635
    avtScalarMetaData::Init();
hrchilds's avatar
hrchilds committed
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672

    // Override some initialization with the passed arguments.
    name           = n;
    originalName   = name;
    meshName       = mn;
    centering      = c;
}

// ****************************************************************************
//  Method: avtScalarMetaData constructor
//
//  Arguments:
//      n           The name of the scalar variable.
//      mn          The name of the mesh the scalar var is defined on.
//      c           The centering of the variable.
//      min         The minimum value of the scalar variable.
//      max         The maximum value of the scalar variable.
//
//  Programmer: Hank Childs
//  Creation:   August 25, 2000
//
//  Modifications:
//    Hank Childs, Mon Dec  9 17:04:39 PST 2002
//    Initialized validVariable.
//
//    Brad Whitlock, Tue Jul 20 13:45:12 PST 2004
//    Added units.
//
//    Kathleen Bonnell, Thu Jul 22 12:10:19 PDT 2004 
//    Initialized treatAsASCII.
//
//    Hank Childs, Mon Feb 14 14:16:49 PST 2005
//    Added original name.
//
//    Jeremy Meredith, Fri Aug 25 17:16:38 EDT 2006
//    Added enumerated scalars.
//
673
674
675
676
//    Mark C. Miller, Wed Mar 26 10:11:46 PDT 2008
//    Added initialization for other enumerated scalar options
//    and hideFromGUI.
//
hrchilds's avatar
hrchilds committed
677
678
679
680
// ****************************************************************************

avtScalarMetaData::avtScalarMetaData(std::string n, std::string mn,
                                     avtCentering c, double min, double max)
681
    : avtVarMetaData(avtScalarMetaData::TmfsStruct)
hrchilds's avatar
hrchilds committed
682
683
{
    // Initialize all values.
684
    avtScalarMetaData::Init();
hrchilds's avatar
hrchilds committed
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776

    // Override some initialization with the passed arguments.
    name           = n;
    originalName   = name;
    meshName       = mn;
    centering      = c;
    double  extents[2] = { min, max };
    SetExtents(extents);
}

// ****************************************************************************
//  Method: avtScalarMetaData::SetExtents
//
//  Purpose:
//      Sets the extents of the scalar variable.
//
//  Arguments:
//      extents     Extents as <min value, max value>.
//
//  Programmer: Hank Childs
//  Creation:   August 30, 2000
//
//  Modifications:
//
//    Hank Childs, Tue May  1 12:53:10 PDT 2001
//    Check for NULL extents.
//
// ****************************************************************************

void
avtScalarMetaData::SetExtents(const double *extents)
{
    if (extents == NULL)
    {
        hasDataExtents = false;
    }
    else
    {
        hasDataExtents = true;
        minDataExtents = extents[0];
        maxDataExtents = extents[1];
    }
}

void
avtScalarMetaData::UnsetExtents()
{
    hasDataExtents = false;
}

// ****************************************************************************
//  Method: avtScalarMetaData::Print
//
//  Purpose:
//      Print statement for debugging.
//
//  Arguments:
//      out      The stream to output to.
//      indent   The number of tabs to indent each line with.
//
//  Programmer:  Hank Childs
//  Creation:    August 28, 2000
//
//  Modifications:
//    Hank Childs, Mon Dec  9 17:04:39 PST 2002
//    Print out validVariable.
//
//    Kathleen Bonnell, Thu Jul 22 12:10:19 PDT 2004 
//    Print out treatAsASCII.
//
//    Brad Whitlock, Tue Jul 20 13:47:04 PST 2004
//    Added units.
//
//    Hank Childs, Mon Feb 14 14:16:49 PST 2005
//    Added original name.
//
//    Jeremy Meredith, Fri Aug 25 17:16:38 EDT 2006
//    Added enumerated scalars.
//
// ****************************************************************************
inline void
Indent(ostream &out, int indent)
{
    for (int i = 0 ; i < indent ; i++)
    {
        out << "\t";
    }
}

void
avtScalarMetaData::Print(ostream &out, int indent) const
{
777
    avtVarMetaData::Print(out, indent);
hrchilds's avatar
hrchilds committed
778
779
780
781
782
783
784

    if (treatAsASCII)
    {
        Indent(out, indent);
        out << "This variable should be treated as ASCII." << endl;
    }

785
    if (enumerationType != None)
hrchilds's avatar
hrchilds committed
786
787
788
789
790
791
792
793
794
795
796
    {
        Indent(out, indent);
        out << "This variable contains enumerated values." << endl;
    }
    else
    {
        Indent(out, indent);
        out << "This variable does not contain enumerated values." << endl;
    }
}

797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
void
avtScalarMetaData::AddEnumGraphEdge(int head, int tail)
{
    enumGraphEdges.push_back(head);
    enumGraphEdges.push_back(tail);
}

// ****************************************************************************
//  Method: AddEnumNameValue
//
//  Purpose: Add name/value pair to an enumeration
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************

int
avtScalarMetaData::AddEnumNameValue(std::string name, double val)
{
    enumNames.push_back(name);
    enumRanges.push_back(val);
    enumRanges.push_back(val);

    return enumNames.size() - 1;
}

// ****************************************************************************
//  Method: AddEnumNameRange
//
//  Purpose: Add name/range pair to an enumeration
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************

int
avtScalarMetaData::AddEnumNameRange(std::string name, double min, double max)
{
    if (min > max)
    {
        EXCEPTION1(ImproperUseException, name);
    }

    enumNames.push_back(name);
    enumRanges.push_back(min);
    enumRanges.push_back(max);

    return enumNames.size() - 1;
}

// ****************************************************************************
//  Method: SetEnumAlwaysExcludeValue
//
//  Purpose: sets value to be used for always excluded in the selection
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************

void
avtScalarMetaData::SetEnumAlwaysExcludeValue(double val)
{
    enumAlwaysExclude[0] = val;
    enumAlwaysExclude[1] = val;
}

// ****************************************************************************
//  Method: SetEnumAlwaysExcludeRange
//
//  Purpose: sets range to be used for always excluded in the selection
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************

void
avtScalarMetaData::SetEnumAlwaysExcludeRange(double min, double max)
{
    enumAlwaysExclude[0] = min;
    enumAlwaysExclude[1] = max;
}

// ****************************************************************************
//  Method: SetEnumAlwaysIncludeValue
//
//  Purpose: sets value to be used for always included in the selection
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************

void
avtScalarMetaData::SetEnumAlwaysIncludeValue(double val)
{
    enumAlwaysInclude[0] = val;
    enumAlwaysInclude[1] = val;
}

// ****************************************************************************
//  Method: SetEnumAlwaysIncludeRange
//
//  Purpose: sets range to be used for always included in the selection
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************

void
avtScalarMetaData::SetEnumAlwaysIncludeRange(double min, double max)
{
    enumAlwaysInclude[0] = min;
    enumAlwaysInclude[1] = max;
}

// ****************************************************************************
//  Method: BuildEnumNChooseRMap
//
//  Purpose: convenience method for caller to build a pascal's triangle map
//  for given N/MaxR
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************
void
avtScalarMetaData::BuildEnumNChooseRMap(int n, int maxr, std::vector<std::vector<int> > &ptMap)
{
916
    for (size_t row = 0; row < ptMap.size(); row++)
917
918
919
        ptMap[row].clear();
    ptMap.clear();

920
    for (int row = 0; row < n; row++)
921
922
    {
        std::vector<int> tmpRow;
923
        for (int col = 0; col <= maxr; col++)
924
925
926
927
            tmpRow.push_back(0);
        ptMap.push_back(tmpRow);
    }

928
929
    for (int row = 0; row < n; row++)
        for (int col = 0; col <= maxr; col++)
930
931
932
933
934
935
936
            ptMap[row][col] = int(NChooseR(n-row-1,col));
}

// ****************************************************************************
//  Function: Bi-nomial coefficient (n-choose-r)
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
937
938
939
940
941
942
//
//  Modifications:
//    Jeremy Meredith, Thu Aug  7 14:24:38 EDT 2008
//    Made it member function so that we got the static namespace benefits
//    without the warnings that static functions in headers tend to generate.
//
943
// ****************************************************************************
944
double avtScalarMetaData::NChooseR(int n, int r)
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
{
    if (n == 0)
    {
        if (r == 0)
            return 1;
        else
            return 0;
    }
    double result = 1;
    int k = 1;
    for (int i = r+1; i <=n; i++)
    {
        result *= (double) i;
        if (k <= n-r)
        {
            result /= (double) k;
            k++;
        }
    }
    return result;
}

// ****************************************************************************
//  Function: ComboValFromDigits
//
//  Purpose: Internal function to compute NChooseR value from list of 
//  ids (digits representing enum set membership)
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
974
975
976
977
978
979
//
//  Modifications:
//    Jeremy Meredith, Thu Aug  7 14:24:38 EDT 2008
//    Made it member function so that we got the static namespace benefits
//    without the warnings that static functions in headers tend to generate.
//
980
981
982
// ****************************************************************************

void
983
avtScalarMetaData::ComboValFromDigits(const std::vector<std::vector<int> > &ptMap,
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
    const std::list<int> &digits, double *id)
{
    int row, col;
    *id = 0.0;
    std::list<int>::const_reverse_iterator it;
    for (col = digits.size()-1, it = digits.rbegin(); col >= 0; col--, it++)
    {
        for (row = 0; row <= *it; row++)
            *id += ptMap[row][col];
    }
    *id -= 1;
}

// ****************************************************************************
//  Function: ComboDigitsFromVal
//
//  Purpose: Internal function to compute list of ids (digits representing enum
//  set membership) to single numerical value.
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
1004
1005
1006
1007
1008
1009
//
//  Modifications:
//    Jeremy Meredith, Thu Aug  7 14:24:38 EDT 2008
//    Made it member function so that we got the static namespace benefits
//    without the warnings that static functions in headers tend to generate.
//
1010
1011
1012
// ****************************************************************************

void
1013
avtScalarMetaData::ComboDigitsFromVal(double id, int n, int maxr,
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
    const std::vector<std::vector<int> > &ptMap, std::list<int> &digits)
{
    int row, col, grp;

    for (grp = 1; grp <= maxr; grp++)
    {
        double grpc = NChooseR(n,grp);
        if (id < grpc)
            break;
        else
            id -= grpc;
    }
    if (grp == maxr+1)
        return;

    int rowmin = 0;
    for (col = grp-1; col >= 0; col--)
    {
        for (row = rowmin; row < n; row++)
        {
            int seglen = ptMap[row][col];
            if (id < seglen)
            {
                rowmin = row+1;
                digits.push_front(row);
                break;
            }
            id -= seglen;
        }
    }
}

// ****************************************************************************
//  Method: UpdateValByInsertingDigit
//
//  Purpose: convenience method for callers to, given a current numerical value
//  reprsenting a list of set ids, compute a new numerical value by adding the
//  new set id.
//
//  Programmer: Mark C. Miller, Thu Mar 27 14:16:45 PDT 2008
// ****************************************************************************

void avtScalarMetaData::UpdateValByInsertingDigit(double *id, int n, int maxr,
const std::vector<std::vector<int> > &ptMap, int newDigit)
{
    std::list<int> currentDigits;
    ComboDigitsFromVal(*id, n, maxr, ptMap, currentDigits);

    std::list<int>::iterator it = currentDigits.begin();
    while (it != currentDigits.end() && *it < newDigit)
        it++;

    if (it == currentDigits.end())
    {
        currentDigits.push_front(newDigit);
        ComboValFromDigits(ptMap, currentDigits, id);
    }
    else
    {
1073
1074
1075
1076
        // only update if we actually adding a new digit
        if (newDigit < *it)
        {
            it++;
1077
1078
1079
1080
1081
1082
            currentDigits.insert(it, newDigit);
            ComboValFromDigits(ptMap, currentDigits, id);
        }
    }
}