Skip to content

Commit

Permalink
Task/slice (#58)
Browse files Browse the repository at this point in the history
* adding slice to the list of supported filters
  • Loading branch information
mclarsen authored Dec 20, 2017
1 parent 7be04c2 commit e9ec1ac
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ascent/runtimes/ascent_main_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ AscentRuntime::ConvertToFlowGraph(const conduit::Node &pipeline,
if(filter["type"].as_string() == "contour")
{
filter_name = "vtkh_marchingcubes";

}
else if(filter["type"].as_string() == "threshold")
{
Expand All @@ -322,6 +321,10 @@ AscentRuntime::ConvertToFlowGraph(const conduit::Node &pipeline,
{
filter_name = "vtkh_clip";
}
else if(filter["type"].as_string() == "slice")
{
filter_name = "vtkh_slice";
}
else
{
ASCENT_ERROR("Unrecognized filter "<<filter["type"].as_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ register_builtin()
Workspace::register_filter_type<VTKHClip>();
Workspace::register_filter_type<VTKHMarchingCubes>();
Workspace::register_filter_type<VTKHThreshold>();
Workspace::register_filter_type<VTKHSlice>();

Workspace::register_filter_type<AddPlot>();
Workspace::register_filter_type<CreatePlot>();
Expand Down
108 changes: 108 additions & 0 deletions src/ascent/runtimes/flow_filters/ascent_runtime_vtkh_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <vtkh/rendering/VolumeRenderer.hpp>
#include <vtkh/filters/Clip.hpp>
#include <vtkh/filters/MarchingCubes.hpp>
#include <vtkh/filters/Slice.hpp>
#include <vtkh/filters/Threshold.hpp>
#include <vtkm/cont/DataSet.h>

Expand Down Expand Up @@ -841,6 +842,113 @@ VTKHMarchingCubes::execute()
set_output<vtkh::DataSet>(iso_output);
}

//-----------------------------------------------------------------------------
VTKHSlice::VTKHSlice()
:Filter()
{
// empty
}

//-----------------------------------------------------------------------------
VTKHSlice::~VTKHSlice()
{
// empty
}

//-----------------------------------------------------------------------------
void
VTKHSlice::declare_interface(Node &i)
{
i["type_name"] = "vtkh_slice";
i["port_names"].append() = "in";
i["output_port"] = "true";
}

//-----------------------------------------------------------------------------
bool
VTKHSlice::verify_params(const conduit::Node &params,
conduit::Node &info)
{
info.reset();
bool res = true;
params.print();
if(! params.has_path("point/x") ||
! params["point/y"].dtype().is_number() )
{
info["errors"].append() = "Missing required numeric parameter 'point/x'";
res = false;
}
if(! params.has_path("point/y") ||
! params["point/y"].dtype().is_number() )
{
info["errors"].append() = "Missing required numeric parameter 'point/y'";
res = false;
}
if(! params.has_path("point/z") ||
! params["point/z"].dtype().is_number() )
{
info["errors"].append() = "Missing required numeric parameter 'point/z'";
res = false;
}

if(! params.has_path("normal/x") ||
! params["normal/x"].dtype().is_number() )
{
info["errors"].append() = "Missing required numeric parameter 'normal/x'";
res = false;
}
if(! params.has_path("normal/y") ||
! params["normal/y"].dtype().is_number() )
{
info["errors"].append() = "Missing required numeric parameter 'normal/y'";
res = false;
}
if(! params.has_path("normal/z") ||
! params["normal/z"].dtype().is_number() )
{
info["errors"].append() = "Missing required numeric parameter 'normal/z'";
res = false;
}


return res;
}

//-----------------------------------------------------------------------------
void
VTKHSlice::execute()
{

ASCENT_INFO("Slicing!");
if(!input(0).check_type<vtkh::DataSet>())
{
ASCENT_ERROR("vtkh_slice input must be a vtk-h dataset");
}

vtkh::DataSet *data = input<vtkh::DataSet>(0);
vtkh::Slice slicer;

slicer.SetInput(data);

const Node &n_point = params()["point"];
const Node &n_normal = params()["normal"];

vtkm::Vec<vtkm::Float32,3> v_point(n_point["x"].to_float32(),
n_point["y"].to_float32(),
n_point["z"].to_float32());

vtkm::Vec<vtkm::Float32,3> v_normal(n_normal["x"].to_float32(),
n_normal["y"].to_float32(),
n_normal["z"].to_float32());

slicer.SetPlane(v_point, v_normal);
slicer.Update();

vtkh::DataSet *slice_output = slicer.GetOutput();

set_output<vtkh::DataSet>(slice_output);
}

//-----------------------------------------------------------------------------
VTKHThreshold::VTKHThreshold()
:Filter()
Expand Down
13 changes: 13 additions & 0 deletions src/ascent/runtimes/flow_filters/ascent_runtime_vtkh_filters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ class VTKHMarchingCubes : public ::flow::Filter
virtual void execute();
};

//-----------------------------------------------------------------------------
class VTKHSlice : public ::flow::Filter
{
public:
VTKHSlice();
virtual ~VTKHSlice();

virtual void declare_interface(conduit::Node &i);
virtual bool verify_params(const conduit::Node &params,
conduit::Node &info);
virtual void execute();
};

//-----------------------------------------------------------------------------
class VTKHThreshold : public ::flow::Filter
{
Expand Down
1 change: 1 addition & 0 deletions src/tests/ascent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set(BASIC_TESTS t_ascent_smoke
t_ascent_clip
t_ascent_contour
t_ascent_threshold
t_ascent_slice
t_ascent_flow_runtime)

set(MPI_TESTS t_ascent_mpi_smoke
Expand Down
183 changes: 183 additions & 0 deletions src/tests/ascent/t_ascent_slice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Copyright (c) 2015-2017, Lawrence Livermore National Security, LLC.
//
// Produced at the Lawrence Livermore National Laboratory
//
// LLNL-CODE-716457
//
// All rights reserved.
//
// This file is part of Ascent.
//
// For details, see: http://software.llnl.gov/ascent/.
//
// Please also read ascent/LICENSE
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the disclaimer below.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the disclaimer (as noted below) in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the LLNS/LLNL nor the names of its contributors may
// be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
// LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//-----------------------------------------------------------------------------
///
/// file: t_ascent_slice.cpp
///
//-----------------------------------------------------------------------------


#include "gtest/gtest.h"

#include <ascent.hpp>

#include <iostream>
#include <math.h>

#include <conduit_blueprint.hpp>

#include "t_config.hpp"
#include "t_utils.hpp"




using namespace std;
using namespace conduit;
using namespace ascent;


index_t EXAMPLE_MESH_SIDE_DIM = 20;


//-----------------------------------------------------------------------------
TEST(ascent_slice, test_slice)
{
// the ascent 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/status"].as_string() == "disabled")
{
ASCENT_INFO("Ascent support disabled, skipping 3D default"
"Pipeline 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));
verify_info.print();

ASCENT_INFO("Testing slice");


string output_path = prepare_output_dir();
string output_file = conduit::utils::join_file_path(output_path,"tout_slice_3d");

// remove old images before rendering
remove_test_image(output_file);


//
// Create the actions.
//

conduit::Node pipelines;
// pipeline 1
pipelines["pl1/f1/type"] = "slice";
// filter knobs
conduit::Node &contour_params = pipelines["pl1/f1/params"];
contour_params["point/x"] = 0.f;
contour_params["point/y"] = 0.f;
contour_params["point/z"] = 0.f;

contour_params["normal/x"] = 0.f;
contour_params["normal/y"] = 0.f;
contour_params["normal/z"] = 1.f;

conduit::Node scenes;
scenes["s1/plots/p1/type"] = "pseudocolor";
scenes["s1/plots/p1/params/field"] = "radial";
scenes["s1/plots/p1/pipeline"] = "pl1";
scenes["s1/image_prefix"] = output_file;

conduit::Node actions;
// add the pipeline
conduit::Node &add_pipelines = actions.append();
add_pipelines["action"] = "add_pipelines";
add_pipelines["pipelines"] = pipelines;
// add the scenes
conduit::Node &add_scenes= actions.append();
add_scenes["action"] = "add_scenes";
add_scenes["scenes"] = scenes;
// execute
conduit::Node &execute = actions.append();
execute["action"] = "execute";

//
// Run Ascent
//

Ascent ascent;

Node ascent_opts;
ascent_opts["runtime/type"] = "ascent";
ascent.open(ascent_opts);
ascent.publish(data);
ascent.execute(actions);
ascent.close();

// check that we created an image
EXPECT_TRUE(check_test_image(output_file));
}
//-----------------------------------------------------------------------------
int main(int argc, char* argv[])
{
int result = 0;

::testing::InitGoogleTest(&argc, argv);

// allow override of the data size via the command line
if(argc == 2)
{
EXAMPLE_MESH_SIDE_DIM = atoi(argv[1]);
}

result = RUN_ALL_TESTS();
return result;
}


0 comments on commit e9ec1ac

Please sign in to comment.