forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkTreeLevelsFilter.cxx
97 lines (77 loc) · 3.05 KB
/
vtkTreeLevelsFilter.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTreeLevelsFilter.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.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
#include "vtkTreeLevelsFilter.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkMath.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkIntArray.h"
#include "vtkDataArray.h"
#include "vtkTree.h"
#include "vtkGraph.h"
vtkStandardNewMacro(vtkTreeLevelsFilter);
vtkTreeLevelsFilter::vtkTreeLevelsFilter()
{
}
int vtkTreeLevelsFilter::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// Storing the inputTree and outputTree handles
vtkTree *inputTree = vtkTree::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkTree *outputTree = vtkTree::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
// Copy the input to the output.
outputTree->ShallowCopy(inputTree);
// Add the 1-tuple array that will store the level from
// the root down (root = 0, and +1 for each level down)
vtkIntArray *levelArray = vtkIntArray::New();
levelArray->SetName("level");
levelArray->SetNumberOfComponents(1);
levelArray->SetNumberOfTuples(outputTree->GetNumberOfVertices());
vtkDataSetAttributes *data = outputTree->GetVertexData();
data->AddArray(levelArray);
// Add the 1-tuple array that will marks each
// leaf with a '1' and everything else with a '0'
vtkIntArray *leafArray = vtkIntArray::New();
leafArray->SetName("leaf");
leafArray->SetNumberOfComponents(1);
leafArray->SetNumberOfTuples(outputTree->GetNumberOfVertices());
data->AddArray(leafArray);
for (vtkIdType i = 0; i < outputTree->GetNumberOfVertices(); i++)
{
levelArray->SetValue(i, outputTree->GetLevel(i));
leafArray->SetValue(i, outputTree->IsLeaf(i));
}
// Set levels as the active point scalar
data->SetActiveScalars("level");
// Clean up
levelArray->Delete();
leafArray->Delete();
return 1;
}
void vtkTreeLevelsFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}