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 [[mged]] create a dsp object of width 142, length 150, no interpolation, cut direction 'ad', cell size 1 (in current units), and unit elevation 0.005 (in current units):
+
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 136: Line 136:
 
A DSP object can be created manually or programmatically by creating an ASCII data file as input using the BRL-CAD utility asc2dsp to convert it directly to the DSP binary format.  An easy way to create the input file for asc2dsp is to first create it row by row in natural form with the top row being the desired top row and so on in desired viewing order.  Then take the finished file and filter it through the Unix utility tac which will reverse the order of the rows (lines).   
 
A DSP object can be created manually or programmatically by creating an ASCII data file as input using the BRL-CAD utility asc2dsp to convert it directly to the DSP binary format.  An easy way to create the input file for asc2dsp is to first create it row by row in natural form with the top row being the desired top row and so on in desired viewing order.  Then take the finished file and filter it through the Unix utility tac which will reverse the order of the rows (lines).   
  
=== A simple example ===
+
For example, let's create the letter T for viewing in the X-Y plane.
 
 
For example, let's create the letter "T" for viewing in the X-Y plane.
 
  
 
  $ cat t-normal.asc
 
  $ cat t-normal.asc
Line 150: Line 148:
 
Now reverse the file:
 
Now reverse the file:
  
  $ tac t-normal.asc > t-reversed.asc
+
  $ tac t-normal.asc > t.asc
  
 
and see the result in perfect form for asc2dsp:
 
and see the result in perfect form for asc2dsp:
  
  $ cat t-reversed.asc
+
  $ cat t.asc
 
  0 0 1 0 0
 
  0 0 1 0 0
 
  0 0 1 0 0
 
  0 0 1 0 0
Line 164: Line 162:
 
Finally, create the dsp file:
 
Finally, create the dsp file:
  
  $ asc2dsp t-reversed.asc t.dsp
+
  $ asc2dsp t.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 data and produce a realistic ground surface.  There are many free sources of such data.  See this site for a start:
 +
 
 +
http://www.naturalgfx.com/free_topo_gis.htm
 +
 
 +
We started with shapefile data for the US from:
 +
 
 +
http://seamless.usgs.gov/data_availability.php?serviceid=Dataset_19
 +
 
 +
We downloaded the zip archive "ned_19_arc.zip" and unzipped in its own directory:
  
Now let's consider a more practical example and a real test of BRL-CADWe can import topological (topo) data and produce a realistic ground surfaceThere are many free sources of such data, but these, for US topo data, seem to be the most likely:
+
$ mkdir ned_19_usa_arcgis_shapefile
 +
$ mv ned_19_arc.zip ned_19_usa_arcgis_shapefile
 +
$ cd ned_19_usa_arcgis_shapefile
 +
  $ unzip ned_19_arc.zip
 +
Archive: ned_19_arc.zip
 +
  inflating: ned_19_arc.dbf         
 +
  inflating: ned_19_arc.pdf         
 +
  inflating: ned_19_arc.prj         
 +
  inflating: ned_19_arc.sbn         
 +
  inflating: ned_19_arc.sbx         
 +
  inflating: ned_19_arc.shp         
 +
  inflating: ned_19_arc.shp.xml     
 +
  inflating: ned_19_arc.shx         
 +
  inflating: ned_19_arc.txt         
 +
  inflating: ned_19_arc.xml         
 +
  inflating: NED_DataDictionary2006.pdf 
  
