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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 2 00:51:10 PDT 2013


Author: martinl
Date: 2013-06-02 00:51:10 -0700 (Sun, 02 Jun 2013)
New Revision: 56546

Modified:
   sandbox/martinl/v.ten/main.cpp
   sandbox/martinl/v.ten/write.cpp
Log:
v.ten: write faces by default


Modified: sandbox/martinl/v.ten/main.cpp
===================================================================
--- sandbox/martinl/v.ten/main.cpp	2013-06-02 00:07:36 UTC (rev 56545)
+++ sandbox/martinl/v.ten/main.cpp	2013-06-02 07:51:10 UTC (rev 56546)
@@ -53,7 +53,7 @@
     if (flag.line->answer)
 	type = GV_LINE;
     else
-	type = GV_BOUNDARY;
+	type = GV_FACE;
 
     /* open input map */
     Vect_open_old2(&In, opt.input->answer, "", opt.field->answer);
@@ -84,7 +84,7 @@
     
     G_message(_("Number of vertices: %d"), nvertices);
     G_message(_("Number of edges: %d"), T.number_of_edges());
-    G_message(_("Number of faces: %d"), T.number_of_facets());
+    G_message(_("Number of triangles: %d"), T.number_of_facets());
     G_message(_("Number of tetrahedrons: %d"), T.number_of_cells());
     
     G_message(_("Writing output features..."));

Modified: sandbox/martinl/v.ten/write.cpp
===================================================================
--- sandbox/martinl/v.ten/write.cpp	2013-06-02 00:07:36 UTC (rev 56545)
+++ sandbox/martinl/v.ten/write.cpp	2013-06-02 07:51:10 UTC (rev 56546)
@@ -5,33 +5,53 @@
 
 #include "local_proto.h"
 
-void write_lines(struct Map_info *Out, int do_lines, const Triangulation &T)
+void write_lines(struct Map_info *Out, int type, const Triangulation &T)
 {
-     Triangulation::Finite_edges_iterator eit;
-     Point pt1, pt2;
-     
-     struct line_pnts *Points;
-     
-     Points = Vect_new_line_struct();
-     
-     if (do_lines) {
-         /* write edges as lines */
-         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(),
-                     pt2.x(), pt2.y(), pt2.z());
-             
-             Vect_reset_line(Points);
-             Vect_append_point(Points, pt1.x(), pt1.y(), pt1.z());
-             Vect_append_point(Points, pt2.x(), pt2.y(), pt2.z());
-             
-             Vect_write_line(Out, GV_LINE, Points, NULL);
-         }
-     }
-     else {
-         /* TODO */
-     }
+    struct line_pnts *Points;
+    
+    Points = Vect_new_line_struct();
+    
+    if (type == GV_LINE) {
+        Triangulation::Finite_edges_iterator eit;
+        Point pt1, pt2;
+        
+        /* write edges as lines */
+        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(),
+                    pt2.x(), pt2.y(), pt2.z());
+            
+            Vect_reset_line(Points);
+            Vect_append_point(Points, pt1.x(), pt1.y(), pt1.z());
+            Vect_append_point(Points, pt2.x(), pt2.y(), pt2.z());
+            
+            Vect_write_line(Out, type, Points, NULL);
+        }
+    }
+    else {
+        int k;
+        Triangulation::Finite_facets_iterator fit;
+        Point pt1, pt2, pt3;
+        
+        /* write edges as lines */
+        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();
+            pt3 = fit->first->vertex((fit->second + (k++)) % 4)->point();
 
-     Vect_destroy_line_struct(Points);
+            G_debug(3, "facet: %f %f %f | %f %f %f | %f %f %f", pt1.x(), pt1.y(), pt1.z(),
+                    pt2.x(), pt2.y(), pt2.z(), pt3.x(), pt3.y(), pt3.z());
+
+            Vect_reset_line(Points);
+            Vect_append_point(Points, pt1.x(), pt1.y(), pt1.z());
+            Vect_append_point(Points, pt2.x(), pt2.y(), pt2.z());
+            Vect_append_point(Points, pt3.x(), pt3.y(), pt3.z());
+            
+            Vect_write_line(Out, type, Points, NULL);
+        }
+    }
+    
+    Vect_destroy_line_struct(Points);
 }



More information about the grass-commit mailing list