From: Regina Obe Date: Sun, 1 May 2011 02:46:40 +0000 (+0000) Subject: Fix handling of 3d polygons (still doesn't handle holes right), update doc to show... X-Git-Tag: 2.0.0alpha1~1729 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6838d38802812f1fb8679debe9c3af4d70ae8682;p=postgis Fix handling of 3d polygons (still doesn't handle holes right), update doc to show example and also caveats so far, add polygon and polyhedralsurface example to c unit tests git-svn-id: http://svn.osgeo.org/postgis/trunk@7078 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/reference_output.xml b/doc/reference_output.xml index c08521fee..32544e398 100644 --- a/doc/reference_output.xml +++ b/doc/reference_output.xml @@ -871,9 +871,15 @@ SELECT ST_AsGML(3, ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 Description - Returns a geometry as an X3D xml formatted node element http://web3d.org/x3d/specifications/ISO-IEC-19776-1.2-X3DEncodings-XML/Part01/EncodingOfNodes.html. If prec (precision) is not specified then defaults to 15. TINs are modeled as IndexedTriangleSet, MultiPoints as PointSet, LineString As LineSets, Polyhedral surfaces as IndexedFaceSet + Returns a geometry as an X3D xml formatted node element http://web3d.org/x3d/specifications/ISO-IEC-19776-1.2-X3DEncodings-XML/Part01/EncodingOfNodes.html. If prec (precision) is not specified then defaults to 15. + + There are various options for translating PostGIS geometries to X3D since X3D geometry types don't map directly to PostGIS geometry types and some newer X3D types that might be better mappings we ahve avoided since most rendering tools don't currently support them. + These are the mappings we have settled on. Feel free to post a bug ticket if you have thoughts on the idea or ways we can allow people to denote their preferred mappings. + TINs are IndexedTriangleSets. MultiPoints are a PointSets. LineStrings are LineSets. Polyhedral Surfaces, Polygons, and Multipolygon as IndexedFaceSets. + + Using with any 2D geometries or 3D geometries with holes currently results in invalid X3D. We are working on fixing this. Lots of advancements happening in 3D space particularly with X3D Integration with HTML5 - There is also a nice open source X3D viewer you can use to view rendered geometries. Free Wrl http://freewrl.sourceforge.net/ binaries available for Mac, Linux, and Windows. + There is also a nice open source X3D viewer you can use to view rendered geometries. Free Wrl http://freewrl.sourceforge.net/ binaries available for Mac, Linux, and Windows. Use the FreeWRL_Launcher packaged to view the geometries. Availability: 2.0.0: ISO-IEC-19776-1.2-X3DEncodings-XML &Z_support; @@ -886,7 +892,7 @@ SELECT ST_AsGML(3, ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 - Example: Create a fully functional X3D document + Example: Create a fully functional X3D document - This will generate a cube that is viewable in FreeWrl and other X3D viewers. @@ -923,6 +929,21 @@ SELECT ST_AsGML(3, ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 ]]> + + + Example: An Octagon elevated 3 Units and decimal precision of 6 + SELECT ST_AsX3D( +ST_Translate( + ST_Force_3d( + ST_Buffer(ST_Point(10,10),5, 'quad_segs=2')), 0,0, + 3) + ,6) As x3dfrag; + +x3dfrag +-------- + + +]]> Example: TIN diff --git a/liblwgeom/cunit/cu_out_x3d.c b/liblwgeom/cunit/cu_out_x3d.c index 14f26edc1..b5bc82884 100644 --- a/liblwgeom/cunit/cu_out_x3d.c +++ b/liblwgeom/cunit/cu_out_x3d.c @@ -91,16 +91,16 @@ static void out_x3d3_test_geoms(void) "", NULL, 0); - /* TODO: Fix Polygon */ - /** do_x3d3_test( - "POLYGON((0 1 5,2 3 5,4 5 5,0 1 5))", - "0 1 5 2 3 5 4 5 5", - NULL, 0); **/ + /* Polygon **/ + do_x3d3_test( + "POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))", + "", + NULL, 3); /* TODO: Polygon - with internal ring - the answer is clearly wrong */ /** do_x3d3_test( - "POLYGON((0 1 3,2 3 3,4 5 3,0 1 3),(6 7 3,8 9 3,10 11 3,6 7 3))", - "0 1 3 2 3 3 4 5 36 7 3 8 9 3 10 11 3 ", + "POLYGON((0 1 3,2 3 3,4 5 3,0 1 3),(6 7 3,8 9 3,10 11 3,6 7 3))", + "", NULL, 0); **/ /* Multiline */ @@ -114,6 +114,12 @@ static void out_x3d3_test_geoms(void) "MULTIPOLYGON(((0 1 1,2 3 1,4 5 1,0 1 1)),((6 7 1,8 9 1,10 11 1,6 7 1)))", "", NULL, 0); + + /* PolyhedralSurface */ + do_x3d3_test( + "POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)), ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )", + "", + NULL, 0); /* TODO: returns garbage at moment correctly implement GeometryCollection -- */ /** do_x3d3_test( diff --git a/liblwgeom/lwout_x3d.c b/liblwgeom/lwout_x3d.c index e405c9a21..a8b9a4687 100644 --- a/liblwgeom/lwout_x3d.c +++ b/liblwgeom/lwout_x3d.c @@ -61,7 +61,10 @@ lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const cha return asx3d3_line((LWLINE*)geom, srs, precision, opts, defid); case POLYGONTYPE: - return asx3d3_poly((LWPOLY*)geom, srs, precision, opts, 0, defid); + /** We might change this later, but putting a polygon in an indexed face set + * seems like the simplest way to go so treat just like a mulitpolygon + */ + return asx3d3_multi((LWCOLLECTION*)lwgeom_as_multi(geom), srs, precision, opts, defid); case TRIANGLETYPE: return asx3d3_triangle((LWTRIANGLE*)geom, srs, precision, opts, defid); @@ -300,19 +303,6 @@ asx3d3_poly_buf(const LWPOLY *poly, char *srs, char *output, int precision, int return (ptr-output); } -static char * -asx3d3_poly(const LWPOLY *poly, char *srs, int precision, int opts, int is_patch, const char *defid) -{ - char *output; - int size; - - size = asx3d3_poly_size(poly, srs, precision, opts, defid); - output = lwalloc(size); - asx3d3_poly_buf(poly, srs, output, precision, opts, is_patch, defid); - return output; -} - - static size_t asx3d3_triangle_size(const LWTRIANGLE *triangle, char *srs, int precision, int opts, const char *defid) {