-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvtkMakeVector.cpp
More file actions
108 lines (91 loc) · 2.81 KB
/
vtkMakeVector.cpp
File metadata and controls
108 lines (91 loc) · 2.81 KB
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMakeVector.cpp
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.
=========================================================================*/
// Copyright 2014-2016 Etienne Tang
#include "vtkMakeVector.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointSet.h"
#include "vtkDoubleArray.h"
#include "vtkPointData.h"
#include "vtkMath.h"
vtkStandardNewMacro(vtkMakeVector)
vtkMakeVector::vtkMakeVector()
{
this->xComponentName = "";
this->yComponentName = "";
this->zComponentName = "";
this->vectorName = "";
}
vtkMakeVector::~vtkMakeVector()
{
}
void vtkMakeVector::PrintSelf(ostream& os, vtkIndent indent)
{
os << "vtkMakeVector\n";
}
int vtkMakeVector::RequestData(vtkInformation* request,
vtkInformationVector** inVector, vtkInformationVector* outVector)
{
vtkInformation* inInfo = inVector[0]->GetInformationObject(0);
if(!inInfo)
{
return 0;
}
vtkPointSet* inData = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
if(!inData)
{
return 0;
}
vtkInformation* outInfo = outVector->GetInformationObject(0);
vtkPointSet* outData = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
if(!outData)
{
return 0;
}
outData->ShallowCopy(inData);
vtkDataArray* xComp = outData->GetPointData()->GetArray(this->xComponentName);
vtkDataArray* yComp = outData->GetPointData()->GetArray(this->yComponentName);
vtkDataArray* zComp = outData->GetPointData()->GetArray(this->zComponentName);
if((!xComp) || (!yComp) || (!zComp) ||
(xComp->GetNumberOfComponents() != 1) ||
(yComp->GetNumberOfComponents() != 1) ||
(zComp->GetNumberOfComponents() != 1))
{
return 0;
}
vtkDoubleArray* vec = vtkDoubleArray::New();
int npts = outData->GetNumberOfPoints();
vec->SetNumberOfComponents(3);
vec->SetNumberOfTuples(npts);
double cur_tuple[3];
for(int i = 0; i < npts; i++)
{
xComp->GetTuple(i, &(cur_tuple[0]));
yComp->GetTuple(i, &(cur_tuple[1]));
zComp->GetTuple(i, &(cur_tuple[2]));
vec->SetTuple(i, cur_tuple);
}
vec->SetName(this->vectorName);
RemoveVar(outData, this->vectorName);
outData->GetPointData()->AddArray(vec);
vec->Delete();
return 1;
}
void vtkMakeVector::RemoveVar(vtkPointSet* data, const char* name)
{
if(data->GetPointData()->HasArray(name))
{
data->GetPointData()->RemoveArray(name);
}
}