Simplify demo example

This commit is contained in:
Kenneth Moreland 2019-07-31 16:28:24 -06:00
parent fb3c9e8186
commit 738ab0e9ad

@ -8,10 +8,8 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/rendering/Actor.h>
#include <vtkm/rendering/CanvasRayTracer.h>
@ -19,57 +17,21 @@
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/View3D.h>
#include <vtkm/io/reader/VTKDataSetReader.h>
#include <vtkm/cont/DataSetFieldAdd.h>
#include <vtkm/filter/MarchingCubes.h>
#include <iostream>
void makeScene(const vtkm::cont::DataSet& inputData,
const vtkm::cont::ColorTable& colorTable,
const std::string& fieldName,
vtkm::rendering::Scene& scene)
{
scene.AddActor(vtkm::rendering::Actor(inputData.GetCellSet(),
inputData.GetCoordinateSystem(),
inputData.GetField(fieldName),
colorTable));
}
// This example reads an input vtk file specified on the command-line (or generates a default
// input data set if none is provided), uses VTK-m's rendering engine to render it to an
// output file using OS Mesa, instantiates an isosurface filter using VTK-m's filter
// mechanism, computes an isosurface on the input data set, packages the output of the filter
// in a new data set, and renders this output data set in a separate iamge file, again
// using VTK-m's rendering engine with OS Mesa.
// This example creates a simple data set and uses 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
int main(int argc, char* argv[])
{
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
vtkm::cont::Initialize(argc, argv, vtkm::cont::InitializeOptions::Strict);
// Input variable declarations
vtkm::cont::DataSet inputData;
vtkm::Float32 isovalue;
std::string fieldName;
// Get input data from specified file, or generate test data set
if (argc < 3)
{
vtkm::cont::testing::MakeTestDataSet maker;
inputData = maker.Make3DUniformDataSet0();
isovalue = 100.0f;
fieldName = "pointvar";
}
else
{
std::cout << "using: " << argv[1] << " as MarchingCubes input file" << std::endl;
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
inputData = reader.ReadDataSet();
isovalue = static_cast<vtkm::Float32>(atof(argv[2]));
fieldName = "pointvar";
}
vtkm::cont::testing::MakeTestDataSet maker;
vtkm::cont::DataSet inputData = maker.Make3DUniformDataSet0();
vtkm::Float32 isovalue = 100.0f;
std::string fieldName = "pointvar";
using Mapper = vtkm::rendering::MapperRayTracer;
using Canvas = vtkm::rendering::CanvasRayTracer;
@ -77,7 +39,7 @@ int main(int argc, char* argv[])
// 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();
vtkm::rendering::Camera camera;
//Set3DView
vtkm::Bounds coordsBounds = coords.GetBounds();
@ -85,9 +47,9 @@ int main(int argc, char* argv[])
camera.ResetToBounds(coordsBounds);
vtkm::Vec3f_32 totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds.X.Max - coordsBounds.X.Min);
totalExtent[1] = vtkm::Float32(coordsBounds.Y.Max - coordsBounds.Y.Min);
totalExtent[2] = vtkm::Float32(coordsBounds.Z.Max - coordsBounds.Z.Min);
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));
@ -102,7 +64,11 @@ int main(int argc, char* argv[])
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
Canvas canvas(512, 512);
makeScene(inputData, colorTable, fieldName, scene);
vtkm::rendering::Actor actor(inputData.GetCellSet(),
inputData.GetCoordinateSystem(),
inputData.GetField(fieldName),
colorTable);
scene.AddActor(actor);
// Create a view and use it to render the input data using OS Mesa
vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg);
view.Initialize();
@ -119,7 +85,15 @@ int main(int argc, char* argv[])
// Render a separate image with the output isosurface
std::cout << "about to render the results of the MarchingCubes filter" << std::endl;
vtkm::rendering::Scene scene2;
makeScene(outputData, colorTable, fieldName, scene2);
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
// 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.
actor2.SetScalarRange(actor.GetScalarRange());
scene2.AddActor(actor2);
vtkm::rendering::View3D view2(scene2, mapper, canvas, camera, bg);
view2.Initialize();