[GRASS-SVN] r65500 - grass-addons/grass7/vector/v.nnstat
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jun 20 02:32:40 PDT 2015
Author: evas
Date: 2015-06-20 02:32:39 -0700 (Sat, 20 Jun 2015)
New Revision: 65500
Added:
grass-addons/grass7/vector/v.nnstat/main.c
Modified:
grass-addons/grass7/vector/v.nnstat/Makefile
grass-addons/grass7/vector/v.nnstat/hull.h
grass-addons/grass7/vector/v.nnstat/local_proto.h
grass-addons/grass7/vector/v.nnstat/mbb.h
grass-addons/grass7/vector/v.nnstat/v.nnstat.html
Log:
v.nnstat: kd-tree (PCL library) replaced by R-tree (GRASS GIS)
Modified: grass-addons/grass7/vector/v.nnstat/Makefile
===================================================================
--- grass-addons/grass7/vector/v.nnstat/Makefile 2015-06-18 19:00:26 UTC (rev 65499)
+++ grass-addons/grass7/vector/v.nnstat/Makefile 2015-06-20 09:32:39 UTC (rev 65500)
@@ -2,9 +2,9 @@
PGM = v.nnstat
-LIBES = $(VECTORLIB) $(DBMILIB) $(GISLIB) $(GMATHLIB) $(IOSTREAMLIB) $(MATHLIB) -lpcl_common -lpcl_features -lpcl_filters -lpcl_io -lpcl_kdtree -lpcl_keypoints -lpcl_octree -lpcl_registration -lpcl_sample_consensus -lpcl_search -lpcl_segmentation -lpcl_surface -lpcl_visualization
-DEPENDENCIES= $(VECTORDEP) $(DBMIDEP) $(GISDEP) $(IOSTREAMDEP)
-EXTRA_INC = $(VECT_INC) -I/usr/include/pcl-1.7 -I/usr/include/eigen3 $(PCL_INCLUDE_DIRS)
+LIBES = $(VECTORLIB) $(DBMILIB) $(GISLIB) $(GMATHLIB) $(IOSTREAMLIB) $(MATHLIB) $(RTREELIB)
+DEPENDENCIES= $(VECTORDEP) $(DBMIDEP) $(GISDEP) $(IOSTREAMDEP) $(RTREEDEP)
+EXTRA_INC = $(VECT_INC)
EXTRA_CFLAGS = $(VECT_CFLAGS)
include $(MODULE_TOPDIR)/include/Make/Module.make
Modified: grass-addons/grass7/vector/v.nnstat/hull.h
===================================================================
--- grass-addons/grass7/vector/v.nnstat/hull.h 2015-06-18 19:00:26 UTC (rev 65499)
+++ grass-addons/grass7/vector/v.nnstat/hull.h 2015-06-20 09:32:39 UTC (rev 65500)
@@ -1,6 +1,4 @@
-extern "C" {
#include <grass/vector.h>
-}
#define ALLOC_CHUNK 256
Modified: grass-addons/grass7/vector/v.nnstat/local_proto.h
===================================================================
--- grass-addons/grass7/vector/v.nnstat/local_proto.h 2015-06-18 19:00:26 UTC (rev 65499)
+++ grass-addons/grass7/vector/v.nnstat/local_proto.h 2015-06-20 09:32:39 UTC (rev 65500)
@@ -6,10 +6,6 @@
#include <string.h>
#include <math.h>
-#include <pcl/point_cloud.h>
-#include <pcl/kdtree/impl/kdtree_flann.hpp>
-
-extern "C" {
#include <grass/vector.h>
#include <grass/dbmi.h>
#include <grass/config.h>
@@ -17,10 +13,9 @@
#include <grass/gmath.h>
#include <grass/la.h>
#include <grass/glocale.h>
-} // end extern "C"
+#include <grass/rtree.h>
-#include <iostream>
-#include <vector>
+#include "hull.h"
#ifndef MAX
#define MIN(a,b) ((a<b) ? a : b)
@@ -33,54 +28,61 @@
struct points
{
- int n;
- double *r; // xyz
- double *r_min; // min coords
- double *r_max; // max coords
+ int n; // # of input points
+ double *r; // coordinates of input points
+ struct RTree *R_tree; // spatial index
+ double *r_min; // minimum coordinates
+ double *r_max; // maximum coordinates
+ double max_dist; // maximum distance
};
struct nna_par
{
- int i3; // TRUE = 3D NNA, FALSE = 2D NNA (user sets by flag)
- char v3; // TRUE = 3D layer, FALSE = 2D layer (according to Vect_is_3d())
- char *zcol; // not NULL if 3D NNA using 2D layer is required
+ int i3; // TRUE = 3D NNA, FALSE = 2D NNA (user sets by flag)
+ char v3; // TRUE = 3D layer, FALSE = 2D layer (according to Vect_is_3d())
+ char *zcol; // not NULL if 3D NNA using 2D layer is required
};
struct convex
{
- int n; // number of hull vertices
- int n_faces; // number of hull faces
+ int n; // # of hull vertices
+ int n_faces; // # of hull faces
int *hull;
- double *coord; // coordinates of faces
- double *faces; // coordinates of vertices
+ double *coord; // coordinates of faces
+ double *faces; // coordinates of vertices
};
struct nearest
{
- double A;
- double rho;
- double rA;
- double rE;
- double R;
- double c;
+ double A; // area/volume for density of input points calculation
+ double rho; // density of the input points
+ double rA; // real average distance of the NN
+ double rE; // expected average distance of the NN
+ double R; // ratio of real and expected average distance of the NN
+ double c; // test statistics
};
-extern "C" {
- double *get_col_values(struct Map_info *, int, const char *);
- void read_points(struct Map_info *, int, struct nna_par *, const char *, struct points *);
- double *triple(double, double, double);
+double *get_col_values(struct Map_info *, int, const char *);
+void read_points(struct Map_info *, int, struct nna_par *, const char *, struct points *);
+double *triple(double, double, double);
+
+struct RTree *create_spatial_index(struct nna_par *);
+void insert_rectangle(int, int, struct points *);
+struct ilist *spatial_search(int, int, struct points *, double);
+struct ilist *find_NNs(int, int, struct points *);
+double sum_NN(int, int, struct ilist *, struct points *);
- double bearing(double, double, double, double);
- double distance(double, double);
- int convexHull(struct points *, struct convex *);
- int make3DHull(struct points *, struct convex *);
- void convexHull3d(struct points *, struct convex *);
- double MBR(struct points *);
- double MBB(struct points *);
- int nn_average_distance_real(struct points *, struct nearest *);
- void density(struct points *, struct nna_par *, const char *, struct nearest *);
- void nn_average_distance_expected(struct nna_par *, struct nearest *);
- void nn_results(struct points *, struct nna_par *, struct nearest *);
- void nn_statistics(struct points *, struct nna_par *, struct nearest *);
-} // end extern "C"
+double bearing(double, double, double, double);
+double distance(double, double);
+int cmpVals(const void *, const void *);
+int convexHull(struct points *, struct convex *);
+int make3DHull(struct points *, struct convex *);
+void convexHull3d(struct points *, struct convex *);
+double MBR(struct points *);
+double MBB(struct points *);
+void nn_average_distance_real(struct nna_par *, struct points *, struct nearest *);
+void density(struct points *, struct nna_par *, const char *, struct nearest *);
+void nn_average_distance_expected(struct nna_par *, struct nearest *);
+void nn_results(struct points *, struct nna_par *, struct nearest *);
+void nn_statistics(struct points *, struct nna_par *, struct nearest *);
#endif
Added: grass-addons/grass7/vector/v.nnstat/main.c
===================================================================
--- grass-addons/grass7/vector/v.nnstat/main.c (rev 0)
+++ grass-addons/grass7/vector/v.nnstat/main.c 2015-06-20 09:32:39 UTC (rev 65500)
@@ -0,0 +1,116 @@
+
+/****************************************************************
+ *
+ * MODULE: v.nnstat
+ *
+ * AUTHOR(S): Eva Stopková
+ * functions in files mbr.cpp and mbb.cpp are mostly taken
+ * from the module
+ * v.hull (Aime, A., Neteler, M., Ducke, B., Landa, M.)
+ *
+ * PURPOSE: Module indicates clusters, separations or random distribution of point set in 2D or 3D space.
+ *
+ * COPYRIGHT: (C) 2013-2014 by Eva Stopková and the GRASS Development Team
+ *
+ * This program is free software under the
+ * GNU General Public License (>=v2).
+ * Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ **************************************************************/
+#include "local_proto.h"
+
+int main(int argc, char *argv[])
+{
+ /* Vector layer and module */
+ struct Map_info map; // input vector map
+ struct GModule *module;
+ struct nna_par xD; // 2D or 3D NNA to be performed
+ struct points pnts; // points: coordinates, number etc.
+
+ struct nearest nna; // structure to save results
+ int field, pass;
+
+ struct {
+ struct Option *map, *A, *type, *field, *lyr, *desc, *zcol; /* A - area (minimum enclosing rectangle or specified by user) */
+ } opt;
+
+ struct {
+ struct Flag *d23;
+ } flg;
+
+ int i;
+ FILE *fp;
+ double *dist_comp;
+ double *d;
+
+ /* Module creation */
+ module = G_define_module();
+ G_add_keyword(_("vector"));
+ G_add_keyword(_("nearest neighbour analysis"));
+ module->description = _("Indicates clusters, separations or random distribution of point set in 2D or 3D space.");
+
+ /* Setting options */
+ opt.map = G_define_standard_option(G_OPT_V_INPUT); // vector input layer
+
+ flg.d23 = G_define_flag(); // to process 2D or 3D Nearest Neighbour Analysis
+ flg.d23->key = '2';
+ flg.d23->description =
+ _("Force 2D NNA even if input is 3D");
+
+ opt.A = G_define_option();
+ opt.A->key = "area";
+ opt.A->type = TYPE_DOUBLE;
+ opt.A->description = _("2D: Area. If not specified, area of Minimum Enclosing Rectangle will be used.\n3D: Volume. If not specified, volume of Minimum Enclosing Box will be used.");
+ opt.A->required = NO;
+
+ opt.field = G_define_standard_option(G_OPT_V_FIELD);
+
+ opt.zcol = G_define_standard_option(G_OPT_DB_COLUMN);
+ opt.zcol->key = "zcolumn";
+ opt.zcol->required = NO;
+ opt.zcol->guisection = _("Fields");
+ opt.zcol->description = _("Column with z coordinate (set for 2D vectors only if 3D NNA is required to be performed)");
+
+ G_gisinit(argv[0]);
+
+ if (G_parser(argc, argv)) {
+ exit(EXIT_FAILURE);
+ }
+
+ /* get parameters from the parser */
+ field = opt.field->answer ? atoi(opt.field->answer) : -1;
+
+ /* open input vector map */
+ Vect_set_open_level(2);
+
+ if (0 > Vect_open_old2(&map, opt.map->answer, "", opt.field->answer)) {
+ G_fatal_error(_("Unable to open vector map <%s>"), opt.map->answer);
+ }
+ Vect_set_error_handler_io(&map, NULL);
+
+ /* perform 2D or 3D NNA ? */
+ xD.v3 = Vect_is_3d(&map); // test if vector layer is 2D or 3D
+ xD.i3 = (flg.d23->answer || (xD.v3 == FALSE && opt.zcol->answer == NULL)) ? FALSE : TRUE; // if -2 flag or input layer is 2D (without zcolumn), perform 2D NNA, otherwise 3D
+
+ /* Warnings */
+ if (flg.d23->answer && opt.zcol->answer) { // -2 flag (2D) vs. zcolumn (3D)
+ G_warning(_("Flag -2 has higher priority than zcolumn considered in 2D layer. 2D Nearest Neighbour Analysis will be performed instead of 3D. If you wish to perform 3D Nearest Neighbour Analysis, please remove flag -2."));
+ }
+
+ if (xD.v3 == TRUE && opt.zcol->answer) {
+ G_warning(_("Input layer <%s> is 3D - it was not necessary to set up attribute column. 3D Nearest Neighbour Analysis is being performed..."), opt.map->answer);
+ }
+
+ read_points(&map, field, &xD, opt.zcol->answer, &pnts); // read coordinates of the points
+
+ /* Nearest Neighbour Analysis */
+ nn_average_distance_real(&xD, &pnts, &nna); // Average distance (AD) between NN in pointset
+ density(&pnts, &xD, opt.A->answer, &nna); // Number of points per area/volume unit
+ nn_average_distance_expected(&xD, &nna); // Expected AD of NN in a randomly distributed pointset
+ nna.R = nna.rA / nna.rE; // Ratio of real and expected AD
+ nn_statistics(&pnts, &xD, &nna); // Student's t-test of significance of the mean
+
+ Vect_close(&map);
+ exit(EXIT_SUCCESS);
+}
Modified: grass-addons/grass7/vector/v.nnstat/mbb.h
===================================================================
--- grass-addons/grass7/vector/v.nnstat/mbb.h 2015-06-18 19:00:26 UTC (rev 65499)
+++ grass-addons/grass7/vector/v.nnstat/mbb.h 2015-06-20 09:32:39 UTC (rev 65500)
@@ -5,9 +5,8 @@
*/
/* Define Boolean type - not necessary in C++*/
-/*typedef enum
+typedef enum
{ BFALSE, BTRUE } bool;
-*/
/* Define vertex indices. */
#define X 0
@@ -63,7 +62,6 @@
tFace faces = NULL;
/* Function declarations */
-extern "C" {
tVertex MakeNullVertex(void);
void ReadVertices(struct points *);
void writeVertices(struct Map_info *Map);
@@ -82,4 +80,3 @@
void CleanFaces(void);
void CleanVertices(void);
bool Collinear(tVertex a, tVertex b, tVertex c);
-}
Modified: grass-addons/grass7/vector/v.nnstat/v.nnstat.html
===================================================================
--- grass-addons/grass7/vector/v.nnstat/v.nnstat.html 2015-06-18 19:00:26 UTC (rev 65499)
+++ grass-addons/grass7/vector/v.nnstat/v.nnstat.html 2015-06-20 09:32:39 UTC (rev 65500)
@@ -56,6 +56,11 @@
In (<a href="http://geoinformatics.fsv.cvut.cz/pdf/geoinformatics-fce-ctu-2013-11.pdf">Stopkova, 2013</a>), there might be seen other examples (also clustered and dispersed datasets).
</p>
+<h2>TODO</h2>
+<ul>
+<li>add <b>graphical output</b>
+</ul>
+
<h2>SEE ALSO</h2>
<em>
@@ -67,7 +72,6 @@
<li><b>LAPACK / BLAS</b> (libraries for numerical computing) for
GMATH library (GRASS Numerical Library)<br>
<a href="http://www.netlib.org/lapack">http://www.netlib.org/lapack</a> (usually available on Linux distros)
-<li><a href="http://pointclouds.org">Point Cloud Library</a>
</ul>
<h2>AUTHOR</h2>
More information about the grass-commit
mailing list