[GRASS-SVN] r56555 - sandbox/martinl/v.ten

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 2 06:20:20 PDT 2013


Author: martinl
Date: 2013-06-02 06:20:20 -0700 (Sun, 02 Jun 2013)
New Revision: 56555

Modified:
   sandbox/martinl/v.ten/local_proto.h
   sandbox/martinl/v.ten/main.cpp
   sandbox/martinl/v.ten/write.cpp
Log:
v.ten: performs Delaunay triangulation by default


Modified: sandbox/martinl/v.ten/local_proto.h
===================================================================
--- sandbox/martinl/v.ten/local_proto.h	2013-06-02 12:18:18 UTC (rev 56554)
+++ sandbox/martinl/v.ten/local_proto.h	2013-06-02 13:20:20 UTC (rev 56555)
@@ -2,15 +2,17 @@
 
 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
 #include <CGAL/Triangulation_3.h>
+#include <CGAL/Delaunay_triangulation_3.h>
 
 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
 
-typedef CGAL::Triangulation_3<K>      Triangulation;
+typedef CGAL::Triangulation_3<K>           Triangulation;
+typedef CGAL::Delaunay_triangulation_3<K>  DelaunayTriangulation;
 typedef Triangulation::Point          Point;
 
 /* read.cpp */
 int read_points(struct Map_info *, int, std::vector<Point>&);
 
 /* write.cpp */
-void write_lines(struct Map_info *, int, const Triangulation &);
+void write_lines(struct Map_info *, int, const Triangulation *);
 #endif

Modified: sandbox/martinl/v.ten/main.cpp
===================================================================
--- sandbox/martinl/v.ten/main.cpp	2013-06-02 12:18:18 UTC (rev 56554)
+++ sandbox/martinl/v.ten/main.cpp	2013-06-02 13:20:20 UTC (rev 56555)
@@ -1,3 +1,19 @@
+/***************************************************************
+ *
+ * MODULE:       v.delaunay3d
+ *
+ * AUTHOR(S):    Martin Landa <landa.martin gmail.com>
+ *
+ * PURPOSE:      Creates a 3D Delaunay triangulation vector map
+ *
+ * COPYRIGHT:    (C) 2013 by Martin Landa, 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 <cstdlib>
 #include <vector>
 
@@ -20,13 +36,14 @@
         struct Option *input, *field, *output;
     } opt;
     struct {
-        struct Flag *line;
+        struct Flag *line, *plain;
     } flag;
     
     struct Map_info In, Out;
     
     std::vector<Point> points;
-
+    Triangulation *T;
+    
     G_gisinit(argv[0]);
     
     module = G_define_module();
@@ -41,6 +58,11 @@
 
     opt.output = G_define_standard_option(G_OPT_V_OUTPUT);
 
+    flag.plain = G_define_flag();
+    flag.plain->key = 'p';
+    flag.plain->description =
+	_("Perform plain triangulation");
+
     flag.line = G_define_flag();
     flag.line->key = 'l';
     flag.line->description =
@@ -75,17 +97,20 @@
     
     /* do 3D triangulation */
     G_message(_("Creating TEN..."));
-    Triangulation T(points.begin(), points.end());
-
-    nvertices = T.number_of_vertices();
+    if (!flag.plain->answer)
+        T = new DelaunayTriangulation(points.begin(), points.end());
+    else
+        T = new Triangulation(points.begin(), points.end());
+    
+    nvertices = T->number_of_vertices();
     if (nvertices != npoints)
         G_fatal_error(_("Invalid number of vertices %d (%d)"), 
                       nvertices, npoints);
     
     G_message(_("Number of vertices: %d"), nvertices);
-    G_message(_("Number of edges: %d"), T.number_of_finite_edges());
-    G_message(_("Number of triangles: %d"), T.number_of_finite_facets());
-    G_message(_("Number of tetrahedrons: %d"), T.number_of_finite_cells());
+    G_message(_("Number of edges: %d"), T->number_of_finite_edges());
+    G_message(_("Number of triangles: %d"), T->number_of_finite_facets());
+    G_message(_("Number of tetrahedrons: %d"), T->number_of_finite_cells());
     
     G_message(_("Writing output features..."));
 

Modified: sandbox/martinl/v.ten/write.cpp
===================================================================
--- sandbox/martinl/v.ten/write.cpp	2013-06-02 12:18:18 UTC (rev 56554)
+++ sandbox/martinl/v.ten/write.cpp	2013-06-02 13:20:20 UTC (rev 56555)
@@ -5,7 +5,7 @@
 
 #include "local_proto.h"
 
-void write_lines(struct Map_info *Out, int type, const Triangulation &T)
+void write_lines(struct Map_info *Out, int type, const Triangulation *T)
 {
     int line;
     struct line_pnts *Points;
@@ -20,7 +20,7 @@
         Point pt1, pt2;
         
         /* write edges as lines */
-        for (eit = T.finite_edges_begin(); eit != T.finite_edges_end(); ++eit) {
+        for (eit = T->finite_edges_begin(); eit != T->finite_edges_end(); ++eit) {
             pt1 = eit->first->vertex(eit->second)->point();
             pt2 = eit->first->vertex(eit->third)->point();
             G_debug(3, "edge: %f %f %f | %f %f %f", pt1.x(), pt1.y(), pt1.z(),
@@ -42,7 +42,7 @@
         Point pt1, pt2, pt3;
         
         /* write edges as lines */
-        for (fit = T.finite_facets_begin(); fit != T.finite_facets_end(); ++fit) {
+        for (fit = T->finite_facets_begin(); fit != T->finite_facets_end(); ++fit) {
             k = 1;
             pt1 = fit->first->vertex((fit->second + (k++)) % 4)->point();
             pt2 = fit->first->vertex((fit->second + (k++)) % 4)->point();



More information about the grass-commit mailing list