cleanup and style

This commit is contained in:
Jeremy Meredith 2016-06-01 13:37:03 -04:00
parent dd27e32cfc
commit 501f34c27a
11 changed files with 728 additions and 730 deletions

@ -63,37 +63,35 @@ public:
} }
}; };
std::string name; std::string Name;
std::string imgfile; std::string ImageFile;
int height; int Height;
int ascender; int Ascender;
int descender; int Descender;
int imgw, imgh; int ImgW, ImgH;
int padl, padr, padt, padb; int PadL, PadR, PadT, PadB;
int shortmap[256]; int ShortMap[256];
std::vector<Character> chars; std::vector<Character> Chars;
void *userPointer; std::vector<unsigned char> RawImageFileData;
long long userLong;
std::vector<unsigned char> rawimagefiledata;
public: public:
BitmapFont() BitmapFont()
{ {
for (int i=0; i<256; ++i) for (int i=0; i<256; ++i)
shortmap[i] = 0; ShortMap[i] = 0;
padl=padr=padt=padb=0; this->PadL=0;
userPointer = NULL; this->PadR=0;
userLong = 0; this->PadT=0;
this->PadB=0;
} }
Character GetChar(char c) Character GetChar(char c)
{ {
return chars[shortmap[(unsigned char)c]]; return this->Chars[ShortMap[(unsigned char)c]];
} }
std::vector<unsigned char> &GetRawImageData() std::vector<unsigned char> &GetRawImageData()
{ {
return rawimagefiledata; return this->RawImageFileData;
} }
vtkm::Float32 GetTextWidth(const std::string &text) vtkm::Float32 GetTextWidth(const std::string &text)
{ {
@ -105,8 +103,8 @@ public:
const bool kerning = true; const bool kerning = true;
if (kerning && nextchar>0) if (kerning && nextchar>0)
width += vtkm::Float32(c.kern[int(nextchar)]) / vtkm::Float32(height); width += vtkm::Float32(c.kern[int(nextchar)]) / vtkm::Float32(this->Height);
width += vtkm::Float32(c.adv) / vtkm::Float32(height); width += vtkm::Float32(c.adv) / vtkm::Float32(this->Height);
} }
return width; return width;
} }
@ -120,22 +118,22 @@ public:
// By default, the origin for the font is at the // By default, the origin for the font is at the
// baseline. That's nice, but we'd rather it // baseline. That's nice, but we'd rather it
// be at the actual bottom, so create an offset. // be at the actual bottom, so create an offset.
vtkm::Float32 yoff = -vtkm::Float32(descender) / vtkm::Float32(height); vtkm::Float32 yoff = -vtkm::Float32(this->Descender) / vtkm::Float32(this->Height);
tl = vtkm::Float32(c.x + padl) / vtkm::Float32(imgw); tl = vtkm::Float32(c.x + this->PadL) / vtkm::Float32(this->ImgW);
tr = vtkm::Float32(c.x + c.w - padr) / vtkm::Float32(imgw); tr = vtkm::Float32(c.x + c.w - this->PadR) / vtkm::Float32(this->ImgW);
tt = 1.f - vtkm::Float32(c.y + padt) / vtkm::Float32(imgh); tt = 1.f - vtkm::Float32(c.y + this->PadT) / vtkm::Float32(this->ImgH);
tb = 1.f - vtkm::Float32(c.y + c.h - padb) / vtkm::Float32(imgh); tb = 1.f - vtkm::Float32(c.y + c.h - this->PadB) / vtkm::Float32(this->ImgH);
vl = x + vtkm::Float32(c.offx + padl) / vtkm::Float32(height); vl = x + vtkm::Float32(c.offx + this->PadL) / vtkm::Float32(this->Height);
vr = x + vtkm::Float32(c.offx + c.w - padr) / vtkm::Float32(height); vr = x + vtkm::Float32(c.offx + c.w - this->PadR) / vtkm::Float32(this->Height);
vt = yoff + y + vtkm::Float32(c.offy - padt) / vtkm::Float32(height); vt = yoff + y + vtkm::Float32(c.offy - this->PadT) / vtkm::Float32(this->Height);
vb = yoff + y + vtkm::Float32(c.offy - c.h + padb) / vtkm::Float32(height); vb = yoff + y + vtkm::Float32(c.offy - c.h + this->PadB) / vtkm::Float32(this->Height);
const bool kerning = true; const bool kerning = true;
if (kerning && nextchar>0) if (kerning && nextchar>0)
x += vtkm::Float32(c.kern[int(nextchar)]) / vtkm::Float32(height); x += vtkm::Float32(c.kern[int(nextchar)]) / vtkm::Float32(this->Height);
x += vtkm::Float32(c.adv) / vtkm::Float32(height); x += vtkm::Float32(c.adv) / vtkm::Float32(this->Height);
} }
}; };

