15#include "UniversalGroundMap.h"
21#include "Projection.h"
22#include "ProjectionFactory.h"
44 unsigned int height) {
56 p_gridSize = (
unsigned long)(ceil(width * height / 8.0) + 0.5);
66 for (
unsigned long i = 0; i <
p_gridSize; i++) {
145 Distance largerRadius = max(radius1, radius2);
152 largerRadius.meters()) * 10;
156 largerRadius.meters()) * 10;
248 IString msg =
"GroundGrid::CreateGrid missing ground map or grid array";
253 for (
unsigned long i = 0; i <
p_gridSize; i++) {
261 bool badLatLonRange =
false;
262 QVector<IString> badLatLonValues;
264 badLatLonValues.append(
"MinimumLatitude");
265 badLatLonRange =
true;
269 badLatLonValues.append(
"MaximumLatitude");
270 badLatLonRange =
true;
274 badLatLonValues.append(
"MinimumLongitude");
275 badLatLonRange =
true;
279 badLatLonValues.append(
"MaximumLongitude");
280 badLatLonRange =
true;
284 if (badLatLonRange) {
285 IString msg =
"Could not determine values for [";
286 for (
int i = 0; i < badLatLonValues.size(); i++) {
290 msg += badLatLonValues[i];
293 msg +=
"], please specify them explicitly";
323 (long)((*
p_maxLon - startLon) / lonInc) * lonInc + startLon;
326 double numSteps = (double)((endLat - startLat) / latInc) + 1;
327 numSteps += (double)((endLon - startLon) / lonInc) + 1;
330 IString msg =
"No gridlines would intersect the image";
342 for (; latStep <= endLat + latInc / 2; latStep += latInc) {
343 unsigned int previousX = 0;
344 unsigned int previousY = 0;
345 bool havePrevious =
false;
350 bool valid =
GetXY(latStep, lon, x, y);
352 if (valid && havePrevious) {
353 if (previousX != x || previousY != y) {
358 havePrevious = valid;
368 for (
Longitude lon = startLon; lon <= endLon + lonInc / 2; lon += lonInc) {
369 unsigned int previousX = 0;
370 unsigned int previousY = 0;
371 bool havePrevious =
false;
377 for (; latStep <= *
p_maxLat; latStep += lonRes) {
381 bool valid =
GetXY(latStep, lon, x, y);
383 if (valid && havePrevious) {
384 if (previousX == x && previousY == y) {
391 havePrevious = valid;
448 for (; latStep <= maxLat; latStep += (maxLat - minLat)) {
449 unsigned int previousX = 0;
450 unsigned int previousY = 0;
451 bool havePrevious =
false;
453 for (
Longitude lon = minLon; lon <= maxLon; lon += latRes) {
456 bool valid =
GetXY(latStep, lon, x, y);
458 if (valid && havePrevious) {
459 if (previousX != x || previousY != y) {
464 havePrevious = valid;
471 for (
Longitude lon = minLon; lon <= maxLon; lon += (maxLon - minLon)) {
472 unsigned int previousX = 0;
473 unsigned int previousY = 0;
474 bool havePrevious =
false;
480 for (; latStep <= maxLat; latStep += lonRes) {
483 bool valid =
GetXY(latStep, lon, x, y);
485 if (valid && havePrevious) {
486 if (previousX != x || previousY != y) {
491 havePrevious = valid;
511 if (x < 0)
return false;
512 if (y < 0)
return false;
514 if (x >= (
int)
p_width)
return false;
515 if (y >= (
int)
p_height)
return false;
530 if (x < 0)
return false;
531 if (y < 0)
return false;
533 if (x >= (
int)
p_width)
return false;
534 if (y >= (
int)
p_height)
return false;
619 unsigned int &x,
unsigned int &y) {
622 if (!
GroundMap()->SetUnboundGround(lat, lon))
return false;
625 if (!
GroundMap()->SetGround(lat, lon))
return false;
656 unsigned long bitPosition = (y *
p_width) + x;
657 unsigned long byteContainer = bitPosition / 8;
658 unsigned int bitOffset = bitPosition % 8;
663 char &importantByte =
p_grid[byteContainer];
664 importantByte |= (1 << bitOffset);
668 importantByte |= (1 << bitOffset);
672 importantByte |= (1 << bitOffset);
675 IString msg =
"GroundGrid::SetGridBit no grids available";
692 unsigned long bitPosition = (y *
p_width) + x;
693 unsigned long byteContainer = bitPosition / 8;
694 unsigned int bitOffset = bitPosition % 8;
701 char &importantByte =
p_grid[byteContainer];
702 result = (importantByte >> bitOffset) & 1;
706 result = (importantByte >> bitOffset) & 1;
710 result = (importantByte >> bitOffset) & 1;
713 IString msg =
"GroundGrid::GetGridBit no grids available";
731 unsigned int x2,
unsigned int y2,
739 double m = (double)dy / (
double)dx;
740 double b = y1 - m * x1;
742 dx = (x2 > x1) ? 1 : -1;
745 y1 = (int)(m * x1 + b + 0.5);
Defines an angle and provides unit conversions.
bool isValid() const
This indicates whether we have a legitimate angle stored or are in an unset, or invalid,...
@ Degrees
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
void BasicMapping(Pvl &map)
Writes the basic mapping group to the specified Pvl.
double HighestImageResolution()
Returns the highest/best resolution in the entire image.
Distance measurement, usually in meters.
@ Meters
The distance is being specified in meters.
void SetGridBit(unsigned int x, unsigned int y, bool latGrid)
This flags a bit as on the grid lines.
Longitude * p_minLon
Lowest longitude in image.
double p_defaultResolution
Default step size in degrees/pixel.
Latitude maxLatitude() const
Returns the maximum latitude for the grid.
char * p_lonLinesGrid
This stores the bits of each pixel in the grid.
Latitude * p_minLat
Lowest latitude in image.
GroundGrid(UniversalGroundMap *gmap, bool splitLatLon, bool extendGrid, unsigned int width, unsigned int height)
This method initializes the class by allocating the grid, calculating the lat/lon range,...
virtual ~GroundGrid()
Delete the object.
PvlGroup * p_mapping
The mapping group representation of the projection or camera.
void CreateGrid(Latitude baseLat, Longitude baseLon, Angle latInc, Angle lonInc, Progress *progress=0)
This method draws the grid internally, using default resolutions.
void SetGroundLimits(Latitude minLat, Longitude minLon, Latitude maxLat, Longitude maxLon)
This restricts (or grows) the ground range in which to draw grid lines.
bool PixelOnGrid(int x, int y)
Returns true if the grid is on this point.
Latitude minLatitude() const
Returns the minimum latitude for the grid.
UniversalGroundMap * p_groundMap
This calculates single grid pts.
UniversalGroundMap * GroundMap()
Returns the ground map for children.
Longitude minLongitude() const
Returns the minimum longitude for the grid.
unsigned int p_width
This is the width of the grid.
PvlGroup * GetMappingGroup()
Returns a mapping group representation of the projection or camera.
bool m_extendGrid
If the grid should extend past the longitude domain boundary.
unsigned long p_gridSize
This is width*height.
char * p_latLinesGrid
This stores the bits of each pixel in the grid.
void DrawLineOnGrid(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, bool isLatLine)
This sets the bits on the grid along the specified line.
Longitude maxLongitude() const
Returns the maximum longitude for the grid.
bool GetGridBit(unsigned int x, unsigned int y, bool latGrid)
Returns true if the specified coordinate is on the grid lines.
bool p_reinitialize
True if we need to reset p_grid in CreateGrid.
unsigned int p_height
This is the height of the grid.
char * p_grid
This stores the bits of each pixel in the grid.
virtual bool GetXY(Latitude lat, Longitude lon, unsigned int &x, unsigned int &y)
This method converts a lat/lon to an X/Y.
void WalkBoundary()
This draws grid lines along the extremes of the lat/lon box of the grid.
Longitude * p_maxLon
Highest longitude in image.
Latitude * p_maxLat
Highest latitude in image.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
Adds specific functionality to C++ strings.
This class is designed to encapsulate the concept of a Latitude.
@ AllowPastPole
Don't throw an exception if a latitude beyond -90/90 is found.
void setErrorChecking(ErrorChecking errors)
Set the error checking status.
This class is designed to encapsulate the concept of a Longitude.
Program progress reporter.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
void CheckStatus()
Checks and updates the status.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Contains multiple PvlContainers.
Container for cube-like labels.
double Sample() const
Returns the current line value of the camera model or projection.
double Resolution() const
Returns the resolution of the camera model or projection.
double Line() const
Returns the current line value of the camera model or projection.
bool HasCamera()
Returns whether the ground map has a camera or not.
Isis::Projection * Projection() const
Return the projection associated with the ground map (NULL implies none)
Isis::Camera * Camera() const
Return the camera associated with the ground map (NULL implies none)
This is free and unencumbered software released into the public domain.
double toDouble(const QString &string)
Global function to convert from a string to a double.
Namespace for the standard library.