<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
Hello,<br>
i need a 2D Scatter Plot and i found an example of this here
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a
href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/ScatterPlot">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/ScatterPlot</a>
<br>
<br>
Subsequently it was necessary have a multiple scatter plot with in
addition the possibility of change size, shape and color of each
single point. It was hard understand how to do this on the previous
example and i think is not possible to do this with a single
vtkPlot*. So i've done some modification to the previous code and
are attached here. But now the problem is that the rendering of the
plot is too slow for a lot of points....<br>
<br>
maybe i'm wrong but is possible to change shape, color and size for
each single point in a more simple way than mine?<br>
<br>
<br>
Thanks<br>
<br>
Giuseppe Marco Randazzo<br>
<br>
------------------ ------------------ ------------------
------------------ <br>
//ScatterPlot2.cxx<br>
<br>
#include <vtkVersion.h><br>
#include <vtkSmartPointer.h><br>
<br>
#include <vtkChartXY.h><br>
#include <vtkContextScene.h><br>
#include <vtkContextView.h><br>
#include <vtkFloatArray.h><br>
#include <vtkPlotPoints.h><br>
#include <vtkRenderWindow.h><br>
#include <vtkRenderWindowInteractor.h><br>
#include <vtkRenderer.h><br>
#include <vtkTable.h><br>
#include <vtkStringArray.h><br>
#include <vtkVariantArray.h><br>
#include <vtkDoubleArray.h><br>
<br>
#include <iostream><br>
#include <sstream><br>
#include <iomanip><br>
#include <vector><br>
using namespace std;<br>
<br>
template <typename T><br>
string NumberToString ( T Number )<br>
{<br>
ostringstream ss;<br>
ss << Number;<br>
return ss.str();<br>
}<br>
<br>
int main(int, char*[])<br>
{<br>
// Set up a 2D scene, add an XY chart to it<br>
vtkSmartPointer<vtkContextView> view =<br>
vtkSmartPointer<vtkContextView>::New();<br>
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);<br>
view->GetRenderWindow()->SetSize(400, 300);<br>
<br>
vtkSmartPointer<vtkChartXY> chart =<br>
vtkSmartPointer<vtkChartXY>::New();<br>
view->GetScene()->AddItem(chart);<br>
chart->SetShowLegend(false);<br>
<br>
std::vector< vtkSmartPointer<vtkTable> > tablist;<br>
std::vector< vtkPlot* > pointlist;<br>
<br>
int numPoints = 10000;<br>
float inc = 7.5 / (numPoints-1);<br>
for (int i = 0; i < numPoints; ++i){<br>
// Create a table with some points in it...<br>
vtkSmartPointer<vtkTable> table =<br>
vtkSmartPointer<vtkTable>::New();<br>
<br>
for(int j = 0; j < 4; j++){<br>
vtkSmartPointer<vtkFloatArray> arrX =<br>
vtkSmartPointer<vtkFloatArray>::New();<br>
string name = "Axis";<br>
name += NumberToString(j+1);<br>
arrX->SetName(name.c_str());<br>
table->AddColumn(arrX);<br>
}<br>
<br>
// Test charting with a few more points...<br>
<br>
table->SetNumberOfRows(1);<br>
<br>
table->SetValue(0, 0, i * inc);<br>
table->SetValue(0, 1, cos(i * inc) + 0.0);<br>
table->SetValue(0, 2, sin(i * inc) + 0.0);<br>
table->SetValue(0, 3, sin(i * inc) - cos(i * inc));<br>
<br>
tablist.push_back(table);<br>
}<br>
<br>
for (int i = 0; i < numPoints; ++i){<br>
// Add multiple scatter plots, setting the colors etc<br>
vtkPlot *points = chart->AddPlot(vtkChart::POINTS);<br>
points->SetInput(tablist[i], 0, 1);<br>
points->SetColor(0, 0, 0, 255);<br>
points->SetWidth(1.0);<br>
vtkPlotPoints::SafeDownCast(points)->SetMarkerStyle(vtkPlotPoints::CIRCLE);<br>
pointlist.push_back(points);<br>
}<br>
<br>
<br>
int b = 1;<br>
for(int i = 0; i < numPoints; ++i){<br>
if(b == 4){<br>
b = 1;<br>
}<br>
<br>
pointlist[i]->SetInput(tablist[i], 0, b);<br>
pointlist[i]->SetColor(0, 0, 0, 255);<br>
pointlist[i]->SetWidth(4.0);<br>
<br>
if(b == 1){<br>
vtkPlotPoints::SafeDownCast(pointlist[i])->SetMarkerStyle(vtkPlotPoints::PLUS);<br>
}<br>
else if(b == 2){<br>
vtkPlotPoints::SafeDownCast(pointlist[i])->SetMarkerStyle(vtkPlotPoints::SQUARE);<br>
}<br>
else{<br>
vtkPlotPoints::SafeDownCast(pointlist[i])->SetMarkerStyle(vtkPlotPoints::CIRCLE);<br>
}<br>
<br>
pointlist[i]->Modified();<br>
pointlist[i]->Update();<br>
b++;<br>
}<br>
<br>
//Finally render the scene<br>
view->GetRenderWindow()->SetMultiSamples(0);<br>
view->GetInteractor()->Initialize();<br>
view->GetInteractor()->Start();<br>
<br>
return EXIT_SUCCESS;<br>
}<br>
<br>
------------------ ------------------ ------------------
------------------<br>
#CMakeLists.txt<br>
PROJECT(ScatterPlot)<br>
<br>
FIND_PACKAGE(VTK REQUIRED)<br>
INCLUDE(${VTK_USE_FILE})<br>
<br>
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -pedantic -ggdb
-Wno-long-long")<br>
<br>
ADD_EXECUTABLE(ScatterPlot ScatterPlot.cxx)<br>
TARGET_LINK_LIBRARIES(ScatterPlot vtkHybrid vtkCharts)<br>
<br>
<br>
</body>
</html>