Skip to content

Commit

Permalink
Merge topic 'contour-labels-tprop-bg' into master
Browse files Browse the repository at this point in the history
3f8164a Use the new background color rendering for the labeled contour test.
7e7306e Add background color/opacity settings to vtkTextProperty.
034dc39 Reenable GL2PS MathText tests.
  • Loading branch information
aashish24 authored and Code Review committed Feb 5, 2015
2 parents 34131e2 + 3f8164a commit 6d67334
Show file tree
Hide file tree
Showing 38 changed files with 942 additions and 187 deletions.
4 changes: 4 additions & 0 deletions IO/Export/Testing/Cxx/TestGL2PSTextActor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ int TestGL2PSTextActor(int, char *[])
break;
}
actor->GetTextProperty()->SetColor(0.75, .2 + col * .26, .2 + row * .2);
actor->GetTextProperty()->SetBackgroundColor(0.0,
0.8 - col * .26,
.8 - row * .2);
actor->GetTextProperty()->SetBackgroundOpacity(0.25);
actor->SetPosition(x[col], y[row]);
setupTextActor(actor.GetPointer(), anchors.GetPointer());
ren->AddActor2D(actor.GetPointer());
Expand Down
4 changes: 4 additions & 0 deletions IO/Export/Testing/Cxx/TestGL2PSTextActor3D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ int TestGL2PSTextActor3D(int, char *[])
actor->GetTextProperty()->SetFontSize(20);
actor->GetTextProperty()->SetOrientation(45.0 * (3 * row + col));
actor->GetTextProperty()->SetColor(0.75, .2 + col * .26, .2 + row * .26);
actor->GetTextProperty()->SetBackgroundColor(0.,
1. - col * .26,
1. - row * .26);
actor->GetTextProperty()->SetBackgroundOpacity(0.25);
actor->SetPosition(x[col], y[row], 0.);
setupTextActor3D(actor.GetPointer(), anchors.GetPointer());
ren->AddActor(actor.GetPointer());
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17db55890fe6ddfeee3bbc35df1ca551
632b71040c062eb22100ada4c81d72f3
2 changes: 1 addition & 1 deletion IO/Export/Testing/Data/Baseline/TestGL2PSTextActor.png.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371446ad76db1b69dd224fe70fede0de
e82e81aaa51e0e4d71ba878fffdeecf9
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bff4fc5c05935949f53e50518adb32b5
b7d370e65738b172570c1d8617e85d0b
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6eeee0c5b11a9d0dfd732422f40ef449
8d07293245771ce47e686dba6cca988a
69 changes: 53 additions & 16 deletions IO/Export/vtkGL2PSExporter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,12 @@ void vtkGL2PSExporter::DrawTextActor3D(vtkTextActor3D *textAct,
{
// Get path
const char *string = textAct->GetInput();
vtkNew<vtkPath> path;
vtkTextProperty *tprop = textAct->GetTextProperty();
vtkNew<vtkPath> textPath;
vtkTextRenderer *tren = vtkTextRenderer::GetInstance();
if (tren)
{
tren->StringToPath(textAct->GetTextProperty(), vtkStdString(string),
path.GetPointer());
tren->StringToPath(tprop, vtkStdString(string), textPath.GetPointer());
}
else
{
Expand All @@ -732,18 +732,55 @@ void vtkGL2PSExporter::DrawTextActor3D(vtkTextActor3D *textAct,
// Get actor info
vtkMatrix4x4 *actorMatrix = textAct->GetMatrix();
double *actorBounds = textAct->GetBounds();
double rasterPos[3] = {(actorBounds[1] + actorBounds[0]) * 0.5,
(actorBounds[3] + actorBounds[2]) * 0.5,
(actorBounds[5] + actorBounds[4]) * 0.5};
double *dcolor = textAct->GetTextProperty()->GetColor();
unsigned char actorColor[4] = {
static_cast<unsigned char>(dcolor[0]*255),
static_cast<unsigned char>(dcolor[1]*255),
static_cast<unsigned char>(dcolor[2]*255),
static_cast<unsigned char>(textAct->GetTextProperty()->GetOpacity()*255)};

vtkGL2PSUtilities::Draw3DPath(path.GetPointer(), actorMatrix, rasterPos,
actorColor);
double textPos[3] = {(actorBounds[1] + actorBounds[0]) * 0.5,
(actorBounds[3] + actorBounds[2]) * 0.5,
(actorBounds[5] + actorBounds[4]) * 0.5};

double *fgColord = tprop->GetColor();
unsigned char fgColor[4] = {
static_cast<unsigned char>(fgColord[0] * 255),
static_cast<unsigned char>(fgColord[1] * 255),
static_cast<unsigned char>(fgColord[2] * 255),
static_cast<unsigned char>(tprop->GetOpacity() * 255)};

// Draw the background quad as a path:
if (tprop->GetBackgroundOpacity() > 0.f)
{
double *bgColord = tprop->GetBackgroundColor();
unsigned char bgColor[4] = {
static_cast<unsigned char>(bgColord[0] * 255),
static_cast<unsigned char>(bgColord[1] * 255),
static_cast<unsigned char>(bgColord[2] * 255),
static_cast<unsigned char>(tprop->GetBackgroundOpacity() * 255)};

vtkTextRenderer::Metrics metrics;
if (tren->GetMetrics(tprop, string, metrics))
{
vtkNew<vtkPath> bgPath;
bgPath->InsertNextPoint(static_cast<double>(metrics.TopLeft.GetX()),
static_cast<double>(metrics.TopLeft.GetY()),
0., vtkPath::MOVE_TO);
bgPath->InsertNextPoint(static_cast<double>(metrics.TopRight.GetX()),
static_cast<double>(metrics.TopRight.GetY()),
0., vtkPath::LINE_TO);
bgPath->InsertNextPoint(static_cast<double>(metrics.BottomRight.GetX()),
static_cast<double>(metrics.BottomRight.GetY()),
0., vtkPath::LINE_TO);
bgPath->InsertNextPoint(static_cast<double>(metrics.BottomLeft.GetX()),
static_cast<double>(metrics.BottomLeft.GetY()),
0., vtkPath::LINE_TO);
bgPath->InsertNextPoint(static_cast<double>(metrics.TopLeft.GetX()),
static_cast<double>(metrics.TopLeft.GetY()),
0., vtkPath::LINE_TO);

vtkGL2PSUtilities::Draw3DPath(bgPath.GetPointer(), actorMatrix, textPos,
bgColor);
}
}

// Draw the text path:
vtkGL2PSUtilities::Draw3DPath(textPath.GetPointer(), actorMatrix, textPos,
fgColor);
}

void vtkGL2PSExporter::DrawTextMapper(vtkTextMapper *textMap,
Expand Down Expand Up @@ -855,7 +892,7 @@ void vtkGL2PSExporter::DrawViewportTextOverlay(const char *string,
glViewport(viewportPixels[0], viewportPixels[1],
viewportSpread[0], viewportSpread[1]);

vtkGL2PSUtilities::DrawString(string, tprop, textPos);
vtkGL2PSUtilities::DrawString(string, tprop, textPos, textPos[2] + 1e-6);

glMatrixMode(GL_MODELVIEW);
glPopMatrix();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
691dadad521a920ac166ef97da4564ab
b3a108656cae9e6f01016395f5ce4e57
2 changes: 2 additions & 0 deletions Rendering/Core/Testing/Cxx/TestLabeledContourMapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ int TestLabeledContourMapper(int argc, char *argv[])
vtkNew<vtkTextProperty> tprop1;
tprop1->SetBold(1);
tprop1->SetFontSize(12);
tprop1->SetBackgroundColor(0.5, 0.5, 0.5);
tprop1->SetBackgroundOpacity(0.25);
tprop1->SetColor(1., 1., 1.);
tprops->AddItem(tprop1.GetPointer());

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3fb283fb1bd0ec86173d0a86e367364c
77b1b4303fb2703732f2ef704494e305
17 changes: 17 additions & 0 deletions Rendering/Core/vtkTextProperty.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ vtkTextProperty::vtkTextProperty()

this->Opacity = 1.0;

this->BackgroundColor[0] = 0.0;
this->BackgroundColor[1] = 0.0;
this->BackgroundColor[2] = 0.0;

this->BackgroundOpacity = 0.0;

this->FontFamilyAsString = 0;
this->FontFile = NULL;
this->SetFontFamilyAsString( "Arial" );
Expand All @@ -46,6 +52,7 @@ vtkTextProperty::vtkTextProperty()
this->Orientation = 0.0;
}

//----------------------------------------------------------------------------
vtkTextProperty::~vtkTextProperty()
{
this->SetFontFamilyAsString(NULL);
Expand All @@ -63,6 +70,9 @@ void vtkTextProperty::ShallowCopy(vtkTextProperty *tprop)
this->SetColor(tprop->GetColor());
this->SetOpacity(tprop->GetOpacity());

this->SetBackgroundColor(tprop->GetBackgroundColor());
this->SetBackgroundOpacity(tprop->GetBackgroundOpacity());

this->SetFontFamilyAsString(tprop->GetFontFamilyAsString());
this->SetFontFile(tprop->GetFontFile());
this->SetFontSize(tprop->GetFontSize());
Expand Down Expand Up @@ -106,6 +116,13 @@ void vtkTextProperty::PrintSelf(ostream& os, vtkIndent indent)

os << indent << "Opacity: " << this->Opacity << "\n";

os << indent << "BackgroundColor: ("
<< this->BackgroundColor[0] << ", "
<< this->BackgroundColor[1] << ", "
<< this->BackgroundColor[2] << ")\n";

os << indent << "BackgroundOpacity: " << this->BackgroundOpacity << "\n";

os << indent << "FontFamilyAsString: "
<< (this->FontFamilyAsString ? this->FontFamilyAsString : "(null)") << endl;
os << indent << "FontFile: "
Expand Down
13 changes: 13 additions & 0 deletions Rendering/Core/vtkTextProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class VTKRENDERINGCORE_EXPORT vtkTextProperty : public vtkObject
vtkSetMacro(Opacity,double);
vtkGetMacro(Opacity,double);

// Description:
// The background color.
vtkSetVector3Macro(BackgroundColor, double);
vtkGetVector3Macro(BackgroundColor, double);

// Description:
// The background opacity. 1.0 is totally opaque and 0.0 is completely
// transparent.
vtkSetMacro(BackgroundOpacity, double);
vtkGetMacro(BackgroundOpacity, double);

// Description:
// Set/Get the font family. Supports legacy three font family system.
// If the symbolic constant VTK_FONT_FILE is returned by GetFontFamily(), the
Expand Down Expand Up @@ -157,6 +168,8 @@ class VTKRENDERINGCORE_EXPORT vtkTextProperty : public vtkObject

double Color[3];
double Opacity;
double BackgroundColor[3];
double BackgroundOpacity;
char* FontFamilyAsString;
char* FontFile;
int FontSize;
Expand Down
51 changes: 51 additions & 0 deletions Rendering/Core/vtkTextRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkObject.h"
#include "vtkTuple.h" // For metrics struct
#include "vtkVector.h" // For metrics struct

class vtkImageData;
class vtkPath;
Expand All @@ -67,6 +69,31 @@ class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
{
public:
struct Metrics
{
// Description:
// Construct a Metrics object with all members initialized to 0.
Metrics()
: BoundingBox(0),
TopLeft(0), TopRight(0), BottomLeft(0), BottomRight(0)
{
}

// Description:
// The axis-aligned bounding box of the rendered text and background, in
// pixels. The origin of the bounding box is the anchor point of the data
// when considering justification. Layout is { xMin, xMax, yMin, yMax }.
vtkTuple<int, 4> BoundingBox;

// Description:
// The corners of the rendered text (or background, if applicable), in pixels.
// Uses the same origin as BoundingBox.
vtkVector2i TopLeft;
vtkVector2i TopRight;
vtkVector2i BottomLeft;
vtkVector2i BottomRight;
};

vtkTypeMacro(vtkTextRenderer, vtkObject)
virtual void PrintSelf(ostream &os, vtkIndent indent);

Expand Down Expand Up @@ -133,6 +160,24 @@ class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
}


// Description:
// Given a text property and a string, get some metrics for the rendered
// string.
// Some rendering backends need the DPI of the target. If it is not provided,
// a DPI of 120 is assumed.
// Return true on success, false otherwise.
bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str,
Metrics &metrics, int dpi = 120, int backend = Default)
{
return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
}
bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str,
Metrics &metrics, int dpi = 120, int backend = Default)
{
return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
}

// Description:
// Given a text property and a string, this function initializes the
// vtkImageData *data and renders it in a vtkImageData.
Expand Down Expand Up @@ -224,6 +269,12 @@ class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
const vtkUnicodeString &str,
int bbox[4], int dpi, int backend) = 0;
virtual bool GetMetricsInternal(vtkTextProperty *tprop,
const vtkStdString &str,
Metrics &metrics, int dpi, int backend) = 0;
virtual bool GetMetricsInternal(vtkTextProperty *tprop,
const vtkUnicodeString &str,
Metrics &metrics, int dpi, int backend) = 0;
virtual bool RenderStringInternal(vtkTextProperty *tprop,
const vtkStdString &str,
vtkImageData *data, int textDims[2],
Expand Down
4 changes: 4 additions & 0 deletions Rendering/FreeType/Testing/Cxx/TestTextActor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ int TestTextActor(int, char *[])
break;
}
actor->GetTextProperty()->SetColor(0.75, .2 + col * .26, .2 + row * .2);
actor->GetTextProperty()->SetBackgroundColor(0.25, 0.4 - col * .13,
.5 - row * .1);
actor->GetTextProperty()->SetBackgroundOpacity(1.0);

actor->SetPosition(x[col], y[row]);
setupTextActor(actor.GetPointer(), anchors.GetPointer());
ren->AddActor2D(actor.GetPointer());
Expand Down
4 changes: 4 additions & 0 deletions Rendering/FreeType/Testing/Cxx/TestTextActor3D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ int TestTextActor3D(int, char *[])
actor->GetTextProperty()->SetFontSize(20);
actor->GetTextProperty()->SetOrientation(45.0 * (3 * row + col));
actor->GetTextProperty()->SetColor(0.75, .2 + col * .26, .2 + row * .26);
actor->GetTextProperty()->SetBackgroundColor(0.,
1. - col * .26,
1. - row * .26);
actor->GetTextProperty()->SetBackgroundOpacity(0.25);
actor->SetPosition(x[col], y[row], 0.);
setupTextActor3D(actor.GetPointer(), anchors.GetPointer());
ren->AddActor(actor.GetPointer());
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371446ad76db1b69dd224fe70fede0de
4e70849a90b83bc26f39aa60905bcad4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6eeee0c5b11a9d0dfd732422f40ef449
8d07293245771ce47e686dba6cca988a
Loading

0 comments on commit 6d67334

Please sign in to comment.