Changeset 8511:f5a22a405c75 in orange


Ignore:
Timestamp:
07/28/11 13:35:55 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
f9a8dca598a97e906fe0c535f8084d6ca24d2ac0
Message:

Point selection now works reasonably well.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/plot/owplot.py

    r8509 r8511  
    765765            self.selection_items.reverse() 
    766766        elif self.state == SELECT: 
    767             point_item = self.point_at(point) 
    768             qDebug(repr(point) + ' ' + repr(point_item)) 
     767            dr = self.data_rect_for_axes() 
     768            gr = self.graph_area 
     769            d = 10 * max(dr.width(), dr.height()) / max(gr.width(), gr.height()) 
     770            point_item = self.nearest_point(self.map_from_graph(point), d) 
     771            qDebug(repr(self.map_from_graph(point)) + ' ' + repr(point_item)) 
    769772            if point_item: 
    770773                point_item.set_selected(True) 
  • source/orangeplot/plot.cpp

    r8501 r8511  
    44 
    55#include <QtCore/QDebug> 
    6  
    7 uint qHash(const DataPoint& pos) 
     6#include <QtCore/qmath.h> 
     7#include <limits> 
     8 
     9inline uint qHash(const DataPoint& pos) 
    810{ 
    911    return pos.x + pos.y; 
    1012} 
    1113 
    12 bool operator==(const DataPoint& one, const DataPoint& other) 
     14inline double distance(const DataPoint& one, const DataPoint& other) 
     15{ 
     16    // For speed, we use the slightly wrong method, also known as Manhattan distance 
     17    return fabs(one.x - other.x) + fabs(one.y - other.y);  
     18} 
     19 
     20inline bool operator==(const DataPoint& one, const DataPoint& other) 
    1321{ 
    1422    return one.x == other.x && one.y == other.y; 
     
    200208Point* Plot::point_at(const DataPoint& pos) 
    201209{ 
    202     Point* point; 
    203210    foreach (PlotItem* item, plot_items()) 
    204211    { 
     
    207214            return m_point_hash[item][pos]; 
    208215        } 
     216    } 
     217    return 0; 
     218} 
     219 
     220Point* Plot::nearest_point(const DataPoint& pos, double max_distance) 
     221{ 
     222    QPair<double, DataPoint> closest_point = qMakePair( std::numeric_limits<double>::max(), DataPoint() ); 
     223    foreach (PlotItem* item, plot_items()) 
     224    { 
     225        if (!m_point_set.contains(item)) 
     226        { 
     227            continue; 
     228        } 
     229        PointSet::ConstIterator it = m_point_set[item].constBegin(); 
     230        PointSet::ConstIterator end = m_point_set[item].constEnd(); 
     231        for (it; it != end; ++it) 
     232        { 
     233            const double d = distance(*it, pos); 
     234            if (d < closest_point.first) 
     235            { 
     236                closest_point.first = d; 
     237                closest_point.second = *it; 
     238            } 
     239        } 
     240    } 
     241    if (closest_point.first < max_distance) 
     242    { 
     243        return point_at(closest_point.second); 
    209244    } 
    210245    return 0; 
  • source/orangeplot/plot.h

    r8501 r8511  
    5050    void mark_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
    5151     
     52    /** 
     53     * For each point defined with @p x_data and @p y_data, this function checks whether such a point is selected.  
     54     * This function is precise, so you have to supply it with precisely the same data as the curves that  
     55     * created the points 
     56     **/ 
    5257    QList< int > selected_points(const QList< double > x_data, const QList< double > y_data, const QTransform& transform); 
    5358     
     59    /** 
     60     * This function uses a fuzzy equality check, so it will return any function that is near enough.  
     61     *  
     62     * The equality check is specified in compare_data() 
     63     *  
     64     **/ 
     65    Point* nearest_point(const DataPoint& pos, double max_distance); 
     66     
    5467    Point* point_at(const DataPoint& pos); 
     68     
     69     
    5570    Point* selected_point_at(const DataPoint& pos); 
    5671     
  • source/orangeplot/plot.sip

    r8501 r8511  
    6363     
    6464    QList< int > selected_points(const QList< double > x_data, const QList< double > y_data, const QTransform& transform); 
     65    Point* nearest_point(const DataPoint& pos, double max_distance); 
    6566    Point* point_at(const DataPoint& pos); 
    6667     
Note: See TracChangeset for help on using the changeset viewer.