Commit 6c67ab11 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

STYLE: A little refactoring and additional docs.

Refactored this class to use smart pointers, and added some notes about
using the view with QVTKWidget.
parent 1740b297
......@@ -35,7 +35,7 @@ vtkCxxSetObjectMacro(vtkContextView, Scene, vtkContextScene);
//----------------------------------------------------------------------------
vtkContextView::vtkContextView()
{
this->Context = vtkContext2D::New();
this->Context = vtkSmartPointer<vtkContext2D>::New();
vtkOpenGLContextDevice2D *pd = vtkOpenGLContextDevice2D::New();
this->Context->Begin(pd);
pd->Delete();
......@@ -44,7 +44,6 @@ vtkContextView::vtkContextView()
this->Renderer->AddActor(actor);
actor->Delete();
this->Scene = actor->GetScene(); // We keep a pointer to this for convenience
this->Scene->Register(this);
// Should not need to do this...
this->Scene->SetRenderer(this->Renderer);
this->Scene->SetInteractorStyle(
......@@ -58,17 +57,18 @@ vtkContextView::vtkContextView()
//----------------------------------------------------------------------------
vtkContextView::~vtkContextView()
{
if (this->Context)
{
this->Context->Delete();
this->Context = NULL;
}
// The scene is owned by the context actor
if (this->Scene)
{
this->Scene->Delete();
this->Scene = NULL;
}
}
//----------------------------------------------------------------------------
vtkContext2D* vtkContextView::GetContext()
{
return this->Context;
}
//----------------------------------------------------------------------------
vtkContextScene* vtkContextView::GetScene()
{
return this->Scene;
}
//----------------------------------------------------------------------------
......
......@@ -15,23 +15,34 @@
// .NAME vtkContextView - provides a view of the vtkContextScene.
//
// .SECTION Description
// This class is derived from vtkRenderView and provides a view of a
// vtkContextScene, with a default interactor style, renderer etc.
// This class is derived from vtkRenderViewBase and provides a view of a
// vtkContextScene, with a default interactor style, renderer etc. It is
// the simplest way to create a vtkRenderWindow and display a 2D scene inside
// of it.
//
// In order to use the view with a QVTKWidget the following code is required
// to ensure the interactor and render window are initialized properly.
// \code
// QVTKWidget *widget = new QVTKWidget;
// vtkContextView *view = vtkContextView::New();
// view->SetInteractor(widget->GetInteractor());
// widget->SetRenderWindow(view->GetRenderWindow());
// \endcode
#ifndef __vtkContextView_h
#define __vtkContextView_h
#include "vtkRenderViewBase.h"
#include "vtkSmartPointer.h" // Needed for SP ivars
class vtkContext2D;
class vtkContextScene;
class vtkRenderWindowInteractor;
class VTK_CHARTS_EXPORT vtkContextView : public vtkRenderViewBase
{
public:
void PrintSelf(ostream& os, vtkIndent indent);
vtkTypeMacro(vtkContextView,vtkRenderViewBase);
vtkTypeMacro(vtkContextView, vtkRenderViewBase);
static vtkContextView* New();
......@@ -41,16 +52,16 @@ public:
// Description:
// Get the vtkContext2D for the view.
vtkGetObjectMacro(Context, vtkContext2D);
// Description:
// Get the scene of the view.
vtkGetObjectMacro(Scene, vtkContextScene);
virtual vtkContext2D* GetContext();
// Description:
// Set the scene object for the view.
virtual void SetScene(vtkContextScene *scene);
// Description:
// Get the scene of the view.
virtual vtkContextScene* GetScene();
// Description:
// Updates the representations, then calls Render() on the render window
// associated with this view.
......@@ -60,8 +71,8 @@ protected:
vtkContextView();
~vtkContextView();
vtkContextScene *Scene;
vtkContext2D *Context;
vtkSmartPointer<vtkContextScene> Scene;
vtkSmartPointer<vtkContext2D> Context;
private:
vtkContextView(const vtkContextView&); // Not implemented.
......
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