1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkTreeMapLayoutStrategy.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 /*-------------------------------------------------------------------------
16 Copyright 2008 Sandia Corporation.
17 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18 the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20
21 #include "vtkTreeMapLayoutStrategy.h"
22
23 #include "vtkAdjacentVertexIterator.h"
24 #include "vtkFloatArray.h"
25 #include "vtkTree.h"
26
27
28 vtkTreeMapLayoutStrategy::vtkTreeMapLayoutStrategy() = default;
29
30 vtkTreeMapLayoutStrategy::~vtkTreeMapLayoutStrategy() = default;
31
PrintSelf(ostream & os,vtkIndent indent)32 void vtkTreeMapLayoutStrategy::PrintSelf(ostream& os, vtkIndent indent)
33 {
34 this->Superclass::PrintSelf(os,indent);
35 }
36
AddBorder(float * boxInfo)37 void vtkTreeMapLayoutStrategy::AddBorder(float *boxInfo)
38 {
39 float dx, dy;
40 dx = 0.5 * (boxInfo[1] - boxInfo[0]) * this->ShrinkPercentage;
41 dy = 0.5 * (boxInfo[3] - boxInfo[2]) * this->ShrinkPercentage;
42 boxInfo[0] += dx;
43 boxInfo[1] -= dx;
44 boxInfo[2] += dy;
45 boxInfo[3] -= dy;
46 }
47
FindVertex(vtkTree * otree,vtkDataArray * array,float pnt[2])48 vtkIdType vtkTreeMapLayoutStrategy::FindVertex(
49 vtkTree* otree, vtkDataArray* array, float pnt[2])
50 {
51 // Check to see that we are in the dataset at all
52 float blimits[4];
53
54 vtkIdType vertex = otree->GetRoot();
55 vtkFloatArray *boxInfo = vtkArrayDownCast<vtkFloatArray>(array);
56 // Now try to find the vertex that contains the point
57 boxInfo->GetTypedTuple(vertex, blimits); // Get the extents of the root
58 if ((pnt[0] < blimits[0]) || (pnt[0] > blimits[1]) ||
59 (pnt[1] < blimits[2]) || (pnt[1] > blimits[3]))
60 {
61 // Point is not in the tree at all
62 return -1;
63 }
64
65 // Now traverse the children to try and find
66 // the vertex that contains the point
67 vtkIdType child;
68 #if 0
69 if (binfo)
70 {
71 binfo[0] = blimits[0];
72 binfo[1] = blimits[1];
73 binfo[2] = blimits[2];
74 binfo[3] = blimits[3];
75 }
76 #endif
77
78 vtkAdjacentVertexIterator *it = vtkAdjacentVertexIterator::New();
79 otree->GetAdjacentVertices(vertex, it);
80 while (it->HasNext())
81 {
82 child = it->Next();
83 boxInfo->GetTypedTuple(child, blimits); // Get the extents of the child
84 if ((pnt[0] < blimits[0]) || (pnt[0] > blimits[1]) ||
85 (pnt[1] < blimits[2]) || (pnt[1] > blimits[3]))
86 {
87 continue;
88 }
89 // If we are here then the point is contained by the child
90 // So recurse down the children of this vertex
91 vertex = child;
92 otree->GetAdjacentVertices(vertex, it);
93 }
94 it->Delete();
95
96 return vertex;
97 }
98
99