This is an overview of the steps for making your own 3D drawing using Unix and HoloDraw. While this is written specifically for the context of a Computers in Geology class, many of the concepts (if not the specifics) apply anywhere.
Appropriate data will have at least two and probably three or more dimensions or attributes that will be meaningful when viewed as spatial relationships. For example, your data might include latitude, longitude, and height or depth. This falls quite easily into the 3 dimensions "X" "Y" and "Z".
If you have only two dimensions, your drawing will end up flat like something printed on a sheet of paper. This could still be useful, however, because you can use the 3D viewing software to zoom in and out, rotate your image, move to a certain portion of it, etc.
If you have more than three dimensions, perhaps the additional dimensions can be expressed using color or size. For example, you could plot an earthquake hypocenter point in 3D space and set the color of the point based on the date of the earthquake, or based on its magnitude. Or, you could plot the earthquake using a sphere instead of a point, and you could set the size of the sphere according to the earthquake's magnitude.
Whatever data you choose, you will have to be familiar with what it means. For example, you will have to know that the latitude appears in the 3rd column of data, or that the depth is expressed in kilometers or feet or whatever.
You should have some idea what the data represents and how you expect it to look when you are done. Points of data are easiest to plot, lines are a little more work, and solid surfaces are most difficult. Note that this is a progression from plotting 0 dimensional objects (points) to 1 dimensional (lines) to 2 dimensional (planes).
The data file used in the remainder of this example can be found here. We will work with the assumption that it is a collection of points that are meaningful to our project in some way.
If the data is on your PC, use sftp to copy the file to your directory on Unix. When copying data files from one computer to another, you will probably need to use text mode (some programs call this ASCII mode).
If the data is on a web site, try saving it as a file on your PC, then copy that file to Unix.
(Note: HoloDraw also runs on Microsoft computers, but not as well. For the purposes of this class, copy your data to Unix. In other situations, if you want to use Windows, you can.)
This is where you have to know something about your data before you can decide how you want to visualize it. First, how big is your data file? If it has more than a few hundred elements of data, you may find that it takes awhile to process. Beyond 10,000 to 100,000 elements you may start to challenge the capacity of current 3D graphics hardware and software.
$ wc -l ./data/spots.dat
12001 ./data/spots.dat
|
The command above shows that our data file ./data/spots.dat consists of 12,001 rows. That is a little bit large, but probably managable.
Use head to look at the first few rows of your data. There may be some "clutter" at the beginning that you don't want. For example, if you don't want to use the first 8 rows, try tail +9 (this means "start at row 9"). Pipe your data to other Unix programs like awk to extract the columns of data you want, and to reformat the data into HoloDraw format.
$ head ./data/spots.dat
X, Y, Z,A
0.9961,14.671,12.409,2
0.3191,1.6958,24.077,8
0.1797,11.501,15.133,3
2.7960,14.565,6.2765,1
2.6589,15.011,6.1656,1
1.7052,12.376,7.1086,1
2.6402,4.9692,15.413,7
0.8833,10.468,7.9641,1
0.0428,0.9109,16.076,7
|
Here we see that there is only one row of preliminary information, presumably followed by 12,000 rows of data. Let's skip the first row and extract the X, Y and Z columns, which are delimited by commas. Also, because we don't want to deal with all 12,000 rows just yet, we will use head to give us only the first few rows while we develop our program.
$ tail +2 < ./data/spots.dat |
> head |
> awk ' BEGIN { FS = "," } { print "point:" $1 " " $2 " " $3 } '
point:0.9961 14.671 12.409
point:0.3191 1.6958 24.077
point:0.1797 11.501 15.133
point:2.7960 14.565 6.2765
point:2.6589 15.011 6.1656
point:1.7052 12.376 7.1086
point:2.6402 4.9692 15.413
point:0.8833 10.468 7.9641
point:0.0428 0.9109 16.076
point:0.5855 10.315 11.851
Broken Pipe
|
Compare the two boxes above and notice that the command produces one HoloDraw point: instruction for each row extracted from our input data file. HoloDraw is designed so that most typical data files (each of which seem to have their own unique format!) can be quickly converted into HoloDraw format with a couple basic Unix commands.
(The "Broken Pipe" message indicates that head interrupted the "pipeline" of data flowing from tail to awk, which is exactly what we wanted, otherwise we would have seen all 12,000 rows of data scrolling by on our screen.)
Above, we tested an awk command to convert our data into HoloDraw format. It worked -- the point: instructions are correctly formatted and accurately reflect the raw data prior to conversion. Now we can proceed to generate a complete 3D image. We could do it all by typing Unix commands that run immediately, but for most projects it is easier in the long run to put all those commands into a file. This series of commands is called a program or script. (In this context both words mean essentially the same thing.)
Use a text editor such as vi to create a file containing our awk command from above, together with a couple other commands, so it looks like this:
tail +2 < ./data/spots.dat |
head -1000 |
awk ' BEGIN { FS = "," } { print "point:" $1 " " $2 " " $3 } ' |
drawwrl.pl > spots.wrl
|
(The head command is now processing the first 1,000 rows of data instead of only 10 as before. This will give us a little better idea how our drawing is shaping up. When we are nearly done, we will remove the head command so that we process all 12,000 rows.)
Once our data had been converted to HoloDraw format by the awk command we could immediately create a 3D image by piping our data to drawwrl.pl. We direct the output from drawwrl.pl into a file. This file will eventually be copied to a Microsoft Windows PC to be viewed in a web browser. Because it is going to be transferred to Microsoft Windows, the file name must end in .wrl. (Unix does not care how you choose to name your files, but Microsoft Windows does.)
However, you may want to do other things to your data before producing your final drawing. For example, perhaps you need to pipe your HoloDraw instructions through drawsize.pl to adjust the scale -- maybe you want to change the vertical exaggeration. Let's say your X and Y are in degrees on the Earth's surface, but your Z is in meters. Using an approximate conversion factor of 111000 meters per degree, you could rescale your data as shown below. The drawsize.pl 111000 111000 1 command says to multiply your X and Y dimensions by 111,000 to convert degrees to meters, but multiply your Z dimension by 1 (no change) since it is already in meters.
tail +2 < ./data/spots.dat |
head -1000 |
awk ' BEGIN { FS = "," } { print "point:" $1 " " $2 " " $3 } ' |
drawsize.pl 111000 111000 1 |
drawwrl.pl > spots.wrl
|
The above example is not meant to suggest that you have to use drawsize.pl in every project. It depends on your data and what you want to do with it. You have to know what you're starting with, what you want to end up with, and then find tools that help you get from here to there.
This step is not absolutely essential, but probably a good idea. Most of the time when we present scientific data, we should identify our units of measure. In a traditional 2D (e.g. printed) graph, we will put axis lines with tickmarks showing the numerical range represented by our graph. When working in 3D, the equivalent set of axes and annotations is called a bounding box.
Making a bounding box is easy with HoloDraw. Just feed your HoloDraw instructions to drawbbox.pl. This usually involves creating some intermediate files and then putting everything together at the end. In this example (unlike the drawsize.pl example above) we have decided to use drawchop.pl to extract a certain geometric region from the data. That extracted subset of data is written to an intermediate file which is then read back in by two programs, drawbbox.pl and drawwrl.pl:
tail +2 < ./data/spots.dat |
awk ' BEGIN { FS = "," } { print "point:" $1 " " $2 " " $3 } ' |
drawchop.pl -R0/4/0/4/0/4 > spots.draw
drawbbox.pl < spots.draw > spots.box
cat spots.draw spots.box |
drawwrl.pl > spots.wrl
|
See the HoloDraw examples for more ways you can manipulate your HoloDraw instructions to produce the most useful drawing.
Use sftp to copy spots.wrl to some directory (folder) on your PC.
Open the copy on your PC using your web browser. Note: You probably will not see the entire picture right away. Click the fit button in the lower right corner. The picture should "slide" into view. If it is a big data file this may take a while. Be patient. If you give your computer extra things to do at this juncture, the only thing you will accomplish is that it will take longer for your computer to catch up with you.
Ensure that study and turn are selected on the left side, then drag the image with your mouse to rotate it to any angle.
Choose fly and plan and you will be able to zoom in and move around inside your image by holding down and moving your mouse. When you are flying, you are moving your self. You are not moving the thing you are looking at. (To do that, choose study mode.)
Choose fly and pan to "slide" from side to side or up and down.
When you are in fly mode, the turn button lets you turn your head. It does not turn the object you are viewing. To do that, switch back to study mode.
When you get lost, just hit restore and fit to start over with the original view.
If you do anything to change the image, such as modifying and re-running your script, you will have to copy your .wrl file back to your PC again, and then hit your browser's reload button.
Usually when you are writing programs, things don't work as you expected the first time. At each of the above steps, you may run into trouble. You have to figure out what went wrong, and how far back you have to go to fix it. For example, if you are at the last step and realize you picked the wrong data, you would have to go all the way back to step one, choose better data, and repeat all the remaining steps.
|
|
|