Move AxisAnnotation classes to rendering library

This commit is contained in:
Kenneth Moreland 2016-08-26 12:58:28 -06:00
parent 0c8919dc6a
commit 07df53d7d1
9 changed files with 506 additions and 345 deletions

@ -0,0 +1,150 @@
//============================================================================
// 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/AxisAnnotation.h>
#include <vtkm/cont/ErrorControlBadType.h>
namespace vtkm {
namespace rendering {
namespace {
inline vtkm::Float64 ffix(vtkm::Float64 value)
{
int ivalue = (int)(value);
vtkm::Float64 v = (value - ivalue);
if (v > 0.9999)
{
ivalue++;
}
return static_cast<vtkm::Float64>(ivalue);
}
} // anonymous namespace
void AxisAnnotation::CalculateTicks(const vtkm::Range &range,
bool minor,
std::vector<vtkm::Float64> &positions,
std::vector<vtkm::Float64> &proportions,
int modifyTickQuantity) const
{
positions.clear();
proportions.clear();
if (!range.IsNonEmpty()) { return; }
vtkm::Float64 length = range.Length();
// Find the integral points.
vtkm::Float64 pow10 = log10(length);
// Build in numerical tolerance
vtkm::Float64 eps = 10.0e-10;
pow10 += eps;
// ffix moves you in the wrong direction if pow10 is negative.
if (pow10 < 0.)
{
pow10 = pow10 - 1.;
}
vtkm::Float64 fxt = pow(10., ffix(pow10));
// Find the number of integral points in the interval.
int numTicks = int(ffix(length/fxt) + 1);
// We should get about major 10 ticks on a length that's near
// the power of 10. (e.g. length=1000). If the length is small
// enough we have less than 5 ticks (e.g. length=400), then
// divide the step by 2, or if it's about 2 ticks (e.g. length=150)
// or less, then divide the step by 5. That gets us back to
// about 10 major ticks.
//
// But we might want more or less. To adjust this up by
// approximately a factor of 2, instead of the default
// 1/2/5 dividers, use 2/5/10, and to adjust it down by
// about a factor of two, use .5/1/2 as the dividers.
// (We constrain to 1s, 2s, and 5s, for the obvious reason
// that only those values are factors of 10.....)
vtkm::Float64 divs[5] = { 0.5, 1, 2, 5, 10 };
int divindex = (numTicks >= 5) ? 1 : (numTicks >= 3 ? 2 : 3);
divindex += modifyTickQuantity;
vtkm::Float64 div = divs[divindex];
// If there aren't enough major tick points in this decade, use the next
// decade.
vtkm::Float64 majorStep = fxt / div;
vtkm::Float64 minorStep = (fxt/div) / 10.;
// When we get too close, we lose the tickmarks. Run some special case code.
if (numTicks <= 1)
{
if (minor)
{
// no minor ticks
return;
}
else
{
positions.resize(3);
proportions.resize(3);
positions[0] = range.Min;
positions[1] = range.Center();
positions[2] = range.Max;
proportions[0] = 0.0;
proportions[1] = 0.5;
proportions[2] = 1.0;
return;
}
}
// Figure out the first major and minor tick locations, relative to the
// start of the axis.
vtkm::Float64 majorStart, minorStart;
if (range.Min < 0.)
{
majorStart = majorStep*(ffix(range.Min*(1./majorStep)));
minorStart = minorStep*(ffix(range.Min*(1./minorStep)));
}
else
{
majorStart = majorStep*(ffix(range.Min*(1./majorStep) + .999));
minorStart = minorStep*(ffix(range.Min*(1./minorStep) + .999));
}
// Create all of the minor ticks
const int max_count_cutoff = 1000;
numTicks = 0;
vtkm::Float64 location = minor ? minorStart : majorStart;
vtkm::Float64 step = minor ? minorStep : majorStep;
while (location <= range.Max && numTicks < max_count_cutoff)
{
positions.push_back(location);
proportions.push_back((location - range.Min) / length);
numTicks++;
location += step;
}
}
}
} // namespace vtkm::rendering

