Get Teem at SourceForge.net. Fast, secure and Free Open Source software downloads
teem / nrrd / demo

  Making a synthetic cone dataset

Like another page, this page shows how unu is a sufficient tool for making an interesting synthetic dataset, with conical isosurfaces.

The cone starts with the function z - 2*sqrt(x*x + y*y) + 0.5, sampled from -1 to 1 on each axis. First start by sampling x, y, and z:

setenv NRRD_DEF_CENTER node
echo "-1 1   -1 1   -1 1   -1 1" \
 | unu reshape -s 2 2 2 \
 | unu resample -s 100 100 90 -k tent -o x.nrrd
unu swap -a 0 1 -i x.nrrd -o y.nrrd
echo "-1 -1   -1 -1   1 1    1 1" \
 | unu reshape -s 2 2 2 \
 | unu resample -s 100 100 90 -k tent -o z.nrrd
Then combine them, and pad out the z axis to 100 samples, to make an initial version, cone0.nrrd, which is Gaussian blurred to make cone1.nrrd:
unu join -i x.nrrd y.nrrd -a 0 -incr \
 | unu project -a 0 -m l2 \
 | unu 2op x - -2 \
 | unu 2op + - z.nrrd \
 | unu 2op + - 0.5 \
 | unu pad -min 0 0 0 -max M M M+10 -b pad -v -2 -o cone0.nrrd

unu resample -s x1 x1 x1 -k gauss:3,3 -i cone0.nrrd -o cone1.nrrd

rm -f xx.nrrd yy.nrrd z.nrrd 
The goal now is to create a cone dataset that is pointy at the top of the cone, but which has a rounded bottom. This is possible by blending between cone0.nrrd and cone1.nrrd with a weight that linearly varies through the slices:

unu dice -i cone0.nrrd -a 2 -o cone0-z
unu dice -i cone1.nrrd -a 2 -o cone1-z

foreach Z ( 00 01 02 03 04 05 06 07 08 09 \
            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 )
  echo $Z
  unu 3op lerp 0.${Z} cone0-z${Z}.nrrd cone1-z${Z}.nrrd -o cone-z${Z}.nrrd
end

unu join -i cone-z*.nrrd -a 2 -o cone.nrrd

rm -f cone0-z* cone1-z* cone-z*

We can compare slices of these three, by first joining the whole volumes side by side (in order cone0.nrrd, cone1.nrrd, and cone.nrrd), and then slicing. This idiom, "join first and slice later", is a somewhat inefficient consequence of the urge to minimize the number of intermediate files created.

unu pad -i cone0.nrrd -min 0 0 0 -max M+20 M M -b pad -v 1.5 \
 | unu join -i - cone1.nrrd -a 0 \
 | unu pad -min 0 0 0 -max M+20 M M -b pad -v 1.5 \
 | unu join -i - cone.nrrd -a 0 \
 | unu slice -a 1 -p 50 \
 | unu quantize -b 8 -o slice.png
slice.png

Quick sample rendering, using miter:

echo "0 1" \
 | unu reshape -s 2 \
 | unu resample -s 256 -k tent -o ramp.nrrd

echo "-2.5 0.0   -0.6 0.0    -0.55 1.0    1.5 1.0" \
 | unu reshape -s 2 4 \
 | unu imap -i ramp.nrrd -r -m - \
 | unu axinsert -a 0 -l "A" \
 | unu axinfo -a 1 -l "gage(v)" -mm -2.5 1.5 -o val-txf.nrrd

unu pad -i cone0.nrrd -min 0 0 0 -max M+20 M M -b pad -v -1 \
 | unu join -i - cone1.nrrd -a 0 \
 | unu pad -min 0 0 0 -max M+20 M M -b pad -v -1 \
 | unu join -i - cone.nrrd -a 0 \
 | unu reshape -s 340 100 100 \
 | miter -i - -txf val-txf.nrrd \
   -k00 cubic:1,0 -k11 cubicd:1,0 -k22 cubicdd:1,0 \
   -rh -fr 6 7 -4 -up 0 0 -1 \
   -dn -2 -di 0 -df 2 -ar \
   -ur -0.95 1.05 -vr -0.6 0.6 \
   -ld 6 -6 -10.5 \
   -ads 0.2 0.6 0.45 -sp 60 -is 500 300 -step 0.004 -nt 10 -o - \
 | overrgb -i - -b 0.3 0.2 0.1 -g 1.3 -o rend.png

unu resample -i rend.png -s = x0.29 x0.29 \
 | unu crop -min 0 2 1 -max M M M-1 -o _rend.png

rm -f ramp.nrrd val-txf.nrrd 
rm -f cone0.nrrd cone1.nrrd
rend.png

The left to right ordering of the cones is as before: cone0.nrrd, cone1.nrrd, and cone.nrrd. Note the unu reshape command just prior to miter: this hack has the effect of nixing the sample spacings information along all the axes. Miter complains if the spacing information exists for some axes but not others, as is the case with the output of the previous unu join and unu pad commands.