vtkPlotPoints3D.cxx 3.12 KB
Newer Older
Zack Galbreath's avatar
Zack Galbreath committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPlotPoints3D.cxx

  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.

=========================================================================*/

#include "vtkChartXYZ.h"
#include "vtkContext2D.h"
#include "vtkContext3D.h"
#include "vtkObjectFactory.h"
#include "vtkNew.h"
#include "vtkPen.h"
#include "vtkPlotPoints3D.h"
#include "vtkUnsignedCharArray.h"
24
#include "vtkIdTypeArray.h"
Zack Galbreath's avatar
Zack Galbreath committed
25 26 27 28 29 30 31 32 33

//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotPoints3D)

//-----------------------------------------------------------------------------
vtkPlotPoints3D::vtkPlotPoints3D()
{
  this->Pen->SetWidth(5);
  this->Pen->SetColor(0, 0, 0, 255);
34
  this->SelectionPen->SetWidth(7);
Zack Galbreath's avatar
Zack Galbreath committed
35 36 37
}

//-----------------------------------------------------------------------------
38
vtkPlotPoints3D::~vtkPlotPoints3D() = default;
Zack Galbreath's avatar
Zack Galbreath committed
39 40 41 42 43 44 45 46 47 48

//-----------------------------------------------------------------------------
void vtkPlotPoints3D::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

//-----------------------------------------------------------------------------
bool vtkPlotPoints3D::Paint(vtkContext2D *painter)
{
49
  if (!this->Visible || this->Points.empty())
50
  {
Zack Galbreath's avatar
Zack Galbreath committed
51
    return false;
52
  }
Zack Galbreath's avatar
Zack Galbreath committed
53 54 55 56 57

  // Get the 3D context.
  vtkContext3D *context = painter->GetContext3D();

  if (!context)
58
  {
Zack Galbreath's avatar
Zack Galbreath committed
59
    return false;
60
  }
Zack Galbreath's avatar
Zack Galbreath committed
61 62 63

  this->Update();

64
  if (!this->Points.empty())
65
  {
Zack Galbreath's avatar
Zack Galbreath committed
66 67

    // Draw the points in 3d.
68
    context->ApplyPen(this->Pen);
Zack Galbreath's avatar
Zack Galbreath committed
69
    if (this->NumberOfComponents == 0)
70
    {
Zack Galbreath's avatar
Zack Galbreath committed
71
      context->DrawPoints(
72
        this->Points[0].GetData(), static_cast<int>(this->Points.size()));
73
    }
Zack Galbreath's avatar
Zack Galbreath committed
74
    else
75
    {
Zack Galbreath's avatar
Zack Galbreath committed
76
      context->DrawPoints(
77 78 79
        this->Points[0].GetData(),
        static_cast<int>(this->Points.size()),
        this->Colors->GetPointer(0), this->NumberOfComponents);
Zack Galbreath's avatar
Zack Galbreath committed
80 81
    }

82 83
  }

84 85
  // Now add some decorations for our selected points...
  if (this->Selection && this->Selection->GetNumberOfTuples())
86
  {
87 88
    if (this->Selection->GetMTime() > this->SelectedPointsBuildTime ||
        this->GetMTime() > this->SelectedPointsBuildTime)
89
    {
90 91
      size_t nSelected(static_cast<size_t>(this->Selection->GetNumberOfTuples()));
      this->SelectedPoints.reserve(nSelected);
92
      for (size_t i = 0; i < nSelected; ++i)
93
      {
94 95
        this->SelectedPoints.push_back(this->Points[
          this->Selection->GetValue(static_cast<vtkIdType>(i))]);
96
      }
97 98
      this->SelectedPointsBuildTime.Modified();
    }
99 100 101

    // Now to render the selected points.
    if (!this->SelectedPoints.empty())
102
    {
103
      context->ApplyPen(this->SelectionPen);
104 105 106
      context->DrawPoints(this->SelectedPoints[0].GetData(),
                          static_cast<int>(this->SelectedPoints.size()));
    }
107
  }
108

Zack Galbreath's avatar
Zack Galbreath committed
109 110
  return true;
}