Commit 9f33a74f authored by David C. Lonie's avatar David C. Lonie
Browse files

Move scalar bar GL2PS special case handler from PV to VTK.

This patch moves the special handler code for scalar bars from paraview
into VTK. The code was originally in PV as the PVScalarBar differed
significantly from vtkScalarBar, but now that they share more of their
implementations VTK can handle the export.

Change-Id: Icf37d51f46ba2569db86da1125c5c0c4f247747f
parent 3fff2799
......@@ -3,6 +3,7 @@ vtk_module(vtkIOExport
StandAlone
DEPENDS
vtkCommonCore
vtkRenderingAnnotation
vtkRenderingContext2D
vtkRenderingCore
vtkRenderingFreeType
......
......@@ -24,6 +24,7 @@
#include "vtkContextActor.h"
#include "vtkContextScene.h"
#include "vtkCoordinate.h"
#include "vtkFloatArray.h"
#include "vtkGL2PSContextDevice2D.h"
#include "vtkGL2PSUtilities.h"
#include "vtkImageData.h"
......@@ -36,11 +37,13 @@
#include "vtkObjectFactory.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkPath.h"
#include "vtkPointData.h"
#include "vtkProp.h"
#include "vtkProp3DCollection.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRendererCollection.h"
#include "vtkScalarBarActor.h"
#include "vtkStdString.h"
#include "vtkTextActor.h"
#include "vtkTextActor3D.h"
......@@ -673,6 +676,10 @@ void vtkGL2PSExporter::HandleSpecialProp(vtkProp *prop, vtkRenderer *ren)
return;
}
}
else if (vtkScalarBarActor *bar = vtkScalarBarActor::SafeDownCast(act2d))
{
this->DrawScalarBarActor(bar, ren);
}
else // Some other actor2D
{
return;
......@@ -749,6 +756,35 @@ void vtkGL2PSExporter::DrawTextMapper(vtkTextMapper *textMap,
this->DrawViewportTextOverlay(string, tprop, coord, ren);
}
void vtkGL2PSExporter::DrawScalarBarActor(vtkScalarBarActor *bar,
vtkRenderer *ren)
{
// Disable colorbar -- the texture doesn't render properly, we'll copy the
// rasterized pixel data for it.
int drawColorBarOrig(bar->GetDrawColorBar());
bar->SetDrawColorBar(0);
// Disable text -- it is handled separately
int drawTickLabelsOrig(bar->GetDrawTickLabels());
bar->SetDrawTickLabels(0);
int drawAnnotationsOrig(bar->GetDrawAnnotations());
bar->SetDrawAnnotations(0);
// Render what's left:
bar->RenderOpaqueGeometry(ren);
bar->RenderOverlay(ren);
// Restore settings
bar->SetDrawColorBar(drawColorBarOrig);
bar->SetDrawTickLabels(drawTickLabelsOrig);
bar->SetDrawAnnotations(drawAnnotationsOrig);
// Copy the color bar into the output.
int rect[4];
bar->GetScalarBarRect(rect, ren);
this->CopyPixels(rect, ren);
}
void vtkGL2PSExporter::DrawViewportTextOverlay(const char *string,
vtkTextProperty *tprop,
vtkCoordinate *coord,
......
......@@ -92,6 +92,7 @@ class vtkPropCollection;
class vtkProp3DCollection;
class vtkRenderer;
class vtkRendererCollection;
class vtkScalarBarActor;
class vtkTextActor;
class vtkTextActor3D;
class vtkTextMapper;
......@@ -310,6 +311,7 @@ protected:
void DrawTextActor3D(vtkTextActor3D *textAct, vtkRenderer *ren);
void DrawTextMapper(vtkTextMapper *textMap, vtkActor2D *textAct,
vtkRenderer *ren);
void DrawScalarBarActor(vtkScalarBarActor *bar, vtkRenderer *ren);
void DrawViewportTextOverlay(const char *string, vtkTextProperty *tprop,
vtkCoordinate *coord, vtkRenderer *ren);
......
......@@ -18,6 +18,7 @@
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkColor.h"
#include "vtkCoordinate.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkImageData.h"
......@@ -27,6 +28,7 @@
#include "vtkPolyDataMapper2D.h"
#include "vtkProperty2D.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkScalarsToColors.h"
#include "vtkSmartPointer.h"
#include "vtkTextActor.h"
......@@ -233,6 +235,7 @@ vtkScalarBarActor::vtkScalarBarActor()
->SetReferenceCoordinate(this->PositionCoordinate);
this->DrawColorBar = true;
this->DrawTickLabels = true;
}
//----------------------------------------------------------------------------
......@@ -265,6 +268,21 @@ void vtkScalarBarActor::ReleaseGraphicsResources(vtkWindow* win)
this->FrameActor->ReleaseGraphicsResources(win);
}
//----------------------------------------------------------------------------
void vtkScalarBarActor::GetScalarBarRect(int rect[4], vtkViewport* viewport)
{
vtkCoordinate *origin = this->ScalarBarActor->GetPositionCoordinate();
int * vpPos = origin->GetComputedViewportValue(viewport);
rect[0] = vpPos[0];
rect[1] = vpPos[1];
double *bounds = this->ScalarBar->GetBounds();
rect[0] += static_cast<int>(bounds[0] + 0.5);
rect[1] += static_cast<int>(bounds[2] + 0.5);
rect[2] = static_cast<int>(bounds[1] - bounds[0] + 0.5);
rect[3] = static_cast<int>(bounds[3] - bounds[2] + 0.5);
}
//----------------------------------------------------------------------------
vtkScalarBarActor::~vtkScalarBarActor()
{
......@@ -327,6 +345,19 @@ int vtkScalarBarActor::RenderOverlay(vtkViewport* viewport)
{
int renderedSomething = 0;
// Is the viewport's RenderWindow capturing GL2PS-special props? We'll need
// to handle this specially to get the texture to show up right.
if (vtkRenderer *renderer = vtkRenderer::SafeDownCast(viewport))
{
if (vtkRenderWindow *renderWindow = renderer->GetRenderWindow())
{
if (renderWindow->GetCapturingGL2PSSpecialProps())
{
renderer->CaptureGL2PSSpecialProp(this);
}
}
}
// Everything is built, just have to render
if (this->DrawBackground)
{
......@@ -348,13 +379,16 @@ int vtkScalarBarActor::RenderOverlay(vtkViewport* viewport)
renderedSomething += this->ScalarBarActor->RenderOverlay(viewport);
}
vtkScalarBarActorInternal::ActorVec::iterator it;
for (
it = this->P->TextActors.begin();
it != this->P->TextActors.end();
++it)
if (this->DrawTickLabels)
{
renderedSomething += (*it)->RenderOverlay(viewport);
vtkScalarBarActorInternal::ActorVec::iterator it;
for (
it = this->P->TextActors.begin();
it != this->P->TextActors.end();
++it)
{
renderedSomething += (*it)->RenderOverlay(viewport);
}
}
}
else if (this->DrawColorBar)
......
......@@ -98,6 +98,12 @@ public:
// resources to release.
virtual void ReleaseGraphicsResources(vtkWindow*);
// Description:
// Fills rect with the dimensions of the scalar bar in viewport coordinates.
// Only the color bar is considered -- text labels are not considered.
// rect is {xmin, xmax, width, height}
virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
// Description:
// Set/Get the lookup table to use. The lookup table specifies the number
// of colors to use in the table (if not overridden), the scalar range,
......@@ -274,6 +280,12 @@ public:
vtkGetMacro(DrawColorBar, int);
vtkBooleanMacro(DrawColorBar, int);
// Description:
// Set/Get whether the tick labels should be drawn. Default is on.
vtkSetMacro(DrawTickLabels, int);
vtkGetMacro(DrawTickLabels, int);
vtkBooleanMacro(DrawTickLabels, int);
// Description:
// Set/Get the background property.
virtual void SetBackgroundProperty(vtkProperty2D* p);
......@@ -476,6 +488,7 @@ protected:
int DrawBackground; // off by default
int DrawFrame; // off by default
int DrawColorBar; // on by default
int DrawTickLabels; // on by default
int DrawAnnotations;
int DrawNanAnnotation;
int AnnotationTextScaling; // off by default
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment