Create configuration for rendering library

I have noticed at least on my windows machine that source code that uses
the rendering package is taking a long time to compile. The rendering
library does not rely much on templates and more on virtual methods.
Thus, it is a good candidate for moving to a library so that it need be
compiled only once.

This sets up the configure scripts to create the library. There is also
a simple port of one class to the library. More will follow.
This commit is contained in:
Kenneth Moreland 2016-08-25 17:54:32 -06:00
parent e5967cfca8
commit ea8602d882
6 changed files with 367 additions and 152 deletions

@ -41,6 +41,7 @@ set(VTKm_AVAILABLE_COMPONENTS
EGL
GLFW
Interop
Rendering
TBB
CUDA
)
@ -202,6 +203,19 @@ macro(vtkm_configure_component_Interop)
)
endmacro(vtkm_configure_component_Interop)
macro(vtkm_configure_component_Rendering)
if(VTKm_BUILD_RENDERING)
vtkm_configure_component_OpenGL()
vtkm_configure_component_EGL()
vtkm_configure_component_OSMesa()
endif()
vtkm_finish_configure_component(Rendering
DEPENDENT_VARIABLES VTKm_BUILD_RENDERING VTKm_Base_FOUND
ADD_LIBRARIES vtkm_rendering
)
endmacro(vtkm_configure_component_Rendering)
macro(vtkm_configure_component_TBB)
if(VTKm_ENABLE_TBB)
vtkm_configure_component_Base()