@ -9553,135 +9553,135 @@ public:
}; };
BitmapFont font; BitmapFont font;
font.name = "Liberation 2 Sans"; font.Name = "Liberation 2 Sans";
font.height = 129; font.Height = 129;
font.ascender = 102; font.Ascender = 102;
font.descender = -24; font.Descender = -24;
font.imgw = 1024; font.ImgW = 1024;
font.imgh = 1024; font.ImgH = 1024;
font.padl = 16; font.PadL = 16;
font.padr = 16; font.PadR = 16;
font.padt = 14; font.PadT = 14;
font.padb = 14; font.PadB = 14;
font.rawimagefiledata.insert( font.RawImageFileData.insert(
font.rawimagefiledata.begin(), font.RawImageFileData.begin(),
Liberation2Sans_rawimage, Liberation2Sans_rawimage,
Liberation2Sans_rawimage + Liberation2Sans_imagelength); Liberation2Sans_rawimage + Liberation2Sans_imagelength);
for (int i=0; i<95; i++) for (int i=0; i<95; i++)
{ {
font.chars.push_back(BitmapFont::Character(Liberation2Sans_charids[i], font.Chars.push_back(BitmapFont::Character(Liberation2Sans_charids[i],
Liberation2Sans_charmetrics[i])); Liberation2Sans_charmetrics[i]));
font.shortmap[Liberation2Sans_charmetrics[i][0]] = i; font.ShortMap[Liberation2Sans_charmetrics[i][0]] = i;
} }
// Character // Character
font.chars[0].kern[65] = -6; font.Chars[0].kern[65] = -6;
font.chars[0].kern[84] = -2; font.Chars[0].kern[84] = -2;
font.chars[0].kern[89] = -2; font.Chars[0].kern[89] = -2;
// Character A // Character A
font.chars[33].kern[32] = -6; font.Chars[33].kern[32] = -6;
font.chars[33].kern[84] = -8; font.Chars[33].kern[84] = -8;
font.chars[33].kern[86] = -8; font.Chars[33].kern[86] = -8;
font.chars[33].kern[87] = -4; font.Chars[33].kern[87] = -4;
font.chars[33].kern[89] = -8; font.Chars[33].kern[89] = -8;
font.chars[33].kern[118] = -2; font.Chars[33].kern[118] = -2;
font.chars[33].kern[119] = -2; font.Chars[33].kern[119] = -2;
font.chars[33].kern[121] = -2; font.Chars[33].kern[121] = -2;
// Character F // Character F
font.chars[38].kern[44] = -12; font.Chars[38].kern[44] = -12;
font.chars[38].kern[46] = -12; font.Chars[38].kern[46] = -12;
font.chars[38].kern[65] = -6; font.Chars[38].kern[65] = -6;
// Character L // Character L
font.chars[44].kern[32] = -4; font.Chars[44].kern[32] = -4;
font.chars[44].kern[84] = -8; font.Chars[44].kern[84] = -8;
font.chars[44].kern[86] = -8; font.Chars[44].kern[86] = -8;
font.chars[44].kern[87] = -8; font.Chars[44].kern[87] = -8;
font.chars[44].kern[89] = -8; font.Chars[44].kern[89] = -8;
font.chars[44].kern[121] = -4; font.Chars[44].kern[121] = -4;
// Character P // Character P
font.chars[48].kern[32] = -2; font.Chars[48].kern[32] = -2;
font.chars[48].kern[44] = -14; font.Chars[48].kern[44] = -14;
font.chars[48].kern[46] = -14; font.Chars[48].kern[46] = -14;
font.chars[48].kern[65] = -8; font.Chars[48].kern[65] = -8;
// Character R // Character R
font.chars[50].kern[84] = -2; font.Chars[50].kern[84] = -2;
font.chars[50].kern[86] = -2; font.Chars[50].kern[86] = -2;
font.chars[50].kern[87] = -2; font.Chars[50].kern[87] = -2;
font.chars[50].kern[89] = -2; font.Chars[50].kern[89] = -2;
// Character T // Character T
font.chars[52].kern[32] = -2; font.Chars[52].kern[32] = -2;
font.chars[52].kern[44] = -12; font.Chars[52].kern[44] = -12;
font.chars[52].kern[45] = -6; font.Chars[52].kern[45] = -6;
font.chars[52].kern[46] = -12; font.Chars[52].kern[46] = -12;
font.chars[52].kern[58] = -12; font.Chars[52].kern[58] = -12;
font.chars[52].kern[59] = -12; font.Chars[52].kern[59] = -12;
font.chars[52].kern[65] = -8; font.Chars[52].kern[65] = -8;
font.chars[52].kern[79] = -2; font.Chars[52].kern[79] = -2;
font.chars[52].kern[97] = -12; font.Chars[52].kern[97] = -12;
font.chars[52].kern[99] = -12; font.Chars[52].kern[99] = -12;
font.chars[52].kern[101] = -12; font.Chars[52].kern[101] = -12;
font.chars[52].kern[105] = -4; font.Chars[52].kern[105] = -4;
font.chars[52].kern[111] = -12; font.Chars[52].kern[111] = -12;
font.chars[52].kern[114] = -4; font.Chars[52].kern[114] = -4;
font.chars[52].kern[115] = -12; font.Chars[52].kern[115] = -12;
font.chars[52].kern[117] = -4; font.Chars[52].kern[117] = -4;
font.chars[52].kern[119] = -6; font.Chars[52].kern[119] = -6;
font.chars[52].kern[121] = -6; font.Chars[52].kern[121] = -6;
// Character V // Character V
font.chars[54].kern[44] = -10; font.Chars[54].kern[44] = -10;
font.chars[54].kern[45] = -6; font.Chars[54].kern[45] = -6;
font.chars[54].kern[46] = -10; font.Chars[54].kern[46] = -10;
font.chars[54].kern[58] = -4; font.Chars[54].kern[58] = -4;
font.chars[54].kern[59] = -4; font.Chars[54].kern[59] = -4;
font.chars[54].kern[65] = -8; font.Chars[54].kern[65] = -8;
font.chars[54].kern[97] = -8; font.Chars[54].kern[97] = -8;
font.chars[54].kern[101] = -6; font.Chars[54].kern[101] = -6;
font.chars[54].kern[105] = -2; font.Chars[54].kern[105] = -2;
font.chars[54].kern[111] = -6; font.Chars[54].kern[111] = -6;
font.chars[54].kern[114] = -4; font.Chars[54].kern[114] = -4;
font.chars[54].kern[117] = -4; font.Chars[54].kern[117] = -4;
font.chars[54].kern[121] = -4; font.Chars[54].kern[121] = -4;
// Character W // Character W
font.chars[55].kern[44] = -6; font.Chars[55].kern[44] = -6;
font.chars[55].kern[45] = -2; font.Chars[55].kern[45] = -2;
font.chars[55].kern[46] = -6; font.Chars[55].kern[46] = -6;
font.chars[55].kern[58] = -2; font.Chars[55].kern[58] = -2;
font.chars[55].kern[59] = -2; font.Chars[55].kern[59] = -2;
font.chars[55].kern[65] = -4; font.Chars[55].kern[65] = -4;
font.chars[55].kern[97] = -4; font.Chars[55].kern[97] = -4;
font.chars[55].kern[101] = -2; font.Chars[55].kern[101] = -2;
font.chars[55].kern[111] = -2; font.Chars[55].kern[111] = -2;
font.chars[55].kern[114] = -2; font.Chars[55].kern[114] = -2;
font.chars[55].kern[117] = -2; font.Chars[55].kern[117] = -2;
font.chars[55].kern[121] = -1; font.Chars[55].kern[121] = -1;
// Character Y // Character Y
font.chars[57].kern[32] = -2; font.Chars[57].kern[32] = -2;
font.chars[57].kern[44] = -14; font.Chars[57].kern[44] = -14;
font.chars[57].kern[45] = -10; font.Chars[57].kern[45] = -10;
font.chars[57].kern[46] = -14; font.Chars[57].kern[46] = -14;
font.chars[57].kern[58] = -6; font.Chars[57].kern[58] = -6;
font.chars[57].kern[59] = -7; font.Chars[57].kern[59] = -7;
font.chars[57].kern[65] = -8; font.Chars[57].kern[65] = -8;
font.chars[57].kern[97] = -8; font.Chars[57].kern[97] = -8;
font.chars[57].kern[101] = -10; font.Chars[57].kern[101] = -10;
font.chars[57].kern[105] = -4; font.Chars[57].kern[105] = -4;
font.chars[57].kern[111] = -10; font.Chars[57].kern[111] = -10;
font.chars[57].kern[112] = -8; font.Chars[57].kern[112] = -8;
font.chars[57].kern[113] = -10; font.Chars[57].kern[113] = -10;
font.chars[57].kern[117] = -6; font.Chars[57].kern[117] = -6;
font.chars[57].kern[118] = -6; font.Chars[57].kern[118] = -6;
// Character r // Character r
font.chars[82].kern[44] = -6; font.Chars[82].kern[44] = -6;
font.chars[82].kern[46] = -6; font.Chars[82].kern[46] = -6;
// Character v // Character v
font.chars[86].kern[44] = -8; font.Chars[86].kern[44] = -8;
font.chars[86].kern[46] = -8; font.Chars[86].kern[46] = -8;
// Character w // Character w
font.chars[87].kern[44] = -6; font.Chars[87].kern[44] = -6;
font.chars[87].kern[46] = -6; font.Chars[87].kern[46] = -6;
// Character y // Character y
font.chars[89].kern[44] = -8; font.Chars[89].kern[44] = -8;
font.chars[89].kern[46] = -8; font.Chars[89].kern[46] = -8;
return font; return font;
} }
}; };

