Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Store GPS track along with time range in a new struct GPSTrack

The track and metadata (start & end times) are set at the
same time when the track is loaded.
  • Loading branch information...
commit 8e3c9d11d6688de0c48ab2e8935f500a7ba5694b 1 parent 469e04a
@dfandrich dfandrich authored
View
30 correlate.c
@@ -104,30 +104,6 @@ struct GPSPoint* CorrelatePhoto(const char* Filename,
* be freed for us. */
free(TimeTemp);
- /* Check to see if MinTime and MaxTime are filled in.
- * If not, fill them in. */
- if (Options->MinTime == 0 && Options->MaxTime == 0)
- {
- /* Alright, fill them in!
- * Requires us to go through the list and keeping
- * the biggest and smallest. The list should,
- * however, be sorted. But we do it this way anyway. */
- struct GPSPoint* Fill = NULL;
- Options->MinTime = Options->Points->Time;
- for (Fill = Options->Points; Fill; Fill = Fill->Next)
- {
- /* Ignore trackseg markers... */
- if (Fill->Lat == 1000 && Fill->Long == 1000)
- continue;
- /* Check the Min time */
- if (Fill->Time < Options->MinTime)
- Options->MinTime = Fill->Time;
- /* Check the Max time */
- if (Fill->Time > Options->MaxTime)
- Options->MaxTime = Fill->Time;
- }
- }
-
/* Check that the photo is within the times that
* our tracks are for. Can't really match it if
* we were not logging when it was taken. */
@@ -135,8 +111,8 @@ struct GPSPoint* CorrelatePhoto(const char* Filename,
* same file will still make it inside of this. In
* some cases, it won't matter, but if it does, then
* keep this in mind!! */
- if ((PhotoTime < Options->MinTime) ||
- (PhotoTime > Options->MaxTime))
+ if ((PhotoTime < Options->Track.MinTime) ||
+ (PhotoTime > Options->Track.MaxTime))
{
/* Outside the range. Abort. */
Options->Result = CORR_NOMATCH;
@@ -151,7 +127,7 @@ struct GPSPoint* CorrelatePhoto(const char* Filename,
Options->Result = CORR_NOMATCH; /* For convenience later */
- for (Search = Options->Points; Search; Search = Search->Next)
+ for (Search = Options->Track.Points; Search; Search = Search->Next)
{
/* Sanity check: we need to peek at the next point.
* Make sure we can. */
View
6 correlate.h
@@ -41,14 +41,11 @@ struct CorrelateOptions {
int Result;
- time_t MinTime; /* Calculated on first pass. Used to */
- time_t MaxTime; /* determine when to throw photos out. */
-
int PhotoOffset; /* Offset applied to Photo time. This is ADDED to PHOTO TIME
to make it match GPS time. In seconds.
This is (GPS - Photo) */
- struct GPSPoint* Points; /* Points to use... */
+ struct GPSTrack Track; /* Points to use... */
};
/* Return codes in order:
@@ -79,4 +76,3 @@ struct CorrelateOptions {
struct GPSPoint* CorrelatePhoto(const char* Filename,
struct CorrelateOptions* Options);
-
View
6 gpsstructure.h
@@ -36,3 +36,9 @@ struct GPSPoint {
int EndOfSegment;
struct GPSPoint* Next;
};
+
+struct GPSTrack {
+ struct GPSPoint* Points;
+ time_t MinTime;
+ time_t MaxTime;
+};
View
37 gpx-read.c
@@ -35,6 +35,7 @@
#include "unixtime.h"
#include "gpsstructure.h"
+/* Pointers to the first and last points, used during parsing */
static struct GPSPoint* FirstPoint;
static struct GPSPoint* LastPoint;
@@ -180,8 +181,30 @@ static void FindTrackSeg(xmlNodePtr Start)
}
+/* Determines and stores the min and max times from the GPS track */
+static void GetTrackRange(struct GPSTrack* Track)
+{
+ /* Requires us to go through the list and keep
+ * the biggest and smallest. The list should,
+ * however, be sorted. But we do it this way anyway. */
+ const struct GPSPoint* Fill = NULL;
+ Track->MinTime = Track->Points->Time;
+ for (Fill = Track->Points; Fill; Fill = Fill->Next)
+ {
+ /* Ignore trackseg markers... */
+ if (Fill->Lat == 1000 && Fill->Long == 1000)
+ continue;
+ /* Check the Min time */
+ if (Fill->Time < Track->MinTime)
+ Track->MinTime = Fill->Time;
+ /* Check the Max time */
+ if (Fill->Time > Track->MaxTime)
+ Track->MaxTime = Fill->Time;
+ }
+}
-struct GPSPoint* ReadGPX(const char* File)
+
+int ReadGPX(const char* File, struct GPSTrack* Track)
{
/* Init the libxml library. Also checks version. */
LIBXML_TEST_VERSION
@@ -257,16 +280,21 @@ struct GPSPoint* ReadGPX(const char* File)
xmlFreeDoc(GPXData);
xmlCleanupParser();
- return FirstPoint;
+ Track->Points = FirstPoint;
+
+ /* Find the time range for this track */
+ GetTrackRange(Track);
+
+ return 1;
};
-void FreePointList(struct GPSPoint* List)
+void FreeTrack(struct GPSTrack* Track)
{
/* Free the memory associated with the
* GPSPoint list... */
struct GPSPoint* NextFree = NULL;
- struct GPSPoint* CurrentFree = List;
+ struct GPSPoint* CurrentFree = Track->Points;
while (1)
{
if (CurrentFree == NULL) break;
@@ -274,4 +302,5 @@ void FreePointList(struct GPSPoint* List)
free(CurrentFree);
CurrentFree = NextFree;
}
+ Track->Points = NULL;
};
View
6 gpx-read.h
@@ -25,5 +25,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-struct GPSPoint* ReadGPX(const char* File);
-void FreePointList(struct GPSPoint* List);
+struct GPSTrack;
+
+int ReadGPX(const char* File, struct GPSTrack* Track);
+void FreeTrack(struct GPSTrack* Track);
View
25 gui.c
@@ -135,7 +135,7 @@ struct GUIPhotoList {
struct GUIPhotoList* FirstPhoto = NULL;
struct GUIPhotoList* LastPhoto = NULL;
-struct GPSPoint* GPSData = NULL;
+struct GPSTrack GPSData;
static const char* ConfigDefaults[] = {
"interpolate", "true",
@@ -577,7 +577,7 @@ gboolean DestroyWindow(GtkWidget *Widget,
}
/* Free the memory for the GPS data, if applicable. */
- if (GPSData) FreePointList(GPSData);
+ FreeTrack(&GPSData);
/* Tell GTK that we're done. */
gtk_exit(0);
@@ -951,14 +951,10 @@ void SelectGPSButtonPress( GtkWidget *Widget, gpointer Data )
/* Process the result of the dialog... */
FileName = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(GPSDataDialog));
- /* Sanity check: do we already have data?
+ /* Sanity check: free the GPS track in case we already have one.
* Note: we check this now, because if we cancelled the dialog,
* we should run with the old data. */
- if (GPSData)
- {
- /* We already had GPS data. Free that first. */
- FreePointList(GPSData);
- }
+ FreeTrack(&GPSData);
/* Prepare our "scratch" for rewriting labels. */
Scratch = malloc(sizeof(char) * (strlen(FileName) + 100));
@@ -976,13 +972,13 @@ void SelectGPSButtonPress( GtkWidget *Widget, gpointer Data )
GtkGUIUpdate();
/* Read in the new data... assuming we can. */
- GPSData = ReadGPX(FileName);
+ int ReadOk = ReadGPX(FileName, &GPSData);
/* Close the dialog now we're done. */
gtk_widget_destroy(ErrorDialog);
/* Check if the data was read ok. */
- if (GPSData)
+ if (ReadOk)
{
/* It's all good!
* Adjust the label to say so. */
@@ -1042,7 +1038,7 @@ void CorrelateButtonPress( GtkWidget *Widget, gpointer Data )
return;
}
- if (GPSData == NULL)
+ if (GPSData.Points == NULL)
{
/* No GPS data... */
ErrorDialog = gtk_message_dialog_new (GTK_WINDOW(MatchWindow),
@@ -1132,11 +1128,8 @@ void CorrelateButtonPress( GtkWidget *Widget, gpointer Data )
/* Photo Offset time */
Options.PhotoOffset = atoi(gtk_entry_get_text(GTK_ENTRY(PhotoOffsetEntry)));
- /* Clean up some other pointers in the structure. */
- Options.MinTime = 0;
- Options.MaxTime = 0;
-
- Options.Points = GPSData;
+ /* Store the GPS track */
+ Options.Track = GPSData;
/* Walk through the list, correlating, and updating the screen. */
struct GUIPhotoList* Walk;
View
45 main-command.c
@@ -218,7 +218,7 @@ int main(int argc, char** argv)
/* But first, some variables to store stuff in. */
int c;
- char* GPSData = NULL; /* Filename of the file with the GPS data. */
+ struct GPSTrack Track = {0,0,0}; /* List of GPS waypoints */
char* TimeAdjustment = NULL; /* Time adjustment, as passed to program. */
int AutoTimeZone = 1;
int TimeZoneHours = 0; /* Integer version of the timezone. */
@@ -236,6 +236,7 @@ int main(int argc, char** argv)
int FixDatestamps = 0;
int DegMinSecs = 1;
int PhotoOffset = 0;
+ int HaveTrack = 0;
while (1)
{
@@ -252,10 +253,18 @@ int main(int argc, char** argv)
case 'g':
/* This parameter specifies the GPS data.
* It must be present. */
- if (optarg)
+ if (optarg && !HaveTrack)
{
- GPSData = malloc((sizeof(char) * strlen(optarg)) + 1);
- strncpy(GPSData, optarg, strlen(optarg)+1);
+ /* Read the XML file into memory and extract the "points". */
+ /* The returned pointer is the start of a singly-linked list. */
+ printf("Reading GPS Data...");
+ fflush(stdout);
+ HaveTrack = ReadGPX(optarg, &Track);
+ printf("\n");
+ if (!HaveTrack)
+ {
+ exit(EXIT_FAILURE);
+ }
}
break;
case 'z':
@@ -438,29 +447,13 @@ int main(int argc, char** argv)
}
- /* See if the user did pass any GPS data.
- * If not, don't continue. */
- if (GPSData == NULL)
- {
- printf("You need to pass some GPS data! Otherwise, nothing to match from!\n");
- exit(EXIT_FAILURE);
- }
-
- /* Read the XML file into memory and extract the "points". */
- /* The returned pointer is the start of a singly-linked list. */
- printf("Reading GPS Data...");
- struct GPSPoint* Points = ReadGPX(GPSData);
- printf("\n");
-
- if (Points)
+ if (!HaveTrack)
{
- /* GPS Data was read correctly. */
- } else {
/* GPS Data was not read correctly... */
/* Tell the user we are bailing.
* Not really required, seeing as ReadGPX should
* inform the user anyway... but, doesn't hurt! */
- printf("Failure reading/processing GPS data.\n");
+ printf("Cannot continue since no GPS data is available.\n");
exit(EXIT_FAILURE);
}
@@ -486,10 +479,7 @@ int main(int argc, char** argv)
Options.DegMinSecs = DegMinSecs;
Options.PhotoOffset = PhotoOffset;
- Options.MinTime = 0;
- Options.MaxTime = 0;
-
- Options.Points = Points;
+ Options.Track = Track;
/* Twig with the terminal settings to make the single character
* output stuff work right. */
@@ -665,8 +655,7 @@ int main(int argc, char** argv)
/* Clean up! */
- FreePointList(Points);
- if (GPSData) free(GPSData);
+ FreeTrack(&Track);
if (TimeAdjustment) free(TimeAdjustment);
if (Datum) free(Datum);
Please sign in to comment.
Something went wrong with that request. Please try again.