1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
2 // Copyright (c) Lawrence Livermore National Security, LLC and other Ascent
3 // Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
4 // other details. No copyright assignment is required to contribute to Ascent.
5 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
6 
7 //-----------------------------------------------------------------------------
8 ///
9 /// file: t_ascent_render_2d_poly.cpp
10 ///
11 //-----------------------------------------------------------------------------
12 
13 #include "gtest/gtest.h"
14 
15 #include <ascent.hpp>
16 
17 #include "t_config.hpp"
18 #include "t_utils.hpp"
19 
20 using namespace std;
21 using namespace conduit;
22 using namespace ascent;
23 //-----------------------------------------------------------------------------
TEST(ascent_pipeline,test_render_2d_poly)24 TEST(ascent_pipeline, test_render_2d_poly)
25 {
26     // the vtkm runtime is currently our only rendering runtime
27     Node n;
28     ascent::about(n);
29     // only run this test if ascent was built with vtkm support
30     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
31     {
32         ASCENT_INFO("Ascent vtkm support disabled, skipping test");
33         return;
34     }
35 
36     //
37     // Create example mesh.
38     //
39     Node data, verify_info;
40     index_t nlevels = 10;
41     index_t nz = 1;
42 
43     conduit::blueprint::mesh::examples::polytess(nlevels, nz, data);
44 
45     EXPECT_TRUE(conduit::blueprint::mesh::verify(data, verify_info));
46 
47     string output_path = prepare_output_dir();
48     string output_file = conduit::utils::join_file_path(output_path,
49                                                         "tout_render_2d_poly");
50     // remove old images before rendering
51     remove_test_image(output_file);
52 
53     //
54     // Create the actions.
55     //
56     conduit::Node scenes;
57     scenes["s1/plots/p1/type"] = "pseudocolor";
58     scenes["s1/plots/p1/field"] = "level";
59     scenes["s1/image_prefix"] = output_file;
60 
61     conduit::Node actions;
62     conduit::Node &add_plots = actions.append();
63     add_plots["action"] = "add_scenes";
64     add_plots["scenes"] = scenes;
65     actions.print();
66 
67     //
68     // Run Ascent
69     //
70 
71     Ascent ascent;
72 
73     Node ascent_opts;
74     Node ascent_info;
75     ascent_opts["runtime/type"] = "ascent";
76     ascent.open(ascent_opts);
77     ascent.publish(data);
78     ascent.execute(actions);
79     ascent.info(ascent_info);
80     EXPECT_EQ(ascent_info["runtime/type"].as_string(), "ascent");
81     ascent_info.print();
82     ascent.close();
83 
84     //
85     // // check that we created an image
86     EXPECT_TRUE(check_test_image(output_file, 0.001f, "0"));
87 }
88 
89 //-----------------------------------------------------------------------------
TEST(ascent_pipeline,test_render_2d_poly_multi)90 TEST(ascent_pipeline, test_render_2d_poly_multi)
91 {
92     // the vtkm runtime is currently our only rendering runtime
93     Node n;
94     ascent::about(n);
95     // only run this test if ascent was built with vtkm support
96     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
97     {
98         ASCENT_INFO("Ascent vtkm support disabled, skipping test");
99         return;
100     }
101 
102     //
103     // Create example mesh.
104     //
105     Node root, verify_info;
106     Node &child1 = root.append();
107     Node &child2 = root.append();
108     index_t nlevels = 3;
109     index_t nz = 1;
110 
111     conduit::blueprint::mesh::examples::polytess(nlevels, nz, child1);
112     conduit::blueprint::mesh::examples::polytess(nlevels, nz, child2);
113 
114     EXPECT_TRUE(conduit::blueprint::mesh::verify(child1, verify_info));
115     EXPECT_TRUE(conduit::blueprint::mesh::verify(child2, verify_info));
116 
117     float64 *y_values = child2["coordsets/coords/values/y"].value();
118 
119     const int num_elements = child1["coordsets/coords/values/y"].dtype().number_of_elements();
120 
121     for (int i = 0; i < num_elements; i ++)
122     {
123         y_values[i] += 10.0f;
124     }
125 
126     EXPECT_TRUE(conduit::blueprint::mesh::verify(child2, verify_info));
127 
128     string output_path = prepare_output_dir();
129     string output_file = conduit::utils::join_file_path(output_path,
130                                                         "tout_render_2d_poly_multi");
131     // remove old images before rendering
132     remove_test_image(output_file);
133 
134     //
135     // Create the actions.
136     //
137     conduit::Node scenes;
138     scenes["s1/plots/p1/type"] = "pseudocolor";
139     scenes["s1/plots/p1/field"] = "level";
140     scenes["s1/image_prefix"] = output_file;
141 
142     conduit::Node actions;
143     conduit::Node &add_plots = actions.append();
144     add_plots["action"] = "add_scenes";
145     add_plots["scenes"] = scenes;
146     actions.print();
147 
148     //
149     // Run Ascent
150     //
151 
152     Ascent ascent;
153 
154     Node ascent_opts;
155     Node ascent_info;
156     ascent_opts["runtime/type"] = "ascent";
157     ascent.open(ascent_opts);
158     ascent.publish(root);
159     ascent.execute(actions);
160     ascent.info(ascent_info);
161     EXPECT_EQ(ascent_info["runtime/type"].as_string(), "ascent");
162     ascent_info.print();
163     ascent.close();
164 
165     //
166     // // check that we created an image
167     EXPECT_TRUE(check_test_image(output_file, 0.001f, "0"));
168 }
169 
170 //-----------------------------------------------------------------------------
TEST(ascent_pipeline,test_render_2d_poly_and_nonpoly)171 TEST(ascent_pipeline, test_render_2d_poly_and_nonpoly)
172 {
173     // the vtkm runtime is currently our only rendering runtime
174     Node n;
175     ascent::about(n);
176     // only run this test if ascent was built with vtkm support
177     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
178     {
179         ASCENT_INFO("Ascent vtkm support disabled, skipping test");
180         return;
181     }
182 
183     //
184     // Create example mesh.
185     //
186     Node data, braid_data, verify_info;
187     index_t nlevels = 5;
188     index_t nz = 1;
189 
190     conduit::blueprint::mesh::examples::polytess(nlevels, nz, data);
191 
192     conduit::blueprint::mesh::examples::braid("quads", 5,5,0,braid_data);
193 
194     data["coordsets/coords_braid"] = braid_data["coordsets/coords"];
195     data["topologies/mesh"] = braid_data["topologies/mesh"];
196     data["topologies/mesh/coordset"] = "coords_braid";
197     data["fields/braid"] = braid_data["fields/braid"];
198     data["fields/radial"] = braid_data["fields/radial"];
199     data["fields/vel"] = braid_data["fields/vel"];
200 
201     EXPECT_TRUE(conduit::blueprint::mesh::verify(data, verify_info));
202 
203     string output_path = prepare_output_dir();
204     string output_file = conduit::utils::join_file_path(output_path,
205                                                         "tout_render_2d_poly_and_nopoly");
206     // remove old images before rendering
207     remove_test_image(output_file);
208 
209     //
210     // Create the actions.
211     //
212     conduit::Node scenes;
213     scenes["s1/plots/p1/type"] = "pseudocolor";
214     scenes["s1/plots/p1/field"] = "level";
215     scenes["s1/image_prefix"] = output_file + "polytess";
216     scenes["s2/plots/p1/type"] = "pseudocolor";
217     scenes["s2/plots/p1/field"] = "braid";
218     scenes["s2/image_prefix"] = output_file + "braid";
219 
220     conduit::Node actions;
221     conduit::Node &add_plots = actions.append();
222     add_plots["action"] = "add_scenes";
223     add_plots["scenes"] = scenes;
224     actions.print();
225 
226     //
227     // Run Ascent
228     //
229 
230     Ascent ascent;
231 
232     Node ascent_opts;
233     Node ascent_info;
234     ascent_opts["runtime/type"] = "ascent";
235     ascent.open(ascent_opts);
236     ascent.publish(data);
237     ascent.execute(actions);
238     ascent.info(ascent_info);
239     EXPECT_EQ(ascent_info["runtime/type"].as_string(), "ascent");
240     ascent_info.print();
241     ascent.close();
242 
243     //
244     // // check that we created an image
245     EXPECT_TRUE(check_test_image(output_file + "polytess", 0.001f, "0"));
246     EXPECT_TRUE(check_test_image(output_file + "braid", 0.001f, "0"));
247 }
248