1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 99.2beta8 (1.46)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>6.11 Making a 3-D RGB color cube</TITLE>
<META NAME="description" CONTENT="6.11 Making a 3-D RGB color cube">
<META NAME="keywords" CONTENT="GMT_Docs">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v99.2beta8">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="GMT_Docs.css">
<LINK REL="next" HREF="node85.html">
<LINK REL="previous" HREF="node83.html">
<LINK REL="up" HREF="node73.html">
<LINK REL="next" HREF="node85.html">
</HEAD>
<BODY bgcolor="#ffffff">
<!--Navigation Panel-->
<A NAME="tex2html2206"
HREF="node85.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.gif"></A>
<A NAME="tex2html2200"
HREF="node73.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.gif"></A>
<A NAME="tex2html2194"
HREF="node83.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.gif"></A>
<A NAME="tex2html2202"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.gif"></A>
<A NAME="tex2html2204"
HREF="node149.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.gif"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2207"
HREF="node85.html">6.12 Optimal triangulation of</A>
<B> Up:</B> <A NAME="tex2html2201"
HREF="node73.html">6. Cook-book</A>
<B> Previous:</B> <A NAME="tex2html2195"
HREF="node83.html">6.10 A geographical bar</A>
  <B> <A NAME="tex2html2203"
HREF="node1.html">Contents</A></B>
  <B> <A NAME="tex2html2205"
