Editing DSP
From BRL-CAD
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 79: | Line 79: | ||
Example 1. | Example 1. | ||
− | In | + | In mged create a dsp object: |
mged> in dsp1.s dsp f Ex1.dsp 142 150 0 ad 1 0.005 | mged> in dsp1.s dsp f Ex1.dsp 142 150 0 ad 1 0.005 | ||
Line 164: | Line 164: | ||
Finally, create the dsp file: | Finally, create the dsp file: | ||
− | $ asc2dsp t-reversed.asc t. | + | $ asc2dsp t-reversed.asc t.sp |
(The TGM creation is left as an exercise for the reader.) | (The TGM creation is left as an exercise for the reader.) | ||
− | === A practical example | + | === A practical example === |
− | Now let's consider a more practical example and a real test of BRL-CAD. We can import topological (topo) data and produce a realistic ground surface. There are many free sources of such data, but | + | Now let's consider a more practical example and a real test of BRL-CAD. We can import topological (topo) data and produce a realistic ground surface. There are many free sources of such data, but this, for US topo data, seems to be the most likely: |
− | http://nationalmap.gov/viewer.html | + | http://nationalmap.gov/viewer.html |
− | |||
− | + | For now, though, the format for the data is not easily found so we found another source of topological data (digital elevation models [DEM]) in [http://mcmcweb.er.usgs.gov/sdts/ SDTS] format: | |
http://data.geocomm.com/dem/demdownload.html | http://data.geocomm.com/dem/demdownload.html | ||
Line 182: | Line 181: | ||
[http://data.geocomm.com/catalog/US/61076/1231/index.html El Paso County], and [http://data.geocomm.com/catalog/US/61076/1231/group4-3.html Digital Elevation Models]. | [http://data.geocomm.com/catalog/US/61076/1231/index.html El Paso County], and [http://data.geocomm.com/catalog/US/61076/1231/group4-3.html Digital Elevation Models]. | ||
− | On that page we downloaded all | + | On that page we downloaded all 12 10-meter files (one data and one info file for each of six areas) because we were not yet sure which one we wanted. Note that you are required to have a Geo Community account for any downloads (membership is free). |
+ | |||
+ | We can view the SDTS data files with a free viewer (for Windows only) available here: | ||
+ | |||
+ | http://www.visualizationsoftware.com/3dem | ||
+ | |||
+ | In order to examine the data in SDTS files there are two directions to take: (1) use a [http://mcmcweb.er.usgs.gov/sdts/sdtsxx/index.html government supplied reader] or (2) use the [http://gdal.org/ GDAL library] mentioned above. | ||
+ | |||
+ | Before we can create the dsp for the topo data we will have to extract the data we want and get it in shape to use. We will use the open source Geospatial Data Abstraction Library (GDAL) and its OGR subset to create a C++ program to manipulate the shapefile data. The library and documentation are available here: | ||
+ | |||
+ | http://gdal.org | ||
+ | |||
+ | We will also use the nanoflann header-only library to help transform the contour data, which is not gridded, into gridded data. That library is available here: | ||
+ | |||
+ | http://code.google.com/p/nanoflann/ | ||
+ | |||
+ | Our program will be made available in the BRL-CAD package. | ||
+ | |||
+ | ==== Strategy ==== | ||
+ | |||
+ | The first thing to do is examine the data in the shapefile set. We used this reference as a guide: | ||
+ | |||
− | + | ==== Nearest neighbors ==== | |
− | + | Part of the strategy is to determine the nearest "neighbors" of each of our grid points. That is defined as the "All nearest neighbors" variant ("m closest neighbors") in this discussion: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | http://en.wikipedia.org/wiki/Nearest_neighbor_search#Approximate_nearest_neighbor | |
− | + | ==== Algorithm ==== | |
− | + | // a naive first approach for defining Z for our grid of points | |
+ | for each grid point p { | ||
+ | get 3 nearest neighbors of p as set n | ||
+ | while (set n does not define a plane) { | ||
+ | get next nearest neighbor of p | ||
+ | set n[2] = next nearest neighbor | ||
+ | } | ||
+ | set p.Z as the Z coordinate of intersection of vector (0, 0, 1) \ | ||
+ | with the plane formed by set n | ||
+ | } | ||
− | + | === Shapefile data === | |
− | |||
− | + | If we obtain topo data in ESRI shapefile format, we also want to examine the data in the shapefile set. | |
− | + | See these pages for details of the [ESRI] shapefile format: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | http://en.wikipedia.org/wiki/Shapefile | |
− | http://www. | + | http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf |
− | + | We used the first reference as a guide and created a Perl program ("manip-shapefile.pl") to help investigate the file. The Perl program uses the Geo::ShapeFile module available from | |
− | + | http://search.cpan.org/~jasonk/Geo-ShapeFile-2.52/ | |
− | + | Using the Perl program we find that the file consists of a set of PolygonZ shapes, each with one part consisting of a varying number of points, each point consisting of X, Y, and Z values. | |
− | + | By looking at the file "NED_DataDictionary2006.pdf" included in the shapefile set, we find that the set of polygons are topological contour lines and other data in the files define such things as units and other parameters we need to properly interpret the data. | |
− | |||
− | + | In general, then, our first approach will be to establish an X-Y section of the set to be converted to a DSP, determine a suitable step size for gridding, and determine a suitable Z scale for the DSP. | |
− | + | Then, for each X-Y point in our grid, determine the closest three points in the shapefile set that form a plane from which to calculate a Z value, write that XYZ to the DSP ascii file, and follow the rest of procedures we used in the "T" case above. |