vtkChartHistogram2D.cxx 3.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkChart2DHistogram.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.

=========================================================================*/

16
#include "vtkChartHistogram2D.h"
17 18 19 20 21 22 23 24

#include "vtkContext2D.h"
#include "vtkBrush.h"
#include "vtkPen.h"
#include "vtkContextScene.h"
#include "vtkContextMouseEvent.h"
#include "vtkTextProperty.h"
#include "vtkAxis.h"
25
#include "vtkPlotHistogram2D.h"
26
#include "vtkColorLegend.h"
27
#include "vtkTooltipItem.h"
28 29 30 31
#include "vtkSmartPointer.h"
#include "vtkObjectFactory.h"

//-----------------------------------------------------------------------------
32
vtkStandardNewMacro(vtkChartHistogram2D);
33 34

//-----------------------------------------------------------------------------
35
vtkChartHistogram2D::vtkChartHistogram2D()
36 37
{
  // Now for the 2D histogram
38
  this->Histogram = vtkSmartPointer<vtkPlotHistogram2D>::New();
39
  this->AddPlot(this->Histogram);
40

41
  this->RemoveItem(this->Legend);
42 43
  this->Legend = vtkSmartPointer<vtkColorLegend>::New();
  this->AddItem(this->Legend);
44 45 46 47

  // Re-add tooltip, making it the last ContextItem to be painted
  this->RemoveItem(this->Tooltip);
  this->AddItem(this->Tooltip);
48 49 50
}

//-----------------------------------------------------------------------------
51
vtkChartHistogram2D::~vtkChartHistogram2D()
52 53 54 55
{
}

//-----------------------------------------------------------------------------
56
void vtkChartHistogram2D::Update()
57
{
58 59
  this->Histogram->Update();
  this->Legend->Update();
60
  this->vtkChartXY::Update();
61 62
}

63
//-----------------------------------------------------------------------------
64
void vtkChartHistogram2D::SetInputData(vtkImageData *data, vtkIdType z)
65
{
66
  this->Histogram->SetInputData(data, z);
67 68
}

69
//-----------------------------------------------------------------------------
70
void vtkChartHistogram2D::SetTransferFunction(vtkScalarsToColors *function)
71 72
{
  this->Histogram->SetTransferFunction(function);
73 74 75 76 77
  vtkColorLegend *legend = vtkColorLegend::SafeDownCast(this->Legend);
  if (legend)
    {
    legend->SetTransferFunction(function);
    }
78 79 80
}

//-----------------------------------------------------------------------------
81
bool vtkChartHistogram2D::UpdateLayout(vtkContext2D *painter)
82
{
83
  this->vtkChartXY::UpdateLayout(painter);
84 85 86 87 88 89 90
  vtkColorLegend *legend = vtkColorLegend::SafeDownCast(this->Legend);
  if (legend)
    {
    legend->SetPosition(vtkRectf(this->Point2[0] + 5, this->Point1[1],
                                 this->Legend->GetSymbolWidth(),
                                 this->Point2[1] - this->Point1[1]));
    }
91 92
  this->Legend->Update();
  return true;
93 94 95
}

//-----------------------------------------------------------------------------
96
bool vtkChartHistogram2D::Hit(const vtkContextMouseEvent &mouse)
97
{
98 99 100 101 102
  vtkVector2i pos(mouse.GetScreenPos());
  if (pos[0] > this->Point1[0] - 10 &&
      pos[0] < this->Point2[0] + 10 &&
      pos[1] > this->Point1[1] &&
      pos[1] < this->Point2[1])
103 104 105 106 107 108 109 110 111
    {
    return true;
    }
  else
    {
    return false;
    }
}

112 113 114 115 116 117 118 119 120 121 122
//-----------------------------------------------------------------------------
vtkPlot* vtkChartHistogram2D::GetPlot(vtkIdType index)
{
  if (index == 0)
    {
    return this->Histogram;
    }

  return 0;
}

123
//-----------------------------------------------------------------------------
124
void vtkChartHistogram2D::PrintSelf(ostream &os, vtkIndent indent)
125 126 127
{
  this->Superclass::PrintSelf(os, indent);
}