mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Merge branch 'master' into marching_cell_wedge
This commit is contained in:
commit
8c0787b5de
@ -169,3 +169,4 @@ include:
|
||||
- local: '/.gitlab/ci/rhel8.yml'
|
||||
- local: '/.gitlab/ci/ubuntu1604.yml'
|
||||
- local: '/.gitlab/ci/ubuntu1804.yml'
|
||||
- local: '/.gitlab/ci/windows10.yml'
|
||||
|
@ -74,10 +74,13 @@ if(DEFINED ENV{CTEST_MEMORYCHECK_SANITIZER_OPTIONS})
|
||||
endif()
|
||||
|
||||
#We need to do write this information out to a file in the build directory
|
||||
file(TO_CMAKE_PATH "${CTEST_SOURCE_DIRECTORY}" src_path) #converted so we can run on windows
|
||||
file(TO_CMAKE_PATH "${CTEST_BINARY_DIRECTORY}" bin_path) #converted so we can run on windows
|
||||
|
||||
set(state
|
||||
"
|
||||
set(CTEST_SOURCE_DIRECTORY \"${CTEST_SOURCE_DIRECTORY}\")
|
||||
set(CTEST_BINARY_DIRECTORY \"${CTEST_BINARY_DIRECTORY}\")
|
||||
set(CTEST_SOURCE_DIRECTORY \"${src_path}\")
|
||||
set(CTEST_BINARY_DIRECTORY \"${bin_path}\")
|
||||
|
||||
set(CTEST_BUILD_NAME ${CTEST_BUILD_NAME})
|
||||
set(CTEST_SITE ${CTEST_SITE})
|
||||
|
14
.gitlab/ci/config/setup_vs_powershell.ps1
Normal file
14
.gitlab/ci/config/setup_vs_powershell.ps1
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
$tempFile = "$env:temp\vcvars.txt"
|
||||
|
||||
if ($env:CI_JOB_NAME -eq "build:windows_vs2019") {
|
||||
cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat`" && set > $tempFile"
|
||||
} else {
|
||||
cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat`" && set > $tempFile"
|
||||
}
|
||||
|
||||
Get-Content "$tempFile" | Foreach-Object {
|
||||
if ($_ -match "^(.*?)=(.*)$") {
|
||||
Set-Content "env:\$($matches[1])" $matches[2]
|
||||
}
|
||||
}
|
@ -52,6 +52,25 @@ build:ubuntu1604_gcc5:
|
||||
# needs:
|
||||
# - build:ubuntu1604_gcc5
|
||||
|
||||
# Build on ubuntu1704 with OpenMP + CUDA
|
||||
# Runs only on nightlies
|
||||
build:ubuntu1604_gcc5_2:
|
||||
tags:
|
||||
- build
|
||||
- vtkm
|
||||
- docker
|
||||
- linux
|
||||
- large-memory
|
||||
extends:
|
||||
- .ubuntu1604_cuda
|
||||
- .cmake_build_linux
|
||||
- .only-master
|
||||
variables:
|
||||
CC: "gcc-5"
|
||||
CXX: "g++-5"
|
||||
CMAKE_BUILD_TYPE: Release
|
||||
VTKM_SETTINGS: "openmp+cuda+pascal+examples"
|
||||
|
||||
# Build on ubuntu1604 with mpi + tbb and test on ubuntu1604
|
||||
# Uses gcc 4.8
|
||||
# Uses OpenMPI
|
||||
@ -105,8 +124,6 @@ build:ubuntu1604_clang5:
|
||||
- docker
|
||||
- linux
|
||||
extends:
|
||||
#Requires the cuda docker image as it uses a sufficiently new
|
||||
#enough CMake version that supports mpi
|
||||
- .ubuntu1604
|
||||
- .cmake_build_linux
|
||||
- .only-default
|
||||
|
@ -126,7 +126,7 @@ build:ubuntu1804_gcc6:
|
||||
variables:
|
||||
CC: "gcc-6"
|
||||
CXX: "g++-6"
|
||||
VTKM_SETTINGS: "openmp+shared"
|
||||
VTKM_SETTINGS: "openmp+shared+examples"
|
||||
|
||||
test:ubuntu1804_gcc6:
|
||||
tags:
|
||||
@ -163,7 +163,7 @@ build:ubuntu1804_clang8:
|
||||
CC: "clang-8"
|
||||
CXX: "clang++-8"
|
||||
CMAKE_BUILD_TYPE: Debug
|
||||
VTKM_SETTINGS: "tbb+shared"
|
||||
VTKM_SETTINGS: "tbb+shared+examples"
|
||||
|
||||
test:ubuntu1804_clang8:
|
||||
tags:
|
||||
|
87
.gitlab/ci/windows10.yml
Normal file
87
.gitlab/ci/windows10.yml
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
.cmake_build_windows: &cmake_build_windows
|
||||
stage: build
|
||||
timeout: 2 hours
|
||||
interruptible: true
|
||||
before_script:
|
||||
- .gitlab/ci/config/setup_vs_powershell.ps1
|
||||
- "cmake --version"
|
||||
- "cmake -V -P .gitlab/ci/config/gitlab_ci_setup.cmake"
|
||||
- "ctest -VV -S .gitlab/ci/ctest_configure.cmake"
|
||||
script:
|
||||
- "ctest -VV -S .gitlab/ci/ctest_build.cmake"
|
||||
artifacts:
|
||||
expire_in: 24 hours
|
||||
when: always
|
||||
paths:
|
||||
# The artifacts of the build.
|
||||
- build/bin/
|
||||
- build/include/
|
||||
- build/lib/
|
||||
|
||||
# CTest and CMake install files.
|
||||
# XXX(globbing): Can be simplified with support from
|
||||
# https://gitlab.com/gitlab-org/gitlab-runner/issues/4840
|
||||
#
|
||||
# Note: this also captures our CIState.cmake file
|
||||
- build/CMakeCache.txt
|
||||
- build/*.cmake
|
||||
- build/*/*.cmake
|
||||
- build/*/*/*.cmake
|
||||
- build/*/*/*/*.cmake
|
||||
- build/*/*/*/*/*.cmake
|
||||
- build/*/*/*/*/*/*.cmake
|
||||
- build/Testing/
|
||||
|
||||
# CDash files.
|
||||
- build/DartConfiguration.tcl
|
||||
|
||||
|
||||
.cmake_test_windows: &cmake_test_windows
|
||||
stage: test
|
||||
timeout: 50 minutes
|
||||
interruptible: true
|
||||
before_script:
|
||||
- .gitlab/ci/config/setup_vs_powershell.ps1
|
||||
script:
|
||||
#Need to use our custom ctest-latest symlink
|
||||
#This will allow us to use 3.17+ which has support
|
||||
#for running failed tests multiple times so failures
|
||||
#due to system load are not reported
|
||||
- "ctest-latest -VV -S .gitlab/ci/ctest_test.cmake"
|
||||
|
||||
# Build on windows10 with Visual Studio
|
||||
# Will have CUDA 10.2 once build issues are resolved
|
||||
build:windows_vs2019:
|
||||
tags:
|
||||
- build
|
||||
- vtkm
|
||||
- windows
|
||||
- vs2019
|
||||
- shell
|
||||
- large-memory
|
||||
extends:
|
||||
- .cmake_build_windows
|
||||
- .only-default
|
||||
variables:
|
||||
CMAKE_GENERATOR: "Ninja"
|
||||
CMAKE_BUILD_TYPE: Release
|
||||
# Disabled while we track down cub allocator issues with vtkm/io tests
|
||||
# VTKM_SETTINGS: "cuda+turing"
|
||||
VTKM_SETTINGS: "serial"
|
||||
|
||||
test:windows_vs2019:
|
||||
tags:
|
||||
- test
|
||||
- vtkm
|
||||
- windows
|
||||
- shell
|
||||
- cuda-rt
|
||||
- turing
|
||||
extends:
|
||||
- .cmake_test_windows
|
||||
- .only-default
|
||||
dependencies:
|
||||
- build:windows_vs2019
|
||||
needs:
|
||||
- build:windows_vs2019
|
@ -157,7 +157,7 @@ Marching Cubes algorithm on it, and render the results to an image:
|
||||
#include <vtkm/Range.h>
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
@ -166,7 +166,7 @@ Marching Cubes algorithm on it, and render the results to an image:
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader("path/to/vtk_image_file");
|
||||
vtkm::io::VTKDataSetReader reader("path/to/vtk_image_file.vtk");
|
||||
vtkm::cont::DataSet inputData = reader.ReadDataSet();
|
||||
std::string fieldName = "scalars";
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include <vtkm/filter/WarpScalar.h>
|
||||
#include <vtkm/filter/WarpVector.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
#include <vtkm/source/Wavelet.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
@ -1005,7 +1005,7 @@ void InitDataSet(int& argc, char** argv)
|
||||
if (!filename.empty())
|
||||
{
|
||||
std::cerr << "[InitDataSet] Loading file: " << filename << "\n";
|
||||
vtkm::io::reader::VTKDataSetReader reader(filename);
|
||||
vtkm::io::VTKDataSetReader reader(filename);
|
||||
InputDataSet = reader.ReadDataSet();
|
||||
}
|
||||
else
|
||||
|
7
docs/changelog/io_reorganize.md
Normal file
7
docs/changelog/io_reorganize.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Reorganization of `io` directory
|
||||
|
||||
The `vtkm/io` directory has been flattened.
|
||||
Namely, the files in `vtkm/io/reader` and `vtkm/io/writer` have been moved up into `vtkm/io`,
|
||||
with the associated changes in namespaces.
|
||||
|
||||
In addition, `vtkm/cont/EncodePNG.h` and `vtkm/cont/DecodePNG.h` have been moved to a more natural home in `vtkm/io`.
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/ClipWithField.h>
|
||||
|
||||
@ -26,7 +26,7 @@ int main(int argc, char* argv[])
|
||||
clipFilter.SetClipValue(20.0);
|
||||
vtkm::cont::DataSet output = clipFilter.Execute(input);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_data.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_data.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -11,8 +11,8 @@
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/worklet/CosmoTools.h>
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/worklet/CosmoTools.h>
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <vtkm/filter/CreateResult.h>
|
||||
#include <vtkm/filter/FilterField.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
@ -90,7 +90,7 @@ int main(int argc, char** argv)
|
||||
helloField.SetActiveField("point_vectors");
|
||||
vtkm::cont::DataSet outputData = helloField.Execute(inputData);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_data.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_data.vtk");
|
||||
writer.WriteDataSet(outputData);
|
||||
|
||||
return 0;
|
||||
|
@ -20,8 +20,8 @@
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/LagrangianStructures.h>
|
||||
|
||||
@ -38,7 +38,7 @@ int main(int argc, char** argv)
|
||||
|
||||
std::cout << "Reading input dataset" << std::endl;
|
||||
vtkm::cont::DataSet input;
|
||||
vtkm::io::reader::VTKDataSetReader reader(datasetName);
|
||||
vtkm::io::VTKDataSetReader reader(datasetName);
|
||||
input = reader.ReadDataSet();
|
||||
std::cout << "Read input dataset" << std::endl;
|
||||
|
||||
@ -50,7 +50,7 @@ int main(int argc, char** argv)
|
||||
lcsFilter.SetActiveField(variableName);
|
||||
|
||||
vtkm::cont::DataSet output = lcsFilter.Execute(input);
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
std::cout << "Written output dataset" << std::endl;
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/filter/MeshQuality.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -206,7 +206,7 @@ int TestMetrics(const char* outFileName,
|
||||
vtkm::cont::DataSet outputData;
|
||||
try
|
||||
{
|
||||
vtkm::io::writer::VTKDataSetWriter writer("testZoo_withPolygons.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("testZoo_withPolygons.vtk");
|
||||
writer.WriteDataSet(data);
|
||||
|
||||
outputData = filter.Execute(data);
|
||||
@ -220,7 +220,7 @@ int TestMetrics(const char* outFileName,
|
||||
}
|
||||
try
|
||||
{
|
||||
vtkm::io::writer::VTKDataSetWriter writer(outFileName);
|
||||
vtkm::io::VTKDataSetWriter writer(outFileName);
|
||||
writer.WriteDataSet(outputData);
|
||||
std::cout << "finished writing data\n";
|
||||
}
|
||||
@ -253,7 +253,7 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
}
|
||||
vtkm::cont::DataSet input;
|
||||
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
|
||||
vtkm::io::VTKDataSetReader reader(argv[1]);
|
||||
|
||||
|
||||
// A cell metric is now computed for every shape type that exists in the
|
||||
|
@ -11,8 +11,8 @@
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/filter/Streamline.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
// Example computing streamlines.
|
||||
// An example vector field is available in the vtk-m data directory: magField.vtk
|
||||
@ -46,7 +46,7 @@ int main(int argc, char** argv)
|
||||
|
||||
if (dataFile.find(".vtk") != std::string::npos)
|
||||
{
|
||||
vtkm::io::reader::VTKDataSetReader rdr(dataFile);
|
||||
vtkm::io::VTKDataSetReader rdr(dataFile);
|
||||
ds = rdr.ReadDataSet();
|
||||
}
|
||||
else
|
||||
@ -83,7 +83,7 @@ int main(int argc, char** argv)
|
||||
streamline.SetActiveField(varName);
|
||||
auto output = streamline.Execute(ds);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter wrt(outputFile);
|
||||
vtkm::io::VTKDataSetWriter wrt(outputFile);
|
||||
wrt.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <complex>
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
#include <vtkm/worklet/Tube.h>
|
||||
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include <vtkm/cont/EnvironmentTracker.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/thirdparty/diy/diy.h>
|
||||
|
||||
@ -44,7 +44,7 @@ int main(int argc, char* argv[])
|
||||
vtkm::cont::DataSet input;
|
||||
if (comm.rank() == 0)
|
||||
{
|
||||
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
|
||||
vtkm::io::VTKDataSetReader reader(argv[1]);
|
||||
input = reader.ReadDataSet();
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ int main(int argc, char* argv[])
|
||||
std::ostringstream str;
|
||||
str << argv[2] << "-" << comm.rank() << ".vtk";
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer(str.str());
|
||||
vtkm::io::VTKDataSetWriter writer(str.str());
|
||||
writer.WriteDataSet(output);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
#include <vtkm/filter/Pathline.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@ -31,20 +31,23 @@ int main(int argc, char** argv)
|
||||
// These example with these datasets can be used for this example as :
|
||||
// ./Temporal_Advection DoubleGyre_0.vtk 0.0 DoubleGyre_5.vtk 5.0
|
||||
// velocity 500 0.025 pathlines.vtk
|
||||
std::cout
|
||||
<< "Parameters : [options] slice1 time1 slice2 time2 field num_steps step_size output\n"
|
||||
<< "slice1 : Time slice 1, sample data in vtk-m/data/temporal_datasets/Double_Gyre0.vtk\n"
|
||||
<< "time1 : simulation time for slice 1, for sample data use 0.0\n"
|
||||
<< "slice2 : Time slice 2, sample data in vtk-m/data/temporal_datasets/Double_Gyre5.vtk\n"
|
||||
<< "time2 : simulation time for slice 2, for sample data use 5.0\n"
|
||||
<< "field : active velocity field in the data set, for sample data use 'velocity'\n"
|
||||
<< "num_steps : maximum number of steps for advection, for sample data use 500\n"
|
||||
<< "step_size : the size of a single step during advection, for sample data use 0.025\n"
|
||||
<< "output : the name of the output file" << std::endl;
|
||||
|
||||
if (argc < 8)
|
||||
{
|
||||
std::cout << "Wrong number of parameters provided" << std::endl;
|
||||
std::cout
|
||||
<< "Usage:\n"
|
||||
<< "./Temporal_Advection slice1 time1 slice2 time2 field num_steps step_size output\n"
|
||||
<< "\tslice1 : Time slice 1, sample data in vtk-m/data/data/rectilinear/Double_Gyre0.vtk\n"
|
||||
<< "\ttime1 : simulation time for slice 1, for sample data use 0.0\n"
|
||||
<< "\tslice2 : Time slice 2, sample data in vtk-m/data/data/rectilinear/Double_Gyre5.vtk\n"
|
||||
<< "\ttime2 : simulation time for slice 2, for sample data use 5.0\n"
|
||||
<< "\tfield : active velocity field in the data set, for sample data use 'velocity'\n"
|
||||
<< "\tnum_steps : maximum number of steps for advection, for sample data use 500\n"
|
||||
<< "\tstep_size : the size of a single step during advection, for sample data use 0.025\n"
|
||||
<< "\toutput : the name of the output file" << std::endl;
|
||||
std::cout << "Example:\n";
|
||||
std::cout << "./Temporal_Advection ~/vtk-m/data/data/rectilinear/DoubleGyre_0.vtk 0.0 "
|
||||
"~/vtk-m/data/data/rectilinear/DoubleGyre_5.vtk 5.0 velocity 500 0.025 "
|
||||
"pathlines.vtk\n";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -63,10 +66,10 @@ int main(int argc, char** argv)
|
||||
stepSize = static_cast<vtkm::Float32>(atof(argv[7]));
|
||||
outputName = std::string(argv[8]);
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader1(datasetName1);
|
||||
vtkm::io::VTKDataSetReader reader1(datasetName1);
|
||||
vtkm::cont::DataSet ds1 = reader1.ReadDataSet();
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader2(datasetName2);
|
||||
vtkm::io::VTKDataSetReader reader2(datasetName2);
|
||||
vtkm::cont::DataSet ds2 = reader2.ReadDataSet();
|
||||
|
||||
// Use the coordinate system as seeds for performing advection
|
||||
@ -77,7 +80,7 @@ int main(int argc, char** argv)
|
||||
vtkm::Id numPts = pts.GetNumberOfValues();
|
||||
seeds.Allocate(numPts);
|
||||
auto ptsPortal = pts.ReadPortal();
|
||||
auto seedPortal = seeds.ReadPortal();
|
||||
auto seedPortal = seeds.WritePortal();
|
||||
for (vtkm::Id i = 0; i < numPts; i++)
|
||||
{
|
||||
vtkm::Particle p;
|
||||
@ -109,7 +112,7 @@ int main(int argc, char** argv)
|
||||
// The way to verify if the code produces correct streamlines
|
||||
// is to do a visual test by using VisIt/ParaView to visualize
|
||||
// the file written by this method.
|
||||
vtkm::io::writer::VTKDataSetWriter writer(outputName);
|
||||
vtkm::io::VTKDataSetWriter writer(outputName);
|
||||
writer.WriteDataSet(output);
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/Tetrahedralize.h>
|
||||
|
||||
@ -25,7 +25,7 @@ int main(int argc, char* argv[])
|
||||
vtkm::filter::Tetrahedralize tetrahedralizeFilter;
|
||||
vtkm::cont::DataSet output = tetrahedralizeFilter.Execute(input);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_tets.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_tets.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/Triangulate.h>
|
||||
|
||||
@ -24,7 +24,7 @@ int main(int argc, char* argv[])
|
||||
vtkm::filter::Triangulate triangulateFilter;
|
||||
vtkm::cont::DataSet output = triangulateFilter.Execute(input);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_tris.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_tris.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -60,14 +60,12 @@
|
||||
// [[deprecated]] is supported, then VTK_M_DEPRECATED_ATTRIBUTE_SUPPORTED will get defined.
|
||||
#ifndef VTK_M_DEPRECATED_ATTRIBUTE_SUPPORTED
|
||||
|
||||
#if __cplusplus >= 201402L
|
||||
#if __cplusplus >= 201402L && !defined(__NVCC__)
|
||||
|
||||
// C++14 and better supports [[deprecated]]
|
||||
// Except in these cases:
|
||||
// - nvcc
|
||||
#if !(defined(VTKM_CUDA))
|
||||
#define VTK_M_DEPRECATED_ATTRIBUTE_SUPPORTED
|
||||
#endif
|
||||
|
||||
#elif defined(VTKM_GCC)
|
||||
|
||||
@ -78,14 +76,14 @@
|
||||
#define VTK_M_DEPRECATED_ATTRIBUTE_SUPPORTED
|
||||
#endif // Too old GCC
|
||||
|
||||
#elif defined(__has_cpp_attribute)
|
||||
#elif defined(__has_cpp_attribute) && !defined(__NVCC__)
|
||||
|
||||
#if __has_cpp_attribute(deprecated)
|
||||
// Compiler not fully C++14 compliant, but it reports to support [[deprecated]]
|
||||
#define VTK_M_DEPRECATED_ATTRIBUTE_SUPPORTED
|
||||
#endif // __has_cpp_attribute(deprecated)
|
||||
|
||||
#elif defined(VTKM_MSVC) && (_MSC_VER >= 1900) && !defined(VTKM_CUDA)
|
||||
#elif defined(VTKM_MSVC) && (_MSC_VER >= 1900) && !defined(__NVCC__)
|
||||
|
||||
#define VTK_M_DEPRECATED_ATTRIBUTE_SUPPORTED
|
||||
|
||||
|
@ -523,6 +523,8 @@ VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template <typename Functor, typename... Ts, typename... Args>
|
||||
VTKM_EXEC_CONT void ListForEachImpl(Functor&& f, vtkm::List<Ts...>, Args&&... args)
|
||||
{
|
||||
VTKM_STATIC_ASSERT_MSG((!std::is_same<vtkm::List<Ts...>, vtkm::ListUniversal>::value),
|
||||
"Cannot call ListFor on vtkm::ListUniversal.");
|
||||
auto init_list = { ListForEachCallThrough(
|
||||
std::forward<Functor>(f), Ts{}, std::forward<Args>(args)...)... };
|
||||
(void)init_list;
|
||||
|
@ -44,13 +44,17 @@ void DataSet::CopyStructure(const vtkm::cont::DataSet& source)
|
||||
const vtkm::cont::Field& DataSet::GetField(vtkm::Id index) const
|
||||
{
|
||||
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfFields()));
|
||||
return this->Fields[static_cast<std::size_t>(index)];
|
||||
auto it = this->Fields.cbegin();
|
||||
std::advance(it, index);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
vtkm::cont::Field& DataSet::GetField(vtkm::Id index)
|
||||
{
|
||||
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfFields()));
|
||||
return this->Fields[static_cast<std::size_t>(index)];
|
||||
auto it = this->Fields.begin();
|
||||
std::advance(it, index);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
vtkm::Id DataSet::GetFieldIndex(const std::string& name, vtkm::cont::Field::Association assoc) const
|
||||
@ -150,19 +154,22 @@ vtkm::Id DataSet::FindFieldIndex(const std::string& name,
|
||||
vtkm::cont::Field::Association association,
|
||||
bool& found) const
|
||||
{
|
||||
for (std::size_t index = 0; index < this->Fields.size(); ++index)
|
||||
const auto it = this->Fields.find({ name, association });
|
||||
if (it != this->Fields.end())
|
||||
{
|
||||
if ((association == vtkm::cont::Field::Association::ANY ||
|
||||
association == this->Fields[index].GetAssociation()) &&
|
||||
this->Fields[index].GetName() == name)
|
||||
{
|
||||
found = true;
|
||||
return static_cast<vtkm::Id>(index);
|
||||
}
|
||||
found = true;
|
||||
return static_cast<vtkm::Id>(std::distance(this->Fields.begin(), it));
|
||||
}
|
||||
|
||||
found = false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
VTKM_CONT void DataSet::AddField(const Field& field)
|
||||
{
|
||||
// map::insert will not replace the duplicated element
|
||||
this->Fields[{ field.GetName(), field.GetAssociation() }] = field;
|
||||
}
|
||||
|
||||
} // namespace cont
|
||||
} // namespace vtkm
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
/// to have the same number of points.
|
||||
VTKM_CONT vtkm::Id GetNumberOfPoints() const;
|
||||
|
||||
VTKM_CONT void AddField(const Field& field) { this->Fields.push_back(field); }
|
||||
VTKM_CONT void AddField(const Field& field);
|
||||
|
||||
VTKM_CONT
|
||||
const vtkm::cont::Field& GetField(vtkm::Id index) const;
|
||||
@ -73,14 +73,14 @@ public:
|
||||
}
|
||||
|
||||
|
||||
/// Returns the first field that matches the provided name and association
|
||||
/// Returns the field that matches the provided name and association
|
||||
/// Will return -1 if no match is found
|
||||
VTKM_CONT
|
||||
vtkm::Id GetFieldIndex(
|
||||
const std::string& name,
|
||||
vtkm::cont::Field::Association assoc = vtkm::cont::Field::Association::ANY) const;
|
||||
|
||||
/// Returns the first field that matches the provided name and association
|
||||
/// Returns the field that matches the provided name and association
|
||||
/// Will throw an exception if no match is found
|
||||
//@{
|
||||
VTKM_CONT
|
||||
@ -203,8 +203,23 @@ public:
|
||||
void PrintSummary(std::ostream& out) const;
|
||||
|
||||
private:
|
||||
struct FieldCompare
|
||||
{
|
||||
using Key = std::pair<std::string, vtkm::cont::Field::Association>;
|
||||
|
||||
template <typename T>
|
||||
bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
if (a.first == b.first)
|
||||
return a.second < b.second && a.second != vtkm::cont::Field::Association::ANY &&
|
||||
b.second != vtkm::cont::Field::Association::ANY;
|
||||
|
||||
return a.first < b.first;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<vtkm::cont::CoordinateSystem> CoordSystems;
|
||||
std::vector<vtkm::cont::Field> Fields;
|
||||
std::map<FieldCompare::Key, vtkm::cont::Field, FieldCompare> Fields;
|
||||
vtkm::cont::DynamicCellSet CellSet;
|
||||
|
||||
VTKM_CONT
|
||||
|
@ -101,6 +101,8 @@ public:
|
||||
template <typename TypeList>
|
||||
VTKM_CONT const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(TypeList) const
|
||||
{
|
||||
VTKM_STATIC_ASSERT_MSG((!std::is_same<TypeList, vtkm::ListUniversal>::value),
|
||||
"Cannot get the field range with vtkm::ListUniversal.");
|
||||
return this->GetRangeImpl(TypeList());
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,8 @@ VTKM_CONT vtkm::cont::ArrayHandle<vtkm::Range> FieldRangeCompute(
|
||||
TypeList)
|
||||
{
|
||||
VTKM_IS_LIST(TypeList);
|
||||
VTKM_STATIC_ASSERT_MSG((!std::is_same<TypeList, vtkm::ListUniversal>::value),
|
||||
"Cannot use vtkm::ListUniversal with FieldRangeCompute.");
|
||||
return vtkm::cont::detail::FieldRangeComputeImpl(pds, name, assoc, TypeList());
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,9 @@ namespace cont
|
||||
template <typename TypeList>
|
||||
class VTKM_ALWAYS_EXPORT VariantArrayHandleBase
|
||||
{
|
||||
VTKM_STATIC_ASSERT_MSG((!std::is_same<TypeList, vtkm::ListUniversal>::value),
|
||||
"Cannot use vtkm::ListUniversal with VariantArrayHandle.");
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
VariantArrayHandleBase() = default;
|
||||
|
@ -172,15 +172,6 @@ public:
|
||||
VTKM_EXEC_CONT
|
||||
ValueType Get(vtkm::Id index) const { return *this->IteratorAt(index); }
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT
|
||||
void Set(vtkm::Id vtkmNotUsed(index), const ValueType& vtkmNotUsed(value)) const
|
||||
{
|
||||
#if !(defined(VTKM_MSVC) && defined(VTKM_CUDA))
|
||||
VTKM_ASSERT(false && "Attempted to write to constant array.");
|
||||
#endif
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT
|
||||
IteratorT GetIteratorBegin() const { return this->BeginIterator; }
|
||||
|
@ -73,6 +73,19 @@ struct TemplatedTests
|
||||
::vtkm::cont::internal::ArrayPortalFromIterators<const ValueType*> const_portal(
|
||||
array, array + ARRAY_SIZE);
|
||||
|
||||
using PortalType = decltype(portal);
|
||||
using PortalConstType = decltype(const_portal);
|
||||
|
||||
std::cout << "Check that PortalSupports* results are valid:" << std::endl;
|
||||
VTKM_TEST_ASSERT(vtkm::internal::PortalSupportsSets<PortalType>::value,
|
||||
"Writable portals should support Set operations");
|
||||
VTKM_TEST_ASSERT(vtkm::internal::PortalSupportsGets<PortalType>::value,
|
||||
"Writable portals should support Get operations");
|
||||
VTKM_TEST_ASSERT(!vtkm::internal::PortalSupportsSets<PortalConstType>::value,
|
||||
"Read-only portals should not allow Set operations");
|
||||
VTKM_TEST_ASSERT(vtkm::internal::PortalSupportsGets<PortalConstType>::value,
|
||||
"Read-only portals should support Get operations");
|
||||
|
||||
std::cout << " Check that ArrayPortalToIterators is not doing indirection." << std::endl;
|
||||
// If you get a compile error here about mismatched types, it might be
|
||||
// that ArrayPortalToIterators is not properly overloaded to return the
|
||||
|
@ -40,6 +40,26 @@ void is_noexcept_movable()
|
||||
VTKM_TEST_ASSERT(valid, msg);
|
||||
}
|
||||
|
||||
// DataSet uses a map which is not nothrow constructible/assignable in the
|
||||
// following implementations
|
||||
template<>
|
||||
void is_noexcept_movable<vtkm::cont::DataSet>()
|
||||
{
|
||||
using T = vtkm::cont::DataSet;
|
||||
|
||||
constexpr bool valid =
|
||||
#if ((defined(__GNUC__) && (__GNUC__ <= 5)) || defined(_WIN32))
|
||||
std::is_move_constructible<T>::value &&
|
||||
std::is_move_assignable<T>::value;
|
||||
#else
|
||||
std::is_nothrow_move_constructible<T>::value &&
|
||||
std::is_nothrow_move_assignable<T>::value;
|
||||
#endif
|
||||
|
||||
std::string msg = typeid(T).name() + std::string(" should be noexcept moveable");
|
||||
VTKM_TEST_ASSERT(valid, msg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void is_triv_noexcept_movable()
|
||||
{
|
||||
|
@ -503,7 +503,8 @@ void MergeBlockFunctor(
|
||||
currNumIterations,
|
||||
block->ComputeRegularStructure,
|
||||
meshBoundaryExecObj);
|
||||
vtkm::worklet::contourtree_augmented::ContourTreeMesh<FieldType>* newContourTreeMesh = 0;
|
||||
vtkm::worklet::contourtree_augmented::ContourTreeMesh<FieldType>* newContourTreeMesh =
|
||||
nullptr;
|
||||
if (block->ComputeRegularStructure == 1)
|
||||
{
|
||||
// If we have the fully augmented contour tree
|
||||
@ -759,7 +760,7 @@ VTKM_CONT void ContourTreeAugmented::DoPostExecute(
|
||||
currBlock.GetField(this->GetActiveFieldName(), this->GetActiveFieldAssociation());
|
||||
//const vtkm::cont::ArrayHandle<T,StorageType> &fieldData = currField.GetData().Cast<vtkm::cont::ArrayHandle<T,StorageType> >();
|
||||
vtkm::cont::ArrayHandle<T> fieldData;
|
||||
vtkm::cont::ArrayCopy(currField.GetData().AsVirtual<T>(), fieldData);
|
||||
vtkm::cont::ArrayCopy(currField.GetData().template AsVirtual<T>(), fieldData);
|
||||
auto currContourTreeMesh =
|
||||
vtkm::filter::detail::MultiBlockContourTreeHelper::ComputeLocalContourTreeMesh<T>(
|
||||
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.LocalBlockOrigins.ReadPortal()
|
||||
|
@ -184,7 +184,7 @@ public:
|
||||
/// A filter is able to state what subset of types it supports
|
||||
/// by default. By default we use ListUniversal to represent that the
|
||||
/// filter accepts all types specified by the users provided policy
|
||||
using SupportedTypes = vtkm::ListUniversal;
|
||||
using SupportedTypes = VTKM_DEFAULT_TYPE_LIST;
|
||||
|
||||
/// \brief Specify which additional field storage to support.
|
||||
///
|
||||
|
@ -212,7 +212,12 @@ template <typename DerivedPolicy>
|
||||
inline VTKM_CONT void Histogram::PreExecute(const vtkm::cont::PartitionedDataSet& input,
|
||||
const vtkm::filter::PolicyBase<DerivedPolicy>&)
|
||||
{
|
||||
using TypeList = typename DerivedPolicy::FieldTypeList;
|
||||
// Policies are on their way out, but until they are we want to respect them. In the mean
|
||||
// time, respect the policy if it is defined.
|
||||
using TypeList = typename std::conditional<
|
||||
std::is_same<typename DerivedPolicy::FieldTypeList, vtkm::ListUniversal>::value,
|
||||
VTKM_DEFAULT_TYPE_LIST,
|
||||
typename DerivedPolicy::FieldTypeList>::type;
|
||||
if (this->Range.IsNonEmpty())
|
||||
{
|
||||
this->ComputedRange = this->Range;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/ErrorFilterExecution.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/worklet/ParticleAdvection.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
#include <vtkm/worklet/particleadvection/GridEvaluators.h>
|
||||
|
@ -32,7 +32,7 @@ namespace filter
|
||||
template <typename Derived>
|
||||
struct PolicyBase
|
||||
{
|
||||
using FieldTypeList = VTKM_DEFAULT_TYPE_LIST;
|
||||
using FieldTypeList = vtkm::ListUniversal;
|
||||
using StorageList = VTKM_DEFAULT_STORAGE_LIST;
|
||||
|
||||
using StructuredCellSetList = VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED;
|
||||
@ -201,10 +201,18 @@ using ArrayHandleMultiplexerForStorageList = vtkm::cont::ArrayHandleMultiplexerF
|
||||
/// passed to the `DoMapField` method of filters.
|
||||
///
|
||||
template <typename DerivedPolicy>
|
||||
VTKM_CONT vtkm::cont::VariantArrayHandleBase<typename DerivedPolicy::FieldTypeList>
|
||||
VTKM_CONT vtkm::cont::VariantArrayHandleBase<typename std::conditional<
|
||||
std::is_same<typename DerivedPolicy::FieldTypeList, vtkm::ListUniversal>::value,
|
||||
VTKM_DEFAULT_TYPE_LIST,
|
||||
typename DerivedPolicy::FieldTypeList>::type>
|
||||
ApplyPolicyFieldNotActive(const vtkm::cont::Field& field, vtkm::filter::PolicyBase<DerivedPolicy>)
|
||||
{
|
||||
using TypeList = typename DerivedPolicy::FieldTypeList;
|
||||
// Policies are on their way out, but until they are we want to respect them. In the mean
|
||||
// time, respect the policy if it is defined.
|
||||
using TypeList = typename std::conditional<
|
||||
std::is_same<typename DerivedPolicy::FieldTypeList, vtkm::ListUniversal>::value,
|
||||
VTKM_DEFAULT_TYPE_LIST,
|
||||
typename DerivedPolicy::FieldTypeList>::type;
|
||||
return field.GetData().ResetTypes(TypeList());
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,6 @@
|
||||
|
||||
#include <vtkm/filter/GhostCellRemove.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
@ -27,8 +27,7 @@
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/filter/MeshQuality.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
//Adapted from vtkm/cont/testing/MakeTestDataSet.h
|
||||
//Modified the content of the MakeExplicitDataSetZoo() function
|
||||
|
248
vtkm/io/BOVDataSetReader.h
Normal file
248
vtkm/io/BOVDataSetReader.h
Normal file
@ -0,0 +1,248 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_BOVDataSetReader_h
|
||||
#define vtk_m_io_BOVDataSetReader_h
|
||||
|
||||
#include <fstream>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderUniform.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/io/ErrorIO.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
class BOVDataSetReader
|
||||
{
|
||||
public:
|
||||
BOVDataSetReader(const char* fileName)
|
||||
: FileName(fileName)
|
||||
, Loaded(false)
|
||||
, DataSet()
|
||||
{
|
||||
}
|
||||
BOVDataSetReader(const std::string& fileName)
|
||||
: FileName(fileName)
|
||||
, Loaded(false)
|
||||
, DataSet()
|
||||
{
|
||||
}
|
||||
|
||||
const vtkm::cont::DataSet& ReadDataSet()
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadFile();
|
||||
}
|
||||
catch (std::ifstream::failure& e)
|
||||
{
|
||||
std::string message("IO Error: ");
|
||||
throw vtkm::io::ErrorIO(message + e.what());
|
||||
}
|
||||
return this->DataSet;
|
||||
}
|
||||
|
||||
private:
|
||||
using DataFormat = enum { ByteData, ShortData, IntegerData, FloatData, DoubleData };
|
||||
|
||||
void LoadFile()
|
||||
{
|
||||
if (this->Loaded)
|
||||
return;
|
||||
|
||||
std::ifstream stream(this->FileName);
|
||||
if (stream.fail())
|
||||
throw vtkm::io::ErrorIO("Failed to open file: " + this->FileName);
|
||||
|
||||
DataFormat dataFormat = ByteData;
|
||||
std::string bovFile, line, token, options, variableName;
|
||||
vtkm::Id numComponents = 1;
|
||||
vtkm::Id3 dim;
|
||||
vtkm::Vec3f origin(0, 0, 0);
|
||||
vtkm::Vec3f spacing(1, 1, 1);
|
||||
bool spacingSet = false;
|
||||
|
||||
while (stream.good())
|
||||
{
|
||||
std::getline(stream, line);
|
||||
if (line.size() == 0 || line[0] == '#')
|
||||
continue;
|
||||
//std::cout<<"::"<<line<<"::"<<std::endl;
|
||||
std::size_t pos = line.find(":");
|
||||
if (pos == std::string::npos)
|
||||
throw vtkm::io::ErrorIO("Unsupported option: " + line);
|
||||
token = line.substr(0, pos);
|
||||
options = line.substr(pos + 1, line.size() - 1);
|
||||
//std::cout<<token<<"::"<<options<<std::endl;
|
||||
|
||||
std::stringstream strStream(options);
|
||||
|
||||
//Format supports both space and "_" separated tokens...
|
||||
if (token.find("DATA") != std::string::npos && token.find("FILE") != std::string::npos)
|
||||
{
|
||||
strStream >> bovFile >> std::ws;
|
||||
}
|
||||
else if (token.find("DATA") != std::string::npos && token.find("SIZE") != std::string::npos)
|
||||
{
|
||||
strStream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
|
||||
}
|
||||
else if (token.find("BRICK") != std::string::npos &&
|
||||
token.find("ORIGIN") != std::string::npos)
|
||||
{
|
||||
strStream >> origin[0] >> origin[1] >> origin[2] >> std::ws;
|
||||
}
|
||||
|
||||
//DRP
|
||||
else if (token.find("BRICK") != std::string::npos && token.find("SIZE") != std::string::npos)
|
||||
{
|
||||
strStream >> spacing[0] >> spacing[1] >> spacing[2] >> std::ws;
|
||||
spacingSet = true;
|
||||
}
|
||||
else if (token.find("DATA") != std::string::npos && token.find("FORMAT") != std::string::npos)
|
||||
{
|
||||
std::string opt;
|
||||
strStream >> opt >> std::ws;
|
||||
if (opt.find("FLOAT") != std::string::npos || opt.find("REAL") != std::string::npos)
|
||||
dataFormat = FloatData;
|
||||
else if (opt.find("DOUBLE") != std::string::npos)
|
||||
dataFormat = DoubleData;
|
||||
else
|
||||
throw vtkm::io::ErrorIO("Unsupported data type: " + token);
|
||||
}
|
||||
else if (token.find("DATA") != std::string::npos &&
|
||||
token.find("COMPONENTS") != std::string::npos)
|
||||
{
|
||||
strStream >> numComponents >> std::ws;
|
||||
if (numComponents != 1 && numComponents != 3)
|
||||
throw vtkm::io::ErrorIO("Unsupported number of components");
|
||||
}
|
||||
else if (token.find("VARIABLE") != std::string::npos &&
|
||||
token.find("PALETTE") == std::string::npos)
|
||||
{
|
||||
strStream >> variableName >> std::ws;
|
||||
if (variableName[0] == '"')
|
||||
variableName = variableName.substr(1, variableName.size() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (spacingSet)
|
||||
{
|
||||
spacing[0] = (spacing[0]) / static_cast<vtkm::FloatDefault>(dim[0] - 1);
|
||||
spacing[1] = (spacing[1]) / static_cast<vtkm::FloatDefault>(dim[1] - 1);
|
||||
spacing[2] = (spacing[2]) / static_cast<vtkm::FloatDefault>(dim[2] - 1);
|
||||
}
|
||||
|
||||
std::string fullPathDataFile;
|
||||
std::size_t pos = FileName.rfind("/");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string baseDir;
|
||||
baseDir = this->FileName.substr(0, pos);
|
||||
fullPathDataFile = baseDir + "/" + bovFile;
|
||||
}
|
||||
else
|
||||
fullPathDataFile = bovFile;
|
||||
|
||||
|
||||
vtkm::cont::DataSetBuilderUniform dataSetBuilder;
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
this->DataSet = dataSetBuilder.Create(dim, origin, spacing);
|
||||
|
||||
vtkm::Id numTuples = dim[0] * dim[1] * dim[2];
|
||||
if (numComponents == 1)
|
||||
{
|
||||
if (dataFormat == FloatData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float64> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
else if (numComponents == 3)
|
||||
{
|
||||
if (dataFormat == FloatData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
|
||||
this->Loaded = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadBuffer(const std::string& fName, const vtkm::Id& sz, std::vector<T>& buff)
|
||||
{
|
||||
FILE* fp = fopen(fName.c_str(), "rb");
|
||||
size_t readSize = static_cast<size_t>(sz);
|
||||
if (fp == nullptr)
|
||||
throw vtkm::io::ErrorIO("Unable to open data file: " + fName);
|
||||
buff.resize(readSize);
|
||||
size_t nread = fread(&buff[0], sizeof(T), readSize, fp);
|
||||
if (nread != readSize)
|
||||
throw vtkm::io::ErrorIO("Data file read failed: " + fName);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadScalar(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<T>& var)
|
||||
{
|
||||
std::vector<T> buff;
|
||||
ReadBuffer(fName, nTuples, buff);
|
||||
var.Allocate(nTuples);
|
||||
for (vtkm::Id i = 0; i < nTuples; i++)
|
||||
var.WritePortal().Set(i, buff[(size_t)i]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadVector(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& var)
|
||||
{
|
||||
std::vector<T> buff;
|
||||
ReadBuffer(fName, nTuples * 3, buff);
|
||||
|
||||
var.Allocate(nTuples);
|
||||
vtkm::Vec<T, 3> v;
|
||||
for (vtkm::Id i = 0; i < nTuples; i++)
|
||||
{
|
||||
v[0] = buff[static_cast<size_t>(i * 3 + 0)];
|
||||
v[1] = buff[static_cast<size_t>(i * 3 + 1)];
|
||||
v[2] = buff[static_cast<size_t>(i * 3 + 2)];
|
||||
var.WritePortal().Set(i, v);
|
||||
}
|
||||
}
|
||||
|
||||
std::string FileName;
|
||||
bool Loaded;
|
||||
vtkm::cont::DataSet DataSet;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // vtkm::io
|
||||
|
||||
#endif // vtk_m_io_BOVReader_h
|
@ -9,11 +9,35 @@
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
BOVDataSetReader.h
|
||||
ErrorIO.h
|
||||
DecodePNG.h
|
||||
EncodePNG.h
|
||||
VTKDataSetReader.h
|
||||
VTKDataSetReaderBase.h
|
||||
VTKPolyDataReader.h
|
||||
VTKRectilinearGridReader.h
|
||||
VTKStructuredGridReader.h
|
||||
VTKStructuredPointsReader.h
|
||||
VTKUnstructuredGridReader.h
|
||||
VTKDataSetWriter.h
|
||||
)
|
||||
|
||||
set(sources
|
||||
DecodePNG.cxx
|
||||
EncodePNG.cxx
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
vtkm_library( NAME vtkm_io
|
||||
SOURCES ${sources}
|
||||
HEADERS ${headers}
|
||||
)
|
||||
|
||||
target_link_libraries(vtkm_io PUBLIC vtkm_cont PRIVATE vtkm_lodepng)
|
||||
|
||||
add_subdirectory(internal)
|
||||
add_subdirectory(reader)
|
||||
add_subdirectory(writer)
|
||||
add_subdirectory(testing)
|
||||
|
@ -8,18 +8,19 @@
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/DecodePNG.h>
|
||||
#include <vtkm/io/DecodePNG.h>
|
||||
|
||||
#include <vtkm/cont/Logging.h>
|
||||
#include <vtkm/internal/Configure.h>
|
||||
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <vtkm/thirdparty/lodepng/vtkmlodepng/lodepng.h>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
namespace io
|
||||
{
|
||||
|
||||
vtkm::UInt32 DecodePNG(std::vector<unsigned char>& out_image,
|
||||
@ -39,4 +40,4 @@ vtkm::UInt32 DecodePNG(std::vector<unsigned char>& out_image,
|
||||
return retcode;
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
} // namespace vtkm::io
|
37
vtkm/io/DecodePNG.h
Normal file
37
vtkm/io/DecodePNG.h
Normal file
@ -0,0 +1,37 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_DecodePNG_h
|
||||
#define vtk_m_io_DecodePNG_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/io/vtkm_io_export.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
/// Decodes a PNG file buffer in memory, into a raw pixel buffer
|
||||
/// Output is RGBA 32-bit (8 bit per channel) color format
|
||||
/// no matter what color type the original PNG image had. This gives predictable,
|
||||
/// usable data from any random input PNG.
|
||||
///
|
||||
VTKM_IO_EXPORT
|
||||
vtkm::UInt32 DecodePNG(std::vector<unsigned char>& out_image,
|
||||
unsigned long& image_width,
|
||||
unsigned long& image_height,
|
||||
const unsigned char* in_png,
|
||||
std::size_t in_size);
|
||||
}
|
||||
} // vtkm::io
|
||||
|
||||
#endif //vtk_m_io_DecodePNG_h
|
@ -8,7 +8,7 @@
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <algorithm> // for std::equal
|
||||
#include <vtkm/rendering/EncodePNG.h>
|
||||
#include <vtkm/io/EncodePNG.h>
|
||||
|
||||
#include <vtkm/cont/Logging.h>
|
||||
#include <vtkm/internal/Configure.h>
|
||||
@ -19,7 +19,7 @@ VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
namespace io
|
||||
{
|
||||
|
||||
vtkm::UInt32 EncodePNG(std::vector<unsigned char> const& image,
|
||||
@ -68,4 +68,4 @@ vtkm::UInt32 SavePNG(std::string const& filename,
|
||||
return error;
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
} // namespace vtkm::io
|
38
vtkm/io/EncodePNG.h
Normal file
38
vtkm/io/EncodePNG.h
Normal file
@ -0,0 +1,38 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_EncodePNG_h
|
||||
#define vtk_m_io_EncodePNG_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/io/vtkm_io_export.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
VTKM_IO_EXPORT
|
||||
vtkm::UInt32 EncodePNG(std::vector<unsigned char> const& image,
|
||||
unsigned long width,
|
||||
unsigned long height,
|
||||
unsigned char* out_png,
|
||||
std::size_t out_size);
|
||||
|
||||
VTKM_IO_EXPORT
|
||||
vtkm::UInt32 SavePNG(std::string const& filename,
|
||||
std::vector<unsigned char> const& image,
|
||||
unsigned long width,
|
||||
unsigned long height);
|
||||
}
|
||||
} // vtkm::io
|
||||
|
||||
#endif //vtk_m_io_EncodePNG_h
|
100
vtkm/io/VTKDataSetReader.h
Normal file
100
vtkm/io/VTKDataSetReader.h
Normal file
@ -0,0 +1,100 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_VTKDataSetReader_h
|
||||
#define vtk_m_io_VTKDataSetReader_h
|
||||
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKPolyDataReader.h>
|
||||
#include <vtkm/io/VTKRectilinearGridReader.h>
|
||||
#include <vtkm/io/VTKStructuredGridReader.h>
|
||||
#include <vtkm/io/VTKStructuredPointsReader.h>
|
||||
#include <vtkm/io/VTKUnstructuredGridReader.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
|
||||
|
||||
class VTKDataSetReader : public VTKDataSetReaderBase
|
||||
{
|
||||
public:
|
||||
explicit VTKDataSetReader(const char* fileName)
|
||||
: VTKDataSetReaderBase(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
explicit VTKDataSetReader(const std::string& fileName)
|
||||
: VTKDataSetReaderBase(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void PrintSummary(std::ostream& out) const
|
||||
{
|
||||
if (this->Reader)
|
||||
{
|
||||
this->Reader->PrintSummary(out);
|
||||
}
|
||||
else
|
||||
{
|
||||
VTKDataSetReaderBase::PrintSummary(out);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void CloseFile()
|
||||
{
|
||||
if (this->Reader)
|
||||
{
|
||||
this->Reader->CloseFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
VTKDataSetReaderBase::CloseFile();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Read()
|
||||
{
|
||||
switch (this->DataFile->Structure)
|
||||
{
|
||||
case vtkm::io::internal::DATASET_STRUCTURED_POINTS:
|
||||
this->Reader.reset(new VTKStructuredPointsReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_STRUCTURED_GRID:
|
||||
this->Reader.reset(new VTKStructuredGridReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_RECTILINEAR_GRID:
|
||||
this->Reader.reset(new VTKRectilinearGridReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_POLYDATA:
|
||||
this->Reader.reset(new VTKPolyDataReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_UNSTRUCTURED_GRID:
|
||||
this->Reader.reset(new VTKUnstructuredGridReader(""));
|
||||
break;
|
||||
default:
|
||||
throw vtkm::io::ErrorIO("Unsupported DataSet type.");
|
||||
}
|
||||
|
||||
this->TransferDataFile(*this->Reader.get());
|
||||
this->Reader->Read();
|
||||
this->DataSet = this->Reader->GetDataSet();
|
||||
}
|
||||
|
||||
std::unique_ptr<VTKDataSetReaderBase> Reader;
|
||||
};
|
||||
}
|
||||
} // vtkm::io
|
||||
|
||||
#endif // vtk_m_io_VTKReader_h
|
@ -7,8 +7,8 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_reader_VTKDataSetReaderBase_h
|
||||
#define vtk_m_io_reader_VTKDataSetReaderBase_h
|
||||
#ifndef vtk_m_io_VTKDataSetReaderBase_h
|
||||
#define vtk_m_io_VTKDataSetReaderBase_h
|
||||
|
||||
#include <vtkm/io/internal/Endian.h>
|
||||
#include <vtkm/io/internal/VTKDataSetCells.h>
|
||||
@ -34,8 +34,6 @@ namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
namespace reader
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
@ -1004,10 +1002,9 @@ private:
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // vtkm::io::reader
|
||||
} // vtkm::io
|
||||
|
||||
VTKM_BASIC_TYPE_VECTOR(vtkm::io::internal::ColorChannel8)
|
||||
VTKM_BASIC_TYPE_VECTOR(vtkm::io::internal::DummyBitType)
|
||||
|
||||
#endif // vtk_m_io_reader_VTKDataSetReaderBase_h
|
||||
#endif // vtk_m_io_VTKDataSetReaderBase_h
|
415
vtkm/io/VTKDataSetWriter.h
Normal file
415
vtkm/io/VTKDataSetWriter.h
Normal file
@ -0,0 +1,415 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_DataSetWriter_h
|
||||
#define vtk_m_io_DataSetWriter_h
|
||||
|
||||
#include <cctype>
|
||||
#include <vtkm/CellShape.h>
|
||||
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/CellSetStructured.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/ErrorBadType.h>
|
||||
#include <vtkm/cont/ErrorBadValue.h>
|
||||
#include <vtkm/cont/Field.h>
|
||||
|
||||
#include <vtkm/io/ErrorIO.h>
|
||||
|
||||
#include <vtkm/io/internal/VTKDataSetTypes.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct OutputPointsFunctor
|
||||
{
|
||||
private:
|
||||
std::ostream& out;
|
||||
|
||||
template <typename PortalType>
|
||||
VTKM_CONT void Output(const PortalType& portal) const
|
||||
{
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
||||
{
|
||||
const int VTKDims = 3; // VTK files always require 3 dims for points
|
||||
|
||||
using ValueType = typename PortalType::ValueType;
|
||||
using VecType = typename vtkm::VecTraits<ValueType>;
|
||||
|
||||
const ValueType& value = portal.Get(index);
|
||||
|
||||
vtkm::IdComponent numComponents = VecType::GetNumberOfComponents(value);
|
||||
for (vtkm::IdComponent c = 0; c < numComponents && c < VTKDims; c++)
|
||||
{
|
||||
out << (c == 0 ? "" : " ") << VecType::GetComponent(value, c);
|
||||
}
|
||||
for (vtkm::IdComponent c = numComponents; c < VTKDims; c++)
|
||||
{
|
||||
out << " 0";
|
||||
}
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
OutputPointsFunctor(std::ostream& o)
|
||||
: out(o)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T, typename Storage>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, Storage>& array) const
|
||||
{
|
||||
this->Output(array.ReadPortal());
|
||||
}
|
||||
};
|
||||
|
||||
struct OutputFieldFunctor
|
||||
{
|
||||
private:
|
||||
std::ostream& out;
|
||||
|
||||
template <typename PortalType>
|
||||
VTKM_CONT void Output(const PortalType& portal) const
|
||||
{
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
||||
{
|
||||
using ValueType = typename PortalType::ValueType;
|
||||
using VecType = typename vtkm::VecTraits<ValueType>;
|
||||
|
||||
const ValueType& value = portal.Get(index);
|
||||
|
||||
vtkm::IdComponent numComponents = VecType::GetNumberOfComponents(value);
|
||||
for (vtkm::IdComponent c = 0; c < numComponents; c++)
|
||||
{
|
||||
out << (c == 0 ? "" : " ") << VecType::GetComponent(value, c);
|
||||
}
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
OutputFieldFunctor(std::ostream& o)
|
||||
: out(o)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T, typename Storage>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, Storage>& array) const
|
||||
{
|
||||
this->Output(array.ReadPortal());
|
||||
}
|
||||
};
|
||||
|
||||
class GetDataTypeName
|
||||
{
|
||||
public:
|
||||
GetDataTypeName(std::string& name)
|
||||
: Name(&name)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ArrayHandleType>
|
||||
void operator()(const ArrayHandleType&) const
|
||||
{
|
||||
using DataType = typename vtkm::VecTraits<typename ArrayHandleType::ValueType>::ComponentType;
|
||||
*this->Name = vtkm::io::internal::DataTypeName<DataType>::Name();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string* Name;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
struct VTKDataSetWriter
|
||||
{
|
||||
private:
|
||||
static void WritePoints(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
///\todo: support other coordinate systems
|
||||
int cindex = 0;
|
||||
auto cdata = dataSet.GetCoordinateSystem(cindex).GetData();
|
||||
|
||||
vtkm::Id npoints = cdata.GetNumberOfValues();
|
||||
out << "POINTS " << npoints << " "
|
||||
<< vtkm::io::internal::DataTypeName<vtkm::FloatDefault>::Name() << " " << '\n';
|
||||
|
||||
detail::OutputPointsFunctor{ out }(cdata);
|
||||
}
|
||||
|
||||
template <class CellSetType>
|
||||
static void WriteExplicitCells(std::ostream& out, const CellSetType& cellSet)
|
||||
{
|
||||
vtkm::Id nCells = cellSet.GetNumberOfCells();
|
||||
|
||||
vtkm::Id conn_length = 0;
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
conn_length += 1 + cellSet.GetNumberOfPointsInCell(i);
|
||||
}
|
||||
|
||||
out << "CELLS " << nCells << " " << conn_length << '\n';
|
||||
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> ids;
|
||||
vtkm::Id nids = cellSet.GetNumberOfPointsInCell(i);
|
||||
cellSet.GetIndices(i, ids);
|
||||
out << nids;
|
||||
auto IdPortal = ids.ReadPortal();
|
||||
for (int j = 0; j < nids; ++j)
|
||||
out << " " << IdPortal.Get(j);
|
||||
out << '\n';
|
||||
}
|
||||
|
||||
out << "CELL_TYPES " << nCells << '\n';
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
vtkm::Id shape = cellSet.GetCellShape(i);
|
||||
out << shape << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteVertexCells(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
vtkm::Id nCells = dataSet.GetCoordinateSystem(0).GetNumberOfPoints();
|
||||
|
||||
out << "CELLS " << nCells << " " << nCells * 2 << '\n';
|
||||
for (int i = 0; i < nCells; i++)
|
||||
{
|
||||
out << "1 " << i << '\n';
|
||||
}
|
||||
out << "CELL_TYPES " << nCells << '\n';
|
||||
for (int i = 0; i < nCells; i++)
|
||||
{
|
||||
out << vtkm::CELL_SHAPE_VERTEX << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
static void WritePointFields(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
bool wrote_header = false;
|
||||
for (vtkm::Id f = 0; f < dataSet.GetNumberOfFields(); f++)
|
||||
{
|
||||
const vtkm::cont::Field field = dataSet.GetField(f);
|
||||
|
||||
if (field.GetAssociation() != vtkm::cont::Field::Association::POINTS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vtkm::Id npoints = field.GetNumberOfValues();
|
||||
int ncomps = field.GetData().GetNumberOfComponents();
|
||||
if (ncomps > 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!wrote_header)
|
||||
{
|
||||
out << "POINT_DATA " << npoints << '\n';
|
||||
wrote_header = true;
|
||||
}
|
||||
|
||||
std::string typeName;
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::GetDataTypeName(typeName));
|
||||
std::string name = field.GetName();
|
||||
for (auto& c : name)
|
||||
{
|
||||
if (std::isspace(c))
|
||||
{
|
||||
c = '_';
|
||||
}
|
||||
}
|
||||
out << "SCALARS " << name << " " << typeName << " " << ncomps << '\n';
|
||||
out << "LOOKUP_TABLE default" << '\n';
|
||||
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::OutputFieldFunctor(out));
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteCellFields(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
bool wrote_header = false;
|
||||
for (vtkm::Id f = 0; f < dataSet.GetNumberOfFields(); f++)
|
||||
{
|
||||
const vtkm::cont::Field field = dataSet.GetField(f);
|
||||
if (!field.IsFieldCell())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
vtkm::Id ncells = field.GetNumberOfValues();
|
||||
int ncomps = field.GetData().GetNumberOfComponents();
|
||||
if (ncomps > 4)
|
||||
continue;
|
||||
|
||||
if (!wrote_header)
|
||||
{
|
||||
out << "CELL_DATA " << ncells << '\n';
|
||||
wrote_header = true;
|
||||
}
|
||||
|
||||
std::string typeName;
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::GetDataTypeName(typeName));
|
||||
|
||||
std::string name = field.GetName();
|
||||
for (auto& c : name)
|
||||
{
|
||||
if (std::isspace(c))
|
||||
{
|
||||
c = '_';
|
||||
}
|
||||
}
|
||||
|
||||
out << "SCALARS " << name << " " << typeName << " " << ncomps << '\n';
|
||||
out << "LOOKUP_TABLE default" << '\n';
|
||||
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::OutputFieldFunctor(out));
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteDataSetAsPoints(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
out << "DATASET UNSTRUCTURED_GRID" << '\n';
|
||||
WritePoints(out, dataSet);
|
||||
WriteVertexCells(out, dataSet);
|
||||
}
|
||||
|
||||
template <class CellSetType>
|
||||
static void WriteDataSetAsUnstructured(std::ostream& out,
|
||||
const vtkm::cont::DataSet& dataSet,
|
||||
const CellSetType& cellSet)
|
||||
{
|
||||
out << "DATASET UNSTRUCTURED_GRID" << '\n';
|
||||
WritePoints(out, dataSet);
|
||||
WriteExplicitCells(out, cellSet);
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent DIM>
|
||||
static void WriteDataSetAsStructured(std::ostream& out,
|
||||
const vtkm::cont::DataSet& dataSet,
|
||||
const vtkm::cont::CellSetStructured<DIM>& cellSet)
|
||||
{
|
||||
///\todo: support uniform/rectilinear
|
||||
out << "DATASET STRUCTURED_GRID" << '\n';
|
||||
|
||||
auto pointDimensions = cellSet.GetPointDimensions();
|
||||
using VTraits = vtkm::VecTraits<decltype(pointDimensions)>;
|
||||
|
||||
out << "DIMENSIONS ";
|
||||
out << VTraits::GetComponent(pointDimensions, 0) << " ";
|
||||
out << (DIM > 1 ? VTraits::GetComponent(pointDimensions, 1) : 1) << " ";
|
||||
out << (DIM > 2 ? VTraits::GetComponent(pointDimensions, 2) : 1) << " ";
|
||||
|
||||
WritePoints(out, dataSet);
|
||||
}
|
||||
|
||||
static void Write(std::ostream& out, const vtkm::cont::DataSet& dataSet, bool just_points = false)
|
||||
{
|
||||
// The Paraview parser cannot handle scientific notation:
|
||||
out << std::fixed;
|
||||
out << "# vtk DataFile Version 3.0" << '\n';
|
||||
out << "vtk output" << '\n';
|
||||
out << "ASCII" << '\n';
|
||||
|
||||
if (just_points)
|
||||
{
|
||||
WriteDataSetAsPoints(out, dataSet);
|
||||
WritePointFields(out, dataSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::cont::DynamicCellSet cellSet = dataSet.GetCellSet();
|
||||
if (cellSet.IsType<vtkm::cont::CellSetExplicit<>>())
|
||||
{
|
||||
WriteDataSetAsUnstructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetExplicit<>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetStructured<1>>())
|
||||
{
|
||||
WriteDataSetAsStructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetStructured<1>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetStructured<2>>())
|
||||
{
|
||||
WriteDataSetAsStructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetStructured<2>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetStructured<3>>())
|
||||
{
|
||||
WriteDataSetAsStructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetStructured<3>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetSingleType<>>())
|
||||
{
|
||||
// these function just like explicit cell sets
|
||||
WriteDataSetAsUnstructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetSingleType<>>());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorBadType("Could not determine type to write out.");
|
||||
}
|
||||
|
||||
WritePointFields(out, dataSet);
|
||||
WriteCellFields(out, dataSet);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
explicit VTKDataSetWriter(const std::string& filename)
|
||||
: FileName(filename)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
void WriteDataSet(const vtkm::cont::DataSet& dataSet, bool just_points = false) const
|
||||
{
|
||||
if (dataSet.GetNumberOfCoordinateSystems() < 1)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue(
|
||||
"DataSet has no coordinate system, which is not supported by VTK file format.");
|
||||
}
|
||||
try
|
||||
{
|
||||
std::ofstream fileStream(this->FileName.c_str(), std::fstream::trunc);
|
||||
this->Write(fileStream, dataSet, just_points);
|
||||
fileStream.close();
|
||||
}
|
||||
catch (std::ofstream::failure& error)
|
||||
{
|
||||
throw vtkm::io::ErrorIO(error.what());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::string FileName;
|
||||
|
||||
}; //struct VTKDataSetWriter
|
||||
}
|
||||
} //namespace vtkm::io
|
||||
|
||||
#endif //vtk_m_io_DataSetWriter_h
|
@ -7,10 +7,10 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_reader_VTKPolyDataReader_h
|
||||
#define vtk_m_io_reader_VTKPolyDataReader_h
|
||||
#ifndef vtk_m_io_VTKPolyDataReader_h
|
||||
#define vtk_m_io_VTKPolyDataReader_h
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
|
||||
@ -20,8 +20,6 @@ namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
namespace reader
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
@ -165,7 +163,6 @@ private:
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::io:reader
|
||||
} // namespace vtkm::io
|
||||
|
||||
#endif // vtk_m_io_reader_VTKPolyDataReader_h
|
||||
#endif // vtk_m_io_VTKPolyDataReader_h
|
@ -7,17 +7,15 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_reader_VTKRectilinearGridReader_h
|
||||
#define vtk_m_io_reader_VTKRectilinearGridReader_h
|
||||
#ifndef vtk_m_io_VTKRectilinearGridReader_h
|
||||
#define vtk_m_io_VTKRectilinearGridReader_h
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
namespace reader
|
||||
{
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
|
||||
|
||||
@ -103,7 +101,6 @@ private:
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::io:reader
|
||||
} // namespace vtkm::io
|
||||
|
||||
#endif // vtk_m_io_reader_VTKRectilinearGridReader_h
|
||||
#endif // vtk_m_io_VTKRectilinearGridReader_h
|
@ -7,17 +7,15 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_reader_VTKStructuredGridReader_h
|
||||
#define vtk_m_io_reader_VTKStructuredGridReader_h
|
||||
#ifndef vtk_m_io_VTKStructuredGridReader_h
|
||||
#define vtk_m_io_VTKStructuredGridReader_h
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
namespace reader
|
||||
{
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
|
||||
|
||||
@ -67,7 +65,6 @@ private:
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::io:reader
|
||||
} // namespace vtkm::io
|
||||
|
||||
#endif // vtk_m_io_reader_VTKStructuredGridReader_h
|
||||
#endif // vtk_m_io_VTKStructuredGridReader_h
|
@ -7,17 +7,15 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_reader_VTKStructuredPointsReader_h
|
||||
#define vtk_m_io_reader_VTKStructuredPointsReader_h
|
||||
#ifndef vtk_m_io_VTKStructuredPointsReader_h
|
||||
#define vtk_m_io_VTKStructuredPointsReader_h
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
namespace reader
|
||||
{
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
|
||||
|
||||
@ -84,7 +82,6 @@ private:
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::io:reader
|
||||
} // namespace vtkm::io
|
||||
|
||||
#endif // vtk_m_io_reader_VTKStructuredPointsReader_h
|
||||
#endif // vtk_m_io_VTKStructuredPointsReader_h
|
@ -7,17 +7,15 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_io_reader_VTKUnstructuredGridReader_h
|
||||
#define vtk_m_io_reader_VTKUnstructuredGridReader_h
|
||||
#ifndef vtk_m_io_VTKUnstructuredGridReader_h
|
||||
#define vtk_m_io_VTKUnstructuredGridReader_h
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
namespace reader
|
||||
{
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
|
||||
|
||||
@ -91,7 +89,6 @@ private:
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::io:reader
|
||||
} // namespace vtkm::io
|
||||
|
||||
#endif // vtk_m_io_reader_VTKUnstructuredGridReader_h
|
||||
#endif // vtk_m_io_VTKUnstructuredGridReader_h
|
@ -10,11 +10,8 @@
|
||||
#ifndef vtk_m_io_reader_BOVDataSetReader_h
|
||||
#define vtk_m_io_reader_BOVDataSetReader_h
|
||||
|
||||
#include <fstream>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderUniform.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/io/ErrorIO.h>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/io/BOVDataSetReader.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
@ -23,256 +20,18 @@ namespace io
|
||||
namespace reader
|
||||
{
|
||||
|
||||
class BOVDataSetReader
|
||||
class VTKM_DEPRECATED(1.6, "Please use vtkm::io::BOVDataSetReader.") BOVDataSetReader
|
||||
: public io::BOVDataSetReader
|
||||
{
|
||||
public:
|
||||
BOVDataSetReader(const char* fileName)
|
||||
: FileName(fileName)
|
||||
, Loaded(false)
|
||||
, DataSet()
|
||||
: io::BOVDataSetReader(fileName)
|
||||
{
|
||||
}
|
||||
BOVDataSetReader(const std::string& fileName)
|
||||
: FileName(fileName)
|
||||
, Loaded(false)
|
||||
, DataSet()
|
||||
: BOVDataSetReader(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
const vtkm::cont::DataSet& ReadDataSet()
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadFile();
|
||||
}
|
||||
catch (std::ifstream::failure& e)
|
||||
{
|
||||
std::string message("IO Error: ");
|
||||
throw vtkm::io::ErrorIO(message + e.what());
|
||||
}
|
||||
return this->DataSet;
|
||||
}
|
||||
|
||||
private:
|
||||
using DataFormat = enum { ByteData, ShortData, IntegerData, FloatData, DoubleData };
|
||||
|
||||
void LoadFile()
|
||||
{
|
||||
if (this->Loaded)
|
||||
return;
|
||||
|
||||
std::ifstream stream(this->FileName);
|
||||
if (stream.fail())
|
||||
throw vtkm::io::ErrorIO("Failed to open file: " + this->FileName);
|
||||
|
||||
DataFormat dataFormat = ByteData;
|
||||
std::string bovFile, line, token, options, variableName;
|
||||
vtkm::Id numComponents = 1;
|
||||
vtkm::Id3 dim;
|
||||
vtkm::Vec3f origin(0, 0, 0);
|
||||
vtkm::Vec3f spacing(1, 1, 1);
|
||||
bool spacingSet = false;
|
||||
|
||||
while (stream.good())
|
||||
{
|
||||
std::getline(stream, line);
|
||||
if (line.size() == 0 || line[0] == '#')
|
||||
continue;
|
||||
//std::cout<<"::"<<line<<"::"<<std::endl;
|
||||
std::size_t pos = line.find(":");
|
||||
if (pos == std::string::npos)
|
||||
throw vtkm::io::ErrorIO("Unsupported option: " + line);
|
||||
token = line.substr(0, pos);
|
||||
options = line.substr(pos + 1, line.size() - 1);
|
||||
//std::cout<<token<<"::"<<options<<std::endl;
|
||||
|
||||
std::stringstream strStream(options);
|
||||
|
||||
//Format supports both space and "_" separated tokens...
|
||||
if (token.find("DATA") != std::string::npos && token.find("FILE") != std::string::npos)
|
||||
{
|
||||
strStream >> bovFile >> std::ws;
|
||||
}
|
||||
else if (token.find("DATA") != std::string::npos && token.find("SIZE") != std::string::npos)
|
||||
{
|
||||
strStream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
|
||||
}
|
||||
else if (token.find("BRICK") != std::string::npos &&
|
||||
token.find("ORIGIN") != std::string::npos)
|
||||
{
|
||||
strStream >> origin[0] >> origin[1] >> origin[2] >> std::ws;
|
||||
}
|
||||
|
||||
//DRP
|
||||
else if (token.find("BRICK") != std::string::npos && token.find("SIZE") != std::string::npos)
|
||||
{
|
||||
strStream >> spacing[0] >> spacing[1] >> spacing[2] >> std::ws;
|
||||
spacingSet = true;
|
||||
}
|
||||
else if (token.find("DATA") != std::string::npos && token.find("FORMAT") != std::string::npos)
|
||||
{
|
||||
std::string opt;
|
||||
strStream >> opt >> std::ws;
|
||||
if (opt.find("FLOAT") != std::string::npos || opt.find("REAL") != std::string::npos)
|
||||
dataFormat = FloatData;
|
||||
else if (opt.find("DOUBLE") != std::string::npos)
|
||||
dataFormat = DoubleData;
|
||||
else
|
||||
throw vtkm::io::ErrorIO("Unsupported data type: " + token);
|
||||
}
|
||||
else if (token.find("DATA") != std::string::npos &&
|
||||
token.find("COMPONENTS") != std::string::npos)
|
||||
{
|
||||
strStream >> numComponents >> std::ws;
|
||||
if (numComponents != 1 && numComponents != 3)
|
||||
throw vtkm::io::ErrorIO("Unsupported number of components");
|
||||
}
|
||||
else if (token.find("VARIABLE") != std::string::npos &&
|
||||
token.find("PALETTE") == std::string::npos)
|
||||
{
|
||||
strStream >> variableName >> std::ws;
|
||||
if (variableName[0] == '"')
|
||||
variableName = variableName.substr(1, variableName.size() - 2);
|
||||
}
|
||||
/*
|
||||
else
|
||||
std::cerr<<"Unsupported BOV option: "<<token<<std::endl;
|
||||
*/
|
||||
}
|
||||
|
||||
if (spacingSet)
|
||||
{
|
||||
spacing[0] = (spacing[0]) / static_cast<vtkm::FloatDefault>(dim[0] - 1);
|
||||
spacing[1] = (spacing[1]) / static_cast<vtkm::FloatDefault>(dim[1] - 1);
|
||||
spacing[2] = (spacing[2]) / static_cast<vtkm::FloatDefault>(dim[2] - 1);
|
||||
}
|
||||
|
||||
std::string fullPathDataFile;
|
||||
std::size_t pos = FileName.rfind("/");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string baseDir;
|
||||
baseDir = this->FileName.substr(0, pos);
|
||||
fullPathDataFile = baseDir + "/" + bovFile;
|
||||
}
|
||||
else
|
||||
fullPathDataFile = bovFile;
|
||||
|
||||
/*
|
||||
//Get whole path for data file.
|
||||
std::string fullPathDataFile;
|
||||
if (bovFile[0] == '/')
|
||||
fullPathDataFile = bovFile;
|
||||
else
|
||||
{
|
||||
//Get base dir.
|
||||
std::string baseDir, baseFile;
|
||||
std::cout<<FileName<<std::endl;
|
||||
std::size_t pos = FileName.rfind("/");
|
||||
if (pos != std::string::npos)
|
||||
baseDir = this->FileName.substr(0, pos);
|
||||
std::cout<<"BASE: "<<baseDir<<std::endl;
|
||||
|
||||
if (bovFile.substr(0,2) == "./")
|
||||
{
|
||||
baseFile = bovFile.substr(2, bovFile.size()-2);
|
||||
}
|
||||
if (baseDir.size() == 0)
|
||||
fullPathDataFile = baseFile;
|
||||
else
|
||||
fullPathDataFile = baseDir + "/" + baseFile;
|
||||
std::cout<<baseDir<<" : "<<baseFile<<std::endl;
|
||||
std::cout<<fullPathDataFile<<std::endl;
|
||||
}
|
||||
*/
|
||||
|
||||
vtkm::cont::DataSetBuilderUniform dataSetBuilder;
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
this->DataSet = dataSetBuilder.Create(dim, origin, spacing);
|
||||
|
||||
vtkm::Id numTuples = dim[0] * dim[1] * dim[2];
|
||||
if (numComponents == 1)
|
||||
{
|
||||
if (dataFormat == FloatData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float64> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
else if (numComponents == 3)
|
||||
{
|
||||
if (dataFormat == FloatData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
|
||||
this->Loaded = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadBuffer(const std::string& fName, const vtkm::Id& sz, std::vector<T>& buff)
|
||||
{
|
||||
FILE* fp = fopen(fName.c_str(), "rb");
|
||||
size_t readSize = static_cast<size_t>(sz);
|
||||
if (fp == nullptr)
|
||||
throw vtkm::io::ErrorIO("Unable to open data file: " + fName);
|
||||
buff.resize(readSize);
|
||||
size_t nread = fread(&buff[0], sizeof(T), readSize, fp);
|
||||
if (nread != readSize)
|
||||
throw vtkm::io::ErrorIO("Data file read failed: " + fName);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadScalar(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<T>& var)
|
||||
{
|
||||
std::vector<T> buff;
|
||||
ReadBuffer(fName, nTuples, buff);
|
||||
var.Allocate(nTuples);
|
||||
for (vtkm::Id i = 0; i < nTuples; i++)
|
||||
var.WritePortal().Set(i, buff[(size_t)i]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadVector(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& var)
|
||||
{
|
||||
std::vector<T> buff;
|
||||
ReadBuffer(fName, nTuples * 3, buff);
|
||||
|
||||
var.Allocate(nTuples);
|
||||
vtkm::Vec<T, 3> v;
|
||||
for (vtkm::Id i = 0; i < nTuples; i++)
|
||||
{
|
||||
v[0] = buff[static_cast<size_t>(i * 3 + 0)];
|
||||
v[1] = buff[static_cast<size_t>(i * 3 + 1)];
|
||||
v[2] = buff[static_cast<size_t>(i * 3 + 2)];
|
||||
var.WritePortal().Set(i, v);
|
||||
}
|
||||
}
|
||||
|
||||
std::string FileName;
|
||||
bool Loaded;
|
||||
vtkm::cont::DataSet DataSet;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -10,15 +10,7 @@
|
||||
|
||||
set(headers
|
||||
BOVDataSetReader.h
|
||||
VTKDataSetReaderBase.h
|
||||
VTKPolyDataReader.h
|
||||
VTKStructuredGridReader.h
|
||||
VTKRectilinearGridReader.h
|
||||
VTKStructuredPointsReader.h
|
||||
VTKUnstructuredGridReader.h
|
||||
VTKDataSetReader.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
add_subdirectory(testing)
|
||||
|
@ -10,14 +10,8 @@
|
||||
#ifndef vtk_m_io_reader_VTKDataSetReader_h
|
||||
#define vtk_m_io_reader_VTKDataSetReader_h
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/reader/VTKPolyDataReader.h>
|
||||
#include <vtkm/io/reader/VTKRectilinearGridReader.h>
|
||||
#include <vtkm/io/reader/VTKStructuredGridReader.h>
|
||||
#include <vtkm/io/reader/VTKStructuredPointsReader.h>
|
||||
#include <vtkm/io/reader/VTKUnstructuredGridReader.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
@ -26,78 +20,20 @@ namespace io
|
||||
namespace reader
|
||||
{
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
|
||||
|
||||
class VTKDataSetReader : public VTKDataSetReaderBase
|
||||
class VTKM_DEPRECATED(1.6, "Please use vtkm::io::VTKDataSetReader.") VTKDataSetReader
|
||||
: public io::VTKDataSetReader
|
||||
{
|
||||
public:
|
||||
explicit VTKDataSetReader(const char* fileName)
|
||||
: VTKDataSetReaderBase(fileName)
|
||||
: io::VTKDataSetReader(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
explicit VTKDataSetReader(const std::string& fileName)
|
||||
: VTKDataSetReaderBase(fileName)
|
||||
: io::VTKDataSetReader(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void PrintSummary(std::ostream& out) const
|
||||
{
|
||||
if (this->Reader)
|
||||
{
|
||||
this->Reader->PrintSummary(out);
|
||||
}
|
||||
else
|
||||
{
|
||||
VTKDataSetReaderBase::PrintSummary(out);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void CloseFile()
|
||||
{
|
||||
if (this->Reader)
|
||||
{
|
||||
this->Reader->CloseFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
VTKDataSetReaderBase::CloseFile();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Read()
|
||||
{
|
||||
switch (this->DataFile->Structure)
|
||||
{
|
||||
case vtkm::io::internal::DATASET_STRUCTURED_POINTS:
|
||||
this->Reader.reset(new VTKStructuredPointsReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_STRUCTURED_GRID:
|
||||
this->Reader.reset(new VTKStructuredGridReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_RECTILINEAR_GRID:
|
||||
this->Reader.reset(new VTKRectilinearGridReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_POLYDATA:
|
||||
this->Reader.reset(new VTKPolyDataReader(""));
|
||||
break;
|
||||
case vtkm::io::internal::DATASET_UNSTRUCTURED_GRID:
|
||||
this->Reader.reset(new VTKUnstructuredGridReader(""));
|
||||
break;
|
||||
default:
|
||||
throw vtkm::io::ErrorIO("Unsupported DataSet type.");
|
||||
}
|
||||
|
||||
this->TransferDataFile(*this->Reader.get());
|
||||
this->Reader->Read();
|
||||
this->DataSet = this->Reader->GetDataSet();
|
||||
}
|
||||
|
||||
std::unique_ptr<VTKDataSetReaderBase> Reader;
|
||||
};
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // vtkm::io::reader
|
||||
|
@ -1,15 +0,0 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestVTKDataSetReader.cxx
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} ALL_BACKENDS)
|
@ -9,6 +9,7 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestVTKDataSetReader.cxx
|
||||
UnitTestVTKDataSetWriter.cxx
|
||||
)
|
||||
|
4
vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx → vtkm/io/testing/UnitTestVTKDataSetReader.cxx
4
vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx → vtkm/io/testing/UnitTestVTKDataSetReader.cxx
@ -9,7 +9,7 @@
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -401,7 +401,7 @@ inline void createFile(const char* buffer, std::size_t size, const char* fname)
|
||||
inline vtkm::cont::DataSet readVTKDataSet(const char* fname)
|
||||
{
|
||||
vtkm::cont::DataSet ds;
|
||||
vtkm::io::reader::VTKDataSetReader reader(fname);
|
||||
vtkm::io::VTKDataSetReader reader(fname);
|
||||
try
|
||||
{
|
||||
ds = reader.ReadDataSet();
|
12
vtkm/io/writer/testing/UnitTestVTKDataSetWriter.cxx → vtkm/io/testing/UnitTestVTKDataSetWriter.cxx
12
vtkm/io/writer/testing/UnitTestVTKDataSetWriter.cxx → vtkm/io/testing/UnitTestVTKDataSetWriter.cxx
@ -11,7 +11,7 @@
|
||||
#include <complex>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
@ -25,7 +25,7 @@ namespace
|
||||
void TestVTKWriteTestData(const std::string& methodName, const vtkm::cont::DataSet& data)
|
||||
{
|
||||
std::cout << "Writing " << methodName << std::endl;
|
||||
vtkm::io::writer::VTKDataSetWriter writer(methodName + ".vtk");
|
||||
vtkm::io::VTKDataSetWriter writer(methodName + ".vtk");
|
||||
writer.WriteDataSet(data);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ void TestVTKExplicitWrite()
|
||||
WRITE_FILE(Make3DExplicitDataSetCowNose);
|
||||
|
||||
std::cout << "Force writer to output an explicit grid as points" << std::endl;
|
||||
vtkm::io::writer::VTKDataSetWriter writer("Make3DExplicitDataSet0-no-grid.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("Make3DExplicitDataSet0-no-grid.vtk");
|
||||
writer.WriteDataSet(tds.Make3DExplicitDataSet0(), true);
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ void TestVTKUniformWrite()
|
||||
WRITE_FILE(Make3DRegularDataSet1);
|
||||
|
||||
std::cout << "Force writer to output a uniform grid as points" << std::endl;
|
||||
vtkm::io::writer::VTKDataSetWriter writer("Make3DUniformDataSet0-no-grid.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("Make3DUniformDataSet0-no-grid.vtk");
|
||||
writer.WriteDataSet(tds.Make3DUniformDataSet0(), true);
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ void TestVTKRectilinearWrite()
|
||||
WRITE_FILE(Make3DRectilinearDataSet0);
|
||||
|
||||
std::cout << "Force writer to output a rectilinear grid as points" << std::endl;
|
||||
vtkm::io::writer::VTKDataSetWriter writer("Make3DRectilinearDataSet0-no-grid.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("Make3DRectilinearDataSet0-no-grid.vtk");
|
||||
writer.WriteDataSet(tds.Make3DRectilinearDataSet0(), true);
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ void TestVTKCompoundWrite()
|
||||
}
|
||||
|
||||
dsf.AddPointField(dataSet, "z", points.data(), static_cast<vtkm::Id>(points.size()));
|
||||
vtkm::io::writer::VTKDataSetWriter writer("chirp.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("chirp.vtk");
|
||||
writer.WriteDataSet(dataSet);
|
||||
std::remove("chirp.vtk");
|
||||
}
|
@ -13,6 +13,3 @@ set(headers
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory(testing)
|
||||
|
@ -10,27 +10,8 @@
|
||||
#ifndef vtk_m_io_writer_DataSetWriter_h
|
||||
#define vtk_m_io_writer_DataSetWriter_h
|
||||
|
||||
#include <cctype>
|
||||
#include <vtkm/CellShape.h>
|
||||
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/CellSetStructured.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/ErrorBadType.h>
|
||||
#include <vtkm/cont/ErrorBadValue.h>
|
||||
#include <vtkm/cont/Field.h>
|
||||
|
||||
#include <vtkm/io/ErrorIO.h>
|
||||
|
||||
#include <vtkm/io/internal/VTKDataSetTypes.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
@ -39,379 +20,15 @@ namespace io
|
||||
namespace writer
|
||||
{
|
||||
|
||||
namespace detail
|
||||
struct VTKM_DEPRECATED(1.6, "Please use vtkm::io::VTKDataSetWriter") VTKDataSetWriter
|
||||
: vtkm::io::VTKDataSetWriter
|
||||
{
|
||||
|
||||
struct OutputPointsFunctor
|
||||
{
|
||||
private:
|
||||
std::ostream& out;
|
||||
|
||||
template <typename PortalType>
|
||||
VTKM_CONT void Output(const PortalType& portal) const
|
||||
{
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
||||
{
|
||||
const int VTKDims = 3; // VTK files always require 3 dims for points
|
||||
|
||||
using ValueType = typename PortalType::ValueType;
|
||||
using VecType = typename vtkm::VecTraits<ValueType>;
|
||||
|
||||
const ValueType& value = portal.Get(index);
|
||||
|
||||
vtkm::IdComponent numComponents = VecType::GetNumberOfComponents(value);
|
||||
for (vtkm::IdComponent c = 0; c < numComponents && c < VTKDims; c++)
|
||||
{
|
||||
out << (c == 0 ? "" : " ") << VecType::GetComponent(value, c);
|
||||
}
|
||||
for (vtkm::IdComponent c = numComponents; c < VTKDims; c++)
|
||||
{
|
||||
out << " 0";
|
||||
}
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
OutputPointsFunctor(std::ostream& o)
|
||||
: out(o)
|
||||
VTKDataSetWriter(const std::string& filename)
|
||||
: vtkm::io::VTKDataSetWriter(filename)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T, typename Storage>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, Storage>& array) const
|
||||
{
|
||||
this->Output(array.ReadPortal());
|
||||
}
|
||||
};
|
||||
|
||||
struct OutputFieldFunctor
|
||||
{
|
||||
private:
|
||||
std::ostream& out;
|
||||
|
||||
template <typename PortalType>
|
||||
VTKM_CONT void Output(const PortalType& portal) const
|
||||
{
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
||||
{
|
||||
using ValueType = typename PortalType::ValueType;
|
||||
using VecType = typename vtkm::VecTraits<ValueType>;
|
||||
|
||||
const ValueType& value = portal.Get(index);
|
||||
|
||||
vtkm::IdComponent numComponents = VecType::GetNumberOfComponents(value);
|
||||
for (vtkm::IdComponent c = 0; c < numComponents; c++)
|
||||
{
|
||||
out << (c == 0 ? "" : " ") << VecType::GetComponent(value, c);
|
||||
}
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
OutputFieldFunctor(std::ostream& o)
|
||||
: out(o)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T, typename Storage>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, Storage>& array) const
|
||||
{
|
||||
this->Output(array.ReadPortal());
|
||||
}
|
||||
};
|
||||
|
||||
class GetDataTypeName
|
||||
{
|
||||
public:
|
||||
GetDataTypeName(std::string& name)
|
||||
: Name(&name)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ArrayHandleType>
|
||||
void operator()(const ArrayHandleType&) const
|
||||
{
|
||||
using DataType = typename vtkm::VecTraits<typename ArrayHandleType::ValueType>::ComponentType;
|
||||
*this->Name = vtkm::io::internal::DataTypeName<DataType>::Name();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string* Name;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
struct VTKDataSetWriter
|
||||
{
|
||||
private:
|
||||
static void WritePoints(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
///\todo: support other coordinate systems
|
||||
int cindex = 0;
|
||||
auto cdata = dataSet.GetCoordinateSystem(cindex).GetData();
|
||||
|
||||
vtkm::Id npoints = cdata.GetNumberOfValues();
|
||||
out << "POINTS " << npoints << " "
|
||||
<< vtkm::io::internal::DataTypeName<vtkm::FloatDefault>::Name() << " " << '\n';
|
||||
|
||||
detail::OutputPointsFunctor{ out }(cdata);
|
||||
}
|
||||
|
||||
template <class CellSetType>
|
||||
static void WriteExplicitCells(std::ostream& out, const CellSetType& cellSet)
|
||||
{
|
||||
vtkm::Id nCells = cellSet.GetNumberOfCells();
|
||||
|
||||
vtkm::Id conn_length = 0;
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
conn_length += 1 + cellSet.GetNumberOfPointsInCell(i);
|
||||
}
|
||||
|
||||
out << "CELLS " << nCells << " " << conn_length << '\n';
|
||||
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> ids;
|
||||
vtkm::Id nids = cellSet.GetNumberOfPointsInCell(i);
|
||||
cellSet.GetIndices(i, ids);
|
||||
out << nids;
|
||||
auto IdPortal = ids.ReadPortal();
|
||||
for (int j = 0; j < nids; ++j)
|
||||
out << " " << IdPortal.Get(j);
|
||||
out << '\n';
|
||||
}
|
||||
|
||||
out << "CELL_TYPES " << nCells << '\n';
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
vtkm::Id shape = cellSet.GetCellShape(i);
|
||||
out << shape << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteVertexCells(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
vtkm::Id nCells = dataSet.GetCoordinateSystem(0).GetNumberOfPoints();
|
||||
|
||||
out << "CELLS " << nCells << " " << nCells * 2 << '\n';
|
||||
for (int i = 0; i < nCells; i++)
|
||||
{
|
||||
out << "1 " << i << '\n';
|
||||
}
|
||||
out << "CELL_TYPES " << nCells << '\n';
|
||||
for (int i = 0; i < nCells; i++)
|
||||
{
|
||||
out << vtkm::CELL_SHAPE_VERTEX << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
static void WritePointFields(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
bool wrote_header = false;
|
||||
for (vtkm::Id f = 0; f < dataSet.GetNumberOfFields(); f++)
|
||||
{
|
||||
const vtkm::cont::Field field = dataSet.GetField(f);
|
||||
|
||||
if (field.GetAssociation() != vtkm::cont::Field::Association::POINTS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vtkm::Id npoints = field.GetNumberOfValues();
|
||||
int ncomps = field.GetData().GetNumberOfComponents();
|
||||
if (ncomps > 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!wrote_header)
|
||||
{
|
||||
out << "POINT_DATA " << npoints << '\n';
|
||||
wrote_header = true;
|
||||
}
|
||||
|
||||
std::string typeName;
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::GetDataTypeName(typeName));
|
||||
std::string name = field.GetName();
|
||||
for (auto& c : name)
|
||||
{
|
||||
if (std::isspace(c))
|
||||
{
|
||||
c = '_';
|
||||
}
|
||||
}
|
||||
out << "SCALARS " << name << " " << typeName << " " << ncomps << '\n';
|
||||
out << "LOOKUP_TABLE default" << '\n';
|
||||
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::OutputFieldFunctor(out));
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteCellFields(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
bool wrote_header = false;
|
||||
for (vtkm::Id f = 0; f < dataSet.GetNumberOfFields(); f++)
|
||||
{
|
||||
const vtkm::cont::Field field = dataSet.GetField(f);
|
||||
if (!field.IsFieldCell())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
vtkm::Id ncells = field.GetNumberOfValues();
|
||||
int ncomps = field.GetData().GetNumberOfComponents();
|
||||
if (ncomps > 4)
|
||||
continue;
|
||||
|
||||
if (!wrote_header)
|
||||
{
|
||||
out << "CELL_DATA " << ncells << '\n';
|
||||
wrote_header = true;
|
||||
}
|
||||
|
||||
std::string typeName;
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::GetDataTypeName(typeName));
|
||||
|
||||
std::string name = field.GetName();
|
||||
for (auto& c : name)
|
||||
{
|
||||
if (std::isspace(c))
|
||||
{
|
||||
c = '_';
|
||||
}
|
||||
}
|
||||
|
||||
out << "SCALARS " << name << " " << typeName << " " << ncomps << '\n';
|
||||
out << "LOOKUP_TABLE default" << '\n';
|
||||
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::OutputFieldFunctor(out));
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteDataSetAsPoints(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
out << "DATASET UNSTRUCTURED_GRID" << '\n';
|
||||
WritePoints(out, dataSet);
|
||||
WriteVertexCells(out, dataSet);
|
||||
}
|
||||
|
||||
template <class CellSetType>
|
||||
static void WriteDataSetAsUnstructured(std::ostream& out,
|
||||
const vtkm::cont::DataSet& dataSet,
|
||||
const CellSetType& cellSet)
|
||||
{
|
||||
out << "DATASET UNSTRUCTURED_GRID" << '\n';
|
||||
WritePoints(out, dataSet);
|
||||
WriteExplicitCells(out, cellSet);
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent DIM>
|
||||
static void WriteDataSetAsStructured(std::ostream& out,
|
||||
const vtkm::cont::DataSet& dataSet,
|
||||
const vtkm::cont::CellSetStructured<DIM>& cellSet)
|
||||
{
|
||||
///\todo: support uniform/rectilinear
|
||||
out << "DATASET STRUCTURED_GRID" << '\n';
|
||||
|
||||
auto pointDimensions = cellSet.GetPointDimensions();
|
||||
using VTraits = vtkm::VecTraits<decltype(pointDimensions)>;
|
||||
|
||||
out << "DIMENSIONS ";
|
||||
out << VTraits::GetComponent(pointDimensions, 0) << " ";
|
||||
out << (DIM > 1 ? VTraits::GetComponent(pointDimensions, 1) : 1) << " ";
|
||||
out << (DIM > 2 ? VTraits::GetComponent(pointDimensions, 2) : 1) << " ";
|
||||
|
||||
WritePoints(out, dataSet);
|
||||
}
|
||||
|
||||
static void Write(std::ostream& out, const vtkm::cont::DataSet& dataSet, bool just_points = false)
|
||||
{
|
||||
// The Paraview parser cannot handle scientific notation:
|
||||
out << std::fixed;
|
||||
out << "# vtk DataFile Version 3.0" << '\n';
|
||||
out << "vtk output" << '\n';
|
||||
out << "ASCII" << '\n';
|
||||
|
||||
if (just_points)
|
||||
{
|
||||
WriteDataSetAsPoints(out, dataSet);
|
||||
WritePointFields(out, dataSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::cont::DynamicCellSet cellSet = dataSet.GetCellSet();
|
||||
if (cellSet.IsType<vtkm::cont::CellSetExplicit<>>())
|
||||
{
|
||||
WriteDataSetAsUnstructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetExplicit<>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetStructured<1>>())
|
||||
{
|
||||
WriteDataSetAsStructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetStructured<1>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetStructured<2>>())
|
||||
{
|
||||
WriteDataSetAsStructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetStructured<2>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetStructured<3>>())
|
||||
{
|
||||
WriteDataSetAsStructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetStructured<3>>());
|
||||
}
|
||||
else if (cellSet.IsType<vtkm::cont::CellSetSingleType<>>())
|
||||
{
|
||||
// these function just like explicit cell sets
|
||||
WriteDataSetAsUnstructured(out, dataSet, cellSet.Cast<vtkm::cont::CellSetSingleType<>>());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorBadType("Could not determine type to write out.");
|
||||
}
|
||||
|
||||
WritePointFields(out, dataSet);
|
||||
WriteCellFields(out, dataSet);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
explicit VTKDataSetWriter(const std::string& filename)
|
||||
: FileName(filename)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
void WriteDataSet(const vtkm::cont::DataSet& dataSet, bool just_points = false) const
|
||||
{
|
||||
if (dataSet.GetNumberOfCoordinateSystems() < 1)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue(
|
||||
"DataSet has no coordinate system, which is not supported by VTK file format.");
|
||||
}
|
||||
try
|
||||
{
|
||||
std::ofstream fileStream(this->FileName.c_str(), std::fstream::trunc);
|
||||
this->Write(fileStream, dataSet, just_points);
|
||||
fileStream.close();
|
||||
}
|
||||
catch (std::ofstream::failure& error)
|
||||
{
|
||||
throw vtkm::io::ErrorIO(error.what());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::string FileName;
|
||||
|
||||
}; //struct VTKDataSetWriter
|
||||
}
|
||||
}
|
||||
} //namespace vtkm::io::writer
|
||||
|
@ -16,23 +16,6 @@ if(NOT VTKm_ENABLE_RENDERING)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# determine what context(s) for rendering we want to build
|
||||
vtkm_option(VTKm_ENABLE_GL_CONTEXT "Enable GL context for vtkm rendering" OFF)
|
||||
if(UNIX AND NOT APPLE)
|
||||
vtkm_option(VTKm_ENABLE_OSMESA_CONTEXT "Enable OSMesa context for vtkm rendering" OFF)
|
||||
vtkm_option(VTKm_ENABLE_EGL_CONTEXT "Enable EGL context for vtkm rendering" OFF)
|
||||
mark_as_advanced(VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
mark_as_advanced(VTKm_ENABLE_EGL_CONTEXT)
|
||||
endif()
|
||||
if(VTKm_ENABLE_GL_CONTEXT AND VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
message(FATAL_ERROR "VTK-m GL and OSMesa contexts are mutually exclusive")
|
||||
endif()
|
||||
if(VTKm_ENABLE_GL_CONTEXT AND VTKm_ENABLE_EGL_CONTEXT)
|
||||
message(FATAL_ERROR "VTK-m GL and EGL contexts are mutually exclusive")
|
||||
endif()
|
||||
if(VTKm_ENABLE_EGL_CONTEXT AND VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
message(FATAL_ERROR "VTK-m EGL and OSMesa contexts are mutually exclusive")
|
||||
endif()
|
||||
|
||||
set(headers
|
||||
Actor.h
|
||||
@ -50,8 +33,8 @@ set(headers
|
||||
ColorLegendAnnotation.h
|
||||
ConnectivityProxy.h
|
||||
Cylinderizer.h
|
||||
DecodePNG.h
|
||||
EncodePNG.h
|
||||
DecodePNG.h # deprecated
|
||||
EncodePNG.h # deprecated
|
||||
LineRenderer.h
|
||||
MatrixHelpers.h
|
||||
Scene.h
|
||||
@ -85,8 +68,6 @@ set(sources
|
||||
|
||||
Camera.cxx
|
||||
Color.cxx
|
||||
DecodePNG.cxx
|
||||
EncodePNG.cxx
|
||||
raytracing/Logger.cxx
|
||||
)
|
||||
|
||||
@ -146,37 +127,7 @@ set(device_sources
|
||||
raytracing/VolumeRendererStructured.cxx
|
||||
)
|
||||
|
||||
# Note that EGL and OSMesa Canvas depend on the GL version being built. Only
|
||||
# the None backend supports not building the opengl version
|
||||
set(opengl_headers
|
||||
CanvasGL.h
|
||||
MapperGL.h
|
||||
TextureGL.h
|
||||
WorldAnnotatorGL.h
|
||||
)
|
||||
|
||||
set(opengl_sources
|
||||
CanvasGL.cxx
|
||||
MapperGL.cxx
|
||||
TextureGL.cxx
|
||||
WorldAnnotatorGL.cxx
|
||||
)
|
||||
|
||||
set(egl_headers
|
||||
CanvasEGL.h
|
||||
)
|
||||
|
||||
set(egl_sources
|
||||
CanvasEGL.cxx
|
||||
)
|
||||
|
||||
set(osmesa_headers
|
||||
CanvasOSMesa.h
|
||||
)
|
||||
|
||||
set(osmesa_sources
|
||||
CanvasOSMesa.cxx
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
vtkm_library(
|
||||
@ -186,22 +137,8 @@ vtkm_library(
|
||||
DEVICE_SOURCES ${device_sources}
|
||||
)
|
||||
|
||||
# Install all headers no matter what backend was selected
|
||||
vtkm_declare_headers(${opengl_headers})
|
||||
vtkm_declare_headers(${osmesa_headers})
|
||||
vtkm_declare_headers(${egl_headers})
|
||||
|
||||
if(VTKm_ENABLE_GL_CONTEXT)
|
||||
target_sources(vtkm_rendering PRIVATE ${opengl_sources})
|
||||
elseif(VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
target_sources(vtkm_rendering PRIVATE ${opengl_sources} ${osmesa_sources})
|
||||
elseif(VTKm_ENABLE_EGL_CONTEXT)
|
||||
target_sources(vtkm_rendering PRIVATE ${opengl_sources} ${egl_sources})
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
target_link_libraries(vtkm_rendering PUBLIC vtkm_filter
|
||||
PRIVATE vtkm_lodepng)
|
||||
target_link_libraries(vtkm_rendering PUBLIC vtkm_filter vtkm_io)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(vtkm_rendering PRIVATE rt)
|
||||
endif()
|
||||
|
@ -12,9 +12,9 @@
|
||||
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/TryExecute.h>
|
||||
#include <vtkm/io/DecodePNG.h>
|
||||
#include <vtkm/io/EncodePNG.h>
|
||||
#include <vtkm/rendering/BitmapFontFactory.h>
|
||||
#include <vtkm/rendering/DecodePNG.h>
|
||||
#include <vtkm/rendering/EncodePNG.h>
|
||||
#include <vtkm/rendering/LineRenderer.h>
|
||||
#include <vtkm/rendering/TextRenderer.h>
|
||||
#include <vtkm/rendering/WorldAnnotator.h>
|
||||
@ -523,7 +523,7 @@ bool Canvas::LoadFont() const
|
||||
const std::vector<unsigned char>& rawPNG = Internals->Font.GetRawImageData();
|
||||
std::vector<unsigned char> rgba;
|
||||
unsigned long textureWidth, textureHeight;
|
||||
auto error = DecodePNG(rgba, textureWidth, textureHeight, &rawPNG[0], rawPNG.size());
|
||||
auto error = io::DecodePNG(rgba, textureWidth, textureHeight, &rawPNG[0], rawPNG.size());
|
||||
if (error != 0)
|
||||
{
|
||||
return false;
|
||||
@ -598,7 +598,8 @@ void Canvas::SaveAs(const std::string& fileName) const
|
||||
}
|
||||
}
|
||||
|
||||
SavePNG(fileName, img, static_cast<unsigned long>(width), static_cast<unsigned long>(height));
|
||||
vtkm::io::SavePNG(
|
||||
fileName, img, static_cast<unsigned long>(width), static_cast<unsigned long>(height));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,122 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/CanvasEGL.h>
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
//#include <GL/gl.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasEGLInternals
|
||||
{
|
||||
EGLContext Context;
|
||||
EGLDisplay Display;
|
||||
EGLSurface Surface;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
CanvasEGL::CanvasEGL(vtkm::Id width, vtkm::Id height)
|
||||
: CanvasGL(width, height)
|
||||
, Internals(new detail::CanvasEGLInternals)
|
||||
{
|
||||
this->Internals->Context = nullptr;
|
||||
this->ResizeBuffers(width, height);
|
||||
}
|
||||
|
||||
CanvasEGL::~CanvasEGL()
|
||||
{
|
||||
}
|
||||
|
||||
void CanvasEGL::Initialize()
|
||||
{
|
||||
this->Internals->Display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (!(this->Internals->Display))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to get EGL display");
|
||||
}
|
||||
EGLint major, minor;
|
||||
if (!(eglInitialize(this->Internals->Display, &major, &minor)))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to initialize EGL display");
|
||||
}
|
||||
|
||||
const EGLint cfgAttrs[] = { EGL_SURFACE_TYPE,
|
||||
EGL_PBUFFER_BIT,
|
||||
EGL_BLUE_SIZE,
|
||||
8,
|
||||
EGL_GREEN_SIZE,
|
||||
8,
|
||||
EGL_RED_SIZE,
|
||||
8,
|
||||
EGL_DEPTH_SIZE,
|
||||
8,
|
||||
EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_BIT,
|
||||
EGL_NONE };
|
||||
|
||||
EGLint nCfgs;
|
||||
EGLConfig cfg;
|
||||
if (!(eglChooseConfig(this->Internals->Display, cfgAttrs, &cfg, 1, &nCfgs)) || (nCfgs == 0))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to get EGL config");
|
||||
}
|
||||
|
||||
const EGLint pbAttrs[] = {
|
||||
EGL_WIDTH, static_cast<EGLint>(this->GetWidth()),
|
||||
EGL_HEIGHT, static_cast<EGLint>(this->GetHeight()),
|
||||
EGL_NONE,
|
||||
};
|
||||
|
||||
this->Internals->Surface = eglCreatePbufferSurface(this->Internals->Display, cfg, pbAttrs);
|
||||
if (!this->Internals->Surface)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to create EGL PBuffer surface");
|
||||
}
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
this->Internals->Context =
|
||||
eglCreateContext(this->Internals->Display, cfg, EGL_NO_CONTEXT, nullptr);
|
||||
if (!this->Internals->Context)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to create EGL context");
|
||||
}
|
||||
if (!(eglMakeCurrent(this->Internals->Display,
|
||||
this->Internals->Surface,
|
||||
this->Internals->Surface,
|
||||
this->Internals->Context)))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to create EGL context current");
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasEGL::Activate()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* CanvasEGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasEGL(*this);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,49 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_CanvasEGL_h
|
||||
#define vtk_m_rendering_CanvasEGL_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasEGLInternals;
|
||||
}
|
||||
|
||||
class VTKM_RENDERING_EXPORT CanvasEGL : public CanvasGL
|
||||
{
|
||||
public:
|
||||
CanvasEGL(vtkm::Id width = 1024, vtkm::Id height = 1024);
|
||||
|
||||
~CanvasEGL();
|
||||
|
||||
virtual void Initialize() override;
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
vtkm::rendering::Canvas* NewCopy() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<detail::CanvasEGLInternals> Internals;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_CanvasEGL_h
|
@ -1,353 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
|
||||
#include <vtkm/rendering/BitmapFontFactory.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/DecodePNG.h>
|
||||
#include <vtkm/rendering/MatrixHelpers.h>
|
||||
#include <vtkm/rendering/WorldAnnotatorGL.h>
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
#include <vtkm/cont/ColorTable.hxx>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
CanvasGL::CanvasGL(vtkm::Id width, vtkm::Id height)
|
||||
: Canvas(width, height)
|
||||
{
|
||||
}
|
||||
|
||||
CanvasGL::~CanvasGL()
|
||||
{
|
||||
}
|
||||
|
||||
void CanvasGL::Initialize()
|
||||
{
|
||||
// Nothing to initialize
|
||||
}
|
||||
|
||||
void CanvasGL::Activate()
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
this->ResizeBuffers(viewport[2], viewport[3]);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void CanvasGL::Clear()
|
||||
{
|
||||
vtkm::rendering::Color backgroundColor = this->GetBackgroundColor();
|
||||
glClearColor(backgroundColor.Components[0],
|
||||
backgroundColor.Components[1],
|
||||
backgroundColor.Components[2],
|
||||
1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void CanvasGL::Finish()
|
||||
{
|
||||
glFinish();
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* CanvasGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasGL(*this);
|
||||
}
|
||||
|
||||
void CanvasGL::SetViewToWorldSpace(const vtkm::rendering::Camera& camera, bool clip)
|
||||
{
|
||||
vtkm::Float32 oglP[16], oglM[16];
|
||||
|
||||
MatrixHelpers::CreateOGLMatrix(camera.CreateProjectionMatrix(this->GetWidth(), this->GetHeight()),
|
||||
oglP);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(oglP);
|
||||
MatrixHelpers::CreateOGLMatrix(camera.CreateViewMatrix(), oglM);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(oglM);
|
||||
|
||||
this->SetViewportClipping(camera, clip);
|
||||
}
|
||||
|
||||
void CanvasGL::SetViewToScreenSpace(const vtkm::rendering::Camera& camera, bool clip)
|
||||
{
|
||||
vtkm::Float32 oglP[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
vtkm::Float32 oglM[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
oglP[0 * 4 + 0] = 1.;
|
||||
oglP[1 * 4 + 1] = 1.;
|
||||
oglP[2 * 4 + 2] = -1.;
|
||||
oglP[3 * 4 + 3] = 1.;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(oglP);
|
||||
|
||||
oglM[0 * 4 + 0] = 1.;
|
||||
oglM[1 * 4 + 1] = 1.;
|
||||
oglM[2 * 4 + 2] = 1.;
|
||||
oglM[3 * 4 + 3] = 1.;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(oglM);
|
||||
|
||||
this->SetViewportClipping(camera, clip);
|
||||
}
|
||||
|
||||
void CanvasGL::SetViewportClipping(const vtkm::rendering::Camera& camera, bool clip)
|
||||
{
|
||||
if (clip)
|
||||
{
|
||||
vtkm::Float32 vl, vr, vb, vt;
|
||||
camera.GetRealViewport(this->GetWidth(), this->GetHeight(), vl, vr, vb, vt);
|
||||
vtkm::Float32 _x = static_cast<vtkm::Float32>(this->GetWidth()) * (1.f + vl) / 2.f;
|
||||
vtkm::Float32 _y = static_cast<vtkm::Float32>(this->GetHeight()) * (1.f + vb) / 2.f;
|
||||
vtkm::Float32 _w = static_cast<vtkm::Float32>(this->GetWidth()) * (vr - vl) / 2.f;
|
||||
vtkm::Float32 _h = static_cast<vtkm::Float32>(this->GetHeight()) * (vt - vb) / 2.f;
|
||||
|
||||
glViewport(static_cast<GLint>(_x),
|
||||
static_cast<GLint>(_y),
|
||||
static_cast<GLsizei>(_w),
|
||||
static_cast<GLsizei>(_h));
|
||||
}
|
||||
else
|
||||
{
|
||||
glViewport(
|
||||
0, 0, static_cast<GLsizei>(this->GetWidth()), static_cast<GLsizei>(this->GetHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasGL::RefreshColorBuffer() const
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
VTKM_ASSERT(viewport[2] == this->GetWidth());
|
||||
VTKM_ASSERT(viewport[3] == this->GetHeight());
|
||||
|
||||
glReadPixels(viewport[0],
|
||||
viewport[1],
|
||||
viewport[2],
|
||||
viewport[3],
|
||||
GL_RGBA,
|
||||
GL_FLOAT,
|
||||
const_cast<vtkm::Vec<float, 4>*>(this->GetColorBuffer().GetStorage().GetArray()));
|
||||
}
|
||||
|
||||
void CanvasGL::RefreshDepthBuffer() const
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
VTKM_ASSERT(viewport[2] == this->GetWidth());
|
||||
VTKM_ASSERT(viewport[3] == this->GetHeight());
|
||||
|
||||
glReadPixels(viewport[0],
|
||||
viewport[1],
|
||||
viewport[2],
|
||||
viewport[3],
|
||||
GL_DEPTH_COMPONENT,
|
||||
GL_FLOAT,
|
||||
const_cast<vtkm::Float32*>(this->GetDepthBuffer().GetStorage().GetArray()));
|
||||
}
|
||||
|
||||
void CanvasGL::AddColorSwatch(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
const vtkm::Vec2f_64& point2,
|
||||
const vtkm::Vec2f_64& point3,
|
||||
const vtkm::rendering::Color& color) const
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(float(point0[0]), float(point0[1]), .99f);
|
||||
glVertex3f(float(point1[0]), float(point1[1]), .99f);
|
||||
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(float(point2[0]), float(point2[1]), .99f);
|
||||
glVertex3f(float(point3[0]), float(point3[1]), .99f);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CanvasGL::AddLine(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
const vtkm::rendering::Color& color) const
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
|
||||
glLineWidth(linewidth);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(float(point0[0]), float(point0[1]));
|
||||
glVertex2f(float(point1[0]), float(point1[1]));
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CanvasGL::AddColorBar(const vtkm::Bounds& bounds,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
bool horizontal) const
|
||||
{
|
||||
const int n = 256;
|
||||
//map through the color table for our 256 + 1 points as the first step
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
colorTable.Sample(n + 1, colors);
|
||||
|
||||
vtkm::Float32 startX = static_cast<vtkm::Float32>(bounds.X.Min);
|
||||
vtkm::Float32 startY = static_cast<vtkm::Float32>(bounds.Y.Min);
|
||||
vtkm::Float32 width = static_cast<vtkm::Float32>(bounds.X.Length());
|
||||
vtkm::Float32 height = static_cast<vtkm::Float32>(bounds.Y.Length());
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
auto colorPortal = colors.ReadPortal();
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
vtkm::Float32 v0 = static_cast<vtkm::Float32>(i) / static_cast<vtkm::Float32>(n);
|
||||
vtkm::Float32 v1 = static_cast<vtkm::Float32>(i + 1) / static_cast<vtkm::Float32>(n);
|
||||
auto c0 = colorPortal.Get(i);
|
||||
auto c1 = colorPortal.Get(i + 1);
|
||||
if (horizontal)
|
||||
{
|
||||
vtkm::Float32 x0 = startX + width * v0;
|
||||
vtkm::Float32 x1 = startX + width * v1;
|
||||
vtkm::Float32 y0 = startY;
|
||||
vtkm::Float32 y1 = startY + height;
|
||||
glColor3ub(c0[0], c0[1], c0[2]);
|
||||
glVertex2f(x0, y0);
|
||||
glVertex2f(x0, y1);
|
||||
glColor3ub(c1[0], c1[1], c1[2]);
|
||||
glVertex2f(x1, y1);
|
||||
glVertex2f(x1, y0);
|
||||
}
|
||||
else // vertical
|
||||
{
|
||||
vtkm::Float32 x0 = startX;
|
||||
vtkm::Float32 x1 = startX + width;
|
||||
vtkm::Float32 y0 = startY + height * v0;
|
||||
vtkm::Float32 y1 = startY + height * v1;
|
||||
glColor3ub(c0[0], c0[1], c0[2]);
|
||||
glVertex2f(x0, y1);
|
||||
glVertex2f(x1, y1);
|
||||
glColor3ub(c1[0], c1[1], c1[2]);
|
||||
glVertex2f(x1, y0);
|
||||
glVertex2f(x0, y0);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CanvasGL::AddText(const vtkm::Vec2f_32& position,
|
||||
vtkm::Float32 scale,
|
||||
vtkm::Float32 angle,
|
||||
vtkm::Float32 windowAspect,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(position[0], position[1], 0);
|
||||
glScalef(1.f / windowAspect, 1, 1);
|
||||
glRotatef(angle, 0, 0, 1);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
this->RenderText(scale, anchor, text);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
vtkm::rendering::WorldAnnotator* CanvasGL::CreateWorldAnnotator() const
|
||||
{
|
||||
return new vtkm::rendering::WorldAnnotatorGL(this);
|
||||
}
|
||||
|
||||
void CanvasGL::RenderText(vtkm::Float32 scale,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const std::string& text) const
|
||||
{
|
||||
if (!this->FontTexture.Valid())
|
||||
{
|
||||
// When we load a font, we save a reference to it for the next time we
|
||||
// use it. Although technically we are changing the state, the logical
|
||||
// state does not change, so we go ahead and do it in this const
|
||||
// function.
|
||||
vtkm::rendering::CanvasGL* self = const_cast<vtkm::rendering::CanvasGL*>(this);
|
||||
self->Font = BitmapFontFactory::CreateLiberation2Sans();
|
||||
const std::vector<unsigned char>& rawpngdata = this->Font.GetRawImageData();
|
||||
|
||||
std::vector<unsigned char> rgba;
|
||||
unsigned long width, height;
|
||||
int error = vtkm::rendering::DecodePNG(rgba, width, height, &rawpngdata[0], rawpngdata.size());
|
||||
if (error != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->FontTexture.CreateAlphaFromRGBA(int(width), int(height), rgba);
|
||||
}
|
||||
|
||||
this->FontTexture.Enable();
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glDisable(GL_LIGHTING);
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -.5);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
vtkm::Float32 textwidth = this->Font.GetTextWidth(text);
|
||||
|
||||
vtkm::Float32 fx = -(.5f + .5f * anchor[0]) * textwidth;
|
||||
vtkm::Float32 fy = -(.5f + .5f * anchor[1]);
|
||||
vtkm::Float32 fz = 0;
|
||||
for (unsigned int i = 0; i < text.length(); ++i)
|
||||
{
|
||||
char c = text[i];
|
||||
char nextchar = (i < text.length() - 1) ? text[i + 1] : 0;
|
||||
|
||||
vtkm::Float32 vl, vr, vt, vb;
|
||||
vtkm::Float32 tl, tr, tt, tb;
|
||||
this->Font.GetCharPolygon(c, fx, fy, vl, vr, vt, vb, tl, tr, tt, tb, nextchar);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tt);
|
||||
glVertex3f(scale * vl, scale * vt, fz);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tb);
|
||||
glVertex3f(scale * vl, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tb);
|
||||
glVertex3f(scale * vr, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tt);
|
||||
glVertex3f(scale * vr, scale * vt, fz);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
this->FontTexture.Disable();
|
||||
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,86 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_CanvasGL_h
|
||||
#define vtk_m_rendering_CanvasGL_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/BitmapFont.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/TextureGL.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT CanvasGL : public Canvas
|
||||
{
|
||||
public:
|
||||
CanvasGL(vtkm::Id width = 1024, vtkm::Id height = 1024);
|
||||
|
||||
~CanvasGL();
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Activate() override;
|
||||
|
||||
void Clear() override;
|
||||
|
||||
void Finish() override;
|
||||
|
||||
vtkm::rendering::Canvas* NewCopy() const override;
|
||||
|
||||
void SetViewToWorldSpace(const vtkm::rendering::Camera& camera, bool clip) override;
|
||||
|
||||
void SetViewToScreenSpace(const vtkm::rendering::Camera& camera, bool clip) override;
|
||||
|
||||
void SetViewportClipping(const vtkm::rendering::Camera& camera, bool clip) override;
|
||||
|
||||
void RefreshColorBuffer() const override;
|
||||
|
||||
virtual void RefreshDepthBuffer() const override;
|
||||
|
||||
vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const override;
|
||||
|
||||
protected:
|
||||
void AddLine(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
const vtkm::rendering::Color& color) const override;
|
||||
|
||||
void AddColorBar(const vtkm::Bounds& bounds,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
bool horizontal) const override;
|
||||
|
||||
void AddColorSwatch(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
const vtkm::Vec2f_64& point2,
|
||||
const vtkm::Vec2f_64& point3,
|
||||
const vtkm::rendering::Color& color) const override;
|
||||
|
||||
void AddText(const vtkm::Vec2f_32& position,
|
||||
vtkm::Float32 scale,
|
||||
vtkm::Float32 angle,
|
||||
vtkm::Float32 windowAspect,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const override;
|
||||
|
||||
private:
|
||||
vtkm::rendering::BitmapFont Font;
|
||||
vtkm::rendering::TextureGL FontTexture;
|
||||
|
||||
void RenderText(vtkm::Float32 scale, const vtkm::Vec2f_32& anchor, const std::string& text) const;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_CanvasGL_h
|
@ -1,120 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/CanvasOSMesa.h>
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
#ifndef GLAPI
|
||||
#define GLAPI extern
|
||||
#endif
|
||||
|
||||
#ifndef GLAPIENTRY
|
||||
#define GLAPIENTRY
|
||||
#endif
|
||||
|
||||
#ifndef APIENTRY
|
||||
#define APIENTRY GLAPIENTRY
|
||||
#endif
|
||||
#include <GL/osmesa.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasOSMesaInternals
|
||||
{
|
||||
OSMesaContext Context;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
CanvasOSMesa::CanvasOSMesa(vtkm::Id width, vtkm::Id height)
|
||||
: CanvasGL(width, height)
|
||||
, Internals(new detail::CanvasOSMesaInternals)
|
||||
{
|
||||
this->Internals->Context = nullptr;
|
||||
this->ResizeBuffers(width, height);
|
||||
}
|
||||
|
||||
CanvasOSMesa::~CanvasOSMesa()
|
||||
{
|
||||
}
|
||||
|
||||
void CanvasOSMesa::Initialize()
|
||||
{
|
||||
this->Internals->Context = OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, nullptr);
|
||||
|
||||
if (!this->Internals->Context)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("OSMesa context creation failed.");
|
||||
}
|
||||
vtkm::Vec4f_32* colorBuffer = this->GetColorBuffer().GetStorage().GetArray();
|
||||
if (!OSMesaMakeCurrent(this->Internals->Context,
|
||||
reinterpret_cast<vtkm::Float32*>(colorBuffer),
|
||||
GL_FLOAT,
|
||||
static_cast<GLsizei>(this->GetWidth()),
|
||||
static_cast<GLsizei>(this->GetHeight())))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("OSMesa context activation failed.");
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasOSMesa::RefreshColorBuffer() const
|
||||
{
|
||||
// Override superclass because our OSMesa implementation renders right
|
||||
// to the color buffer.
|
||||
}
|
||||
|
||||
void CanvasOSMesa::Activate()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void CanvasOSMesa::Finish()
|
||||
{
|
||||
this->CanvasGL::Finish();
|
||||
|
||||
// This is disabled because it is handled in RefreshDepthBuffer
|
||||
#if 0
|
||||
//Copy zbuff into floating point array.
|
||||
unsigned int *raw_zbuff;
|
||||
int zbytes, w, h;
|
||||
GLboolean ret;
|
||||
ret = OSMesaGetDepthBuffer(this->Internals->Context, &w, &h, &zbytes, (void**)&raw_zbuff);
|
||||
if (!ret ||
|
||||
static_cast<vtkm::Id>(w)!=this->GetWidth() ||
|
||||
static_cast<vtkm::Id>(h)!=this->GetHeight())
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Wrong width/height in ZBuffer");
|
||||
}
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32>::WritePortalType depthPortal =
|
||||
this->GetDepthBuffer().WritePortal();
|
||||
vtkm::Id npixels = this->GetWidth()*this->GetHeight();
|
||||
for (vtkm::Id i=0; i<npixels; i++)
|
||||
for (std::size_t i=0; i<npixels; i++)
|
||||
{
|
||||
depthPortal.Set(i, float(raw_zbuff[i]) / float(UINT_MAX));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* CanvasOSMesa::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasOSMesa(*this);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,54 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_CanvasOSMesa_h
|
||||
#define vtk_m_rendering_CanvasOSMesa_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasOSMesaInternals;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
class VTKM_RENDERING_EXPORT CanvasOSMesa : public CanvasGL
|
||||
{
|
||||
public:
|
||||
CanvasOSMesa(vtkm::Id width = 1024, vtkm::Id height = 1024);
|
||||
|
||||
~CanvasOSMesa();
|
||||
|
||||
virtual void Initialize() override;
|
||||
|
||||
virtual void RefreshColorBuffer() const override;
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
virtual void Finish() override;
|
||||
|
||||
vtkm::rendering::Canvas* NewCopy() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<detail::CanvasOSMesaInternals> Internals;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_CanvasOSMesa_h
|
@ -9,29 +9,26 @@
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_DecodePNG_h
|
||||
#define vtk_m_rendering_DecodePNG_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/io/DecodePNG.h>
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
/// Decodes a PNG file buffer in memory, into a raw pixel buffer
|
||||
/// Output is RGBA 32-bit (8 bit per channel) color format
|
||||
/// no matter what color type the original PNG image had. This gives predictable,
|
||||
/// usable data from any random input PNG.
|
||||
///
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::UInt32 DecodePNG(std::vector<unsigned char>& out_image,
|
||||
unsigned long& image_width,
|
||||
unsigned long& image_height,
|
||||
const unsigned char* in_png,
|
||||
std::size_t in_size);
|
||||
std::size_t in_size) VTKM_DEPRECATED(1.6, "Please use vtkm::io::DecodePNG")
|
||||
{
|
||||
return vtkm::io::DecodePNG(out_image, image_width, image_height, in_png, in_size);
|
||||
}
|
||||
}
|
||||
} // vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_DecodePNG_h
|
||||
|
||||
#endif
|
||||
|
@ -10,11 +10,9 @@
|
||||
#ifndef vtk_m_rendering_EncodePNG_h
|
||||
#define vtk_m_rendering_EncodePNG_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/io/EncodePNG.h>
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
@ -25,13 +23,19 @@ vtkm::UInt32 EncodePNG(std::vector<unsigned char> const& image,
|
||||
unsigned long width,
|
||||
unsigned long height,
|
||||
unsigned char* out_png,
|
||||
std::size_t out_size);
|
||||
std::size_t out_size) VTKM_DEPRECATED(1.6, "Please use vtkm::io::EncodePNG.")
|
||||
{
|
||||
return io::EncodePNG(image, width, height, out_png, out_size);
|
||||
}
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
VTKM_IO_EXPORT
|
||||
vtkm::UInt32 SavePNG(std::string const& filename,
|
||||
std::vector<unsigned char> const& image,
|
||||
unsigned long width,
|
||||
unsigned long height);
|
||||
unsigned long height) VTKM_DEPRECATED("Please use SavePNG from vtkm::io")
|
||||
{
|
||||
return io::SavePNG(filename, image, width, height);
|
||||
}
|
||||
}
|
||||
} // vtkm::rendering
|
||||
|
||||
|
@ -1,534 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/TryExecute.h>
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
#include <vtkm/rendering/internal/RunTriangulator.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/exec/ColorTable.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using Id4Type = TypeListId4;
|
||||
|
||||
class MapColorAndVertices : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
const vtkm::exec::ColorTableBase* ColorTable;
|
||||
const vtkm::Float32 SMin, SDiff;
|
||||
|
||||
VTKM_CONT
|
||||
MapColorAndVertices(const vtkm::exec::ColorTableBase* table,
|
||||
vtkm::Float32 sMin,
|
||||
vtkm::Float32 sDiff)
|
||||
: ColorTable(table)
|
||||
, SMin(sMin)
|
||||
, SDiff(sDiff)
|
||||
{
|
||||
}
|
||||
using ControlSignature = void(FieldIn vertexId,
|
||||
WholeArrayIn indices,
|
||||
WholeArrayIn scalar,
|
||||
WholeArrayIn verts,
|
||||
WholeArrayOut out_color,
|
||||
WholeArrayOut out_vertices);
|
||||
using ExecutionSignature = void(_1, _2, _3, _4, _5, _6);
|
||||
|
||||
template <typename InputArrayIndexPortalType,
|
||||
typename InputArrayPortalType,
|
||||
typename InputArrayV3PortalType,
|
||||
typename OutputArrayPortalType>
|
||||
VTKM_EXEC void operator()(const vtkm::Id& i,
|
||||
InputArrayIndexPortalType& indices,
|
||||
const InputArrayPortalType& scalar,
|
||||
const InputArrayV3PortalType& verts,
|
||||
OutputArrayPortalType& c_array,
|
||||
OutputArrayPortalType& v_array) const
|
||||
{
|
||||
vtkm::Id4 idx = indices.Get(i);
|
||||
vtkm::Id i1 = idx[1];
|
||||
vtkm::Id i2 = idx[2];
|
||||
vtkm::Id i3 = idx[3];
|
||||
|
||||
vtkm::Vec3f_32 p1 = verts.Get(idx[1]);
|
||||
vtkm::Vec3f_32 p2 = verts.Get(idx[2]);
|
||||
vtkm::Vec3f_32 p3 = verts.Get(idx[3]);
|
||||
|
||||
vtkm::Float32 s;
|
||||
vtkm::Vec<float, 3> color1;
|
||||
vtkm::Vec<float, 3> color2;
|
||||
vtkm::Vec<float, 3> color3;
|
||||
|
||||
if (SDiff == 0)
|
||||
{
|
||||
s = 0;
|
||||
color1 = ColorTable->MapThroughColorSpace(s);
|
||||
color2 = ColorTable->MapThroughColorSpace(s);
|
||||
color3 = ColorTable->MapThroughColorSpace(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
s = scalar.Get(i1);
|
||||
s = (s - SMin) / SDiff;
|
||||
color1 = ColorTable->MapThroughColorSpace(s);
|
||||
|
||||
s = scalar.Get(i2);
|
||||
s = (s - SMin) / SDiff;
|
||||
color2 = ColorTable->MapThroughColorSpace(s);
|
||||
|
||||
s = scalar.Get(i3);
|
||||
s = (s - SMin) / SDiff;
|
||||
color3 = ColorTable->MapThroughColorSpace(s);
|
||||
}
|
||||
|
||||
const vtkm::Id offset = 9;
|
||||
|
||||
v_array.Set(i * offset, p1[0]);
|
||||
v_array.Set(i * offset + 1, p1[1]);
|
||||
v_array.Set(i * offset + 2, p1[2]);
|
||||
c_array.Set(i * offset, color1[0]);
|
||||
c_array.Set(i * offset + 1, color1[1]);
|
||||
c_array.Set(i * offset + 2, color1[2]);
|
||||
|
||||
v_array.Set(i * offset + 3, p2[0]);
|
||||
v_array.Set(i * offset + 4, p2[1]);
|
||||
v_array.Set(i * offset + 5, p2[2]);
|
||||
c_array.Set(i * offset + 3, color2[0]);
|
||||
c_array.Set(i * offset + 4, color2[1]);
|
||||
c_array.Set(i * offset + 5, color2[2]);
|
||||
|
||||
v_array.Set(i * offset + 6, p3[0]);
|
||||
v_array.Set(i * offset + 7, p3[1]);
|
||||
v_array.Set(i * offset + 8, p3[2]);
|
||||
c_array.Set(i * offset + 6, color3[0]);
|
||||
c_array.Set(i * offset + 7, color3[1]);
|
||||
c_array.Set(i * offset + 8, color3[2]);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PtType>
|
||||
struct MapColorAndVerticesInvokeFunctor
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id4> TriangleIndices;
|
||||
vtkm::cont::ColorTable ColorTable;
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32> Scalar;
|
||||
const vtkm::Range ScalarRange;
|
||||
const PtType Vertices;
|
||||
vtkm::Float32 SMin;
|
||||
vtkm::Float32 SDiff;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> OutColor;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> OutVertices;
|
||||
|
||||
VTKM_CONT
|
||||
MapColorAndVerticesInvokeFunctor(const vtkm::cont::ArrayHandle<vtkm::Id4>& indices,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
const vtkm::cont::ArrayHandle<Float32>& scalar,
|
||||
const vtkm::Range& scalarRange,
|
||||
const PtType& vertices,
|
||||
vtkm::Float32 s_min,
|
||||
vtkm::Float32 s_max,
|
||||
vtkm::cont::ArrayHandle<Float32>& out_color,
|
||||
vtkm::cont::ArrayHandle<Float32>& out_vertices)
|
||||
: TriangleIndices(indices)
|
||||
, ColorTable(colorTable)
|
||||
, Scalar(scalar)
|
||||
, ScalarRange(scalarRange)
|
||||
, Vertices(vertices)
|
||||
, SMin(s_min)
|
||||
, SDiff(s_max - s_min)
|
||||
, OutColor(out_color)
|
||||
, OutVertices(out_vertices)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Device>
|
||||
VTKM_CONT bool operator()(Device device) const
|
||||
{
|
||||
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||
|
||||
vtkm::cont::Token token;
|
||||
MapColorAndVertices worklet(
|
||||
this->ColorTable.PrepareForExecution(device, token), this->SMin, this->SDiff);
|
||||
vtkm::worklet::DispatcherMapField<MapColorAndVertices> dispatcher(worklet);
|
||||
dispatcher.SetDevice(Device{});
|
||||
|
||||
vtkm::cont::ArrayHandleIndex indexArray(this->TriangleIndices.GetNumberOfValues());
|
||||
dispatcher.Invoke(indexArray,
|
||||
this->TriangleIndices,
|
||||
this->Scalar,
|
||||
this->Vertices,
|
||||
this->OutColor,
|
||||
this->OutVertices);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderStructuredLineSegments(vtkm::Id numVerts,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
vtkm::cont::ColorTable ct,
|
||||
bool logY)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(1);
|
||||
vtkm::UInt8 r, g, b, a;
|
||||
|
||||
//This is horrible as the color table API isn't designed for users to query
|
||||
//on a single value basis. We use the GetPoint and GetPointAlpha escape hatches
|
||||
//and manually convert from float to uchar
|
||||
vtkm::Vec<double, 4> data;
|
||||
ct.GetPoint(0, data);
|
||||
r = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
g = static_cast<vtkm::UInt8>(data[2] * 255.0 + 0.5);
|
||||
b = static_cast<vtkm::UInt8>(data[3] * 255.0 + 0.5);
|
||||
ct.GetPointAlpha(0, data);
|
||||
a = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
|
||||
glColor4ub(r, g, b, a);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (int i = 0; i < numVerts; i++)
|
||||
{
|
||||
vtkm::Vec3f_32 pt = verts.ReadPortal().Get(i);
|
||||
vtkm::Float32 s = scalar.ReadPortal().Get(i);
|
||||
if (logY)
|
||||
s = vtkm::Float32(log10(s));
|
||||
glVertex3f(pt[0], s, 0.0f);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderExplicitLineSegments(vtkm::Id numVerts,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
vtkm::cont::ColorTable ct,
|
||||
bool logY)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(1);
|
||||
vtkm::UInt8 r, g, b, a;
|
||||
//This is horrible as the color table API isn't designed for users to query
|
||||
//on a single value basis. We use the GetPoint and GetPointAlpha escape hatches
|
||||
//and manually convert from float to uchar
|
||||
vtkm::Vec<double, 4> data;
|
||||
ct.GetPoint(0, data);
|
||||
r = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
g = static_cast<vtkm::UInt8>(data[2] * 255.0 + 0.5);
|
||||
b = static_cast<vtkm::UInt8>(data[3] * 255.0 + 0.5);
|
||||
ct.GetPointAlpha(0, data);
|
||||
a = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
|
||||
glColor4ub(r, g, b, a);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (int i = 0; i < numVerts; i++)
|
||||
{
|
||||
vtkm::Vec3f_32 pt = verts.ReadPortal().Get(i);
|
||||
vtkm::Float32 s = scalar.ReadPortal().Get(i);
|
||||
if (logY)
|
||||
s = vtkm::Float32(log10(s));
|
||||
glVertex3f(pt[0], s, 0.0f);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderTriangles(MapperGL& mapper,
|
||||
vtkm::Id numTri,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id4>& indices,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
const vtkm::cont::ColorTable& ct,
|
||||
const vtkm::Range& scalarRange,
|
||||
const vtkm::rendering::Camera& camera)
|
||||
{
|
||||
if (!mapper.loaded)
|
||||
{
|
||||
// The glewExperimental global switch can be turned on by setting it to
|
||||
// GL_TRUE before calling glewInit(), which ensures that all extensions
|
||||
// with valid entry points will be exposed. This is needed as the glut
|
||||
// context that is being created is not a valid 'core' context but
|
||||
// instead a 'compatibility' context
|
||||
//
|
||||
glewExperimental = GL_TRUE;
|
||||
GLenum GlewInitResult = glewInit();
|
||||
if (GlewInitResult)
|
||||
std::cerr << "ERROR: " << glewGetErrorString(GlewInitResult) << std::endl;
|
||||
mapper.loaded = true;
|
||||
|
||||
vtkm::Float32 sMin = vtkm::Float32(scalarRange.Min);
|
||||
vtkm::Float32 sMax = vtkm::Float32(scalarRange.Max);
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> out_vertices, out_color;
|
||||
out_vertices.Allocate(9 * indices.GetNumberOfValues());
|
||||
out_color.Allocate(9 * indices.GetNumberOfValues());
|
||||
|
||||
vtkm::cont::TryExecute(MapColorAndVerticesInvokeFunctor<PtType>(
|
||||
indices, ct, scalar, scalarRange, verts, sMin, sMax, out_color, out_vertices));
|
||||
|
||||
|
||||
vtkm::Id vtx_cnt = out_vertices.GetNumberOfValues();
|
||||
vtkm::Float32* v_ptr = out_vertices.GetStorage().GetArray();
|
||||
vtkm::Float32* c_ptr = out_color.GetStorage().GetArray();
|
||||
|
||||
vtkm::Id floatSz = static_cast<vtkm::Id>(sizeof(vtkm::Float32));
|
||||
GLsizeiptr sz = static_cast<GLsizeiptr>(vtx_cnt * floatSz);
|
||||
|
||||
GLuint points_vbo = 0;
|
||||
glGenBuffers(1, &points_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sz, v_ptr, GL_STATIC_DRAW);
|
||||
|
||||
GLuint colours_vbo = 0;
|
||||
glGenBuffers(1, &colours_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, colours_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sz, c_ptr, GL_STATIC_DRAW);
|
||||
|
||||
mapper.vao = 0;
|
||||
glGenVertexArrays(1, &mapper.vao);
|
||||
glBindVertexArray(mapper.vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, colours_vbo);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
const char* vertex_shader = "#version 120\n"
|
||||
"attribute vec3 vertex_position;"
|
||||
"attribute vec3 vertex_color;"
|
||||
"varying vec3 ourColor;"
|
||||
"uniform mat4 mv_matrix;"
|
||||
"uniform mat4 p_matrix;"
|
||||
|
||||
"void main() {"
|
||||
" gl_Position = p_matrix*mv_matrix * vec4(vertex_position, 1.0);"
|
||||
" ourColor = vertex_color;"
|
||||
"}";
|
||||
const char* fragment_shader = "#version 120\n"
|
||||
"varying vec3 ourColor;"
|
||||
"void main() {"
|
||||
" gl_FragColor = vec4 (ourColor, 1.0);"
|
||||
"}";
|
||||
|
||||
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vs, 1, &vertex_shader, nullptr);
|
||||
glCompileShader(vs);
|
||||
GLint isCompiled = 0;
|
||||
glGetShaderiv(vs, GL_COMPILE_STATUS, &isCompiled);
|
||||
if (isCompiled == GL_FALSE)
|
||||
{
|
||||
GLint maxLength = 0;
|
||||
glGetShaderiv(vs, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
std::string msg;
|
||||
if (maxLength <= 0)
|
||||
msg = "No error message";
|
||||
else
|
||||
{
|
||||
// The maxLength includes the nullptr character
|
||||
GLchar* strInfoLog = new GLchar[maxLength + 1];
|
||||
glGetShaderInfoLog(vs, maxLength, &maxLength, strInfoLog);
|
||||
msg = std::string(strInfoLog);
|
||||
delete[] strInfoLog;
|
||||
}
|
||||
throw vtkm::cont::ErrorBadValue("Shader compile error:" + msg);
|
||||
}
|
||||
|
||||
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fs, 1, &fragment_shader, nullptr);
|
||||
glCompileShader(fs);
|
||||
glGetShaderiv(fs, GL_COMPILE_STATUS, &isCompiled);
|
||||
if (isCompiled == GL_FALSE)
|
||||
{
|
||||
GLint maxLength = 0;
|
||||
glGetShaderiv(fs, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
std::string msg;
|
||||
if (maxLength <= 0)
|
||||
msg = "No error message";
|
||||
else
|
||||
{
|
||||
// The maxLength includes the nullptr character
|
||||
GLchar* strInfoLog = new GLchar[maxLength + 1];
|
||||
glGetShaderInfoLog(vs, maxLength, &maxLength, strInfoLog);
|
||||
msg = std::string(strInfoLog);
|
||||
delete[] strInfoLog;
|
||||
}
|
||||
throw vtkm::cont::ErrorBadValue("Shader compile error:" + msg);
|
||||
}
|
||||
|
||||
mapper.shader_programme = glCreateProgram();
|
||||
if (mapper.shader_programme > 0)
|
||||
{
|
||||
glAttachShader(mapper.shader_programme, fs);
|
||||
glAttachShader(mapper.shader_programme, vs);
|
||||
glBindAttribLocation(mapper.shader_programme, 0, "vertex_position");
|
||||
glBindAttribLocation(mapper.shader_programme, 1, "vertex_color");
|
||||
|
||||
glLinkProgram(mapper.shader_programme);
|
||||
GLint linkStatus;
|
||||
glGetProgramiv(mapper.shader_programme, GL_LINK_STATUS, &linkStatus);
|
||||
if (!linkStatus)
|
||||
{
|
||||
char log[2048];
|
||||
GLsizei len;
|
||||
glGetProgramInfoLog(mapper.shader_programme, 2048, &len, log);
|
||||
std::string msg = std::string("Shader program link failed: ") + std::string(log);
|
||||
throw vtkm::cont::ErrorBadValue(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mapper.shader_programme > 0)
|
||||
{
|
||||
vtkm::Id width = mapper.GetCanvas()->GetWidth();
|
||||
vtkm::Id height = mapper.GetCanvas()->GetWidth();
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> viewM = camera.CreateViewMatrix();
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> projM = camera.CreateProjectionMatrix(width, height);
|
||||
|
||||
MatrixHelpers::CreateOGLMatrix(viewM, mapper.mvMat);
|
||||
MatrixHelpers::CreateOGLMatrix(projM, mapper.pMat);
|
||||
|
||||
glUseProgram(mapper.shader_programme);
|
||||
GLint mvID = glGetUniformLocation(mapper.shader_programme, "mv_matrix");
|
||||
glUniformMatrix4fv(mvID, 1, GL_FALSE, mapper.mvMat);
|
||||
GLint pID = glGetUniformLocation(mapper.shader_programme, "p_matrix");
|
||||
glUniformMatrix4fv(pID, 1, GL_FALSE, mapper.pMat);
|
||||
glBindVertexArray(mapper.vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(numTri * 3));
|
||||
glUseProgram(0);
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
MapperGL::MapperGL()
|
||||
: Canvas(nullptr)
|
||||
, loaded(false)
|
||||
{
|
||||
}
|
||||
|
||||
MapperGL::~MapperGL()
|
||||
{
|
||||
}
|
||||
|
||||
void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
|
||||
const vtkm::cont::CoordinateSystem& coords,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
const vtkm::rendering::Camera& camera,
|
||||
const vtkm::Range& scalarRange)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> sf;
|
||||
sf = scalarField.GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
||||
auto dcoords = coords.GetData();
|
||||
vtkm::Id numVerts = coords.GetNumberOfPoints();
|
||||
|
||||
//Handle 1D cases.
|
||||
if (cellset.IsSameType(vtkm::cont::CellSetStructured<1>()))
|
||||
{
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates verts;
|
||||
verts = dcoords.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
RenderStructuredLineSegments(numVerts, verts, sf, colorTable, this->LogarithmY);
|
||||
}
|
||||
else if (cellset.IsSameType(vtkm::cont::CellSetSingleType<>()) &&
|
||||
cellset.Cast<vtkm::cont::CellSetSingleType<>>().GetCellShapeAsId() ==
|
||||
vtkm::CELL_SHAPE_LINE)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> verts;
|
||||
verts = dcoords.Cast<vtkm::cont::ArrayHandle<vtkm::Vec3f_32>>();
|
||||
RenderExplicitLineSegments(numVerts, verts, sf, colorTable, this->LogarithmY);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id4> indices;
|
||||
vtkm::Id numTri;
|
||||
vtkm::rendering::internal::RunTriangulator(cellset, indices, numTri);
|
||||
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates uVerts;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> eVerts;
|
||||
|
||||
if (dcoords.IsType<vtkm::cont::ArrayHandleUniformPointCoordinates>())
|
||||
{
|
||||
uVerts = dcoords.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
RenderTriangles(*this, numTri, uVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
else if (dcoords.IsType<vtkm::cont::ArrayHandle<vtkm::Vec3f_32>>())
|
||||
{
|
||||
eVerts = dcoords.Cast<vtkm::cont::ArrayHandle<vtkm::Vec3f_32>>();
|
||||
RenderTriangles(*this, numTri, eVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
else if (dcoords.IsType<vtkm::cont::ArrayHandleCartesianProduct<
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>())
|
||||
{
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>
|
||||
rVerts;
|
||||
rVerts = dcoords.Cast<
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>();
|
||||
RenderTriangles(*this, numTri, rVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
}
|
||||
glFinish();
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void MapperGL::StartScene()
|
||||
{
|
||||
// Nothing needs to be done.
|
||||
}
|
||||
|
||||
void MapperGL::EndScene()
|
||||
{
|
||||
// Nothing needs to be done.
|
||||
}
|
||||
|
||||
void MapperGL::SetCanvas(vtkm::rendering::Canvas* c)
|
||||
{
|
||||
if (c != nullptr)
|
||||
{
|
||||
this->Canvas = dynamic_cast<vtkm::rendering::CanvasGL*>(c);
|
||||
if (this->Canvas == nullptr)
|
||||
throw vtkm::cont::ErrorBadValue("Bad canvas type for MapperGL. Must be CanvasGL");
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* MapperGL::GetCanvas() const
|
||||
{
|
||||
return this->Canvas;
|
||||
}
|
||||
|
||||
vtkm::rendering::Mapper* MapperGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::MapperGL(*this);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,56 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_MapperGL_h
|
||||
#define vtk_m_rendering_MapperGL_h
|
||||
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/cont/CoordinateSystem.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT MapperGL : public Mapper
|
||||
{
|
||||
public:
|
||||
MapperGL();
|
||||
|
||||
~MapperGL();
|
||||
|
||||
void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
|
||||
const vtkm::cont::CoordinateSystem& coords,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
const vtkm::rendering::Camera&,
|
||||
const vtkm::Range& scalarRange) override;
|
||||
|
||||
void StartScene() override;
|
||||
void EndScene() override;
|
||||
void SetCanvas(vtkm::rendering::Canvas* canvas) override;
|
||||
virtual vtkm::rendering::Canvas* GetCanvas() const override;
|
||||
|
||||
vtkm::rendering::Mapper* NewCopy() const override;
|
||||
|
||||
vtkm::rendering::CanvasGL* Canvas;
|
||||
GLuint shader_programme;
|
||||
GLfloat mvMat[16], pMat[16];
|
||||
bool loaded;
|
||||
GLuint vao;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_MapperGL_h
|
@ -1,176 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/TextureGL.h>
|
||||
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
struct TextureGL::InternalsType
|
||||
{
|
||||
GLuint Id;
|
||||
int Dimension;
|
||||
bool MIPMap;
|
||||
bool Linear2D;
|
||||
bool LinearMIP;
|
||||
|
||||
VTKM_CONT
|
||||
InternalsType()
|
||||
: Id(0)
|
||||
, Dimension(0)
|
||||
, MIPMap(false)
|
||||
, Linear2D(true)
|
||||
, LinearMIP(true)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
~InternalsType()
|
||||
{
|
||||
if (this->Id != 0)
|
||||
{
|
||||
glDeleteTextures(1, &this->Id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TextureGL::TextureGL()
|
||||
: Internals(new InternalsType)
|
||||
{
|
||||
}
|
||||
|
||||
TextureGL::~TextureGL()
|
||||
{
|
||||
}
|
||||
|
||||
bool TextureGL::Valid() const
|
||||
{
|
||||
return (this->Internals->Id != 0);
|
||||
}
|
||||
|
||||
void TextureGL::Enable() const
|
||||
{
|
||||
if (!this->Valid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->Internals->Dimension == 1)
|
||||
{
|
||||
// no this->Internals->MIPMapping for 1D (at the moment)
|
||||
glBindTexture(GL_TEXTURE_1D, this->Internals->Id);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
if (this->Internals->Linear2D)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
glEnable(GL_TEXTURE_1D);
|
||||
}
|
||||
else if (this->Internals->Dimension == 2)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->Internals->Id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
if (this->Internals->Linear2D)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
if (!this->Internals->MIPMap)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
else if (this->Internals->LinearMIP)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
if (!this->Internals->MIPMap)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
else if (this->Internals->LinearMIP)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
}
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fail silently for invalid dimension.
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGL::Disable() const
|
||||
{
|
||||
if (this->Internals->Dimension == 1)
|
||||
{
|
||||
glDisable(GL_TEXTURE_1D);
|
||||
}
|
||||
else if (this->Internals->Dimension == 2)
|
||||
{
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fail silently for invalid dimension
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGL::CreateAlphaFromRGBA(vtkm::Id width,
|
||||
vtkm::Id height,
|
||||
const std::vector<unsigned char>& rgba)
|
||||
{
|
||||
this->Internals->Dimension = 2;
|
||||
std::vector<unsigned char> alpha(rgba.size() / 4);
|
||||
VTKM_ASSERT(width * height == static_cast<vtkm::Id>(alpha.size()));
|
||||
for (std::size_t i = 0; i < alpha.size(); i++)
|
||||
{
|
||||
alpha[i] = rgba[i * 4 + 3];
|
||||
}
|
||||
|
||||
if (this->Internals->Id == 0)
|
||||
{
|
||||
glGenTextures(1, &this->Internals->Id);
|
||||
}
|
||||
|
||||
if (this->Internals->Dimension == 1)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_1D, this->Internals->Id);
|
||||
}
|
||||
else if (this->Internals->Dimension == 2)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->Internals->Id);
|
||||
//#define HW_MIPMAPS
|
||||
#ifdef HW_MIPMAPS
|
||||
mpimap = true;
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
||||
#endif
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_ALPHA,
|
||||
static_cast<GLsizei>(width),
|
||||
static_cast<GLsizei>(height),
|
||||
0,
|
||||
GL_ALPHA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
(void*)(&(alpha[0])));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,47 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_TextureGL_h
|
||||
#define vtk_m_TextureGL_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT TextureGL
|
||||
{
|
||||
public:
|
||||
TextureGL();
|
||||
|
||||
~TextureGL();
|
||||
|
||||
bool Valid() const;
|
||||
|
||||
void Enable() const;
|
||||
|
||||
void Disable() const;
|
||||
|
||||
void CreateAlphaFromRGBA(vtkm::Id width, vtkm::Id height, const std::vector<unsigned char>& rgba);
|
||||
|
||||
private:
|
||||
struct InternalsType;
|
||||
std::shared_ptr<InternalsType> Internals;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_TextureGL_h
|
@ -1,163 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/WorldAnnotatorGL.h>
|
||||
|
||||
#include <vtkm/Matrix.h>
|
||||
#include <vtkm/rendering/BitmapFontFactory.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/DecodePNG.h>
|
||||
#include <vtkm/rendering/MatrixHelpers.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
WorldAnnotatorGL::WorldAnnotatorGL(const vtkm::rendering::Canvas* canvas)
|
||||
: WorldAnnotator(canvas)
|
||||
{
|
||||
}
|
||||
|
||||
WorldAnnotatorGL::~WorldAnnotatorGL()
|
||||
{
|
||||
}
|
||||
|
||||
void WorldAnnotatorGL::AddLine(const vtkm::Vec3f_64& point0,
|
||||
const vtkm::Vec3f_64& point1,
|
||||
vtkm::Float32 lineWidth,
|
||||
const vtkm::rendering::Color& color,
|
||||
bool inFront) const
|
||||
{
|
||||
if (inFront)
|
||||
{
|
||||
glDepthRange(-.0001, .9999);
|
||||
}
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
|
||||
glLineWidth(lineWidth);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3d(point0[0], point0[1], point0[2]);
|
||||
glVertex3d(point1[0], point1[1], point1[2]);
|
||||
glEnd();
|
||||
|
||||
if (inFront)
|
||||
{
|
||||
glDepthRange(0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void WorldAnnotatorGL::AddText(const vtkm::Vec3f_32& origin,
|
||||
const vtkm::Vec3f_32& right,
|
||||
const vtkm::Vec3f_32& up,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text,
|
||||
const vtkm::Float32 vtkmNotUsed(depth)) const
|
||||
{
|
||||
|
||||
vtkm::Vec3f_32 n = vtkm::Cross(right, up);
|
||||
vtkm::Normalize(n);
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> m;
|
||||
m = MatrixHelpers::WorldMatrix(origin, right, up, n);
|
||||
|
||||
vtkm::Float32 ogl[16];
|
||||
MatrixHelpers::CreateOGLMatrix(m, ogl);
|
||||
glPushMatrix();
|
||||
glMultMatrixf(ogl);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
this->RenderText(scale, anchor[0], anchor[1], text);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void WorldAnnotatorGL::RenderText(vtkm::Float32 scale,
|
||||
vtkm::Float32 anchorx,
|
||||
vtkm::Float32 anchory,
|
||||
std::string text) const
|
||||
{
|
||||
if (!this->FontTexture.Valid())
|
||||
{
|
||||
// When we load a font, we save a reference to it for the next time we
|
||||
// use it. Although technically we are changing the state, the logical
|
||||
// state does not change, so we go ahead and do it in this const
|
||||
// function.
|
||||
vtkm::rendering::WorldAnnotatorGL* self = const_cast<vtkm::rendering::WorldAnnotatorGL*>(this);
|
||||
self->Font = BitmapFontFactory::CreateLiberation2Sans();
|
||||
const std::vector<unsigned char>& rawpngdata = this->Font.GetRawImageData();
|
||||
|
||||
std::vector<unsigned char> rgba;
|
||||
unsigned long width, height;
|
||||
int error = vtkm::rendering::DecodePNG(rgba, width, height, &rawpngdata[0], rawpngdata.size());
|
||||
if (error != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->FontTexture.CreateAlphaFromRGBA(int(width), int(height), rgba);
|
||||
}
|
||||
|
||||
this->FontTexture.Enable();
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glDisable(GL_LIGHTING);
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -.5);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
vtkm::Float32 textwidth = this->Font.GetTextWidth(text);
|
||||
|
||||
vtkm::Float32 fx = -(.5f + .5f * anchorx) * textwidth;
|
||||
vtkm::Float32 fy = -(.5f + .5f * anchory);
|
||||
vtkm::Float32 fz = 0;
|
||||
for (unsigned int i = 0; i < text.length(); ++i)
|
||||
{
|
||||
char c = text[i];
|
||||
char nextchar = (i < text.length() - 1) ? text[i + 1] : 0;
|
||||
|
||||
vtkm::Float32 vl, vr, vt, vb;
|
||||
vtkm::Float32 tl, tr, tt, tb;
|
||||
this->Font.GetCharPolygon(c, fx, fy, vl, vr, vt, vb, tl, tr, tt, tb, nextchar);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tt);
|
||||
glVertex3f(scale * vl, scale * vt, fz);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tb);
|
||||
glVertex3f(scale * vl, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tb);
|
||||
glVertex3f(scale * vr, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tt);
|
||||
glVertex3f(scale * vr, scale * vt, fz);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
this->FontTexture.Disable();
|
||||
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,58 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_WorldAnnotatorGL_h
|
||||
#define vtk_m_rendering_WorldAnnotatorGL_h
|
||||
|
||||
#include <vtkm/rendering/WorldAnnotator.h>
|
||||
|
||||
#include <vtkm/rendering/BitmapFont.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/TextureGL.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT WorldAnnotatorGL : public WorldAnnotator
|
||||
{
|
||||
public:
|
||||
WorldAnnotatorGL(const vtkm::rendering::Canvas* canvas);
|
||||
|
||||
~WorldAnnotatorGL();
|
||||
|
||||
void AddLine(const vtkm::Vec3f_64& point0,
|
||||
const vtkm::Vec3f_64& point1,
|
||||
vtkm::Float32 lineWidth,
|
||||
const vtkm::rendering::Color& color,
|
||||
bool inFront) const override;
|
||||
|
||||
void AddText(const vtkm::Vec3f_32& origin,
|
||||
const vtkm::Vec3f_32& right,
|
||||
const vtkm::Vec3f_32& up,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text,
|
||||
const vtkm::Float32 depth = 0.f) const override;
|
||||
|
||||
private:
|
||||
BitmapFont Font;
|
||||
TextureGL FontTexture;
|
||||
|
||||
void RenderText(vtkm::Float32 scale,
|
||||
vtkm::Float32 anchorx,
|
||||
vtkm::Float32 anchory,
|
||||
std::string text) const;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif // vtk_m_rendering_WorldAnnotatorGL_h
|
@ -28,14 +28,3 @@ set(unit_tests
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} ALL_BACKENDS LIBRARIES vtkm_rendering)
|
||||
|
||||
if(VTKm_ENABLE_GL_CONTEXT)
|
||||
# message(STATUS "rendering testing/glfw needs a FindGLFW")
|
||||
# message(STATUS "rendering testing/glut needs compile corrections")
|
||||
# add_subdirectory(glfw)
|
||||
# add_subdirectory(glut)
|
||||
elseif(VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
add_subdirectory(osmesa)
|
||||
elseif(VTKm_ENABLE_EGL_CONTEXT)
|
||||
add_subdirectory(egl)
|
||||
endif()
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
@ -38,7 +38,7 @@ void RenderTests()
|
||||
vtkm::cont::DataSet rectDS, unsDS;
|
||||
std::string basePath = vtkm::cont::testing::Testing::GetTestDataBasePath();
|
||||
std::string rectfname = basePath + "/rectilinear/noise.vtk";
|
||||
vtkm::io::reader::VTKDataSetReader rectReader(rectfname);
|
||||
vtkm::io::VTKDataSetReader rectReader(rectfname);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
#include <vtkm/rendering/ScalarRenderer.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
@ -31,7 +31,7 @@ void RenderTests()
|
||||
vtkm::rendering::ScalarRenderer::Result res = renderer.Render(camera);
|
||||
|
||||
vtkm::cont::DataSet result = res.ToDataSet();
|
||||
vtkm::io::writer::VTKDataSetWriter writer("scalar.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("scalar.vtk");
|
||||
writer.WriteDataSet(result);
|
||||
}
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperEGL.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering)
|
@ -1,103 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasEGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View1D.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
using M = vtkm::rendering::MapperGL;
|
||||
using C = vtkm::rendering::CanvasEGL;
|
||||
using V3 = vtkm::rendering::View3D;
|
||||
using V2 = vtkm::rendering::View2D;
|
||||
using V1 = vtkm::rendering::View1D;
|
||||
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V2>(
|
||||
maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DUniformDataSet0(), "pointvar", vtkm::rendering::Color::white, "uniform1D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DExplicitDataSet0(), "pointvar", vtkm::rendering::Color::white, "expl1D.pnm");
|
||||
|
||||
vtkm::cont::DataSet ds = maker.Make1DUniformDataSet0();
|
||||
vtkm::Int32 nVerts = ds.GetField(0).GetNumberOfValues();
|
||||
vtkm::Float32 vars[nVerts];
|
||||
vtkm::Float32 smallVal = 1.000;
|
||||
for (vtkm::Int32 i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = smallVal;
|
||||
smallVal += .01;
|
||||
}
|
||||
dsf.AddPointField(ds, "smallScaledYAxis", vars, nVerts);
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
ds, "smallScaledYAxis", vtkm::rendering::Color::white, "uniform1DSmallScaledYAxis.pnm");
|
||||
|
||||
// Test to demonstrate that straight horizontal lines can be drawn
|
||||
ds = maker.Make1DUniformDataSet0();
|
||||
nVerts = ds.GetField(0).GetNumberOfValues();
|
||||
vtkm::Float32 largeVal = 1e-16;
|
||||
for (vtkm::Int32 i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = largeVal;
|
||||
}
|
||||
dsf.AddPointField(ds, "straightLine", vars, nVerts);
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
ds, "straightLine", vtkm::rendering::Color::white, "uniform1DStraightLine.pnm");
|
||||
|
||||
|
||||
ds = maker.Make1DUniformDataSet0();
|
||||
nVerts = ds.GetField(0).GetNumberOfValues();
|
||||
largeVal = 1;
|
||||
for (vtkm::Int32 i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = largeVal;
|
||||
if (i < 2)
|
||||
{
|
||||
largeVal *= 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
largeVal /= 2.25;
|
||||
}
|
||||
}
|
||||
dsf.AddPointField(ds, "logScaledYAxis", vars, nVerts);
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
ds, "logScaledYAxis", vtkm::rendering::Color::white, "uniform1DLogScaledYAxis.pnm", true);
|
||||
}
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperEGL(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests, argc, argv);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
find_package(GLFW QUIET)
|
||||
if(NOT TARGET GLFW::GLFW)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperGLFW.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests}
|
||||
TEST_ARGS -B
|
||||
LIBRARIES vtkm_rendering GLFW::GLFW)
|
||||
|
@ -1,188 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View1D.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
// this needs to be included after the vtk-m headers so that we include
|
||||
// the gl headers in the correct order
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr vtkm::Id WIDTH = 512, HEIGHT = 512;
|
||||
static vtkm::Id which = 0, NUM_DATASETS = 5;
|
||||
static bool done = false;
|
||||
static bool batch = false;
|
||||
|
||||
static void keyCallback(GLFWwindow* vtkmNotUsed(window),
|
||||
int key,
|
||||
int vtkmNotUsed(scancode),
|
||||
int action,
|
||||
int vtkmNotUsed(mods))
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
done = true;
|
||||
if (action == 1)
|
||||
which = (which + 1) % NUM_DATASETS;
|
||||
}
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
std::cout << "Press any key to cycle through datasets. ESC to quit." << std::endl;
|
||||
|
||||
using MapperType = vtkm::rendering::MapperGL;
|
||||
using CanvasType = vtkm::rendering::CanvasGL;
|
||||
using View3DType = vtkm::rendering::View3D;
|
||||
using View2DType = vtkm::rendering::View2D;
|
||||
using View1DType = vtkm::rendering::View1D;
|
||||
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
glfwInit();
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "GLFW Test", nullptr, nullptr);
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetKeyCallback(window, keyCallback);
|
||||
|
||||
CanvasType canvas[5] = { CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512) };
|
||||
vtkm::rendering::Scene scene[5];
|
||||
vtkm::cont::DataSet ds[5];
|
||||
MapperType mapper[5];
|
||||
vtkm::rendering::Camera camera[5];
|
||||
|
||||
ds[0] = maker.Make3DRegularDataSet0();
|
||||
ds[1] = maker.Make3DRectilinearDataSet0();
|
||||
ds[2] = maker.Make3DExplicitDataSet4();
|
||||
ds[3] = maker.Make2DRectilinearDataSet0();
|
||||
//create 1D uniform DS with tiny Y axis
|
||||
vtkm::cont::DataSet tinyDS = maker.Make1DUniformDataSet0();
|
||||
const std::size_t nVerts = static_cast<std::size_t>(tinyDS.GetField(0).GetNumberOfValues());
|
||||
std::vector<vtkm::Float32> vars(nVerts);
|
||||
float smallVal = 1.000;
|
||||
for (std::size_t i = 0; i < nVerts; i++)
|
||||
{
|
||||
vars[i] = smallVal;
|
||||
smallVal += .01f;
|
||||
}
|
||||
dsf.AddPointField(tinyDS, "smallScaledXAxis", vars);
|
||||
ds[4] = tinyDS;
|
||||
tinyDS.PrintSummary(std::cerr);
|
||||
|
||||
std::string fldNames[5];
|
||||
fldNames[0] = "pointvar";
|
||||
fldNames[1] = "pointvar";
|
||||
fldNames[2] = "pointvar";
|
||||
fldNames[3] = "pointvar";
|
||||
fldNames[4] = "smallScaledXAxis";
|
||||
|
||||
for (int i = 0; i < NUM_DATASETS; i++)
|
||||
{
|
||||
if (i < 3)
|
||||
{
|
||||
scene[i].AddActor(vtkm::rendering::Actor(ds[i].GetCellSet(),
|
||||
ds[i].GetCoordinateSystem(),
|
||||
ds[i].GetField(fldNames[i].c_str()),
|
||||
colorTable));
|
||||
vtkm::rendering::testing::SetCamera<View3DType>(camera[i],
|
||||
ds[i].GetCoordinateSystem().GetBounds());
|
||||
}
|
||||
else if (i == 3)
|
||||
{
|
||||
scene[i].AddActor(vtkm::rendering::Actor(ds[i].GetCellSet(),
|
||||
ds[i].GetCoordinateSystem(),
|
||||
ds[i].GetField(fldNames[i].c_str()),
|
||||
colorTable));
|
||||
vtkm::rendering::testing::SetCamera<View2DType>(camera[i],
|
||||
ds[i].GetCoordinateSystem().GetBounds());
|
||||
}
|
||||
else
|
||||
{
|
||||
scene[i].AddActor(vtkm::rendering::Actor(ds[i].GetCellSet(),
|
||||
ds[i].GetCoordinateSystem(),
|
||||
ds[i].GetField(fldNames[i].c_str()),
|
||||
vtkm::rendering::Color::white));
|
||||
vtkm::rendering::testing::SetCamera<View1DType>(
|
||||
camera[i], ds[i].GetCoordinateSystem().GetBounds(), ds[i].GetField(fldNames[i].c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
View3DType view3d0(
|
||||
scene[0], mapper[0], canvas[0], camera[0], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View3DType view3d1(
|
||||
scene[1], mapper[1], canvas[1], camera[1], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View3DType view3d2(
|
||||
scene[2], mapper[2], canvas[2], camera[2], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View2DType view2d0(
|
||||
scene[3], mapper[3], canvas[3], camera[3], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View1DType view1d0(
|
||||
scene[4], mapper[4], canvas[4], camera[4], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
|
||||
while (!glfwWindowShouldClose(window) && !done)
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
if (which == 0)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View3DType>(view3d0, "reg3D.pnm");
|
||||
else if (which == 1)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View3DType>(view3d1, "rect3D.pnm");
|
||||
else if (which == 2)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View3DType>(view3d2, "expl3D.pnm");
|
||||
else if (which == 3)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View2DType>(view2d0, "rect2D.pnm");
|
||||
else if (which == 4)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View1DType>(
|
||||
view1d0, "uniform1DSmallScaledXAxis.pnm");
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
if (batch)
|
||||
{
|
||||
which++;
|
||||
if (which >= NUM_DATASETS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
}
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperGLFW(int argc, char* argv[])
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1], "-B") == 0)
|
||||
{
|
||||
batch = true;
|
||||
}
|
||||
}
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
if(NOT TARGET GLUT::GLUT)
|
||||
find_package(GLUT QUIET)
|
||||
|
||||
if(NOT TARGET GLUT::GLUT)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperGLUT.cxx
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests}
|
||||
TEST_ARGS -B
|
||||
LIBRARIES vtkm_rendering GLUT::GLUT)
|
||||
|
@ -1,113 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#if defined(__APPLE__)
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr vtkm::Id WIDTH = 512, HEIGHT = 512;
|
||||
static vtkm::Id windowID, which = 0, NUM_DATASETS = 4;
|
||||
static bool done = false;
|
||||
static bool batch = false;
|
||||
|
||||
static void keyboardCall(unsigned char key, int vtkmNotUsed(x), int vtkmNotUsed(y))
|
||||
{
|
||||
if (key == 27)
|
||||
glutDestroyWindow(windowID);
|
||||
else
|
||||
{
|
||||
which = (which + 1) % NUM_DATASETS;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
|
||||
static void displayCall()
|
||||
{
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
using M = vtkm::rendering::MapperGL;
|
||||
using C = vtkm::rendering::CanvasGL;
|
||||
using V3 = vtkm::rendering::View3D;
|
||||
using V2 = vtkm::rendering::View2D;
|
||||
|
||||
if (which == 0)
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm");
|
||||
else if (which == 1)
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm");
|
||||
else if (which == 2)
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm");
|
||||
else if (which == 3)
|
||||
vtkm::rendering::testing::Render<M, C, V2>(
|
||||
maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm");
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void batchIdle()
|
||||
{
|
||||
which++;
|
||||
if (which >= NUM_DATASETS)
|
||||
glutDestroyWindow(windowID);
|
||||
else
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
if (!batch)
|
||||
std::cout << "Press any key to cycle through datasets. ESC to quit." << std::endl;
|
||||
|
||||
int argc = 0;
|
||||
char* argv = nullptr;
|
||||
glutInit(&argc, &argv);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(WIDTH, HEIGHT);
|
||||
windowID = glutCreateWindow("GLUT test");
|
||||
glutDisplayFunc(displayCall);
|
||||
glutKeyboardFunc(keyboardCall);
|
||||
if (batch)
|
||||
glutIdleFunc(batchIdle);
|
||||
|
||||
glutMainLoop();
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperGLUT(int argc, char* argv[])
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1], "-B") == 0)
|
||||
{
|
||||
batch = true;
|
||||
}
|
||||
}
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperOSMesa.cxx
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering)
|
||||
|
@ -1,56 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasOSMesa.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
using M = vtkm::rendering::MapperGL;
|
||||
using C = vtkm::rendering::CanvasOSMesa;
|
||||
using V3 = vtkm::rendering::View3D;
|
||||
using V2 = vtkm::rendering::View2D;
|
||||
using V1 = vtkm::rendering::View1D;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V2>(
|
||||
maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DUniformDataSet0(), "pointvar", vtkm::rendering::Color(1, 1, 1, 1), "uniform1D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DExplicitDataSet0(), "pointvar", vtkm::rendering::Color(1, 1, 1, 1), "expl1D.pnm");
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperOSMesa(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests, argc, argv);
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/exec/CellInterpolate.h>
|
||||
#include <vtkm/exec/ParametricCoordinates.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/worklet/ExternalFaces.h>
|
||||
|
||||
@ -115,9 +114,6 @@ void TestExternalFaces2()
|
||||
vtkm::cont::testing::MakeTestDataSet dataSetMaker;
|
||||
vtkm::cont::DataSet inDataSet = dataSetMaker.Make3DExplicitDataSet5();
|
||||
|
||||
// vtkm::io::writer::VTKDataSetWriter writer("vtkm_explicit_data_5.vtk");
|
||||
// writer.WriteDataSet(inDataSet);
|
||||
|
||||
// Expected faces
|
||||
const vtkm::IdComponent MAX_POINTS_PER_FACE = 4;
|
||||
const vtkm::Id NUM_FACES = 12;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/StreamSurface.h>
|
||||
|
||||
@ -62,13 +62,6 @@ void TestSameNumPolylines()
|
||||
"Wrong number of points in StreamSurface worklet");
|
||||
VTKM_TEST_ASSERT(newCells.GetNumberOfCells() == 12,
|
||||
"Wrong number of cells in StreamSurface worklet");
|
||||
/*
|
||||
vtkm::cont::DataSet ds2;
|
||||
ds2.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coords", newPoints));
|
||||
ds2.SetCellSet(newCells);
|
||||
vtkm::io::writer::VTKDataSetWriter writer("srf.vtk");
|
||||
writer.WriteDataSet(ds2);
|
||||
*/
|
||||
}
|
||||
|
||||
void TestUnequalNumPolylines(int unequalType)
|
||||
@ -129,14 +122,6 @@ void TestUnequalNumPolylines(int unequalType)
|
||||
"Wrong number of points in StreamSurface worklet");
|
||||
VTKM_TEST_ASSERT(newCells.GetNumberOfCells() == numRequiredCells,
|
||||
"Wrong number of cells in StreamSurface worklet");
|
||||
|
||||
/*
|
||||
vtkm::cont::DataSet ds2;
|
||||
ds2.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coords", newPoints));
|
||||
ds2.SetCellSet(newCells);
|
||||
vtkm::io::writer::VTKDataSetWriter writer("srf.vtk");
|
||||
writer.WriteDataSet(ds2);
|
||||
*/
|
||||
}
|
||||
|
||||
void TestStreamSurface()
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include <vtkm/worklet/particleadvection/Particles.h>
|
||||
#include <vtkm/worklet/particleadvection/TemporalGridEvaluators.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
template <typename ScalarType>
|
||||
vtkm::cont::DataSet CreateUniformDataSet(const vtkm::Bounds& bounds, const vtkm::Id3& dims)
|
||||
{
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/Tube.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user