[Git][debian-gis-team/jeolib-miallib][upstream] New upstream version 1.1.7
Bas Couwenberg (@sebastic)
gitlab at salsa.debian.org
Sat Oct 25 08:45:11 BST 2025
Bas Couwenberg pushed to branch upstream at Debian GIS Project / jeolib-miallib
Commits:
e0792e76 by Bas Couwenberg at 2025-10-25T09:07:59+02:00
New upstream version 1.1.7
- - - - -
10 changed files:
- CMakeLists.txt
- core/c/convolve.c
- core/c/dcluster.c
- core/c/miallib.h
- + core/c/myhull.c
- − core/c/myhull.cc
- core/c/myhull.h
- core/c/registration.c
- core/c/setreg.c
- core/c/uswilk.c
Changes:
=====================================
CMakeLists.txt
=====================================
@@ -32,7 +32,7 @@ set(MIALLIB_LIB_NAME miallib)
set (MIALLIB_VERSION_MAJOR 1)
set (MIALLIB_VERSION_MINOR 1)
-set (MIALLIB_VERSION_PATCH 6)
+set (MIALLIB_VERSION_PATCH 7)
set (MIALLIB_VERSION "${MIALLIB_VERSION_MAJOR}.${MIALLIB_VERSION_MINOR}.${MIALLIB_VERSION_PATCH}")
set (MIALLIB_SOVERSION "${MIALLIB_VERSION_MAJOR}")
@@ -198,7 +198,7 @@ set(SOURCES
${MIALLIB_SRC_DIR}/mslabel.h
${MIALLIB_SRC_DIR}/msmm.c
${MIALLIB_SRC_DIR}/mspa.c
- ${MIALLIB_SRC_DIR}/myhull.cc
+ ${MIALLIB_SRC_DIR}/myhull.c
${MIALLIB_SRC_DIR}/myhull.h
${MIALLIB_SRC_DIR}/natngbint.c
${MIALLIB_SRC_DIR}/newlabelcc.c
=====================================
core/c/convolve.c
=====================================
@@ -1014,7 +1014,7 @@ IMAGE *mean2dse(IMAGE *im, IMAGE *imse, int ox, int oy)
}
return NULL;
}
-extern ERROR_TYPE write_tiff();
+extern ERROR_TYPE write_tiff(IMAGE *im, char *fn);
#include "uc_def.h"
=====================================
core/c/dcluster.c
=====================================
@@ -26,7 +26,7 @@ along with miallib. If not, see <https://www.gnu.org/licenses/>.
-extern ERROR_TYPE us_plotline();
+extern ERROR_TYPE us_plotline(IMAGE *im, int x1, int y1, int x2, int y2, int val);
ERROR_TYPE agglo_cluster(int *x, int *y, int *pn, double maxdst)
=====================================
core/c/miallib.h
=====================================
@@ -355,8 +355,8 @@ extern void stdputstr(char *); /* print a message to the standard output */
extern void errputstr(char *); /* print a message to the standard error */
#else
static char buf[1024]; /* used by sprintf() and stdputstr() */
-extern void stdputstr(); /* print a message to the standard output */
-extern void errputstr(); /* print a message to the standard error */
+extern void stdputstr(char *); /* print a message to the standard output */
+extern void errputstr(char *); /* print a message to the standard error */
#endif /* #if (defined(XLISP)) */
#endif
=====================================
core/c/myhull.c
=====================================
@@ -0,0 +1,342 @@
+/***********************************************************************
+Author(s): Pierre Soille
+ Pieter Kempeneers
+Copyright (C) 2010-2025 European Union (Joint Research Centre)
+ 2025 Francesco Lovergine <francesco at lovergine.com>
+
+This file is part of miallib.
+
+miallib is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+miallib is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with miallib. If not, see <https://www.gnu.org/licenses/>.
+***********************************************************************/
+
+/* first 20101004 for convex hull and enclosing rectangle for building detection */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+
+#include "miallib.h"
+#include "fifo.h"
+#include "myhull.h"
+
+#ifdef OPENMP
+#include <omp.h>
+#endif
+
+/* Function to compare two points for sorting */
+int intpair_compare(const void *a, const void *b) {
+ const intpair_t *pa = (const intpair_t *)a;
+ const intpair_t *pb = (const intpair_t *)b;
+
+ if (pa->a < pb->a) return -1;
+ if (pa->a > pb->a) return 1;
+ if (pa->b < pb->b) return -1;
+ if (pa->b > pb->b) return 1;
+ return 0;
+}
+
+/* Calculate the orientation of three points (counterclockwise, collinear, or clockwise) */
+int orientation(intpair_t p, intpair_t q, intpair_t r) {
+ return (q.b - p.b) * (r.a - q.a) - (q.a - p.a) * (r.b - q.b);
+}
+
+/* Function to find the convex hull using Andrew's monotone chain algorithm */
+int chainHull_2D(intpair_t *points, int n, intpair_t *hull) {
+ /* Sort the points lexicographically (first by x, then by y) */
+ qsort(points, n, sizeof(intpair_t), intpair_compare);
+
+ int k = 0; /* Index for hull array */
+
+ /* Build lower hull */
+ for (int i = 0; i < n; i++) {
+ while (k >= 2 && orientation(hull[k-2], hull[k-1], points[i]) <= 0) {
+ k--;
+ }
+ hull[k++] = points[i];
+ }
+
+ /* Build upper hull */
+ int t = k + 1; /* t points to the start of upper hull in the output array */
+ for (int i = n - 2; i >= 0; i--) {
+ while (k >= t && orientation(hull[k-2], hull[k-1], points[i]) <= 0) {
+ k--;
+ }
+ hull[k++] = points[i];
+ }
+
+ /* Remove the last point which is a duplicate of the first point */
+ if (k > 1) k--;
+
+ return k; /* Return the number of points in the hull */
+}
+
+/* Sorting function for integers
+int intsort(const void *a, const void *b) {
+ int _a = *(int*)a;
+ int _b = *(int*)b;
+ return _a - _b;
+} */
+
+#include "u32_def.h"
+#define MY_LUT_TYPE UINT32
+#define t_MY_LUT_TYPE t_UINT32
+
+IMAGE *u32_chull(IMAGE *ilbl, int graph) {
+ /* Processing based on contour representation:
+ only points with change of direction are kept.
+ Use MSB for flagging.
+ assumes border is set to zero to avoid border overflow.
+ */
+ G_TYPE *pg;
+ IMAGE *lut;
+ MY_LUT_TYPE *plut;
+ PIX_TYPE *plbl, maxlbl, lbl;
+ IMAGE *imout;
+ UCHAR *pout;
+ int nx = GetImNx(ilbl);
+ long int i, npix, pos; // openMP requires signed loop index
+
+ // Defines the neighborhood offset position from current position and the neighborhood
+ // position we want to check next if we find a new border at checkLocationNr
+ // 1 2 3
+ // 0 x 4
+ // 7 6 5
+ int neighborhood[8][2] = {
+ {-1, 7}, // red
+ {-1-nx, 7}, // green
+ {-nx, 1}, // blue
+ {-nx+1, 1}, // yellow
+ {1, 3}, // magenta
+ {1+nx, 3}, // cyan
+ {nx, 5}, // white
+ {nx-1, 5} // grey
+ };
+
+ if (graph != 8)
+ graph = 4;
+ if (graph == 4) {
+ // - 1 -
+ // 0 x 2
+ // - 3 -
+ neighborhood[0][0] = -1; // red
+ neighborhood[0][1] = 4;
+ neighborhood[1][0] = -nx; // green
+ neighborhood[1][1] = 1;
+ neighborhood[2][0] = 1; // blue
+ neighborhood[2][1] = 2;
+ neighborhood[3][0] = nx; // yellow
+ neighborhood[3][1] = 3;
+ }
+
+ imout = (IMAGE *)create_image(t_UCHAR, GetImNx(ilbl), GetImNy(ilbl), 1);
+ if (imout == NULL)
+ return NULL;
+
+ /* get min & max values */
+ pg = min_max(ilbl);
+ if (pg == NULL)
+ return(NULL);
+ maxlbl = pg[1].u32_val;
+ free((char *)pg);
+
+ lut = (IMAGE *)create_image(t_MY_LUT_TYPE, maxlbl+1, 1, 1);
+ if (lut == NULL) {
+ free_image(imout);
+ return NULL;
+ }
+ plut = (MY_LUT_TYPE *)GetImPtr(lut);
+ plbl = (PIX_TYPE *)GetImPtr(ilbl);
+ pout = (UCHAR *)GetImPtr(imout);
+ npix = GetImNPix(ilbl);
+
+ plut[0] = 1; // dummy value to speed-up next loop
+ /* first collect first point of each CC in an array
+ for subsequent parallel processing */
+ for (i = 0; i < npix; i++) {
+ if (plut[plbl[i]] == 0) {
+ plut[plbl[i]] = i;
+ }
+ }
+
+ /* process one cc at a time */
+#ifdef OPENMP
+#pragma omp parallel for private(lbl, pos)
+#endif
+ for (i = 1; i <= maxlbl; i++) { // lbl==0 for background or border
+ int checkLocationNr = 1; // The neighbor number of the location we want to check for a
+ // new border point
+ int checkPosition; // The corresponding absolute array address of checkLocationNr
+ int newCheckLocationNr; // Variable that holds the neighborhood position we want to
+ // check if we find a new border at checkLocationNr
+ long int startPos = plut[i]; // Set start position
+ int counter = 0; // Counter is used for the jacobi stop criterion
+ int counter2 = 0; // Counter2 is used to determine if the point we have discovered
+ // is one single point
+ int prevCheckLocationNr = 9; // init with dummy direction
+ int n = 0; // number of points with change of direction
+ int nh = 0; // number of points in convex hull
+
+ intpair_t ip;
+ intpair_t *pairs = NULL;
+ int pairs_size = 0;
+ int pairs_capacity = 32; // Initial capacity of the dynamic array
+ int j;
+
+ // Allocate initial memory for the pairs array
+ pairs = (intpair_t *)malloc(pairs_capacity * sizeof(intpair_t));
+ if (pairs == NULL) {
+ continue; // Skip this label if memory allocation fails
+ }
+
+ if (startPos != 0) {
+ lbl = plbl[startPos];
+ pout[startPos] = 9; // mark pixel as border
+ pos = startPos;
+
+ // Trace around the neighborhood
+ while(1) {
+ checkPosition = pos + neighborhood[checkLocationNr-1][0];
+ newCheckLocationNr = neighborhood[checkLocationNr-1][1];
+
+ if (plbl[checkPosition] == lbl) { // Next border point found
+ if (checkPosition == startPos) {
+ pout[pos] = checkLocationNr; // direction of next border point
+
+ // set to 9 if point of change of direction
+ if (checkLocationNr != prevCheckLocationNr) {
+ pout[pos] = 9;
+ pout[checkPosition] = 9;
+ prevCheckLocationNr = checkLocationNr;
+ ip.a = pos % nx; // x coor
+ ip.b = pos / nx; // y coor
+
+ // Add point to the pairs array, resize if needed
+ if (n >= pairs_capacity) {
+ pairs_capacity *= 2;
+ intpair_t *temp = (intpair_t *)realloc(pairs, pairs_capacity * sizeof(intpair_t));
+ if (temp == NULL) {
+ free(pairs);
+ break; // Memory allocation failed
+ }
+ pairs = temp;
+ }
+ pairs[n++] = ip;
+ }
+
+ counter++;
+ // Stopping criterion (jacob)
+ if (newCheckLocationNr == 1 || counter >= 1) { // Close loop
+ break;
+ }
+ }
+ pout[pos] = checkLocationNr; // direction of next border point
+
+ // set to 9 if point of change of direction
+ if (checkLocationNr != prevCheckLocationNr) {
+ pout[pos] = 9;
+ pout[checkPosition] = 9;
+ prevCheckLocationNr = checkLocationNr;
+ ip.a = pos % nx; // x coor
+ ip.b = pos / nx; // y coor
+
+ // Add point to the pairs array, resize if needed
+ if (n >= pairs_capacity) {
+ pairs_capacity *= 2;
+ intpair_t *temp = (intpair_t *)realloc(pairs, pairs_capacity * sizeof(intpair_t));
+ if (temp == NULL) {
+ free(pairs);
+ break; // Memory allocation failed
+ }
+ pairs = temp;
+ }
+ pairs[n++] = ip;
+ }
+
+ checkLocationNr = newCheckLocationNr; // Update which neighborhood position we should check next
+ pos = checkPosition;
+ counter2 = 0; // Reset the counter that keeps track of how many neighbors we have visited
+ } else {
+ // Rotate clockwise in the neighborhood
+ checkLocationNr = 1 + (checkLocationNr % graph);
+ if (counter2 > graph) {
+ // If counter2 is above graph we have traced around the neighborhood and
+ // therefore the border is a single black pixel and we can exit
+ counter2 = 0;
+ ip.a = pos % nx; // x coor
+ ip.b = pos / nx; // y coor
+
+ // Add point to the pairs array, resize if needed
+ if (n >= pairs_capacity) {
+ pairs_capacity *= 2;
+ intpair_t *temp = (intpair_t *)realloc(pairs, pairs_capacity * sizeof(intpair_t));
+ if (temp == NULL) {
+ free(pairs);
+ break; // Memory allocation failed
+ }
+ pairs = temp;
+ }
+ pairs[n++] = ip;
+ break;
+ } else {
+ counter2++;
+ }
+ }
+ }
+
+ if (n > 0) {
+ // Allocate memory for the hull
+ intpair_t *hull = (intpair_t *)calloc((size_t)n+1, sizeof(intpair_t));
+ if (hull == NULL) {
+ fprintf(stderr, "Cannot allocate %lu bytes for point array in convex hull computation of lbl=%u\n",
+ (unsigned long)(n+1)*sizeof(intpair_t), lbl);
+ free(pairs);
+ continue;
+ }
+
+ // Compute the convex hull
+ nh = chainHull_2D(pairs, n, hull);
+
+ // Mark the hull points in the output image
+ for (j = 0; j < nh; j++) {
+ pout[hull[j].a + hull[j].b * nx] = 10;
+ }
+
+ free(hull);
+ }
+
+ free(pairs);
+ } // startPos != 0
+ } // for each label
+
+ free_image(lut);
+ return imout;
+}
+#undef MY_LUT_TYPE
+#undef t_MY_LUT_TYPE
+#include "u32_undef.h"
+
+// chull: use outercontour name for convenience in developing
+IMAGE *chull(IMAGE *ilbl, int graph) {
+ switch (GetImDataType(ilbl)) {
+
+ case t_UINT32:
+ return u32_chull(ilbl, graph);
+ break;
+
+ default:
+ fprintf(stderr, "ERROR in chull(IMAGE *ilbl, int graph): invalid ImDataType\n");
+ return(NULL);
+ }
+}
=====================================
core/c/myhull.cc deleted
=====================================
@@ -1,351 +0,0 @@
-/***********************************************************************
-Author(s): Pierre Soille
- Pieter Kempeneers (repaced ut_vector with std::vector and
- re-implemented chainHull_2D for license)
-Copyright (C) 2010-2024 European Union (Joint Research Centre)
-
-This file is part of miallib.
-
-miallib is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-miallib is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with miallib. If not, see <https://www.gnu.org/licenses/>.
-***********************************************************************/
-
-/* first 20101004 for convex hull and enclosing rectangle for building detection */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <vector>
-#include <string>
-#include <algorithm>
-#include <iostream>
-
-#include "myhull.h"
-extern "C" {
-#include "miallib.h"
-#include "fifo.h"
-}
-#ifdef OPENMP
-#include <omp.h>
-#endif
-
-// Function to find the convex hull using Andrew's monotone chain algorithm
-std::vector<intpair_t> chainHull_2D(std::vector<intpair_t>& points){
- std::sort(points.begin(), points.end(), [](const intpair_t& a, const intpair_t& b) {
- return a.a < b.a || (a.a == b.a && a.b < b.b);
- });
-
- auto orientation = [](intpair_t p, intpair_t q, intpair_t r){
- return (q.b - p.b) * (r.a - q.a) - (q.a - p.a) * (r.b - q.b);
- };
-
- std::vector<intpair_t> hull;
-
- // Build lower hull
- for (const intpair_t& p : points){
- while (hull.size() >= 2 && orientation(hull[hull.size() - 2], hull[hull.size() - 1], p) <= 0){
- hull.pop_back();
- }
- hull.push_back(p);
- }
-
- // Build upper hull
- for (int i = points.size() - 2, t = hull.size() + 1; i >= 0; i--){
- const intpair_t& p = points[i];
- while (hull.size() >= t && orientation(hull[hull.size() - 2], hull[hull.size() - 1], p) <= 0){
- hull.pop_back();
- }
- hull.push_back(p);
- }
-
- // Remove duplicates from hull
- hull.pop_back();
-
- return hull;
-}
-
-
-// #include <utarray.h>
-
-int intsort(const void *a,const void*b) {
- int _a = *(int*)a;
- int _b = *(int*)b;
- return _a - _b;
-}
-
-// int intpairsort(const void *a,const void*b) {
-// intpair_t _a = *(intpair_t*)a;
-// intpair_t _b = *(intpair_t*)b;
-// return _a.a < _b.a || (_a.a == _b.a && _a.b < _b.b);
-// }
-
-// extern double polygonArea(intpair_t *P, int points);
-// extern int chainHull_2D( intpair_t * P, int n, intpair_t * H );
-
-
-/** \addtogroup group_opclo
- * @{
- */
-
-
-#include "u32_def.h"
-#define MY_LUT_TYPE UINT32
-#define t_MY_LUT_TYPE t_UINT32
-IMAGE *u32_chull(IMAGE *ilbl, int graph)
-{
-
- /* Processing based on contour representation:
- only points with change of direction are kept.
- Use MSB for flagging.
- assumes border is set to zero to avoid border overflow.
- Pierre Soille
- First 20100930 (for building footprint characterisation)
- Pieter Kempeneers 13/09/2024: replace utarray with c++ std::vector
- and reimplement hull for license issue
-
- based on Moore's contour tracing algorithm with Jacob's condition, see
- http://www.thebigblob.com/moore-neighbor-contour-tracing-algorithm-in-c/
- by Erik Smistad (see local file moore_tracing.c)
- extended for label images as well as omp speed-up and graph.
- Also, speed-up since I start always from ulcx!
- Additional image not actually necessary (coding in MSB is enough)
- but used to return an image with mask of outer edge pixels set to 1 (others to 0).
- */
- G_TYPE *pg;
- IMAGE *lut;
- MY_LUT_TYPE *plut;
- PIX_TYPE *plbl, maxlbl, lbl;
- IMAGE *imout;
- UCHAR *pout;
- int nx=GetImNx(ilbl);
- long int i, npix, pos; // openMP requires signed loop index
-
- // Defines the neighborhood offset position from current position and the neighborhood
- // position we want to check next if we find a new border at checkLocationNr
- // 1 2 3
- // 0 x 4
- // 7 6 5
- int neighborhood[8][2] = {
- {-1,7}, // red
- {-1-nx,7}, // green
- {-nx,1}, // blue
- {-nx+1,1}, // yellow
- {1,3}, // magenta
- {1+nx,3}, // cyan
- {nx,5}, // white
- {nx-1,5} // grey
- };
-
- if (graph!=8)
- graph=4;
- if (graph==4){
- // - 1 -
- // 0 x 2
- // - 3 -
- neighborhood[0][0] = -1; // red
- neighborhood[0][1] = 4;
- neighborhood[1][0] = -nx; // green
- neighborhood[1][1] = 1;
- neighborhood[2][0] = 1; // blue
- neighborhood[2][1] = 2;
- neighborhood[3][0] = nx; // yellow
- neighborhood[3][1] = 3;
- }
-
- imout=(IMAGE *)create_image(t_UCHAR, GetImNx(ilbl), GetImNy(ilbl), 1);
- if (imout==NULL)
- return NULL;
-
- /* get min & max values */
- pg = min_max(ilbl);
- if (pg == NULL)
- return(NULL);
- maxlbl = pg[1].u32_val;
- free((char *)pg);
-
- lut= (IMAGE *)create_image(t_MY_LUT_TYPE, maxlbl+1, 1, 1);
- if (lut==NULL){
- free_image(imout);
- return NULL;
- }
- plut =(MY_LUT_TYPE *)GetImPtr(lut);
- plbl =(PIX_TYPE *)GetImPtr(ilbl);
- pout =(UCHAR *)GetImPtr(imout);
- npix =GetImNPix(ilbl);
-
- plut[0]=1; // dummy value to speed-up next loop
- /* first collect first point of each CC in an array
- for subsequent parallel processing */
- for (i=0;i<npix;i++){
- if (plut[plbl[i]]==0){
- plut[plbl[i]]=i;
- }
- }
-
- /* process one cc at a time */
-#ifdef OPENMP
-#pragma omp parallel for private(lbl, pos)
-#endif
- for (i=1; i<=maxlbl; i++){ // lbl==0 for background or border
- int checkLocationNr = 1;// The neighbor number of the location we want to check for a
- // new border point
- int checkPosition; // The corresponding absolute array address of checkLocationNr
- int newCheckLocationNr; // Variable that holds the neighborhood position we want to
- // check if we find a new border at checkLocationNr
- long int startPos = plut[i]; // Set start position
- int counter = 0; // Counter is used for the jacobi stop criterion
- int counter2 = 0; // Counter2 is used to determine if the point we have discovered
- // is one single point
- int prevCheckLocationNr = 9; // init with dummy direction
- int n = 0; // number of points with change of direction
- int nh = 0; // number of points in convex hull
-
- // UT_array *pairs;
- // UT_icd intpair_icd = {sizeof(intpair_t), NULL, NULL, NULL};
- // intpair_t ip, *ph, *phori;
- intpair_t ip;
- std::vector<intpair_t> ph;
- int j;
-
- // utarray_new(pairs,&intpair_icd);
- std::vector<intpair_t> pairs;
- // utarray_new(pairs,&intpair_icd);
-
- if (startPos!=0){
- lbl=plbl[startPos];
- //IFMSB plbl[startPos]|=PIX_MSB; // mark pixel as border
- pout[startPos]=9; // mark pixel as border
- pos=startPos;
-
- // Trace around the neighborhood
- while(1){
- checkPosition = pos + neighborhood[checkLocationNr-1][0];
- newCheckLocationNr = neighborhood[checkLocationNr-1][1];
-
- if( plbl[checkPosition] == lbl) { // Next border point found
- if(checkPosition == startPos){
-
- pout[pos]=checkLocationNr; // direction of next border point
-
- // set to 9 if point of change of direction
- if (checkLocationNr!=prevCheckLocationNr){
- pout[pos]=9;
- pout[checkPosition]=9;
- prevCheckLocationNr=checkLocationNr;
- ip.a=pos%nx; // x coor
- ip.b=pos/nx; // y coor
- pairs.push_back(ip);
- // utarray_push_back(pairs, &ip);
- n++;
- }
-
- counter ++;
- // Stopping criterion (jacob)
- if(newCheckLocationNr == 1 || counter >= 1) { // Close loop
- break;
- }
- }
- pout[pos]=checkLocationNr; // direction of next border point
-
- // set to 9 if point of change of direction
- if (checkLocationNr!=prevCheckLocationNr){
- pout[pos]=9;
- pout[checkPosition]=9;
- prevCheckLocationNr=checkLocationNr;
- ip.a=pos%nx; // x coor
- ip.b=pos/nx; // y coor
- pairs.push_back(ip);
- // utarray_push_back(pairs, &ip);
- n++;
- }
-
- checkLocationNr = newCheckLocationNr;// Update which neighborhood position we should check next
- pos = checkPosition;
- counter2 = 0; // Reset the counter that keeps track of how many neighbors we have visited
- }
- else{
- // Rotate clockwise in the neighborhood
- checkLocationNr = 1 + (checkLocationNr % graph);
- if(counter2 > graph){
- // If counter2 is above 8 we have traced around the neighborhood and
- // therefore the border is a single black pixel and we can exit
- counter2 = 0;
- ip.a=pos%nx; // x coor
- ip.b=pos/nx; // y coor
- pairs.push_back(ip);
- // utarray_push_back(pairs, &ip);
- n++;
- break;
- }
- else{
- counter2 ++;
- }
- }
- }
- //printf("n=%d\n", n);
-
- // ph=phori=(intpair_t *)calloc((size_t) n+1, sizeof(intpair_t));
- ph.resize(n+1);
-
- // if (ph==NULL){
- // printf("cannot allocate %ld bytes for point array in convex hull computation of lbl=%ud\n", \
- // (n+1)*sizeof(intpair_t), lbl);
- // utarray_free(pairs);
- // continue;
- // }
- // utarray_sort(pairs, &intpairsort);
- // nh=chainHull_2D( (intpair_t *)utarray_eltptr(pairs, 0), n, ph );
-
- ph = chainHull_2D(pairs);
- //printf("nh=%d\n", nh);
-
- for (auto it = ph.begin(); it!=ph.end(); ++it)
- pout[it->a + it->b *nx] = 10;
-
- // for(j=0; j<nh; j++)
- // pout[ph[j].a + ph[j].b * nx]=10;
-
- // free(phori);
-
- // utarray_free(pairs);
- } // startPos != 0
- } // for each label
- free_image(lut);
-
- return imout;
-}
-#undef MY_LUT_TYPE
-#undef t_MY_LUT_TYPE
-#include "u32_undef.h"
-
-
-
-// chull: use outercontour name for convenience in developing
-IMAGE *chull(IMAGE *ilbl, int graph)
-{
- switch (GetImDataType(ilbl)){
-
- case t_UINT32:
- return u32_chull(ilbl, graph);
- break;
-
- default:
- std::cerr << "ERROR in chull chull(IMAGE *ilbl, int graph): invalid ImDataType" << std::endl;
- // (void)sprintf(buf, "ERROR in chull(IMAGE *ilbl, int graph): \
- // invalid ImDataType\n"); errputstr(buf);
- return(NULL);
- }
-}
-
-
-/*@}*/
=====================================
core/c/myhull.h
=====================================
@@ -1,5 +1,6 @@
/***********************************************************************
Author(s): Pieter Kempeneers
+ Francesco Lovergine <autobot at lovergine.com>
Copyright (C) 2000-2024 European Union (Joint Research Centre)
This file is part of miallib.
@@ -19,20 +20,31 @@ along with miallib. If not, see <https://www.gnu.org/licenses/>.
***********************************************************************/
/*
-** Header file for myhull.cc
+** Header file for myhull.c
*/
#ifndef _MYHULL_H
#define _MYHULL_H
-#include <vector>
-
/* for point with integer coordinates */
typedef struct {
int a;
int b;
} intpair_t;
-std::vector<intpair_t> chainHull_2D(std::vector<intpair_t>& points);
-
-#endif /* _MYHULL_H */
\ No newline at end of file
+/* Function to find the convex hull using Andrew's monotone chain algorithm
+ * points: array of input points
+ * n: number of input points
+ * hull: pre-allocated array to store the resulting hull points (should be at least n+1 in size)
+ * returns: number of points in the hull
+ */
+int chainHull_2D(intpair_t *points, int n, intpair_t *hull);
+
+/* Compute convex hull of an image with labels
+ * ilbl: input labeled image
+ * graph: connectivity (4 or 8)
+ * returns: image with hull points marked
+ */
+IMAGE *chull(IMAGE *ilbl, int graph);
+
+#endif /* _MYHULL_H */
=====================================
core/c/registration.c
=====================================
@@ -61,7 +61,7 @@ IMAGE *uc_ssda(IMAGE *imin, IMAGE *imt, int xi, int yi, int w)
/* check w leads to windows falling in imin */
if( (xi-(wd2+nxtd2)<0) || (xi+(wd2+nxtd2)>=nxi) || \
(yi-(wd2+nytd2)<0) || (yi+(wd2+nytd2)>=nyi) ){
- (void)sprintf(buf,"*ssda(): lead to a window falling outside imin defintion domain\n"); errputstr(buf);
+ (void)sprintf(buf,"*ssda(): lead to a window falling outside imin definition domain\n"); errputstr(buf);
return NULL;
}
@@ -141,7 +141,7 @@ IMAGE *us_ssda(IMAGE *imin, IMAGE *imt, int xi, int yi, int w)
/* check w leads to windows falling in imin */
if( (xi-(wd2+nxtd2)<0) || (xi+(wd2+nxtd2)>=nxi) || \
(yi-(wd2+nytd2)<0) || (yi+(wd2+nytd2)>=nyi) ){
- (void)sprintf(buf,"*ssda(): lead to a window falling outside imin defintion domain\n"); errputstr(buf);
+ (void)sprintf(buf,"*ssda(): lead to a window falling outside imin definition domain\n"); errputstr(buf);
return NULL;
}
@@ -248,7 +248,7 @@ IMAGE *uc_ncclewis(IMAGE *imin, IMAGE *imt, IMAGE *sim, IMAGE *ssqim, int xi, in
/* check w leads to windows falling in imin */
if( (xi-(wd2+nxtd2)<0) || (xi+(wd2+nxtd2)>=nxi) || \
(yi-(wd2+nytd2)<0) || (yi+(wd2+nytd2)>=nyi) ){
- (void)sprintf(buf,"*ncc(): lead to a window falling outside imin defintion domain\n"); errputstr(buf);
+ (void)sprintf(buf,"*ncc(): lead to a window falling outside imin definition domain\n"); errputstr(buf);
return NULL;
}
@@ -386,7 +386,7 @@ IMAGE *uc_ncc(IMAGE *imin, IMAGE *imt, int xi, int yi, int w)
/* check w leads to windows falling in imin */
if( (xi-(wd2+nxtd2)<0) || (xi+(wd2+nxtd2)>=nxi) || \
(yi-(wd2+nytd2)<0) || (yi+(wd2+nytd2)>=nyi) ){
- (void)sprintf(buf,"*ncc(): lead to a window falling outside imin defintion domain\n"); errputstr(buf);
+ (void)sprintf(buf,"*ncc(): lead to a window falling outside imin definition domain\n"); errputstr(buf);
return NULL;
}
@@ -482,7 +482,7 @@ IMAGE *us_ncc(IMAGE *imin, IMAGE *imt, int xi, int yi, int w)
/* check w leads to windows falling in imin */
if( (xi-(wd2+nxtd2)<0) || (xi+(wd2+nxtd2)>=nxi) || \
(yi-(wd2+nytd2)<0) || (yi+(wd2+nytd2)>=nyi) ){
- (void)sprintf(buf,"*ncc(): lead to a window falling outside imin defintion domain\n"); errputstr(buf);
+ (void)sprintf(buf,"*ncc(): lead to a window falling outside imin definition domain\n"); errputstr(buf);
return NULL;
}
=====================================
core/c/setreg.c
=====================================
@@ -34,9 +34,9 @@ along with miallib. If not, see <https://www.gnu.org/licenses/>.
*/
extern int cluster();
-extern ERROR_TYPE agglo_cluster();
-extern ERROR_TYPE nearest_cluster();
-extern ERROR_TYPE knearest_cluster();
+extern ERROR_TYPE agglo_cluster(int *x, int *y, int *pn, double maxdst);
+extern ERROR_TYPE nearest_cluster(IMAGE *im, int *x, int *y, int *pn, double maxdst);
+extern ERROR_TYPE knearest_cluster(IMAGE *im, int *x, int *y, int *pn, int k, double maxdst);
#define set_mean_type(TYPE1, TYPE2, i1, i2) \
{\
@@ -162,7 +162,7 @@ extern ERROR_TYPE knearest_cluster();
} \
}
-extern IMBLOB *create_blob();
+extern IMBLOB *create_blob(LBL_TYPE n);
=====================================
core/c/uswilk.c
=====================================
@@ -1505,7 +1505,7 @@ int MAXROIVAL = 65534; /* pixels outside ROI should be at 255,
int OUTROI = 65535;
-extern ERROR_TYPE set_seq_shift();
+extern ERROR_TYPE set_seq_shift(long int , long int , long int , long int , long int *);
void GreyAttributeClosingROI ( double lambdaVal, /* threshold on attribute */
int width, /* image width */
View it on GitLab: https://salsa.debian.org/debian-gis-team/jeolib-miallib/-/commit/e0792e764d4bcb09afe072828f93650546fe38e6
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/jeolib-miallib/-/commit/e0792e764d4bcb09afe072828f93650546fe38e6
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20251025/262964cd/attachment-0001.htm>
More information about the Pkg-grass-devel
mailing list