Difference between revisions of "DSP"

From BRL-CAD
(Preparing your height field data: adding examples)
(rearrange examples to fit existing sections better; make a new section to be filled in)
Line 3: Line 3:
 
= Displacement (DSP) map primitive=
 
= Displacement (DSP) map primitive=
  
== Creating a DSP object ==
+
== Creating a DSP object from miscellaneous images ==
  
== Preparing your height field data ==
+
We will use two examples to illustrate the next few sections.
 +
 
 +
1. A black and white (gray scale) image (png format):
 +
 
 +
[[Image:Class65-150h.png]]
 +
 
 +
with properties:
 +
 
 +
$ file Class65-150h.png
 +
Class65-150h.png: PNG image, 142 x 150, 8-bit gray+alpha, non-interlaced
 +
 
 +
2. A color png file:
 +
 
 +
[[Image:Cs-24-150h.png]]
 +
 
 +
with properties:
 +
 
 +
$ file Cs-24-150h.png
 +
Cs-24-150h.png: PNG image, 152 x 150, 8-bit/color RGBA, non-interlaced
 +
 
 +
=== Preparing your height field data ===
  
 
The DSP takes unsigned short (16-bit) integer data. Our various command-line data converters can help bring data in from pretty much any existing format, including image data, via various processing commands. If the data was in png image format, for example (which is basically 3-channel 8-bit integer data), the data could be prepared with a combination of 'png-pix', 'pix-bw', and 'cv'.  
 
The DSP takes unsigned short (16-bit) integer data. Our various command-line data converters can help bring data in from pretty much any existing format, including image data, via various processing commands. If the data was in png image format, for example (which is basically 3-channel 8-bit integer data), the data could be prepared with a combination of 'png-pix', 'pix-bw', and 'cv'.  
Line 17: Line 37:
 
The data format for the DSP primitive is network-ordered unsigned short integers (nu16).  BRL-CAD has a couple of dozen tools that you can use for converting existing data into that raw format, such as the 'cv' command or the 'bw-d' and 'd-u' commands among other similar tool chains.  If you use the cv command, the output format is "nus" for network unsigned shorts.
 
The data format for the DSP primitive is network-ordered unsigned short integers (nu16).  BRL-CAD has a couple of dozen tools that you can use for converting existing data into that raw format, such as the 'cv' command or the 'bw-d' and 'd-u' commands among other similar tool chains.  If you use the cv command, the output format is "nus" for network unsigned shorts.
  
An example black and white (gray scale) image (png format):
+
Using  the two examples to convert the data to dsp format.
  
[[Image:Class65-150h.png]]
+
Example 1.
 
 
Run the 'file' command on it:
 
 
 
$ file Class65-150h.png
 
Class65-150h.png: PNG image, 142 x 150, 8-bit gray+alpha, non-interlaced
 
  
 
Convert it to a bw file (one pixel is one unsigned char):
 
Convert it to a bw file (one pixel is one unsigned char):
Line 38: Line 53:
 
  $ cv huc nu16 Class65-150h.bw Class65-150h.dsp
 
  $ cv huc nu16 Class65-150h.bw Class65-150h.dsp
  
And use it to create a dsp object:
+
Example 2.
 
 
mged> in dsp.s dsp f Class65-150h.dsp 142 150 0 ad 1 0.005
 
 
 
Now raytrace it:
 
 
 
mged> B dsp.s
 
mged> ae 45 45
 
mged> rt
 
 
 
You should see something like this:
 
 
 
[[Image:Dsp.png]]
 
 
 
You can play around with the scaling factors (the end pair: 1 - cell width, 0.005 - cell height) to improve the looks of the image.
 
 
 
Now use a color png file:
 
 
 
[[Image:Cs-24-150h.png]]
 
 
 
Run the 'file' command on it:
 
 
 
$ file Cs-24-150h.png
 
Cs-24-150h.png: PNG image, 152 x 150, 8-bit/color RGBA, non-interlaced
 
  
 
Convert it to a pix file (one pixel is defined by three unsigned chars):
 
Convert it to a pix file (one pixel is defined by three unsigned chars):
Line 83: Line 75:
 
  $ cv huc nu16 Cs-24-150h.bw Cs-24-150h.dsp
 
  $ cv huc nu16 Cs-24-150h.bw Cs-24-150h.dsp
  
And use it to create a dsp object:
+
=== Importing DSP data into a .g file ===
 +
 
 +
Example 1.
 +
 
 +
In mged create a dsp object:
 +
 
 +
mged> in dsp.s dsp f Class65-150h.dsp 142 150 0 ad 1 0.005
 +
 
 +
Example 2.
 +
 
 +
