Debian Codegraph @

Modules/Bridge/VtkGlue/test/QuickViewTest.cxx

raw
1 /*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19 #include "QuickView.h"
20
21 #include "itkImageFileReader.h"
22
23 template <typename T>
24 void
25 View(const char * name,
26 T,
27 std::string fileName,
28 bool sharedCamera = false,
29 bool interpolate = true,
30 const std::string & snapshotPath = "",
31 const std::string & ext = "png")
32 {
33 using ImageType = itk::Image<T, 2>;
34 using SourceType = itk::ImageFileReader<ImageType>;
35
36 typename SourceType::Pointer source = SourceType::New();
37 source->SetFileName(fileName);
38
39 QuickView viewer1;
40 if (sharedCamera)
41 {
42 viewer1.ShareCameraOn();
43 }
44 else
45 {
46 viewer1.ShareCameraOff();
47 }
48 if (interpolate)
49 {
50 viewer1.InterpolateOn();
51 }
52 else
53 {
54 viewer1.InterpolateOff();
55 }
56 viewer1.AddImage(source->GetOutput(), true, std::string(name) + " flipped");
57 viewer1.AddImage(source->GetOutput(), false, std::string(name) + " not flipped");
58
59 std::string path(snapshotPath);
60 if (!path.empty())
61 {
62 viewer1.SnapshotOn();
63 viewer1.SetSnapshotPrefix("/QuickViewTest");
64 viewer1.SetSnapshotPath(snapshotPath);
65 viewer1.SetSnapshotExtension(ext);
66 }
67 viewer1.Visualize(false);
68 }
69
70 template <typename T>
71 void
72 ViewRGB(const char * name,
73 T,
74 std::string fileName,
75 bool sharedCamera = false,
76 bool interpolate = true,
77 const std::string & snapshotPath = "",
78 const std::string & ext = "png")
79 {
80 using ColorPixelType = itk::RGBPixel<T>;
81 using ColorImageType = itk::Image<ColorPixelType, 2>;
82 using SourceType = itk::ImageFileReader<ColorImageType>;
83
84 typename SourceType::Pointer source = SourceType::New();
85
86 source->SetFileName(fileName);
87 QuickView viewer1;
88
89 if (sharedCamera)
90 {
91 viewer1.ShareCameraOn();
92 }
93 else
94 {
95 viewer1.ShareCameraOff();
96 }
97 if (interpolate)
98 {
99 viewer1.InterpolateOn();
100 }
101 else
102 {
103 viewer1.InterpolateOff();
104 }
105
106
107 viewer1.AddRGBImage(source->GetOutput(), true, std::string(name) + " flipped");
108 viewer1.AddRGBImage(source->GetOutput(), false, std::string(name) + " not flipped");
109
110 std::string path(snapshotPath);
111 if (!path.empty())
112 {
113 viewer1.SnapshotOn();
114 viewer1.SetSnapshotPrefix("/QuickViewTest");
115 viewer1.SetSnapshotPath(snapshotPath);
116 viewer1.SetSnapshotExtension(ext);
117 }
118 viewer1.Visualize(false);
119 }
120
121 int
122 QuickViewTest(int argc, char * argv[])
123 {
124 View("unsigned char", static_cast<unsigned char>(0), argv[1], true, true);
125 View("unsigned char", static_cast<unsigned char>(0), argv[1]);
126 View("char", static_cast<char>(0), argv[1]);
127 View("unsigned short", static_cast<unsigned short>(0), argv[1]);
128 View("short", static_cast<short>(0), argv[1]);
129 View("unsigned int", 0U, argv[1]);
130 View("int", 0, argv[1]);
131 View("unsigned long", 0UL, argv[1]);
132 View("long", 0L, argv[1]);
133 View("float", static_cast<float>(0), argv[1]);
134 View("double", static_cast<double>(0), argv[1]);
135
136 ViewRGB("RGB-float", static_cast<float>(0), argv[1], true, false);
137 ViewRGB("RGB-float", static_cast<float>(0), argv[1]);
138
139 if (argc > 2)
140 {
141 View("unsigned char", static_cast<unsigned char>(0), argv[1], false, true, argv[2]);
142 View("unsigned char", static_cast<unsigned char>(0), argv[1], false, true, argv[2], std::string("tif"));
143 View("unsigned char", static_cast<unsigned char>(0), argv[1], false, true, argv[2], std::string("jpg"));
144 View("unsigned char", static_cast<unsigned char>(0), argv[1], false, true, argv[2], std::string("bmp"));
145 }
146
147 return EXIT_SUCCESS;
148 }