1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPolyDataItem.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 "vtkPolyDataItem.h"
#include "vtkAbstractMapper.h"
#include "vtkContext2D.h"
#include "vtkFieldData.h"
#include "vtkFloatArray.h"
#include "vtkIntArray.h"
#include "vtkObjectFactory.h"
#include "vtkPen.h"
#include "vtkPolyData.h"
#include "vtkUnsignedCharArray.h"
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkPolyDataItem);
vtkCxxSetObjectMacro(vtkPolyDataItem, PolyData, vtkPolyData);
vtkCxxSetObjectMacro(vtkPolyDataItem, MappedColors, vtkUnsignedCharArray);
class vtkPolyDataItem::DrawHintsHelper
{
public:
DrawHintsHelper()
{
this->previousLineType = 0;
this->previousLineWidth = 0.0f;
}
/**
* Retrieve drawing hints as field data from the polydata and use the
* provided context2D to apply them
*/
void ApplyDrawHints(vtkContext2D* painter, vtkPolyData* polyData)
{
vtkFieldData* fieldData = polyData->GetFieldData();
vtkIntArray* stippleArray =
vtkIntArray::SafeDownCast(fieldData->GetAbstractArray("StippleType"));
vtkFloatArray* lineWidthArray =
vtkFloatArray::SafeDownCast(fieldData->GetAbstractArray("LineWidth"));
vtkPen* pen = painter->GetPen();
this->previousLineType = pen->GetLineType();
this->previousLineWidth = pen->GetWidth();
if (stippleArray != nullptr)
{
pen->SetLineType(stippleArray->GetValue(0));
}
if (lineWidthArray != nullptr)
{
pen->SetWidth(lineWidthArray->GetValue(0));
}
}
/**
* "Un-apply" hints by restoring saved drawing state
*/
void RemoveDrawHints(vtkContext2D* painter)
{
vtkPen* pen = painter->GetPen();
pen->SetLineType(this->previousLineType);
pen->SetWidth(this->previousLineWidth);
};
private:
DrawHintsHelper(const DrawHintsHelper&) = delete;
void operator=(const DrawHintsHelper&) = delete;
int previousLineType;
float previousLineWidth;
};
//------------------------------------------------------------------------------
vtkPolyDataItem::vtkPolyDataItem()
: PolyData(nullptr)
, MappedColors(nullptr)
, ScalarMode(VTK_SCALAR_MODE_USE_POINT_DATA)
{
this->Position[0] = this->Position[1] = 0;
this->HintHelper = new vtkPolyDataItem::DrawHintsHelper();
}
//------------------------------------------------------------------------------
vtkPolyDataItem::~vtkPolyDataItem()
{
this->SetPolyData(nullptr);
this->SetMappedColors(nullptr);
delete this->HintHelper;
}
//------------------------------------------------------------------------------
bool vtkPolyDataItem::Paint(vtkContext2D* painter)
{
if (this->PolyData && this->MappedColors)
{
this->HintHelper->ApplyDrawHints(painter, this->PolyData);
// Draw the PolyData in the bottom left corner of the item.
painter->DrawPolyData(
this->Position[0], this->Position[1], this->PolyData, this->MappedColors, this->ScalarMode);
this->HintHelper->RemoveDrawHints(painter);
}
return true;
}
//------------------------------------------------------------------------------
void vtkPolyDataItem::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os, indent);
}
VTK_ABI_NAMESPACE_END
|