@ -34,54 +34,54 @@ namespace rendering {
class RenderSurface class RenderSurface
{ {
public: public:
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
RenderSurface(std::size_t width=1024, std::size_t height=1024, RenderSurface(std::size_t width=1024, std::size_t height=1024,
const vtkm::rendering::Color &color=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f)) const vtkm::rendering::Color &color=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
: Width(width), Height(height), BackgroundColor(color) : Width(width), Height(height), BackgroundColor(color)
{ {
this->ColorBuffer.resize(width*height*4); this->ColorBuffer.resize(width*height*4);
this->DepthBuffer.resize(width*height); this->DepthBuffer.resize(width*height);
} }
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void Initialize() {} virtual void Initialize() {}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void Activate() {} virtual void Activate() {}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void Clear() {} virtual void Clear() {}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void Finish() {} virtual void Finish() {}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void SetViewToWorldSpace(vtkm::rendering::View &, bool) {} virtual void SetViewToWorldSpace(vtkm::rendering::View &, bool) {}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void SetViewToScreenSpace(vtkm::rendering::View &, bool) {} virtual void SetViewToScreenSpace(vtkm::rendering::View &, bool) {}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
void SetViewportClipping(vtkm::rendering::View &, bool) {} void SetViewportClipping(vtkm::rendering::View &, bool) {}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void SaveAs(const std::string &) {} virtual void SaveAs(const std::string &) {}
virtual void AddLine(vtkm::Float64, vtkm::Float64, virtual void AddLine(vtkm::Float64, vtkm::Float64,
vtkm::Float64, vtkm::Float64, vtkm::Float64, vtkm::Float64,
vtkm::Float32, vtkm::Float32,
const vtkm::rendering::Color &) {} const vtkm::rendering::Color &) {}
virtual void AddColorBar(vtkm::Float32, vtkm::Float32, virtual void AddColorBar(vtkm::Float32, vtkm::Float32,
vtkm::Float32, vtkm::Float32, vtkm::Float32, vtkm::Float32,
const vtkm::rendering::ColorTable &, const vtkm::rendering::ColorTable &,
bool) {} bool) {}
virtual void AddText(vtkm::Float32, vtkm::Float32, 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, Color,
std::string) {} std::string) {}
std::size_t Width, Height; std::size_t Width, Height;
vtkm::rendering::Color BackgroundColor; vtkm::rendering::Color BackgroundColor;
std::vector<vtkm::Float32> ColorBuffer; std::vector<vtkm::Float32> ColorBuffer;
std::vector<vtkm::Float32> DepthBuffer; std::vector<vtkm::Float32> DepthBuffer;
}; };
}} //namespace vtkm::rendering }} //namespace vtkm::rendering

