Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

zzclip.c

Go to the documentation of this file.
00001 /* zzclip.f -- translated by f2c (version 19961017).
00002    You must link the resulting object file with the libraries:
00003         -lf2c -lm   (in that order)
00004 */
00005 
00006 #include "f2c.h"
00007 
00008 /* Common Block Declarations */
00009 
00010 extern struct {
00011     real xpgmin, ypgmin, xpgmax, ypgmax, xclbot, yclbot, xcltop, ycltop, xbot,
00012              ybot, xtop, ytop, xmin, ymin, xmax, ymax;
00013     integer ixcoor, iycoor;
00014     real alphxx, betaxx, alphyy, betayy, tmajx, tminx, tmajy, tminy;
00015     integer majrx, minrx, majry, minry, isizx, isizy;
00016     real xphold, yphold;
00017 } zzzplt_;
00018 
00019 #define zzzplt_1 zzzplt_
00020 
00021 extern struct {
00022     real xphmax, yphmax;
00023     integer ixpmax, iypmax;
00024     real xpscal, ypscal;
00025     integer iflip, nplotr;
00026     char cfile[64];
00027 } zzpltr_;
00028 
00029 #define zzpltr_1 zzpltr_
00030 
00031 
00032 
00033 
00034 /* Subroutine */ int zzclip_(real *x1in, real *y1in, real *x2in, real *y2in)
00035 {
00036     static real temp, slope, x1, x2, y1, y2, dx, dy;
00037     static logical linter;
00038 
00039 
00040 /*  Clip the input line to the predefined plotting region. */
00041 
00042 /*  INPUTS */
00043 /*  ------ */
00044 /*  X1IN   = start X-coordinate of line  (physical coordinates) */
00045 /*  Y1IN   = start Y-coordinate of line */
00046 /*  X2IN   = end X-coordinate of line */
00047 /*  Y2IN   = end Y-coordinate of line */
00048 
00049 /*  OUTPUTS */
00050 /*  ------- */
00051 /*  same as above but clipped so that the line fits into the plotting */
00052 /*  region defined by calling SETW. */
00053 
00054 /*  If the line falls entirely outside of the plotting region, then */
00055 /*  X1IN is returned as -1.E+38. */
00056 /* .......................................................................
00057  */
00058 
00059 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00060  */
00061 /*  Check to see if line can be thrown out as being totally out of */
00062 /*  the plotting region. */
00063 
00064 
00065 /*  Internal Data for PLOTPAK */
00066 
00067     if (dmax(*x1in,*x2in) < zzzplt_1.xclbot || dmin(*x1in,*x2in) > 
00068             zzzplt_1.xcltop || dmax(*y1in,*y2in) < zzzplt_1.yclbot || dmin(*
00069             y1in,*y2in) > zzzplt_1.ycltop) {
00070 
00071         *x1in = -1e38f;
00072         goto L8000;
00073     }
00074 
00075 /*  Copy input coordinates to local variables, making sure */
00076 /*  that X1 .LE. X2 by interchanging the points if necessary. */
00077 
00078     linter = *x1in > *x2in;
00079     if (linter) {
00080         x1 = *x2in;
00081         x2 = *x1in;
00082         y1 = *y2in;
00083         y2 = *y1in;
00084     } else {
00085         x1 = *x1in;
00086         x2 = *x2in;
00087         y1 = *y1in;
00088         y2 = *y2in;
00089     }
00090 
00091 /*  Clip line in X direction */
00092 
00093     dx = x2 - x1;
00094     if (dx > 0.f) {
00095 /*  only clip if line has some X range */
00096         slope = (y2 - y1) / dx;
00097         if (x1 < zzzplt_1.xclbot) {
00098 /*  intercept of line at left side */
00099             y1 += slope * (zzzplt_1.xclbot - x1);
00100             x1 = zzzplt_1.xclbot;
00101         }
00102         if (x2 > zzzplt_1.xcltop) {
00103 /*  intercept at right */
00104             y2 += slope * (zzzplt_1.xcltop - x2);
00105             x2 = zzzplt_1.xcltop;
00106         }
00107     }
00108 
00109 /*  Check line again to see if it falls outside of plot region. */
00110 
00111     if (dmax(y1,y2) < zzzplt_1.yclbot || dmin(y1,y2) > zzzplt_1.ycltop) {
00112         *x1in = -1e38f;
00113         goto L8000;
00114     }
00115 
00116 /*  Clip Y-direction.  To do this, must have Y1 .LE. Y2 */
00117 
00118     if (y1 > y2) {
00119         temp = x1;
00120         x1 = x2;
00121         x2 = temp;
00122         temp = y1;
00123         y1 = y2;
00124         y2 = temp;
00125 
00126         linter = ! linter;
00127     }
00128 
00129     dy = y2 - y1;
00130     if (dy > 0.f) {
00131 /*  only clip if line has some Y range */
00132         slope = (x2 - x1) / dy;
00133         if (y1 < zzzplt_1.yclbot) {
00134 /*  intercept of line at bottom */
00135             x1 += slope * (zzzplt_1.yclbot - y1);
00136             y1 = zzzplt_1.yclbot;
00137         }
00138         if (y2 > zzzplt_1.ycltop) {
00139 /*  intercept at top */
00140             x2 += slope * (zzzplt_1.ycltop - y2);
00141             y2 = zzzplt_1.ycltop;
00142         }
00143     }
00144 
00145 /*  Line is now guaranteed to be totally inside the plot region. */
00146 /*  Copy local clipped coordinates to output values and return. */
00147 /*  Note that we must restore points to original input order. */
00148 
00149     if (linter) {
00150         *x1in = x2;
00151         *x2in = x1;
00152         *y1in = y2;
00153         *y2in = y1;
00154     } else {
00155         *x1in = x1;
00156         *y1in = y1;
00157         *x2in = x2;
00158         *y2in = y2;
00159     }
00160 
00161 L8000:
00162     return 0;
00163 } /* zzclip_ */
00164 
 

Powered by Plone

This site conforms to the following standards: