QScalarsToColors.cxx 2.72 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   Visualization Toolkit
4
  Module:    QScalarsToColors.cxx
5 6 7 8 9 10 11 12 13 14 15

  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 17
#include "QVTKOpenGLWidget.h"
#include "vtkChartXY.h"
18 19 20
#include "vtkColorTransferFunction.h"
#include "vtkCompositeTransferFunctionItem.h"
#include "vtkContextScene.h"
21 22 23 24 25 26
#include "vtkContextView.h"
#include "vtkFloatArray.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPiecewiseFunction.h"
27
#include "vtkPlot.h"
28 29 30
#include "vtkQtTableView.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
31 32 33 34
#include "vtkTimerLog.h"

#include <QApplication>
#include <QHBoxLayout>
35 36 37
#include <QMainWindow>
#include <QSurfaceFormat>
#include <QWidget>
38 39 40 41 42


//----------------------------------------------------------------------------
int main( int argc, char * argv [] )
{
43 44 45
  // needed to ensure appropriate OpenGL context is created for VTK rendering.
  QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());

46 47 48 49
  // Qt initialization
  QApplication app(argc, argv);

  // QVTK set up and initialization
50
  QVTKOpenGLWidget qvtkWidget;
51 52 53

  vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
  qvtkWidget.SetRenderWindow(renderWindow);
54 55

  // Set up my 2D world...
56 57
  vtkNew<vtkContextView> view;; // This contains a chart object
  view->SetRenderWindow(qvtkWidget.GetRenderWindow());
58 59
  view->SetInteractor(qvtkWidget.GetInteractor());

60
  vtkNew<vtkChartXY> chart;
61 62 63
  chart->SetTitle("Chart");
  view->GetScene()->AddItem(chart);

64
  vtkNew<vtkColorTransferFunction> colorTransferFunction;
65 66 67 68 69
  colorTransferFunction->AddHSVSegment(0.,0.,1.,1.,0.3333,0.3333,1.,1.);
  colorTransferFunction->AddHSVSegment(0.3333,0.3333,1.,1.,0.6666,0.6666,1.,1.);
  colorTransferFunction->AddHSVSegment(0.6666,0.6666,1.,1.,1.,0.,1.,1.);
  colorTransferFunction->Build();

70
  vtkNew<vtkPiecewiseFunction> opacityFunction;
71 72 73 74
  opacityFunction->AddPoint(0.,0.);
  opacityFunction->AddPoint(0.5,0.5);
  opacityFunction->AddPoint(1.,1.);

75
  vtkNew<vtkCompositeTransferFunctionItem> item3;
76 77 78 79 80 81 82 83 84 85
  item3->SetColorTransferFunction(colorTransferFunction);
  item3->SetOpacityFunction(opacityFunction);
  item3->SetOpacity(0.2);
  item3->SetMaskAboveCurve(true);
  chart->AddPlot(item3);

  // Now show the application and start the event loop
  qvtkWidget.show();
  return app.exec();
}