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_3d.cpp
10 ///
11 //-----------------------------------------------------------------------------
12 
13 
14 #include "gtest/gtest.h"
15 
16 #include <ascent.hpp>
17 
18 #include <iostream>
19 #include <math.h>
20 
21 #include <conduit_blueprint.hpp>
22 #include <conduit_relay_io_blueprint.hpp>
23 
24 #include "t_config.hpp"
25 #include "t_utils.hpp"
26 
27 
28 using namespace std;
29 using namespace conduit;
30 using namespace ascent;
31 
32 
33 index_t EXAMPLE_MESH_SIDE_DIM = 20;
34 
35 //-----------------------------------------------------------------------------
TEST(ascent_amr,test_amr_render_simple)36 TEST(ascent_amr, test_amr_render_simple)
37 {
38     // the vtkm runtime is currently our only rendering runtime
39     Node n;
40     ascent::about(n);
41     // only run this test if ascent was built with vtkm support
42     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
43     {
44         ASCENT_INFO("Ascent support disabled, skipping test");
45         return;
46     }
47 
48 
49     //
50     // Create an example mesh.
51     //
52     Node data, verify_info;
53     blueprint::mesh::examples::julia_nestsets_simple(-2.0,  2.0, // x range
54                                                      -2.0,  2.0, // y range
55                                                      0.285, 0.01, // c value
56                                                      data);
57     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
58 
59     ASCENT_INFO("Testing 3D Rendering with Default Pipeline");
60 
61 
62     string output_path = prepare_output_dir();
63     string output_file = conduit::utils::join_file_path(output_path,
64                                                         "tout_render_amr_simple");
65 
66     // remove old images before rendering
67     remove_test_image(output_file);
68 
69     //
70     // Create the actions.
71     //
72 
73     conduit::Node scenes;
74     scenes["s1/plots/p1/type"] = "pseudocolor";
75     scenes["s1/plots/p1/field"] = "iters";
76     //scenes["s1/plots/p2/type"] = "mesh";
77     scenes["s1/image_prefix"] = output_file;
78 
79     conduit::Node actions;
80     // add the scenes
81     conduit::Node &add_scenes= actions.append();
82     add_scenes["action"] = "add_scenes";
83     add_scenes["scenes"] = scenes;
84 
85     //
86     // Run Ascent
87     //
88 
89     Ascent ascent;
90 
91     Node ascent_opts;
92     ascent_opts["runtime/type"] = "ascent";
93     ascent.open(ascent_opts);
94     ascent.publish(data);
95     ascent.execute(actions);
96     ascent.close();
97 
98     // check that we created an image
99     EXPECT_TRUE(check_test_image(output_file,0.01,"0"));
100     std::string msg = "An example of rendering amr data";
101     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
102 }
103 
104 //-----------------------------------------------------------------------------
TEST(ascent_amr,test_amr_render_complex)105 TEST(ascent_amr, test_amr_render_complex)
106 {
107     // the vtkm runtime is currently our only rendering runtime
108     Node n;
109     ascent::about(n);
110     // only run this test if ascent was built with vtkm support
111     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
112     {
113         ASCENT_INFO("Ascent support disabled, skipping test");
114         return;
115     }
116 
117 
118     //
119     // Create an example mesh.
120     //
121     Node data, verify_info;
122     blueprint::mesh::examples::julia_nestsets_complex(EXAMPLE_MESH_SIDE_DIM,
123                                                       EXAMPLE_MESH_SIDE_DIM,
124                                                       -2.0,  2.0, // x range
125                                                       -2.0,  2.0, // y range
126                                                       0.285, 0.01, // c value
127                                                       2, // amr levels
128                                                       data);
129     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
130 
131     ASCENT_INFO("Testing 3D Rendering with Default Pipeline");
132 
133 
134     string output_path = prepare_output_dir();
135     string output_file = conduit::utils::join_file_path(output_path,
136                                                         "tout_render_amr_complex");
137 
138     // remove old images before rendering
139     remove_test_image(output_file);
140 
141     //
142     // Create the actions.
143     //
144 
145     conduit::Node scenes;
146     scenes["s1/plots/p1/type"] = "pseudocolor";
147     scenes["s1/plots/p1/field"] = "iters";
148     //scenes["s1/plots/p1/field"] = "topo_ghosts";
149     //scenes["s1/plots/p2/type"] = "mesh";
150     scenes["s1/image_prefix"] = output_file;
151 
152     conduit::Node actions;
153     // add the scenes
154     conduit::Node &add_scenes= actions.append();
155     add_scenes["action"] = "add_scenes";
156     add_scenes["scenes"] = scenes;
157 
158     //
159     // Run Ascent
160     //
161 
162     Ascent ascent;
163 
164     Node ascent_opts;
165     ascent_opts["runtime/type"] = "ascent";
166     ascent.open(ascent_opts);
167     ascent.publish(data);
168     ascent.execute(actions);
169     ascent.close();
170 
171     // check that we created an image
172     EXPECT_TRUE(check_test_image(output_file,0.01,"0"));
173     std::string msg = "An example of rendering amr data";
174     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
175 }
176 
177 //-----------------------------------------------------------------------------
TEST(ascent_amr,test_amr_render_complex_ghosts)178 TEST(ascent_amr, test_amr_render_complex_ghosts)
179 {
180     // the vtkm runtime is currently our only rendering runtime
181     Node n;
182     ascent::about(n);
183     // only run this test if ascent was built with vtkm support
184     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
185     {
186         ASCENT_INFO("Ascent support disabled, skipping test");
187         return;
188     }
189 
190 
191     //
192     // Create an example mesh.
193     //
194     Node data, verify_info;
195     blueprint::mesh::examples::julia_nestsets_complex(EXAMPLE_MESH_SIDE_DIM,
196                                                       EXAMPLE_MESH_SIDE_DIM,
197                                                       -2.0,  2.0, // x range
198                                                       -2.0,  2.0, // y range
199                                                       0.285, 0.01, // c value
200                                                       2, // amr levels
201                                                       data);
202 
203     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
204     ASCENT_INFO("Testing 3D Rendering with Default Pipeline");
205 
206 
207 
208     string output_path = prepare_output_dir();
209     string output_file = conduit::utils::join_file_path(output_path,
210                                                         "tout_render_amr_complex_ghost");
211 
212     // remove old images before rendering
213     remove_test_image(output_file);
214 
215     //
216     // Create the actions.
217     //
218 
219     conduit::Node scenes;
220     scenes["s1/plots/p1/type"] = "pseudocolor";
221     scenes["s1/plots/p1/field"] = "iters";
222     scenes["s1/image_prefix"] = output_file;
223 
224     conduit::Node actions;
225     // add the scenes
226     conduit::Node &add_scenes= actions.append();
227     add_scenes["action"] = "add_scenes";
228     add_scenes["scenes"] = scenes;
229 
230     //
231     // Run Ascent
232     //
233 
234     Ascent ascent;
235 
236     Node ascent_opts;
237     ascent_opts["runtime/type"] = "ascent";
238     ascent.open(ascent_opts);
239     ascent.publish(data);
240     ascent.execute(actions);
241     ascent.close();
242 
243     // check that we created an image
244     EXPECT_TRUE(check_test_image(output_file,0.01,"0"));
245     std::string msg = "An example of rendering amr data";
246     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
247 }
248 
249 
250 //-----------------------------------------------------------------------------
main(int argc,char * argv[])251 int main(int argc, char* argv[])
252 {
253     int result = 0;
254 
255     ::testing::InitGoogleTest(&argc, argv);
256 
257     // allow override of the data size via the command line
258     if(argc == 2)
259     {
260         EXAMPLE_MESH_SIDE_DIM = atoi(argv[1]);
261     }
262 
263     result = RUN_ALL_TESTS();
264     return result;
265 }
266 
267 
268