// --------------------------------------------------------------------------
QString voPCAProjectionDynView::stringify(const voDataObject& dataObject)
{
  vtkTable * table = vtkTable::SafeDownCast(dataObject.dataAsVTKDataObject());
  if (!table)
    {
    qCritical() << "voPCAProjectionDynView - Failed to setDataObject - vtkTable data is expected !";
    return QString();
    }
  return voUtils::stringify(this->viewName(), table, QList<vtkIdType>() << 0);
}
Ejemplo n.º 2
0
// --------------------------------------------------------------------------
void voHorizontalBarView::setDataObjectInternal(const voDataObject& dataObject)
{
   Q_D(voHorizontalBarView);

  vtkTable * table = vtkTable::SafeDownCast(dataObject.dataAsVTKDataObject());
  if (!table)
    {
    qCritical() << "voHorizontalBarView - Failed to setDataObject - vtkTable data is expected !";
    return;
    }

  //Need a scratch copy, so we can insert a new column for verticalLocations
  vtkNew<vtkTable> localTable;
  localTable->DeepCopy(table);

  // verticalLocations is used to set axis tick marks, and as a dimension of the plotted data
  vtkNew<vtkDoubleArray> verticalLocations;
  for(double i = localTable->GetNumberOfRows(); i >= 1.0; i--)
    {
    verticalLocations->InsertNextValue(i);
    }
  verticalLocations->SetName("verticalLocations"); // Will never actually be displayed, but required by vtkPlot
  voUtils::insertColumnIntoTable(localTable.GetPointer(), 1, verticalLocations.GetPointer());

  vtkStringArray* verticalLabels = vtkStringArray::SafeDownCast(localTable->GetColumn(0));
  if (!verticalLabels)
    {
    qCritical() << "voHorizontalBarView - Failed to setDataObject - first column of vtkTable data could not be converted to string !";
    return;
    }

  // See http://www.colorjack.com/?swatch=A6CEE3
  unsigned char color[3] = {166, 206, 227};

  d->BarPlot->SetInput(localTable.GetPointer(), 1, 2);
  d->BarPlot->SetOrientation(vtkPlotBar::HORIZONTAL);
  d->BarPlot->SetColor(color[0], color[1], color[2], 255);
  d->BarPlot->SetIndexedLabels(verticalLabels);
  d->BarPlot->SetTooltipLabelFormat("%i: %y");

  d->Chart->GetAxis(vtkAxis::LEFT)->SetBehavior(vtkAxis::FIXED);
  // Default vertical zoom shows all bars at once. If we have many bars, we may want to change this.
  d->Chart->GetAxis(vtkAxis::LEFT)->SetRange(0.0, static_cast<double>(localTable->GetNumberOfRows()) + 1.0);
  d->Chart->GetAxis(vtkAxis::LEFT)->SetTickPositions(verticalLocations.GetPointer());
  d->Chart->GetAxis(vtkAxis::LEFT)->SetTickLabels(verticalLabels);
  d->Chart->GetAxis(vtkAxis::LEFT)->SetGridVisible(false);
  d->Chart->GetAxis(vtkAxis::LEFT)->SetTitle("");

  d->Chart->GetAxis(vtkAxis::BOTTOM)->SetTitle(localTable->GetColumnName(2));

  d->Chart->SetDrawAxesAtOrigin(true);

  d->ChartView->GetRenderWindow()->SetMultiSamples(4);
  d->ChartView->Render();
}
Ejemplo n.º 3
0
// --------------------------------------------------------------------------
void voTreeGraphView::setDataObjectInternal(const voDataObject& dataObject)
{
  Q_D(voTreeGraphView);

  vtkTree * tree = vtkTree::SafeDownCast(dataObject.dataAsVTKDataObject());
  if (!tree)
    {
    qCritical() << "voTreeGraphView - Failed to setDataObject - vtkTree data is expected !";
    return;
    }

  d->GraphView->SetRepresentationFromInputConnection(tree->GetProducerPort());
  d->GraphView->ResetCamera();
  d->GraphView->Render();
}
Ejemplo n.º 4
0
// --------------------------------------------------------------------------
void voHeatMapView::setDataObjectInternal(const voDataObject& dataObject)
{
  Q_D(voHeatMapView);

  vtkTable * table = vtkTable::SafeDownCast(dataObject.dataAsVTKDataObject());
  if (!table)
    {
    qCritical() << "voHeatMapView - Failed to setDataObject - vtkTable data is expected !";
    return;
    }

  vtkNew<vtkStringArray> verticalLabels;
    {
    // Flip vertical labels
    vtkSmartPointer<vtkStringArray> verticalLabelsRaw = vtkStringArray::SafeDownCast(table->GetColumn(0));
    if (!verticalLabelsRaw)
      {
      qCritical() << "voHeatMapView - Failed to setDataObject - first column of vtkTable data could not be converted to string !";
      return;
      }
    vtkIdType numVertLabels = verticalLabelsRaw->GetNumberOfValues();
    verticalLabels->SetNumberOfValues(numVertLabels);
    for (vtkIdType i = 0; i < numVertLabels; i++)
      {
      verticalLabels->SetValue(i, verticalLabelsRaw->GetValue(numVertLabels-i-1));
      }
    }

  vtkSmartPointer<vtkStringArray> horizontalLabels = vtkSmartPointer<vtkStringArray>::Take(voUtils::tableColumnNames(table, 1));

  vtkNew<vtkDoubleArray> verticalTicks;
  for(double i = 0.0; i < table->GetNumberOfRows(); i++)
    {
    verticalTicks->InsertNextValue(i + 0.5);
    }

  vtkNew<vtkDoubleArray> horizontalTicks;
  for(double i = 0.0; i < table->GetNumberOfColumns()-1; i++)
    {
    horizontalTicks->InsertNextValue(i + 0.5);
    }

  // Generate image of the correlation table
  vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
  vtkIdType corrMatrixNumberOfCols = table->GetNumberOfColumns();
  vtkIdType corrMatrixNumberOfRows = table->GetNumberOfRows();

  imageData->SetExtent(0, corrMatrixNumberOfCols-2,
                       0, corrMatrixNumberOfRows-1,
                       0,
                       0);
  imageData->AllocateScalars(VTK_DOUBLE, 1);
  imageData->SetOrigin(0.0, 0.0, 0.0);
  imageData->SetSpacing(1.0, 1.0, 1.0);

  double *dPtr = static_cast<double *>(imageData->GetScalarPointer(0, 0, 0));
  //double *dPtr = static_cast<double *>(imageData->GetScalarPointer());
  for (vtkIdType i = 0; i < corrMatrixNumberOfRows; ++i)
    {
    for (vtkIdType j = 1 ; j < corrMatrixNumberOfCols; ++j) // Skip first column (header labels)
      {
      double cellValue = table->GetValue(i,j).ToDouble();
      // Flip vertically for table -> image mapping
      dPtr[((corrMatrixNumberOfRows - i -1) * (corrMatrixNumberOfCols - 1)) + (j - 1) ] = cellValue;
      }
    }

  d->Chart->SetInputData( imageData );

  d->Chart->GetAxis(vtkAxis::LEFT)->SetTitle("");
  d->Chart->GetAxis(vtkAxis::LEFT)->SetBehavior(vtkAxis::FIXED);
  d->Chart->GetAxis(vtkAxis::LEFT)->SetRange(0.0, static_cast<double>(table->GetNumberOfRows()));
  d->Chart->GetAxis(vtkAxis::LEFT)->SetCustomTickPositions(verticalTicks.GetPointer(),verticalLabels.GetPointer());

  d->Chart->GetAxis(vtkAxis::BOTTOM)->SetTitle("");
  d->Chart->GetAxis(vtkAxis::BOTTOM)->SetBehavior(vtkAxis::FIXED);
  d->Chart->GetAxis(vtkAxis::BOTTOM)->SetRange(0.0, static_cast<double>(table->GetNumberOfColumns()-1));
  d->Chart->GetAxis(vtkAxis::BOTTOM)->SetCustomTickPositions(horizontalTicks.GetPointer(),horizontalLabels.GetPointer());
  d->Chart->GetAxis(vtkAxis::BOTTOM)->GetLabelProperties()->SetOrientation(270.0);
  d->Chart->GetAxis(vtkAxis::BOTTOM)->GetLabelProperties()->SetJustificationToRight(); // This actually justifies to the left
  d->Chart->GetAxis(vtkAxis::BOTTOM)->GetLabelProperties()->SetVerticalJustificationToCentered();

  vtkPlotHistogram2D* plotHistogram = vtkPlotHistogram2D::SafeDownCast(d->Chart->GetPlot(0));
  plotHistogram->SetTooltipPrecision(2);
  plotHistogram->SetTooltipNotation(vtkAxis::FIXED_NOTATION);
  plotHistogram->SetTooltipLabelFormat("%j / %i : %v");

  double minValue = -1.0;
  if (dataObject.property("min_value").isValid())
    {
    minValue = dataObject.property("min_value").toDouble();
    }
  double maxValue = 1.0;
  if (dataObject.property("max_value").isValid())
    {
    maxValue = dataObject.property("max_value").toDouble();
    }
  double midValue = 0.0;
  if (minValue != -1.0 && maxValue != 1.0)
    {
    midValue = (maxValue-minValue)/2.0;
    }
  double hsvScalars[3] = {minValue, midValue, maxValue};
  double hsvHues[3] = {0.3, 0.15, 0.0}; // green - red
  double hsvSats[3] = {1.0, 0.3, 1.0};
  double hsvValues[3] = {1.0, 0.3, 1.0};

  vtkNew<vtkColorTransferFunction> transferFunction;
  for(int i = 0; i < 3 - 1; ++i)
    {
    transferFunction->AddHSVSegment(hsvScalars[i], hsvHues[i], hsvSats[i], hsvValues[i],
                                    hsvScalars[i+1], hsvHues[i+1], hsvSats[i+1], hsvValues[i+1]);
    }
  transferFunction->Build();

  d->Chart->SetTransferFunction(transferFunction.GetPointer());

  d->ChartView->Render();
}