HREF="node149.html">Index</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0014110000000000000000"></A>
<A NAME="10985"></A>
<BR>
6.11 Making a 3-D RGB color cube
</H1>
<P>
In this example we generate a series of 6 color images,
arranged in the shape of a cross, that can be cut out
and assembled into a 3-D color cube. The six faces of
the cube represent the outside of the R-G-B color space.
On each face one of the color components is fixed at either
0 or 255 and the other two components vary smoothly across
the face from 0 to 255. The cube is configured as a
right-handed coordinate system with <I>x-y-z</I> mapping
R-G-B. Hence, the 8 corners of the cube represent the
primaries red, green, and blue, plus the secondaries cyan,
magenta and yellow, plus black and white.
<P>
The method for generating the 6 color faces utilizes
<I>$AWK</I><A NAME="11010"></A> in two steps. First, a <I>z</I>-grid is composed
which is 256 by 256 with <I>z</I>-values increasing in a planar
fashion from 0 to 65535. This <I>z</I>-grid is common to all
six faces. The color variations are generated by creating a
different color palette for each face using the supplied
<I>$AWK</I><A NAME="11015"></A> script <U>rgb_cube.awk</U>. This script generates a
``cpt'' file appropriate for each face using arguments for
each of the three color components. The arguments specify
if that component (<IMG
WIDTH="37" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
SRC="img111.gif"
ALT="$r,g,b$">) is to be held fixed at 0 or 255,
is to vary in <I>x</I>, or is to vary in <I>y</I>. If the
color is to increase in <I>x</I> or <I>y</I>, a lower case
<I>x</I> or <I>y</I> is specified; if the color is to decrease
in <I>x</I> or <I>y</I>, an upper case <I>X</I> or <I>Y</I> is
used. Here is the shell script and accompanying <I>$AWK</I><A NAME="11021"></A>
script to generate the RGB cube:
<P>
<P>
<BR>
<P>
<BR CLEAR="ALL">
<HR>
<BR>
<PRE>
grdmath -I1 -R0/255/0/255 Y 256 MUL X ADD = rgb_cube.grd
gmtset TICK_LENGTH 0 COLOR_MODEL rgb
pstext -R0/8/0/11 -Jx1i < /dev/null -P -U"Example 11 in Cookbook" -K >! example_11.ps
$AWK -f rgb_cube.awk r=x g=y b=255 < /dev/null >! rgb_cube.cpt
grdimage rgb_cube.grd -Crgb_cube.cpt -JX2.5i/2.5i -R0/255/0/255 -K -O -X2i -Y4.5i -B256wesn \
>> example_11.ps
$AWK -f rgb_cube.awk r=255 g=y b=X < /dev/null >! rgb_cube.cpt
grdimage rgb_cube.grd -Crgb_cube.cpt -JX -K -O -X2.5i -B256wesn >> example_11.ps
$AWK -f rgb_cube.awk r=x g=255 b=Y < /dev/null >! rgb_cube.cpt
grdimage rgb_cube.grd -Crgb_cube.cpt -JX -K -O -X-2.5i -Y2.5i -B256wesn >> example_11.ps
psxy -W0.25pto -JX -R -K -O -X2.5i << END >> example_11.ps
0 0
20 20
20 235
0 255
END
psxy -W0.25pto -JX -R -K -O -X-2.5i -Y2.5i << END >> example_11.ps
0 0
20 20
235 20
255 0
END
psxy -W0.25pto -JX -R -K -O -X-2.5i -Y-2.5i << END >> example_11.ps
255 0
235 20
235 235
255 255
END
$AWK -f rgb_cube.awk r=0 g=y b=x < /dev/null >! rgb_cube.cpt
grdimage rgb_cube.grd -Crgb_cube.cpt -JX -K -O -Y-2.5i -B256wesn >> example_11.ps
$AWK -f rgb_cube.awk r=x g=0 b=y < /dev/null >! rgb_cube.cpt
grdimage rgb_cube.grd -Crgb_cube.cpt -JX -K -O -X2.5i -Y-2.5i -B256wesn >> example_11.ps
pstext -JX -R -G255 -K -O << END >> example_11.ps
10 10 14 0 -Times-BoldItalic 1 GMT 3
END
psxy -W0.25pto -JX -R -K -O -X2.5i << END >> example_11.ps
0 0
20 20
20 235
0 255
END
psxy -W0.25pto -JX -R -K -O -X-5i << END >> example_11.ps
255 0
235 20
235 235
255 255
END
$AWK -f rgb_cube.awk r=x g=Y b=0 < /dev/null >! rgb_cube.cpt
grdimage rgb_cube.grd -Crgb_cube.cpt -JX -K -O -X2.5i -Y-2.5i -B256wesn >> example_11.ps
psxy -W0.25pto -JX -R -K -O -X2.5i << END >> example_11.ps
0 0
20 20
20 235
0 255
END
psxy -W0.25pto -JX -R -O -X-5i << END >> example_11.ps
255 0
235 20
235 235
255 255
END
\rm -f rgb_cube.cpt rgb_cube.grd .gmtcommands
</PRE>
<P>
<BR>
<BR>
<P>
<BR CLEAR="ALL">
<HR>
<P>
The <I>$AWK</I><A NAME="11096"></A> script <U>rgb_cube.awk</U> is as follows:
<P>
<P>
<BR>
<P>
<BR CLEAR="ALL">
<HR>
<BR>
<PRE>
END{
z=-.5;
if(r=="X" || g=="X" || b=="X"){
xl=255; xr=0; xd=-255;
}else{
xl=0; xr=255; xd=255;
}
if(r=="Y" || g=="Y" || b=="Y"){
yb=255; yt=-1; yd=-1;
}else{
yb=0; yt=256; yd=1;
}
for(y=yb; y!=yt; y+=yd){
x=xl;
if(r=="x" || r=="X"){
if(g=="y" || g=="Y"){
printf("%7.1f %3d %3d %3d " ,z,x,y,b);
x+=xd; z+=256;
printf("%7.1f %3d %3d %3d\n",z,x,y,b);
}else{
printf("%7.1f %3d %3d %3d " ,z,x,g,y);
x+=xd; z+=256;
printf("%7.1f %3d %3d %3d\n",z,x,g,y);
}
}else if(g=="x" || g=="X"){
if(r=="y" || r=="Y"){
printf("%7.1f %3d %3d %3d " ,z,y,x,b);
x+=xd; z+=256;
printf("%7.1f %3d %3d %3d\n",z,y,x,b);
}else{
printf("%7.1f %3d %3d %3d " ,z,r,x,y);
x+=xd; z+=256;
printf("%7.1f %3d %3d %3d\n",z,r,x,y);
}
}else{
if(r=="y" || r=="Y"){
printf("%7.1f %3d %3d %3d " ,z,y,g,x);
x+=xd; z+=256;
printf("%7.1f %3d %3d %3d\n",z,y,g,x);
}else{
printf("%7.1f %3d %3d %3d " ,z,r,y,x);
x+=xd; z+=256;
printf("%7.1f %3d %3d %3d\n",z,r,y,x);
}
}
}
exit;
}
</PRE>
<P>
<BR>
<BR>
<P>
<BR CLEAR="ALL">
<HR>
<P>
The cube can be viewed in Figure <A HREF="node84.html#fig:GMT_example_11">6.11</A>
<P>
<P></P>
<DIV ALIGN="CENTER"><A NAME="fig:GMT_example_11"></A><A NAME="11136"></A>
<TABLE>
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 6.11:</STRONG>
The color cube</CAPTION>
<TR><TD><IMG
WIDTH="432" HEIGHT="587" BORDER="0"
SRC="img112.gif"
ALT="\begin{figure}\centering\epsfig{figure=eps/GMT_example_11.eps}\end{figure}"></TD></TR>
</TABLE>
</DIV><P></P>
<P>
<A NAME="11126"></A>
<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html2206"
HREF="node85.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.gif"></A>
<A NAME="tex2html2200"
HREF="node73.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.gif"></A>
<A NAME="tex2html2194"
HREF="node83.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.gif"></A>
<A NAME="tex2html2202"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.gif"></A>
<A NAME="tex2html2204"
HREF="node149.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.gif"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2207"
HREF="node85.html">6.12 Optimal triangulation of</A>
<B> Up:</B> <A NAME="tex2html2201"
HREF="node73.html">6. Cook-book</A>
<B> Previous:</B> <A NAME="tex2html2195"
HREF="node83.html">6.10 A geographical bar</A>
  <B> <A NAME="tex2html2203"
HREF="node1.html">Contents</A></B>
  <B> <A NAME="tex2html2205"
HREF="node149.html">Index</A></B>
<!--End of Navigation Panel-->
<ADDRESS>
Paul Wessel
2001-04-18
</ADDRESS>
</BODY>
</HTML>
|