Description: Strip any 3DEdge-related functionality from AFNI
 The license of this library makes it non-distributable, hence it cannot be
 shipped with the Debian package. This patch adds switches to all affected tool
 that allow 3DEdge-related functionality to be disabled. To maintain
 identical default behavior of upstream AFNI and the Debian version these
 switches are not enabled by default. That causes affected tools to fail by
 default, but ensures user awareness of this issue until it can be resolved
 properly.
Forwarded: Rick Reynolds <reynoldr@mail.nih.gov>
Author: Judd Storrs <storrsjm@email.uc.edu>, Michael Hanke <michael.hanke@gmail.com>
Last-Update: 2009-10-21
--- a/@auto_tlrc
+++ b/@auto_tlrc
@@ -304,6 +304,12 @@
          set ss_opt = "$ss_opt -no_avoid_eyes";      
          set donext = 0      
       endif
+      # add option, since Debian package has no edges3, due to licensing
+      # problems with it
+      if ($donext && "$argv[$cnt]" == "-no_use_edge") then
+         set ss_opt = "$ss_opt -no_use_edge";
+         set donext = 0
+      endif
       if ($donext == 1) then
          echo "Error: Option or parameter '$argv[$cnt]' not understood"
          goto END
@@ -1222,6 +1228,9 @@
 echo "      -no_avoid_eyes : An option that gets passed to 3dSkullStrip."
 echo "                       Use it when parts of the frontal lobes get clipped"
 echo "                       See 3dSkullStrip -help for more details."
+echo "      -no_use_edge   : An option that gets passed to 3dSkullStrip. Do not"
+echo "                       use edge detection to reduce leakage into meninges"
+echo "                       and eyes. See 3dSkullStrip -help for more details."
 echo "      -ncr           : 3dWarpDrive option -coarserot is now a default."
 echo "                       It will cause no harm, only good shall come of it."
 echo "                       -ncr is there however, should you choose NOT TO"
--- a/Makefile.INCLUDE
+++ b/Makefile.INCLUDE
@@ -11,8 +11,8 @@
 
 ## 07 Dec 2005: modify the include flags here
 
