mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 02:25:42 +00:00
Update demo to exhibit more VTK-m capabilities.
This commit is contained in:
parent
69e8c9948a
commit
1c7b41aa5f
@ -7,7 +7,7 @@
|
|||||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
## PURPOSE. See the above copyright notice for more information.
|
## PURPOSE. See the above copyright notice for more information.
|
||||||
##============================================================================
|
##============================================================================
|
||||||
cmake_minimum_required(VERSION 3.12...3.15 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.12...3.18 FATAL_ERROR)
|
||||||
project(VTKmDemo CXX)
|
project(VTKmDemo CXX)
|
||||||
|
|
||||||
#Find the VTK-m package
|
#Find the VTK-m package
|
||||||
@ -15,7 +15,7 @@ find_package(VTKm REQUIRED QUIET)
|
|||||||
|
|
||||||
if(TARGET vtkm_rendering)
|
if(TARGET vtkm_rendering)
|
||||||
add_executable(Demo Demo.cxx)
|
add_executable(Demo Demo.cxx)
|
||||||
target_link_libraries(Demo PRIVATE vtkm_filter vtkm_rendering)
|
target_link_libraries(Demo PRIVATE vtkm_filter vtkm_rendering vtkm_source)
|
||||||
vtkm_add_target_information(Demo
|
vtkm_add_target_information(Demo
|
||||||
DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS
|
DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS
|
||||||
DEVICE_SOURCES Demo.cxx)
|
DEVICE_SOURCES Demo.cxx)
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <vtkm/cont/Initialize.h>
|
#include <vtkm/cont/Initialize.h>
|
||||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
#include <vtkm/source/Tangle.h>
|
||||||
|
|
||||||
#include <vtkm/rendering/Actor.h>
|
#include <vtkm/rendering/Actor.h>
|
||||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||||
#include <vtkm/rendering/MapperRayTracer.h>
|
#include <vtkm/rendering/MapperRayTracer.h>
|
||||||
|
#include <vtkm/rendering/MapperVolume.h>
|
||||||
|
#include <vtkm/rendering/MapperWireframer.h>
|
||||||
#include <vtkm/rendering/Scene.h>
|
#include <vtkm/rendering/Scene.h>
|
||||||
#include <vtkm/rendering/View3D.h>
|
#include <vtkm/rendering/View3D.h>
|
||||||
|
|
||||||
@ -23,82 +25,71 @@
|
|||||||
// write that image to a file. It then computes an isosurface on the input data set and renders
|
// 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
|
// this output data set in a separate image file
|
||||||
|
|
||||||
|
using vtkm::rendering::MapperVolume;
|
||||||
|
using vtkm::rendering::MapperRayTracer;
|
||||||
|
using vtkm::rendering::MapperWireframer;
|
||||||
|
using vtkm::rendering::CanvasRayTracer;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
vtkm::cont::Initialize(argc, argv, vtkm::cont::InitializeOptions::Strict);
|
vtkm::cont::Initialize(argc, argv, vtkm::cont::InitializeOptions::Strict);
|
||||||
|
|
||||||
// Input variable declarations
|
auto tangle = vtkm::source::Tangle(vtkm::Id3{ 50, 50, 50 });
|
||||||
vtkm::cont::testing::MakeTestDataSet maker;
|
vtkm::cont::DataSet tangleData = tangle.Execute();
|
||||||
vtkm::cont::DataSet inputData = maker.Make3DUniformDataSet0();
|
std::string fieldName = "nodevar";
|
||||||
vtkm::Float32 isovalue = 100.0f;
|
|
||||||
std::string fieldName = "pointvar";
|
|
||||||
|
|
||||||
using Mapper = vtkm::rendering::MapperRayTracer;
|
|
||||||
using Canvas = vtkm::rendering::CanvasRayTracer;
|
|
||||||
|
|
||||||
// Set up a camera for rendering the input data
|
// Set up a camera for rendering the input data
|
||||||
const vtkm::cont::CoordinateSystem coords = inputData.GetCoordinateSystem();
|
|
||||||
Mapper mapper;
|
|
||||||
vtkm::rendering::Camera camera;
|
vtkm::rendering::Camera camera;
|
||||||
|
camera.SetLookAt(vtkm::Vec3f_32(0.5, 0.5, 0.5));
|
||||||
//Set3DView
|
|
||||||
vtkm::Bounds coordsBounds = coords.GetBounds();
|
|
||||||
|
|
||||||
camera.ResetToBounds(coordsBounds);
|
|
||||||
|
|
||||||
vtkm::Vec3f_32 totalExtent;
|
|
||||||
totalExtent[0] = vtkm::Float32(coordsBounds.X.Length());
|
|
||||||
totalExtent[1] = vtkm::Float32(coordsBounds.Y.Length());
|
|
||||||
totalExtent[2] = vtkm::Float32(coordsBounds.Z.Length());
|
|
||||||
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
|
|
||||||
vtkm::Normalize(totalExtent);
|
|
||||||
camera.SetLookAt(totalExtent * (mag * .5f));
|
|
||||||
camera.SetViewUp(vtkm::make_Vec(0.f, 1.f, 0.f));
|
camera.SetViewUp(vtkm::make_Vec(0.f, 1.f, 0.f));
|
||||||
camera.SetClippingRange(1.f, 100.f);
|
camera.SetClippingRange(1.f, 10.f);
|
||||||
camera.SetFieldOfView(60.f);
|
camera.SetFieldOfView(60.f);
|
||||||
camera.SetPosition(totalExtent * (mag * 2.f));
|
camera.SetPosition(vtkm::Vec3f_32(1.5, 1.5, 1.5));
|
||||||
vtkm::cont::ColorTable colorTable("inferno");
|
vtkm::cont::ColorTable colorTable("inferno");
|
||||||
|
|
||||||
// Create a scene for rendering the input data
|
// Background color:
|
||||||
vtkm::rendering::Scene scene;
|
|
||||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
Canvas canvas(512, 512);
|
vtkm::rendering::Actor actor(tangleData.GetCellSet(),
|
||||||
|
tangleData.GetCoordinateSystem(),
|
||||||
vtkm::rendering::Actor actor(inputData.GetCellSet(),
|
tangleData.GetField(fieldName),
|
||||||
inputData.GetCoordinateSystem(),
|
|
||||||
inputData.GetField(fieldName),
|
|
||||||
colorTable);
|
colorTable);
|
||||||
|
vtkm::rendering::Scene scene;
|
||||||
scene.AddActor(actor);
|
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
|
// Create a view and use it to render the input data using OS Mesa
|
||||||
vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg);
|
vtkm::rendering::View3D view(scene, MapperVolume(), canvas, camera, bg);
|
||||||
view.Initialize();
|
view.Initialize();
|
||||||
view.Paint();
|
view.Paint();
|
||||||
view.SaveAs("demo_input.pnm");
|
view.SaveAs("volume.png");
|
||||||
|
|
||||||
// Create an isosurface filter
|
// Compute an isosurface:
|
||||||
vtkm::filter::Contour filter;
|
vtkm::filter::Contour filter;
|
||||||
filter.SetGenerateNormals(false);
|
// [min, max] of the tangle field is [-0.887, 24.46]:
|
||||||
filter.SetMergeDuplicatePoints(false);
|
filter.SetIsoValue(3.0);
|
||||||
filter.SetIsoValue(0, isovalue);
|
|
||||||
filter.SetActiveField(fieldName);
|
filter.SetActiveField(fieldName);
|
||||||
vtkm::cont::DataSet outputData = filter.Execute(inputData);
|
vtkm::cont::DataSet isoData = filter.Execute(tangleData);
|
||||||
// Render a separate image with the output isosurface
|
// Render a separate image with the output isosurface
|
||||||
std::cout << "about to render the results of the Contour filter" << std::endl;
|
vtkm::rendering::Actor isoActor(
|
||||||
vtkm::rendering::Scene scene2;
|
isoData.GetCellSet(), isoData.GetCoordinateSystem(), isoData.GetField(fieldName), colorTable);
|
||||||
vtkm::rendering::Actor actor2(outputData.GetCellSet(),
|
|
||||||
outputData.GetCoordinateSystem(),
|
|
||||||
outputData.GetField(fieldName),
|
|
||||||
colorTable);
|
|
||||||
// By default, the actor will automatically scale the scalar range of the color table to match
|
// 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
|
// 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.
|
// from, so we want the scalar range to match that of the previous image.
|
||||||
actor2.SetScalarRange(actor.GetScalarRange());
|
isoActor.SetScalarRange(actor.GetScalarRange());
|
||||||
scene2.AddActor(actor2);
|
vtkm::rendering::Scene isoScene;
|
||||||
|
isoScene.AddActor(isoActor);
|
||||||
|
|
||||||
vtkm::rendering::View3D view2(scene2, mapper, canvas, camera, bg);
|
// Wireframe surface:
|
||||||
view2.Initialize();
|
vtkm::rendering::View3D isoView(isoScene, MapperWireframer(), canvas, camera, bg);
|
||||||
view2.Paint();
|
isoView.Initialize();
|
||||||
view2.SaveAs("demo_output.pnm");
|
isoView.Paint();
|
||||||
|
isoView.SaveAs("isosurface_wireframer.png");
|
||||||
|
|
||||||
|
// Smooth surface:
|
||||||
|
vtkm::rendering::View3D solidView(isoScene, MapperRayTracer(), canvas, camera, bg);
|
||||||
|
solidView.Initialize();
|
||||||
|
solidView.Paint();
|
||||||
|
solidView.SaveAs("isosurface_raytracer.png");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user