text annotations almost working, pending one texture bug fix
This commit is contained in:
parent
854cbf5c7f
commit
230650c02b
@ -28,6 +28,7 @@
|
||||
#include <vtkm/rendering/RenderSurface.h>
|
||||
#include <vtkm/rendering/WorldAnnotator.h>
|
||||
#include <vtkm/rendering/AxisAnnotation.h>
|
||||
#include <vtkm/rendering/TextAnnotation.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
@ -39,15 +40,15 @@ protected:
|
||||
vtkm::Float64 min_tx, min_ty, min_toff;
|
||||
vtkm::Float64 x0, y0, x1, y1;
|
||||
vtkm::Float64 lower, upper;
|
||||
vtkm::Float64 fontscale;
|
||||
vtkm::Float32 fontscale;
|
||||
vtkm::Float32 linewidth;
|
||||
vtkm::rendering::Color color;
|
||||
bool logarithmic;
|
||||
#if 0
|
||||
eavlTextAnnotation::HorizontalAlignment halign;
|
||||
eavlTextAnnotation::VerticalAlignment valign;
|
||||
std::vector<eavlTextAnnotation*> labels;
|
||||
#endif
|
||||
|
||||
TextAnnotation::HorizontalAlignment halign;
|
||||
TextAnnotation::VerticalAlignment valign;
|
||||
std::vector<TextAnnotation*> labels;
|
||||
|
||||
|
||||
std::vector<vtkm::Float64> maj_positions;
|
||||
std::vector<vtkm::Float64> maj_proportions;
|
||||
@ -55,23 +56,17 @@ protected:
|
||||
std::vector<vtkm::Float64> min_positions;
|
||||
std::vector<vtkm::Float64> min_proportions;
|
||||
|
||||
///\todo: Don't need anymore??
|
||||
bool worldSpace;
|
||||
|
||||
int moreOrLessTickAdjustment;
|
||||
public:
|
||||
AxisAnnotation2D() : AxisAnnotation()
|
||||
{
|
||||
#if 0
|
||||
halign = eavlTextAnnotation::HCenter;
|
||||
valign = eavlTextAnnotation::VCenter;
|
||||
#endif
|
||||
fontscale = 0.05;
|
||||
halign = TextAnnotation::HCenter;
|
||||
valign = TextAnnotation::VCenter;
|
||||
fontscale = 0.05f;
|
||||
linewidth = 1.0;
|
||||
color = Color(1,1,1);
|
||||
logarithmic = false;
|
||||
moreOrLessTickAdjustment = 0;
|
||||
worldSpace = false;
|
||||
}
|
||||
virtual ~AxisAnnotation2D()
|
||||
{
|
||||
@ -82,10 +77,6 @@ public:
|
||||
logarithmic = l;
|
||||
}
|
||||
#endif
|
||||
void SetWorldSpace(bool ws)
|
||||
{
|
||||
worldSpace = ws;
|
||||
}
|
||||
void SetMoreOrLessTickAdjustment(int offset)
|
||||
{
|
||||
moreOrLessTickAdjustment = offset;
|
||||
@ -123,21 +114,17 @@ public:
|
||||
x1 = x1_;
|
||||
y1 = y1_;
|
||||
}
|
||||
#if 0
|
||||
void SetLabelAlignment(eavlTextAnnotation::HorizontalAlignment h,
|
||||
eavlTextAnnotation::VerticalAlignment v)
|
||||
void SetLabelAlignment(TextAnnotation::HorizontalAlignment h,
|
||||
TextAnnotation::VerticalAlignment v)
|
||||
{
|
||||
halign = h;
|
||||
valign = v;
|
||||
}
|
||||
#endif
|
||||
void SetLabelFontScale(vtkm::Float64 s)
|
||||
void SetLabelFontScale(vtkm::Float32 s)
|
||||
{
|
||||
fontscale = s;
|
||||
#if 0
|
||||
for (unsigned int i=0; i<labels.size(); i++)
|
||||
labels[i]->SetScale(s);
|
||||
#endif
|
||||
}
|
||||
void SetRangeForAutoTicks(vtkm::Float64 l, vtkm::Float64 u)
|
||||
{
|
||||
@ -173,33 +160,22 @@ public:
|
||||
min_proportions.clear();
|
||||
min_proportions.insert(min_proportions.begin(), prop.begin(), prop.end());
|
||||
}
|
||||
virtual void Render(View &,
|
||||
WorldAnnotator &,
|
||||
virtual void Render(View &view,
|
||||
WorldAnnotator &worldAnnotator,
|
||||
RenderSurface &renderSurface)
|
||||
{
|
||||
renderSurface.AddLine(x0,y0, x1,y1, linewidth, color);
|
||||
|
||||
// major ticks
|
||||
unsigned int nmajor = (unsigned int)maj_proportions.size();
|
||||
#if 0
|
||||
while (labels.size() < nmajor)
|
||||
{
|
||||
if (worldSpace)
|
||||
{
|
||||
labels.push_back(new eavlBillboardTextAnnotation(win,"test",
|
||||
color,
|
||||
fontscale,
|
||||
0,0,0, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
labels.push_back(new eavlScreenTextAnnotation(win,"test",
|
||||
color,
|
||||
fontscale,
|
||||
0,0, 0));
|
||||
}
|
||||
labels.push_back(new ScreenTextAnnotation("test",
|
||||
color,
|
||||
fontscale,
|
||||
0,0, 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
for (unsigned int i=0; i<nmajor; ++i)
|
||||
{
|
||||
vtkm::Float64 xc = x0 + (x1-x0) * maj_proportions[i];
|
||||
@ -220,17 +196,12 @@ public:
|
||||
char val[256];
|
||||
snprintf(val, 256, "%g", maj_positions[i]);
|
||||
|
||||
#if 0
|
||||
labels[i]->SetText(val);
|
||||
//if (fabs(maj_positions[i]) < 1e-10)
|
||||
// labels[i]->SetText("0");
|
||||
if (worldSpace)
|
||||
((eavlBillboardTextAnnotation*)(labels[i]))->SetPosition(xs,ys,0);
|
||||
else
|
||||
((eavlScreenTextAnnotation*)(labels[i]))->SetPosition(xs,ys);
|
||||
((ScreenTextAnnotation*)(labels[i]))->SetPosition(xs,ys);
|
||||
|
||||
labels[i]->SetAlignment(halign,valign);
|
||||
#endif
|
||||
}
|
||||
|
||||
// minor ticks
|
||||
@ -250,13 +221,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
for (int i=0; i<nmajor; ++i)
|
||||
{
|
||||
labels[i]->Render(view);
|
||||
labels[i]->Render(view, worldAnnotator, renderSurface);
|
||||
///\todo: REMOVE THIS BREAK
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
axis.SetScreenPosition(l,b, r,b);
|
||||
axis.SetMajorTickSize(0, .02, 1.0);
|
||||
axis.SetMinorTickSize(0,0,0); // no minor ticks
|
||||
axis.SetLabelAlignment(TextAnnotation::HCenter,
|
||||
TextAnnotation::Top);
|
||||
axis.Render(view, worldAnnotator, renderSurface);
|
||||
}
|
||||
};
|
||||
|
@ -249,8 +249,10 @@ public:
|
||||
private:
|
||||
void RenderText(float scale, float anchorx, float anchory, std::string text)
|
||||
{
|
||||
std::cerr << "Doing RenderText ("<<text<<")\n";
|
||||
static BitmapFont font = BitmapFontFactory::CreateLiberation2Sans();
|
||||
static TextureGL tex;
|
||||
std::cerr << "tex.id="<<tex.id<<"\n";
|
||||
if (tex.id == 0)
|
||||
{
|
||||
std::vector<unsigned char> &rawpngdata = font.GetRawImageData();
|
||||
@ -310,6 +312,8 @@ private:
|
||||
|
||||
glEnd();
|
||||
|
||||
tex.Disable();
|
||||
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
144
vtkm/rendering/TextAnnotation.h
Normal file
144
vtkm/rendering/TextAnnotation.h
Normal file
@ -0,0 +1,144 @@
|
||||
//============================================================================
|
||||
// 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_TextAnnotation_h
|
||||
#define vtk_m_rendering_TextAnnotation_h
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/rendering/ColorTable.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/RenderSurface.h>
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
class TextAnnotation
|
||||
{
|
||||
public:
|
||||
enum HorizontalAlignment
|
||||
{
|
||||
Left,
|
||||
HCenter,
|
||||
Right
|
||||
};
|
||||
enum VerticalAlignment
|
||||
{
|
||||
Bottom,
|
||||
VCenter,
|
||||
Top
|
||||
};
|
||||
|
||||
protected:
|
||||
std::string text;
|
||||
Color color;
|
||||
vtkm::Float32 scale;
|
||||
vtkm::Float32 anchorx, anchory;
|
||||
|
||||
public:
|
||||
TextAnnotation(const std::string &txt, Color c, vtkm::Float32 s)
|
||||
: text(txt), color(c), scale(s)
|
||||
{
|
||||
// default anchor: bottom-left
|
||||
anchorx = -1;
|
||||
anchory = -1;
|
||||
}
|
||||
virtual ~TextAnnotation()
|
||||
{
|
||||
}
|
||||
void SetText(const std::string &txt)
|
||||
{
|
||||
text = txt;
|
||||
}
|
||||
void SetRawAnchor(vtkm::Float32 h, vtkm::Float32 v)
|
||||
{
|
||||
anchorx = h;
|
||||
anchory = v;
|
||||
}
|
||||
void SetAlignment(HorizontalAlignment h, VerticalAlignment v)
|
||||
{
|
||||
switch (h)
|
||||
{
|
||||
case Left: anchorx = -1.0f; break;
|
||||
case HCenter: anchorx = 0.0f; break;
|
||||
case Right: anchorx = +1.0f; break;
|
||||
}
|
||||
|
||||
// For vertical alignment, "center" is generally the center
|
||||
// of only the above-baseline contents of the font, so we
|
||||
// use a value slightly off of zero for VCenter.
|
||||
// (We don't use an offset value instead of -1.0 for the
|
||||
// bottom value, because generally we want a true minimum
|
||||
// extent, e.g. to have text sitting at the bottom of a
|
||||
// window, and in that case, we need to keep all the text,
|
||||
// including parts that descend below the baseline, above
|
||||
// the bottom of the window.
|
||||
switch (v)
|
||||
{
|
||||
case Bottom: anchory = -1.0f; break;
|
||||
case VCenter: anchory = -0.06f; break;
|
||||
case Top: anchory = +1.0f; break;
|
||||
}
|
||||
}
|
||||
void SetScale(vtkm::Float32 s)
|
||||
{
|
||||
scale = s;
|
||||
}
|
||||
virtual void Render(View &view,
|
||||
WorldAnnotator &worldAnnotator,
|
||||
RenderSurface &renderSurface) = 0;
|
||||
};
|
||||
|
||||
class ScreenTextAnnotation : public TextAnnotation
|
||||
{
|
||||
protected:
|
||||
vtkm::Float32 x,y;
|
||||
vtkm::Float32 angle;
|
||||
public:
|
||||
ScreenTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s,
|
||||
vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 angleDeg = 0.)
|
||||
: TextAnnotation(txt,c,s)
|
||||
{
|
||||
x = ox;
|
||||
y = oy;
|
||||
angle = angleDeg;
|
||||
}
|
||||
void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy)
|
||||
{
|
||||
x = ox;
|
||||
y = oy;
|
||||
}
|
||||
virtual void Render(View &view,
|
||||
WorldAnnotator &,
|
||||
RenderSurface &renderSurface)
|
||||
{
|
||||
vtkm::Float32 WindowAspect = vtkm::Float32(view.Width) /
|
||||
vtkm::Float32(view.Height);
|
||||
|
||||
//win->SetupForScreenSpace();
|
||||
renderSurface.AddText(x,y,
|
||||
scale,
|
||||
angle,
|
||||
WindowAspect,
|
||||
anchorx, anchory,
|
||||
color, text);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
#endif //vtk_m_rendering_TextAnnotation_h
|
@ -71,6 +71,7 @@ class TextureGL
|
||||
}
|
||||
else if (dim == 2)
|
||||
{
|
||||
std::cerr << "Binding 2D, id="<<id<<"\n";
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <vtkm/rendering/AxisAnnotation3D.h>
|
||||
#include <vtkm/rendering/AxisAnnotation2D.h>
|
||||
#include <vtkm/rendering/ColorBarAnnotation.h>
|
||||
#include <vtkm/rendering/TextAnnotation.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
@ -255,8 +256,8 @@ public:
|
||||
haxis.SetRangeForAutoTicks(this->view.View2d.Left, this->view.View2d.Right);
|
||||
haxis.SetMajorTickSize(0, .05, 1.0);
|
||||
haxis.SetMinorTickSize(0, .02, 1.0);
|
||||
//haxis.SetLabelAlignment(eavlTextAnnotation::HCenter,
|
||||
// eavlTextAnnotation::Top);
|
||||
haxis.SetLabelAlignment(TextAnnotation::HCenter,
|
||||
TextAnnotation::Top);
|
||||
haxis.Render(this->view, this->worldAnnotator, this->surface);
|
||||
|
||||
vtkm::Float32 windowaspect = vtkm::Float32(this->view.Width) / vtkm::Float32(this->view.Height);
|
||||
@ -266,8 +267,8 @@ public:
|
||||
vaxis.SetRangeForAutoTicks(this->view.View2d.Bottom, this->view.View2d.Top);
|
||||
vaxis.SetMajorTickSize(.05 / windowaspect, 0, 1.0);
|
||||
vaxis.SetMinorTickSize(.02 / windowaspect, 0, 1.0);
|
||||
//vaxis.SetLabelAlignment(eavlTextAnnotation::Right,
|
||||
// eavlTextAnnotation::VCenter);
|
||||
vaxis.SetLabelAlignment(TextAnnotation::Right,
|
||||
TextAnnotation::VCenter);
|
||||
vaxis.Render(this->view, this->worldAnnotator, this->surface);
|
||||
|
||||
if (scene.plots.size() > 0)
|
||||
@ -278,12 +279,9 @@ public:
|
||||
colorbar.Render(this->view, this->worldAnnotator, this->surface);
|
||||
}
|
||||
|
||||
this->surface.AddText(-.9f,-.9f,
|
||||
.1f,
|
||||
0,1,
|
||||
0,0,
|
||||
Color(1,1,1),
|
||||
"TEsTinG");
|
||||
ScreenTextAnnotation st("hello", Color(1,1,1), 0.1, 0,0,0);
|
||||
st.SetAlignment(TextAnnotation::Left, TextAnnotation::Top);
|
||||
st.Render(this->view, this->worldAnnotator, this->surface);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user