|
Canorus
0.7
|
Space partitioning structure for fast access to drawable elements on canvas. More...
#include <kdtree.h>

Public Member Functions | |
| CAKDTree () | |
| void | addElement (T elt) |
| bool | removeElement (T elt) |
| T | removeElement (double x, double y, bool autoDelete=true) |
| void | import (CAKDTree *tree) |
| QList< T > | findInRange (double x, double y, double w=0, double h=0) |
| QList< T > | findInRange (QRect &area) |
| T | findNearestLeft (double x, bool timeBased=false, CADrawableContext *context=0, CAVoice *voice=0) |
| T | findNearestRight (double x, bool timeBased=false, CADrawableContext *context=0, CAVoice *voice=0) |
| T | findNearestUp (double y) |
| T | findNearestDown (double y) |
| double | getMaxX () |
| double | getMaxY () |
| void | clear (bool autoDelete=true) |
| int | size () |
| T | at (int i) |
| QList< T > & | list () |
Private Member Functions | |
| void | calculateMaxXY () |
Private Attributes | |
| QList< T > | _list |
| double | _maxX |
| double | _maxY |
Space partitioning structure for fast access to drawable elements on canvas.
Copyright (c) 2006-2009, Matevž Jekovec, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors.
Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE.GPL for details.
kd-tree is usually used for description of the music elements on the canvas. It's used for fast insertion/lookup of a list of elements in the given region. Each canvas has its own kd-tree of drawable elements. One for contexts and the other for music elements.
Canorus kd-tree is a template class which requires derivates of CADrawable base class elements to work.
See http://en.wikipedia.org/wiki/Kd_tree
| void CAKDTree< T >::addElement | ( | T | elt | ) |
Adds a drawable element elt to the tree.
References CADrawable::yPos().
Referenced by CAScoreViewPort::addCElement(), CAScoreViewPort::addMElement(), and CAScoreViewPort::coordsToTime().


|
inline |
Referenced by CAScoreViewPort::addToSelection(), CAScoreViewPort::findCElement(), CAScoreViewPort::findMElement(), CAScoreViewPort::importCElements(), CAScoreViewPort::importElements(), CAScoreViewPort::importMElements(), CAScoreViewPort::invertSelection(), CAScoreViewPort::selectAll(), CAScoreViewPort::selectContext(), CAScoreViewPort::selectMElement(), CAScoreViewPort::setLastMousePressCoordsAfter(), CAScoreViewPort::timeToCoords(), and CAScoreViewPort::timeToCoordsSimpleVersion().

|
private |
Used internally for the maxX and maxY properties to update. Calculates the largest X and Y coordinates among all ends of elements and store it locally. This operation takes O(n) time complexity where n is number of elements in the tree.
References CADrawable::yPos().

| void CAKDTree< T >::clear | ( | bool | autoDelete = true | ) |
Removes all elements from the tree. Also destroys the elements if autoDelete is true.
Referenced by CAScoreViewPort::clearCElements(), CAScoreViewPort::clearMElements(), CAScoreViewPort::rebuild(), and CAScoreViewPort::~CAScoreViewPort().

| QList< T > CAKDTree< T >::findInRange | ( | double | x, |
| double | y, | ||
| double | w = 0, |
||
| double | h = 0 |
||
| ) |
Returns the list of elements present in the given rectangular area or an empty list if none found. Element is in the list, if the region only touches it - not neccessarily fits the whole in the region.
Referenced by CAScoreViewPort::contextCollision(), CAScoreViewPort::findContextsInRegion(), CAScoreViewPort::musElementsAt(), CAScoreViewPort::paintEvent(), and CAScoreViewPort::selectCElement().

| QList< T > CAKDTree< T >::findInRange | ( | QRect & | rect | ) |
This function is provided for convenience. Returns the list of elements present in the given rectangular area or an empty list if none found. Element is in the list, if the region only touches it - not neccessarily fits the whole in the region.
| T CAKDTree< T >::findNearestDown | ( | double | y | ) |
Finds the nearest lower element to the given coordinate and returns a pointer to it or 0 if none found. Top element border is taken into account.
If timeBased is false (default), the lookup should be view-based - the nearest element is selected as it appears on the screen. If timeBased if true, the nearest element is selected according to the nearest start/end time.
References CADrawable::yPos().
Referenced by CAScoreViewPort::nearestDownContext().


