vtkContextView.cxx 2.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkContextView.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkContextView.h"

#include "vtkContext2D.h"
18
#include "vtkContextDevice2D.h"
19 20 21 22 23 24 25 26
#include "vtkContextScene.h"

#include "vtkViewport.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyle.h"
#include "vtkContextActor.h"
27
#include "vtkContextInteractorStyle.h"
28 29 30 31 32 33 34 35 36 37 38

#include "vtkObjectFactory.h"

vtkStandardNewMacro(vtkContextView);

vtkCxxSetObjectMacro(vtkContextView, Context, vtkContext2D);
vtkCxxSetObjectMacro(vtkContextView, Scene, vtkContextScene);

//----------------------------------------------------------------------------
vtkContextView::vtkContextView()
{
39
  this->Context = vtkSmartPointer<vtkContext2D>::New();
40
  vtkNew<vtkContextDevice2D> pd;
41
  this->Context->Begin(pd);
42 43 44

  vtkContextActor *actor = vtkContextActor::New();
  this->Renderer->AddActor(actor);
45 46
  actor->Delete();
  this->Scene = actor->GetScene(); // We keep a pointer to this for convenience
47
  // Should not need to do this...
48
  this->Scene->SetRenderer(this->Renderer);
49

50 51
  vtkContextInteractorStyle* style = vtkContextInteractorStyle::New();
  style->SetScene(this->Scene);
52 53
  this->GetInteractor()->SetInteractorStyle(style);
  style->Delete();
54

55
  // Single color background by default.
56 57 58 59
  this->Renderer->SetBackground(1.0, 1.0, 1.0);
}

//----------------------------------------------------------------------------
60
vtkContextView::~vtkContextView() = default;
61 62 63 64 65 66 67 68 69 70 71

//----------------------------------------------------------------------------
vtkContext2D* vtkContextView::GetContext()
{
  return this->Context;
}

//----------------------------------------------------------------------------
vtkContextScene* vtkContextView::GetScene()
{
  return this->Scene;
72 73 74 75 76 77 78 79 80
}

//----------------------------------------------------------------------------
void vtkContextView::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "Context: " << this->Context << "\n";
  if (this->Context)
81
  {
82
    this->Context->PrintSelf(os, indent.GetNextIndent());
83
  }
84
}