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

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

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

@ -39,172 +39,172 @@ namespace rendering {
class RenderSurfaceGL : public RenderSurface
{
public:
VTKM_CONT_EXPORT
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))
: RenderSurface(w,h,c)
VTKM_CONT_EXPORT
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))
: 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
virtual void Clear()
glViewport(static_cast<int>(_x), static_cast<int>(_y),
static_cast<int>(_w), static_cast<int>(_h));
}
else
{
glClearColor(this->BackgroundColor.Components[0],
this->BackgroundColor.Components[1],
this->BackgroundColor.Components[2],
1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0, v.Width, v.Height);
}
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_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;
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();
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();
}
VTKM_CONT_EXPORT
@ -226,17 +226,17 @@ public:
}
private:
BitmapFont font;
TextureGL fontTexture;
BitmapFont Font;
TextureGL FontTexture;
void RenderText(vtkm::Float32 scale,
vtkm::Float32 anchorx, vtkm::Float32 anchory,
std::string text)
{
if (fontTexture.id == 0)
if (this->FontTexture.ID == 0)
{
font = BitmapFontFactory::CreateLiberation2Sans();
std::vector<unsigned char> &rawpngdata = font.GetRawImageData();
Font = BitmapFontFactory::CreateLiberation2Sans();
std::vector<unsigned char> &rawpngdata = this->Font.GetRawImageData();
std::vector<unsigned char> rgba;
unsigned long width, height;
@ -247,11 +247,11 @@ private:
return;
}
fontTexture.CreateAlphaFromRGBA(int(width),int(height),rgba);
this->FontTexture.CreateAlphaFromRGBA(int(width),int(height),rgba);
}
fontTexture.Enable();
this->FontTexture.Enable();
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -262,7 +262,7 @@ private:
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 fy = -(.5f + .5f*anchory);
@ -274,7 +274,7 @@ private:
vtkm::Float32 vl,vr,vt,vb;
vtkm::Float32 tl,tr,tt,tb;
font.GetCharPolygon(c, fx, fy,
this->Font.GetCharPolygon(c, fx, fy,
vl, vr, vt, vb,
tl, tr, tt, tb, nextchar);
@ -293,7 +293,7 @@ private:
glEnd();
fontTexture.Disable();
this->FontTexture.Disable();
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
glDepthMask(GL_TRUE);

@ -36,56 +36,56 @@ namespace rendering {
class RenderSurfaceGLX : public RenderSurfaceGL
{
public:
VTKM_CONT_EXPORT
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))
: RenderSurfaceGL(w,h,c)
{
ctx = NULL;
}
VTKM_CONT_EXPORT
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))
: RenderSurfaceGL(w,h,c)
{
ctx = NULL;
}
VTKM_CONT_EXPORT
virtual void Initialize()
{
ctx = glXGetCurrentContext();
if (!ctx)
throw vtkm::cont::ErrorControlBadValue("GL context creation failed.");
/*
rgba.resize(width*height*4);
if (!OSMesaMakeCurrent(ctx, &rgba[0], GL_FLOAT, static_cast<GLsizei>(width), static_cast<GLsizei>(height)))
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
*/
VTKM_CONT_EXPORT
virtual void Initialize()
{
ctx = glXGetCurrentContext();
if (!ctx)
throw vtkm::cont::ErrorControlBadValue("GL context creation failed.");
/*
rgba.resize(width*height*4);
if (!OSMesaMakeCurrent(ctx, &rgba[0], GL_FLOAT, static_cast<GLsizei>(width), static_cast<GLsizei>(height)))
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
*/
glEnable(GL_DEPTH_TEST);
}
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
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();
/* TODO
//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)!=width || static_cast<std::size_t>(h)!=height)
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
std::size_t npixels = width*height;
for (std::size_t i=0; i<npixels; i++)
zbuff[i] = float(raw_zbuff[i]) / float(UINT_MAX);
*/
}
/* TODO
//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)!=width || static_cast<std::size_t>(h)!=height)
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
std::size_t npixels = width*height;
for (std::size_t i=0; i<npixels; i++)
zbuff[i] = float(raw_zbuff[i]) / float(UINT_MAX);
*/
}
private:
GLXContext ctx;

@ -36,64 +36,64 @@ namespace rendering {
class RenderSurfaceOSMesa : public RenderSurfaceGL
{
public:
VTKM_CONT_EXPORT
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))
: RenderSurfaceGL(w,h,c)
VTKM_CONT_EXPORT
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))
: 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
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);
}
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
virtual void Clear()
//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)
{
glClearColor(this->BackgroundColor.Components[0],
this->BackgroundColor.Components[1],
this->BackgroundColor.Components[2],
1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
}
VTKM_CONT_EXPORT
virtual void Finish()
std::size_t npixels = this->Width*this->Height;
for (std::size_t i=0; i<npixels; i++)
{
RenderSurfaceGL::Finish();
//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);
}
this->DepthBuffer[i] = float(raw_zbuff[i]) / float(UINT_MAX);
}
}
private:
OSMesaContext ctx;

