Here I have an example script to create a sequence of images using
a ForEachN loop inside a macro. It just rotate an isosurface of an
arbitrary scalar field, but with some small adjustment you can use it to
update the filename and import them.

call with

dx -script movie_vase.net

It uses another macro to create the images: show_plane.net
make sure that this macro is in the same directory or somewhere in your
DXMACRO path

finally, the serie of tiff images that is generated by dx can easily by
converted to an mpeg movie using the scrip tifftompg.sh with

tifftompg block_t

This script actually calls the program 'mpeg', that is is available  by
anonymous  ftp  from  havefun.stanford.edu:pub/mpeg/MPEGv1.2.tar.Z.
(by Andy Hung)

Cheers

Eelco



On Mon, 2 Sep 2002, Angel Dimitrov wrote:

>
>  Hello,
>
>  Can you give me some advice how to make animations in DX.
>
>  I have 30 NetCDF files and I want to make animation from them. In
> now the script which make the animation is actually a bash script
> which run dx with option -script ... so I have 30 .net files and
> every file create one image... after that with Image Magic it become
> into one GIF file... so can you send me some example script to look
> inside because in now it take me more than 30 minutes to configure
> every .net file if I want to make a new GIF from other direction or
> with other isosurface;>
>
>
>  Thank you.
>
>
>  Greetings,
>
>         Angel
>
>
>
> =====
> Angel Dimitrov
> Storm Laboratory
> Tel.: +359 52 475-919
> Department of Meteorology
> Physic faculty at Sofia University
> http://www.angelfire.com/sc/stormlab/index.html
> http://www.angelfire.com/sc3/wmc/index.html
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
>

Attachment: tifftompg.sh
Description: Bourne shell script

