6 * $Date: 2012-07-07 17:14:54 +0200 (Sa, 07. Jul 2012) $
7 ***************************************************************/
10 * \brief Implementation of class LinearQuadtree.
12 * \author Martin Gronemann
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #include "LinearQuadtree.h"
48 void LinearQuadtree::init(float min_x
, float min_y
, float max_x
, float max_y
)
54 m_sideLengthGrid
= ((double)(0x1 << 24) - 1.0);
55 m_sideLengthPoints
= (double)max(m_max_x
- m_min_x
, m_max_y
- m_min_y
);
56 m_scaleInv
= (m_sideLengthGrid
/ m_sideLengthPoints
);
57 m_cellSize
= m_sideLengthPoints
/((double)m_sideLengthGrid
);
62 void LinearQuadtree::clear()
71 LinearQuadtree::LinearQuadtree(__uint32 n
, float* origXPos
, float* origYPos
, float* origSize
) : m_origXPos(origXPos
), m_origYPos(origYPos
), m_origSize(origSize
)
79 LinearQuadtree::~LinearQuadtree(void)
85 void LinearQuadtree::allocate(__uint32 n
)
89 m_tree
= (LQNode
*)MALLOC_16(m_maxNumNodes
*sizeof(LQNode
));
90 m_nodeXPos
= (float*)MALLOC_16(m_maxNumNodes
*sizeof(float));
91 m_nodeYPos
= (float*)MALLOC_16(m_maxNumNodes
*sizeof(float));
92 m_nodeSize
= (float*)MALLOC_16(m_maxNumNodes
*sizeof(float));
93 m_points
= (LQPoint
*)MALLOC_16(m_numPoints
*sizeof(LQPoint
));
94 for (__uint32 i
= 0; i
< m_numPoints
; i
++)
96 m_pointXPos
= (float*)MALLOC_16(m_numPoints
*sizeof(float));
97 m_pointYPos
= (float*)MALLOC_16(m_numPoints
*sizeof(float));
98 m_pointSize
= (float*)MALLOC_16(m_numPoints
*sizeof(float));
99 m_notWspd
= (LQWSPair
*)MALLOC_16(m_maxNumNodes
*sizeof(LQWSPair
)*27);
100 m_directNodes
= (NodeID
*)MALLOC_16(m_maxNumNodes
*sizeof(NodeID
));
101 m_WSPD
= new WSPD(m_maxNumNodes
);
105 void LinearQuadtree::deallocate()
112 FREE_16(m_pointXPos
);
113 FREE_16(m_pointYPos
);
114 FREE_16(m_pointSize
);
116 FREE_16(m_directNodes
);
121 __uint64
LinearQuadtree::sizeInBytes() const
123 return m_numPoints
*sizeof(LQPoint
) +
124 m_maxNumNodes
*sizeof(LQNode
) +
125 m_maxNumNodes
*sizeof(LQWSPair
)*27 +
126 m_maxNumNodes
*sizeof(NodeID
) +
127 m_WSPD
->sizeInBytes();
131 //! iterates back in the sequence until the first point with another morton number occures, returns that point +1
132 LinearQuadtree::PointID
LinearQuadtree::findFirstPointInCell(LinearQuadtree::PointID somePointInCell
) const
134 if (somePointInCell
==0) return 0;
135 LinearQuadtree::PointID result
= somePointInCell
-1;
136 while (mortonNr(somePointInCell
) == mortonNr(result
))
138 if (result
==0) return 0;
145 void LinearQuadtree::addWSPD(NodeID s
, NodeID t
)
148 m_WSPD
->addWSP(s
, t
);
152 void LinearQuadtree::addDirectPair(NodeID s
, NodeID t
)
154 m_notWspd
[m_numNotWSP
].a
= s
;
155 m_notWspd
[m_numNotWSP
].b
= t
;
160 void LinearQuadtree::addDirect(NodeID s
)
162 m_directNodes
[m_numDirectNodes
] = s
;
166 } // end of namespace ogdf