1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: ArrayExtents.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 <vtkArrayCoordinates.h>
23 #include <vtkArrayExtents.h>
24
25 #include <vtksys/ios/iostream>
26 #include <vtksys/ios/sstream>
27 #include <vtksys/stl/stdexcept>
28 #include "vtkSetGet.h"
29
30 #define test_expression(expression) \
31 { \
32 if(!(expression)) \
33 { \
34 vtksys_ios::ostringstream buffer; \
35 buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \
36 throw std::runtime_error(buffer.str()); \
37 } \
38 }
39
TestArrayExtents(int vtkNotUsed (argc),char * vtkNotUsed (argv)[])40 int TestArrayExtents(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
41 {
42 try
43 {
44 vtkArrayExtents slice(vtkArrayRange(2, 4), vtkArrayRange(6, 9));
45
46 test_expression(slice.GetDimensions() == 2);
47 test_expression(slice[0].GetSize() == 2);
48 test_expression(slice[1].GetSize() == 3);
49 test_expression(slice.GetSize() == 6);
50
51 vtkArrayCoordinates coordinates;
52 for(vtkArrayExtents::SizeT n = 0; n != slice.GetSize(); ++n)
53 {
54 slice.GetLeftToRightCoordinatesN(n, coordinates);
55 cerr << coordinates << endl;
56 }
57
58 slice.GetLeftToRightCoordinatesN(0, coordinates);
59 test_expression(coordinates == vtkArrayCoordinates(2, 6));
60 slice.GetLeftToRightCoordinatesN(1, coordinates);
61 test_expression(coordinates == vtkArrayCoordinates(3, 6));
62 slice.GetLeftToRightCoordinatesN(2, coordinates);
63 test_expression(coordinates == vtkArrayCoordinates(2, 7));
64 slice.GetLeftToRightCoordinatesN(3, coordinates);
65 test_expression(coordinates == vtkArrayCoordinates(3, 7));
66 slice.GetLeftToRightCoordinatesN(4, coordinates);
67 test_expression(coordinates == vtkArrayCoordinates(2, 8));
68 slice.GetLeftToRightCoordinatesN(5, coordinates);
69 test_expression(coordinates == vtkArrayCoordinates(3, 8));
70
71 test_expression(slice.Contains(vtkArrayCoordinates(3, 7)));
72 test_expression(!slice.Contains(vtkArrayCoordinates(1, 7)));
73
74 return 0;
75 }
76 catch(std::exception& e)
77 {
78 cerr << e.what() << endl;
79 return 1;
80 }
81 }
82