1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkPath.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkPath.h"
16 
17 #include "vtkGenericCell.h"
18 #include "vtkIdList.h"
19 #include "vtkInformation.h"
20 #include "vtkInformationVector.h"
21 #include "vtkNew.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkPointData.h"
24 #include "vtkIntArray.h"
25 
26 #include <cassert>
27 
28 //----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPath)29 vtkStandardNewMacro(vtkPath)
30 
31 //----------------------------------------------------------------------------
32 vtkPath::vtkPath()
33 {
34   vtkNew<vtkPoints> points;
35   this->SetPoints(points);
36 
37   vtkNew<vtkIntArray> controlPointCodes;
38   controlPointCodes->SetNumberOfComponents(1);
39   this->PointData->SetScalars(controlPointCodes);
40 }
41 
42 //----------------------------------------------------------------------------
43 vtkPath::~vtkPath() = default;
44 
45 //----------------------------------------------------------------------------
Allocate(vtkIdType size,int extSize)46 void vtkPath::Allocate(vtkIdType size, int extSize)
47 {
48   this->Points->Allocate(size, extSize);
49   this->PointData->Allocate(size, extSize);
50 }
51 
52 //----------------------------------------------------------------------------
GetCell(vtkIdType,vtkGenericCell * cell)53 void vtkPath::GetCell(vtkIdType, vtkGenericCell *cell)
54 {
55   cell->SetCellTypeToEmptyCell();
56 }
57 
58 //----------------------------------------------------------------------------
GetCellPoints(vtkIdType,vtkIdList * ptIds)59 void vtkPath::GetCellPoints(vtkIdType, vtkIdList *ptIds)
60 {
61   ptIds->Reset();
62 }
63 
64 //----------------------------------------------------------------------------
GetPointCells(vtkIdType,vtkIdList * cellIds)65 void vtkPath::GetPointCells(vtkIdType, vtkIdList *cellIds)
66 {
67   cellIds->Reset();
68 }
69 
70 //----------------------------------------------------------------------------
Reset()71 void vtkPath::Reset()
72 {
73   this->Points->Reset();
74   this->PointData->Reset();
75 }
76 
77 //----------------------------------------------------------------------------
GetData(vtkInformation * info)78 vtkPath* vtkPath::GetData(vtkInformation* info)
79 {
80   return info ? vtkPath::SafeDownCast(info->Get(DATA_OBJECT())) : nullptr;
81 }
82 
83 //----------------------------------------------------------------------------
GetData(vtkInformationVector * v,int i)84 vtkPath* vtkPath::GetData(vtkInformationVector* v, int i)
85 {
86   return vtkPath::GetData(v->GetInformationObject(i));
87 }
88 
89 //----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)90 void vtkPath::PrintSelf(ostream& os, vtkIndent indent)
91 {
92   this->Superclass::PrintSelf(os,indent);
93 }
94 
95 //----------------------------------------------------------------------------
InsertNextPoint(float pts[],int code)96 void vtkPath::InsertNextPoint(float pts[], int code)
97 {
98   this->Points->InsertNextPoint(pts);
99 
100   vtkIntArray *codes = vtkArrayDownCast<vtkIntArray>(
101         this->PointData->GetScalars());
102   assert("control point code array is int type" && codes);
103   codes->InsertNextValue(code);
104 }
105 
106 //----------------------------------------------------------------------------
InsertNextPoint(double pts[],int code)107 void vtkPath::InsertNextPoint(double pts[], int code)
108 {
109   this->InsertNextPoint(pts[0], pts[1], pts[2], code);
110 }
111 
112 //----------------------------------------------------------------------------
InsertNextPoint(double x,double y,double z,int code)113 void vtkPath::InsertNextPoint(double x, double y, double z, int code)
114 {
115   this->Points->InsertNextPoint(x, y, z);
116 
117   vtkIntArray *codes = vtkArrayDownCast<vtkIntArray>(
118         this->PointData->GetScalars());
119   assert("control point code array is int type" && codes);
120   codes->InsertNextValue(code);
121 }
122 
123 //----------------------------------------------------------------------------
SetCodes(vtkIntArray * codes)124 void vtkPath::SetCodes(vtkIntArray *codes)
125 {
126   this->PointData->SetScalars(codes);
127 }
128 
129 //----------------------------------------------------------------------------
GetCodes()130 vtkIntArray *vtkPath::GetCodes()
131 {
132   return vtkArrayDownCast<vtkIntArray>(this->PointData->GetScalars());
133 }
134