GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
points.c
Go to the documentation of this file.
1 #include <grass/imagery.h>
2 #include <grass/glocale.h>
3 
4 #define POINT_FILE "POINTS"
5 
6 static int I_read_control_points(FILE * fd, struct Control_Points *cp)
7 {
8  char buf[100];
9  double e1, e2, n1, n2;
10  int status;
11 
12  cp->count = 0;
13 
14  /* read the control point lines. format is:
15  image_east image_north target_east target_north status
16  */
17  cp->e1 = NULL;
18  cp->e2 = NULL;
19  cp->n1 = NULL;
20  cp->n2 = NULL;
21  cp->status = NULL;
22 
23  while (G_getl2(buf, sizeof buf, fd)) {
24  G_strip(buf);
25  if (*buf == '#' || *buf == 0)
26  continue;
27  if (sscanf(buf, "%lf%lf%lf%lf%d", &e1, &n1, &e2, &n2, &status) == 5)
28  I_new_control_point(cp, e1, n1, e2, n2, status);
29  else
30  return -4;
31  }
32 
33  return 1;
34 }
35 
36 
57 int I_new_control_point(struct Control_Points *cp,
58  double e1, double n1, double e2, double n2,
59  int status)
60 {
61  int i;
62  unsigned int size;
63 
64  if (status < 0)
65  return 1;
66  i = (cp->count)++;
67  size = cp->count * sizeof(double);
68  cp->e1 = (double *)G_realloc(cp->e1, size);
69  cp->e2 = (double *)G_realloc(cp->e2, size);
70  cp->n1 = (double *)G_realloc(cp->n1, size);
71  cp->n2 = (double *)G_realloc(cp->n2, size);
72  size = cp->count * sizeof(int);
73  cp->status = (int *)G_realloc(cp->status, size);
74 
75  cp->e1[i] = e1;
76  cp->e2[i] = e2;
77  cp->n1[i] = n1;
78  cp->n2[i] = n2;
79  cp->status[i] = status;
80 
81  return 0;
82 }
83 
84 static int I_write_control_points(FILE * fd, const struct Control_Points *cp)
85 {
86  int i;
87 
88  fprintf(fd, "# %7s %15s %15s %15s %9s status\n", "", "image", "",
89  "target", "");
90  fprintf(fd, "# %15s %15s %15s %15s (1=ok)\n", "east", "north", "east",
91  "north");
92  fprintf(fd, "#\n");
93  for (i = 0; i < cp->count; i++)
94  if (cp->status[i] >= 0)
95  fprintf(fd, " %15f %15f %15f %15f %4d\n",
96  cp->e1[i], cp->n1[i], cp->e2[i], cp->n2[i],
97  cp->status[i]);
98 
99  return 0;
100 }
101 
102 
117 int I_get_control_points(const char *group, struct Control_Points *cp)
118 {
119  FILE *fd;
120  int stat;
121 
122  fd = I_fopen_group_file_old(group, POINT_FILE);
123  if (fd == NULL) {
124  G_warning(_("Unable to open control point file for group [%s in %s]"),
125  group, G_mapset());
126  return 0;
127  }
128 
129  stat = I_read_control_points(fd, cp);
130  fclose(fd);
131  if (stat < 0) {
132  G_warning(_("Bad format in control point file for group [%s in %s]"),
133  group, G_mapset());
134  return 0;
135  }
136  return 1;
137 }
138 
139 
153 int I_put_control_points(const char *group, const struct Control_Points *cp)
154 {
155  FILE *fd;
156 
157  fd = I_fopen_group_file_new(group, POINT_FILE);
158  if (fd == NULL) {
159  G_warning(_("Unable to create control point file for group [%s in %s]"),
160  group, G_mapset());
161  return 0;
162  }
163 
164  I_write_control_points(fd, cp);
165  fclose(fd);
166  return 1;
167 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
#define POINT_FILE
Definition: points.c:4
int I_new_control_point(struct Control_Points *cp, double e1, double n1, double e2, double n2, int status)
add new control point
Definition: points.c:57
FILE * fd
Definition: g3dcolor.c:368
int I_put_control_points(const char *group, const struct Control_Points *cp)
write group control points
Definition: points.c:153
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
Definition: getl.c:52
int stat
Definition: g3dcolor.c:369
int I_get_control_points(const char *group, struct Control_Points *cp)
read group control points
Definition: points.c:117
int G_strip(char *buf)
Removes all leading and trailing white space from string.
Definition: strings.c:389
FILE * I_fopen_group_file_old(const char *group, const char *file)
Definition: fopen.c:43
FILE * I_fopen_group_file_new(const char *group, const char *file)
Definition: fopen.c:17
int
Definition: g3dcolor.c:48
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
fclose(fd)