Commit b052d737 authored by Allison Vacanti's avatar Allison Vacanti Committed by Kitware Robot

Merge topic '17233-billboard_bounds_badly_broken_by_bug'

ecf70fee Retain renderer to recompute right rendered rectangle.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3904
parents 411dd52b ecf70fee
......@@ -324,6 +324,9 @@ int vtkBillboardTextActor3D::RenderOpaqueGeometry(vtkViewport *vp)
return 0;
}
// Cache for updating bounds between renders (#17233):
this->RenderedRenderer = ren;
// Alert OpenGL1 GL2PS export that this prop needs special handling:
if (ren->GetRenderWindow() &&
ren->GetRenderWindow()->GetCapturingGL2PSSpecialProps())
......@@ -331,15 +334,7 @@ int vtkBillboardTextActor3D::RenderOpaqueGeometry(vtkViewport *vp)
ren->CaptureGL2PSSpecialProp(this);
}
if (this->TextureIsStale(ren))
{
this->GenerateTexture(ren);
}
if (this->IsValid() && this->QuadIsStale(ren))
{
this->GenerateQuad(ren);
}
this->UpdateInternals(ren);
this->PreRender();
return this->QuadActor->RenderOpaqueGeometry(vp);
......@@ -364,6 +359,7 @@ int vtkBillboardTextActor3D::RenderTranslucentPolygonalGeometry(vtkViewport *vp)
//------------------------------------------------------------------------------
void vtkBillboardTextActor3D::ReleaseGraphicsResources(vtkWindow *win)
{
this->RenderedRenderer = nullptr;
this->Texture->ReleaseGraphicsResources(win);
this->QuadMapper->ReleaseGraphicsResources(win);
this->QuadActor->ReleaseGraphicsResources(win);
......@@ -372,6 +368,11 @@ void vtkBillboardTextActor3D::ReleaseGraphicsResources(vtkWindow *win)
//------------------------------------------------------------------------------
double *vtkBillboardTextActor3D::GetBounds()
{
if (this->RenderedRenderer)
{
this->UpdateInternals(this->RenderedRenderer);
}
if (this->IsValid())
{
this->QuadActor->GetBounds(this->Bounds);
......@@ -426,6 +427,7 @@ vtkBillboardTextActor3D::~vtkBillboardTextActor3D()
{
this->SetInput(nullptr);
this->SetTextProperty(nullptr);
this->RenderedRenderer = nullptr;
}
//------------------------------------------------------------------------------
......@@ -437,6 +439,20 @@ bool vtkBillboardTextActor3D::InputIsValid()
this->TextRenderer != nullptr);
}
//------------------------------------------------------------------------------
void vtkBillboardTextActor3D::UpdateInternals(vtkRenderer *ren)
{
if (this->TextureIsStale(ren))
{
this->GenerateTexture(ren);
}
if (this->IsValid() && this->QuadIsStale(ren))
{
this->GenerateQuad(ren);
}
}
//------------------------------------------------------------------------------
bool vtkBillboardTextActor3D::TextureIsStale(vtkRenderer *ren)
{
......@@ -468,7 +484,8 @@ void vtkBillboardTextActor3D::GenerateTexture(vtkRenderer *ren)
//------------------------------------------------------------------------------
bool vtkBillboardTextActor3D::QuadIsStale(vtkRenderer *ren)
{
return (this->Quad->GetMTime() < this->Image->GetMTime() ||
return (this->Quad->GetMTime() < this->GetMTime() ||
this->Quad->GetMTime() < this->Image->GetMTime() ||
this->Quad->GetMTime() < ren->GetMTime() ||
this->Quad->GetMTime() < ren->GetRenderWindow()->GetMTime() ||
this->Quad->GetMTime() < ren->GetActiveCamera()->GetMTime());
......
......@@ -23,6 +23,7 @@
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkProp3D.h"
#include "vtkNew.h" // For.... vtkNew!
#include "vtkSmartPointer.h" // For.... vtkSmartPointer!
class vtkActor;
class vtkImageData;
......@@ -111,6 +112,8 @@ protected:
bool InputIsValid();
void UpdateInternals(vtkRenderer *ren);
bool TextureIsStale(vtkRenderer *ren);
void GenerateTexture(vtkRenderer *ren);
......@@ -135,6 +138,9 @@ protected:
int RenderedDPI;
vtkTimeStamp InputMTime;
// We cache this so we can recompute the bounds between renders, if needed.
vtkSmartPointer<vtkRenderer> RenderedRenderer;
// Rendering stuffies
vtkNew<vtkTextRenderer> TextRenderer;
vtkNew<vtkImageData> Image;
......
......@@ -30,6 +30,7 @@
#include "vtkTextProperty.h"
#include "vtkUnsignedCharArray.h"
#include <algorithm>
#include <sstream>
#include <vector>
......@@ -92,6 +93,33 @@ void setupGrid(vtkPolyData *grid)
grid->InsertNextCell(VTK_QUAD, 4, &quads[i]);
}
}
// Test for bug #17233: https://gitlab.kitware.com/vtk/vtk/issues/17233
// The Bounds were not updated when the position changed. Ensure that we aren't
// returning stale bounds after modifying the actor.
bool RegressionTest_17233(vtkBillboardTextActor3D *actor)
{
double *bounds = actor->GetBounds();
double origBounds[6] = { bounds[0], bounds[1],
bounds[2], bounds[3],
bounds[4], bounds[5] };
double pos[3];
actor->GetPosition(pos);
pos[0] += 50.;
pos[1] += 50.;
pos[2] += 50.;
actor->SetPosition(pos);
bounds = actor->GetBounds();
if (std::equal(bounds, bounds + 6, origBounds))
{
std::cerr << "Regression for bug #17233: Stale bounds used.\n";
return false;
}
return true;
}
} // end namespace vtkTestBillboardTextActor3D
//----------------------------------------------------------------------------
......@@ -101,6 +129,9 @@ int TestBillboardTextActor3D(int, char *[])
vtkNew<vtkRenderer> ren;
ren->UseDepthPeelingOn();
// use this to capture one of the text actors for later regression testing:
vtkBillboardTextActor3D *bbActor = nullptr;
int width = 600;
int height = 600;
int x[3] = {100, 300, 500};
......@@ -155,6 +186,7 @@ int TestBillboardTextActor3D(int, char *[])
actor->SetPosition(x[col], y[row], 0.);
setupBillboardTextActor3D(actor, anchors);
ren->AddActor(actor);
bbActor = actor;
}
}
......@@ -215,5 +247,12 @@ int TestBillboardTextActor3D(int, char *[])
win->GetInteractor()->Initialize();
win->GetInteractor()->Start();
// Now that the image has been rendered, use one of the actors to do
// regression testing:
if (!RegressionTest_17233(bbActor))
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
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