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) {
33 if (latInc > Angle(0.0, Angle::Degrees) && lonInc > Angle(0.0, Angle::Degrees)) {
35 Projection *proj = projectionSrc->getProjection();
36 Projection::ProjectionType pType = proj->projectionType();
38 if (proj && pType == Projection::Triaxial && lonMin < lonMax && latMin < latMax) {
39 TProjection *tproj = (TProjection *) proj;
40 PvlGroup mappingGroup(tproj->Mapping());
47 if (mappingGroup[
"LongitudeDirection"][0] ==
"PositiveWest") {
48 Longitude temp = lonMin;
53 if (mappingGroup[
"LatitudeType"][0] ==
"Planetographic") {
55 Distance equaRad(tproj->EquatorialRadius(), Distance::Meters);
56 Distance polRad(tproj->PolarRadius(), Distance::Meters);
58 minLat = Latitude(latMin.planetographic(Angle::Degrees), mappingGroup,
60 maxLat = Latitude(latMax.planetographic(Angle::Degrees), mappingGroup,
62 baseLat = Latitude(baseLat.degrees(), equaRad, polRad,
63 Latitude::Planetocentric, Angle::Degrees);
66 if (!qFuzzyCompare(latInc.radians(), 0.0)) {
71 while (startLat < minLat) {
72 startLat = startLat.add(latInc, mappingGroup);
75 catch (IException &) {
79 while (startLat.add(latInc * -1, mappingGroup) >= minLat) {
80 startLat = startLat.add(latInc * -1, mappingGroup);
83 catch (IException &) {
92 while (endLat > maxLat) {
93 endLat = endLat.add(latInc * -1, mappingGroup);
96 catch (IException &) {
101 while (endLat.add(latInc, mappingGroup) <= maxLat) {
102 endLat = endLat.add(latInc, mappingGroup);
105 catch (IException &) {
110 minLat = Latitude(latMin.degrees(), mappingGroup,
112 maxLat = Latitude(latMax.degrees(), mappingGroup,
116 if (!qFuzzyCompare(latInc.radians(), 0.0)) {
118 baseLat - Angle(floor((baseLat - minLat) / latInc) * latInc), mappingGroup);
120 if (qFuzzyCompare(startLat.degrees(), -90.0))
121 startLat = Latitude(-90.0, mappingGroup, Angle::Degrees);
125 (
long)((maxLat - startLat) / latInc) * latInc + startLat,
127 if (qFuzzyCompare(endLat.degrees(), 90.0))
128 endLat = Latitude(90.0, mappingGroup, Angle::Degrees);
131 Longitude minLon(lonMin.degrees(), mappingGroup,
133 Longitude maxLon(lonMax.degrees(), mappingGroup,
138 if (!qFuzzyCompare(lonInc.radians(), 0.0)) {
139 startLon = Longitude(
140 baseLon - Angle(floor((baseLon - minLon) / lonInc) * lonInc));
144 (long)((maxLon - startLon) / lonInc) * lonInc + startLon;
146 if (qFuzzyCompare( (endLon + lonInc).radians(), maxLon.radians() )) {
151 if (!qFuzzyCompare( (startLat + latInc).radians(), startLat.radians() ) &&
152 !qFuzzyCompare( (startLon + lonInc).radians(), startLon.radians() )) {
154 int numCurvedLines = (int)ceil(((maxLat - minLat) / latInc) + 1);
155 numCurvedLines += (int)ceil(((maxLon - minLon) / lonInc) + 1);
157 int curvedLineDensity = density / numCurvedLines + 1;
158 Angle latRes((maxLon - minLon) / (
double)curvedLineDensity);
159 Angle lonRes((maxLat - minLat) / (
double)curvedLineDensity);
161 if (mappingGroup[
"LatitudeType"][0] ==
"Planetographic") {
163 (maxLat.planetographic() - minLat.planetographic()) / (
double)curvedLineDensity,
167 if (latRes <= Angle(0, Angle::Degrees))
168 latRes = Angle(1
E-10, Angle::Degrees);
170 if (lonRes <= Angle(0, Angle::Degrees))
171 lonRes = Angle(1
E-10, Angle::Degrees);
173 bool firstIteration =
true;
174 bool atMaxLat =
false;
175 bool atMaxLon =
false;
181 Latitude lat = minLat;
183 double previousX = 0;
184 double previousY = 0;
185 bool havePrevious =
false;
187 for(Longitude lon = minLon; lon != maxLon + latRes; lon += latRes) {
189 if (lon > maxLon && !atMaxLon) {
196 bool valid = tproj->SetUniversalGround(lat.degrees(), lon.degrees());
200 y = -1 * tproj->YCoord();
203 if(previousX != x || previousY != y) {
204 QGraphicsLineItem* latLine =
205 new QGraphicsLineItem(QLineF(previousX, previousY, x, y),
this);
209 pen.setCosmetic(
true);
210 latLine->setPen(pen);
215 havePrevious = valid;
229 firstIteration =
false;
235 nextLat = lat.add(latInc, mappingGroup);
237 catch (IException &) {
241 if (lat == minLat && minLat != startLat) {
243 if (startLat < minLat || startLat > maxLat) {
252 else if (lat >= maxLat) {
255 else if (nextLat > endLat) {
262 firstIteration =
true;
267 for (Longitude lon = minLon; lon != maxLon + lonInc; lon += lonInc) {
269 if (lon > endLon && lon < maxLon) {
273 if (lon > maxLon && !atMaxLon) {
278 double previousX = 0;
279 double previousY = 0;
280 bool havePrevious =
false;
282 Latitude lat = minLat;
286 bool valid = tproj->SetUniversalGround(lat.degrees(), lon.degrees());
290 y = -1 * tproj->YCoord();
294 y = -1 * proj->YCoord();
296 if(previousX != x || previousY != y) {
297 QGraphicsLineItem* lonLine =
298 new QGraphicsLineItem(QLineF(previousX, previousY, x, y),
this);
302 pen.setCosmetic(
true);
303 lonLine->setPen(pen);
308 havePrevious = valid;
316 lat = lat.add(lonRes, mappingGroup);
321 lon = startLon - lonInc;
323 firstIteration =
false;
334 GridGraphicsItem::~GridGraphicsItem() {
338 void GridGraphicsItem::paint(QPainter *painter,
339 const QStyleOptionGraphicsItem *style,
QWidget * widget) {
343 QRectF GridGraphicsItem::boundingRect()
const {
344 return m_boundingRect;
348 QRectF GridGraphicsItem::rect()
const {
349 return m_boundingRect;
353 QRectF GridGraphicsItem::calcRect()
const {
357 sceneRect = sceneRect.united(child->boundingRect());
364 void GridGraphicsItem::setRect(QRectF newBoundingRect) {
365 if (m_boundingRect != newBoundingRect) {
366 prepareGeometryChange();
367 m_boundingRect = newBoundingRect;
Namespace for the standard library.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
const double E
Sets some basic constants for use in ISIS programming.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Namespace for ISIS/Bullet specific routines.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.