forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkOTUtilities.cxx
110 lines (94 loc) · 2.84 KB
/
vtkOTUtilities.cxx
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOTUtilities.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 "vtkOTUtilities.h"
#include "vtkDataArrayCollection.h"
#include "vtkDoubleArray.h"
#include "vtkOTIncludes.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
using namespace OT;
//------------------------------------------------------------------------------
Sample* vtkOTUtilities::SingleDimArraysToSample(vtkDataArrayCollection* arrays)
{
if (arrays == nullptr)
{
return nullptr;
}
int numComp = arrays->GetNumberOfItems();
if (numComp == 0)
{
vtkWarningWithObjectMacro(arrays, "Collection is empty");
return nullptr;
}
int numTuples = arrays->GetItem(0)->GetNumberOfTuples();
Sample* ns = new Sample(numTuples, numComp);
int j = 0;
arrays->InitTraversal();
vtkDataArray* array = arrays->GetNextItem();
while (array != nullptr)
{
if (numTuples != array->GetNumberOfTuples())
{
// TODO nullptr Object
vtkErrorWithObjectMacro(arrays,
"An array has not the expected number of tuples. Expecting: "
<< numTuples << " , got: " << array->GetNumberOfTuples() << " , dropping it");
continue;
}
for (int i = 0; i < numTuples; ++i)
{
ns->at(i, j) = array->GetComponent(i, 0);
}
array = arrays->GetNextItem();
j++;
}
return ns;
}
//------------------------------------------------------------------------------
Sample* vtkOTUtilities::ArrayToSample(vtkDataArray* arr)
{
if (arr == nullptr)
{
return nullptr;
}
vtkIdType numTuples = arr->GetNumberOfTuples();
int numComp = arr->GetNumberOfComponents();
Sample* ns = new Sample(numTuples, numComp);
for (vtkIdType i = 0; i < numTuples; ++i)
{
for (unsigned int j = 0; j < ns->getDimension(); j++)
{
ns->at(i, j) = arr->GetComponent(i, j);
}
}
return ns;
}
//------------------------------------------------------------------------------
vtkDataArray* vtkOTUtilities::SampleToArray(Sample* ns)
{
if (ns == nullptr)
{
return nullptr;
}
int numTuples = ns->getSize();
int numComp = ns->getDimension();
vtkDoubleArray* arr = vtkDoubleArray::New();
arr->SetNumberOfTuples(numTuples);
arr->SetNumberOfComponents(numComp);
for (int i = 0; i < numTuples; i++)
{
for (int j = 0; j < numComp; j++)
{
arr->SetComponent(i, j, ns->at(i, j));
}
}
return arr;
}