1 #include "GridGraphicsItem.h"
8 #include <QGraphicsScene>
17 #include "MosaicGraphicsView.h"
18 #include "MosaicSceneWidget.h"
26 GridGraphicsItem::GridGraphicsItem(Latitude baseLat, Longitude baseLon,
27 Angle latInc, Angle lonInc, MosaicSceneWidget *projectionSrc,
28 int density, Latitude latMin, Latitude latMax,
29 Longitude lonMin, Longitude lonMax) {
32 if (latInc > Angle(0.0, Angle::Degrees) && lonInc > Angle(0.0, Angle::Degrees)) {
34 Projection *proj = projectionSrc->getProjection();
35 Projection::ProjectionType pType = proj->projectionType();
37 if (proj && pType == Projection::Triaxial && lonMin < lonMax && latMin < latMax) {
38 TProjection *tproj = (TProjection *) proj;
39 PvlGroup mappingGroup(tproj->Mapping());
46 if (mappingGroup[
"LatitudeType"][0] ==
"Planetographic") {
48 Distance equaRad(tproj->EquatorialRadius(), Distance::Meters);
49 Distance polRad(tproj->PolarRadius(), Distance::Meters);
51 minLat = Latitude(latMin.planetographic(Angle::Degrees), mappingGroup,
53 maxLat = Latitude(latMax.planetographic(Angle::Degrees), mappingGroup,
55 baseLat = Latitude(baseLat.degrees(), equaRad, polRad,
56 Latitude::Planetocentric, Angle::Degrees);
59 if (!qFuzzyCompare(latInc.radians(), 0.0)) {
64 while (startLat < minLat) {
65 startLat = startLat.add(latInc, mappingGroup);
68 catch (IException &) {
72 while (startLat.add(latInc * -1, mappingGroup) >= minLat) {
73 startLat = startLat.add(latInc * -1, mappingGroup);
76 catch (IException &) {
85 while (endLat > maxLat) {
86 endLat = endLat.add(latInc * -1, mappingGroup);
89 catch (IException &) {
94 while (endLat.add(latInc, mappingGroup) <= maxLat) {
95 endLat = endLat.add(latInc, mappingGroup);
98 catch (IException &) {
103 minLat = Latitude(latMin.degrees(), mappingGroup,
105 maxLat = Latitude(latMax.degrees(), mappingGroup,
109 if (!qFuzzyCompare(latInc.radians(), 0.0)) {
111 baseLat - Angle(floor((baseLat - minLat) / latInc) * latInc), mappingGroup);
113 if (qFuzzyCompare(startLat.degrees(), -90.0))
114 startLat = Latitude(-90.0, mappingGroup, Angle::Degrees);
118 (
long)((maxLat - startLat) / latInc) * latInc + startLat,
120 if (qFuzzyCompare(endLat.degrees(), 90.0))
121 endLat = Latitude(90.0, mappingGroup, Angle::Degrees);
124 Longitude minLon(lonMin.degrees(), mappingGroup,
126 Longitude maxLon(lonMax.degrees(), mappingGroup,
131 if (!qFuzzyCompare(lonInc.radians(), 0.0)) {
132 startLon = Longitude(
133 baseLon - Angle(floor((baseLon - minLon) / lonInc) * lonInc));
137 (long)((maxLon - startLon) / lonInc) * lonInc + startLon;
139 if (qFuzzyCompare( (endLon + lonInc).radians(), maxLon.radians() )) {
144 if (!qFuzzyCompare( (startLat + latInc).radians(), startLat.radians() ) &&
145 !qFuzzyCompare( (startLon + lonInc).radians(), startLon.radians() )) {
147 int numCurvedLines = (int)ceil(((maxLat - minLat) / latInc) + 1);
148 numCurvedLines += (int)ceil(((maxLon - minLon) / lonInc) + 1);
150 int curvedLineDensity = density / numCurvedLines + 1;
151 Angle latRes((maxLon - minLon) / (
double)curvedLineDensity);
152 Angle lonRes((maxLat - minLat) / (
double)curvedLineDensity);
154 if (mappingGroup[
"LatitudeType"][0] ==
"Planetographic") {
156 (maxLat.planetographic() - minLat.planetographic()) / (
double)curvedLineDensity,
160 if (latRes <= Angle(0, Angle::Degrees))
161 latRes = Angle(1
E-10, Angle::Degrees);
163 if (lonRes <= Angle(0, Angle::Degrees))
164 lonRes = Angle(1E-10, Angle::Degrees);
166 bool firstIteration = true;
167 bool atMaxLat = false;
168 bool atMaxLon = false;
174 Latitude lat = minLat;
176 double previousX = 0;
177 double previousY = 0;
178 bool havePrevious =
false;
180 for(Longitude lon = minLon; lon != maxLon + latRes; lon += latRes) {
182 if (lon > maxLon && !atMaxLon) {
189 bool valid = tproj->SetUniversalGround(lat.degrees(), lon.degrees());
193 y = -1 * tproj->YCoord();
196 if(previousX != x || previousY != y) {
197 QGraphicsLineItem* latLine =
198 new QGraphicsLineItem(QLineF(previousX, previousY, x, y),
this);
202 pen.setCosmetic(
true);
203 latLine->setPen(pen);
208 havePrevious = valid;
222 firstIteration =
false;
228 nextLat = lat.add(latInc, mappingGroup);
230 catch (IException &) {
234 if (lat == minLat && minLat != startLat) {
236 if (startLat < minLat || startLat > maxLat) {
245 else if (lat >= maxLat) {
248 else if (nextLat > endLat) {
255 firstIteration =
true;
260 for (Longitude lon = minLon; lon != maxLon + lonInc; lon += lonInc) {
262 if (lon > endLon && lon < maxLon) {
266 if (lon > maxLon && !atMaxLon) {
271 double previousX = 0;
272 double previousY = 0;
273 bool havePrevious =
false;
275 Latitude lat = minLat;
279 bool valid = tproj->SetUniversalGround(lat.degrees(), lon.degrees());
283 y = -1 * tproj->YCoord();
287 y = -1 * proj->YCoord();
289 if(previousX != x || previousY != y) {
290 QGraphicsLineItem* lonLine =
291 new QGraphicsLineItem(QLineF(previousX, previousY, x, y),
this);
295 pen.setCosmetic(
true);
296 lonLine->setPen(pen);
301 havePrevious = valid;
309 lat = lat.add(lonRes, mappingGroup);
314 lon = startLon - lonInc;
316 firstIteration =
false;
327 GridGraphicsItem::~GridGraphicsItem() {
331 void GridGraphicsItem::paint(QPainter *painter,
332 const QStyleOptionGraphicsItem *style,
QWidget * widget) {
336 QRectF GridGraphicsItem::boundingRect()
const {
337 return m_boundingRect;
341 QRectF GridGraphicsItem::rect()
const {
342 return m_boundingRect;
346 QRectF GridGraphicsItem::calcRect()
const {
350 sceneRect = sceneRect.united(child->boundingRect());
357 void GridGraphicsItem::setRect(QRectF newBoundingRect) {
358 if (m_boundingRect != newBoundingRect) {
359 prepareGeometryChange();
360 m_boundingRect = newBoundingRect;
const double E(2.7182818284590452354)
Sets some basic constants for use in ISIS programming.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.