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_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_3d_poly)24 TEST(ascent_pipeline, test_render_3d_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 length = 10;
41 
42     conduit::blueprint::mesh::examples::polychain(length, data);
43 
44     EXPECT_TRUE(conduit::blueprint::mesh::verify(data, verify_info));
45 
46     string output_path = prepare_output_dir();
47     string output_file = conduit::utils::join_file_path(output_path,
48                                                         "tout_render_3d_poly");
49     // remove old images before rendering
50     remove_test_image(output_file);
51 
52     //
53     // Create the actions.
54     //
55     conduit::Node scenes;
56     scenes["s1/plots/p1/type"] = "pseudocolor";
57     scenes["s1/plots/p1/field"] = "chain";
58     scenes["s1/image_prefix"] = output_file;
59 
60     conduit::Node actions;
61     conduit::Node &add_plots = actions.append();
62     add_plots["action"] = "add_scenes";
63     add_plots["scenes"] = scenes;
64     actions.print();
65 
66     //
67     // Run Ascent
68     //
69 
70     Ascent ascent;
71 
72     Node ascent_opts;
73     Node ascent_info;
74     ascent_opts["runtime/type"] = "ascent";
75     ascent.open(ascent_opts);
76     ascent.publish(data);
77     ascent.execute(actions);
78     ascent.info(ascent_info);
79     EXPECT_EQ(ascent_info["runtime/type"].as_string(), "ascent");
80     ascent_info.print();
81     ascent.close();
82 
83     //
84     // // check that we created an image
85     EXPECT_TRUE(check_test_image(output_file, 0.001f, "0"));
86 }
87 
88 //-----------------------------------------------------------------------------
TEST(ascent_pipeline,test_render_3d_poly_multi)89 TEST(ascent_pipeline, test_render_3d_poly_multi)
90 {
91     // the vtkm runtime is currently our only rendering runtime
92     Node n;
93     ascent::about(n);
94     // only run this test if ascent was built with vtkm support
95     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
96     {
97         ASCENT_INFO("Ascent vtkm support disabled, skipping test");
98         return;
99     }
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 = 3;
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_3d_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