http://nationalmap.gov/viewer.html/
+
See these pages for details of the [ESRI] shapefile format:
http://earthexplorer.usgs.gov/
 
  
Trying to find suitable topo data, in a desired format for a specific area, is not so easy there, so we located another source of topological data (digital elevation models [DEM]) in [http://mcmcweb.er.usgs.gov/sdts/ SDTS] format:
+
http://en.wikipedia.org/wiki/Shapefile
  
  http://data.geocomm.com/dem/demdownload.html
+
  http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
  
We selected [http://data.geocomm.com/catalog/US/61076/sublist.html Colorado],
+
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://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 six 10-meter data archive files for complete coverage of the county. We also downloaded the six *TXT files which contain metadata about each archive. [Note that you are required to have a Geo Community account for any downloads (membership is free).] 
+
  http://gdal.org
  
The six archive files are:
+
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:
  
  3818122.DEM.SDTS.TAR.GZ
+
  http://code.google.com/p/nanoflann/
4055020.DEM.SDTS.TAR.GZ
 
4055026.DEM.SDTS.TAR.GZ
 
4055028.DEM.SDTS.TAR.GZ
 
4055034.DEM.SDTS.TAR.GZ
 
4057865.DEM.SDTS.TAR.GZ
 
  
Taking the first archive as an example:
+
Our program will be made available in the BRL-CAD package.
  
$ tar -tvzf 3818122.DEM.SDTS.TAR.GZ
+
==== Strategy ====
  
we see that the archive files are not in a directory (but they are a set with possibly redundant file names found in other sets), so we create a directory for each:
+
The first thing to do is examine the data in the shapefile set.  We used this reference as a guide:
  
  $ mkdir 3818122.dem
+
  https://en.wikipedia.org/wiki/Shapefile
...
 
  
Now move each archive into its own directory and unpack it:
+
and created a Perl program ("manip-shapefile.pl") to help investigate the file.  The Perl program uses the Geo::ShapeFile module available from
  
  $ mv 3818122.DEM.SDTS.TAR.GZ 3818122.dem
+
  http://search.cpan.org/~jasonk/Geo-ShapeFile-2.52/
$ cd 3818122.dem
 
$ tar -xvzf 3818122.DEM.SDTS.TAR.GZ
 
3814CATD.DDF
 
3814CATS.DDF
 
3814CEL0.DDF
 
3814DDDF.DDF
 
3814DDOM.DDF
 
3814DDSH.DDF
 
3814DQAA.DDF
 
3814DQCG.DDF
 
3814DQHL.DDF
 
3814DQLC.DDF
 
3814DQPA.DDF
 
3814IDEN.DDF
 
3814IREF.DDF
 
3814LDEF.DDF
 
3814RSDF.DDF
 
3814SPDM.DDF
 
3814STAT.DDF
 
3814XREF.DDF
 
README
 
  
We can view the SDTS data files with a free viewer (for Windows only) available here:
+
Using the Perl program we find that the file consists of a set of 2915 PolygonZ shapes, each with one part consisting of a varying number of points, each point consisting of X, Y, and Z values.
  
http://www.visualizationsoftware.com/3dem
+
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 order to manipulate the data in SDTS files we used the [http://gdal.org/ GDAL library] and then created a C++ program called 'sdtsdem2asc' which can be found here:
+
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.
  
  https://github.com/tbrowder/brlcad-usgs-topo-tools
+
Then, for each X-Y point in our grid, determine the closest three points in the shapefile set from which to interpolate a Z value for our point, write that XYZ to the DSP ascii file, and follow the procedures we used in the "T" case above. We also would like our point to be inside the triangle defined by those three points.
  
After building and installing that program, we can change directory to the desired data set and create the dsp.  We enter the desired base name of the image (we choose the unique data set base name)  and use the '--chop' option to minimize the dsp's vertical height to the default one meter below the lowest height in the data set.  Note the program will do all the work for us with the options shown:
+
==== Nearest neighbors ====
  
$ cd /path/to/3818122.dem
+
Part of the strategy is to determine the nearest "neighbors" of each of our grid pointsThat is defined as the "All nearest neighbors" variant ("m closest neighbors") in this discussion:
  $ sdtsdem2asc 3814CATD.DDF --base=3818122 --chop
 
  
The resulting default png file (but cropped) is shown below.
+
http://en.wikipedia.org/wiki/Nearest_neighbor_search#Approximate_nearest_neighbor
  
[[Image:381822-az35-el25.png]]
+
[TO BE CONTINUED]

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)
Retrieved from "https://brlcad.org/wiki/DSP"