tutorial: Adding vtkm-tutorial
This commit is contained in:
parent
569deda9b5
commit
9624888982
38
vtkm-tutorial/tutorialExamples/CMakeLists.txt
Normal file
38
vtkm-tutorial/tutorialExamples/CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(VTKm_tut)
|
||||
|
||||
find_package(VTKm REQUIRED)
|
||||
|
||||
add_executable(tut_io tut_io.cxx)
|
||||
target_link_libraries(tut_io PUBLIC vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_contour tut_contour.cxx)
|
||||
target_link_libraries(tut_contour PUBLIC vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_contour_2fields tut_contour_2fields.cxx)
|
||||
target_link_libraries(tut_contour_2fields PUBLIC vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_2filters tut_2filters.cxx)
|
||||
target_link_libraries(tut_2filters PUBLIC vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_mag_grad tut_mag_grad.cxx)
|
||||
target_link_libraries(tut_mag_grad PUBLIC vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_rendering tut_rendering.cxx)
|
||||
target_link_libraries(tut_rendering PUBLIC vtkm_filter vtkm_io vtkm_rendering)
|
||||
|
||||
add_executable(tut_error_handling tut_error_handling.cxx)
|
||||
target_link_libraries(tut_error_handling PUBLIC vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_logging tut_logging.cxx)
|
||||
target_link_libraries(tut_logging PUBLIC vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_point_to_cell tut_point_to_cell.cxx)
|
||||
target_link_libraries(tut_point_to_cell PUBLIC vtkm_cont vtkm_filter vtkm_io)
|
||||
|
||||
add_executable(tut_extract_edges tut_extract_edges.cxx)
|
||||
target_link_libraries(tut_extract_edges PUBLIC vtkm_cont vtkm_filter vtkm_io)
|
||||
|
||||
|
||||
# Copy the data file to be adjacent to the binaries
|
||||
file(GENERATE OUTPUT "$<TARGET_FILE_DIR:tut_io>/data/kitchen.vtk" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/data/kitchen.vtk")
|
9
vtkm-tutorial/tutorialExamples/README.md
Normal file
9
vtkm-tutorial/tutorialExamples/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# vtk-m-tutorial
|
||||
The repository containts code samples for the tutorial of the [VTK-m code library](http://m.vtk.org).
|
||||
Other tutorial material is avaialble on the [VTK-m wiki](http://m.vtk.org/index.php/Tutorial)
|
||||
|
||||
# Organization
|
||||
The tutorial is divided into 3 sections based on what users want to accomplish with VTK-m:
|
||||
1. Using VTK-m
|
||||
2. Algorithm development with VTK-m
|
||||
3. Advanced development with VTK-m
|
32
vtkm-tutorial/tutorialExamples/azure-pipelines.yml
Normal file
32
vtkm-tutorial/tutorialExamples/azure-pipelines.yml
Normal file
@ -0,0 +1,32 @@
|
||||
# Verify VTK-m tutorial pipeline
|
||||
|
||||
schedules:
|
||||
- cron: "0 0 * * *"
|
||||
displayName: Nighly build
|
||||
branches:
|
||||
include:
|
||||
- master
|
||||
always: true
|
||||
|
||||
# Also run builds each time master changes
|
||||
trigger:
|
||||
- master
|
||||
|
||||
pool:
|
||||
vmImage: 'ubuntu-16.04'
|
||||
jobs:
|
||||
- job: BuildAndVerify
|
||||
timeoutInMinutes: 100
|
||||
steps:
|
||||
- script: |
|
||||
sudo apt update -qq
|
||||
sudo apt install -y ninja-build
|
||||
sudo apt clean
|
||||
wget https://github.com/Kitware/CMake/releases/download/v3.15.1/cmake-3.15.1-Linux-x86_64.sh
|
||||
chmod +x cmake-3.15.1-Linux-x86_64.sh
|
||||
./cmake-3.15.1-Linux-x86_64.sh --skip-license --prefix=${PWD}
|
||||
displayName: 'Setup Env with CMake 3.15, and Ninja'
|
||||
|
||||
- script: |
|
||||
./.azure/build.sh ${PWD}/bin/cmake
|
||||
displayName: 'Build VTK-m and tutorials'
|
37
vtkm-tutorial/tutorialExamples/tut_2filters.cxx
Normal file
37
vtkm-tutorial/tutorialExamples/tut_2filters.cxx
Normal file
@ -0,0 +1,37 @@
|
||||
// Example 4: do a contour and a clip-with-field, and write it out.
|
||||
//
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/filter/ClipWithField.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
vtkm::io::VTKDataSetReader reader("data/kitchen.vtk");
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
vtkm::filter::Contour contour;
|
||||
contour.SetActiveField("c1");
|
||||
contour.SetFieldsToPass({ "c1", "ke" });
|
||||
contour.SetNumberOfIsoValues(3);
|
||||
contour.SetIsoValue(0, 0.05);
|
||||
contour.SetIsoValue(1, 0.10);
|
||||
contour.SetIsoValue(2, 0.15);
|
||||
vtkm::cont::DataSet ds_from_mc = contour.Execute(ds_from_file);
|
||||
|
||||
vtkm::filter::ClipWithField clip;
|
||||
clip.SetActiveField("ke");
|
||||
clip.SetClipValue(1e-7);
|
||||
//clip.SetInvertClip(true); // <1e-7 instead of >1e-7
|
||||
|
||||
vtkm::cont::DataSet ds_from_clip = clip.Execute(ds_from_mc);
|
||||
|
||||
vtkm::io::VTKDataSetWriter writer("out_2filters.vtk");
|
||||
writer.WriteDataSet(ds_from_clip);
|
||||
|
||||
return 0;
|
||||
}
|
28
vtkm-tutorial/tutorialExamples/tut_contour.cxx
Normal file
28
vtkm-tutorial/tutorialExamples/tut_contour.cxx
Normal file
@ -0,0 +1,28 @@
|
||||
// Example 2: do a contour!, write it out.
|
||||
//
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
vtkm::io::VTKDataSetReader reader("data/kitchen.vtk");
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
vtkm::filter::Contour contour;
|
||||
contour.SetActiveField("c1");
|
||||
contour.SetNumberOfIsoValues(3);
|
||||
contour.SetIsoValue(0, 0.05);
|
||||
contour.SetIsoValue(1, 0.10);
|
||||
contour.SetIsoValue(2, 0.15);
|
||||
|
||||
vtkm::cont::DataSet ds_from_mc = contour.Execute(ds_from_file);
|
||||
vtkm::io::VTKDataSetWriter writer("out_mc.vtk");
|
||||
writer.WriteDataSet(ds_from_mc);
|
||||
|
||||
return 0;
|
||||
}
|
29
vtkm-tutorial/tutorialExamples/tut_contour_2fields.cxx
Normal file
29
vtkm-tutorial/tutorialExamples/tut_contour_2fields.cxx
Normal file
@ -0,0 +1,29 @@
|
||||
// Example 3: do a contour (but only evaluate two fields), write it out.
|
||||
//
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
vtkm::io::VTKDataSetReader reader("data/kitchen.vtk");
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
vtkm::filter::Contour contour;
|
||||
contour.SetActiveField("c1");
|
||||
contour.SetFieldsToPass({ "c1", "ke" });
|
||||
contour.SetNumberOfIsoValues(3);
|
||||
contour.SetIsoValue(0, 0.05);
|
||||
contour.SetIsoValue(1, 0.10);
|
||||
contour.SetIsoValue(2, 0.15);
|
||||
|
||||
vtkm::cont::DataSet ds_from_mc = contour.Execute(ds_from_file);
|
||||
vtkm::io::VTKDataSetWriter writer("out_mc_2fields.vtk");
|
||||
writer.WriteDataSet(ds_from_mc);
|
||||
|
||||
return 0;
|
||||
}
|
37
vtkm-tutorial/tutorialExamples/tut_error_handling.cxx
Normal file
37
vtkm-tutorial/tutorialExamples/tut_error_handling.cxx
Normal file
@ -0,0 +1,37 @@
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
try
|
||||
{
|
||||
vtkm::io::VTKDataSetReader reader("data/kitchen.vtk");
|
||||
|
||||
// PROBLEM! ... we aren't reading from a file, so we have an empty vtkm::cont::DataSet.
|
||||
//vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
vtkm::cont::DataSet ds_from_file;
|
||||
|
||||
vtkm::filter::Contour contour;
|
||||
contour.SetActiveField("c1");
|
||||
contour.SetNumberOfIsoValues(3);
|
||||
contour.SetIsoValue(0, 0.05);
|
||||
contour.SetIsoValue(1, 0.10);
|
||||
contour.SetIsoValue(2, 0.15);
|
||||
|
||||
vtkm::cont::DataSet ds_from_mc = contour.Execute(ds_from_file);
|
||||
vtkm::io::VTKDataSetWriter writer("out_mc.vtk");
|
||||
writer.WriteDataSet(ds_from_mc);
|
||||
}
|
||||
catch (const vtkm::cont::Error& error)
|
||||
{
|
||||
std::cerr << "VTK-m error occurred!: " << error.GetMessage() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
226
vtkm-tutorial/tutorialExamples/tut_extract_edges.cxx
Normal file
226
vtkm-tutorial/tutorialExamples/tut_extract_edges.cxx
Normal file
@ -0,0 +1,226 @@
|
||||
#include <vtkm/cont/ArrayHandleGroupVec.h>
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/exec/CellEdge.h>
|
||||
|
||||
#include <vtkm/worklet/AverageByKey.h>
|
||||
#include <vtkm/worklet/Keys.h>
|
||||
#include <vtkm/worklet/ScatterCounting.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/filter/FilterDataSet.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace worklet
|
||||
{
|
||||
|
||||
struct CountEdgesWorklet : vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
{
|
||||
using ControlSignature = void(CellSetIn cellSet, FieldOut numEdges);
|
||||
using ExecutionSignature = _2(CellShape, PointCount);
|
||||
|
||||
template <typename CellShapeTag>
|
||||
VTKM_EXEC_CONT vtkm::IdComponent operator()(CellShapeTag cellShape,
|
||||
vtkm::IdComponent numPointsInCell) const
|
||||
{
|
||||
vtkm::IdComponent numEdges;
|
||||
vtkm::exec::CellEdgeNumberOfEdges(numPointsInCell, cellShape, numEdges);
|
||||
return numEdges;
|
||||
}
|
||||
};
|
||||
|
||||
struct EdgeIdsWorklet : vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
{
|
||||
using ControlSignature = void(CellSetIn cellSet, FieldOut canonicalIds);
|
||||
using ExecutionSignature = void(CellShape cellShape,
|
||||
PointIndices globalPointIndices,
|
||||
VisitIndex localEdgeIndex,
|
||||
_2 canonicalIdOut);
|
||||
|
||||
using ScatterType = vtkm::worklet::ScatterCounting;
|
||||
|
||||
template <typename CellShapeTag, typename PointIndexVecType>
|
||||
VTKM_EXEC void operator()(CellShapeTag cellShape,
|
||||
const PointIndexVecType& globalPointIndicesForCell,
|
||||
vtkm::IdComponent localEdgeIndex,
|
||||
vtkm::Id2& canonicalIdOut) const
|
||||
{
|
||||
vtkm::IdComponent numPointsInCell = globalPointIndicesForCell.GetNumberOfComponents();
|
||||
|
||||
vtkm::exec::CellEdgeCanonicalId(
|
||||
numPointsInCell, localEdgeIndex, cellShape, globalPointIndicesForCell, canonicalIdOut);
|
||||
}
|
||||
};
|
||||
|
||||
struct EdgeIndicesWorklet : vtkm::worklet::WorkletReduceByKey
|
||||
{
|
||||
using ControlSignature = void(KeysIn keys,
|
||||
WholeCellSetIn<> inputCells,
|
||||
ValuesIn originCells,
|
||||
ValuesIn originEdges,
|
||||
ReducedValuesOut connectivityOut);
|
||||
using ExecutionSignature = void(_2 inputCells, _3 originCell, _4 originEdge, _5 connectivityOut);
|
||||
using InputDomain = _1;
|
||||
|
||||
template <typename CellSetType, typename OriginCellsType, typename OriginEdgesType>
|
||||
VTKM_EXEC void operator()(const CellSetType& cellSet,
|
||||
const OriginCellsType& originCells,
|
||||
const OriginEdgesType& originEdges,
|
||||
vtkm::Id2& connectivityOut) const
|
||||
{
|
||||
// Regardless of how many cells are sharing the edge we are generating, we
|
||||
// know that each cell/edge given to us by the reduce-by-key refers to the
|
||||
// same edge, so we can just look at the first cell to get the edge.
|
||||
vtkm::IdComponent numPointsInCell = cellSet.GetNumberOfIndices(originCells[0]);
|
||||
vtkm::IdComponent edgeIndex = originEdges[0];
|
||||
auto cellShape = cellSet.GetCellShape(originCells[0]);
|
||||
|
||||
vtkm::IdComponent pointInCellIndex0;
|
||||
vtkm::exec::CellEdgeLocalIndex(numPointsInCell, 0, edgeIndex, cellShape, pointInCellIndex0);
|
||||
vtkm::IdComponent pointInCellIndex1;
|
||||
vtkm::exec::CellEdgeLocalIndex(numPointsInCell, 1, edgeIndex, cellShape, pointInCellIndex1);
|
||||
|
||||
auto globalPointIndicesForCell = cellSet.GetIndices(originCells[0]);
|
||||
connectivityOut[0] = globalPointIndicesForCell[pointInCellIndex0];
|
||||
connectivityOut[1] = globalPointIndicesForCell[pointInCellIndex1];
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace worklet
|
||||
} // namespace vtkm
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
|
||||
class ExtractEdges : public vtkm::filter::FilterDataSet<ExtractEdges>
|
||||
{
|
||||
public:
|
||||
template <typename Policy>
|
||||
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData,
|
||||
vtkm::filter::PolicyBase<Policy> policy);
|
||||
|
||||
template <typename T, typename StorageType, typename Policy>
|
||||
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::ArrayHandle<T, StorageType>& input,
|
||||
const vtkm::filter::FieldMetadata& fieldMeta,
|
||||
const vtkm::filter::PolicyBase<Policy>& policy);
|
||||
|
||||
private:
|
||||
vtkm::worklet::ScatterCounting::OutputToInputMapType OutputToInputCellMap;
|
||||
vtkm::worklet::Keys<vtkm::Id2> CellToEdgeKeys;
|
||||
};
|
||||
|
||||
template <typename Policy>
|
||||
inline VTKM_CONT vtkm::cont::DataSet ExtractEdges::DoExecute(
|
||||
const vtkm::cont::DataSet& inData,
|
||||
vtkm::filter::PolicyBase<Policy> policy)
|
||||
{
|
||||
auto inCellSet = vtkm::filter::ApplyPolicyCellSet(inData.GetCellSet(), policy, *this);
|
||||
|
||||
// First, count the edges in each cell.
|
||||
vtkm::cont::ArrayHandle<vtkm::IdComponent> edgeCounts;
|
||||
this->Invoke(vtkm::worklet::CountEdgesWorklet{}, inCellSet, edgeCounts);
|
||||
|
||||
// Second, using these counts build a scatter that repeats a cell's visit
|
||||
// for each edge in the cell.
|
||||
vtkm::worklet::ScatterCounting scatter(edgeCounts);
|
||||
this->OutputToInputCellMap = scatter.GetOutputToInputMap(inCellSet.GetNumberOfCells());
|
||||
vtkm::worklet::ScatterCounting::VisitArrayType outputToInputEdgeMap =
|
||||
scatter.GetVisitArray(inCellSet.GetNumberOfCells());
|
||||
|
||||
// Third, for each edge, extract a canonical id.
|
||||
vtkm::cont::ArrayHandle<vtkm::Id2> canonicalIds;
|
||||
this->Invoke(vtkm::worklet::EdgeIdsWorklet{}, scatter, inCellSet, canonicalIds);
|
||||
|
||||
// Fourth, construct a Keys object to combine all like edge ids.
|
||||
this->CellToEdgeKeys = vtkm::worklet::Keys<vtkm::Id2>(canonicalIds);
|
||||
|
||||
// Fifth, use a reduce-by-key to extract indices for each unique edge.
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connectivityArray;
|
||||
this->Invoke(vtkm::worklet::EdgeIndicesWorklet{},
|
||||
this->CellToEdgeKeys,
|
||||
inCellSet,
|
||||
this->OutputToInputCellMap,
|
||||
outputToInputEdgeMap,
|
||||
vtkm::cont::make_ArrayHandleGroupVec<2>(connectivityArray));
|
||||
|
||||
// Sixth, use the created connectivity array to build a cell set.
|
||||
vtkm::cont::CellSetSingleType<> outCellSet;
|
||||
outCellSet.Fill(inCellSet.GetNumberOfPoints(), vtkm::CELL_SHAPE_LINE, 2, connectivityArray);
|
||||
|
||||
vtkm::cont::DataSet outData;
|
||||
|
||||
outData.SetCellSet(outCellSet);
|
||||
|
||||
for (vtkm::IdComponent coordSystemIndex = 0;
|
||||
coordSystemIndex < inData.GetNumberOfCoordinateSystems();
|
||||
++coordSystemIndex)
|
||||
{
|
||||
outData.AddCoordinateSystem(inData.GetCoordinateSystem(coordSystemIndex));
|
||||
}
|
||||
|
||||
return outData;
|
||||
}
|
||||
|
||||
template <typename T, typename StorageType, typename Policy>
|
||||
inline VTKM_CONT bool ExtractEdges::DoMapField(
|
||||
vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::ArrayHandle<T, StorageType>& inputArray,
|
||||
const vtkm::filter::FieldMetadata& fieldMeta,
|
||||
const vtkm::filter::PolicyBase<Policy>&)
|
||||
{
|
||||
vtkm::cont::Field outputField;
|
||||
|
||||
if (fieldMeta.IsPointField())
|
||||
{
|
||||
outputField = fieldMeta.AsField(inputArray); // pass through
|
||||
}
|
||||
else if (fieldMeta.IsCellField())
|
||||
{
|
||||
auto outputCellArray = vtkm::worklet::AverageByKey::Run(
|
||||
this->CellToEdgeKeys,
|
||||
vtkm::cont::make_ArrayHandlePermutation(this->OutputToInputCellMap, inputArray));
|
||||
outputField = fieldMeta.AsField(outputCellArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result.AddField(outputField);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
const char* input = "data/kitchen.vtk";
|
||||
vtkm::io::VTKDataSetReader reader(input);
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
vtkm::filter::Contour contour;
|
||||
contour.SetActiveField("c1");
|
||||
contour.SetIsoValue(0.10);
|
||||
vtkm::cont::DataSet ds_from_contour = contour.Execute(ds_from_file);
|
||||
|
||||
vtkm::filter::ExtractEdges extractEdges;
|
||||
vtkm::cont::DataSet wireframe = extractEdges.Execute(ds_from_contour);
|
||||
|
||||
vtkm::io::VTKDataSetWriter writer("out_wireframe.vtk");
|
||||
writer.WriteDataSet(wireframe);
|
||||
|
||||
return 0;
|
||||
}
|
20
vtkm-tutorial/tutorialExamples/tut_io.cxx
Normal file
20
vtkm-tutorial/tutorialExamples/tut_io.cxx
Normal file
@ -0,0 +1,20 @@
|
||||
// Example 1: very simple VTK-m program.
|
||||
// Read data set, write it out.
|
||||
//
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
const char* input = "data/kitchen.vtk";
|
||||
vtkm::io::VTKDataSetReader reader(input);
|
||||
vtkm::cont::DataSet ds = reader.ReadDataSet();
|
||||
vtkm::io::VTKDataSetWriter writer("out_io.vtk");
|
||||
writer.WriteDataSet(ds);
|
||||
|
||||
return 0;
|
||||
}
|
27
vtkm-tutorial/tutorialExamples/tut_logging.cxx
Normal file
27
vtkm-tutorial/tutorialExamples/tut_logging.cxx
Normal file
@ -0,0 +1,27 @@
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
|
||||
// SetLogLevelName must be called before Initialize
|
||||
vtkm::cont::SetLogLevelName(vtkm::cont::LogLevel::UserFirst, "tut_log");
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
const std::string input = "data/kitchen.vtk";
|
||||
vtkm::io::VTKDataSetReader reader(input);
|
||||
VTKM_LOG_F(vtkm::cont::LogLevel::Info, "Reading from file %s", input.c_str());
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
VTKM_LOG_F(vtkm::cont::LogLevel::Info, "Done reading from file %s", input.c_str());
|
||||
|
||||
const std::string output = "out_logging.vtk";
|
||||
VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Writing to file" << output);
|
||||
vtkm::io::VTKDataSetWriter writer(output);
|
||||
writer.WriteDataSet(ds_from_file);
|
||||
VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Done writing to file" << output);
|
||||
|
||||
return 0;
|
||||
}
|
70
vtkm-tutorial/tutorialExamples/tut_mag_grad.cxx
Normal file
70
vtkm-tutorial/tutorialExamples/tut_mag_grad.cxx
Normal file
@ -0,0 +1,70 @@
|
||||
#include <vtkm/VectorAnalysis.h>
|
||||
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/filter/Gradient.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/Gradient.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
struct ComputeMagnitude : vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn inputVectors, FieldOut outputMagnitudes);
|
||||
|
||||
VTKM_EXEC void operator()(const vtkm::Vec3f& inVector, vtkm::FloatDefault& outMagnitude) const
|
||||
{
|
||||
outMagnitude = vtkm::Magnitude(inVector);
|
||||
}
|
||||
};
|
||||
|
||||
#include <vtkm/filter/FilterField.h>
|
||||
|
||||
class FieldMagnitude : public vtkm::filter::FilterField<FieldMagnitude>
|
||||
{
|
||||
public:
|
||||
using SupportedTypes = vtkm::ListTagBase<vtkm::Vec3f>;
|
||||
|
||||
template <typename ArrayHandleType, typename Policy>
|
||||
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inDataSet,
|
||||
const ArrayHandleType& inField,
|
||||
const vtkm::filter::FieldMetadata& fieldMetadata,
|
||||
vtkm::filter::PolicyBase<Policy>)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> outField;
|
||||
this->Invoke(ComputeMagnitude{}, inField, outField);
|
||||
|
||||
std::string outFieldName = this->GetOutputFieldName();
|
||||
if (outFieldName == "")
|
||||
{
|
||||
outFieldName = fieldMetadata.GetName() + "_magnitude";
|
||||
}
|
||||
|
||||
return vtkm::filter::CreateResult(inDataSet, outField, outFieldName, fieldMetadata);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
vtkm::io::VTKDataSetReader reader("data/kitchen.vtk");
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
vtkm::filter::Gradient grad;
|
||||
grad.SetActiveField("c1");
|
||||
vtkm::cont::DataSet ds_from_grad = grad.Execute(ds_from_file);
|
||||
|
||||
FieldMagnitude mag;
|
||||
mag.SetActiveField("Gradients");
|
||||
vtkm::cont::DataSet mag_grad = mag.Execute(ds_from_grad);
|
||||
|
||||
vtkm::io::VTKDataSetWriter writer("out_mag_grad.vtk");
|
||||
writer.WriteDataSet(mag_grad);
|
||||
|
||||
return 0;
|
||||
}
|
94
vtkm-tutorial/tutorialExamples/tut_mag_grad_generalized.cxx
Normal file
94
vtkm-tutorial/tutorialExamples/tut_mag_grad_generalized.cxx
Normal file
@ -0,0 +1,94 @@
|
||||
#include <vtkm/VecTraits.h>
|
||||
#include <vtkm/VectorAnalysis.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
#include <vtkm/cont/VariantArrayHandle.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/Gradient.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace worklet
|
||||
{
|
||||
|
||||
struct Magnitude : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn inputVectors, FieldOut outputMagnitudes);
|
||||
|
||||
template <typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC void operator()(const vtkm::Vec<T, Size>& inVector, T& outMagnitude) const
|
||||
{
|
||||
outMagnitude = vtkm::Magnitude(inVector);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace worklet
|
||||
} // namespace vtkm
|
||||
|
||||
#include <vtkm/filter/FilterField.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
|
||||
class FieldMagnitude : public vtkm::filter::FilterField<FieldMagnitude>
|
||||
{
|
||||
public:
|
||||
using SupportedTypes = vtkm::TypeListTagVecCommon;
|
||||
|
||||
template <typename ArrayHandleType, typename Policy>
|
||||
VTKM_CONT cont::DataSet DoExecute(const vtkm::cont::DataSet& inDataSet,
|
||||
const ArrayHandleType& inField,
|
||||
const vtkm::filter::FieldMetadata& fieldMetadata,
|
||||
vtkm::filter::PolicyBase<Policy>)
|
||||
{
|
||||
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
||||
|
||||
using ValueType = typename ArrayHandleType::ValueType;
|
||||
using ComponentType = decltype(ValueType{}[0]); //component type of vector
|
||||
|
||||
vtkm::cont::ArrayHandle<ComponentType> outField;
|
||||
this->Invoke(vtkm::worklet::Magnitude{}, inField, outField);
|
||||
|
||||
std::string outFieldName = this->GetOutputFieldName();
|
||||
if (outFieldName == "")
|
||||
{
|
||||
outFieldName = fieldMetadata.GetName() + "_magnitude";
|
||||
}
|
||||
|
||||
return vtkm::filter::CreateResult(inDataSet, outField, outFieldName, fieldMetadata);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
vtkm::io::VTKDataSetReader reader("data/kitchen.vtk");
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
vtkm::filter::Gradient grad;
|
||||
grad.SetActiveField("c1");
|
||||
vtkm::cont::DataSet ds_from_grad = grad.Execute(ds_from_file);
|
||||
|
||||
vtkm::filter::FieldMagnitude mag;
|
||||
mag.SetActiveField("Gradients");
|
||||
vtkm::cont::DataSet mag_grad = mag.Execute(ds_from_grad);
|
||||
|
||||
vtkm::io::VTKDataSetWriter writer("out_mag_grad.vtk");
|
||||
writer.WriteDataSet(mag_grad);
|
||||
|
||||
return 0;
|
||||
}
|
101
vtkm-tutorial/tutorialExamples/tut_point_to_cell.cxx
Normal file
101
vtkm-tutorial/tutorialExamples/tut_point_to_cell.cxx
Normal file
@ -0,0 +1,101 @@
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace worklet
|
||||
{
|
||||
|
||||
struct ConvertPointFieldToCells : vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
{
|
||||
using ControlSignature = void(CellSetIn topology,
|
||||
FieldInPoint inPointField,
|
||||
FieldOutCell outCellField);
|
||||
using ExecutionSignature = void(_2 inPointField, _3 outCellField);
|
||||
using InputDomain = _1;
|
||||
|
||||
template <typename InPointFieldVecType, typename OutCellFieldType>
|
||||
void operator()(const InPointFieldVecType& inPointFieldVec, OutCellFieldType& outCellField) const
|
||||
{
|
||||
vtkm::IdComponent numPoints = inPointFieldVec.GetNumberOfComponents();
|
||||
|
||||
outCellField = OutCellFieldType(0);
|
||||
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; ++pointIndex)
|
||||
{
|
||||
outCellField = outCellField + inPointFieldVec[pointIndex];
|
||||
}
|
||||
outCellField = outCellField / OutCellFieldType(numPoints);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace worklet
|
||||
} // namespace vtkm
|
||||
|
||||
#include <vtkm/filter/FilterField.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
|
||||
struct ConvertPointFieldToCells : vtkm::filter::FilterField<ConvertPointFieldToCells>
|
||||
{
|
||||
template <typename ArrayHandleType, typename Policy>
|
||||
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inDataSet,
|
||||
const ArrayHandleType& inField,
|
||||
const vtkm::filter::FieldMetadata& fieldMetadata,
|
||||
vtkm::filter::PolicyBase<Policy>);
|
||||
};
|
||||
|
||||
template <typename ArrayHandleType, typename Policy>
|
||||
VTKM_CONT cont::DataSet ConvertPointFieldToCells::DoExecute(
|
||||
const vtkm::cont::DataSet& inDataSet,
|
||||
const ArrayHandleType& inField,
|
||||
const vtkm::filter::FieldMetadata& fieldMetadata,
|
||||
vtkm::filter::PolicyBase<Policy> policy)
|
||||
{
|
||||
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
||||
|
||||
using ValueType = typename ArrayHandleType::ValueType;
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> outField;
|
||||
this->Invoke(vtkm::worklet::ConvertPointFieldToCells{},
|
||||
vtkm::filter::ApplyPolicyCellSet(inDataSet.GetCellSet(), policy, *this),
|
||||
inField,
|
||||
outField);
|
||||
|
||||
std::string outFieldName = this->GetOutputFieldName();
|
||||
if (outFieldName == "")
|
||||
{
|
||||
outFieldName = fieldMetadata.GetName();
|
||||
}
|
||||
|
||||
return vtkm::filter::CreateResultFieldCell(inDataSet, outField, outFieldName);
|
||||
}
|
||||
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
const char* input = "data/kitchen.vtk";
|
||||
vtkm::io::VTKDataSetReader reader(input);
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
vtkm::filter::ConvertPointFieldToCells pointToCell;
|
||||
pointToCell.SetActiveField("c1");
|
||||
vtkm::cont::DataSet ds_from_convert = pointToCell.Execute(ds_from_file);
|
||||
|
||||
vtkm::io::VTKDataSetWriter writer("out_point_to_cell.vtk");
|
||||
writer.WriteDataSet(ds_from_convert);
|
||||
|
||||
return 0;
|
||||
}
|
49
vtkm-tutorial/tutorialExamples/tut_rendering.cxx
Normal file
49
vtkm-tutorial/tutorialExamples/tut_rendering.cxx
Normal file
@ -0,0 +1,49 @@
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
#include <vtkm/rendering/MapperRayTracer.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
||||
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
||||
|
||||
//Loading .vtk File
|
||||
vtkm::io::VTKDataSetReader reader("data/kitchen.vtk");
|
||||
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
||||
|
||||
//Creating Actor
|
||||
vtkm::cont::ColorTable colorTable("viridis");
|
||||
vtkm::rendering::Actor actor(ds_from_file.GetCellSet(),
|
||||
ds_from_file.GetCoordinateSystem(),
|
||||
ds_from_file.GetField("c1"),
|
||||
colorTable);
|
||||
|
||||
//Creating Scene and adding Actor
|
||||
vtkm::rendering::Scene scene;
|
||||
scene.AddActor(actor);
|
||||
|
||||
//Creating and initializing the View using the Canvas, Ray Tracer Mappers, and Scene
|
||||
vtkm::rendering::MapperRayTracer mapper;
|
||||
vtkm::rendering::CanvasRayTracer canvas(1920, 1080);
|
||||
vtkm::rendering::View3D view(scene, mapper, canvas);
|
||||
|
||||
//Setting the background and foreground colors; optional.
|
||||
view.SetBackgroundColor(vtkm::rendering::Color(1.0f, 1.0f, 1.0f));
|
||||
view.SetForegroundColor(vtkm::rendering::Color(0.0f, 0.0f, 0.0f));
|
||||
|
||||
//Painting View
|
||||
view.Paint();
|
||||
|
||||
//Saving View
|
||||
view.SaveAs("BasicRendering.ppm");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user