-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkTreeVertexToEdgeSelection.cxx
112 lines (99 loc) · 3.17 KB
/
vtkTreeVertexToEdgeSelection.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
111
// Copyright 2009 Sandia Corporation, Kitware Inc.
// See LICENSE.txt for details.
#include "vtkTreeVertexToEdgeSelection.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkTree.h"
#include <vtksys/stl/map>
class vtkTreeVertexToEdgeSelectionInternals
{
public:
vtksys_stl::map<vtkIdType, vtkIdType> PedigreeToId;
};
vtkCxxRevisionMacro(vtkTreeVertexToEdgeSelection, "$Revision$");
vtkStandardNewMacro(vtkTreeVertexToEdgeSelection);
vtkTreeVertexToEdgeSelection::vtkTreeVertexToEdgeSelection()
{
this->SetNumberOfInputPorts(2);
this->Internals = new vtkTreeVertexToEdgeSelectionInternals;
this->Tree = NULL;
this->TreeMTime = 0;
}
vtkTreeVertexToEdgeSelection::~vtkTreeVertexToEdgeSelection()
{
delete this->Internals;
}
void vtkTreeVertexToEdgeSelection::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
int vtkTreeVertexToEdgeSelection::RequestData(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkSelection* input = vtkSelection::GetData(inputVector[0]);
vtkTree* tree = vtkTree::GetData(inputVector[1]);
vtkSelection* output = vtkSelection::GetData(outputVector);
// Update mapping
if (tree != this->Tree || tree->GetMTime() > this->TreeMTime)
{
this->Internals->PedigreeToId.clear();
vtkIdTypeArray* ped = vtkIdTypeArray::SafeDownCast(
tree->GetVertexData()->GetAbstractArray("PedigreeVertexId"));
for (vtkIdType v = 0; v < tree->GetNumberOfVertices(); v++)
{
this->Internals->PedigreeToId[ped->GetValue(v)] = v;
}
this->Tree = tree;
this->TreeMTime = tree->GetMTime();
}
vtkSelectionNode* node = input->GetNode(0);
if (node)
{
vtkIdTypeArray* arr = vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
if (arr)
{
vtkSmartPointer<vtkIdTypeArray> outArr =
vtkSmartPointer<vtkIdTypeArray>::New();
vtkSmartPointer<vtkSelectionNode> outNode =
vtkSmartPointer<vtkSelectionNode>::New();
for (vtkIdType i = 0; i < arr->GetNumberOfTuples(); i++)
{
vtkIdType pedigree = arr->GetValue(i);
vtkIdType vertId = this->Internals->PedigreeToId[pedigree];
vtkEdgeType edgeId = tree->GetParentEdge(vertId);
if (edgeId.Id >= 0)
{
outArr->InsertNextValue(edgeId.Id);
}
}
outNode->SetSelectionList(outArr);
outNode->GetProperties()->Copy(node->GetProperties());
outNode->SetContentType(vtkSelectionNode::INDICES);
outNode->SetFieldType(vtkSelectionNode::CELL);
output->AddNode(outNode);
}
}
return 1;
}
//----------------------------------------------------------------------------
int vtkTreeVertexToEdgeSelection::FillInputPortInformation(
int port, vtkInformation* info)
{
// now add our info
if (port == 0)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkSelection");
}
else if (port == 1)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTree");
}
return 1;
}