[vtkusers] Set the Color of each line in vtkChartParallelCoordinates

Matthias Eggert besessener at gmx.net
Wed Nov 23 08:06:53 EST 2011


Narf, I just can'T give up. 
My program works absolutly fine, when I just want to see the coordinates. But if 
I have too many lines I cannot trace them back without different colors. I tried 
a lot of things with this SafeDownCast, but it won't work. 

Here is my source code:


#include "ui_SimpleVTK.h"
#include "SimpleVTK.h"

#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSphereSource.h>

#include <vtkTextActor.h>
#include <vtkTextProperty.h>

#include <QMessageBox>

#include <vtkPlot.h>
#include <vtkTable.h>
#include <vtkFloatArray.h>
#include <vtkContextScene.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderView.h>
#include <vtkIdTypeArray.h>
#include <vtkLookupTable.h>

// Constructor
SimpleVTK::SimpleVTK()
{
  this->ui = new Ui_SimpleVTK;
  this->ui->setupUi(this);


  // Set up a 2D scene, add an chart to it
  view = vtkSmartPointer<vtkContextView>::New();
  view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
  chart = vtkSmartPointer<vtkChartParallelCoordinates>::New();

  // Create a table with some points in it...
  vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();
  vtkSmartPointer<vtkFloatArray> arrX = vtkSmartPointer<vtkFloatArray>::New();
  arrX->SetName("Field1");
  arrX->InsertNextValue(0.0);
  table->AddColumn(arrX);
  vtkSmartPointer<vtkFloatArray> arrC = vtkSmartPointer<vtkFloatArray>::New();
  arrC->SetName("Field2");
  arrC->InsertNextValue(1.03);
  table->AddColumn(arrC);
  vtkSmartPointer<vtkFloatArray> arrS = vtkSmartPointer<vtkFloatArray>::New();
  arrS->SetName("Field3");
  arrS->InsertNextValue(1.0);
  table->AddColumn(arrS);
  vtkSmartPointer<vtkFloatArray> arrS2 = vtkSmartPointer<vtkFloatArray>::New();
  arrS2->SetName("Field4");
  arrS2->InsertNextValue(1.0);
  table->AddColumn(arrS2);
  
  // Test charting with a few more points...
  table->SetNumberOfRows(100);
  srand ( time(NULL) );
  for (int i = 0; i < 100; ++i)
    {
    table->SetValue(i, 0, rand());
    table->SetValue(i, 1, rand());
    table->SetValue(i, 2, rand());
    table->SetValue(i, 3, rand());
    }

  // Connect VTK with Qt with Renderer
  chart->GetPlot(0)->SetInput(table);

  view->GetScene()->AddItem(chart);
  view->SetInteractor(this->ui->qvtkWidget->GetInteractor());
  this->ui->qvtkWidget->SetRenderWindow(view->GetRenderWindow());
};


I know it is kind of greedy to ask. But would anyone please say what exactly I 
have to put in my code so that the lines have the very simplest lookuptable 
applied? (I could also provide the complete project with the cmake file if 
needed :( )

Also I've got another problem. When i select some lines with this selection box 
on each axis, how do I get the corresponding coordiantes of each line?


I really hope thats not asking too much :(
Kind regards,
Matthias




More information about the vtkusers mailing list