@ -36,77 +36,77 @@ namespace rendering {
class RenderSurfaceRayTracer : public RenderSurface
{
public:
VTKM_CONT_EXPORT
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))
: RenderSurface(width,height,color)
{
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
}
VTKM_CONT_EXPORT
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))
: RenderSurface(width,height,color)
{
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
}
class ClearBuffers : public vtkm::worklet::WorkletMapField
{
vtkm::rendering::Color ClearColor;
vtkm::Id NumPixels;
public:
VTKM_CONT_EXPORT
ClearBuffers(const vtkm::rendering::Color &clearColor,
vtkm::Id numPixels)
class ClearBuffers : public vtkm::worklet::WorkletMapField
{
vtkm::rendering::Color ClearColor;
vtkm::Id NumPixels;
public:
VTKM_CONT_EXPORT
ClearBuffers(const vtkm::rendering::Color &clearColor,
vtkm::Id numPixels)
: ClearColor(clearColor),
NumPixels(numPixels)
{}
typedef void ControlSignature(FieldOut<>,
ExecObject);
typedef void ExecutionSignature(_1,
_2,
WorkIndex);
VTKM_EXEC_EXPORT
void operator()(vtkm::Float32 &depth,
vtkm::exec::ExecutionWholeArray<vtkm::Float32> &colorBuffer,
const vtkm::Id &index) const
{}
typedef void ControlSignature(FieldOut<>,
ExecObject);
typedef void ExecutionSignature(_1,
_2,
WorkIndex);
VTKM_EXEC_EXPORT
void operator()(vtkm::Float32 &depth,
vtkm::exec::ExecutionWholeArray<vtkm::Float32> &colorBuffer,
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;
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]);
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);
}
}; //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
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 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;
vtkm::cont::ArrayHandle<vtkm::Float32> ColorArray;
vtkm::cont::ArrayHandle<vtkm::Float32> DepthArray;
};

@ -44,38 +44,38 @@ public:
};
protected:
std::string text;
Color color;
vtkm::Float32 scale;
vtkm::Float32 anchorx, anchory;
std::string Text;
Color TextColor;
vtkm::Float32 Scale;
vtkm::Float32 AnchorX, AnchorY;
public:
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
anchorx = -1;
anchory = -1;
AnchorX = -1;
AnchorY = -1;
}
virtual ~TextAnnotation()
{
}
void SetText(const std::string &txt)
{
text = txt;
Text = txt;
}
void SetRawAnchor(vtkm::Float32 h, vtkm::Float32 v)
{
anchorx = h;
anchory = 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;
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
@ -89,14 +89,14 @@ public:
// 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;
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;
Scale = s;
}
virtual void Render(View &view,
WorldAnnotator &worldAnnotator,
@ -106,21 +106,21 @@ public:
class ScreenTextAnnotation : public TextAnnotation
{
protected:
vtkm::Float32 x,y;
vtkm::Float32 angle;
vtkm::Float32 XPos,YPos;
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;
XPos = ox;
YPos = oy;
Angle = angleDeg;
}
void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy)
{
x = ox;
y = oy;
XPos = ox;
YPos = oy;
}
virtual void Render(View &view,
WorldAnnotator &,
@ -129,36 +129,36 @@ public:
vtkm::Float32 WindowAspect = vtkm::Float32(view.Width) /
vtkm::Float32(view.Height);
renderSurface.AddText(x,y,
scale,
angle,
renderSurface.AddText(XPos,YPos,
Scale,
Angle,
WindowAspect,
anchorx, anchory,
color, text);
AnchorX, AnchorY,
TextColor, Text);
}
};
class BillboardTextAnnotation : public TextAnnotation
{
protected:
vtkm::Float32 x,y,z;
vtkm::Float32 angle;
vtkm::Float32 XPos,YPos,ZPos;
vtkm::Float32 Angle;
public:
BillboardTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s,
vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz,
vtkm::Float32 angleDeg = 0.)
: TextAnnotation(txt,c,s)
{
x = ox;
y = oy;
z = oz;
angle = angleDeg;
XPos = ox;
YPos = oy;
ZPos = oz;
Angle = angleDeg;
}
void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz)
{
x = ox;
y = oy;
z = oz;
XPos = ox;
YPos = oy;
ZPos = oz;
}
virtual void Render(View &view,
@ -169,7 +169,7 @@ public:
V = view.CreateViewMatrix();
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::MatrixMultiply(vtkm::MatrixMultiply(P,V), p4w);
@ -201,7 +201,7 @@ public:
}
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> right4(1,0,0,0);
@ -235,9 +235,9 @@ public:
worldAnnotator.AddText(px,py,pz,
rx,ry,rz,
ux,uy,uz,
scale,
anchorx, anchory,
color, text);
Scale,
AnchorX, AnchorY,
TextColor, Text);
renderSurface.SetViewToWorldSpace(view,true);
}

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

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

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