<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2017-02-12 12:30 GMT+01:00 Elvis Stansvik <span dir="ltr"><<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi all,<br><br></div>In the test case below, I'm trying to get the bounding rect of a vtkAxis in a vtkChartXY, but I'm getting a crash in the call to GetBoundingRect with the following backtrace:<br><br>#0 vtkOpenGLContextDevice2D::<wbr>ComputeStringBounds (this=this@entry=0x689ea0, string=..., bounds=bounds@entry=<wbr>0x7fffffffcda0)<br> at /buildbot/vtk7-builder/build/<wbr>Rendering/ContextOpenGL2/<wbr>vtkOpenGLContextDevice2D.cxx:<wbr>1755<br>#1 0x00007ffff78454f1 in vtkOpenGLContextDevice2D::<wbr>ComputeStringBounds (this=0x689ea0, string=..., bounds=0x7fffffffcda0)<br> at /buildbot/vtk7-builder/build/<wbr>Rendering/ContextOpenGL2/<wbr>vtkOpenGLContextDevice2D.cxx:<wbr>1626<br>#2 0x00007ffff6f2722d in vtkContext2D::<wbr>ComputeStringBounds (this=this@entry=0x67e3f0, string=..., bounds=bounds@entry=<wbr>0x7fffffffcda0) at /buildbot/vtk7-builder/build/<wbr>Rendering/Context2D/<wbr>vtkContext2D.cxx:645<br>#3 0x00007ffff7ab4b28 in vtkAxis::GetBoundingRect (this=0x671490, painter=0x67e3f0) at /buildbot/vtk7-builder/build/<wbr>Charts/Core/vtkAxis.cxx:990<br>#4 0x0000000000402ab1 in main (argc=1, argv=0x7fffffffd038) at /home/estan/testcrash/main.<wbr>cpp:50<br><br>The reason seems to be that the render window (RenderWindow member) of vtkOpenGLContextDevice2D is NULL at that point (!).<br><br></div>Am I using the GetBoundingRect API in the wrong way somehow? How can I get the computed bounding rect for a vtkAxis?<br></div></div></div></blockquote><div><br></div><div>I realize now that RenderWindow of the vtkOpenGLContextDevice2D is only valid during a paint (between Begin() and End()). At other times it is NULL. So is it not safe to call vtkAxis::GetBoundingRect(..) except during rendering..? If so, is there any other way to get the bounding rect of a vtkAxis as a user?<br><br></div><div>Elvis<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><br></div>Thanks in advance,<br></div>Elvis<br><div><div><div><br>main.cpp:<br><br>#include <vtkAxis.h><br>#include <vtkChartXY.h><br>#include <vtkContextScene.h><br>#include <vtkContextView.h><br>#include <vtkFloatArray.h><br>#include <vtkNew.h><br>#include <vtkPlot.h><br>#include <vtkRenderer.h><br>#include <vtkRenderWindow.h><br>#include <vtkRenderWindowInteractor.h><br>#include <vtkTable.h><br><br>int main(int argc, char *argv[]) {<br> vtkNew<vtkRenderer> renderer;<br><br> vtkNew<vtkRenderWindow> window;<br> window->AddRenderer(renderer.<wbr>Get());<br><br> vtkNew<<wbr>vtkRenderWindowInteractor> interactor;<br> interactor->SetRenderWindow(<wbr>window.Get());<br><br> vtkNew<vtkChartXY> chart;<br><br> vtkNew<vtkTable> table;<br> vtkNew<vtkFloatArray> xArray;<br> xArray->SetName("X Axis");<br> table->AddColumn(xArray.Get())<wbr>;<br> vtkNew<vtkFloatArray> yArray;<br> yArray->SetName("Y Axis");<br> table->AddColumn(yArray.Get())<wbr>;<br> table->SetNumberOfRows(2);<br> table->SetValue(0, 0, 0);<br> table->SetValue(0, 1, 0);<br> table->SetValue(1, 0, 1);<br> table->SetValue(1, 1, 1);<br><br> auto linePlot = chart->AddPlot(vtkChart::LINE)<wbr>;<br> linePlot->SetInputData(table.<wbr>Get(), 0, 1);<br><br> vtkNew<vtkContextView> view;<br> view->GetScene()->AddItem(<wbr>chart.Get());<br> view->SetRenderWindow(window.<wbr>Get());<br> view->SetInteractor(<wbr>interactor.Get());<br><br> window->Render();<br><br> // Get bounding rect of the left axis<br> auto leftAxis = chart->GetAxis(vtkAxis::LEFT);<br> leftAxis->Update();<br> auto rect = leftAxis->GetBoundingRect(<wbr>view->GetContext());<br><br> interactor->Start();<br><br> return 0;<br>}<br><br></div><div><br></div><div>CMakeLists.txt:<br><br>cmake_minimum_required(VERSION 3.1)<br> <br>project(TestCase)<br> <br>set(CMAKE_CXX_STANDARD 11)<br>set(CMAKE_CXX_STANDARD_<wbr>REQUIRED ON)<br><br>find_package(VTK COMPONENTS<br> vtkChartsCore<br> vtkCommonCore<br> vtkInteractionStyle<br> vtkRenderingContext2D<br> vtkRenderingContextOpenGL2<br> vtkRenderingCore<br> vtkRenderingFreeType<br> vtkRenderingOpenGL2<br> vtkViewsContext2D<br>)<br><br>add_executable(TestCase main.cpp)<br> <br>target_link_libraries(TestCase PUBLIC<br> vtkChartsCore<br> vtkCommonCore<br> vtkInteractionStyle<br> vtkRenderingContext2D<br> vtkRenderingContextOpenGL2<br> vtkRenderingCore<br> vtkRenderingFreeType<br> vtkRenderingOpenGL2<br> vtkViewsContext2D<br>)<br><br>target_include_directories(<wbr>TestCase PUBLIC<br> ${VTK_INCLUDE_DIRS}<br>)<br><br> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <br>target_compile_definitions(<wbr>TestCase PUBLIC <wbr> <wbr> <wbr> <wbr> <wbr> <br> ${VTK_DEFINITIONS} <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <br>)<br></div></div></div></div>
</blockquote></div><br></div></div>