Unverified Commit e5b0fbd7 authored by Amy Stamile's avatar Amy Stamile Committed by GitHub
Browse files

Added Qview Lat/Lon Grid (#5043)

* LatLonGridTool

* draw lat lon grid

* toggles grid on and off.

* Small fixes and updated docs.

* added changelog and fixed segfault
parent dcfe42f2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ release.
### Changed

### Added
- Added LatLonGrid Tool to Qview to view latitude and longitude lines if camera model information is present.

### Deprecated

+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ find files of those names at the top level of this repository. **/
#include "BandTool.h"
#include "BlinkTool.h"
#include "EditTool.h"
#include "LatLonGridTool.h"
#include "FeatureNomenclatureTool.h"
#include "FileName.h"
#include "FileTool.h"
@@ -173,6 +174,8 @@ int main(int argc, char *argv[]) {

  Tool *editTool = createTool<EditTool>(vw, &tools);

  Tool *latLonGridTool = createTool<LatLonGridTool>(vw, &tools);

  Tool *windowTool = createTool<WindowTool>(vw, &tools);

  Tool *measureTool = createTool<MeasureTool>(vw, &tools);
@@ -274,6 +277,7 @@ int main(int argc, char *argv[]) {
  delete statsTool;
  delete helpTool;
  delete matchTool;
  delete latLonGridTool;
  delete stereoTool;
  delete histTool;
  delete spatialPlotTool;
+3 −0
Original line number Diff line number Diff line
@@ -266,5 +266,8 @@
    <change name="Summer Stapleton" date="2018-03-14">
      Included documentation for Spatial Plot Tool in this .xml. References #5281.
    </change>
    <change name="Amy Stamile" date="2022-08-26">
      Added latitude and longtitude grid display.
    </change>
  </history>
</application>
+152 −0
Original line number Diff line number Diff line
/** This is free and unencumbered software released into the public domain.

The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include "LatLonGridTool.h"

#include <QAction>
#include <QPixmap>
#include <QStackedWidget>
#include <QHBoxLayout>
#include <QCheckBox>
#include <QPainter>

#include "MdiCubeViewport.h"
#include "ToolPad.h"
#include "Camera.h"


namespace Isis {
  /**
   * Constructs an LatLonGridTool object.
   *
   * @param parent Parent widget
   */
  LatLonGridTool::LatLonGridTool(QWidget *parent) : Tool(parent) {
  }

  /**
   * Adds the LatLonGridTool to the tool pad.
   *
   * @param pad input - The tool pad that LatLonGridTool is to be added to
   *
   * @return QAction*
   */
  QAction *LatLonGridTool::toolPadAction(ToolPad *pad) {
    QAction *action = new QAction(pad);
    action->setIcon(QPixmap(toolIconDir() + "/grid.png"));
    action->setToolTip("Lat Lon Grid Tool (G)");
    action->setShortcut(Qt::Key_G);

    QString text  =
      "<b>Function:</b>  View lat lon grid \
      <p><b>Shortcut:</b> G</p> ";
    action->setWhatsThis(text);

    return action;
  }

  /**
   * Creates the toolbar containing the lat-lon grid tool widgets
   *
   * @param active  input  The widget that will contain the lat-lon grid tool
   *                       specific widgets
   *
   * @return QWidget*
   */
  QWidget *LatLonGridTool::createToolBarWidget(QStackedWidget *active) {
    QWidget *container = new QWidget(active);
    container->setObjectName("LatLonGridToolActiveToolBarWidget");

    m_gridCheckBox = new QCheckBox;
    m_gridCheckBox->setText("Show Grid");

    QHBoxLayout *layout = new QHBoxLayout;
    layout->setMargin(0);
    layout->addWidget(m_gridCheckBox);
    layout->addStretch(1);
    container->setLayout(layout);

    m_container = container;
    return container;
  }

  /**
   * Draws grid onto cube viewport
   * This is overiding the parents paintViewport member.
   *
   * @param vp Pointer to Viewport to be painted
   * @param painter
   */
  void LatLonGridTool::paintViewport(MdiCubeViewport *mvp, QPainter *painter) {
    int x1, x2, y1, y2;
    double lat, lon;

    QFont font;
    QBrush brush(Qt::gray);
    QPen pen(brush, 1);

    // Only draws if "Show Grid" checkbox is checked
    if (m_gridCheckBox->isChecked()) {
      painter->setPen(pen);
      font.setPixelSize(8);
      painter->setFont(font);

      // Draws Longitude Lines
      for (int i = mvp->cubeSamples(); i > 0; i -= mvp->cubeSamples() / 12) {
        if (mvp->camera() != NULL) {
            mvp->camera()->SetImage(i, 0);
            lon = mvp->camera()->UniversalLongitude();

            lon = ceil(lon * 100.0) / 100.0;

            mvp->cubeToViewport(i, 0, x1, y1);
            mvp->cubeToViewport(0, mvp->cubeLines(), x2, y2);
            painter->drawLine(x1, y1, x1, y2);

            painter->drawText(x1, y2 + 10, toString(lon));
        }
      }

      // Draws Latitude Lines
      for (int i = mvp->cubeLines(); i > 0; i -= mvp->cubeLines() / 12) {
        if (mvp->camera() != NULL) {
            mvp->camera()->SetImage(0, i);
            lat = mvp->camera()->UniversalLatitude();

            lat = ceil(lat * 100.0) / 100.0;

            mvp->cubeToViewport(0, i, x1, y1);
            mvp->cubeToViewport(mvp->cubeSamples(), 0, x2, y2);
            painter->drawLine(x1, y1, x2, y1);

            painter->drawText(x2 + 5, y1, toString(lat));
        }
      }
    }
    // remove grid by updating viewport to original cubeViewport
    else {
      mvp = cubeViewport();
    }
  }

  /**
   * Enables/Disable grid option tool based on camera model
   */
  void LatLonGridTool::updateTool() {
    MdiCubeViewport *vp = cubeViewport();

    if (vp != NULL) {
      if (vp->camera() == NULL) {
        m_gridCheckBox->setEnabled(false);
      }
      else {
          m_gridCheckBox->setEnabled(true);
      }
    }
  }
}
+56 −0
Original line number Diff line number Diff line
#ifndef LatLonGridTool_h
#define LatLonGridTool_h

/** This is free and unencumbered software released into the public domain.

The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include "Tool.h"


#include <QMap>
#include <QStack>
#include <QPointer>


class QToolButton;
class QPainter;
class QCheckBox;

namespace Isis {
  class MdiCubeViewport;


  /**
   * @brief Lat Lon Grid View Tool
   *
   * This tool is part of the Qisis namespace and allows visualizes latitude and
   * longitude lines on cube.
   *
   * @ingroup Visualization Tools
   *
   * @author  2022-08-08  Amy Stamile
   */
  class LatLonGridTool : public Tool {
      Q_OBJECT

    public:
      LatLonGridTool(QWidget *parent);
      void paintViewport(MdiCubeViewport *mvp, QPainter *painter);

    protected:
      QAction *toolPadAction(ToolPad *pad);
      QWidget *createToolBarWidget(QStackedWidget *active);
      void updateTool();

    private:
      QWidget *m_container;
      QPointer<QCheckBox> m_gridCheckBox;
  };
};

#endif
Loading