Changeset cc9e2c65 in git


Ignore:
Timestamp:
11/03/15 05:00:49 (5 years ago)
Author:
Olly Betts <olly@…>
Branches:
line_contents, master, stereo, travis-osx
Children:
0dc273d
Parents:
a4e7c6f
Message:

lib/,src/: Add "Colour by Gradient".

Files:
26 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    ra4e7c6f rcc9e2c65  
     1Wed Mar 11 05:00:26 GMT 2015  Olly Betts <olly@survex.com>
     2
     3        * lib/,src/: Add "Colour by Gradient".
     4
    15Wed Mar 11 04:55:38 GMT 2015  Olly Betts <olly@survex.com>
    26
  • lib/bg.po

    ra4e7c6f rcc9e2c65  
    19531953#: n:289
    19541954msgid "Colour by E&rror"
     1955msgstr ""
     1956
     1957#: n:85
     1958msgid "Colour by Grad&ient"
    19551959msgstr ""
    19561960
  • lib/ca.po

    ra4e7c6f rcc9e2c65  
    19521952msgid "Colour by E&rror"
    19531953msgstr "Colour by Err&or"
     1954
     1955#: n:85
     1956msgid "Colour by Grad&ient"
     1957msgstr ""
    19541958
    19551959#: ../src/gfxcore.cc:3422
  • lib/de.po

    ra4e7c6f rcc9e2c65  
    19511951msgid "Colour by E&rror"
    19521952msgstr "Anhand Fehle&rn einfärben"
     1953
     1954#: n:85
     1955msgid "Colour by Grad&ient"
     1956msgstr ""
    19531957
    19541958#: ../src/gfxcore.cc:3422
  • lib/de_CH.po

    ra4e7c6f rcc9e2c65  
    19511951msgid "Colour by E&rror"
    19521952msgstr "Anhand Fehle&rn einfärben"
     1953
     1954#: n:85
     1955msgid "Colour by Grad&ient"
     1956msgstr ""
    19531957
    19541958#: ../src/gfxcore.cc:3422
  • lib/el.po

    ra4e7c6f rcc9e2c65  
    19471947#: n:289
    19481948msgid "Colour by E&rror"
     1949msgstr ""
     1950
     1951#: n:85
     1952msgid "Colour by Grad&ient"
    19491953msgstr ""
    19501954
  • lib/en_US.po

    ra4e7c6f rcc9e2c65  
    19481948msgid "Colour by E&rror"
    19491949msgstr "Color by E&rror"
     1950
     1951#: n:85
     1952msgid "Colour by Grad&ient"
     1953msgstr "Color by Grad&ient"
    19501954
    19511955#: ../src/gfxcore.cc:3422
  • lib/es.po

    ra4e7c6f rcc9e2c65  
    19521952msgid "Colour by E&rror"
    19531953msgstr "Color por E&rror"
     1954
     1955#: n:85
     1956msgid "Colour by Grad&ient"
     1957msgstr ""
    19541958
    19551959#: ../src/gfxcore.cc:3422
  • lib/hu.po

    ra4e7c6f rcc9e2c65  
    19491949#: n:289
    19501950msgid "Colour by E&rror"
     1951msgstr ""
     1952
     1953#: n:85
     1954msgid "Colour by Grad&ient"
    19511955msgstr ""
    19521956
  • lib/id.po

    ra4e7c6f rcc9e2c65  
    19481948msgid "Colour by E&rror"
    19491949msgstr "Warna berdasarkan Kesa&lahan"
     1950
     1951#: n:85
     1952msgid "Colour by Grad&ient"
     1953msgstr ""
    19501954
    19511955#: ../src/gfxcore.cc:3422
  • lib/it.po

    ra4e7c6f rcc9e2c65  
    19511951msgid "Colour by E&rror"
    19521952msgstr "Colore di &Error"
     1953
     1954#: n:85
     1955msgid "Colour by Grad&ient"
     1956msgstr ""
    19531957
    19541958#: ../src/gfxcore.cc:3422
  • lib/pl.po

    ra4e7c6f rcc9e2c65  
    19481948#: n:289
    19491949msgid "Colour by E&rror"
     1950msgstr ""
     1951
     1952#: n:85
     1953msgid "Colour by Grad&ient"
    19501954msgstr ""
    19511955
  • lib/pt.po

    ra4e7c6f rcc9e2c65  
    19541954msgid "Colour by E&rror"
    19551955msgstr "Colorir de acordo com Err&os"
     1956
     1957#: n:85
     1958msgid "Colour by Grad&ient"
     1959msgstr ""
    19561960
    19571961#: ../src/gfxcore.cc:3422
  • lib/pt_BR.po

    ra4e7c6f rcc9e2c65  
    19551955msgid "Colour by E&rror"
    19561956msgstr "Colorir de acordo com Err&os"
     1957
     1958#: n:85
     1959msgid "Colour by Grad&ient"
     1960msgstr ""
    19571961
    19581962#: ../src/gfxcore.cc:3422
  • lib/ro.po

    ra4e7c6f rcc9e2c65  
    19521952msgid "Colour by E&rror"
    19531953msgstr "Culori in functie de &Eroare"
     1954
     1955#: n:85
     1956msgid "Colour by Grad&ient"
     1957msgstr ""
    19541958
    19551959#: ../src/gfxcore.cc:3422
  • lib/ru.po

    ra4e7c6f rcc9e2c65  
    19481948msgid "Colour by E&rror"
    19491949msgstr "Раскраска по &ошибкам на кольцах"
     1950
     1951#: n:85
     1952msgid "Colour by Grad&ient"
     1953msgstr ""
    19501954
    19511955#: ../src/gfxcore.cc:3422
  • lib/sk.po

    ra4e7c6f rcc9e2c65  
    19511951msgid "Colour by E&rror"
    19521952msgstr "Colour &by Error"
     1953
     1954#: n:85
     1955msgid "Colour by Grad&ient"
     1956msgstr ""
    19531957
    19541958#: ../src/gfxcore.cc:3422
  • lib/survex.pot

    ra4e7c6f rcc9e2c65  
    19491949#: n:289
    19501950msgid "Colour by E&rror"
     1951msgstr ""
     1952
     1953#: n:85
     1954msgid "Colour by Grad&ient"
    19511955msgstr ""
    19521956
  • lib/zh_CN.po

    ra4e7c6f rcc9e2c65  
    19471947#: n:289
    19481948msgid "Colour by E&rror"
     1949msgstr ""
     1950
     1951#: n:85
     1952msgid "Colour by Grad&ient"
    19491953msgstr ""
    19501954
  • src/gfxcore.cc

    ra4e7c6f rcc9e2c65  
    224224    InvalidateList(LIST_DATE_KEY);
    225225    InvalidateList(LIST_ERROR_KEY);
     226    InvalidateList(LIST_GRADIENT_KEY);
    226227    InvalidateList(LIST_LENGTH_KEY);
    227228    InvalidateList(LIST_UNDERGROUND_LEGS);
     
    10781079}
    10791080
     1081void GfxCore::DrawGradientKey()
     1082{
     1083    int num_bands;
     1084    // Use fixed colours for each gradient so it's directly visually comparable
     1085    // between surveys.
     1086    num_bands = GetNumColourBands();
     1087    wxString units = wmsg(m_Degrees ? /*°*/344 : /*ᵍ*/76);
     1088    for (int band = 0; band < num_bands; ++band) {
     1089        double gradient = double(band) / (num_bands - 1);
     1090        if (m_Degrees) {
     1091            gradient *= 90.0;
     1092        } else {
     1093            gradient *= 100.0;
     1094        }
     1095        key_legends[band].Printf(wxT("%.f%s"), gradient, units);
     1096    }
     1097
     1098    DrawColourKey(num_bands, wxString(), wxString());
     1099}
     1100
    10801101void GfxCore::DrawLengthKey()
    10811102{
     
    22172238            DrawErrorKey();
    22182239            break;
     2240        case LIST_GRADIENT_KEY:
     2241            DrawGradientKey();
     2242            break;
    22192243        case LIST_LENGTH_KEY:
    22202244            DrawLengthKey();
     
    23962420            case COLOUR_BY_ERROR:
    23972421                key_list = LIST_ERROR_KEY; break;
     2422            case COLOUR_BY_GRADIENT:
     2423                key_list = LIST_GRADIENT_KEY; break;
    23982424            case COLOUR_BY_LENGTH:
    23992425                key_list = LIST_LENGTH_KEY; break;
     
    27512777    }
    27522778    EndPolyline();
     2779}
     2780
     2781// gradient is in *radians*.
     2782void GfxCore::SetColourFromGradient(double gradient, Double factor)
     2783{
     2784    // Set the drawing colour based on the gradient of the leg.
     2785
     2786    const Double GRADIENT_MAX = M_PI_2;
     2787    gradient = fabs(gradient);
     2788    Double how_far = gradient / GRADIENT_MAX;
     2789    SetColourFrom01(how_far, factor);
     2790}
     2791
     2792void GfxCore::AddPolylineGradient(const traverse & centreline)
     2793{
     2794    vector<PointInfo>::const_iterator i, prev_i;
     2795    i = centreline.begin();
     2796    prev_i = i;
     2797    while (++i != centreline.end()) {
     2798        BeginPolyline();
     2799        SetColourFromGradient((*i - *prev_i).gradient(), 1.0);
     2800        PlaceVertex(*prev_i);
     2801        PlaceVertex(*i);
     2802        prev_i = i;
     2803        EndPolyline();
     2804    }
     2805}
     2806
     2807static double static_gradient_hack; // FIXME
     2808
     2809void GfxCore::AddQuadrilateralGradient(const Vector3 &a, const Vector3 &b,
     2810                                       const Vector3 &c, const Vector3 &d)
     2811{
     2812    Vector3 normal = (a - c) * (d - b);
     2813    normal.normalise();
     2814    Double factor = dot(normal, light) * .3 + .7;
     2815    int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2));
     2816    int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2));
     2817    // FIXME: should plot triangles instead to avoid rendering glitches.
     2818    BeginQuadrilaterals();
     2819////    PlaceNormal(normal);
     2820    SetColourFromGradient(static_gradient_hack, factor);
     2821    PlaceVertex(a, 0, 0);
     2822    PlaceVertex(b, w, 0);
     2823    PlaceVertex(c, w, h);
     2824    PlaceVertex(d, 0, h);
     2825    EndQuadrilaterals();
    27532826}
    27542827
     
    30063079
    30073080        if (draw) {
    3008             static_length_hack = (pt_v - prev_pt_v).magnitude();
     3081            const Vector3 & delta = pt_v - prev_pt_v;
     3082            static_length_hack = delta.magnitude();
     3083            static_gradient_hack = delta.gradient();
    30093084            if (segment > 0) {
    30103085                (this->*AddQuad)(v[0], v[1], U[1], U[0]);
     
    31323207            AddQuad = &GfxCore::AddQuadrilateralError;
    31333208            AddPoly = &GfxCore::AddPolylineError;
     3209            break;
     3210        case COLOUR_BY_GRADIENT:
     3211            AddQuad = &GfxCore::AddQuadrilateralGradient;
     3212            AddPoly = &GfxCore::AddPolylineGradient;
    31343213            break;
    31353214        case COLOUR_BY_LENGTH:
     
    33793458        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
    33803459        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_ERROR, wmsg(/*Colour by E&rror*/289));
     3460        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_GRADIENT, wmsg(/*Colour by Grad&ient*/85));
    33813461        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
    33823462        menu.AppendSeparator();
     
    33873467        if (m_ColourBy == COLOUR_BY_DEPTH || m_ColourBy == COLOUR_BY_LENGTH)
    33883468            menu.AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342));
     3469        else if (m_ColourBy == COLOUR_BY_GRADIENT)
     3470            menu.AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343));
    33893471        menu.Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)&wxEvtHandler::ProcessEvent, NULL, m_Parent->GetEventHandler());
    33903472        PopupMenu(&menu);
  • src/gfxcore.h

    ra4e7c6f rcc9e2c65  
    9292    COLOUR_BY_DATE,
    9393    COLOUR_BY_ERROR,
     94    COLOUR_BY_GRADIENT,
    9495    COLOUR_BY_LENGTH,
    9596    COLOUR_BY_LIMIT_ // Leave this last.
     
    125126        LIST_DATE_KEY,
    126127        LIST_ERROR_KEY,
     128        LIST_GRADIENT_KEY,
    127129        LIST_LENGTH_KEY,
    128130        LIST_UNDERGROUND_LEGS,
     
    246248    void SetColourFromDate(int date, Double factor);
    247249    void SetColourFromError(double E, Double factor);
     250    void SetColourFromGradient(double angle, Double factor);
    248251    void SetColourFromLength(double len, Double factor);
    249252
     
    271274    void DrawDateKey();
    272275    void DrawErrorKey();
     276    void DrawGradientKey();
    273277    void DrawLengthKey();
    274278    void DrawCompass();
     
    468472        ToggleFlag(&m_HitTestDebug);
    469473    }
    470     void ToggleDegrees() { ToggleFlag(&m_Degrees); }
     474    void ToggleDegrees() {
     475        ToggleFlag(&m_Degrees);
     476        InvalidateList(LIST_GRADIENT_KEY);
     477    }
    471478    void TogglePercent() { ToggleFlag(&m_Percent); }
    472479    void ToggleTubes() { ToggleFlag(&m_Tubes); }
     
    507514    void AddPolylineDate(const traverse & centreline);
    508515    void AddPolylineError(const traverse & centreline);
     516    void AddPolylineGradient(const traverse & centreline);
    509517    void AddPolylineLength(const traverse & centreline);
    510518    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
     
    517525    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
    518526                               const Vector3 &c, const Vector3 &d);
     527    void AddQuadrilateralGradient(const Vector3 &a, const Vector3 &b,
     528                                  const Vector3 &c, const Vector3 &d);
    519529    void AddQuadrilateralLength(const Vector3 &a, const Vector3 &b,
    520530                                const Vector3 &c, const Vector3 &d);
  • src/guicontrol.cc

    ra4e7c6f rcc9e2c65  
    545545}
    546546
     547void GUIControl::OnColourByGradient()
     548{
     549    if (m_View->ColouringBy() == COLOUR_BY_GRADIENT) {
     550        m_View->SetColourBy(COLOUR_BY_NONE);
     551    } else {
     552        m_View->SetColourBy(COLOUR_BY_GRADIENT);
     553    }
     554}
     555
    547556void GUIControl::OnColourByLength()
    548557{
     
    570579    cmd.Enable(m_View->HasData());
    571580    cmd.Check(m_View->ColouringBy() == COLOUR_BY_ERROR);
     581}
     582
     583void GUIControl::OnColourByGradientUpdate(wxUpdateUIEvent& cmd)
     584{
     585    cmd.Enable(m_View->HasData());
     586    cmd.Check(m_View->ColouringBy() == COLOUR_BY_GRADIENT);
    572587}
    573588
  • src/guicontrol.h

    ra4e7c6f rcc9e2c65  
    7676    void OnColourByDate();
    7777    void OnColourByError();
     78    void OnColourByGradient();
    7879    void OnColourByLength();
    7980    void OnShowCrosses();
     
    126127    void OnColourByDateUpdate(wxUpdateUIEvent&);
    127128    void OnColourByErrorUpdate(wxUpdateUIEvent&);
     129    void OnColourByGradientUpdate(wxUpdateUIEvent&);
    128130    void OnColourByLengthUpdate(wxUpdateUIEvent&);
    129131    void OnShowCrossesUpdate(wxUpdateUIEvent&);
  • src/mainfrm.cc

    ra4e7c6f rcc9e2c65  
    593593    EVT_MENU(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDate)
    594594    EVT_MENU(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByError)
     595    EVT_MENU(menu_VIEW_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradient)
    595596    EVT_MENU(menu_VIEW_COLOUR_BY_LENGTH, MainFrm::OnColourByLength)
    596597    EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface)
     
    656657    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDateUpdate)
    657658    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByErrorUpdate)
     659    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradientUpdate)
    658660    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_LENGTH, MainFrm::OnColourByLengthUpdate)
    659661    EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate)
     
    920922    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
    921923    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_ERROR, wmsg(/*Colour by E&rror*/289));
     924    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_GRADIENT, wmsg(/*Colour by Grad&ient*/85));
    922925    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
    923926    viewmenu->AppendSeparator();
  • src/mainfrm.h

    ra4e7c6f rcc9e2c65  
    118118    menu_VIEW_COLOUR_BY_DATE,
    119119    menu_VIEW_COLOUR_BY_ERROR,
     120    menu_VIEW_COLOUR_BY_GRADIENT,
    120121    menu_VIEW_COLOUR_BY_LENGTH,
    121122    menu_IND_COMPASS,
     
    322323    void OnColourByDateUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnColourByDateUpdate(event); }
    323324    void OnColourByErrorUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnColourByErrorUpdate(event); }
     325    void OnColourByGradientUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnColourByGradientUpdate(event); }
    324326    void OnColourByLengthUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnColourByLengthUpdate(event); }
    325327    void OnShowCrossesUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnShowCrossesUpdate(event); }
     
    374376    void OnColourByDate(wxCommandEvent&) { if (m_Control) m_Control->OnColourByDate(); }
    375377    void OnColourByError(wxCommandEvent&) { if (m_Control) m_Control->OnColourByError(); }
     378    void OnColourByGradient(wxCommandEvent&) { if (m_Control) m_Control->OnColourByGradient(); }
    376379    void OnColourByLength(wxCommandEvent&) { if (m_Control) m_Control->OnColourByLength(); }
    377380    void OnShowCrosses(wxCommandEvent&) { if (m_Control) m_Control->OnShowCrosses(); }
  • src/vector3.h

    ra4e7c6f rcc9e2c65  
    44//
    55//  Copyright (C) 2000-2002, Mark R. Shinwell.
    6 //  Copyright (C) 2002-2004,2005,2006 Olly Betts
     6//  Copyright (C) 2002-2004,2005,2006,2015 Olly Betts
    77//
    88//  This program is free software; you can redistribute it and/or modify
     
    4040    double magnitude() const {
    4141        return sqrt(x*x + y*y + z*z);
     42    }
     43
     44    // Returns a value in *radians*.
     45    double gradient() const {
     46        return atan2(z, sqrt(x*x + y*y));
    4247    }
    4348
Note: See TracChangeset for help on using the changeset viewer.