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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkVectorText.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 "vtkVectorText.h"
#include "vtkCellArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkTransformPolyDataFilter.h"
#include <clocale>
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkVectorText);
VTK_ABI_NAMESPACE_END
// NOLINTNEXTLINE(bugprone-suspicious-include)
#include "vtkVectorTextData.cxx"
// Construct object with no string set and backing enabled.
VTK_ABI_NAMESPACE_BEGIN
vtkVectorText::vtkVectorText()
{
this->Text = nullptr;
this->SetNumberOfInputPorts(0);
}
int vtkVectorText::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
{
// get the info object
vtkInformation* outInfo = outputVector->GetInformationObject(0);
// get the output
vtkPolyData* output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPoints* newPoints;
vtkCellArray* newPolys;
int ptOffset = 0;
int aPoint, i;
int pos = 0;
float xpos = 0;
float ypos = 0;
int ptCount, triCount;
VTK_VECTOR_TEXT_GLYPH aLetter;
float width;
float ftmp[3];
if (this->Text == nullptr)
{
vtkErrorMacro(<< "Text is not set!");
return 0;
}
// Set things up; allocate memory
newPoints = vtkPoints::New();
newPolys = vtkCellArray::New();
ftmp[2] = 0.0;
// Create Text
while (this->Text[pos])
{
switch (this->Text[pos])
{
case 32:
xpos += 0.4;
break;
case 10:
ypos -= 1.4;
xpos = 0;
break;
default:
// if we have a valid character
if ((this->Text[pos] > 32) && (this->Text[pos] < 127))
{
// add the result to our output
aLetter = Letters[static_cast<int>(this->Text[pos]) - 33];
ptCount = aLetter.ptCount;
width = aLetter.width;
for (i = 0; i < ptCount; i++)
{
ftmp[0] = aLetter.points[i].x;
ftmp[1] = aLetter.points[i].y;
ftmp[0] += xpos;
ftmp[1] += ypos;
newPoints->InsertNextPoint(ftmp);
}
triCount = aLetter.triCount;
for (i = 0; i < triCount; i++)
{
newPolys->InsertNextCell(3);
aPoint = aLetter.triangles[i].p1;
newPolys->InsertCellPoint(aPoint + ptOffset);
aPoint = aLetter.triangles[i].p2;
newPolys->InsertCellPoint(aPoint + ptOffset);
aPoint = aLetter.triangles[i].p3;
newPolys->InsertCellPoint(aPoint + ptOffset);
}
ptOffset += ptCount;
xpos += width;
}
break;
}
pos++;
}
//
// Update ourselves and release memory
//
output->SetPoints(newPoints);
newPoints->Delete();
output->SetPolys(newPolys);
newPolys->Delete();
return 1;
}
void vtkVectorText::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Text: " << (this->Text ? this->Text : "(none)") << "\n";
}
vtkVectorText::~vtkVectorText()
{
delete[] this->Text;
}
VTK_ABI_NAMESPACE_END
|