|
@@ -0,0 +1,137 @@
|
|
|
|
+/*=========================================================================
|
|
|
|
+
|
|
|
|
+ Library: CTK
|
|
|
|
+
|
|
|
|
+ Copyright (c) 2010 Kitware Inc.
|
|
|
|
+
|
|
|
|
+ Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
+ you may not use this file except in compliance with the License.
|
|
|
|
+ You may obtain a copy of the License at
|
|
|
|
+
|
|
|
|
+ http://www.commontk.org/LICENSE
|
|
|
|
+
|
|
|
|
+ Unless required by applicable law or agreed to in writing, software
|
|
|
|
+ distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
+ See the License for the specific language governing permissions and
|
|
|
|
+ limitations under the License.
|
|
|
|
+
|
|
|
|
+=========================================================================*/
|
|
|
|
+/*
|
|
|
|
+// Qt includes
|
|
|
|
+#include <QApplication>
|
|
|
|
+#include <QSharedPointer>
|
|
|
|
+#include <QTimer>
|
|
|
|
+
|
|
|
|
+// CTK includes
|
|
|
|
+#include "ctkVTKScalarsToColorsView.h"
|
|
|
|
+
|
|
|
|
+// VTK includes
|
|
|
|
+#include <vtkColorTransferFunction.h>
|
|
|
|
+#include <vtkPiecewiseFunction.h>
|
|
|
|
+#include <vtkPlot.h>
|
|
|
|
+#include <vtkSmartPointer.h>
|
|
|
|
+
|
|
|
|
+// STD includes
|
|
|
|
+#include <iostream>
|
|
|
|
+*/
|
|
|
|
+#include "vtkRenderWindow.h"
|
|
|
|
+#include "vtkSmartPointer.h"
|
|
|
|
+#include "vtkChartXY.h"
|
|
|
|
+#include "vtkPlot.h"
|
|
|
|
+#include "vtkTable.h"
|
|
|
|
+#include "vtkFloatArray.h"
|
|
|
|
+#include "vtkContextView.h"
|
|
|
|
+#include "vtkContextScene.h"
|
|
|
|
+#include "vtkRenderWindowInteractor.h"
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
+int ctkVTKScalarsToColorsViewTest4(int argc, char * argv [] )
|
|
|
|
+{
|
|
|
|
+ /*
|
|
|
|
+ QApplication app(argc, argv);
|
|
|
|
+
|
|
|
|
+ // Opacity function 1
|
|
|
|
+ vtkSmartPointer<vtkPiecewiseFunction> opacityFunction1 =
|
|
|
|
+ vtkSmartPointer<vtkPiecewiseFunction>::New();
|
|
|
|
+ opacityFunction1->AddPoint(0.,0.0);
|
|
|
|
+ opacityFunction1->AddPoint(0.2, 0.75);
|
|
|
|
+ opacityFunction1->AddPoint(0.35, 0.65);
|
|
|
|
+ opacityFunction1->AddPoint(0.8, 0.);
|
|
|
|
+
|
|
|
|
+ // Opacity function 2
|
|
|
|
+ vtkSmartPointer<vtkPiecewiseFunction> opacityFunction2 =
|
|
|
|
+ vtkSmartPointer<vtkPiecewiseFunction>::New();
|
|
|
|
+ opacityFunction2->AddPoint(0.4, 0.0);
|
|
|
|
+ opacityFunction2->AddPoint(0.5, 0.60);
|
|
|
|
+ opacityFunction2->AddPoint(0.9, 0.85);
|
|
|
|
+ opacityFunction2->AddPoint(1.0, 0.0);
|
|
|
|
+
|
|
|
|
+ ctkVTKScalarsToColorsView view(0);
|
|
|
|
+ // add transfer function item
|
|
|
|
+ vtkPlot* p1 = view.addOpacityFunction(opacityFunction1);
|
|
|
|
+ p1->SetColor(194, 66, 66, 255);
|
|
|
|
+ vtkPlot* p2 = view.addOpacityFunction(opacityFunction2);
|
|
|
|
+ p2->SetColor(193, 255, 66, 255);
|
|
|
|
+ view.fitAxesToBounds();
|
|
|
|
+ view.show();
|
|
|
|
+
|
|
|
|
+ QTimer autoExit;
|
|
|
|
+ if (argc < 2 || QString(argv[1]) != "-I")
|
|
|
|
+ {
|
|
|
|
+ QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
|
|
|
|
+ autoExit.start(1000);
|
|
|
|
+ }
|
|
|
|
+ return app.exec();
|
|
|
|
+ */
|
|
|
|
+ // Set up a 2D scene, add an XY chart to it
|
|
|
|
+ vtkSmartPointer<vtkContextView> view =
|
|
|
|
+ vtkSmartPointer<vtkContextView>::New();
|
|
|
|
+ view->GetRenderWindow()->SetSize(400, 300);
|
|
|
|
+ vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
|
|
|
|
+ view->GetScene()->AddItem(chart);
|
|
|
|
+
|
|
|
|
+ // Create a table with some points in it...
|
|
|
|
+ vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();
|
|
|
|
+ vtkSmartPointer<vtkFloatArray> arrX = vtkSmartPointer<vtkFloatArray>::New();
|
|
|
|
+ arrX->SetName("X Axis");
|
|
|
|
+ table->AddColumn(arrX);
|
|
|
|
+ vtkSmartPointer<vtkFloatArray> arrC = vtkSmartPointer<vtkFloatArray>::New();
|
|
|
|
+ arrC->SetName("Cosine");
|
|
|
|
+ table->AddColumn(arrC);
|
|
|
|
+ vtkSmartPointer<vtkFloatArray> arrS = vtkSmartPointer<vtkFloatArray>::New();
|
|
|
|
+ arrS->SetName("Sine");
|
|
|
|
+ table->AddColumn(arrS);
|
|
|
|
+ vtkSmartPointer<vtkFloatArray> arrS2 = vtkSmartPointer<vtkFloatArray>::New();
|
|
|
|
+ arrS2->SetName("Sine2");
|
|
|
|
+ table->AddColumn(arrS2);
|
|
|
|
+ // Test charting with a few more points...
|
|
|
|
+ int numPoints = 69;
|
|
|
|
+ float inc = 7.5 / (numPoints-1);
|
|
|
|
+ table->SetNumberOfRows(numPoints);
|
|
|
|
+ for (int i = 0; i < numPoints; ++i)
|
|
|
|
+ {
|
|
|
|
+ table->SetValue(i, 0, i * inc);
|
|
|
|
+ table->SetValue(i, 1, cos(i * inc) + 0.0);
|
|
|
|
+ table->SetValue(i, 2, sin(i * inc) + 0.0);
|
|
|
|
+ table->SetValue(i, 3, sin(i * inc) + 0.5);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Add multiple line plots, setting the colors etc
|
|
|
|
+ vtkPlot *line = chart->AddPlot(vtkChart::LINE);
|
|
|
|
+ line->SetInput(table, 0, 1);
|
|
|
|
+ line->SetColor(0, 255, 0, 255);
|
|
|
|
+ line->SetWidth(1.0);
|
|
|
|
+ line = chart->AddPlot(vtkChart::LINE);
|
|
|
|
+ line->SetInput(table, 0, 2);
|
|
|
|
+ line->SetColor(255, 0, 0, 255);
|
|
|
|
+ line->SetWidth(5.0);
|
|
|
|
+ line = chart->AddPlot(vtkChart::LINE);
|
|
|
|
+ line->SetInput(table, 0, 3);
|
|
|
|
+ line->SetColor(0, 0, 255, 255);
|
|
|
|
+ line->SetWidth(4.0);
|
|
|
|
+
|
|
|
|
+ //Finally render the scene and compare the image to a reference image
|
|
|
|
+ view->GetRenderWindow()->SetMultiSamples(0);
|
|
|
|
+ view->GetInteractor()->Start();
|
|
|
|
+ return EXIT_SUCCESS;
|
|
|
|
+}
|