@ -19,6 +19,7 @@
##============================================================================
include(CMakeParseArguments)
include(GenerateExportHeader)
# Utility to build a kit name from the current directory.
function(vtkm_get_kit_name kitvar)
@ -552,6 +553,84 @@ function(vtkm_benchmarks device_adapter)
endfunction(vtkm_benchmarks)
# Add a VTK-m library. The name of the library will match the "kit" name
# (e.g. vtkm_rendering) unless the NAME argument is given.
#
# vtkm_library(
# [NAME <name>]
# SOURCES <source_list>
# [CUDA]
# )
function(vtkm_library)
set(options CUDA)
set(oneValueArgs NAME)
set(multiValueArgs SOURCES)
cmake_parse_arguments(VTKm_LIB
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
vtkm_get_kit_name(kit dir_prefix)
if(VTKm_LIB_NAME)
set(lib_name ${VTKm_LIB_NAME})
else()
set(lib_name ${kit})
endif()
if(VTKm_LIB_CUDA)
vtkm_setup_nvcc_flags(old_nvcc_flags old_cxx_flags)
# Cuda compiles do not respect target_include_directories
cuda_include_directories(${VTKm_INCLUDE_DIRS})
cuda_add_library(${lib_name} ${VTKm_LIB_SOURCES})
set(CUDA_NVCC_FLAGS ${old_nvcc_flags})
set(CMAKE_CXX_FLAGS ${old_cxx_flags})
else()
add_library(${lib_name} ${VTKm_LIB_SOURCES})
endif()
#do it as a property value so we don't pollute the include_directories
#for any other targets
set_property(TARGET ${lib_name} APPEND PROPERTY
INCLUDE_DIRECTORIES ${VTKm_INCLUDE_DIRS} )
target_link_libraries(${lib_name} ${VTKm_LIBRARIES})
target_compile_options(${lib_name} PRIVATE ${VTKm_COMPILE_OPTIONS})
if(MSVC)
vtkm_setup_msvc_properties(${lib_name})
endif()
if(VTKm_EXTRA_COMPILER_WARNINGS)
set_property(TARGET ${lib_name}
APPEND PROPERTY COMPILE_FLAGS
${CMAKE_CXX_FLAGS_WARN_EXTRA}
)
endif(VTKm_EXTRA_COMPILER_WARNINGS)
generate_export_header(${lib_name})
#generate_export_header creates the header in CMAKE_CURRENT_BINARY_DIR.
#The build expects it in the install directory.
file(COPY
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_export.h
DESTINATION
${CMAKE_BINARY_DIR}/${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}
)
install(TARGETS ${lib_name}
ARCHIVE DESTINATION ${VTKm_INSTALL_LIB_DIR}
LIBRARY DESTINATION ${VTKm_INSTALL_LIB_DIR}
RUNTIME DESTINATION ${VTKm_INSTALL_BIN_DIR}
)
vtkm_install_headers("${dir_prefix}"
${CMAKE_BINARY_DIR}/${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}/${lib_name}_export.h
)
endfunction(vtkm_library)
# The Thrust project is not as careful as the VTKm project in avoiding warnings
# on shadow variables and unused arguments. With a real GCC compiler, you
# can disable these warnings inline, but with something like nvcc, those

@ -46,7 +46,9 @@ set(VTKm_PATCH_VERSION 0)
set(VTKm_VERSION "${VTKm_MAJOR_VERSION}.${VTKm_MINOR_VERSION}.${VTKm_PATCH_VERSION}")
set(VTKm_INSTALL_INCLUDE_DIR "include")
set(VTKm_INSTALL_CONFIG_DIR "include")
set(VTKm_INSTALL_CONFIG_DIR "lib")
set(VTKm_INSTALL_LIB_DIR "lib")
set(VTKm_INSTALL_BIN_DIR "bin")
set(VTKm_INSTALL_CMAKE_MODULE_DIR "share/vtkm/cmake")
set(VTKm_REQUIRED_BOOST_VERSION "1.48")
@ -149,7 +151,7 @@ set( EXECUTABLE_OUTPUT_PATH
## Set the directory where the libraries will be stored
set( LIBRARY_OUTPUT_PATH
${PROJECT_BINARY_DIR}/libs
${PROJECT_BINARY_DIR}/lib
CACHE PATH
"Directory where all the libraries will be stored"
)

@ -0,0 +1,177 @@
//============================================================================
// 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 2016 Sandia Corporation.
// Copyright 2016 UT-Battelle, LLC.
// Copyright 2016 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.
//============================================================================
#include <vtkm/rendering/AxisAnnotation2D.h>
namespace vtkm {
namespace rendering {
AxisAnnotation2D::AxisAnnotation2D()
: AxisAnnotation()
{
this->AlignH = TextAnnotation::HCenter;
this->AlignV = TextAnnotation::VCenter;
this->FontScale = 0.05f;
this->LineWidth = 1.0;
this->Color = vtkm::rendering::Color(1,1,1);
this->Logarithmic = false;
this->MoreOrLessTickAdjustment = 0;
}
AxisAnnotation2D::~AxisAnnotation2D()
{
}
void AxisAnnotation2D::SetRangeForAutoTicks(const Range &range)
{
this->TickRange = range;
#if 0
if (this->Logarithmic)
{
CalculateTicksLogarithmic(this->TickRange.Min,
this->TickRange.Max,
false,
this->PositionsMajor,
this->ProportionsMajor,
this->MoreOrLessTickAdjustment);
CalculateTicksLogarithmic(this->TickRange.Min,
this->TickRange.Max,
true,
this->PositionsMinor,
this->ProportionsMinor,
this->MoreOrLessTickAdjustment);
}
else
#endif
{
CalculateTicks(this->TickRange.Min,
this->TickRange.Max,
false,
this->PositionsMajor,
this->ProportionsMajor,
this->MoreOrLessTickAdjustment);
CalculateTicks(this->TickRange.Min,
this->TickRange.Max,
true,
this->PositionsMinor,
this->ProportionsMinor,
this->MoreOrLessTickAdjustment);
}
}
void AxisAnnotation2D::SetMajorTicks(const std::vector<vtkm::Float64> &pos,
const std::vector<vtkm::Float64> &prop)
{
this->PositionsMajor.clear();
this->PositionsMajor.insert(this->PositionsMajor.begin(),
pos.begin(),
pos.end());
this->ProportionsMajor.clear();
this->ProportionsMajor.insert(this->ProportionsMajor.begin(),
prop.begin(),
prop.end());
}
void AxisAnnotation2D::SetMinorTicks(const std::vector<vtkm::Float64> &pos,
const std::vector<vtkm::Float64> &prop)
{
this->PositionsMinor.clear();
this->PositionsMinor.insert(this->PositionsMinor.begin(), pos.begin(), pos.end());
this->ProportionsMinor.clear();
this->ProportionsMinor.insert(this->ProportionsMinor.begin(), prop.begin(), prop.end());
}
void AxisAnnotation2D::Render(
const vtkm::rendering::Camera &camera,
const vtkm::rendering::WorldAnnotator &worldAnnotator,
vtkm::rendering::Canvas &canvas)
{
canvas.AddLine(this->PosX0,this->PosY0, this->PosX1,this->PosY1, this->LineWidth, this->Color);
// major ticks
unsigned int nmajor = (unsigned int)this->ProportionsMajor.size();
while (this->Labels.size() < nmajor)
{
this->Labels.push_back(new ScreenTextAnnotation("test",
this->Color,
this->FontScale,
0,0, 0));
}
std::stringstream numberToString;
for (unsigned int i=0; i<nmajor; ++i)
{
vtkm::Float64 xc = this->PosX0 + (this->PosX1-this->PosX0) * this->ProportionsMajor[i];
vtkm::Float64 yc = this->PosY0 + (this->PosY1-this->PosY0) * this->ProportionsMajor[i];
vtkm::Float64 xs = xc - this->MajorTickSizeX*this->MajorTickOffset;
vtkm::Float64 xe = xc + this->MajorTickSizeX*(1. - this->MajorTickOffset);
vtkm::Float64 ys = yc - this->MajorTickSizeY*this->MajorTickOffset;
vtkm::Float64 ye = yc + this->MajorTickSizeY*(1. - this->MajorTickOffset);
canvas.AddLine(xs,ys, xe,ye, 1.0, this->Color);
if (this->MajorTickSizeY == 0)
{
// slight shift to space between label and tick
xs -= (this->MajorTickSizeX<0?-1.:+1.) * this->FontScale * .1;
}
numberToString.str("");
numberToString << this->PositionsMajor[i];
this->Labels[i]->SetText(numberToString.str());
//if (fabs(this->PositionsMajor[i]) < 1e-10)
// this->Labels[i]->SetText("0");
((ScreenTextAnnotation*)(this->Labels[i]))->SetPosition(vtkm::Float32(xs),
vtkm::Float32(ys));
this->Labels[i]->SetAlignment(this->AlignH,this->AlignV);
}
// minor ticks
if (this->MinorTickSizeX != 0 || this->MinorTickSizeY != 0)
{
unsigned int nminor = (unsigned int)this->ProportionsMinor.size();
for (unsigned int i=0; i<nminor; ++i)
{
vtkm::Float64 xc = this->PosX0 + (this->PosX1-this->PosX0) * this->ProportionsMinor[i];
vtkm::Float64 yc = this->PosY0 + (this->PosY1-this->PosY0) * this->ProportionsMinor[i];
vtkm::Float64 xs = xc - this->MinorTickSizeX*this->MinorTickOffset;
vtkm::Float64 xe = xc + this->MinorTickSizeX*(1. - this->MinorTickOffset);
vtkm::Float64 ys = yc - this->MinorTickSizeY*this->MinorTickOffset;
vtkm::Float64 ye = yc + this->MinorTickSizeY*(1. - this->MinorTickOffset);
canvas.AddLine(xs,ys, xe,ye, 1.0, this->Color);
}
}
for (unsigned int i=0; i<nmajor; ++i)
{
this->Labels[i]->Render(camera, worldAnnotator, canvas);
}
}
}
} // namespace vtkm::rendering

@ -20,13 +20,18 @@
#ifndef vtk_m_rendering_AxisAnnotation2D_h
#define vtk_m_rendering_AxisAnnotation2D_h
#include <vtkm/rendering/vtkm_rendering_export.h>
#include <vtkm/rendering/AxisAnnotation.h>
#include <vtkm/rendering/Color.h>
#include <vtkm/Range.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/Canvas.h>
#include <vtkm/rendering/Color.h>
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/WorldAnnotator.h>
#include <vtkm/rendering/AxisAnnotation.h>
#include <vtkm/rendering/TextAnnotation.h>
#include <sstream>
@ -37,198 +42,127 @@ namespace rendering {
class AxisAnnotation2D : public AxisAnnotation
{
protected:
vtkm::Float64 maj_tx, maj_ty, maj_toff;
vtkm::Float64 min_tx, min_ty, min_toff;
vtkm::Float64 x0, y0, x1, y1;
vtkm::Float64 lower, upper;
vtkm::Float32 fontscale;
vtkm::Float32 linewidth;
vtkm::rendering::Color color;
bool logarithmic;
vtkm::Float64 MajorTickSizeX, MajorTickSizeY, MajorTickOffset;
vtkm::Float64 MinorTickSizeX, MinorTickSizeY, MinorTickOffset;
vtkm::Float64 PosX0, PosY0, PosX1, PosY1;
vtkm::Range TickRange;
vtkm::Float32 FontScale;
vtkm::Float32 LineWidth;
vtkm::rendering::Color Color;
bool Logarithmic;
TextAnnotation::HorizontalAlignment halign;
TextAnnotation::VerticalAlignment valign;
std::vector<TextAnnotation*> labels;
TextAnnotation::HorizontalAlignment AlignH;
TextAnnotation::VerticalAlignment AlignV;
std::vector<TextAnnotation*> Labels;
std::vector<vtkm::Float64> maj_positions;
std::vector<vtkm::Float64> maj_proportions;
std::vector<vtkm::Float64> PositionsMajor;
std::vector<vtkm::Float64> ProportionsMajor;
std::vector<vtkm::Float64> min_positions;
std::vector<vtkm::Float64> min_proportions;
std::vector<vtkm::Float64> PositionsMinor;
std::vector<vtkm::Float64> ProportionsMinor;
int moreOrLessTickAdjustment;
int MoreOrLessTickAdjustment;
public:
AxisAnnotation2D() : AxisAnnotation()
{
halign = TextAnnotation::HCenter;
valign = TextAnnotation::VCenter;
fontscale = 0.05f;
linewidth = 1.0;
color = Color(1,1,1);
logarithmic = false;
moreOrLessTickAdjustment = 0;
}
virtual ~AxisAnnotation2D()
{
}
VTKM_RENDERING_EXPORT
AxisAnnotation2D();
VTKM_RENDERING_EXPORT
virtual ~AxisAnnotation2D();
#if 0
VTKM_RENDERING_EXPORT
void SetLogarithmic(bool l)
{
logarithmic = l;
this->Logarithmic = l;
}
#endif
VTKM_RENDERING_EXPORT
void SetMoreOrLessTickAdjustment(int offset)
{
moreOrLessTickAdjustment = offset;
this->MoreOrLessTickAdjustment = offset;
}
VTKM_RENDERING_EXPORT
void SetColor(vtkm::rendering::Color c)
{
color = c;
this->Color = c;
}
VTKM_RENDERING_EXPORT
void SetLineWidth(vtkm::Float32 lw)
{
linewidth = lw;
this->LineWidth = lw;
}
VTKM_RENDERING_EXPORT
void SetMajorTickSize(vtkm::Float64 xlen, vtkm::Float64 ylen, vtkm::Float64 offset)
{
/// offset of 0 means the tick is inside the frame
/// offset of 1 means the tick is outside the frame
/// offset of 0.5 means the tick is centered on the frame
maj_tx=xlen;
maj_ty=ylen;
maj_toff = offset;
this->MajorTickSizeX=xlen;
this->MajorTickSizeY=ylen;
this->MajorTickOffset = offset;
}
VTKM_RENDERING_EXPORT
void SetMinorTickSize(vtkm::Float64 xlen, vtkm::Float64 ylen, vtkm::Float64 offset)
{
min_tx=xlen;
min_ty=ylen;
min_toff = offset;
this->MinorTickSizeX=xlen;
this->MinorTickSizeY=ylen;
this->MinorTickOffset = offset;
}
///\todo: rename, since it might be screen OR world position?
void SetScreenPosition(vtkm::Float64 x0_, vtkm::Float64 y0_,
vtkm::Float64 x1_, vtkm::Float64 y1_)
{
x0 = x0_;
y0 = y0_;
x1 = x1_;
y1 = y1_;
///\todo: rename, since it might be screen OR world position?
VTKM_RENDERING_EXPORT
void SetScreenPosition(vtkm::Float64 x0, vtkm::Float64 y0,
vtkm::Float64 x1, vtkm::Float64 y1)
{
this->PosX0 = x0;
this->PosY0 = y0;
this->PosX1 = x1;
this->PosY1 = y1;
}
VTKM_RENDERING_EXPORT
void SetLabelAlignment(TextAnnotation::HorizontalAlignment h,
TextAnnotation::VerticalAlignment v)
{
halign = h;
valign = v;
this->AlignH = h;
this->AlignV = v;
}
VTKM_RENDERING_EXPORT
void SetLabelFontScale(vtkm::Float32 s)
{
fontscale = s;
for (unsigned int i=0; i<labels.size(); i++)
labels[i]->SetScale(s);
this->FontScale = s;
for (unsigned int i=0; i<this->Labels.size(); i++)
this->Labels[i]->SetScale(s);
}
void SetRangeForAutoTicks(vtkm::Float64 l, vtkm::Float64 u)
{
lower = l;
upper = u;
#if 0
if (logarithmic)
VTKM_RENDERING_EXPORT
void SetRangeForAutoTicks(const vtkm::Range &range);
VTKM_RENDERING_EXPORT
void SetRangeForAutoTicks(vtkm::Float64 lower, vtkm::Float64 upper)
{
CalculateTicksLogarithmic(lower, upper, false, maj_positions, maj_proportions, moreOrLessTickAdjustment);
CalculateTicksLogarithmic(lower, upper, true, min_positions, min_proportions, moreOrLessTickAdjustment);
this->SetRangeForAutoTicks(vtkm::Range(lower, upper));
}
else
#endif
{
CalculateTicks(lower, upper, false, maj_positions, maj_proportions, moreOrLessTickAdjustment);
CalculateTicks(lower, upper, true, min_positions, min_proportions, moreOrLessTickAdjustment);
}
}
void SetMajorTicks(const std::vector<vtkm::Float64> &pos, const std::vector<vtkm::Float64> &prop)
{
maj_positions.clear();
maj_positions.insert(maj_positions.begin(), pos.begin(), pos.end());
maj_proportions.clear();
maj_proportions.insert(maj_proportions.begin(), prop.begin(), prop.end());
}
void SetMinorTicks(const std::vector<vtkm::Float64> &pos, const std::vector<vtkm::Float64> &prop)
{
min_positions.clear();
min_positions.insert(min_positions.begin(), pos.begin(), pos.end());
VTKM_RENDERING_EXPORT
void SetMajorTicks(const std::vector<vtkm::Float64> &pos,
const std::vector<vtkm::Float64> &prop);
min_proportions.clear();
min_proportions.insert(min_proportions.begin(), prop.begin(), prop.end());
}
VTKM_RENDERING_EXPORT
void SetMinorTicks(const std::vector<vtkm::Float64> &pos,
const std::vector<vtkm::Float64> &prop);
VTKM_RENDERING_EXPORT
virtual void Render(const vtkm::rendering::Camera &camera,
const vtkm::rendering::WorldAnnotator &worldAnnotator,
vtkm::rendering::Canvas &canvas)
{
canvas.AddLine(x0,y0, x1,y1, linewidth, color);
// major ticks
unsigned int nmajor = (unsigned int)maj_proportions.size();
while (labels.size() < nmajor)
{
labels.push_back(new ScreenTextAnnotation("test",
color,
fontscale,
0,0, 0));
}
std::stringstream numberToString;
for (unsigned int i=0; i<nmajor; ++i)
{
vtkm::Float64 xc = x0 + (x1-x0) * maj_proportions[i];
vtkm::Float64 yc = y0 + (y1-y0) * maj_proportions[i];
vtkm::Float64 xs = xc - maj_tx*maj_toff;
vtkm::Float64 xe = xc + maj_tx*(1. - maj_toff);
vtkm::Float64 ys = yc - maj_ty*maj_toff;
vtkm::Float64 ye = yc + maj_ty*(1. - maj_toff);
canvas.AddLine(xs,ys, xe,ye, 1.0, color);
if (maj_ty == 0)
{
// slight shift to space between label and tick
xs -= (maj_tx<0?-1.:+1.) * fontscale * .1;
}
numberToString.str("");
numberToString << maj_positions[i];
labels[i]->SetText(numberToString.str());
//if (fabs(maj_positions[i]) < 1e-10)
// labels[i]->SetText("0");
((ScreenTextAnnotation*)(labels[i]))->SetPosition(vtkm::Float32(xs),
vtkm::Float32(ys));
labels[i]->SetAlignment(halign,valign);
}
// minor ticks
if (min_tx != 0 || min_ty != 0)
{
unsigned int nminor = (unsigned int)min_proportions.size();
for (unsigned int i=0; i<nminor; ++i)
{
vtkm::Float64 xc = x0 + (x1-x0) * min_proportions[i];
vtkm::Float64 yc = y0 + (y1-y0) * min_proportions[i];
vtkm::Float64 xs = xc - min_tx*min_toff;
vtkm::Float64 xe = xc + min_tx*(1. - min_toff);
vtkm::Float64 ys = yc - min_ty*min_toff;
vtkm::Float64 ye = yc + min_ty*(1. - min_toff);
canvas.AddLine(xs,ys, xe,ye, 1.0, color);
}
}
for (unsigned int i=0; i<nmajor; ++i)
{
labels[i]->Render(camera, worldAnnotator, canvas);
}
}
vtkm::rendering::Canvas &canvas);
};
}} //namespace vtkm::rendering

@ -43,6 +43,10 @@ set(headers
WorldAnnotator.h
)
set(sources
AxisAnnotation2D.cxx
)
set(opengl_headers
CanvasGL.h
MapperGL.h
@ -80,6 +84,11 @@ endif()
vtkm_declare_headers(${headers})
vtkm_library(SOURCES ${sources})
# Subclasses need rendering library
vtkm_configure_component_Rendering()
add_subdirectory(internal)
add_subdirectory(raytracing)