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 
vtkTreeMapLayoutStrategy()28 vtkTreeMapLayoutStrategy::vtkTreeMapLayoutStrategy()
29 {
30 }
31 
~vtkTreeMapLayoutStrategy()32 vtkTreeMapLayoutStrategy::~vtkTreeMapLayoutStrategy()
33 {
34 }
35 
PrintSelf(ostream & os,vtkIndent indent)36 void vtkTreeMapLayoutStrategy::PrintSelf(ostream& os, vtkIndent indent)
37 {
38   this->Superclass::PrintSelf(os,indent);
39 }
40 
AddBorder(float * boxInfo)41 void vtkTreeMapLayoutStrategy::AddBorder(float *boxInfo)
42 {
43   float dx, dy;
44   dx = 0.5 * (boxInfo[1] - boxInfo[0]) * this->ShrinkPercentage;
45   dy = 0.5 * (boxInfo[3] - boxInfo[2]) * this->ShrinkPercentage;
46   boxInfo[0] += dx;
47   boxInfo[1] -= dx;
48   boxInfo[2] += dy;
49   boxInfo[3] -= dy;
50 }
51 
FindVertex(vtkTree * otree,vtkDataArray * array,float pnt[2])52 vtkIdType vtkTreeMapLayoutStrategy::FindVertex(
53     vtkTree* otree, vtkDataArray* array, float pnt[2])
54 {
55   // Check to see that we are in the dataset at all
56   float blimits[4];
57 
58   vtkIdType vertex = otree->GetRoot();
59   vtkFloatArray *boxInfo = vtkFloatArray::SafeDownCast(array);
60   // Now try to find the vertex that contains the point
61   boxInfo->GetTupleValue(vertex, blimits); // Get the extents of the root
62   if ((pnt[0] < blimits[0]) || (pnt[0] > blimits[1]) ||
63       (pnt[1] < blimits[2]) || (pnt[1] > blimits[3]))
64     {
65     // Point is not in the tree at all
66     return -1;
67     }
68 
69   // Now traverse the children to try and find
70   // the vertex that contains the point
71   vtkIdType child;
72 #if 0
73   if (binfo)
74     {
75     binfo[0] = blimits[0];
76     binfo[1] = blimits[1];
77     binfo[2] = blimits[2];
78     binfo[3] = blimits[3];
79     }
80 #endif
81 
82   vtkAdjacentVertexIterator *it = vtkAdjacentVertexIterator::New();
83   otree->GetAdjacentVertices(vertex, it);
84   while (it->HasNext())
85     {
86     child = it->Next();
87     boxInfo->GetTupleValue(child, blimits); // Get the extents of the child
88     if ((pnt[0] < blimits[0]) || (pnt[0] > blimits[1]) ||
89             (pnt[1] < blimits[2]) || (pnt[1] > blimits[3]))
90       {
91       continue;
92       }
93     // If we are here then the point is contained by the child
94     // So recurse down the children of this vertex
95     vertex = child;
96     otree->GetAdjacentVertices(vertex, it);
97     }
98   it->Delete();
99 
100   return vertex;
101 }
102 
103