1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: ArrayVariants.cxx
5
6 -------------------------------------------------------------------------
7 Copyright 2008 Sandia Corporation.
8 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 the U.S. Government retains certain rights in this software.
10 -------------------------------------------------------------------------
11
12 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13 All rights reserved.
14 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notice for more information.
19
20 =========================================================================*/
21
22 #include <vtkDenseArray.h>
23 #include <vtkSmartPointer.h>
24
25 #include <vtksys/ios/iostream>
26 #include <vtksys/ios/sstream>
27 #include <vtksys/stl/stdexcept>
28
29 #define test_expression(expression) \
30 { \
31 if(!(expression)) \
32 { \
33 vtksys_ios::ostringstream buffer; \
34 buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \
35 throw std::runtime_error(buffer.str()); \
36 } \
37 }
38
TestArrayVariants(int vtkNotUsed (argc),char * vtkNotUsed (argv)[])39 int TestArrayVariants(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
40 {
41 try
42 {
43 // Exercise the API that gets/sets variants ...
44 vtkSmartPointer<vtkDenseArray<double> > concrete = vtkSmartPointer<vtkDenseArray<double> >::New();
45 concrete->Resize(3, 2);
46 vtkTypedArray<double>* const typed = concrete;
47 vtkArray* const abstract = concrete;
48
49 abstract->SetVariantValue(0, 0, 1.0);
50 abstract->SetVariantValue(vtkArrayCoordinates(0, 1), 2.0);
51 typed->SetVariantValue(1, 0, 3.0);
52 typed->SetVariantValue(vtkArrayCoordinates(1, 1), 4.0);
53 concrete->SetVariantValue(2, 0, 5.0);
54 concrete->SetVariantValue(vtkArrayCoordinates(2, 1), 6.0);
55
56 test_expression(abstract->GetVariantValue(0, 0) == 1.0);
57 test_expression(abstract->GetVariantValue(vtkArrayCoordinates(0, 1)) == 2.0);
58 test_expression(typed->GetVariantValue(1, 0) == 3.0);
59 test_expression(typed->GetVariantValue(vtkArrayCoordinates(1, 1)) == 4.0);
60 test_expression(concrete->GetVariantValue(2, 0) == 5.0);
61 test_expression(concrete->GetVariantValue(vtkArrayCoordinates(2, 1)) == 6.0);
62
63 abstract->SetVariantValueN(0, 7.0);
64 test_expression(abstract->GetVariantValueN(0) == 7.0);
65 typed->SetVariantValueN(0, 8.0);
66 test_expression(typed->GetVariantValueN(0) == 8.0);
67 concrete->SetVariantValueN(0, 9.0);
68 test_expression(concrete->GetVariantValueN(0) == 9.0);
69
70 return 0;
71 }
72 catch(std::exception& e)
73 {
74 cerr << e.what() << endl;
75 return 1;
76 }
77 }
78