Changeset af50685 in git for src/gfxcore.cc


Ignore:
Timestamp:
08/03/15 09:36:41 (5 years ago)
Author:
Olly Betts <olly@…>
Branches:
line_contents, master, stereo, travis-osx
Children:
69f54b0, db71ab5
Parents:
be28d00
Message:

lib/survex.pot,src/: Add "Colour by Length".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gfxcore.cc

    rbe28d00 raf50685  
    5656// Any error value higher than this is clamped to this.
    5757#define MAX_ERROR 12.0
     58
     59// Any length greater than pow(10, LOG_LEN_MAX) will be clamped to this.
     60const Double LOG_LEN_MAX = 1.5;
    5861
    5962// How many bins per letter height to use when working out non-overlapping
     
    221224    InvalidateList(LIST_DATE_KEY);
    222225    InvalidateList(LIST_ERROR_KEY);
     226    InvalidateList(LIST_LENGTH_KEY);
    223227    InvalidateList(LIST_UNDERGROUND_LEGS);
    224228    InvalidateList(LIST_TUBES);
     
    10741078}
    10751079
     1080void GfxCore::DrawLengthKey()
     1081{
     1082    int num_bands;
     1083    // Use fixed colours for each length so it's directly visually comparable
     1084    // between surveys.
     1085    num_bands = GetNumColourBands();
     1086    for (int band = 0; band < num_bands; ++band) {
     1087        double len = pow(10, LOG_LEN_MAX * band / (num_bands - 1));
     1088        int units = /*m*/424;
     1089        if (!m_Metric) {
     1090            len /= METRES_PER_FOOT;
     1091            units = /*ft*/428;
     1092        }
     1093        key_legends[band].Printf(wxT("%.2f%s"), len, wmsg(units));
     1094    }
     1095
     1096    DrawColourKey(num_bands, wxString(), wxString());
     1097}
     1098
    10761099void GfxCore::DrawScaleBar()
    10771100{
     
    21962219            DrawErrorKey();
    21972220            break;
     2221        case LIST_LENGTH_KEY:
     2222            DrawLengthKey();
     2223            break;
    21982224        case LIST_UNDERGROUND_LEGS:
    21992225            GenerateDisplayList();
     
    23722398        } else if (m_ColourBy == COLOUR_BY_ERROR) {
    23732399            DrawList2D(LIST_ERROR_KEY, GetXSize() - KEY_OFFSET_X,
     2400                       GetYSize() - KEY_OFFSET_Y, 0);
     2401        } else if (m_ColourBy == COLOUR_BY_LENGTH) {
     2402            DrawList2D(LIST_LENGTH_KEY, GetXSize() - KEY_OFFSET_X,
    23742403                       GetYSize() - KEY_OFFSET_Y, 0);
    23752404        }
     
    27622791    }
    27632792    EndPolyline();
     2793}
     2794
     2795void GfxCore::SetColourFromLength(double length, Double factor)
     2796{
     2797    // Set the drawing colour based on log(length_of_leg).
     2798
     2799    Double log_len = log10(length);
     2800    Double how_far = log_len / LOG_LEN_MAX;
     2801    how_far = max(how_far, 0.0);
     2802    how_far = min(how_far, 1.0);
     2803
     2804    int band = int(floor(how_far * (GetNumColourBands() - 1)));
     2805    GLAPen pen1 = GetPen(band);
     2806    if (band < GetNumColourBands() - 1) {
     2807        const GLAPen& pen2 = GetPen(band + 1);
     2808
     2809        Double interval = LOG_LEN_MAX / (GetNumColourBands() - 1);
     2810        Double into_band = log_len / interval - band;
     2811
     2812        assert(into_band >= 0.0);
     2813        assert(into_band <= 1.0);
     2814
     2815        pen1.Interpolate(pen2, into_band);
     2816    }
     2817    SetColour(pen1, factor);
     2818}
     2819
     2820void GfxCore::AddPolylineLength(const traverse & centreline)
     2821{
     2822    vector<PointInfo>::const_iterator i, prev_i;
     2823    i = centreline.begin();
     2824    prev_i = i;
     2825    while (++i != centreline.end()) {
     2826        Double len = (*i - *prev_i).magnitude();
     2827        BeginPolyline();
     2828        SetColourFromLength(len, 1.0);
     2829        PlaceVertex(*prev_i);
     2830        PlaceVertex(*i);
     2831        prev_i = i;
     2832        EndPolyline();
     2833    }
     2834}
     2835
     2836static double static_length_hack; // FIXME
     2837
     2838void GfxCore::AddQuadrilateralLength(const Vector3 &a, const Vector3 &b,
     2839                                     const Vector3 &c, const Vector3 &d)
     2840{
     2841    Vector3 normal = (a - c) * (d - b);
     2842    normal.normalise();
     2843    Double factor = dot(normal, light) * .3 + .7;
     2844    int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2));
     2845    int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2));
     2846    // FIXME: should plot triangles instead to avoid rendering glitches.
     2847    BeginQuadrilaterals();
     2848////    PlaceNormal(normal);
     2849    SetColourFromLength(static_length_hack, factor);
     2850    PlaceVertex(a, 0, 0);
     2851    PlaceVertex(b, w, 0);
     2852    PlaceVertex(c, w, h);
     2853    PlaceVertex(d, 0, h);
     2854    EndQuadrilaterals();
    27642855}
    27652856
     
    29563047
    29573048        if (draw) {
     3049            static_length_hack = (pt_v - prev_pt_v).magnitude();
    29583050            if (segment > 0) {
    29593051                (this->*AddQuad)(v[0], v[1], U[1], U[0]);
     
    30813173            AddQuad = &GfxCore::AddQuadrilateralError;
    30823174            AddPoly = &GfxCore::AddPolylineError;
     3175            break;
     3176        case COLOUR_BY_LENGTH:
     3177            AddQuad = &GfxCore::AddQuadrilateralLength;
     3178            AddPoly = &GfxCore::AddPolylineLength;
    30833179            break;
    30843180        default: // case COLOUR_BY_NONE:
     
    33243420        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
    33253421        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_ERROR, wmsg(/*Colour by E&rror*/289));
     3422        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
    33263423        menu.AppendSeparator();
    33273424        /* TRANSLATORS: Menu item which turns off the colour key.
Note: See TracChangeset for help on using the changeset viewer.