@ -39,172 +39,172 @@ namespace rendering {
class RenderSurfaceGL : public RenderSurface class RenderSurfaceGL : public RenderSurface
{ {
public: public:
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
RenderSurfaceGL(std::size_t w=1024, std::size_t h=1024, RenderSurfaceGL(std::size_t w=1024, std::size_t h=1024,
const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f)) const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
: RenderSurface(w,h,c) : RenderSurface(w,h,c)
{
}
VTKM_CONT_EXPORT
virtual void Clear()
{
glClearColor(this->BackgroundColor.Components[0],
this->BackgroundColor.Components[1],
this->BackgroundColor.Components[2],
1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
VTKM_CONT_EXPORT
virtual void Finish()
{
glFinish();
}
VTKM_CONT_EXPORT
virtual void SetViewToWorldSpace(vtkm::rendering::View &v, bool clip)
{
vtkm::Float32 oglP[16], oglM[16];
MatrixHelpers::CreateOGLMatrix(v.CreateProjectionMatrix(), oglP);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(oglP);
MatrixHelpers::CreateOGLMatrix(v.CreateViewMatrix(), oglM);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(oglM);
SetViewportClipping(v, clip);
}
VTKM_CONT_EXPORT
virtual void SetViewToScreenSpace(vtkm::rendering::View &v, bool clip)
{
vtkm::Float32 oglP[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
vtkm::Float32 oglM[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
oglP[0*4+0] = 1.;
oglP[1*4+1] = 1.;
oglP[2*4+2] = -1.;
oglP[3*4+3] = 1.;
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(oglP);
oglM[0*4+0] = 1.;
oglM[1*4+1] = 1.;
oglM[2*4+2] = 1.;
oglM[3*4+3] = 1.;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(oglM);
SetViewportClipping(v, clip);
}
VTKM_CONT_EXPORT
virtual void SetViewportClipping(vtkm::rendering::View &v, bool clip)
{
if (clip)
{ {
} vtkm::Float32 vl, vr, vb, vt;
v.GetRealViewport(vl,vr,vb,vt);
vtkm::Float32 _x = static_cast<vtkm::Float32>(v.Width)*(1.f+vl)/2.f;
vtkm::Float32 _y = static_cast<vtkm::Float32>(v.Height)*(1.f+vb)/2.f;
vtkm::Float32 _w = static_cast<vtkm::Float32>(v.Width)*(vr-vl)/2.f;
vtkm::Float32 _h = static_cast<vtkm::Float32>(v.Height)*(vt-vb)/2.f;
VTKM_CONT_EXPORT glViewport(static_cast<int>(_x), static_cast<int>(_y),
virtual void Clear() static_cast<int>(_w), static_cast<int>(_h));
}
else
{ {
glClearColor(this->BackgroundColor.Components[0], glViewport(0,0, v.Width, v.Height);
this->BackgroundColor.Components[1],
this->BackgroundColor.Components[2],
1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} }
VTKM_CONT_EXPORT }
virtual void Finish()
VTKM_CONT_EXPORT
virtual void SaveAs(const std::string &fileName)
{
std::ofstream of(fileName.c_str());
of << "P6" << std::endl
<< this->Width << " " << this->Height <<std::endl
<< 255 << std::endl;
int height = static_cast<int>(this->Height);
for (int yIndex=height-1; yIndex>=0; yIndex--)
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
{
const vtkm::Float32 *tuple =
&(this->ColorBuffer[static_cast<std::size_t>(yIndex)*this->Width*4 + xIndex*4]);
of<<(unsigned char)(tuple[0]*255);
of<<(unsigned char)(tuple[1]*255);
of<<(unsigned char)(tuple[2]*255);
}
of.close();
}
VTKM_CONT_EXPORT
virtual void AddLine(vtkm::Float64 x0, vtkm::Float64 y0,
vtkm::Float64 x1, vtkm::Float64 y1,
vtkm::Float32 linewidth,
const vtkm::rendering::Color &c)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glColor3fv(c.Components);
glLineWidth(linewidth);
glBegin(GL_LINES);
glVertex2f(float(x0),float(y0));
glVertex2f(float(x1),float(y1));
glEnd();
}
VTKM_CONT_EXPORT
virtual void AddColorBar(vtkm::Float32 x, vtkm::Float32 y,
vtkm::Float32 w, vtkm::Float32 h,
const vtkm::rendering::ColorTable &ct,
bool horizontal)
{
const int n = 256;
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glBegin(GL_QUADS);
for (int i=0; i<n; i++)
{ {
glFinish(); vtkm::Float32 v0 = static_cast<vtkm::Float32>(i)/static_cast<vtkm::Float32>(n);
} vtkm::Float32 v1 = static_cast<vtkm::Float32>(i+1)/static_cast<vtkm::Float32>(n);
Color c0 = ct.MapRGB(v0);
VTKM_CONT_EXPORT Color c1 = ct.MapRGB(v1);
virtual void SetViewToWorldSpace(vtkm::rendering::View &v, bool clip) if (horizontal)
{ {
vtkm::Float32 oglP[16], oglM[16]; vtkm::Float32 x0 = x + w*v0;
vtkm::Float32 x1 = x + w*v1;
MatrixHelpers::CreateOGLMatrix(v.CreateProjectionMatrix(), oglP); vtkm::Float32 y0 = y;
glMatrixMode(GL_PROJECTION); vtkm::Float32 y1 = y + h;
glLoadMatrixf(oglP); glColor3fv(c0.Components);
MatrixHelpers::CreateOGLMatrix(v.CreateViewMatrix(), oglM); glVertex2f(x0,y0);
glMatrixMode(GL_MODELVIEW); glVertex2f(x0,y1);
glLoadMatrixf(oglM); glColor3fv(c1.Components);
glVertex2f(x1,y1);
SetViewportClipping(v, clip); glVertex2f(x1,y0);
} }
else // vertical
VTKM_CONT_EXPORT {
virtual void SetViewToScreenSpace(vtkm::rendering::View &v, bool clip) vtkm::Float32 x0 = x;
{ vtkm::Float32 x1 = x + w;
vtkm::Float32 oglP[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; vtkm::Float32 y0 = y + h*v0;
vtkm::Float32 oglM[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; vtkm::Float32 y1 = y + h*v1;
glColor3fv(c0.Components);
oglP[0*4+0] = 1.; glVertex2f(x0,y1);
oglP[1*4+1] = 1.; glVertex2f(x1,y1);
oglP[2*4+2] = -1.; glColor3fv(c1.Components);
oglP[3*4+3] = 1.; glVertex2f(x1,y0);
glVertex2f(x0,y0);
glMatrixMode(GL_PROJECTION); }
glLoadMatrixf(oglP);
oglM[0*4+0] = 1.;
oglM[1*4+1] = 1.;
oglM[2*4+2] = 1.;
oglM[3*4+3] = 1.;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(oglM);
SetViewportClipping(v, clip);
}
VTKM_CONT_EXPORT
virtual void SetViewportClipping(vtkm::rendering::View &v, bool clip)
{
if (clip)
{
vtkm::Float32 vl, vr, vb, vt;
v.GetRealViewport(vl,vr,vb,vt);
vtkm::Float32 _x = static_cast<vtkm::Float32>(v.Width)*(1.f+vl)/2.f;
vtkm::Float32 _y = static_cast<vtkm::Float32>(v.Height)*(1.f+vb)/2.f;
vtkm::Float32 _w = static_cast<vtkm::Float32>(v.Width)*(vr-vl)/2.f;
vtkm::Float32 _h = static_cast<vtkm::Float32>(v.Height)*(vt-vb)/2.f;
glViewport(static_cast<int>(_x), static_cast<int>(_y),
static_cast<int>(_w), static_cast<int>(_h));
}
else
{
glViewport(0,0, v.Width, v.Height);
}
}
VTKM_CONT_EXPORT
virtual void SaveAs(const std::string &fileName)
{
std::ofstream of(fileName.c_str());
of << "P6" << std::endl
<< this->Width << " " << this->Height <<std::endl
<< 255 << std::endl;
int height = static_cast<int>(this->Height);
for (int yIndex=height-1; yIndex>=0; yIndex--)
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
{
const vtkm::Float32 *tuple =
&(this->ColorBuffer[static_cast<std::size_t>(yIndex)*this->Width*4 + xIndex*4]);
of<<(unsigned char)(tuple[0]*255);
of<<(unsigned char)(tuple[1]*255);
of<<(unsigned char)(tuple[2]*255);
}
of.close();
}
VTKM_CONT_EXPORT
virtual void AddLine(vtkm::Float64 x0, vtkm::Float64 y0,
vtkm::Float64 x1, vtkm::Float64 y1,
vtkm::Float32 linewidth,
const vtkm::rendering::Color &c)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glColor3fv(c.Components);
glLineWidth(linewidth);
glBegin(GL_LINES);
glVertex2f(float(x0),float(y0));
glVertex2f(float(x1),float(y1));
glEnd();
}
VTKM_CONT_EXPORT
virtual void AddColorBar(vtkm::Float32 x, vtkm::Float32 y,
vtkm::Float32 w, vtkm::Float32 h,
const vtkm::rendering::ColorTable &ct,
bool horizontal)
{
const int n = 256;
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glBegin(GL_QUADS);
for (int i=0; i<n; i++)
{
vtkm::Float32 v0 = static_cast<vtkm::Float32>(i)/static_cast<vtkm::Float32>(n);
vtkm::Float32 v1 = static_cast<vtkm::Float32>(i+1)/static_cast<vtkm::Float32>(n);
Color c0 = ct.MapRGB(v0);
Color c1 = ct.MapRGB(v1);
if (horizontal)
{
vtkm::Float32 x0 = x + w*v0;
vtkm::Float32 x1 = x + w*v1;
vtkm::Float32 y0 = y;
vtkm::Float32 y1 = y + h;
glColor3fv(c0.Components);
glVertex2f(x0,y0);
glVertex2f(x0,y1);
glColor3fv(c1.Components);
glVertex2f(x1,y1);
glVertex2f(x1,y0);
}
else // vertical
{
vtkm::Float32 x0 = x;
vtkm::Float32 x1 = x + w;
vtkm::Float32 y0 = y + h*v0;
vtkm::Float32 y1 = y + h*v1;
glColor3fv(c0.Components);
glVertex2f(x0,y1);
glVertex2f(x1,y1);
glColor3fv(c1.Components);
glVertex2f(x1,y0);
glVertex2f(x0,y0);
}
}
glEnd();
} }
glEnd();
}
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
@ -226,17 +226,17 @@ public:
} }
private: private:
BitmapFont font; BitmapFont Font;
TextureGL fontTexture; TextureGL FontTexture;
void RenderText(vtkm::Float32 scale, void RenderText(vtkm::Float32 scale,
vtkm::Float32 anchorx, vtkm::Float32 anchory, vtkm::Float32 anchorx, vtkm::Float32 anchory,
std::string text) std::string text)
{ {
if (fontTexture.id == 0) if (this->FontTexture.ID == 0)
{ {
font = BitmapFontFactory::CreateLiberation2Sans(); Font = BitmapFontFactory::CreateLiberation2Sans();
std::vector<unsigned char> &rawpngdata = font.GetRawImageData(); std::vector<unsigned char> &rawpngdata = this->Font.GetRawImageData();
std::vector<unsigned char> rgba; std::vector<unsigned char> rgba;
unsigned long width, height; unsigned long width, height;
@ -247,11 +247,11 @@ private:
return; return;
} }
fontTexture.CreateAlphaFromRGBA(int(width),int(height),rgba); this->FontTexture.CreateAlphaFromRGBA(int(width),int(height),rgba);
} }
fontTexture.Enable(); this->FontTexture.Enable();
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -262,7 +262,7 @@ private:
glBegin(GL_QUADS); glBegin(GL_QUADS);
vtkm::Float32 textwidth = font.GetTextWidth(text); vtkm::Float32 textwidth = this->Font.GetTextWidth(text);
vtkm::Float32 fx = -(.5f + .5f*anchorx) * textwidth; vtkm::Float32 fx = -(.5f + .5f*anchorx) * textwidth;
vtkm::Float32 fy = -(.5f + .5f*anchory); vtkm::Float32 fy = -(.5f + .5f*anchory);
@ -274,7 +274,7 @@ private:
vtkm::Float32 vl,vr,vt,vb; vtkm::Float32 vl,vr,vt,vb;
vtkm::Float32 tl,tr,tt,tb; vtkm::Float32 tl,tr,tt,tb;
font.GetCharPolygon(c, fx, fy, this->Font.GetCharPolygon(c, fx, fy,
vl, vr, vt, vb, vl, vr, vt, vb,
tl, tr, tt, tb, nextchar); tl, tr, tt, tb, nextchar);
@ -293,7 +293,7 @@ private:
glEnd(); glEnd();
fontTexture.Disable(); this->FontTexture.Disable();
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0); //glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);

@ -36,56 +36,56 @@ namespace rendering {
class RenderSurfaceGLX : public RenderSurfaceGL class RenderSurfaceGLX : public RenderSurfaceGL
{ {
public: public:
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
RenderSurfaceGLX(std::size_t w=1024, std::size_t h=1024, RenderSurfaceGLX(std::size_t w=1024, std::size_t h=1024,
const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f)) const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
: RenderSurfaceGL(w,h,c) : RenderSurfaceGL(w,h,c)
{ {
ctx = NULL; ctx = NULL;
} }
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void Initialize() virtual void Initialize()
{ {
ctx = glXGetCurrentContext(); ctx = glXGetCurrentContext();
if (!ctx) if (!ctx)
throw vtkm::cont::ErrorControlBadValue("GL context creation failed."); throw vtkm::cont::ErrorControlBadValue("GL context creation failed.");
/* /*
rgba.resize(width*height*4); rgba.resize(width*height*4);
if (!OSMesaMakeCurrent(ctx, &rgba[0], GL_FLOAT, static_cast<GLsizei>(width), static_cast<GLsizei>(height))) if (!OSMesaMakeCurrent(ctx, &rgba[0], GL_FLOAT, static_cast<GLsizei>(width), static_cast<GLsizei>(height)))
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed."); throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
*/ */
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void Clear() virtual void Clear()
{ {
glClearColor(this->BackgroundColor.Components[0], glClearColor(this->BackgroundColor.Components[0],
this->BackgroundColor.Components[1], this->BackgroundColor.Components[1],
this->BackgroundColor.Components[2], 1.0f); this->BackgroundColor.Components[2], 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} }
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
virtual void Finish() virtual void Finish()
{ {
RenderSurfaceGL::Finish(); RenderSurfaceGL::Finish();
/* TODO /* TODO
//Copy zbuff into floating point array. //Copy zbuff into floating point array.
unsigned int *raw_zbuff; unsigned int *raw_zbuff;
int zbytes, w, h; int zbytes, w, h;
GLboolean ret; GLboolean ret;
ret = OSMesaGetDepthBuffer(ctx, &w, &h, &zbytes, (void**)&raw_zbuff); ret = OSMesaGetDepthBuffer(ctx, &w, &h, &zbytes, (void**)&raw_zbuff);
if (!ret || static_cast<std::size_t>(w)!=width || static_cast<std::size_t>(h)!=height) if (!ret || static_cast<std::size_t>(w)!=width || static_cast<std::size_t>(h)!=height)
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer"); throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
std::size_t npixels = width*height; std::size_t npixels = width*height;
for (std::size_t i=0; i<npixels; i++) for (std::size_t i=0; i<npixels; i++)
zbuff[i] = float(raw_zbuff[i]) / float(UINT_MAX); zbuff[i] = float(raw_zbuff[i]) / float(UINT_MAX);
*/ */
} }
private: private:
GLXContext ctx; GLXContext ctx;

@ -36,64 +36,64 @@ namespace rendering {
class RenderSurfaceOSMesa : public RenderSurfaceGL class RenderSurfaceOSMesa : public RenderSurfaceGL
{ {
public: public:
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
RenderSurfaceOSMesa(std::size_t w=1024, std::size_t h=1024, RenderSurfaceOSMesa(std::size_t w=1024, std::size_t h=1024,
const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f)) const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
: RenderSurfaceGL(w,h,c) : RenderSurfaceGL(w,h,c)
{
ctx = NULL;
}
VTKM_CONT_EXPORT
virtual void Initialize()
{
ctx = OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, NULL);
if (!ctx)
throw vtkm::cont::ErrorControlBadValue("OSMesa context creation failed.");
this->ColorBuffer.resize(this->Width*this->Height*4);
if (!OSMesaMakeCurrent(ctx,
&this->ColorBuffer[0],
GL_FLOAT,
static_cast<GLsizei>(this->Width),
static_cast<GLsizei>(this->Height)))
{ {
ctx = NULL; throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
} }
VTKM_CONT_EXPORT glEnable(GL_DEPTH_TEST);
virtual void Initialize() }
{
ctx = OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, NULL);
if (!ctx)
throw vtkm::cont::ErrorControlBadValue("OSMesa context creation failed.");
this->ColorBuffer.resize(this->Width*this->Height*4);
if (!OSMesaMakeCurrent(ctx,
&this->ColorBuffer[0],
GL_FLOAT,
static_cast<GLsizei>(this->Width),
static_cast<GLsizei>(this->Height)))
{
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
}
glEnable(GL_DEPTH_TEST); VTKM_CONT_EXPORT
} virtual void Clear()
{
glClearColor(this->BackgroundColor.Components[0],
this->BackgroundColor.Components[1],
this->BackgroundColor.Components[2],
1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
VTKM_CONT_EXPORT
virtual void Finish()
{
RenderSurfaceGL::Finish();
VTKM_CONT_EXPORT //Copy zbuff into floating point array.
virtual void Clear() unsigned int *raw_zbuff;
int zbytes, w, h;
GLboolean ret;
ret = OSMesaGetDepthBuffer(ctx, &w, &h, &zbytes, (void**)&raw_zbuff);
if (!ret ||
static_cast<std::size_t>(w)!=this->Width ||
static_cast<std::size_t>(h)!=this->Height)
{ {
glClearColor(this->BackgroundColor.Components[0], throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
this->BackgroundColor.Components[1],
this->BackgroundColor.Components[2],
1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} }
VTKM_CONT_EXPORT std::size_t npixels = this->Width*this->Height;
virtual void Finish() for (std::size_t i=0; i<npixels; i++)
{ {
RenderSurfaceGL::Finish(); this->DepthBuffer[i] = float(raw_zbuff[i]) / float(UINT_MAX);
//Copy zbuff into floating point array.
unsigned int *raw_zbuff;
int zbytes, w, h;
GLboolean ret;
ret = OSMesaGetDepthBuffer(ctx, &w, &h, &zbytes, (void**)&raw_zbuff);
if (!ret ||
static_cast<std::size_t>(w)!=this->Width ||
static_cast<std::size_t>(h)!=this->Height)
{
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
}
std::size_t npixels = this->Width*this->Height;
for (std::size_t i=0; i<npixels; i++)
{
this->DepthBuffer[i] = float(raw_zbuff[i]) / float(UINT_MAX);
}
} }
}
private: private:
OSMesaContext ctx; OSMesaContext ctx;

@ -36,77 +36,77 @@ namespace rendering {
class RenderSurfaceRayTracer : public RenderSurface class RenderSurfaceRayTracer : public RenderSurface
{ {
public: public:
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
RenderSurfaceRayTracer(std::size_t width=1024, std::size_t height=1024, RenderSurfaceRayTracer(std::size_t width=1024, std::size_t height=1024,
const vtkm::rendering::Color &color=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f)) const vtkm::rendering::Color &color=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
: RenderSurface(width,height,color) : RenderSurface(width,height,color)
{ {
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer); this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer); this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
} }
class ClearBuffers : public vtkm::worklet::WorkletMapField class ClearBuffers : public vtkm::worklet::WorkletMapField
{ {
vtkm::rendering::Color ClearColor; vtkm::rendering::Color ClearColor;
vtkm::Id NumPixels; vtkm::Id NumPixels;
public: public:
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
ClearBuffers(const vtkm::rendering::Color &clearColor, ClearBuffers(const vtkm::rendering::Color &clearColor,
vtkm::Id numPixels) vtkm::Id numPixels)
: ClearColor(clearColor), : ClearColor(clearColor),
NumPixels(numPixels) NumPixels(numPixels)
{} {}
typedef void ControlSignature(FieldOut<>, typedef void ControlSignature(FieldOut<>,
ExecObject); ExecObject);
typedef void ExecutionSignature(_1, typedef void ExecutionSignature(_1,
_2, _2,
WorkIndex); WorkIndex);
VTKM_EXEC_EXPORT VTKM_EXEC_EXPORT
void operator()(vtkm::Float32 &depth, void operator()(vtkm::Float32 &depth,
vtkm::exec::ExecutionWholeArray<vtkm::Float32> &colorBuffer, vtkm::exec::ExecutionWholeArray<vtkm::Float32> &colorBuffer,
const vtkm::Id &index) const const vtkm::Id &index) const
{
if(index >= NumPixels) return;
depth = 1.001f;
vtkm::Id offset = index * 4;
colorBuffer.Set(offset + 0, ClearColor.Components[0]);
colorBuffer.Set(offset + 1, ClearColor.Components[1]);
colorBuffer.Set(offset + 2, ClearColor.Components[2]);
colorBuffer.Set(offset + 3, ClearColor.Components[3]);
}
}; //class ClearBuffers
VTKM_CONT_EXPORT
virtual void SaveAs(const std::string &fileName)
{
std::ofstream of(fileName.c_str());
of<<"P6"<<std::endl<<this->Width<<" "<<this->Height<<std::endl<<255<<std::endl;
int height = static_cast<int>(this->Height);
for (int yIndex=height-1; yIndex>=0; yIndex--)
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
{ {
if(index >= NumPixels) return; const vtkm::Float32 *tuple =
depth = 1.001f; &(this->ColorBuffer[static_cast<std::size_t>(yIndex)*this->Width*4 + xIndex*4]);
vtkm::Id offset = index * 4; of<<(unsigned char)(tuple[0]*255);
colorBuffer.Set(offset + 0, ClearColor.Components[0]); of<<(unsigned char)(tuple[1]*255);
colorBuffer.Set(offset + 1, ClearColor.Components[1]); of<<(unsigned char)(tuple[2]*255);
colorBuffer.Set(offset + 2, ClearColor.Components[2]);
colorBuffer.Set(offset + 3, ClearColor.Components[3]);
} }
}; //class ClearBuffers of.close();
}
VTKM_CONT_EXPORT
virtual void Clear()
{
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
vtkm::worklet::DispatcherMapField< ClearBuffers >(
ClearBuffers( this->BackgroundColor,
static_cast<vtkm::Int32>(this->Width*this->Height) ) )
.Invoke( this->DepthArray,
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(this->ColorArray) );
}
VTKM_CONT_EXPORT vtkm::cont::ArrayHandle<vtkm::Float32> ColorArray;
virtual void SaveAs(const std::string &fileName) vtkm::cont::ArrayHandle<vtkm::Float32> DepthArray;
{
std::ofstream of(fileName.c_str());
of<<"P6"<<std::endl<<this->Width<<" "<<this->Height<<std::endl<<255<<std::endl;
int height = static_cast<int>(this->Height);
for (int yIndex=height-1; yIndex>=0; yIndex--)
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
{
const vtkm::Float32 *tuple =
&(this->ColorBuffer[static_cast<std::size_t>(yIndex)*this->Width*4 + xIndex*4]);
of<<(unsigned char)(tuple[0]*255);
of<<(unsigned char)(tuple[1]*255);
of<<(unsigned char)(tuple[2]*255);
}
of.close();
}
VTKM_CONT_EXPORT
virtual void Clear()
{
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
vtkm::worklet::DispatcherMapField< ClearBuffers >(
ClearBuffers( this->BackgroundColor,
static_cast<vtkm::Int32>(this->Width*this->Height) ) )
.Invoke( this->DepthArray,
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(this->ColorArray) );
}
vtkm::cont::ArrayHandle<vtkm::Float32> ColorArray;
vtkm::cont::ArrayHandle<vtkm::Float32> DepthArray;
}; };

@ -44,38 +44,38 @@ public:
}; };
protected: protected:
std::string text; std::string Text;
Color color; Color TextColor;
vtkm::Float32 scale; vtkm::Float32 Scale;
vtkm::Float32 anchorx, anchory; vtkm::Float32 AnchorX, AnchorY;
public: public:
TextAnnotation(const std::string &txt, Color c, vtkm::Float32 s) TextAnnotation(const std::string &txt, Color c, vtkm::Float32 s)
: text(txt), color(c), scale(s) : Text(txt), TextColor(c), Scale(s)
{ {
// default anchor: bottom-left // default anchor: bottom-left
anchorx = -1; AnchorX = -1;
anchory = -1; AnchorY = -1;
} }
virtual ~TextAnnotation() virtual ~TextAnnotation()
{ {
} }
void SetText(const std::string &txt) void SetText(const std::string &txt)
{ {
text = txt; Text = txt;
} }
void SetRawAnchor(vtkm::Float32 h, vtkm::Float32 v) void SetRawAnchor(vtkm::Float32 h, vtkm::Float32 v)
{ {
anchorx = h; AnchorX = h;
anchory = v; AnchorY = v;
} }
void SetAlignment(HorizontalAlignment h, VerticalAlignment v) void SetAlignment(HorizontalAlignment h, VerticalAlignment v)
{ {
switch (h) switch (h)
{ {
case Left: anchorx = -1.0f; break; case Left: AnchorX = -1.0f; break;
case HCenter: anchorx = 0.0f; break; case HCenter: AnchorX = 0.0f; break;
case Right: anchorx = +1.0f; break; case Right: AnchorX = +1.0f; break;
} }
// For vertical alignment, "center" is generally the center // For vertical alignment, "center" is generally the center
@ -89,14 +89,14 @@ public:
// the bottom of the window. // the bottom of the window.
switch (v) switch (v)
{ {
case Bottom: anchory = -1.0f; break; case Bottom: AnchorY = -1.0f; break;
case VCenter: anchory = -0.06f; break; case VCenter: AnchorY = -0.06f; break;
case Top: anchory = +1.0f; break; case Top: AnchorY = +1.0f; break;
} }
} }
void SetScale(vtkm::Float32 s) void SetScale(vtkm::Float32 s)
{ {
scale = s; Scale = s;
} }
virtual void Render(View &view, virtual void Render(View &view,
WorldAnnotator &worldAnnotator, WorldAnnotator &worldAnnotator,
@ -106,21 +106,21 @@ public:
class ScreenTextAnnotation : public TextAnnotation class ScreenTextAnnotation : public TextAnnotation
{ {
protected: protected:
vtkm::Float32 x,y; vtkm::Float32 XPos,YPos;
vtkm::Float32 angle; vtkm::Float32 Angle;
public: public:
ScreenTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s, ScreenTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s,
vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 angleDeg = 0.) vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 angleDeg = 0.)
: TextAnnotation(txt,c,s) : TextAnnotation(txt,c,s)
{ {
x = ox; XPos = ox;
y = oy; YPos = oy;
angle = angleDeg; Angle = angleDeg;
} }
void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy) void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy)
{ {
x = ox; XPos = ox;
y = oy; YPos = oy;
} }
virtual void Render(View &view, virtual void Render(View &view,
WorldAnnotator &, WorldAnnotator &,
@ -129,36 +129,36 @@ public:
vtkm::Float32 WindowAspect = vtkm::Float32(view.Width) / vtkm::Float32 WindowAspect = vtkm::Float32(view.Width) /
vtkm::Float32(view.Height); vtkm::Float32(view.Height);
renderSurface.AddText(x,y, renderSurface.AddText(XPos,YPos,
scale, Scale,
angle, Angle,
WindowAspect, WindowAspect,
anchorx, anchory, AnchorX, AnchorY,
color, text); TextColor, Text);
} }
}; };
class BillboardTextAnnotation : public TextAnnotation class BillboardTextAnnotation : public TextAnnotation
{ {
protected: protected:
vtkm::Float32 x,y,z; vtkm::Float32 XPos,YPos,ZPos;
vtkm::Float32 angle; vtkm::Float32 Angle;
public: public:
BillboardTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s, BillboardTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s,
vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz, vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz,
vtkm::Float32 angleDeg = 0.) vtkm::Float32 angleDeg = 0.)
: TextAnnotation(txt,c,s) : TextAnnotation(txt,c,s)
{ {
x = ox; XPos = ox;
y = oy; YPos = oy;
z = oz; ZPos = oz;
angle = angleDeg; Angle = angleDeg;
} }
void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz) void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz)
{ {
x = ox; XPos = ox;
y = oy; YPos = oy;
z = oz; ZPos = oz;
} }
virtual void Render(View &view, virtual void Render(View &view,
@ -169,7 +169,7 @@ public:
V = view.CreateViewMatrix(); V = view.CreateViewMatrix();
P = view.CreateProjectionMatrix(); P = view.CreateProjectionMatrix();
vtkm::Vec<vtkm::Float32,4> p4w(x,y,z,1); vtkm::Vec<vtkm::Float32,4> p4w(XPos,YPos,ZPos,1);
vtkm::Vec<vtkm::Float32,4> p4s = vtkm::Vec<vtkm::Float32,4> p4s =
vtkm::MatrixMultiply(vtkm::MatrixMultiply(P,V), p4w); vtkm::MatrixMultiply(vtkm::MatrixMultiply(P,V), p4w);
@ -201,7 +201,7 @@ public:
} }
vtkm::Matrix<vtkm::Float32, 4, 4> R; vtkm::Matrix<vtkm::Float32, 4, 4> R;
R = MatrixHelpers::RotateZMatrix(angle * 3.14159265f / 180.f); R = MatrixHelpers::RotateZMatrix(Angle * 3.14159265f / 180.f);
vtkm::Vec<vtkm::Float32,4> origin4(0,0,0,1); vtkm::Vec<vtkm::Float32,4> origin4(0,0,0,1);
vtkm::Vec<vtkm::Float32,4> right4(1,0,0,0); vtkm::Vec<vtkm::Float32,4> right4(1,0,0,0);
@ -235,9 +235,9 @@ public:
worldAnnotator.AddText(px,py,pz, worldAnnotator.AddText(px,py,pz,
rx,ry,rz, rx,ry,rz,
ux,uy,uz, ux,uy,uz,
scale, Scale,
anchorx, anchory, AnchorX, AnchorY,
color, text); TextColor, Text);
renderSurface.SetViewToWorldSpace(view,true); renderSurface.SetViewToWorldSpace(view,true);
} }

@ -32,113 +32,113 @@ namespace rendering {
class TextureGL class TextureGL
{ {
public: public:
GLuint id; GLuint ID;
int dim; int Dimension;
bool mipmap; bool MIPMap;
bool linear2D; bool Linear2D;
bool linearMip; bool LinearMIP;
public: public:
TextureGL() TextureGL()
{ {
id = 0; this->ID = 0;
dim = 0; this->Dimension = 0;
mipmap = false; this->MIPMap = false;
linear2D = true; this->Linear2D = true;
linearMip = true; this->LinearMIP = true;
} }
void Enable() void Enable()
{ {
if (id == 0) if (this->ID == 0)
return; return;
if (dim == 1) if (this->Dimension == 1)
{
// no mipmapping for 1D (at the moment)
glBindTexture(GL_TEXTURE_1D, id);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
if (linear2D)
{
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
glEnable(GL_TEXTURE_1D);
}
else if (dim == 2)
{
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);
if (linear2D)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (!mipmap)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
else if (linearMip)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (!mipmap)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
else if (linearMip)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
}
glEnable(GL_TEXTURE_2D);
}
}
void Disable()
{ {
if (dim == 1) // no this->MIPMapping for 1D (at the moment)
glDisable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, this->ID);
else if (dim == 2) glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glDisable(GL_TEXTURE_2D); if (this->Linear2D)
{
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
glEnable(GL_TEXTURE_1D);
} }
void CreateAlphaFromRGBA(int w, int h, std::vector<unsigned char> &rgba) else if (this->Dimension == 2)
{ {
dim = 2; glBindTexture(GL_TEXTURE_2D, this->ID);
std::vector<unsigned char> alpha(rgba.size()/4); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
for (unsigned int i=0; i<alpha.size(); i++) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
{ if (this->Linear2D)
alpha[i] = rgba[i*4+3]; {
} glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (!this->MIPMap)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
else if (this->LinearMIP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (!this->MIPMap)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
else if (this->LinearMIP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
}
glEnable(GL_TEXTURE_2D);
}
}
void Disable()
{
if (this->Dimension == 1)
glDisable(GL_TEXTURE_1D);
else if (this->Dimension == 2)
glDisable(GL_TEXTURE_2D);
}
void CreateAlphaFromRGBA(int w, int h, std::vector<unsigned char> &rgba)
{
this->Dimension = 2;
std::vector<unsigned char> alpha(rgba.size()/4);
for (unsigned int i=0; i<alpha.size(); i++)
{
alpha[i] = rgba[i*4+3];
}
if (id == 0) if (this->ID == 0)
{ {
glGenTextures(1, &id); glGenTextures(1, &this->ID);
} }
if (dim == 1) if (this->Dimension == 1)
{ {
glBindTexture(GL_TEXTURE_1D, id); glBindTexture(GL_TEXTURE_1D, this->ID);
} }
else if (dim == 2) else if (this->Dimension == 2)
{ {
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, this->ID);
//#define HW_MIPMAPS //#define HW_MIPMAPS
#ifdef HW_MIPMAPS #ifdef HW_MIPMAPS
mpimap = true; mpimap = true;
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
#endif #endif
glTexImage2D(GL_TEXTURE_2D, 0, glTexImage2D(GL_TEXTURE_2D, 0,
GL_ALPHA, GL_ALPHA,
w, h, w, h,
0, 0,
GL_ALPHA, GL_ALPHA,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
(void*)(&(alpha[0]))); (void*)(&(alpha[0])));
}
} }
}
}; };

@ -108,67 +108,67 @@ public:
void operator()(const CellNodeVecType &cellIndices, void operator()(const CellNodeVecType &cellIndices,
const vtkm::Id &cellIndex) const const vtkm::Id &cellIndex) const
{ {
vtkm::Vec<vtkm::Id,4> triangle; vtkm::Vec<vtkm::Id,4> triangle;
if (DIM == 2) if (DIM == 2)
{ {
const vtkm::Id triangleOffset = cellIndex * 2; const vtkm::Id triangleOffset = cellIndex * 2;
// 0-1-2 // 0-1-2
triangle[1] = cellIndices[0]; triangle[1] = cellIndices[0];
triangle[2] = cellIndices[1]; triangle[2] = cellIndices[1];
triangle[3] = cellIndices[2]; triangle[3] = cellIndices[2];
triangle[0] = cellIndex; triangle[0] = cellIndex;
OutputIndices.Set(triangleOffset, triangle); OutputIndices.Set(triangleOffset, triangle);
// 0-3-2 // 0-3-2
triangle[2] = cellIndices[3]; triangle[2] = cellIndices[3];
OutputIndices.Set(triangleOffset+1, triangle); OutputIndices.Set(triangleOffset+1, triangle);
} }
else if (DIM == 3) else if (DIM == 3)
{ {
const vtkm::Id triangleOffset = cellIndex * 12; const vtkm::Id triangleOffset = cellIndex * 12;
// 0-1-2 // 0-1-2
triangle[1] = cellIndices[0]; triangle[1] = cellIndices[0];
triangle[2] = cellIndices[1]; triangle[2] = cellIndices[1];
triangle[3] = cellIndices[2]; triangle[3] = cellIndices[2];
triangle[0] = cellIndex; triangle[0] = cellIndex;
OutputIndices.Set(triangleOffset, triangle); OutputIndices.Set(triangleOffset, triangle);
// 0-3-2 // 0-3-2
triangle[2] = cellIndices[3]; triangle[2] = cellIndices[3];
OutputIndices.Set(triangleOffset+1, triangle); OutputIndices.Set(triangleOffset+1, triangle);
// 0-3-7 // 0-3-7
triangle[3] = cellIndices[7]; triangle[3] = cellIndices[7];
OutputIndices.Set(triangleOffset+2, triangle); OutputIndices.Set(triangleOffset+2, triangle);
// 0-4-7 // 0-4-7
triangle[2] = cellIndices[4]; triangle[2] = cellIndices[4];
OutputIndices.Set(triangleOffset+3, triangle); OutputIndices.Set(triangleOffset+3, triangle);
// 5-4-7 // 5-4-7
triangle[1] = cellIndices[5]; triangle[1] = cellIndices[5];
OutputIndices.Set(triangleOffset+4, triangle); OutputIndices.Set(triangleOffset+4, triangle);
// 5-6-7 // 5-6-7
triangle[2] = cellIndices[6]; triangle[2] = cellIndices[6];
OutputIndices.Set(triangleOffset+5, triangle); OutputIndices.Set(triangleOffset+5, triangle);
// 3-6-7 // 3-6-7
triangle[1] = cellIndices[3]; triangle[1] = cellIndices[3];
OutputIndices.Set(triangleOffset+6, triangle); OutputIndices.Set(triangleOffset+6, triangle);
// 3-6-2 // 3-6-2
triangle[3] = cellIndices[2]; triangle[3] = cellIndices[2];
OutputIndices.Set(triangleOffset+7, triangle); OutputIndices.Set(triangleOffset+7, triangle);
// 1-6-2 // 1-6-2
triangle[1] = cellIndices[1]; triangle[1] = cellIndices[1];
OutputIndices.Set(triangleOffset+8, triangle); OutputIndices.Set(triangleOffset+8, triangle);
// 1-6-5 // 1-6-5
triangle[3] = cellIndices[5]; triangle[3] = cellIndices[5];
OutputIndices.Set(triangleOffset+9, triangle); OutputIndices.Set(triangleOffset+9, triangle);
// 1-4-5 // 1-4-5
triangle[2] = cellIndices[4]; triangle[2] = cellIndices[4];
OutputIndices.Set(triangleOffset+10, triangle); OutputIndices.Set(triangleOffset+10, triangle);
// 1-4-0 // 1-4-0
triangle[3] = cellIndices[0]; triangle[3] = cellIndices[0];
OutputIndices.Set(triangleOffset+11, triangle); OutputIndices.Set(triangleOffset+11, triangle);
} }
else else
{ {
throw vtkm::cont::ErrorControlBadType("Unsupported dimension for structured trianglulation"); throw vtkm::cont::ErrorControlBadType("Unsupported dimension for structured trianglulation");
} }
} }
}; };
@ -540,7 +540,7 @@ public:
vtkm::Id shapeTypeAsId = cellSetSingleType.GetCellShape(0); vtkm::Id shapeTypeAsId = cellSetSingleType.GetCellShape(0);
if(shapeTypeAsId == vtkm::CellShapeTagTriangle::Id) if(shapeTypeAsId == vtkm::CellShapeTagTriangle::Id)
{ {
//generate the outputIndices //generate the outputIndices
vtkm::Id totalTriangles = cellSetSingleType.GetNumberOfCells(); vtkm::Id totalTriangles = cellSetSingleType.GetNumberOfCells();
vtkm::cont::ArrayHandleCounting<vtkm::Id> cellIdxs(0,1,totalTriangles); vtkm::cont::ArrayHandleCounting<vtkm::Id> cellIdxs(0,1,totalTriangles);
@ -549,16 +549,16 @@ public:
vtkm::worklet::DispatcherMapField<Trianglulate>( Trianglulate(outputIndices, vtkm::worklet::DispatcherMapField<Trianglulate>( Trianglulate(outputIndices,
cellSetSingleType.GetConnectivityArray( PointTag(), CellTag() ), cellSetSingleType.GetConnectivityArray( PointTag(), CellTag() ),
totalTriangles) ) totalTriangles) )
.Invoke(cellSetSingleType.GetShapesArray( PointTag(), CellTag() ), .Invoke(cellSetSingleType.GetShapesArray( PointTag(), CellTag() ),
cellSetSingleType.GetIndexOffsetArray( PointTag(), CellTag()), cellSetSingleType.GetIndexOffsetArray( PointTag(), CellTag()),
cellIdxs ); cellIdxs );
outputTriangles = totalTriangles; outputTriangles = totalTriangles;
} }
else else
{ {
throw vtkm::cont::ErrorControlBadType("Unsupported cell type for trianglulation with CellSetSingleType"); throw vtkm::cont::ErrorControlBadType("Unsupported cell type for trianglulation with CellSetSingleType");
} }
} }
else else
{ {

@ -93,17 +93,17 @@ public:
} }
private: private:
BitmapFont font; BitmapFont Font;
TextureGL fontTexture; TextureGL FontTexture;
void RenderText(vtkm::Float32 scale, void RenderText(vtkm::Float32 scale,
vtkm::Float32 anchorx, vtkm::Float32 anchory, vtkm::Float32 anchorx, vtkm::Float32 anchory,
std::string text) std::string text)
{ {
if (fontTexture.id == 0) if (this->FontTexture.ID == 0)
{ {
font = BitmapFontFactory::CreateLiberation2Sans(); Font = BitmapFontFactory::CreateLiberation2Sans();
std::vector<unsigned char> &rawpngdata = font.GetRawImageData(); std::vector<unsigned char> &rawpngdata = this->Font.GetRawImageData();
std::vector<unsigned char> rgba; std::vector<unsigned char> rgba;
unsigned long width, height; unsigned long width, height;
@ -114,11 +114,11 @@ private:
return; return;
} }
fontTexture.CreateAlphaFromRGBA(int(width),int(height),rgba); this->FontTexture.CreateAlphaFromRGBA(int(width),int(height),rgba);
} }
fontTexture.Enable(); this->FontTexture.Enable();
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -129,7 +129,7 @@ private:
glBegin(GL_QUADS); glBegin(GL_QUADS);
vtkm::Float32 textwidth = font.GetTextWidth(text); vtkm::Float32 textwidth = this->Font.GetTextWidth(text);
vtkm::Float32 fx = -(.5f + .5f*anchorx) * textwidth; vtkm::Float32 fx = -(.5f + .5f*anchorx) * textwidth;
vtkm::Float32 fy = -(.5f + .5f*anchory); vtkm::Float32 fy = -(.5f + .5f*anchory);
@ -141,7 +141,7 @@ private:
vtkm::Float32 vl,vr,vt,vb; vtkm::Float32 vl,vr,vt,vb;
vtkm::Float32 tl,tr,tt,tb; vtkm::Float32 tl,tr,tt,tb;
font.GetCharPolygon(c, fx, fy, this->Font.GetCharPolygon(c, fx, fy,
vl, vr, vt, vb, vl, vr, vt, vb,
tl, tr, tt, tb, nextchar); tl, tr, tt, tb, nextchar);
@ -160,7 +160,7 @@ private:
glEnd(); glEnd();
fontTexture.Disable(); this->FontTexture.Disable();
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0); //glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);