| T CAKDTree< T >::findNearestLeft | ( | double | x, |
| bool | timeBased = false, |
||
| CADrawableContext * | context = 0, |
||
| CAVoice * | voice = 0 |
||
| ) |
Finds the nearest left element to the given coordinate and returns a pointer to it or 0 if none found. Left elements borders are taken into account.
If timeBased is false (default), the lookup should be view-based - the nearest element is selected as it appears on the screen. If timeBased if true, the nearest element is selected according to the nearest start/end time.
References CAVoice::contains(), CAVoice::staff(), and CADrawable::xPos().
Referenced by CAScoreViewPort::calculateTime(), and CAScoreViewPort::nearestLeftElement().


| T CAKDTree< T >::findNearestRight | ( | double | x, |
| bool | timeBased = false, |
||
| CADrawableContext * | context = 0, |
||
| CAVoice * | voice = 0 |
||
| ) |
Finds the nearest right element to the given coordinate and returns a pointer to it or 0 if none found. Left elements borders are taken into account.
If timeBased is false (default), the lookup should be view-based - the nearest element is selected as it appears on the screen. If timeBased if true, the nearest element is selected according to the nearest start/end time.
References CAVoice::contains(), CAVoice::staff(), and CADrawable::xPos().
Referenced by CAScoreViewPort::calculateTime(), and CAScoreViewPort::nearestRightElement().


| T CAKDTree< T >::findNearestUp | ( | double | y | ) |
Finds the nearest upper element to the given coordinate and returns a pointer to it or 0 if none found. Top element border is taken into account.
If timeBased is false (default), the lookup should be view-based - the nearest element is selected as it appears on the screen. If timeBased if true, the nearest element is selected according to the nearest start/end time.
References CADrawable::height(), and CADrawable::yPos().
Referenced by CAScoreViewPort::nearestUpContext().


| double CAKDTree< T >::getMaxX | ( | ) |
Returns the max X coordinate of the end of the most-right element. This value is read from buffer, so the calculation time is constant.
Referenced by CAScoreViewPort::getMaxXExtended(), and CAScoreViewPort::zoomToFit().

| double CAKDTree< T >::getMaxY | ( | ) |
Returns the max Y coordinate of the end of the most-bottom element. This value is read from buffer, so the calculation time is constant.
Referenced by CAScoreViewPort::getMaxYExtended(), and CAScoreViewPort::zoomToFit().

Imports all the elements from the given tree. It actually merges the given tree with this one.
References CAKDTree< T >::list().

|
inline |
Referenced by CAScoreViewPort::coordsToTime(), CAKDTree< T >::import(), CAScoreViewPort::importElements(), and CAScoreViewPort::rebuild().

| bool CAKDTree< T >::removeElement | ( | T | elt | ) |
Removes the given element elt from the tree. Returns true, if the given element was found and deleted; otherwise false.
Referenced by CAScoreViewPort::removeMElement().

| T CAKDTree< T >::removeElement | ( | double | x, |
| double | y, | ||
| bool | autoDelete = true |
||
| ) |
Removes the first element at the given x and y absolute world coordinates and returns the pointer to this element, if successful. Destroys element, if autoDelete is true. Returns pointer to the deleted element or null, if no element found at the given coordinates.
|
inline |
Returns the number of elements currently in the tree.
Referenced by CAScoreViewPort::addToSelection(), CAScoreViewPort::findCElement(), CAScoreViewPort::findMElement(), CAScoreViewPort::importCElements(), CAScoreViewPort::importElements(), CAScoreViewPort::importMElements(), CAScoreViewPort::invertSelection(), CAScoreViewPort::paintEvent(), CAScoreViewPort::rebuild(), CAScoreViewPort::selectAll(), CAScoreViewPort::selectContext(), CAScoreViewPort::selectMElement(), CAScoreViewPort::setLastMousePressCoordsAfter(), CAScoreViewPort::timeToCoords(), and CAScoreViewPort::timeToCoordsSimpleVersion().

|
private |
|
private |
|
private |
1.8.3