mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge remote-tracking branch 'upstream/master' into StreamingArray
This commit is contained in:
commit
72d9783c38
@ -241,7 +241,7 @@ macro(vtkm_configure_component_Rendering)
|
||||
|
||||
vtkm_finish_configure_component(Rendering
|
||||
DEPENDENT_VARIABLES VTKm_ENABLE_RENDERING VTKm_Base_FOUND
|
||||
ADD_LIBRARIES vtkm_rendering
|
||||
ADD_LIBRARIES vtkm_rendering ${GLEW_LIBRARIES}
|
||||
)
|
||||
endmacro(vtkm_configure_component_Rendering)
|
||||
|
||||
|
@ -284,7 +284,10 @@ install(FILES ${VTKm_SOURCE_DIR}/LICENSE.txt
|
||||
install(
|
||||
FILES
|
||||
${VTKm_SOURCE_DIR}/CMake/FindBoostHeaders.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/FindEGL.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/FindGLEW.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/FindGLFW.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/FindMESA.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/FindTBB.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/FindThrust.cmake
|
||||
DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
|
||||
@ -296,7 +299,7 @@ install(
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmMacros.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmConfigureComponents.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmCompilerOptimizations.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmDetectCUDAVersion.cxx
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmDetectCUDAVersion.cu
|
||||
DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
|
||||
)
|
||||
|
||||
|
@ -34,6 +34,8 @@
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h> //Required for compile....
|
||||
|
||||
#if defined (__APPLE__)
|
||||
# include <GLUT/glut.h>
|
||||
#else
|
||||
|
@ -194,8 +194,9 @@ public:
|
||||
|
||||
template<typename T, typename U>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::Vec<T,3>& vec, U& result) const
|
||||
void operator()(const vtkm::Vec<T,3>& , U& ) const
|
||||
{
|
||||
this->RaiseError("Mixed types unsupported.");
|
||||
}
|
||||
};
|
||||
|
||||
@ -256,13 +257,14 @@ public:
|
||||
|
||||
template <typename WeightType, typename T, typename S, typename D, typename U>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::Id2& low_high,
|
||||
const WeightType &weight,
|
||||
const vtkm::exec::ExecutionWholeArrayConst<T,S,D>& inPortal,
|
||||
U &result) const
|
||||
void operator()(const vtkm::Id2& ,
|
||||
const WeightType &,
|
||||
const vtkm::exec::ExecutionWholeArrayConst<T,S,D>& ,
|
||||
U &) const
|
||||
{
|
||||
//the inPortal and result need to be the same type so this version only
|
||||
//exists to generate code when using dynamic arrays
|
||||
this->RaiseError("Mixed types unsupported.");
|
||||
}
|
||||
};
|
||||
|
||||
@ -732,4 +734,4 @@ int main(int argc, char *argv[])
|
||||
//now actually execute the benchmarks
|
||||
return vtkm::benchmarking::BenchmarkFieldAlgorithms
|
||||
<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Run(benchmarks);
|
||||
}
|
||||
}
|
||||
|
@ -65,40 +65,48 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
DataSetBuilderRectilinear() {}
|
||||
|
||||
//2D grids.
|
||||
//1D grids.
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
vtkm::cont::DataSet
|
||||
Create(vtkm::Id nx, vtkm::Id ny,
|
||||
T *xvals, T *yvals,
|
||||
Create(const std::vector<T> &xvals,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
T zvals = 0;
|
||||
return DataSetBuilderRectilinear::Create(
|
||||
2, nx,ny, 1, xvals, yvals, &zvals, coordNm, cellNm);
|
||||
std::vector<T> yvals(1,0), zvals(1,0);
|
||||
return DataSetBuilderRectilinear::BuildDataSet(
|
||||
1, xvals,yvals,zvals, coordNm,cellNm);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
vtkm::cont::DataSet
|
||||
Create(int dim, vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
|
||||
T *xvals, T *yvals, T *zvals,
|
||||
std::string coordNm, std::string cellNm)
|
||||
Create(vtkm::Id nx, T *xvals,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
VTKM_ASSERT(nx>1 && ny>1 &&
|
||||
((dim==2 && nz==1)||(dim==3 && nz>=1)));
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
|
||||
DataSetBuilderRectilinear::CopyInto(xvals,nx,Xc);
|
||||
DataSetBuilderRectilinear::CopyInto(yvals,ny,Yc);
|
||||
DataSetBuilderRectilinear::CopyInto(zvals,nz,Zc);
|
||||
|
||||
T yvals = 0, zvals = 0;
|
||||
return DataSetBuilderRectilinear::BuildDataSet(
|
||||
dim, Xc,Yc,Zc, coordNm, cellNm);
|
||||
1, nx,1, 1, xvals, &yvals, &zvals, coordNm, cellNm);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
vtkm::cont::DataSet
|
||||
Create(const vtkm::cont::ArrayHandle<T> &xvals,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> yvals, zvals;
|
||||
yvals.Allocate(1);
|
||||
yvals.GetPortalControl().Set(0,0.0);
|
||||
zvals.Allocate(1);
|
||||
zvals.GetPortalControl().Set(0,0.0);
|
||||
return DataSetBuilderRectilinear::BuildDataSet(
|
||||
1, xvals,yvals,zvals, coordNm, cellNm);
|
||||
}
|
||||
|
||||
//2D grids.
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
@ -111,6 +119,19 @@ public:
|
||||
2, xvals,yvals,zvals, coordNm,cellNm);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
vtkm::cont::DataSet
|
||||
Create(vtkm::Id nx, vtkm::Id ny,
|
||||
T *xvals, T *yvals,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
T zvals = 0;
|
||||
return DataSetBuilderRectilinear::BuildDataSet(
|
||||
2, nx,ny, 1, xvals, yvals, &zvals, coordNm, cellNm);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
@ -119,8 +140,6 @@ public:
|
||||
const vtkm::cont::ArrayHandle<T> &yvals,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
VTKM_ASSERT(xvals.GetNumberOfValues()>1 && yvals.GetNumberOfValues()>1);
|
||||
|
||||
vtkm::cont::ArrayHandle<T> zvals;
|
||||
zvals.Allocate(1);
|
||||
zvals.GetPortalControl().Set(0,0.0);
|
||||
@ -137,7 +156,7 @@ public:
|
||||
T *xvals, T *yvals, T *zvals,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
return DataSetBuilderRectilinear::Create(
|
||||
return DataSetBuilderRectilinear::BuildDataSet(
|
||||
3, nx,ny,nz, xvals, yvals, zvals, coordNm, cellNm);
|
||||
}
|
||||
|
||||
@ -163,9 +182,6 @@ public:
|
||||
const vtkm::cont::ArrayHandle<T> &zvals,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
VTKM_ASSERT(xvals.GetNumberOfValues()>1 &&
|
||||
yvals.GetNumberOfValues()>1 &&
|
||||
zvals.GetNumberOfValues()>1);
|
||||
return DataSetBuilderRectilinear::BuildDataSet(
|
||||
3, xvals,yvals,zvals, coordNm, cellNm);
|
||||
}
|
||||
@ -181,8 +197,9 @@ private:
|
||||
const std::vector<T> &zvals,
|
||||
std::string coordNm, std::string cellNm)
|
||||
{
|
||||
VTKM_ASSERT(xvals.size()>1 && yvals.size()>1 &&
|
||||
((dim==2 && zvals.size()==1)||(dim==3 && zvals.size()>=1)));
|
||||
VTKM_ASSERT((dim==1 && xvals.size()>1 && yvals.size()==1 && zvals.size()==1) ||
|
||||
(dim==2 && xvals.size()>1 && yvals.size()>1 && zvals.size()==1) ||
|
||||
(dim==3 && xvals.size()>1 && yvals.size()>1 && zvals.size()>1));
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
|
||||
DataSetBuilderRectilinear::CopyInto(xvals, Xc);
|
||||
@ -193,6 +210,27 @@ private:
|
||||
dim, Xc,Yc,Zc, coordNm, cellNm);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
vtkm::cont::DataSet
|
||||
BuildDataSet(int dim, vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
|
||||
const T *xvals, const T *yvals, const T *zvals,
|
||||
std::string coordNm, std::string cellNm)
|
||||
{
|
||||
VTKM_ASSERT((dim==1 && nx>1 && ny==1 && nz==1) ||
|
||||
(dim==2 && nx>1 && ny>1 && nz==1) ||
|
||||
(dim==3 && nx>1 && ny>1 && nz>1));
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
|
||||
DataSetBuilderRectilinear::CopyInto(xvals, nx, Xc);
|
||||
DataSetBuilderRectilinear::CopyInto(yvals, ny, Yc);
|
||||
DataSetBuilderRectilinear::CopyInto(zvals, nz, Zc);
|
||||
|
||||
return DataSetBuilderRectilinear::BuildDataSet(
|
||||
dim, Xc,Yc,Zc, coordNm, cellNm);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
@ -220,14 +258,20 @@ private:
|
||||
vtkm::cont::CoordinateSystem cs(coordNm, coords);
|
||||
dataSet.AddCoordinateSystem(cs);
|
||||
|
||||
if (dim == 2)
|
||||
if (dim == 1)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<1> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(Xc.GetNumberOfValues());
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else if (dim == 2)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<2> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(Xc.GetNumberOfValues(),
|
||||
Yc.GetNumberOfValues()));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else
|
||||
else if (dim == 3)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<3> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(Xc.GetNumberOfValues(),
|
||||
@ -235,6 +279,8 @@ private:
|
||||
Zc.GetNumberOfValues()));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else
|
||||
throw vtkm::cont::ErrorControlBadValue("Invalid cell set dimension");
|
||||
|
||||
return dataSet;
|
||||
}
|
||||
|
@ -32,6 +32,24 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
DataSetBuilderUniform() {}
|
||||
|
||||
//1D uniform grid
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
vtkm::cont::DataSet
|
||||
Create(const vtkm::Id &dimension,
|
||||
const vtkm::FloatDefault &origin = 0.0f,
|
||||
const vtkm::FloatDefault &spacing = 1.0f,
|
||||
std::string coordNm="coords", std::string cellNm="cells")
|
||||
{
|
||||
vtkm::Vec<vtkm::FloatDefault,3> origin3d(origin, 0.0f, 0.0f);
|
||||
vtkm::Vec<vtkm::FloatDefault,3> spacing3d(spacing, 1.0f, 1.0f);
|
||||
return DataSetBuilderUniform::CreateDS(1,
|
||||
dimension,1,1,
|
||||
origin3d,
|
||||
spacing3d,
|
||||
coordNm, cellNm);
|
||||
}
|
||||
|
||||
//2D uniform grids.
|
||||
VTKM_CONT_EXPORT
|
||||
static
|
||||
@ -76,32 +94,38 @@ private:
|
||||
const vtkm::Vec<vtkm::FloatDefault,3> &spacing,
|
||||
std::string coordNm, std::string cellNm)
|
||||
{
|
||||
VTKM_ASSERT(nx>1 && ny>1 && ((dim==2 && nz==1)||(dim==3 && nz>=1)));
|
||||
VTKM_ASSERT((dim==1 && nx>1 && ny==1 && nz==1) ||
|
||||
(dim==2 && nx>1 && ny>1 && nz==1) ||
|
||||
(dim==3 && nx>1 && ny>1 && nz>1));
|
||||
VTKM_ASSERT(spacing[0]>0 && spacing[1]>0 && spacing[2]>0);
|
||||
|
||||
vtkm::cont::DataSet dataSet;
|
||||
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates
|
||||
coords(vtkm::Id3(nx, ny, nz),
|
||||
origin,
|
||||
spacing
|
||||
);
|
||||
|
||||
|
||||
origin, spacing);
|
||||
vtkm::cont::CoordinateSystem cs(coordNm, coords);
|
||||
dataSet.AddCoordinateSystem(cs);
|
||||
|
||||
if (dim == 2)
|
||||
if (dim == 1)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<1> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(nx);
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else if (dim == 2)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<2> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(nx,ny));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else
|
||||
else if (dim == 3)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<3> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(nx,ny,nz));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else
|
||||
throw vtkm::cont::ErrorControlBadValue("Invalid cell set dimension");
|
||||
|
||||
return dataSet;
|
||||
}
|
||||
|
@ -39,8 +39,15 @@ VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
// define NOMINMAX to fix that problem. We also include WIN32_LEAN_AND_MEAN
|
||||
// to reduce the number of macros and objects windows.h imports as those also
|
||||
// can cause conflicts
|
||||
// TBB's header include a #pragma comment(lib,"tbb.lib") line to make all
|
||||
// consuming
|
||||
|
||||
#pragma push_macro("WIN32_LEAN_AND_MEAN")
|
||||
#pragma push_macro("NOMINMAX")
|
||||
#pragma push_macro("__TBB_NO_IMPLICITLINKAGE")
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#define __TBB_NO_IMPLICIT_LINKAGE
|
||||
#endif
|
||||
|
||||
#include <tbb/tbb_stddef.h>
|
||||
@ -62,8 +69,9 @@ VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
|
||||
#if defined(VTKM_MSVC)
|
||||
#include <Windows.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
#undef NOMINMAX
|
||||
#pragma pop_macro("WIN32_LEAN_AND_MEAN")
|
||||
#pragma pop_macro("NOMINMAX")
|
||||
#pragma pop_macro("__TBB_NO_IMPLICITLINKAGE")
|
||||
#endif
|
||||
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
@ -35,6 +35,9 @@ namespace testing {
|
||||
class MakeTestDataSet
|
||||
{
|
||||
public:
|
||||
// 1D uniform datasets.
|
||||
vtkm::cont::DataSet Make1DUniformDataSet0();
|
||||
|
||||
// 2D uniform datasets.
|
||||
vtkm::cont::DataSet Make2DUniformDataSet0();
|
||||
|
||||
@ -59,6 +62,28 @@ public:
|
||||
vtkm::cont::DataSet Make3DExplicitDataSetCowNose();
|
||||
};
|
||||
|
||||
//Make a simple 1D dataset.
|
||||
|
||||
inline vtkm::cont::DataSet
|
||||
MakeTestDataSet::Make1DUniformDataSet0()
|
||||
{
|
||||
vtkm::cont::DataSetBuilderUniform dsb;
|
||||
vtkm::Id dimension = 6;
|
||||
vtkm::cont::DataSet dataSet = dsb.Create(dimension);
|
||||
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
const vtkm::Id nVerts = 6;
|
||||
vtkm::Float32 var[nVerts] = {10.1f, 20.1f, 30.1f, 40.1f, 50.1f, 60.1f};
|
||||
|
||||
dsf.AddPointField(dataSet, "pointvar", var, nVerts);
|
||||
|
||||
const vtkm::Id nCells = 6;
|
||||
vtkm::Float32 cellvar[nCells] = {100.1f, 200.1f, 300.1f, 400.1f, 500.1f};
|
||||
dsf.AddCellField(dataSet, "cellvar", cellvar, nCells, "cells");
|
||||
|
||||
return dataSet;
|
||||
}
|
||||
|
||||
|
||||
//Make a simple 2D, 2 cell uniform dataset.
|
||||
|
||||
|
@ -136,12 +136,21 @@ RectilinearTests()
|
||||
FillArray(yCoordinates, dimensions[1], fillMethodY);
|
||||
FillArray(zCoordinates, dimensions[2], fillMethodZ);
|
||||
|
||||
vtkm::Id numPoints, numCells;
|
||||
vtkm::Bounds bounds(0,0, 0,0, 0,0);
|
||||
|
||||
std::cout << "1D cases" << std::endl;
|
||||
numPoints = dimensions[0];
|
||||
numCells = dimensions[0]-1;
|
||||
bounds.X = vtkm::Range(xCoordinates.front(), xCoordinates.back());
|
||||
std::cout << " Create with std::vector" << std::endl;
|
||||
dataSet = dataSetBuilder.Create(xCoordinates);
|
||||
ValidateDataSet(dataSet, 1, numPoints, numCells, bounds);
|
||||
|
||||
std::cout << "2D cases" << std::endl;
|
||||
vtkm::Id numPoints = dimensions[0]*dimensions[1];
|
||||
vtkm::Id numCells = (dimensions[0]-1)*(dimensions[1]-1);
|
||||
vtkm::Bounds bounds(xCoordinates.front(), xCoordinates.back(),
|
||||
yCoordinates.front(), yCoordinates.back(),
|
||||
0.0, 0.0);
|
||||
numPoints = dimensions[0]*dimensions[1];
|
||||
numCells = (dimensions[0]-1)*(dimensions[1]-1);
|
||||
bounds.Y = vtkm::Range(yCoordinates.front(), yCoordinates.back());
|
||||
|
||||
std::cout << " Create with std::vector" << std::endl;
|
||||
dataSet = dataSetBuilder.Create(xCoordinates, yCoordinates);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <vtkm/cont/DataSetBuilderUniform.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/DynamicCellSet.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
@ -55,13 +56,19 @@ void ValidateDataSet(const vtkm::cont::DataSet &ds,
|
||||
VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == numCells,
|
||||
"Wrong number of cells.");
|
||||
|
||||
|
||||
//Make sure bounds are correct.
|
||||
vtkm::Bounds res = ds.GetCoordinateSystem().GetBounds(DeviceAdapter());
|
||||
VTKM_TEST_ASSERT(test_equal(bounds, res),
|
||||
"Bounds of coordinates do not match");
|
||||
|
||||
if (dim == 2)
|
||||
if (dim == 1)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<1> cellSet;
|
||||
ds.GetCellSet(0).CopyTo(cellSet);
|
||||
vtkm::IdComponent shape = cellSet.GetCellShape();
|
||||
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_LINE, "Wrong element type");
|
||||
}
|
||||
else if (dim == 2)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<2> cellSet;
|
||||
ds.GetCellSet(0).CopyTo(cellSet);
|
||||
@ -175,50 +182,17 @@ UniformTests()
|
||||
vtkm::Vec<T,2>(origin[0], origin[1]),
|
||||
vtkm::Vec<T,2>(spacing[0], spacing[1]));
|
||||
ValidateDataSet(dataSet, 2, numPoints, numCells, bounds);
|
||||
|
||||
std::cout << "1D case" <<std::endl;
|
||||
numPoints = dimensions[0];
|
||||
numCells = dimensions[0]-1;
|
||||
bounds.Y = vtkm::Range(0, 0);
|
||||
bounds.Z = vtkm::Range(0, 0);
|
||||
dataSet = dataSetBuilder.Create(dimensions[0],
|
||||
static_cast<vtkm::FloatDefault>(origin[0]),
|
||||
static_cast<vtkm::FloatDefault>(spacing[0]));
|
||||
ValidateDataSet(dataSet, 1, numPoints, numCells, bounds);
|
||||
}
|
||||
|
||||
#if 0
|
||||
vtkm::cont::DataSetBuilderUniform dsb;
|
||||
vtkm::cont::DataSet ds;
|
||||
|
||||
vtkm::Id nx = 12, ny = 12, nz = 12;
|
||||
int nm = 5;
|
||||
vtkm::Float64 bounds[6];
|
||||
|
||||
for (vtkm::Id i = 2; i < nx; i++)
|
||||
for (vtkm::Id j = 2; j < ny; j++)
|
||||
for (int mi = 0; mi < nm; mi++)
|
||||
for (int mj = 0; mj < nm; mj++)
|
||||
{
|
||||
//2D cases
|
||||
vtkm::Id np = i*j, nc = (i-1)*(j-1);
|
||||
|
||||
vtkm::Id2 dims2(i,j);
|
||||
T oi, oj, si, sj;
|
||||
FillMethod(mi, dims2[0], oi, si, bounds[0],bounds[1]);
|
||||
FillMethod(mj, dims2[1], oj, sj, bounds[2],bounds[3]);
|
||||
bounds[4] = bounds[5] = 0;
|
||||
vtkm::Vec<T,2> o2(oi,oj), sp2(si,sj);
|
||||
|
||||
ds = dsb.Create(dims2, o2, sp2);
|
||||
ValidateDataSet(ds, 2, np, nc, bounds);
|
||||
|
||||
//3D cases
|
||||
for (vtkm::Id k = 2; k < nz; k++)
|
||||
for (int mk = 0; mk < nm; mk++)
|
||||
{
|
||||
np = i*j*k;
|
||||
nc = (i-1)*(j-1)*(k-1);
|
||||
|
||||
vtkm::Id3 dims3(i,j,k);
|
||||
T ok, sk;
|
||||
FillMethod(mk, dims3[2], ok, sk, bounds[4],bounds[5]);
|
||||
vtkm::Vec<T,3> o3(oi,oj,ok), sp3(si,sj,sk);
|
||||
ds = dsb.Create(dims3, o3, sp3);
|
||||
ValidateDataSet(ds, 3, np, nc, bounds);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -38,7 +38,8 @@ template<typename PortalType>
|
||||
class VecFromPortal
|
||||
{
|
||||
public:
|
||||
typedef typename PortalType::ValueType ComponentType;
|
||||
using ComponentType =
|
||||
typename std::remove_const<typename PortalType::ValueType>::type;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
@ -56,9 +57,9 @@ public:
|
||||
return this->NumComponents;
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent DestSize>
|
||||
template<typename T, vtkm::IdComponent DestSize>
|
||||
VTKM_EXEC_EXPORT
|
||||
void CopyInto(vtkm::Vec<ComponentType,DestSize> &dest) const
|
||||
void CopyInto(vtkm::Vec<T,DestSize> &dest) const
|
||||
{
|
||||
vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents);
|
||||
for (vtkm::IdComponent index = 0; index < numComponents; index++)
|
||||
|
@ -39,7 +39,9 @@ template<typename IndexVecType, typename PortalType>
|
||||
class VecFromPortalPermute
|
||||
{
|
||||
public:
|
||||
typedef typename PortalType::ValueType ComponentType;
|
||||
using ComponentType =
|
||||
typename std::remove_const<typename PortalType::ValueType>::type;
|
||||
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VecFromPortalPermute() { }
|
||||
|
@ -91,7 +91,7 @@ static int vtkm_force_linking_to_pthread_to_fix_nvidia_libgl_bug()
|
||||
{ return static_cast<int>(pthread_self()); }
|
||||
#endif
|
||||
|
||||
int UnitTestTransferGLUT(int argc, char **argv)
|
||||
int UnitTestTransferGLUT(int argc, char *argv[])
|
||||
{
|
||||
//get glut to construct a context for us
|
||||
glutInit(&argc, argv);
|
||||
|
@ -23,6 +23,10 @@
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/Range.h>
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
|
@ -32,10 +32,12 @@ namespace rendering {
|
||||
class CanvasGL : public Canvas
|
||||
{
|
||||
public:
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
CanvasGL(vtkm::Id width=1024,
|
||||
vtkm::Id height=1024);
|
||||
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
~CanvasGL();
|
||||
|
||||
@ -93,6 +95,7 @@ public:
|
||||
const vtkm::rendering::Color & color,
|
||||
const std::string &text) const VTKM_OVERRIDE;
|
||||
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::WorldAnnotator *CreateWorldAnnotator() const VTKM_OVERRIDE;
|
||||
|
||||
|
@ -24,7 +24,17 @@
|
||||
#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 {
|
||||
@ -55,6 +65,7 @@ void CanvasOSMesa::Initialize()
|
||||
{
|
||||
this->Internals->Context =
|
||||
OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, NULL);
|
||||
|
||||
if (!this->Internals->Context)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context creation failed.");
|
||||
@ -69,6 +80,8 @@ void CanvasOSMesa::Initialize()
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CanvasOSMesa::RefreshColorBuffer() const
|
||||
|
@ -23,63 +23,323 @@
|
||||
#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/cont/ArrayHandleIndex.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
namespace {
|
||||
|
||||
struct TypeListTagId4 : vtkm::ListTagBase<vtkm::Vec<Id, 4> > { };
|
||||
typedef TypeListTagId4 Id4Type;
|
||||
|
||||
template <typename PtType>
|
||||
VTKM_CONT_EXPORT
|
||||
void RenderTriangles(vtkm::Id numTri, const PtType &verts,
|
||||
const vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Id, 4> > &indices,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32> &scalar,
|
||||
const vtkm::rendering::ColorTable &ct,
|
||||
const vtkm::Range &scalarRange)
|
||||
class MapColorAndVertices : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
vtkm::Float32 sMin = vtkm::Float32(scalarRange.Min);
|
||||
vtkm::Float32 sMax = vtkm::Float32(scalarRange.Max);
|
||||
vtkm::Float32 sDiff = sMax-sMin;
|
||||
public:
|
||||
const vtkm::rendering::ColorTable ColorTable;
|
||||
const vtkm::Float32 SMin, SDiff;
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (int i = 0; i < numTri; i++)
|
||||
VTKM_CONT_EXPORT
|
||||
MapColorAndVertices(const vtkm::rendering::ColorTable &colorTable,
|
||||
vtkm::Float32 sMin, vtkm::Float32 sDiff)
|
||||
: ColorTable(colorTable),
|
||||
SMin(sMin),
|
||||
SDiff(sDiff)
|
||||
{}
|
||||
typedef void ControlSignature(FieldIn<IdType> vertexId,
|
||||
WholeArrayIn<Id4Type> indices,
|
||||
WholeArrayIn<Scalar> scalar,
|
||||
WholeArrayIn<Vec3> verts,
|
||||
WholeArrayOut<Scalar> out_color,
|
||||
WholeArrayOut<Scalar> out_vertices);
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6);
|
||||
|
||||
template<typename InputArrayIndexPortalType,
|
||||
typename InputArrayPortalType,
|
||||
typename InputArrayV3PortalType,
|
||||
typename OutputArrayPortalType>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::Id &i,
|
||||
InputArrayIndexPortalType &indices,
|
||||
const InputArrayPortalType &scalar,
|
||||
const InputArrayV3PortalType &verts,
|
||||
OutputArrayPortalType &c_array,
|
||||
OutputArrayPortalType &v_array) const
|
||||
{
|
||||
vtkm::Vec<vtkm::Id, 4> idx = indices.GetPortalConstControl().Get(i);
|
||||
vtkm::Vec<vtkm::Id, 4> idx = indices.Get(i);
|
||||
vtkm::Id i1 = idx[1];
|
||||
vtkm::Id i2 = idx[2];
|
||||
vtkm::Id i3 = idx[3];
|
||||
|
||||
vtkm::Vec<vtkm::Float32, 3> p1 = verts.GetPortalConstControl().Get(idx[1]);
|
||||
vtkm::Vec<vtkm::Float32, 3> p2 = verts.GetPortalConstControl().Get(idx[2]);
|
||||
vtkm::Vec<vtkm::Float32, 3> p3 = verts.GetPortalConstControl().Get(idx[3]);
|
||||
vtkm::Vec<vtkm::Float32, 3> p1 = verts.Get(idx[1]);
|
||||
vtkm::Vec<vtkm::Float32, 3> p2 = verts.Get(idx[2]);
|
||||
vtkm::Vec<vtkm::Float32, 3> p3 = verts.Get(idx[3]);
|
||||
|
||||
vtkm::Float32 s = scalar.GetPortalConstControl().Get(i1);
|
||||
s = (s-sMin)/sDiff;
|
||||
vtkm::Float32 s;
|
||||
vtkm::rendering::Color color;
|
||||
|
||||
Color color = ct.MapRGB(s);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glVertex3f(p1[0],p1[1],p1[2]);
|
||||
const vtkm::Id offset = 9;
|
||||
|
||||
s = scalar.GetPortalConstControl().Get(i2);
|
||||
s = (s-sMin)/sDiff;
|
||||
color = ct.MapRGB(s);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glVertex3f(p2[0],p2[1],p2[2]);
|
||||
s = scalar.Get(i1);
|
||||
s = (s-SMin)/SDiff;
|
||||
color = ColorTable.MapRGB(s);
|
||||
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, color.Components[0]);
|
||||
c_array.Set(i*offset+1, color.Components[1]);
|
||||
c_array.Set(i*offset+2, color.Components[2]);
|
||||
|
||||
s = scalar.GetPortalConstControl().Get(i3);
|
||||
s = (s-sMin)/sDiff;
|
||||
color = ct.MapRGB(s);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glVertex3f(p3[0],p3[1],p3[2]);
|
||||
s = scalar.Get(i2);
|
||||
s = (s-SMin)/SDiff;
|
||||
color = ColorTable.MapRGB(s);
|
||||
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, color.Components[0]);
|
||||
c_array.Set(i*offset+4, color.Components[1]);
|
||||
c_array.Set(i*offset+5, color.Components[2]);
|
||||
|
||||
s = scalar.Get(i3);
|
||||
s = (s-SMin)/SDiff;
|
||||
color = ColorTable.MapRGB(s);
|
||||
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, color.Components[0]);
|
||||
c_array.Set(i*offset+7, color.Components[1]);
|
||||
c_array.Set(i*offset+8, color.Components[2]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename PtType>
|
||||
struct MapColorAndVerticesInvokeFunctor
|
||||
{
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4> > TriangleIndices;
|
||||
vtkm::rendering::ColorTable ColorTable;
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32> Scalar;
|
||||
const vtkm::Range ScalarRange;
|
||||
const PtType Vertices;
|
||||
MapColorAndVertices Worklet;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> OutColor;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> OutVertices;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
MapColorAndVerticesInvokeFunctor(
|
||||
const vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Id, 4> > &indices,
|
||||
const vtkm::rendering::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),
|
||||
Worklet(colorTable, s_min, s_max - s_min),
|
||||
|
||||
OutColor(out_color),
|
||||
OutVertices(out_vertices)
|
||||
{}
|
||||
|
||||
template<typename Device>
|
||||
VTKM_CONT_EXPORT
|
||||
bool operator()(Device) const
|
||||
{
|
||||
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||
|
||||
vtkm::worklet::DispatcherMapField<MapColorAndVertices, Device>
|
||||
dispatcher(this->Worklet);
|
||||
|
||||
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_EXPORT
|
||||
void RenderTriangles(MapperGL &mapper,
|
||||
vtkm::Id numTri, const PtType &verts,
|
||||
const vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Id, 4> > &indices,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32> &scalar,
|
||||
const vtkm::rendering::ColorTable &ct,
|
||||
const vtkm::Range &scalarRange,
|
||||
const vtkm::rendering::Camera &camera)
|
||||
{
|
||||
|
||||
if (!mapper.loaded)
|
||||
{
|
||||
GLenum GlewInitResult = glewInit();
|
||||
if (GlewInitResult)
|
||||
std::cout << "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<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().StealArray();
|
||||
vtkm::Float32 *c_ptr = out_color.GetStorage().StealArray();
|
||||
|
||||
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, NULL);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, colours_vbo);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
vtkm::Matrix<vtkm::Float32,4,4> viewM = camera.CreateViewMatrix();
|
||||
vtkm::Matrix<vtkm::Float32,4,4> projM = camera.CreateProjectionMatrix(512,512);
|
||||
|
||||
MatrixHelpers::CreateOGLMatrix(viewM, mapper.mvMat);
|
||||
MatrixHelpers::CreateOGLMatrix(projM, mapper.pMat);
|
||||
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, NULL);
|
||||
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 NULL character
|
||||
GLchar *strInfoLog = new GLchar[maxLength + 1];
|
||||
glGetShaderInfoLog(vs, maxLength, &maxLength, strInfoLog);
|
||||
msg = std::string(strInfoLog);
|
||||
delete [] strInfoLog;
|
||||
}
|
||||
throw vtkm::cont::ErrorControlBadValue("Shader compile error:"+msg);
|
||||
}
|
||||
|
||||
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fs, 1, &fragment_shader, NULL);
|
||||
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 NULL character
|
||||
GLchar *strInfoLog = new GLchar[maxLength + 1];
|
||||
glGetShaderInfoLog(vs, maxLength, &maxLength, strInfoLog);
|
||||
msg = std::string(strInfoLog);
|
||||
delete [] strInfoLog;
|
||||
}
|
||||
throw vtkm::cont::ErrorControlBadValue("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::ErrorControlBadValue(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mapper.shader_programme > 0)
|
||||
{
|
||||
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()
|
||||
{ }
|
||||
{ this->loaded = false; }
|
||||
|
||||
MapperGL::~MapperGL()
|
||||
{ }
|
||||
@ -88,7 +348,7 @@ void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet &cellset,
|
||||
const vtkm::cont::CoordinateSystem &coords,
|
||||
const vtkm::cont::Field &scalarField,
|
||||
const vtkm::rendering::ColorTable &colorTable,
|
||||
const vtkm::rendering::Camera &,
|
||||
const vtkm::rendering::Camera &camera,
|
||||
const vtkm::Range &scalarRange)
|
||||
{
|
||||
vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Id, 4> > indices;
|
||||
@ -105,12 +365,12 @@ void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet &cellset,
|
||||
if(dcoords.IsSameType(vtkm::cont::ArrayHandleUniformPointCoordinates()))
|
||||
{
|
||||
uVerts = dcoords.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
RenderTriangles(numTri, uVerts, indices, sf, colorTable, scalarRange);
|
||||
RenderTriangles(*this, numTri, uVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
else if(dcoords.IsSameType(vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Float32,3> >()))
|
||||
{
|
||||
eVerts = dcoords.Cast<vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Float32,3> > > ();
|
||||
RenderTriangles(numTri, eVerts, indices, sf, colorTable, scalarRange);
|
||||
RenderTriangles(*this, numTri, eVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
else if(dcoords.IsSameType(vtkm::cont::ArrayHandleCartesianProduct<
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
@ -125,7 +385,7 @@ void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet &cellset,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> > > ();
|
||||
RenderTriangles(numTri, rVerts, indices, sf, colorTable, scalarRange);
|
||||
RenderTriangles(*this, numTri, rVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
glFinish();
|
||||
glFlush();
|
||||
|
@ -56,6 +56,12 @@ public:
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Mapper *NewCopy() const VTKM_OVERRIDE;
|
||||
|
||||
|
||||
GLuint shader_programme;
|
||||
GLfloat mvMat[16], pMat[16];
|
||||
bool loaded;
|
||||
GLuint vao;
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
|
@ -26,8 +26,10 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/glew.h>
|
||||
#if defined(__APPLE__)
|
||||
# include <OpenGL/gl.h>
|
||||
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
#endif
|
||||
|
@ -61,7 +61,17 @@ SetCamera<vtkm::rendering::View2D>(vtkm::rendering::Camera &camera,
|
||||
camera.SetClippingRange(1.f, 100.f);
|
||||
camera.SetViewport(-0.7f, +0.7f, -0.7f, +0.7f);
|
||||
}
|
||||
|
||||
|
||||
template <typename MapperType,typename CanvasType, typename ViewType>
|
||||
void
|
||||
Render(
|
||||
ViewType &view,
|
||||
const std::string &outputFile)
|
||||
{
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.SaveAs(outputFile);
|
||||
}
|
||||
template <typename MapperType,typename CanvasType, typename ViewType>
|
||||
void
|
||||
Render(const vtkm::cont::DataSet &ds,
|
||||
@ -72,21 +82,19 @@ Render(const vtkm::cont::DataSet &ds,
|
||||
MapperType mapper;
|
||||
CanvasType canvas(512,512);
|
||||
vtkm::rendering::Scene scene;
|
||||
|
||||
|
||||
scene.AddActor(vtkm::rendering::Actor(ds.GetCellSet(),
|
||||
ds.GetCoordinateSystem(),
|
||||
ds.GetField(fieldNm),
|
||||
colorTable));
|
||||
vtkm::rendering::Camera camera;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
SetCamera<ViewType>(camera,
|
||||
ds.GetCoordinateSystem().GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()));
|
||||
|
||||
ViewType view(scene, mapper, canvas, camera,
|
||||
vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.SaveAs(outputFile);
|
||||
|
||||
Render<MapperType, CanvasType, ViewType>(view, outputFile);
|
||||
}
|
||||
|
||||
}}} // namespace vtkm::rendering::testing
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace {
|
||||
|
||||
@ -67,7 +68,6 @@ void Render(const vtkm::cont::DataSet &ds,
|
||||
vtkm::rendering::ColorTable(ctName)));
|
||||
|
||||
vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg);
|
||||
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.SaveAs(outputFile);
|
||||
@ -75,8 +75,8 @@ void Render(const vtkm::cont::DataSet &ds,
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
//3D tests.
|
||||
Render(maker.Make3DRegularDataSet0(),
|
||||
"pointvar", "thermal", "reg3D.pnm");
|
||||
@ -85,9 +85,9 @@ void RenderTests()
|
||||
Render(maker.Make3DExplicitDataSet4(),
|
||||
"pointvar", "thermal", "expl3D.pnm");
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
int UnitTestMapperRayTracer(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
@ -95,3 +97,4 @@ int UnitTestMapperVolume(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
||||
|
||||
|
@ -54,5 +54,5 @@ void RenderTests()
|
||||
|
||||
int UnitTestMapperEGL(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
||||
|
@ -29,7 +29,9 @@
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
static const vtkm::Id WIDTH = 512, HEIGHT = 512;
|
||||
@ -63,23 +65,57 @@ void RenderTests()
|
||||
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "GLFW Test", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetKeyCallback(window, keyCallback);
|
||||
|
||||
|
||||
CanvasType canvas[4] = {CanvasType(512,512),CanvasType(512,512),
|
||||
CanvasType(512,512),CanvasType(512,512)};
|
||||
vtkm::rendering::Scene scene[4];
|
||||
vtkm::cont::DataSet ds[4];
|
||||
MapperType mapper[4];
|
||||
vtkm::rendering::Camera camera[4];
|
||||
|
||||
ds[0] = maker.Make3DRegularDataSet0();
|
||||
ds[1] = maker.Make3DRectilinearDataSet0();
|
||||
ds[2] = maker.Make3DExplicitDataSet4();
|
||||
ds[3] = maker.Make2DRectilinearDataSet0();
|
||||
|
||||
std::string fldNames[4];
|
||||
fldNames[0] = "pointvar";
|
||||
fldNames[1] = "pointvar";
|
||||
fldNames[2] = "pointvar";
|
||||
fldNames[3] = "pointvar";
|
||||
|
||||
for (int i=0; i<NUM_DATASETS; i++){
|
||||
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(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()));
|
||||
|
||||
}
|
||||
|
||||
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 view2d(scene[3], mapper[3], canvas[3], camera[3],
|
||||
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>(maker.Make3DRegularDataSet0(),
|
||||
"pointvar", colorTable, "reg3D.pnm");
|
||||
vtkm::rendering::testing::Render<MapperType,CanvasType,View3DType>(view3d0,"reg3D.pnm");
|
||||
else if (which == 1)
|
||||
vtkm::rendering::testing::Render<MapperType,CanvasType,View3DType>(maker.Make3DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect3D.pnm");
|
||||
vtkm::rendering::testing::Render<MapperType,CanvasType,View3DType>(view3d1,"rect3D.pnm");
|
||||
else if (which == 2)
|
||||
vtkm::rendering::testing::Render<MapperType,CanvasType,View3DType>(maker.Make3DExplicitDataSet4(),
|
||||
"pointvar", colorTable, "expl3D.pnm");
|
||||
vtkm::rendering::testing::Render<MapperType,CanvasType,View3DType>(view3d2,"expl3D.pnm");
|
||||
else if (which == 3)
|
||||
vtkm::rendering::testing::Render<MapperType,CanvasType,View2DType>(maker.Make2DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect2D.pnm");
|
||||
vtkm::rendering::testing::Render<MapperType,CanvasType,View2DType>(view2d,"rect2D.pnm");
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
if (batch)
|
||||
|
Loading…
Reference in New Issue
Block a user