[vtk-developers] [Insight-users] bash script to search example files for terms

Darren Weber darren.weber.lists at gmail.com
Tue Oct 13 14:17:39 EDT 2009


Hi Andrew,

This version below uses 'grep' options to replace the 'find' utility; the
grep options provide a case-insensitive search (-i) and recursion through
directories (-r), with an include pattern to identify file types (.cxx,
.tcl, .py).  The script now has a 'continue' statement if the vtkPath
doesn't exist.  (I don't have commit rights to the cvs.)


#####BEGIN SCRIPT
#!/bin/bash

if [ $# -lt 1 ]; then
    echo "$0 'search term' ['search term' ...]"
    exit 1
fi

vtkExamplePath="/opt/local/share/vtk/examples"
vtkTestingPath="/opt/local/share/vtk/testing"

for term in $@; do
    echo
    echo "Search term: ${term}"
    for vtkPath in "${vtkExamplePath}" "${vtkTestingPath}" ; do
        if [ ! -d ${vtkPath} ]; then
            echo "Path not found: ${vtkPath}"
            continue
        fi
        echo "Searching VTK files in: ${vtkPath}"
        grep -l -E -i -r --include='*.cxx' --regexp=${term} ${vtkPath}
        grep -l -E -i -r --include='*.tcl' --regexp=${term} ${vtkPath}
        grep -l -E -i -r --include='*.py'  --regexp=${term} ${vtkPath}
    done
done
#####END SCRIPT


This is an example run on my OSX-MacPorts system (I maintain the vtk-devel
port in MacPorts, currently at ver 5.4.2):

$ vtkSearchExamples.bash 'vtkIdentityTransform' 'vtkImageClip'

Search term: vtkIdentityTransform
Searching VTK files in: /opt/local/share/vtk/examples
Searching VTK files in: /opt/local/share/vtk/testing
/opt/local/share/vtk/testing/Graphics/Testing/Tcl/TransformPolyData.tcl

Search term: vtkImageClip
Searching VTK files in: /opt/local/share/vtk/examples
/opt/local/share/vtk/examples/ImageProcessing/Tcl/HistogramWidget.tcl
Searching VTK files in: /opt/local/share/vtk/testing
/opt/local/share/vtk/testing/VolumeRendering/Testing/Cxx/TestMinIntensityRendering.cxx
/opt/local/share/vtk/testing/Graphics/Testing/Tcl/contour2DAll.tcl
/opt/local/share/vtk/testing/Graphics/Testing/Tcl/contour3DAll.tcl
/opt/local/share/vtk/testing/Graphics/Testing/Tcl/imageMCAll.tcl
/opt/local/share/vtk/testing/Graphics/Testing/Tcl/sync3dAll.tcl
/opt/local/share/vtk/testing/Graphics/Testing/Tcl/testDataSetTriangleFilter.tcl
/opt/local/share/vtk/testing/Imaging/Testing/Tcl/TestAccumulate.tcl
/opt/local/share/vtk/testing/Imaging/Testing/Tcl/TestGradientMagnitude2.tcl
/opt/local/share/vtk/testing/Imaging/Testing/Tcl/TestSkeleton2D.tcl
/opt/local/share/vtk/testing/Parallel/Testing/Tcl/TestBranchExtentTranslator.tcl




Regards,
Darren






On Mon, Oct 12, 2009 at 10:23 PM, Andrew Maclean <a.maclean at cas.edu.au>wrote:

>  Hi Darren,
>
>   It is in VTK/Examples.
>
>    I modified the script slightly.
>
>
>
> Regards
>
>    Andrew
>
>
>
>
>
> *From:* Darren Weber [mailto:darren.weber.lists at gmail.com]
> *Sent:* Tuesday, 13 October 2009 14:24
> *To:* a.maclean at cas.edu.au
> *Cc:* Luis Ibanez; VTK Developers; ITK Users
> *Subject:* Re: [Insight-users] bash script to search example files for
> terms
>
>
>
>
>
> On Mon, Oct 12, 2009 at 7:50 PM, Andrew Maclean <andrew.amaclean at gmail.com>
> wrote:
>
> Could this script with appropriate modifications also be added to VTK?
> It strikes me as useful.
>
>
>
> Sure, that's just a change to the search paths (and a slight hack with
> 'find' to get all the files, which might be a better solution in the itk
> version too; see the script details below).  Note that the file attribute on
> the script file is executable and I keep the script below in
> ${HOME}/bin/vtkSearchExamples.bash
>
> This is an example run on my system (the script attached is suited to my
> install paths):
>
> $ vtkSearchExamples.bash 'vtkIdentityTransform' 'vtkImageClip'
>
> Search term: vtkIdentityTransform
> Searching VTK files in: /opt/local/share/vtk/examples
> Searching VTK files in: /opt/local/share/vtk/testing
> /opt/local/share/vtk/testing/Graphics/Testing/Tcl/TransformPolyData.tcl
>
> Search term: vtkImageClip
> Searching VTK files in: /opt/local/share/vtk/examples
> /opt/local/share/vtk/examples/ImageProcessing/Tcl/HistogramWidget.tcl
> Searching VTK files in: /opt/local/share/vtk/testing
>
> /opt/local/share/vtk/testing/VolumeRendering/Testing/Cxx/TestMinIntensityRendering.cxx
> /opt/local/share/vtk/testing/Graphics/Testing/Tcl/contour2DAll.tcl
> /opt/local/share/vtk/testing/Graphics/Testing/Tcl/contour3DAll.tcl
> /opt/local/share/vtk/testing/Graphics/Testing/Tcl/imageMCAll.tcl
> /opt/local/share/vtk/testing/Graphics/Testing/Tcl/sync3dAll.tcl
>
> /opt/local/share/vtk/testing/Graphics/Testing/Tcl/testDataSetTriangleFilter.tcl
> /opt/local/share/vtk/testing/Imaging/Testing/Tcl/TestAccumulate.tcl
> /opt/local/share/vtk/testing/Imaging/Testing/Tcl/TestGradientMagnitude2.tcl
> /opt/local/share/vtk/testing/Imaging/Testing/Tcl/TestSkeleton2D.tcl
>
> /opt/local/share/vtk/testing/Parallel/Testing/Tcl/TestBranchExtentTranslator.tcl
>
>
>   #######BEGIN SCRIPT
> #!/bin/bash
>
> if [ $# -lt 1 ]; then
>     echo "$0 'search term' ['search term' ...]"
>     exit 1
> fi
>
> vtkExamplePath="/opt/local/share/vtk/examples"
> vtkTestingPath="/opt/local/share/vtk/testing"
>
> for term in $@; do
>     echo
>     echo "Search term: ${term}"
>     for vtkPath in "${vtkExamplePath}" "${vtkTestingPath}" ; do
>         if [ ! -d ${vtkPath} ]; then
>             echo "Path not found: ${vtkPath}"
>         fi
>         echo "Searching VTK files in: ${vtkPath}"
>         cxxFiles=$(find ${vtkPath} -name "*.cxx")
>         grep -l -E -e ${term} ${cxxFiles}
>         tclFiles=$(find ${vtkPath} -name "*.tcl")
>         grep -l -E -e ${term} ${tclFiles}
>         pyFiles=$(find ${vtkPath} -name "*.py")
>         grep -l -E -e ${term} ${pyFiles}
>     done
> done
> #######END SCRIPT
>
>
> Again, feel free to incorporate this into the VTK cvs, with suitable
> open-source license that's compatible with vtk.
>
> Take care,
> Darren
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20091013/b5ed9bff/attachment.html>


More information about the vtk-developers mailing list