-INFLAGS  = $(IFLAGS) -Inifti/niftilib -Inifti/nifticdf -Inifti/znzlib -I3DEdge/src -Irickr $(USE_ZLIB) $(USE_GIFTI)
-ISFLAGS  = $(IFLAGS) -I../nifti/niftilib -I../nifti/nifticdf -I../nifti/znzlib -I../3DEdge/src -I../rickr $(USE_ZLIB)
+INFLAGS  = $(IFLAGS) -Inifti/niftilib -Inifti/nifticdf -Inifti/znzlib -Irickr $(USE_ZLIB) $(USE_GIFTI)
+ISFLAGS  = $(IFLAGS) -I../nifti/niftilib -I../nifti/nifticdf -I../nifti/znzlib -I../rickr $(USE_ZLIB)
 
 DOCS     = ../doc/ps/*.ps ../doc/README/README*                    \
            rickr/AFNI.changes.rickr rhammett/AFNI.changes.rhammett \
@@ -77,7 +77,7 @@
            3dDeconvolve_f 3dAnhist 3dAFNIto3D 3dUniformize 3dWarp nicat         \
            3dSpatNorm fftest serial_helper 3dDTeig 3dDWItoDT 3dWarpDrive        \
            nifti_tool 3dAllineate nifti1_test whereami plugout_drive            \
-           3dMedianFilter 3dretroicor 3dAFNItoNIML 3dAFNItoRaw im2niml 3dedge3  \
+           3dMedianFilter 3dretroicor 3dAFNItoNIML 3dAFNItoRaw im2niml          \
            DTIStudioFibertoSegments Dimon 3dLocalstat 3danisosmooth 3dmaxima    \
            3dTwotoComplex 3dInvFMRI 3dmatcalc 3dAcost 3dLocalBistat 3dFWHMx     \
            3dBlurToFWHM 1dSEM 3dDFT 3dSynthesize 1dMarry 3dEmpty 3dsvm          \
@@ -619,9 +619,10 @@
 	$(RM) $@
 	$(CC) -o 3dvolreg 3dvolreg.o $(LFLAGS) $(LLIBS)
 
-3dedge:3dedge.o
-	$(RM) $@
-	$(CC) -o 3dedge 3dedge.o $(LFLAGS) $(LLIBS)
+# Debian cannot have this due to licensing issues with edges3
+# 3dedge:3dedge.o
+#	$(RM) $@
+#	$(CC) -o 3dedge 3dedge.o $(LFLAGS) $(LLIBS)
 
 from3d:from3d.o
 	$(RM) $@
@@ -720,10 +721,11 @@
 	$(RM) $@
 	$(CC) -o 3dttest++ 3dttest++.o $(LFLAGS) $(LLIBS)
 
-3dedge3:lib3DEdge.a 3dedge3.o
-	$(RM) $@
-	$(CC) -o 3dedge3 3dedge3.o -I3DEdge/src            \
-              $(LFLAGS) -l3DEdge $(LLIBS)
+# Debian cannot have this due to licensing issues with edges3
+# 3dedge3:lib3DEdge.a 3dedge3.o
+#	$(RM) $@
+#	$(CC) -o 3dedge3 3dedge3.o -I3DEdge/src            \
+#             $(LFLAGS) -l3DEdge $(LLIBS)
 
 ### From Stephen Laconte
 3dsvm:svm/svm_common.c svm/svm_learn.c svm/3dsvm_common.c svm/svm_hideo.c svm/3dsvm.c
@@ -1540,7 +1542,7 @@
 	$(CP) -pr coxplot volpack moveup moveAFNI* eispack avovk                 ./afni_src
 	$(CP) -pr $(SCRIPTS) $(PY_DIR) $(R_DIR)                                  ./afni_src
 	$(CP) -pr gifsicledir qhulldir f2cdir mpeg_encodedir                     ./afni_src
-	$(CP) -pr 3DEdge netcdf-3.5.0 jpeg-6b niml Makefile_* nifti dlcompat     ./afni_src
+	$(CP) -pr        netcdf-3.5.0 jpeg-6b niml Makefile_* nifti dlcompat     ./afni_src
 	$(CP) -pr SUMA svm matlab rickr faces poems gifti ni_test_? README.*     ./afni_src
 	chmod -R ugo+rw                                                          ./afni_src
 	$(TAR) cf - afni_src | $(GZIP) -9v > afni_src.tgz
@@ -2291,8 +2293,9 @@
 #######
 # 3DEdge library files - make them and move them up here
 
-lib3DEdge.a:
-	( cd 3DEdge/src ; $(MAKE) clean lib3DEdge.a 'RM=$(RM)' 'AR=$(AR)' 'RANLIB=$(RANLIB)' 'CC=$(CCFAST)' 'IFLAGS=$(ISFLAGS)' 'LFLAGS=$(LFLAGS)' ; $(MV) *.a ../.. ; )
+# Debian cannot have this due to licensing issues with edges3
+# lib3DEdge.a:
+#	( cd 3DEdge/src ; $(MAKE) clean lib3DEdge.a 'RM=$(RM)' 'AR=$(AR)' 'RANLIB=$(RANLIB)' 'CC=$(CCFAST)' 'IFLAGS=$(ISFLAGS)' 'LFLAGS=$(LFLAGS)' ; $(MV) *.a ../.. ; )
 
 #######
 # Eispack and CDF library files - make them and move them up here
--- a/SUMA/SUMA_3dSkullStrip.c
+++ b/SUMA/SUMA_3dSkullStrip.c
@@ -13,6 +13,21 @@
       sts = SUMA_help_talk(ps);
       printf ( 
 "\n"
+"WARNING !! WARNING !! WARNING !! WARNING\n"
+"\n"
+"    THIS VERSION OF 3dSkullStrip HAS BEEN MODIFIED!\n"
+"\n"
+"    YOU MUST USE:   -no_use_edge\n"
+"    YOU CANNOT USE: -push_to_edge\n"
+"\n"
+"    A licensing issue required the -push_to_edge and -use_edge\n"
+"    options and the 3dedge3 program to be removed from the Debian\n"
+"    AFNI packages.\n"
+"\n"
+"    Unmodified binaries for your platform may be available from\n"
+"\n"
+"    http://afni.nimh.nih.gov/afni/download/afni/releases/latest \n"
+"\n"
 "Usage: A program to extract the brain from surrounding.\n"
 "  tissue from MRI T1-weighted images. The fully automated\n"
 "  process consists of three steps:\n"
@@ -1012,6 +1027,16 @@
       fprintf(SUMA_STDERR,"Error %s:\nCannot use -push_to_edge without -use_edge\n", FuncName);
       exit (1);      
    }
+
+   /* Can neither -use_edge nor -push_to_edge in debian package */
+   if (Opt->Use_emask) {
+      fprintf(SUMA_STDERR,"Error %s:\nCannot -use_edge with debian 3dSkullStrip\n", FuncName);
+      exit (1);
+   }
+   if (Opt->PushToEdge) {
+      fprintf(SUMA_STDERR,"Error %s:\nCannot -push_to_edge with debian 3dSkullStrip\n", FuncName);
+      exit (1);
+   }
    
    if (Opt->bot_lztclip < 0) {
       if (!Opt->Use_emask) Opt->bot_lztclip = 0.65;
@@ -1527,6 +1552,13 @@
       exit(1);
    }
 