@ -20,6 +20,8 @@
#ifndef vtk_m_rendering_AxisAnnotation_h
#define vtk_m_rendering_AxisAnnotation_h
#include <vtkm/rendering/vtkm_rendering_export.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/rendering/Color.h>
#include <vtkm/rendering/Scene.h>
@ -30,134 +32,18 @@ namespace rendering {
class AxisAnnotation
{
private:
protected:
inline vtkm::Float64 ffix(vtkm::Float64 value)
{
int ivalue = (int)(value);
vtkm::Float64 v = (value - ivalue);
if (v > 0.9999)
{
ivalue++;
}
return static_cast<vtkm::Float64>(ivalue);
}
void CalculateTicks(vtkm::Float64 lower, vtkm::Float64 upper, bool minor,
void CalculateTicks(const vtkm::Range &range,
bool minor,
std::vector<vtkm::Float64> &positions,
std::vector<vtkm::Float64> &proportions,
int modifyTickQuantity)
{
positions.clear();
proportions.clear();
int modifyTickQuantity) const;
vtkm::Float64 sortedRange[2];
sortedRange[0] = lower < upper ? lower : upper;
sortedRange[1] = lower > upper ? lower : upper;
vtkm::Float64 range = sortedRange[1] - sortedRange[0];
// Find the integral points.
vtkm::Float64 pow10 = log10(range);
// Build in numerical tolerance
vtkm::Float64 eps = 10.0e-10;
pow10 += eps;
// ffix moves you in the wrong direction if pow10 is negative.
if (pow10 < 0.)
{
pow10 = pow10 - 1.;
}
vtkm::Float64 fxt = pow(10., ffix(pow10));
// Find the number of integral points in the interval.
int numTicks = int(ffix(range/fxt) + 1);
// We should get about major 10 ticks on a range that's near
// the power of 10. (e.g. range=1000). If the range is small
// enough we have less than 5 ticks (e.g. range=400), then
// divide the step by 2, or if it's about 2 ticks (e.g. range=150)
// or less, then divide the step by 5. That gets us back to
// about 10 major ticks.
//
// But we might want more or less. To adjust this up by
// approximately a factor of 2, instead of the default
// 1/2/5 dividers, use 2/5/10, and to adjust it down by
// about a factor of two, use .5/1/2 as the dividers.
// (We constrain to 1s, 2s, and 5s, for the obvious reason
// that only those values are factors of 10.....)
vtkm::Float64 divs[5] = { 0.5, 1, 2, 5, 10 };
int divindex = (numTicks >= 5) ? 1 : (numTicks >= 3 ? 2 : 3);
divindex += modifyTickQuantity;
vtkm::Float64 div = divs[divindex];
// If there aren't enough major tick points in this decade, use the next
// decade.
vtkm::Float64 majorStep = fxt / div;
vtkm::Float64 minorStep = (fxt/div) / 10.;
// When we get too close, we lose the tickmarks. Run some special case code.
if (numTicks <= 1)
{
if (minor)
{
// no minor ticks
return;
}
else
{
positions.resize(3);
proportions.resize(3);
positions[0] = lower;
positions[1] = (lower+upper) / 2.;
positions[2] = upper;
proportions[0] = 0.0;
proportions[1] = 0.5;
proportions[2] = 1.0;
return;
}
}
// Figure out the first major and minor tick locations, relative to the
// start of the axis.
vtkm::Float64 majorStart, minorStart;
if (sortedRange[0] < 0.)
{
majorStart = majorStep*(ffix(sortedRange[0]*(1./majorStep)));
minorStart = minorStep*(ffix(sortedRange[0]*(1./minorStep)));
}
else
{
majorStart = majorStep*(ffix(sortedRange[0]*(1./majorStep) + .999));
minorStart = minorStep*(ffix(sortedRange[0]*(1./minorStep) + .999));
}
// Create all of the minor ticks
const int max_count_cutoff = 1000;
numTicks = 0;
vtkm::Float64 location = minor ? minorStart : majorStart;
vtkm::Float64 step = minor ? minorStep : majorStep;
while (location <= sortedRange[1] && numTicks < max_count_cutoff)
{
positions.push_back(location);
proportions.push_back((location - sortedRange[0]) / range);
numTicks++;
location += step;
}
if (sortedRange[0] != lower)
{
// We must reverse all of the proportions.
for (unsigned int j = 0 ; j < proportions.size(); j++)
{
proportions[j] = 1. - proportions[j];
}
}
}
public:
VTKM_RENDERING_EXPORT
virtual void Render(const vtkm::rendering::Camera &camera,
const vtkm::rendering::WorldAnnotator &worldAnnotator,
vtkm::rendering::Canvas &canvas) = 0;
};

@ -20,6 +20,8 @@
#include <vtkm/rendering/AxisAnnotation2D.h>
#include <sstream>
namespace vtkm {
namespace rendering {
@ -63,14 +65,12 @@ void AxisAnnotation2D::SetRangeForAutoTicks(const Range &range)
else
#endif
{
CalculateTicks(this->TickRange.Min,
this->TickRange.Max,
CalculateTicks(this->TickRange,
false,
this->PositionsMajor,
this->ProportionsMajor,
this->MoreOrLessTickAdjustment);
CalculateTicks(this->TickRange.Min,
this->TickRange.Max,
CalculateTicks(this->TickRange,
true,
this->PositionsMinor,
this->ProportionsMinor,

@ -22,20 +22,15 @@
#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/AxisAnnotation.h>
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/Canvas.h>
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/Color.h>
#include <vtkm/rendering/WorldAnnotator.h>
#include <vtkm/rendering/TextAnnotation.h>
#include <sstream>
namespace vtkm {
namespace rendering {
@ -160,9 +155,9 @@ public:
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);
void Render(const vtkm::rendering::Camera &camera,
const vtkm::rendering::WorldAnnotator &worldAnnotator,
vtkm::rendering::Canvas &canvas) VTKM_OVERRIDE;
};
}} //namespace vtkm::rendering

@ -0,0 +1,190 @@
//============================================================================
// 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/AxisAnnotation3D.h>
namespace vtkm {
namespace rendering {
AxisAnnotation3D::AxisAnnotation3D()
: AxisAnnotation(),
TickMajorSize(1.0),
TickMajorOffset(1.0),
TickMinorSize(0.1),
TickMinorOffset(1.0),
Axis(0),
Invert(1, 1, 1),
Point0(0, 0, 0),
Point1(1, 0, 0),
Range(0, 1),
FontScale(0.05f), // screen space font size
FontOffset(0.1f), // world space offset from axis
LineWidth(1.0),
Color(1,1,1),
MoreOrLessTickAdjustment(0)
{ }
AxisAnnotation3D::~AxisAnnotation3D()
{ }
void AxisAnnotation3D::SetTickInvert(bool x, bool y, bool z)
{
this->Invert[0] = x ? +1.0f : -1.0f;
this->Invert[1] = y ? +1.0f : -1.0f;
this->Invert[2] = z ? +1.0f : -1.0f;
}
void AxisAnnotation3D::SetLabelFontScale(Float64 s)
{
this->FontScale = s;
for (unsigned int i=0; i<this->Labels.size(); i++)
{
this->Labels[i]->SetScale(vtkm::Float32(s));
}
}
void AxisAnnotation3D::Render(const Camera &camera,
const WorldAnnotator &worldAnnotator,
Canvas &canvas)
{
bool infront = true;
worldAnnotator.AddLine(this->Point0,this->Point1,this->LineWidth,this->Color,infront);
std::vector<vtkm::Float64> positions;
std::vector<vtkm::Float64> proportions;
// major ticks
CalculateTicks(this->Range, false, positions, proportions, this->MoreOrLessTickAdjustment);
unsigned int nmajor = (unsigned int)proportions.size();
while (this->Labels.size() < nmajor)
{
this->Labels.push_back(new BillboardTextAnnotation("test",
this->Color,
vtkm::Float32(this->FontScale),
0,0,0,
0));
}
std::stringstream numberToString;
for (unsigned int i=0; i<nmajor; ++i)
{
vtkm::Vec<vtkm::Float64,3> tickPos =
proportions[i]*(this->Point1-this->Point0) + this->Point0;
for (int pass=0; pass<=1; pass++)
{
vtkm::Vec<vtkm::Float64,3> tickSize(0);
if (pass == 0)
{
switch (this->Axis)
{
case 0: tickSize[1] = this->TickMajorSize; break;
case 1: tickSize[0] = this->TickMajorSize; break;
case 2: tickSize[0] = this->TickMajorSize; break;
}
}
else // pass == 1
{
switch (this->Axis)
{
case 0: tickSize[2] = this->TickMajorSize; break;
case 1: tickSize[2] = this->TickMajorSize; break;
case 2: tickSize[1] = this->TickMajorSize; break;
}
}
tickSize = tickSize * this->Invert;
vtkm::Vec<vtkm::Float64,3> start =
tickPos - tickSize*this->TickMajorOffset;
vtkm::Vec<vtkm::Float64,3> end =
tickPos - tickSize*(1.0 - this->TickMajorOffset);
worldAnnotator.AddLine(start,
end,
this->LineWidth,
this->Color,
infront);
}
vtkm::Vec<vtkm::Float32,3> tickSize(0);
vtkm::Float32 s = 0.4f * this->FontOffset;
switch (this->Axis)
{
case 0: tickSize[1]=s; tickSize[2]=s; break;
case 1: tickSize[0]=s; tickSize[2]=s; break;
case 2: tickSize[0]=s; tickSize[1]=s; break;
}
tickSize = tickSize * this->Invert;
numberToString.str("");
numberToString << positions[i];
this->Labels[i]->SetText(numberToString.str());
//if (fabs(positions[i]) < 1e-10)
// this->Labels[i]->SetText("0");
this->Labels[i]->SetPosition(vtkm::Float32(tickPos[0] - tickSize[0]),
vtkm::Float32(tickPos[1] - tickSize[1]),
vtkm::Float32(tickPos[2] - tickSize[2]));
this->Labels[i]->SetAlignment(TextAnnotation::HCenter,
TextAnnotation::VCenter);
}
// minor ticks
CalculateTicks(this->Range, true, positions, proportions, this->MoreOrLessTickAdjustment);
unsigned int nminor = (unsigned int)proportions.size();
for (unsigned int i=0; i<nminor; ++i)
{
vtkm::Vec<vtkm::Float64,3> tickPos =
proportions[i]*(this->Point1-this->Point0) + this->Point0;
for (int pass=0; pass<=1; pass++)
{
vtkm::Vec<vtkm::Float64,3> tickSize(0);
if (pass == 0)
{
switch (this->Axis)
{
case 0: tickSize[1] = this->TickMajorSize; break;
case 1: tickSize[0] = this->TickMajorSize; break;
case 2: tickSize[0] = this->TickMajorSize; break;
}
}
else // pass == 1
{
switch (this->Axis)
{
case 0: tickSize[2] = this->TickMajorSize; break;
case 1: tickSize[2] = this->TickMajorSize; break;
case 2: tickSize[1] = this->TickMajorSize; break;
}
}
tickSize = tickSize * this->Invert;
vtkm::Vec<vtkm::Float64,3> start =
tickPos - tickSize*this->TickMinorOffset;
vtkm::Vec<vtkm::Float64,3> end =
tickPos - tickSize*(1.0 - this->TickMinorOffset);
worldAnnotator.AddLine(start, end, this->LineWidth, this->Color, infront);
}
}
for (unsigned int i=0; i<nmajor; ++i)
{
this->Labels[i]->Render(camera, worldAnnotator, canvas);
}
}
}
} // namespace vtkm::rendering

@ -20,6 +20,9 @@
#ifndef vtk_m_rendering_AxisAnnotation3D_h
#define vtk_m_rendering_AxisAnnotation3D_h
#include <vtkm/rendering/vtkm_rendering_export.h>
#include <vtkm/Range.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/Color.h>
@ -37,204 +40,102 @@ class AxisAnnotation3D : public AxisAnnotation
{
private:
protected:
vtkm::Float64 maj_size, maj_toff;
vtkm::Float64 min_size, min_toff;
int axis;
vtkm::Float32 invertx, inverty, invertz;
vtkm::Float64 x0, y0, z0, x1, y1, z1;
vtkm::Float64 lower, upper;
vtkm::Float64 fontscale;
vtkm::Float32 fontoffset;
vtkm::Float32 linewidth;
vtkm::rendering::Color color;
std::vector<BillboardTextAnnotation*> labels;
int moreOrLessTickAdjustment;
vtkm::Float64 TickMajorSize, TickMajorOffset;
vtkm::Float64 TickMinorSize, TickMinorOffset;
int Axis;
vtkm::Vec<vtkm::Float32,3> Invert;
vtkm::Vec<vtkm::Float64,3> Point0, Point1;
vtkm::Range Range;
vtkm::Float64 FontScale;
vtkm::Float32 FontOffset;
vtkm::Float32 LineWidth;
vtkm::rendering::Color Color;
std::vector<BillboardTextAnnotation*> Labels;
int MoreOrLessTickAdjustment;
public:
AxisAnnotation3D() : AxisAnnotation()
{
axis = 0;
color = Color(1,1,1);
fontoffset = 0.1f; // world space offset from axis
fontscale = 0.05; // screen space font size
linewidth = 1.0;
color = Color(1,1,1);
moreOrLessTickAdjustment = 0;
}
virtual ~AxisAnnotation3D()
{
}
VTKM_RENDERING_EXPORT
AxisAnnotation3D();
VTKM_RENDERING_EXPORT
virtual ~AxisAnnotation3D();
VTKM_CONT_EXPORT
void SetMoreOrLessTickAdjustment(int offset)
{
moreOrLessTickAdjustment = offset;
this->MoreOrLessTickAdjustment = offset;
}
VTKM_CONT_EXPORT
void SetColor(vtkm::rendering::Color c)
{
color = c;
this->Color = c;
}
VTKM_CONT_EXPORT
void SetAxis(int a)
{
axis = a;
}
void SetTickInvert(bool x, bool y, bool z)
{
invertx = x ? +1.0f : -1.0f;
inverty = y ? +1.0f : -1.0f;
invertz = z ? +1.0f : -1.0f;
this->Axis = a;
}
VTKM_RENDERING_EXPORT
void SetTickInvert(bool x, bool y, bool z);
/// 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
VTKM_CONT_EXPORT
void SetMajorTickSize(vtkm::Float64 size, 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_size = size;
maj_toff = offset;
this->TickMajorSize = size;
this->TickMajorOffset = offset;
}
VTKM_CONT_EXPORT
void SetMinorTickSize(vtkm::Float64 size, vtkm::Float64 offset)
{
min_size = size;
min_toff = offset;
this->TickMinorSize = size;
this->TickMinorOffset = offset;
}
void SetWorldPosition(vtkm::Float64 x0_, vtkm::Float64 y0_, vtkm::Float64 z0_,
vtkm::Float64 x1_, vtkm::Float64 y1_, vtkm::Float64 z1_)
{
x0 = x0_;
y0 = y0_;
z0 = z0_;
x1 = x1_;
y1 = y1_;
z1 = z1_;
}
void SetLabelFontScale(vtkm::Float64 s)
VTKM_CONT_EXPORT
void SetWorldPosition(const vtkm::Vec<vtkm::Float64,3> &point0,
const vtkm::Vec<vtkm::Float64,3> &point1)
{
fontscale = s;
for (unsigned int i=0; i<labels.size(); i++)
labels[i]->SetScale(vtkm::Float32(s));
this->Point0 = point0;
this->Point1 = point1;
}
VTKM_CONT_EXPORT
void SetWorldPosition(vtkm::Float64 x0, vtkm::Float64 y0, vtkm::Float64 z0,
vtkm::Float64 x1, vtkm::Float64 y1, vtkm::Float64 z1)
{
this->SetWorldPosition(vtkm::make_Vec(x0,y0,z0), vtkm::make_Vec(x1,y1,z1));
}
VTKM_RENDERING_EXPORT
void SetLabelFontScale(vtkm::Float64 s);
VTKM_RENDERING_EXPORT
void SetLabelFontOffset(vtkm::Float32 off)
{
fontoffset = off;
this->FontOffset = off;
}
void SetRange(vtkm::Float64 l, vtkm::Float64 u)
VTKM_RENDERING_EXPORT
void SetRange(const vtkm::Range &range)
{
lower = l;
upper = u;
this->Range = range;
}
VTKM_RENDERING_EXPORT
void SetRange(vtkm::Float64 lower, vtkm::Float64 upper)
{
this->SetRange(vtkm::Range(lower, upper));
}
virtual void Render(const vtkm::rendering::Camera &camera,
const vtkm::rendering::WorldAnnotator &worldAnnotator,
vtkm::rendering::Canvas &canvas)
{
bool infront = true;
worldAnnotator.AddLine(x0,y0,z0,
x1,y1,z1,
linewidth, color, infront);
std::vector<vtkm::Float64> positions;
std::vector<vtkm::Float64> proportions;
// major ticks
CalculateTicks(lower, upper, false, positions, proportions, moreOrLessTickAdjustment);
unsigned int nmajor = (unsigned int)proportions.size();
while (labels.size() < nmajor)
{
labels.push_back(new BillboardTextAnnotation("test",
color,
vtkm::Float32(fontscale),
0,0,0,
0));
}
std::stringstream numberToString;
for (unsigned int i=0; i<nmajor; ++i)
{
vtkm::Float64 xc = x0 + (x1-x0) * proportions[i];
vtkm::Float64 yc = y0 + (y1-y0) * proportions[i];
vtkm::Float64 zc = z0 + (z1-z0) * proportions[i];
for (int pass=0; pass<=1; pass++)
{
vtkm::Float64 tx=0, ty=0, tz=0;
switch (axis)
{
case 0: if (pass==0) ty=maj_size; else tz=maj_size; break;
case 1: if (pass==0) tx=maj_size; else tz=maj_size; break;
case 2: if (pass==0) tx=maj_size; else ty=maj_size; break;
}
tx *= invertx;
ty *= inverty;
tz *= invertz;
vtkm::Float64 xs = xc - tx*maj_toff;
vtkm::Float64 xe = xc + tx*(1. - maj_toff);
vtkm::Float64 ys = yc - ty*maj_toff;
vtkm::Float64 ye = yc + ty*(1. - maj_toff);
vtkm::Float64 zs = zc - tz*maj_toff;
vtkm::Float64 ze = zc + tz*(1. - maj_toff);
worldAnnotator.AddLine(xs,ys,zs,
xe,ye,ze,
linewidth, color, infront);
}
vtkm::Float32 tx=0, ty=0, tz=0;
const vtkm::Float32 s = 0.4f;
switch (axis)
{
case 0: ty=s*fontoffset; tz=s*fontoffset; break;
case 1: tx=s*fontoffset; tz=s*fontoffset; break;
case 2: tx=s*fontoffset; ty=s*fontoffset; break;
}
tx *= invertx;
ty *= inverty;
tz *= invertz;
numberToString.str("");
numberToString << positions[i];
labels[i]->SetText(numberToString.str());
//if (fabs(positions[i]) < 1e-10)
// labels[i]->SetText("0");
labels[i]->SetPosition(vtkm::Float32(xc - tx),
vtkm::Float32(yc - ty),
vtkm::Float32(zc - tz));
labels[i]->SetAlignment(TextAnnotation::HCenter,
TextAnnotation::VCenter);
}
// minor ticks
CalculateTicks(lower, upper, true, positions, proportions, moreOrLessTickAdjustment);
unsigned int nminor = (unsigned int)proportions.size();
for (unsigned int i=0; i<nminor; ++i)
{
vtkm::Float64 xc = x0 + (x1-x0) * proportions[i];
vtkm::Float64 yc = y0 + (y1-y0) * proportions[i];
vtkm::Float64 zc = z0 + (z1-z0) * proportions[i];
for (int pass=0; pass<=1; pass++)
{
vtkm::Float64 tx=0, ty=0, tz=0;
switch (axis)
{
case 0: if (pass==0) ty=min_size; else tz=min_size; break;
case 1: if (pass==0) tx=min_size; else tz=min_size; break;
case 2: if (pass==0) tx=min_size; else ty=min_size; break;
}
tx *= invertx;
ty *= inverty;
tz *= invertz;
vtkm::Float64 xs = xc - tx*min_toff;
vtkm::Float64 xe = xc + tx*(1. - min_toff);
vtkm::Float64 ys = yc - ty*min_toff;
vtkm::Float64 ye = yc + ty*(1. - min_toff);
vtkm::Float64 zs = zc - tz*min_toff;
vtkm::Float64 ze = zc + tz*(1. - min_toff);
worldAnnotator.AddLine(xs,ys,zs,
xe,ye,ze,
linewidth, color, infront);
}
}
for (unsigned int i=0; i<nmajor; ++i)
{
labels[i]->Render(camera, worldAnnotator, canvas);
}
}
vtkm::rendering::Canvas &canvas) VTKM_OVERRIDE;
};

@ -44,7 +44,9 @@ set(headers
)
set(sources
AxisAnnotation.cxx
AxisAnnotation2D.cxx
AxisAnnotation3D.cxx
)
set(opengl_headers

@ -31,18 +31,54 @@ class WorldAnnotator
public:
virtual ~WorldAnnotator() { }
virtual void AddLine(vtkm::Float64, vtkm::Float64, vtkm::Float64,
vtkm::Float64, vtkm::Float64, vtkm::Float64,
vtkm::Float32,
const vtkm::rendering::Color &,
bool=false) const {}
virtual void AddText(vtkm::Float32, vtkm::Float32, vtkm::Float32,
vtkm::Float32, vtkm::Float32, vtkm::Float32,
vtkm::Float32, vtkm::Float32, vtkm::Float32,
vtkm::Float32,
vtkm::Float32, vtkm::Float32,
Color,
std::string) const {}
virtual void AddLine(const vtkm::Vec<vtkm::Float64,3> &vtkmNotUsed(point0),
const vtkm::Vec<vtkm::Float64,3> &vtkmNotUsed(point1),
vtkm::Float32 vtkmNotUsed(lineWidth),
const vtkm::rendering::Color &vtkmNotUsed(color),
bool vtkmNotUsed(inFront) = false) const {}
void AddLine(vtkm::Float64 x0, vtkm::Float64 y0, vtkm::Float64 z0,
vtkm::Float64 x1, vtkm::Float64 y1, vtkm::Float64 z1,
vtkm::Float32 lineWidth,
const vtkm::rendering::Color &color,
bool inFront = false) const
{
this->AddLine(vtkm::make_Vec(x0,y0,z0),
vtkm::make_Vec(x1,y1,z1),
lineWidth,
color,
inFront);
}
virtual void AddText(const vtkm::Vec<vtkm::Float32,3> &vtkmNotUsed(origin),
const vtkm::Vec<vtkm::Float32,3> &vtkmNotUsed(right),
const vtkm::Vec<vtkm::Float32,3> &vtkmNotUsed(up),
vtkm::Float32 vtkmNotUsed(scale),
const vtkm::Vec<vtkm::Float32,2> &vtkmNotUsed(anchor),
const vtkm::rendering::Color &vtkmNotUsed(color),
const std::string &vtkmNotUsed(text)) const { }
void AddText(vtkm::Float32 originX,
vtkm::Float32 originY,
vtkm::Float32 originZ,
vtkm::Float32 rightX,
vtkm::Float32 rightY,
vtkm::Float32 rightZ,
vtkm::Float32 upX,
vtkm::Float32 upY,
vtkm::Float32 upZ,
vtkm::Float32 scale,
vtkm::Float32 anchorX,
vtkm::Float32 anchorY,
const vtkm::rendering::Color &color,
const std::string &text) const
{
this->AddText(vtkm::make_Vec(originX, originY, originZ),
vtkm::make_Vec(rightX, rightY, rightZ),
vtkm::make_Vec(upX, upY, upZ),
scale,
vtkm::make_Vec(anchorX, anchorY),
color,
text);
}
};
}} //namespace vtkm::rendering

@ -38,55 +38,56 @@ namespace rendering {
class WorldAnnotatorGL : public WorldAnnotator
{
public:
virtual void AddLine(vtkm::Float64 x0, vtkm::Float64 y0, vtkm::Float64 z0,
vtkm::Float64 x1, vtkm::Float64 y1, vtkm::Float64 z1,
vtkm::Float32 linewidth,
const vtkm::rendering::Color &c,
bool infront) const
virtual void AddLine(const vtkm::Vec<vtkm::Float64,3> &point0,
const vtkm::Vec<vtkm::Float64,3> &point1,
vtkm::Float32 lineWidth,
const vtkm::rendering::Color &color,
bool inFront) const
{
if (infront)
if (inFront)
{
glDepthRange(-.0001,.9999);
}
glDisable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glColor3f(c.Components[0], c.Components[1], c.Components[2]);
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
glLineWidth(linewidth);
glLineWidth(lineWidth);
glBegin(GL_LINES);
glVertex3d(x0,y0,z0);
glVertex3d(x1,y1,z1);
glVertex3d(point0[0], point0[1], point0[2]);
glVertex3d(point1[0], point1[1], point1[2]);
glEnd();
if (infront)
if (inFront)
{
glDepthRange(0,1);
}
}
virtual void AddText(vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz,
vtkm::Float32 rx, vtkm::Float32 ry, vtkm::Float32 rz,
vtkm::Float32 ux, vtkm::Float32 uy, vtkm::Float32 uz,
virtual void AddText(const vtkm::Vec<vtkm::Float32,3> &origin,
const vtkm::Vec<vtkm::Float32,3> &right,
const vtkm::Vec<vtkm::Float32,3> &up,
vtkm::Float32 scale,
vtkm::Float32 anchorx, vtkm::Float32 anchory,
Color color,
std::string text) const
const vtkm::Vec<vtkm::Float32,2> &anchor,
const vtkm::rendering::Color &color,
const std::string &text) const
{
vtkm::Vec<vtkm::Float32,3> o(ox,oy,oz);
vtkm::Vec<vtkm::Float32,3> r(rx,ry,rz);
vtkm::Vec<vtkm::Float32,3> u(ux,uy,uz);
vtkm::Vec<vtkm::Float32,3> n = vtkm::Cross(r,u);
vtkm::Vec<vtkm::Float32,3> n = vtkm::Cross(right,up);
vtkm::Normalize(n);
vtkm::Matrix<vtkm::Float32,4,4> m;
m = MatrixHelpers::WorldMatrix(o, r, u, n);
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, anchorx, anchory, text);
this->RenderText(scale, anchor[0], anchor[1], text);
glPopMatrix();
}