macro show_plane( data,                                                 // the 
data field to show (2d or 3d)
                                                selectplanes=[2,0,0],   // 
[direction, thickness, positions1,
                                                                                
                           // postion2, position3] 
                                                datarange,                      
                // min, max, or [min,max] 
                                                caption,                        
                        // caption and color{"cap","color"}
                                                captionposition,                
        // the position of the caption
                                                captionscale,                   
        // the size of the caption
                                                showcolors=1,                   
        // 0=none, 1=color, 2=greyscale
                                                coloropacity=1,                 
// the color opacity
                                                colorrange,                     
                // [start, range]
                                                showbox=0,                      
                // a color string or 1 to show box
                                                showboxplane=0,                 
// same as showbox, but only for slab
                                                showgrid=0,                     
                // a color string or 1 to show grid
                                                isolines,                       
                // if 1 int: number of line
                                                                                
                                // if list of floats: the line values
                                                isolinecolor="black",   // the 
isoline color
                                                isosurface,                     
                // idem as isolines,
                                                isosurfacecolor,
                                                isosurfaceopacity,
                                                showzeros=[0 0 0],              
// show the coordinate axes
                                                zerocolors,                     
                // sting (list) of the axes colors
                                                origin,                         
                // the origin of the coordinate axes
                                                showaxes=0,     
                                                axesscale=1,
                                                rubber=0,
                                                showbar=0,                      
                // if 1 or color string, show bar
                                                barposition,
                                                barshape,
                                                showglyph=0,
                                                glyphtype=0,
                                                glyphscale=1,
                                                addglyph,       
                                                background="grey",
                                                direction,
                                                width,  
                                                aspect=.75,
                                                resolution=300,
                                                from,
                                                to,
                                                up=[0 0 1],
                                                camera,
                                                showlight=[1 1],                
// turn on the default spotlights/ambient
                                                lightcolor,
                                                lightposition,
                                                lightcamera,
                                                ambientlightcolor,
                                                image_title="") -> 
(image,camera,collect)
{

                                                
        // set the axes labels
        axlab={"x","y","z"};

        // check if 2D or 3d data field
        is3d    = Inquire(data,"is 3D positions");

   // pick slice from the data

        // first, see how many planes are given in the array
        shape                           = Inquire(selectplanes,"shape");
        number                  = Compute("$0-2",shape);
        planedirect        = Compute("$0.x",selectplanes);
        thickness          = Compute("$0.y",selectplanes);
        planenumber1   = Compute("select($0,2)",selectplanes);
        planenumber2   = Compute("$1 > 1 ? select($0,3): 
-1",selectplanes,number);
        planenumber3   = Compute("$1 > 2 ? select($0,4): 
-1",selectplanes,number);
        planenumber4   = Compute("$1 > 3 ? select($0,5): 
-1",selectplanes,number);
        planenumber5   = Compute("$1 > 4 ? select($0,6): 
-1",selectplanes,number);
        showplane2              = Compute("$0>=0 ? 1 : 2",planenumber2);
        showplane3              = Compute("$0>=0 ? 1 : 2",planenumber3);
        showplane4              = Compute("$0>=0 ? 1 : 2",planenumber4);
        showplane5              = Compute("$0>=0 ? 1 : 2",planenumber5);
        planenumber2    = Switch(showplane2,planenumber2,NULL);
        planenumber3    = Switch(showplane3,planenumber3,NULL);
        planenumber4    = Switch(showplane4,planenumber4,NULL);
        planenumber5    = Switch(showplane5,planenumber5,NULL);
        planenumber             = 
List(planenumber1,planenumber2,planenumber3,planenumber4,
                                                                 planenumber5);

   slice            = Slab(data,planedirect,planenumber,thickness=thickness);
        temp                              = ShowBoundary(slice);
        taketemp                          = Compute("$0>0 ? 1 : 2",thickness);
        slice                             = Switch(taketemp,temp,slice);

        // make volume 
        volume                          = ShowBoundary(data);

        showvolume                      = Compute("$0<0 ? 1 : 2",planenumber1);

        // choise between volume and slice
        slice                           = Switch(showvolume,volume,slice);

        // if 2d data field, take original data
        slice                           = Switch(is3d+1,data,slice);

        // make grid
        isstring                        = Inquire(showgrid,"is string");        
                
        isint                           = Inquire(showgrid,"is int");
        showcolor               = Compute("$0==1 ? $1 : 
$2",isstring,showgrid,"black");
        showit                  = Compute("$0==1 ? $1 : 0",isint,showgrid);
        showit                  = Compute("$0==1 || $1==1 ? 1 : 
0",showit,isstring);
        grid                            = ShowConnections(slice);
        grid                            = Color(grid,showcolor);
        grid                            = Route(showit,grid);

        // make bounding boxes
        isstring                        = Inquire(showbox,"is string");         
        
        isint                           = Inquire(showbox,"is int");
        showcolor               = Compute("$0==1 ? $1 : 
$2",isstring,showbox,"black");
        showit                  = Compute("$0==1 ? $1 : 0",isint,showbox);
        showit                  = Compute("$0==1 || $1==1 ? 1 : 
0",showit,isstring);
        box                             = ShowBox(data);
        box                             = Color(box,showcolor);
        box                             = Route(showit,box);

        // make bounding boxes
        isstring                        = Inquire(showboxplane,"is string");    
                
        isint                           = Inquire(showboxplane,"is int");
        showcolor               = Compute("$0==1 ? $1 : 
$2",isstring,showboxplane,"black");
        showit                  = Compute("$0==1 ? $1 : 0",isint,showboxplane);
        showit                  = Compute("$0==1 || $1==1 ? 1 : 
0",showit,isstring);
        boxplane                        = ShowBox(slice);
        boxplane                        = Color(boxplane,showcolor);
        boxplane                        = Route(showit,boxplane);

        // make iso contours
        isnull                  = Inquire(isolines,"is null");
        isint                           = Inquire(isolines,"is int");
        // is the isolines is an integer, take them to be the number of lines
        num                             = Switch(isint+1,NULL,isolines);
        testnum                 = Switch(isint+1,1,isolines);
        tmp                             = Compute("$0==0 && $1==1 ? 0 : 
1",testnum,isint);
        linedata                        = Route(tmp,slice);
        tmp                             = Route(isint,tmp);

        // else use them as values
        val                             = Switch(isint+1,isolines,NULL);
        
        linedata                        = Route(isnull+1,linedata);
        lines                           = 
Isosurface(linedata,value=val,number=num);
        lines                           = Color(lines,isolinecolor);

   // add colors to the data
        isvector                                = Inquire(colorrange,"is 
vector");
        colorrange                      = Route(isvector,colorrange);
        startcolor                      = Compute("$0.x",colorrange);
        rangecolor                      = Compute("$0.y",colorrange);
        startcolor                      = Switch(isvector+1,NULL,startcolor);
        rangecolor                      = Switch(isvector+1,NULL,rangecolor);

        isvector                                = Inquire(datarange,"is 
vector");
        datarange                       = Route(isvector,datarange);
        min                                     = Compute("$0.x",datarange);
        max                                     = Compute("$0.y",datarange);
        min                                     = Switch(isvector+1,NULL,min);
        max                                     = Switch(isvector+1,NULL,max);

        sliceu,colormapu        = Color(slice,"white",0);
   slicec,colormapc     = AutoColor(slice,min=min,max=max,start=startcolor,
                                                                                
        range=rangecolor,opacity=coloropacity);
   sliceg,colormapg     = AutoGrayScale(slice,min=min,max=max,start=startcolor,
                                                                                
                 range=rangecolor,opacity=coloropacity);
        slice                                   = 
Switch(showcolors+1,sliceu,slicec,sliceg);
        colormap                                = 
Switch(showcolors+1,NULL,colormapc,colormapg);

   // create relief
   rubbersheet      = RubberSheet(slice);
   rubbersheet      = Normals(rubbersheet,"connections");

        rubber                          = Compute("$0==1 ? 1 : 2",rubber);
   slice                = Switch(rubber,rubbersheet,slice);


        // make the isosurfaces ////////////////////////////////////////

        isnull                  = Inquire(isosurface,"is null");
        isint                           = Inquire(isosurface,"is int");

        // set number if 'isosurface' is integer, else set NULL
        num                             = Switch(isint+1,NULL,isosurface);
        // for test use in compute, is no integer, set tmp to zero
        tmp                             = Switch(isint+1,0,isosurface);

        // if 'isosurface' was no integer, take it as value list
        val                             = Switch(isint+1,isosurface,NULL);

        // display only if 'isosurface' was integer greater then zero or a 
value list
        tmp                             = Compute("($0==1 && $1>0) || ($0==0 && 
$2==0) ? 1 :0 ",
                                                                         
isint,tmp,isnull);
        surfacedata             = Route(tmp,data);
        surface                 = Isosurface(surfacedata,value=val,number=num);
        surface                 = 
Color(surface,isosurfacecolor,isosurfaceopacity);

        // make x and y zeroline        ////////////////////////////////////////
        // first extract the bounding box and the corners
        corners                 = Extract(data,"box");
        cnr1                            = Select(corners,0);
        dimdata                 = Inquire(data,"is 3d positions");
        select                  = Compute("$0==1 ? 7 : 3",dimdata);
        cnr2                            = Select(corners,select);
        cnr1                            = Compute("$0==1 ? $1 : [$1.x, $1.y, 
0]",is3d,cnr1);
        cnr2                            = Compute("$0==1 ? $1 : [$1.x, $1.y, 
0]",is3d,cnr2);
        center                  = Compute("($0+$1)/2.0",cnr1,cnr2);

        // choose between default or passed origin
        isnull                  = Inquire(origin,"is null");
        origin                  = Switch(isnull+1,origin,center);

        // in case of a 2d origin, transform to a 2d vector
        is2vector               = Inquire(origin,"is 2vector");
        origin                  = Compute("$0==1 ?  [$1.x, $1.y, 0]: $1 ",
                                                                         
is2vector,origin);

        // check the axis colors
        isarray                 = Inquire(zerocolors,"is array");
        items                           = Inquire(zerocolors,"items");
        items                           = Switch(isarray+1,0,items);
        select0                 = Select(zerocolors,0);
        select1                 = Select(zerocolors,1);
        select2                 = Select(zerocolors,2);

        isstring                        = Inquire(zerocolors,"is null");
        select                  = zerocolors;
        select                  = Switch(isstring+1,select,"black");
        item                            = Compute("$0>=1 ? 2 : 1 ",items);
        item                            = Compute("$0>=2 ? 2 : 1 ",items);
        item                            = Compute("$0>=3 ? 2 : 1 ",items);
        xzerocolor              = Switch(item,select,select0);
        yzerocolor              = Switch(item,select,select1);
        zzerocolor              = Switch(item,select,select2);


        // calculate of each zeroline its centrum and half length
        linex_o                 = 
Compute("[($1.x+$2.x)/2.,$0.y,$0.z]",origin,cnr1,cnr2);
        liney_o                 = 
Compute("[$0.x,($1.y+$2.y)/2.,$0.z]",origin,cnr1,cnr2);
        linez_o                 = 
Compute("[$0.x,$0.y,($1.z+$2.z)/2.]",origin,cnr1,cnr2);
        linex_n                 = Compute("[($1.x - $0.x)/2., 0, 0]",cnr1,cnr2);
        liney_n                 = Compute("[0, ($1.y - $0.y)/2., 0]",cnr1,cnr2);
        linez_n                 = Compute("[0, 0, ($1.z - $0.z)/2.]",cnr1,cnr2);

        //  check if it excists
        rank                            = Inquire(showzeros,"rank");
        dim                             = Inquire(showzeros,"shape");
        dim                             = Switch(rank+1,1,dim);
        showxzero               = Compute("$0==0          ? $2   : \
                                                                          $0==1 
&& $1>=1 ? $2.x : 0",rank,shape,showzeros);
        showyzero               = Compute("$0==1 && $1>=2 ? $2.y : 
0",rank,shape,showzeros);
        showzzero               = Compute("$0==1 && $1>=3 ? $2.z : 
0",rank,shape,showzeros);



        xzero                           = Grid(linex_o,"line",linex_n,2);
        xzero                           = ShowConnections(xzero);
        xzero                           = Color(xzero,xzerocolor);
        xzero                           = Route(showxzero,xzero);

        yzero                           = Grid(liney_o,"line",liney_n,2);
        yzero                           = ShowConnections(yzero);
        yzero                           = Color(yzero,yzerocolor);
        yzero                           = Route(showyzero,yzero);

        zzero                           = Grid(linez_o,"line",linez_n,2);
        zzero                           = ShowConnections(zzero);
        zzero                           = Color(zzero,zzerocolor);
        zzero                           = Route(showzzero,zzero);

   // create captions 
        isnull                  = Inquire(caption,"is null");
        isnull                  = Compute("$0==1 ? 0 : 1",isnull);
        caption                 = Route(isnull,caption);


        // see if the caption input is given as an array 
        isarray                 = Inquire(caption,"is array");
        isarray                 = isarray+1;

        // only get the number of items if caption was an array, else take 0
        items                           = Inquire(caption,"items");
        items                           = Switch(isarray,0,items);
        items                           = Compute("$0==2 ? 1 : 0",items);

        // now select the elements from the array
        captionselect0  = Select(caption,0);
        captionselect1  = Select(caption,items);

        // if no color was given: take the default col
        defaultcolor    = Compute("$0==2 && $1==2 ? 2 : 1",isarray,items);
        captioncolor    = Switch(defaultcolor,"black",captionselect1);

        captiontext             = Switch(isarray,caption,captionselect0);
        captioncolor    = Compute("$0==0 ? $2 : $1  
",items,captionselect1,"black");

   imagecaption   = Caption(captiontext,position=captionposition,font="fixed",
                                                                         
height=captionscale,alignment=0.0);
        imagecaption    = Color(imagecaption,captioncolor);

   // create colorbars
        isstring                        = Inquire(showbar,"is string");         
        
        isint                           = Inquire(showbar,"is int");
        showcolor               = Compute("$0==1 ? $1 : 
$2",isstring,showbar,"black");
        showit                  = Compute("$0==1 ? $1 : 0",isint,showbar);
        showit                  = Compute("$0==1 || $1==1 ? 1 : 
0",showit,isstring);

   bar                  = ColorBar(colormap,shape=barshape,position=barposition,
                                                                          
colors=showcolor,min=min,max=max);
        bar                             = Route(showit,bar);

        // create glyph
        isstring                        = Inquire(showglyph,"is string");       
                
        isint                           = Inquire(showglyph,"is int");
        showcolor               = Compute("$0==1 ? $1 : 
$2",isstring,showglyph,"black");
        showit                  = Compute("$0==1 ? $1 : 0",isint,showglyph);
        showit                  = Compute("$0==1 || $1==1 ? 1 : 
0",showit,isstring);
        glyphs                  = 
AutoGlyph(slice,type=glyphtype,scale=glyphscale);
        glyphs                  = Color(glyphs,showcolor);
        glyphs                  = Route(showit,glyphs);
        
        // create lights
        showspotlight           = Compute("$0.x",showlight);
        showambientlight        = Compute("$0.y",showlight);
        spotlight                       = 
Light(lightposition,lightcolor,lightcamera);
        ambientlight            = AmbientLight(ambientlightcolor);
        light                                   = 
Route(showambientlight,ambientlight);
        spotlight                       = Route(showspotlight,spotlight);
        lights                          = Collect(spotlight,ambientlight);


   // set the camera

        // first get the default viewing directions
        view                                                                    
                        = Collect(slice,box);
   camera_auto                                                          = 
AutoCamera(view,direction);
        to_auto,from_auto,up_auto,width_auto    = 
GetCameraSettings(camera_auto);

        // see if the camera settings are given, if so: overule defaults
        isto                                    = Inquire(to,"is null");
        isfrom                          = Inquire(from,"is null");
        iswidth                         = Inquire(width,"is null");
        isup                                    = Inquire(up,"is null");
        iscamera                                = Inquire(camera,"is null");
        to                                              = 
Switch(isto+1,to,to_auto);
        from                                    = 
Switch(isfrom+1,from,from_auto);
        width                                   = 
Switch(iswidth+1,width,width_auto);
        up                                              = 
Switch(isup+1,up,up_auto);

        // now set the camera
        camera_user                     = 
Camera(to,from,width,resolution,aspect,up,
                                                                                
 background=background);

        // if a whole camera was give, urule everything
        camera                          = Switch(iscamera+1,camera,camera_user);

        // 
        isstring                        = Inquire(showaxes,"is string");        
                
        isint                           = Inquire(showaxes,"is int");
        showcolor               = Compute("$0==1 ? $1 : 
$2",isstring,showaxes,"black");
        showit                  = Compute("$0==1 ? $1 : 0",isint,showaxes);
        showit                  = Compute("$0==1 || $1==1 ? 1 : 
0",showit,isstring);
        ax                                      = 
AutoAxes(slice,camera,axlab,grid=0,
                                                                                
  labelscale=axesscale,colors=showcolor);
        ax                              = Route(showit,ax);

        // if there are no colors, don't show it
        showcolors              = Compute("$0==0? 0  : 1",showcolors);
        slice                           = Route(showcolors,slice);

   // collect all items of each individual image
   collect   = Collect(slice,imagecaption,bar,ax,addglyph,lines,box,grid,glyphs,
                                                          
xzero,yzero,zzero,lights,surface,boxplane);


   // render the images
   image            = Render(collect,camera)[cache:0];

   // finally: show it if title is set
        doshow = Compute("strlen($0)==0 ? 0 : 1",image_title);
   string = Format("X,,%s",image_title);
        imshow = Route(doshow,image);
   Display(imshow,where=string);
}
// dx script to create a serie of tiff images of rotating block 
include "show_plane.net";

// define macro to rotate dat
macro rotate(data,camera)
{
        // get current filenumber (0 for first call)
        nr,link = GetLocal(0);

        // updata loop 
        current = ForEachN(0,340,20);

        // create caption text
        text            = Format("%-5s%3d","angle:",current);

        // rotate data
        dataout = Rotate(data,1,current);

        // create image
        image           = show_plane(dataout, showcolors=0,camera=camera,
                                caption=text,captionposition=[.1,.05],
                                isosurface={.2},showbox=0,isosurfacecolor="red",
                                isosurfaceopacity=1,showlight=[1 
0],lightcolor="yellow");

        // show image
        Display(image);

        // create next filename and write it
        filename=Format("block_t%d",current);
        Echo("write file",filename);
        WriteImage(image,filename,"tiff");

        // updata file number
        nr                      = nr + 1;
        SetLocal(nr,link);
}

// allocate memory
data            = Construct([-5 -7 -10],[1 1 1],[10 15 20],0.0);

// generate some quadratic scalar function
data            = Mark(data,"positions");
data            = Compute("0.1*$0.x*$0.x + 0.4*$0.x*$0.z + 0.1*$0.y*$0.y 
",data);
data            = Remove(data,"saved data");

// rotate data under first angle
data            = Rotate(data,1,45);

// set camera position
camera  = AutoCamera(data,direction="diagonal",width=25,
                                                        background=[.273 .8 
.095],resolution=400,aspect=1);


// loop to rotate camera over the other angle
rotate(data,camera);

Reply via email to