From 96112343d08e41e73db6d8083f91bd682ebf15a8 Mon Sep 17 00:00:00 2001 From: Tushar Athawale Date: Tue, 13 Dec 2022 15:15:22 -0500 Subject: [PATCH] README: Updated VTK-m installation instruction --- README.md | 133 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 20d10b5c6..7f0bc8d07 100644 --- a/README.md +++ b/README.md @@ -132,10 +132,10 @@ and then build. Here are some example *nix commands for the process (individual commands may vary). ```sh -$ tar xvzf ~/Downloads/vtk-m-v1.4.0.tar.gz +$ tar xvzf ~/Downloads/vtk-m-v1.9.0.tar.gz $ mkdir vtkm-build $ cd vtkm-build -$ cmake-gui ../vtk-m-v1.4.0 +$ cmake-gui ../vtk-m-v1.9.0 $ cmake --build -j . # Runs make (or other build program) ``` @@ -147,76 +147,109 @@ Users Guide]. The VTK-m source distribution includes a number of examples. The goal of the VTK-m examples is to illustrate specific VTK-m concepts in a consistent and -simple format. However, these examples only cover a small part of the +simple format. However, these examples only cover a small portion of the capabilities of VTK-m. -Below is a simple example of using VTK-m to load a VTK image file, run the -Marching Cubes algorithm on it, and render the results to an image: +Below is a simple example of using VTK-m to create a simple data set and use VTK-m's rendering +engine to render an image and write that image to a file. It then computes an isosurface on the +input data set and renders this output data set in a separate image file: ```cpp -#include -#include -#include -#include -#include +#include +#include + #include -#include #include -#include #include +#include +#include #include #include -vtkm::io::VTKDataSetReader reader("path/to/vtk_image_file.vtk"); -vtkm::cont::DataSet inputData = reader.ReadDataSet(); -std::string fieldName = "scalars"; +#include -vtkm::Range range; -inputData.GetPointField(fieldName).GetRange(&range); -vtkm::Float64 isovalue = range.Center(); +using vtkm::rendering::CanvasRayTracer; +using vtkm::rendering::MapperRayTracer; +using vtkm::rendering::MapperVolume; +using vtkm::rendering::MapperWireframer; -// Create an isosurface filter -vtkm::filter::Contour filter; -filter.SetIsoValue(0, isovalue); -filter.SetActiveField(fieldName); -vtkm::cont::DataSet outputData = filter.Execute(inputData); +int main(int argc, char* argv[]) +{ + vtkm::cont::Initialize(argc, argv, vtkm::cont::InitializeOptions::Strict); -// compute the bounds and extends of the input data -vtkm::Bounds coordsBounds = inputData.GetCoordinateSystem().GetBounds(); + auto tangle = vtkm::source::Tangle(vtkm::Id3{ 50, 50, 50 }); + vtkm::cont::DataSet tangleData = tangle.Execute(); + std::string fieldName = "tangle"; -// setup a camera and point it to towards the center of the input data -vtkm::rendering::Camera camera; -camera.ResetToBounds(coordsBounds); -vtkm::cont::ColorTable colorTable("inferno"); + // Set up a camera for rendering the input data + vtkm::rendering::Camera camera; + camera.SetLookAt(vtkm::Vec3f_32(0.5, 0.5, 0.5)); + camera.SetViewUp(vtkm::make_Vec(0.f, 1.f, 0.f)); + camera.SetClippingRange(1.f, 10.f); + camera.SetFieldOfView(60.f); + camera.SetPosition(vtkm::Vec3f_32(1.5, 1.5, 1.5)); + vtkm::cont::ColorTable colorTable("inferno"); -// Create a mapper, canvas and view that will be used to render the scene -vtkm::rendering::Scene scene; -vtkm::rendering::MapperRayTracer mapper; -vtkm::rendering::CanvasRayTracer canvas(512, 512); -vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f); + // Background color: + vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f); + vtkm::rendering::Actor actor(tangleData.GetCellSet(), + tangleData.GetCoordinateSystem(), + tangleData.GetField(fieldName), + colorTable); + vtkm::rendering::Scene scene; + scene.AddActor(actor); + // 2048x2048 pixels in the canvas: + CanvasRayTracer canvas(2048, 2048); + // Create a view and use it to render the input data using OS Mesa -// Render an image of the output isosurface -scene.AddActor(vtkm::rendering::Actor(outputData.GetCellSet(), - outputData.GetCoordinateSystem(), - outputData.GetField(fieldName), - colorTable)); -vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg); -view.Paint(); -view.SaveAs("demo_output.png"); + vtkm::rendering::View3D view(scene, MapperVolume(), canvas, camera, bg); + view.Paint(); + view.SaveAs("volume.png"); + + // Compute an isosurface: + vtkm::filter::contour::Contour filter; + // [min, max] of the tangle field is [-0.887, 24.46]: + filter.SetIsoValue(3.0); + filter.SetActiveField(fieldName); + vtkm::cont::DataSet isoData = filter.Execute(tangleData); + // Render a separate image with the output isosurface + vtkm::rendering::Actor isoActor( + isoData.GetCellSet(), isoData.GetCoordinateSystem(), isoData.GetField(fieldName), colorTable); + // By default, the actor will automatically scale the scalar range of the color table to match + // that of the data. However, we are coloring by the scalar that we just extracted a contour + // from, so we want the scalar range to match that of the previous image. + isoActor.SetScalarRange(actor.GetScalarRange()); + vtkm::rendering::Scene isoScene; + isoScene.AddActor(isoActor); + + // Wireframe surface: + vtkm::rendering::View3D isoView(isoScene, MapperWireframer(), canvas, camera, bg); + isoView.Paint(); + isoView.SaveAs("isosurface_wireframer.png"); + + // Smooth surface: + vtkm::rendering::View3D solidView(isoScene, MapperRayTracer(), canvas, camera, bg); + solidView.Paint(); + solidView.SaveAs("isosurface_raytracer.png"); + + return 0; +} ``` A minimal CMakeLists.txt such as the following one can be used to build this example. ```CMake -project(example) +cmake_minimum_required(VERSION 3.12...3.15 FATAL_ERROR) +project(VTKmDemo CXX) -set(VTKm_DIR "/somepath/lib/cmake/vtkm-XYZ") +#Find the VTK-m package +find_package(VTKm REQUIRED QUIET) -find_package(VTKm REQUIRED) - -add_executable(example example.cxx) -target_link_libraries(example vtkm_cont vtkm_rendering) +if(TARGET vtkm_rendering) + add_executable(Demo Demo.cxx) + target_link_libraries(Demo PRIVATE vtkm_filter vtkm_rendering vtkm_source) +endif() ``` ## License ## @@ -229,11 +262,11 @@ See [LICENSE.txt](LICENSE.txt) for details. [VTK-m Coding Conventions]: docs/CodingConventions.md [VTK-m Doxygen latest]: https://docs-m.vtk.org/latest/index.html [VTK-m Doxygen nightly]: https://docs-m.vtk.org/nightly/ -[VTK-m download page]: http://m.vtk.org/index.php/VTK-m_Releases +[VTK-m download page]: https://gitlab.kitware.com/vtk/vtk-m/-/releases [VTK-m git repository]: https://gitlab.kitware.com/vtk/vtk-m/ [VTK-m Issue Tracker]: https://gitlab.kitware.com/vtk/vtk-m/-/issues [VTK-m Overview]: http://m.vtk.org/images/2/29/VTKmVis2016.pptx -[VTK-m Users Guide]: http://m.vtk.org/images/c/c8/VTKmUsersGuide.pdf +[VTK-m Users Guide]: https://gitlab.kitware.com/vtk/vtk-m-user-guide/-/wikis/home [VTK-m users email list]: http://vtk.org/mailman/listinfo/vtkm [VTK-m Wiki]: http://m.vtk.org/ [VTK-m Tutorial]: http://m.vtk.org/index.php/Tutorial