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  

edt_buildmask.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #include "mrilib.h"
00008 
00009 /*-----------------------------------------------------------------------------
00010    Routine to make a cluster that is a mask of points closer than max_dist.
00011 
00012       nx, ny, nz   = number of voxels along each axis
00013       dx, dy, dz   = voxel dimensions
00014       max_dist     = maximum distance for a point to be included in the mask
00015 
00016    Date   :  11 September 1996
00017 
00018    To correct error due to abiguity in identification of clusters,
00019    voxel coordinates are now stored as 3 separate short integers.
00020    BDW  06 March 1997
00021 
00022    30 Apr 2002: max_dist input as <= 0 now gives NN connectivity
00023 -----------------------------------------------------------------------------*/
00024 
00025 MCW_cluster * MCW_build_mask (int nx, int ny, int nz,
00026                               float dx, float dy, float dz,
00027                               float max_dist)
00028 {
00029    int ii, jj, kk, idx, jdy, kdz, nxy, nxyz, ijkma, mnum;
00030    float xq, yq, zq, dist_q;
00031    MCW_cluster * mask;
00032 
00033 ENTRY("MCW_build_mask") ;
00034 
00035    if( max_dist <= 0.0 ){                   /* 30 Apr 2002 */
00036      dx = dy = dz = 1.0 ; max_dist = 1.01 ;
00037    }
00038 
00039    idx = max_dist / dx ; jdy = max_dist / dy ; kdz = max_dist / dz ;
00040 
00041 #ifdef CLUST_DEBUG
00042 printf("MCW_find_clusters: idx=%d jdy=%d kdz=%d\n",idx,jdy,kdz) ;
00043 #endif
00044 
00045    if( (idx < 1 && jdy < 1 && kdz < 1) || (idx < 0 || jdy < 0 || kdz < 0 ) ){
00046       fprintf(stderr,"*** Illegal dimensions input to MCW_build_mask:\n"
00047                      "*** dx=%g dy=%g dz=%g max_dist=%g\n",
00048                      dx,dy,dz,max_dist ) ;
00049       RETURN( NULL );
00050    }
00051 
00052    INIT_CLUSTER(mask) ;
00053 
00054    dist_q = max_dist * max_dist ;
00055    nxy = nx*ny ; nxyz = nxy * nz ;
00056 
00057    for( kk=-kdz ; kk <= kdz ; kk++ ){
00058       zq = (kk*dz) * (kk*dz) ;
00059       for( jj=-jdy ; jj <= jdy ; jj++ ){
00060          yq = zq + (jj*dy) * (jj*dy) ;
00061          for( ii=-idx ; ii <= idx ; ii++ ){
00062             xq = yq + (ii*dx)*(ii*dx) ;
00063             if( xq <= dist_q && xq > 0.0 ){
00064               ADDTO_CLUSTER( mask , ii, jj, kk, 0 ) ;
00065             }
00066          }
00067       }
00068    }
00069 
00070 #ifdef CLUST_DEBUG
00071 printf("  mask size = %d\n",mask->num_pt ) ;
00072 #endif
00073 
00074    mnum = mask->num_pt ;
00075    if( mnum < 2 ){
00076       KILL_CLUSTER(mask) ;
00077       fprintf(stderr,
00078               "*** MCW_build_mask error: mask has only %d elements!\n",mnum);
00079       RETURN( NULL );
00080    }
00081 
00082    RETURN (mask);
00083 }
 

Powered by Plone

This site conforms to the following standards: