Coloring Particles and Objects
Coloring Particles and Objects
There are three fundamental ways in which data and objects are colored in Partiview. The simplest method is to give your data a constant color using the color const command. Another, more complicated method involves giving each particle its own color via a data variable using the color datavar command, which then refers to a column of data in the data file or a separate color map file. Finally, one can color an object (not particle data) using the cment command.
To begin our exploration of color, let's load the Complex Data and give the points a high luminosity with this command:
lum const 1000As you can see, the particles are multi-colored.
Setting a Constant Color
Let's replicate what we saw in the Test Data and make the particles all one color. This is accomplished using the color const command:
color const 0.5 0.5 0.9for a nice gray-blue color. Partiview reports that you are now “coloring-by rgb 0.5 0.5 0.9,” meaning it recognizes that we are setting a constant color to all particles.
Setting a Color Variable
A color variable for each particle can be set within a .speck file. If you inspect the complex.speck file (or issue the datavar command to get a report on the data variables defined in that file), you will notice that data variable 1 holds the coloring information for each point. Using the color datavar command, change from a constant color to assigning colors from that column via
color coloridx
Since coloridx refers to datavar 1, you may also refer to this number rather than the name in an equivalent command color 1. However, we recommend learning data variable names since data columns can change. With this command, Partiview reports: “coloring-by 1(coloridx) exactly (cindex=data+0; data 0.. 6, cmap 0..7).” This means that Partiview is coloring the data exactly according to data variable 1, called coloridx. Exact coloring means that the color index for a point will exactly match the color indexes in the color map file.
If you inspect the coloridx data, you will notice the correlation: a value of zero for the center point, a value of 1 for the x = 1 plane, and a value of 2 for the x = - 1 plane. The coloring is consistent, but where are the actual colors coming from? To answer this question, we need to understand color maps.
Creating a Color Map
For the Complex Data, we have created a simple color map file called complex.cmap where we define a group of colors. A color map file takes the form R G B alpha with the number of colors in the file appearing in the first line. The complex.cmap file looks like this:
8We see that the file begins with the number 8, then lists eight colors. Comments are also allowed in the file, as you can see (anything after the #). Particles can be colored as an exact match to the color entries, or distributed over a range using the entries as a guide.
0.5 0.5 0.5 0.3 # 0.gray
1.0 0.0 0.0 1.0 # 1.red
0.0 1.0 0.0 1.0 # 2.green
0.0 0.0 1.0 1.0 # 3.blue
1.0 1.0 0.0 1.0 # 4.yellow
1.0 0.5 0.0 0.6 # 5.orange
0.0 1.0 1.0 1.0 # 6.aqua
1.0 1.0 1.0 0.3 # 7.white
Using a Color Map
A color map file is read in using the cmap filename command. In the Complex Data, the center particle (coloridx = 0) is gray, the x = 1 plane (coloridx = 1) is red, and so on.
There are two ways to use a color map file. One method involves using the color datavar exact command to use the exact colors in the color map file, while the other method distributes the coloring over a continuous range that is based on the color map file.
The Complex Data is loaded using exact coloring which is set in the complex.cf file. If you want to color the particles over a continuous range, type the command:
color coloridx -exactThe -exact part of this command removes the exact coloring and colors the particles over a continuous range. In this case, the range has been unspecified and defaults to the range of the coloridx data variable. You can specify that the colors be distributed over half the range using this command:
color coloridx 0 3
Summing up:
- color datavar exact [baseval]
Color particles by mapping one-to-one the color datavar to the color index in the color map file. For example, data with a coloridx of 2, will be colored green (if we assume we're using the complex.cmap file), data with a coloridx of 7 will be white, and so on. Also, out of range values are assigned to the first or last entry in the file. For example, a coloridx of 30 will be colored white.If you use negative values, the colors will be re-scaled according to where the negative value appears in your data. Any data prior to this point will be colored gray, the first entry in the color map file. We recommend using positive values for your color variable for more predictable results.
If you wish to start at some base color other than the first color in the file, then you may use the baseval option. For example, try setting the baseval to 2, and see what happens to the data. Now, data of coloridx = 0 will be mapped to the third color in the file. The rest of the colors follow from there, adding on one from the base. The values of coloridx that are attempting to reference colors that are not in the color map file will be given the last color and treated as out of range, so they will be colored white in our example color map file. If you were to start at baseval = 7, then all the points would be colored white.
- color datavar -exact
Use the -exact command to turn off exact coloring once it has been turned on. Colors are now distributed over a continuous range (just as color datavar [MIN MAX] is). Type the commandcolor coloridx -exact
to turn off exact coloring. Note that using the color datavar [min max] after using exact coloring will not remove the exact coloring, you must use the color datavar -exact command.
- color datavar [min max]
Color particles using datavar. By default (without the min max arguments), the colors are mapped to colors between the second color and the n - 1 color in the color map, in this case red to aqua. The first and last colors (gray and white in this file) are used for out of range values. If we supply the min max arguments, the colors are mapped over this range. For example, if we issue the commandcolor coloridx 1 7
we replicate the coloring of the exact command (if you issued the -exact command prior). Note that the center point is gray not because we are assigning it that color, but because it is out of the 1-7 range, and, therefore, receives the first (out-of-range) color. If we adjust the max range down to 6, you will notice that the last point (x, y, z) = (0, 0, - 1) is out of range, so it changes from aqua to white. Continue shrinking the range to 1-5. Now, you see a major shift in color. Now, all points in the yz plane (aside from the point on the origin) change color as the distribution is over a smaller range, making fewer colors available. Continue shrinking the range and see what happens.
Customizing a Color Index
There are times when you want to set the color of one index value. The command to do this is cment. This command can be applied in many situations: coloring particles, objects, labels, and boxes. For example, let's say we want to change the x = - 1 plane from green to purple. First, set the coloring of the particles back to exact using the command
color coloridx exact
Since we can see from the data file that the x = - 1 plane points have the coloridx value of 2, let's just assign that color index a different color via the command
cment 2 1 0 1
This sets the color index 2 to the color purple (R, G, B) = (1, 0, 1).
We will also use this when defining objects like ellipsoids, meshes, and other objects. Let's draw a sphere and assign it the color green. Define a new data group called sphere, then draw a green sphere using the commands:
g2=sphere
add 0 0 0 ellipsoid -r 100 -c 20 -s wire -n 36,19
cment 20 0 .7 0
You may notice that if you try to define a color index of 20 in group 1, Partiview would have told you the color index was out of range. This is due to the fact that the data group is using the complex.cmap color map that has color indices ranging from 0-7. There are similar commands for adding color to labels and boxes, which we discuss next.
Coloring Text
There are two commands needed to color text in Partiview. The color is set using the textcment command and assigned to that color index using the textcolor command. We define a text color index in the config file complex.cf using the command
textcment 1 .2 .4 .6
We then issue the command
textcolor 1in the data file, complex.speck, where the labeling data is located. This command tells Partiview that the labels should be colored according to color index 1. While the textcolor command cannot be entered at the Command Line, textcment can be altered interactively. Knowing that the color index of the text color is 1, you can alter the color by reassigning the color from the bluish color to an orange color (provided you have the correct group selected) using the command
textcment 1 .6 .4 .2To change the color index number, you must change the argument of the textcolor command in the data file, then re-load the data file.
Coloring Boxes
Let's create a box around our sphere that's centered on the point (x, y, z) = (0, 0, 0) and with half-lengths of 100:
add box -n 1 -l 4 0,0,0 100,100,100A blue box appears; the -l 4 argument sets the color index to 4 which is blue in the default color map. We can change this color via the boxcment command. Similar to the cment command, we can change the color to red by issuing the command
boxcment 4 .7 .1 .1
We can also color the box according to a color map file by reading that file using the boxcmap command. Change the box color to read from the file using this command:
boxcmap complex.cmap
Now the box color, still set to a color index of 4, is yellow, according to the 4th color of the color map file. Finally, the box axes can be highlighted to show the fundamental red, green, and blue axes by using the boxaxes command.
boxaxes onThis adds a fade of red, green, and blue to the x, y, and z axes, respectively. To change back, just toggle the boxaxes off.
© 2002-2005 American Museum of Natural History
Last Modified: 2006-04-28 by Brian Abbott