+#if 1 /* Edges disabled for Debian package -- license problem with 3DEdge */
+   if (Opt->Use_emask) {
+      /* This should not be reached */
+      fprintf(SUMA_STDERR,"Error %s:\nCannot -use_edge with debian 3dSkullStrip\n", FuncName);
+      exit (1);
+   }
+#else
    /* calculate an edge mask ? */
    if (Opt->Use_emask) {
       float *emask_sort = NULL, PercRange[2]= { 10, 90 }, 
@@ -1653,7 +1685,8 @@
          }
       }
    } 
-  
+#endif /* Disabled for Debian package -- license problem with 3DEdge */
+
    if (Opt->blur_fwhm) {
      if (Opt->debug) fprintf (SUMA_STDERR,"%s: Blurring...\n", FuncName);
      EDIT_blur_volume(  DSET_NX(Opt->in_vol), 
@@ -2068,6 +2101,13 @@
       }
 
       PUSH_TO_EDGE:
+#if 1 /* Edges disabled for Debian package -- license problem with 3DEdge */
+      if (Opt->PushToEdge) {
+	/* This should not be reached */
+	fprintf(SUMA_STDERR,"Error %s:\nCannot -push_to_edge with debian 3dSkullStrip\n", FuncName);
+	exit (1);
+      }
+#else
       if (Opt->PushToEdge) {
          fprintf (SUMA_STDERR,"%s: Pushing to Edge ...\n", FuncName);
          ps->cs->kth = 1; /*make sure all gets sent at this stage */
@@ -2120,7 +2160,7 @@
          if (LocalHead) fprintf (SUMA_STDERR,"%s: Edge push correction  Done.\n", FuncName);
          ps->cs->kth = kth_buf; 
       }
-
+#endif /* Disabled for Debian package -- license problem with 3DEdge */
 
       BEAUTY:
       /* smooth the surface a bit */
--- a/SUMA/SUMA_BrainWrap.c
+++ b/SUMA/SUMA_BrainWrap.c
@@ -1,6 +1,8 @@
 #include "SUMA_suma.h"
 #include "../thd_brainormalize.h"
+#if 0 /* Disabled for Debian package -- license problem with 3DEdge */
 #include "extrema.h"
+#endif  /* Disabled for Debian package -- license problem with 3DEdge */
 
 static int InteractiveQuit;
 
@@ -3980,6 +3982,7 @@
    \param poutsetp (THD_3dim_dataset **)If not null, it will point to a dataset that contains
                                         the edges.
 */
+#if 0 /* Disabled for Debian package -- license problem with 3DEdge */
 SUMA_Boolean SUMA_3dedge3(THD_3dim_dataset *inset, float *emask, THD_3dim_dataset **poutsetp)
 {
    static char FuncName[]={"SUMA_3dedge3"};
@@ -4200,3 +4203,4 @@
       
    SUMA_RETURN(YUP);
 }
+#endif /* Disabled for Debian package -- license problem with 3DEdge */
--- a/SUMA/SUMA_BrainWrap.h
+++ b/SUMA/SUMA_BrainWrap.h
@@ -35,7 +35,9 @@
 int SUMA_DidUserQuit(void);
 EDIT_options *SUMA_BlankAfniEditOptions(void);
 void *SUMA_Push_Nodes_To_Hull(SUMA_SurfaceObject *SO, SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt, SUMA_COMM_STRUCT *cs, int N_itermax);
+#if 0 /* Disabled for Debian package -- license problem with 3DEdge */
 SUMA_Boolean SUMA_3dedge3(THD_3dim_dataset *inset, float *emask, THD_3dim_dataset **poutsetp);
+#endif /* Disabled for Debian package -- license problem with 3DEdge */
 
 /*!
    SUMA_WRAP_BRAIN_SMOOTH(niter, bufp1, bufp2);
--- a/SUMA/SUMA_Makefile_NoDev
+++ b/SUMA/SUMA_Makefile_NoDev
@@ -3,14 +3,14 @@
 MAKE = make
 SUMALIB = libSUMA.a
 SUMAGTSLIB = libSUMAGTS.a
-AFNILIB = -lmrix -lcoxplot -lmri -lf2c -l3DEdge
+AFNILIB = -lmrix -lcoxplot -lmri -lf2c
 MAINCODE = SUMA
 SUMALIBLIST = libSUMA.a libglut.a libply.a 
 GLWLIB = libGLws.a
 
 ## 07 Dec 2005 -- Modify include path (RWCox)
 
-SUMA_INPATH = ${SUMA_INCLUDE_PATH} -I../nifti/niftilib -I../nifti/nifticdf -I../nifti/znzlib -I../3DEdge/src -I../rickr
+SUMA_INPATH = ${SUMA_INCLUDE_PATH} -I../nifti/niftilib -I../nifti/nifticdf -I../nifti/znzlib -I../rickr
 
 SUMA_SRCS = SUMA_trackball.c SUMA_SVmanip.c SUMA_input.c \
 		 SUMA_MiscFunc.c SUMA_IV_XYZextract.c	\
@@ -292,7 +292,7 @@
 	$(RM) $@
 	${CC} -DSUMA_COMPILED  ${CCOPT} ${WARNOPT} -o $@ $(AFWARPOBJS) \
 		${AFNI_OBJS} SUMA_3dSkullStrip.c ${SUMA_INPATH} ${SUMA_LINK_PATH} 	\
-		${AFNI_3dOBJS} MarchingCubes/debug/MarchingCubes.o	-I../3DEdge/src -l3DEdge\
+		${AFNI_3dOBJS} MarchingCubes/debug/MarchingCubes.o	\
 		${SUMALIBLIST} ${AFNILIB} ${ZLIB} ${SUMA_LINK_LIB}
 
 3dGenPriors: SUMA_3dGenPriors.c libSUMA.a
--- a/@RetinoProc
+++ b/@RetinoProc
@@ -247,6 +247,7 @@
                         -epi  EpiAnatRef+orig   \
                         -AddEdge -anat2epi \
                         -epi_base 0 \
+                        -skullstrip_opts '-no_use_edge' \
                         -suffix RetinoProc
       3drename *RetinoProc*HEAD AVol@Epi
    else
