Commit 43bb6acd authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot
Browse files

Merge topic 'mclarsen/vtk-m-rendering'

76b6179a Add missing copyright headers.
6a2a47d3 Remove order from new entries in MakeTestDataSet
d7c295f4 added rectilinear to test.
a8c7f92d Move mesa package to right place. Also, add in code for rectlinear mesh.
294b73e0 Make the rendering part of the build optional. Add the mesa libs to the link line.
719b715b Support for explicit cell sets.
98837735 Corrected error in projection matrix that was causing mismatches with ray tracing image and depth buffers.
f9c6f9cd

 cleanup of code.
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !383
parents 220b0f79 76b6179a
##============================================================================
## 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.
##
## Copyright 2014 Sandia Corporation.
## Copyright 2014 UT-Battelle, LLC.
## Copyright 2014 Los Alamos National Security.
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
# Try to find Mesa off-screen library and include dir.
# Once done this will define
#
# OSMESA_FOUND - true if OSMesa has been found
# OSMESA_INCLUDE_DIR - where the GL/osmesa.h can be found
# OSMESA_LIBRARY - Link this to use OSMesa
if(NOT OSMESA_INCLUDE_DIR)
# If we have a root defined look there first
if(OSMESA_ROOT)
find_path(OSMESA_INCLUDE_DIR GL/osmesa.h PATHS ${OSMESA_ROOT}/include
NO_DEFAULT_PATH
)
endif()
if(NOT OSMESA_INCLUDE_DIR)
find_path(OSMESA_INCLUDE_DIR GL/osmesa.h PATHS
/usr/openwin/share/include
/opt/graphics/OpenGL/include
)
endif()
endif()
# This may be left blank if OSMesa symbols are included
# in the main Mesa library
if(NOT OSMESA_LIBRARY)
# If we have a root defined look there first
if(OSMESA_ROOT)
find_library(OSMESA_LIBRARY OSMesa PATHS ${OSMESA_ROOT}/lib
NO_DEFAULT_PATH
)
endif()
if(NOT OSMESA_LIBRARY)
find_library(OSMESA_LIBRARY OSMesa PATHS
/opt/graphics/OpenGL/lib
/usr/openwin/lib
)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OSMesa DEFAULT_MSG OSMESA_LIBRARY OSMESA_INCLUDE_DIR)
mark_as_advanced(OSMESA_INCLUDE_DIR OSMESA_LIBRARY)
......@@ -97,6 +97,7 @@ option(VTKm_ENABLE_BENCHMARKS "Enable VTKm Benchmarking" OFF)
option(VTKm_BUILD_DOCUMENTATION "Build Doxygen documentation" OFF)
option(VTKm_BUILD_EXAMPLES "Build examples" OFF)
option(VTKm_BUILD_RENDERING "Build rendering" OFF)
option(VTKm_USE_DOUBLE_PRECISION
"Use double precision for floating point calculations"
......
......@@ -55,6 +55,12 @@ if(VTKm_ENABLE_OPENGL_INTEROP)
add_subdirectory(opengl)
endif(VTKm_ENABLE_OPENGL_INTEROP)
#-----------------------------------------------------------------------------
# Build rendering
if(VTKm_BUILD_RENDERING)
add_subdirectory(rendering)
endif(VTKm_BUILD_RENDERING)
#-----------------------------------------------------------------------------
#add the control and exec folders
add_subdirectory(cont)
......
......@@ -40,6 +40,8 @@ public:
// 3D uniform datasets.
vtkm::cont::DataSet Make3DUniformDataSet0();
vtkm::cont::DataSet Make3DRegularDataSet0();
vtkm::cont::DataSet Make3DRegularDataSet1();
//2D rectilinear
vtkm::cont::DataSet Make2DRectilinearDataSet0();
......@@ -47,9 +49,13 @@ public:
//3D rectilinear
vtkm::cont::DataSet Make3DRectilinearDataSet0();
// 3D explicit datasets.
vtkm::cont::DataSet Make3DExplicitDataSet0();
vtkm::cont::DataSet Make3DExplicitDataSet1();
vtkm::cont::DataSet Make3DExplicitDataSet2();
vtkm::cont::DataSet Make3DExplicitDataSet3();
vtkm::cont::DataSet Make3DExplicitDataSet4();
vtkm::cont::DataSet Make3DExplicitDataSetCowNose();
};
......@@ -128,6 +134,65 @@ MakeTestDataSet::Make2DRectilinearDataSet0()
return dataSet;
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DRegularDataSet0()
{
vtkm::cont::DataSet dataSet;
const int nVerts = 18;
vtkm::cont::ArrayHandleUniformPointCoordinates
coordinates(vtkm::Id3(3, 2, 3));
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.1f, 40.1f, 50.2f, 60.2f, 70.2f, 80.2f, 90.3f,
100.3f, 110.3f, 120.3f, 130.4f, 140.4f, 150.4f, 160.4f, 170.5f,
180.5f};
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", coordinates));
//Set point scalar
dataSet.AddField(Field("pointvar", vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
//Set cell scalar
vtkm::Float32 cellvar[4] = {100.1f, 100.2f, 100.3f, 100.4f};
dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 4));
static const vtkm::IdComponent dim = 3;
vtkm::cont::CellSetStructured<dim> cellSet("cells");
cellSet.SetPointDimensions( vtkm::make_Vec(3,2,3) );
dataSet.AddCellSet(cellSet);
return dataSet;
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DRegularDataSet1()
{
vtkm::cont::DataSet dataSet;
const int nVerts = 8;
vtkm::cont::ArrayHandleUniformPointCoordinates
coordinates(vtkm::Id3(2, 2, 2));
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.1f, 40.1f, 50.2f, 60.2f, 70.2f, 80.2f};
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", coordinates));
//Set point scalar
dataSet.AddField(Field("pointvar", vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
//Set cell scalar
vtkm::Float32 cellvar[1] = {100.1f};
dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 1));
static const vtkm::IdComponent dim = 3;
vtkm::cont::CellSetStructured<dim> cellSet("cells");
cellSet.SetPointDimensions( vtkm::make_Vec(2,2,2) );
dataSet.AddCellSet(cellSet);
return dataSet;
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DRectilinearDataSet0()
{
......@@ -286,6 +351,161 @@ MakeTestDataSet::Make3DExplicitDataSet1()
return dataSet;
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DExplicitDataSet2()
{
vtkm::cont::DataSet dataSet;
const int nVerts = 8;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
CoordType coordinates[nVerts] = {
CoordType(0, 0, 0),
CoordType(1, 0, 0),
CoordType(1, 0, 1),
CoordType(0, 0, 1),
CoordType(0, 1, 0),
CoordType(1, 1, 0),
CoordType(1, 1, 1),
CoordType(0, 1, 1)
};
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f, 60.2f, 70.2f, 80.3f};
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", coordinates, nVerts));
//Set point scalar
dataSet.AddField(Field("pointvar", vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
//Set cell scalar
vtkm::Float32 cellvar[2] = {100.1f};
dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 1));
vtkm::cont::CellSetExplicit<> cellSet(nVerts,"cells");
vtkm::Vec<vtkm::Id, 8> ids;
ids[0] = 0;
ids[1] = 1;
ids[2] = 2;
ids[3] = 3;
ids[4] = 4;
ids[5] = 5;
ids[6] = 6;
ids[7] = 7;
cellSet.PrepareToAddCells(1, 8);
cellSet.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON, 8, ids);
cellSet.CompleteAddingCells();
//todo this need to be a reference/shared_ptr style class
dataSet.AddCellSet(cellSet);
return dataSet;
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DExplicitDataSet4()
{
vtkm::cont::DataSet dataSet;
const int nVerts = 12;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
CoordType coordinates[nVerts] = {
CoordType(0, 0, 0), //0
CoordType(1, 0, 0), //1
CoordType(1, 0, 1), //2
CoordType(0, 0, 1), //3
CoordType(0, 1, 0), //4
CoordType(1, 1, 0), //5
CoordType(1, 1, 1), //6
CoordType(0, 1, 1), //7
CoordType(2, 0, 0), //8
CoordType(2, 0, 1), //9
CoordType(2, 1, 1), //10
CoordType(2, 1, 0) //11
};
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f, 60.2f, 70.2f, 80.3f, 90.f, 10.f, 11.f, 12.f};
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", coordinates, nVerts));
//Set point scalar
dataSet.AddField(Field("pointvar", vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
//Set cell scalar
vtkm::Float32 cellvar[2] = {100.1f, 110.f};
dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 2));
vtkm::cont::CellSetExplicit<> cellSet(nVerts,"cells");
vtkm::Vec<vtkm::Id, 8> ids;
ids[0] = 0;
ids[1] = 1;
ids[2] = 5;
ids[3] = 4;
ids[4] = 3;
ids[5] = 2;
ids[6] = 6;
ids[7] = 7;
cellSet.PrepareToAddCells(2, 16);
cellSet.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON, 8, ids);
ids[0] = 1;
ids[1] = 8;
ids[2] = 11;
ids[3] = 5;
ids[4] = 2;
ids[5] = 9;
ids[6] = 10;
ids[7] = 6;
cellSet.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON, 8, ids);
cellSet.CompleteAddingCells();
//todo this need to be a reference/shared_ptr style class
dataSet.AddCellSet(cellSet);
return dataSet;
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DExplicitDataSet3()
{
vtkm::cont::DataSet dataSet;
const int nVerts = 4;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
CoordType coordinates[nVerts] = {
CoordType(0, 0, 0),
CoordType(1, 0, 0),
CoordType(1, 0, 1),
CoordType(0, 1, 0)
};
vtkm::Float32 vars[nVerts] = {10.1f, 10.1f, 10.2f, 30.2f};
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", coordinates, nVerts));
//Set point scalar
dataSet.AddField(Field("pointvar", vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
//Set cell scalar
vtkm::Float32 cellvar[2] = {100.1f};
dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 1));
vtkm::cont::CellSetExplicit<> cellSet(nVerts,"cells");
vtkm::Vec<vtkm::Id, 4> ids;
ids[0] = 0;
ids[1] = 1;
ids[2] = 2;
ids[3] = 3;
cellSet.PrepareToAddCells(1, 4);
cellSet.AddCell(vtkm::CELL_SHAPE_TETRA, 4, ids);
cellSet.CompleteAddingCells();
//todo this need to be a reference/shared_ptr style class
dataSet.AddCellSet(cellSet);
return dataSet;
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DExplicitDataSetCowNose()
{
......
......@@ -115,6 +115,12 @@ public:
return Helper::LogicalToFlatToIndex(this->Internals, logicalToIndex);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<vtkm::Id,Dimension> GetPointDimensions() const
{
return this->Internals.GetPointDimensions();
}
private:
InternalsType Internals;
};
......
##============================================================================
## 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.
##
## Copyright 2014 Sandia Corporation.
## Copyright 2014 UT-Battelle, LLC.
## Copyright 2014 Los Alamos National Security.
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
set(headers
Color.h
ColorTable.h
Plot.h
RenderSurface.h
Scene.h
SceneRenderer.h
SceneRendererOSMesa.h
SceneRendererVolume.h
Triangulator.h
View.h
Window.h
)
#-----------------------------------------------------------------------------
find_package(MESA REQUIRED)
vtkm_declare_headers(${headers})
add_subdirectory(raytracing)
include_directories(${OSMESA_INCLUDE_DIR})
#-----------------------------------------------------------------------------
add_subdirectory(testing)
//============================================================================
// 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.
//
// Copyright 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_rendering_Color_h
#define vtk_m_rendering_Color_h
#include <iostream>
#include <vtkm/cont/DataSet.h>
namespace vtkm {
namespace rendering {
/// \brief It's a color!
///
/// This class provides the basic representation of a color. This class was
/// Ported from EAVL. Originally created by Jeremy Meredith, Dave Pugmire,
/// and Sean Ahern.
///
class Color
{
public:
vtkm::Float32 Components[4];
Color()
{
Components[0] = 0;
Components[1] = 0;
Components[2] = 0;
Components[3] = 1;
}
Color(vtkm::Float32 r_,
vtkm::Float32 g_,
vtkm::Float32 b_,
vtkm::Float32 a_ = 1.f)
{
Components[0] = r_;
Components[1] = g_;
Components[2] = b_;
Components[3] = a_;
}
inline void SetComponentFromByte(vtkm::Int32 i, vtkm::UInt8 v)
{
// Note that though GetComponentAsByte below
// multiplies by 256, we're dividing by 255. here.
// This is, believe it or not, still correct.
// That's partly because we always round down in
// that method. For example, if we set the float
// here using byte(1), /255 gives us .00392, which
// *256 gives us 1.0035, which is then rounded back
// down to byte(1) below. Or, if we set the float
// here using byte(254), /255 gives us .99608, which
// *256 gives us 254.996, which is then rounded
// back down to 254 below. So it actually reverses
// correctly, even though the mutliplier and
// divider don't match between these two methods.
//
// Of course, converting in GetComponentAsByte from
// 1.0 gives 256, so we need to still clamp to 255
// anyway. Again, this is not a problem, because it
// doesn't really extend the range of floating point
// values which map to 255.
Components[i] = float(v) / 255.f;
// clamp?
if (Components[i]<0) Components[i] = 0;
if (Components[i]>1) Components[i] = 1;
}
inline vtkm::UInt8 GetComponentAsByte(int i)
{
// We need this to match what OpenGL/Mesa do.
// Why? Well, we need to set glClearColor
// using floats, but the frame buffer comes
// back as bytes (and is internally such) in
// most cases. In one example -- parallel
// compositing -- we need the byte values
// returned from here to match the byte values
// returned in the frame buffer. Though
// a quick source code inspection of Mesa
// led me to believe I should do *255., in
// fact this led to a mismatch. *256. was
// actually closer. (And arguably more correct
// if you think the byte value 255 should share
// approximately the same range in the float [0,1]
// space as the other byte values.) Note in the
// inverse method above, though, we still use 255;
// see SetComponentFromByte for an explanation of
// why that is correct, if non-obvious.
int tv = vtkm::Int32(Components[i] * 256.f);
// Converting even from valid values (i.e 1.0)
// can give a result outside the range (i.e. 256),
// but we have to clamp anyway.
return vtkm::UInt8((tv < 0) ? 0 : (tv > 255) ? 255 : tv);
}
void GetRGBA(vtkm::UInt8 &r, vtkm::UInt8 &g,
vtkm::UInt8 &b, vtkm::UInt8 &a)
{
r = GetComponentAsByte(0);
g = GetComponentAsByte(1);
b = GetComponentAsByte(2);
a = GetComponentAsByte(3);
}
vtkm::Float64 RawBrightness()
{
return (Components[0]+Components[1]+Components[2])/3.;
}
friend std::ostream &operator<<(std::ostream &out, const Color &c)
{
out << "["<<c.Components[0]<<","<<c.Components[1]<<","<<c.Components[2]<<","<<c.Components[3]<<"]";
return out;
}
};
}}//namespace vtkm::rendering
#endif //vtk_m_rendering_Color_h
\ No newline at end of file
This diff is collapsed.
//============================================================================
// 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.
//
// Copyright 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_rendering_Plot_h
#define vtk_m_rendering_Plot_h
#include <vtkm/rendering/SceneRenderer.h>
#include <vector>
namespace vtkm {
namespace rendering {
class Plot
{
public:
//Plot(points, cells, field, colortable) {}
VTKM_CONT_EXPORT
Plot(const vtkm::cont::DynamicCellSet &cs,
const vtkm::cont::CoordinateSystem &c,
const vtkm::cont::Field &f,
const vtkm::rendering::ColorTable &ct) :
cellSet(cs), coords(c), scalarField(f), colorTable(ct)
{
f.GetBounds(scalarBounds,
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
}
template<typename SceneRendererType, typename SurfaceType>
VTKM_CONT_EXPORT
void Render(SceneRendererType &sr,
SurfaceType &)//surface)
{
//??????
//feed surface into sr somehow??
sr.RenderCells(cellSet, coords, scalarField,
colorTable, scalarBounds);
}
vtkm::cont::DynamicCellSet cellSet;
vtkm::cont::CoordinateSystem coords;
vtkm::cont::Field scalarField;
vtkm::rendering::ColorTable colorTable;
vtkm::Float64 scalarBounds[2];
};
}} //namespace vtkm::rendering
#endif //vtk_m_rendering_Plot_h
This diff is collapsed.
//============================================================================
// 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.
//
// Copyright 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.