From ceb908999a5f5a6217e4225f10a8c10d4a28cd21 Mon Sep 17 00:00:00 2001 From: Cyrus Harrison Date: Tue, 4 Feb 2025 08:59:11 -0800 Subject: [PATCH] wire up scalar rendering fields option --- CHANGELOG.md | 1 + .../ascent_runtime_vtkh_filters.cpp | 36 +++++++- src/tests/ascent/t_ascent_scalar_renderer.cpp | 82 ++++++++++++++++++- 3 files changed, 115 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d307f857..e69eb4200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s - Added `add_mpi_ranks` and `add_domain_ids` filters for adding rank and domain fields to a mesh - Added `transform` filter, which allows you to rotate, scale, translate, mesh coordinates - Added python script in src/utilities/visit_session_converters to convert VisIt color table to Ascent actions color table +- Added `fields` option to the project 2d to support scalar rendering of specific fields. ### Changed - Changed the replay utility's binary names such that `replay_ser` is now `ascent_replay` and `raplay_mpi` is now `ascent_replay_mpi`. This will help prevent potential name collisions with other tools that also have replay utilities. diff --git a/src/libs/ascent/runtimes/flow_filters/ascent_runtime_vtkh_filters.cpp b/src/libs/ascent/runtimes/flow_filters/ascent_runtime_vtkh_filters.cpp index 1d0e8b213..7f4eae23e 100644 --- a/src/libs/ascent/runtimes/flow_filters/ascent_runtime_vtkh_filters.cpp +++ b/src/libs/ascent/runtimes/flow_filters/ascent_runtime_vtkh_filters.cpp @@ -4018,13 +4018,21 @@ VTKHProject2d::verify_params(const conduit::Node ¶ms, res &= check_numeric("image_width",params, info, false); res &= check_numeric("image_height",params, info, false); + if(params.has_child("fields") && !params["fields"].dtype().is_list()) + { + res = false; + info["errors"].append() = "fields is not a list"; + } + std::vector valid_paths; std::vector ignore_paths; valid_paths.push_back("topology"); valid_paths.push_back("image_width"); valid_paths.push_back("image_height"); - valid_paths.push_back("camera"); ignore_paths.push_back("camera"); + valid_paths.push_back("fields"); + ignore_paths.push_back("fields"); + valid_paths.push_back("camera"); std::string surprises = surprise_check(valid_paths, ignore_paths, params); @@ -4074,11 +4082,35 @@ VTKHProject2d::execute() vtkm::rendering::Camera camera; camera.ResetToBounds(bounds); + std::vector field_names; + if(params().has_path("camera")) { parse_camera(params()["camera"], camera); } + if(params().has_path("fields")) + { + + const conduit::Node &flist = params()["fields"]; + const int num_fields = flist.number_of_children(); + + if(num_fields == 0) + { + ASCENT_ERROR("'fields' list must be non-empty"); + } + + for(int i = 0; i < num_fields; i++) + { + const conduit::Node &f = flist.child(i); + if(!f.dtype().is_string()) + { + ASCENT_ERROR("'fields' list values must be a string"); + } + field_names.push_back(f.as_string()); + } + } + int width = 512; int height = 512; if(params().has_path("image_width")) @@ -4096,7 +4128,7 @@ VTKHProject2d::execute() tracer.SetHeight(height); tracer.SetInput(&data); tracer.SetCamera(camera); - + tracer.SetFields(field_names); tracer.Update(); vtkh::DataSet *output = tracer.GetOutput(); diff --git a/src/tests/ascent/t_ascent_scalar_renderer.cpp b/src/tests/ascent/t_ascent_scalar_renderer.cpp index 97cf79cf1..5efeba83b 100644 --- a/src/tests/ascent/t_ascent_scalar_renderer.cpp +++ b/src/tests/ascent/t_ascent_scalar_renderer.cpp @@ -58,7 +58,7 @@ TEST(ascent_scalar_rendering, test_scalar_rendering) EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info)); - ASCENT_INFO("Testing scalar Rendering"); + ASCENT_INFO("Testing Scalar Rendering"); string output_path = prepare_output_dir(); @@ -98,7 +98,6 @@ TEST(ascent_scalar_rendering, test_scalar_rendering) // Ascent ascent; - Node ascent_opts; ascent_opts["runtime/type"] = "ascent"; ascent.open(ascent_opts); @@ -111,6 +110,85 @@ TEST(ascent_scalar_rendering, test_scalar_rendering) ASCENT_ACTIONS_DUMP(actions,output_file,msg); } + +//----------------------------------------------------------------------------- +TEST(ascent_scalar_rendering, test_scalar_rendering_fields_specified) +{ + // the vtkm runtime is currently our only rendering runtime + Node n; + ascent::about(n); + // only run this test if ascent was built with vtkm support + if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled") + { + ASCENT_INFO("Ascent support disabled, skipping test"); + return; + } + + + // + // Create an example mesh. + // + Node data, verify_info; + conduit::blueprint::mesh::examples::braid("hexs", + EXAMPLE_MESH_SIDE_DIM, + EXAMPLE_MESH_SIDE_DIM, + EXAMPLE_MESH_SIDE_DIM, + data); + + EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info)); + + ASCENT_INFO("Testing Scalar Rendering with fields specified"); + + + string output_path = prepare_output_dir(); + string output_file = conduit::utils::join_file_path(output_path,"tout_scalar_rendering_fields_specified"); + + // + // Create the actions. + // + + conduit::Node pipelines; + // pipeline 1 + pipelines["pl1/f1/type"] = "project_2d"; + // filter knobs + conduit::Node ¶ms = pipelines["pl1/f1/params"]; + params["image_width"] = 512; + params["image_height"] = 512; + params["fields"].append() = "braid"; + + conduit::Node extracts; + extracts["e1/type"] = "relay"; + extracts["e1/pipeline"] = "pl1"; + + extracts["e1/params/path"] = output_file; + extracts["e1/params/protocol"] = "blueprint/mesh/hdf5"; + + conduit::Node actions; + // add the extracts + conduit::Node &add_extracts = actions.append(); + add_extracts["action"] = "add_extracts"; + add_extracts["extracts"] = extracts; + // add the pipeline + conduit::Node &add_pipelines= actions.append(); + add_pipelines["action"] = "add_pipelines"; + add_pipelines["pipelines"] = pipelines; + + // + // Run Ascent + // + + Ascent ascent; + Node ascent_opts; + ascent.open(ascent_opts); + ascent.publish(data); + ascent.execute(actions); + ascent.close(); + + // check that we created an image + std::string msg = "An example of scalar rendering of specific fields"; + ASCENT_ACTIONS_DUMP(actions,output_file,msg); +} + //----------------------------------------------------------------------------- int main(int argc, char* argv[]) {