In mged create a dsp object:
  
 
  mged> in dsp2.s dsp f Cs-24-150h.dsp 152 150 0 ad 1 0.005
 
  mged> in dsp2.s dsp f Cs-24-150h.dsp 152 150 0 ad 1 0.005
  
Now raytrace it:
+
=== Rendering your DSP ===
 +
 
 +
Example 1.
 +
 
 +
mged> B dsp.s
 +
mged> ae 45 45
 +
mged> rt
 +
 
 +
You should see something like this:
 +
 
 +
[[Image:Dsp.png]]
 +
 
 +
You can play around with the scaling factors (the end pair: 1 - cell width, 0.005 - cell height) to improve the looks of the image.
 +
 
 +
Example 2.
  
 
  mged> B dsp2.s
 
  mged> B dsp2.s
Line 99: Line 115:
 
Again, you could play with various parameters to get the desired look.
 
Again, you could play with various parameters to get the desired look.
  
== Importing DSP data into a .g file ==
+
== Creating a DSP object from manual or programmatic generation of data ==
  
== Rendering your DSP ==
+
(to be continued)

Revision as of 15:04, 6 June 2012


Displacement (DSP) map primitive

Creating a DSP object from miscellaneous images

We will use two examples to illustrate the next few sections.

1. A black and white (gray scale) image (png format):

File:Class65-150h.png

with properties:

$ file Class65-150h.png
Class65-150h.png: PNG image, 142 x 150, 8-bit gray+alpha, non-interlaced

2. A color png file:

File:Cs-24-150h.png

with properties:

$ file Cs-24-150h.png
Cs-24-150h.png: PNG image, 152 x 150, 8-bit/color RGBA, non-interlaced

Preparing your height field data

The DSP takes unsigned short (16-bit) integer data. Our various command-line data converters can help bring data in from pretty much any existing format, including image data, via various processing commands. If the data was in png image format, for example (which is basically 3-channel 8-bit integer data), the data could be prepared with a combination of 'png-pix', 'pix-bw', and 'cv'.

If you type the 'in' command, it will prompt you for each parameter individually and that should help some. For the DSP, the main parameters are: the source of the height data, the width (number of points in the Y direction) and length (number of points in the X direction) of the input data, width/length/height scaling factors, and whether to smoothly interpolate between cells (0 = do not interpolate, 1 = interpolate).

See the 'dsp_add' tool for combining two existing DSP data files into one.

A DSP primitive is an array of cells initially defined by points in the XY plane as positive heights from Z = 0. The DSP can then be transformed to other orientations and positions. The number of cells is (numX * numY).

The data format for the DSP primitive is network-ordered unsigned short integers (nu16). BRL-CAD has a couple of dozen tools that you can use for converting existing data into that raw format, such as the 'cv' command or the 'bw-d' and 'd-u' commands among other similar tool chains. If you use the cv command, the output format is "nus" for network unsigned shorts.

Using the two examples to convert the data to dsp format.

Example 1.

Convert it to a bw file (one pixel is one unsigned char):

$ png-bw Class65-150h.png > Class65-150h.bw

View the result:

$ bw-fb -w142 -n150 Class65-150h.bw

Convert it to the format required for a dsp file (nu16):

$ cv huc nu16 Class65-150h.bw Class65-150h.dsp

Example 2.

Convert it to a pix file (one pixel is defined by three unsigned chars):

$ png-pix Cs-24-150h.png > Cs-24-150h.pix

View the result:

$ pix-fb -w152 -n150 Cs-24-150h.pix

Convert it to a bw file (one pixel is one unsigned char):

$ pix-bw Cs-24-150h.pix > Cs-24-150h.bw

View the result:

$ bw-fb -w152 -n150 Cs-24-150h.bw

Convert it to the format required for a dsp file:

$ cv huc nu16 Cs-24-150h.bw Cs-24-150h.dsp

Importing DSP data into a .g file

Example 1.

In mged create a dsp object:

mged> in dsp.s dsp f Class65-150h.dsp 142 150 0 ad 1 0.005

Example 2.

In mged create a dsp object:

mged> in dsp2.s dsp f Cs-24-150h.dsp 152 150 0 ad 1 0.005

Rendering your DSP

Example 1.

mged> B dsp.s
mged> ae 45 45
mged> rt

You should see something like this:

Dsp.png

You can play around with the scaling factors (the end pair: 1 - cell width, 0.005 - cell height) to improve the looks of the image.

Example 2.

mged> B dsp2.s
mged> ae 45 45
mged> rt

You should see something like this:

Dsp2.png

Again, you could play with various parameters to get the desired look.

Creating a DSP object from manual or programmatic generation of data

(to be continued)