[Insight-users] How to get a progess from an iterator?
lynx.abraxas at freenet.de
lynx.abraxas at freenet.de
Wed Dec 9 11:52:10 EST 2009
On 09/12/09 09:51:12, Luis Ibanez wrote:
> Hi Lynx,
>
> Some compilers will warn you about uninitialized objects.
>
> In GCC you could use the flag : -Wuninitialized
>
> that is one of the options turned on with : -Wall
>
> http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
>
> Note that you have to use it in combination with -O.
Thanks again Luis for Your answer. I'm sorry I forgot to paste the code (it's from the users guide). If I compile
const unsigned int Dimension = 3;
typedef itk::Image<IPixelType, Dimension> ImageType;
typedef itk::Image<OPixelType, Dimension> OImageType;
typedef itk::ConstShapedNeighborhoodIterator<ImageType> ShapedNeighborhoodIteratorType;
typedef itk::ImageRegionIterator<ImageType> IteratorType;
typedef itk::ImageRegionIterator<OImageType> OIteratorType;
OIteratorType out;
.
.
.
for ( fit=faceList.begin(); fit != faceList.end(); ++fit){
ShapedNeighborhoodIteratorType it( radius, reader->GetOutput(), *fit );
it.OverrideBoundaryCondition(&BC); // assign the boundary condition
out = OIteratorType( output, *fit );
// Creates a circular structuring element by activating all the pixels less
// than radius distance from the center of the neighborhood.
ShapedNeighborhoodIteratorType::OffsetType off;
for (float y = -rad; y <= rad; y++){
for (float x = -rad; x <= rad; x++){
float dis = vcl_sqrt( x*x + y*y);
if (dis <= rad){
off[0] = static_cast<int>(x);
off[1] = static_cast<int>(y);
it.ActivateOffset(off); //if segfaults comment this! Why???
}
}
this with:
[100%] Building CXX object CMakeFiles/mean_masked02.dir/mean_masked02.cxx.o
/usr/local/bin/c++ -O -Wall -I/usr/local/include/InsightToolkit/Numerics/Statistics/ -ftemplate-depth-50 -Wall -Wno-deprecated -I/usr/local/include -I/usr/local/include/InsightToolkit/Review/Statistics -I/usr/local/include/InsightToolkit/Review -I/usr/local/include/InsightToolkit/Patented -I/usr/local/include/InsightToolkit/gdcm/src -I/usr/local/include/InsightToolkit/gdcm -I/usr/local/include/InsightToolkit/Utilities/vxl/core -I/usr/local/include/InsightToolkit/Utilities/vxl/vcl -I/usr/local/include/InsightToolkit/Utilities/vxl/v3p/netlib -I/usr/local/include/InsightToolkit/Utilities -I/usr/local/include/InsightToolkit/Utilities/itkExtHdrs -I/usr/local/include/InsightToolkit/Utilities/nifti/znzlib -I/usr/local/include/InsightToolkit/Utilities/nifti/niftilib -I/usr/local/include/InsightToolkit/Utilities/expat -I/usr/local/include/InsightToolkit/Utilities/DICOMParser -I/usr/local/include/InsightToolkit/Utilities/NrrdIO -I/usr/local/include/InsightToolkit/Utilities/MetaIO -I/usr/local/include/InsightToolkit/SpatialObject -I/usr/local/include/InsightToolkit/Numerics/NeuralNetworks -I/usr/local/include/InsightToolkit/Numerics/FEM -I/usr/local/include/InsightToolkit/IO -I/usr/local/include/InsightToolkit/Numerics -I/usr/local/include/InsightToolkit/Common -I/usr/local/include/InsightToolkit/BasicFilters -I/usr/local/include/InsightToolkit/Algorithms -I/usr/local/include/InsightToolkit -I/net/home/ftd/localusr/lib/InsightToolkit -o CMakeFiles/mean_masked02.dir/mean_masked02.cxx.o -c /home/lynx/itk/simple/mean_masked02.cxx
Linking CXX executable mean_masked02
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/mean_masked02.dir/link.txt --verbose=1
/usr/local/bin/c++ -O -Wall -I/usr/local/include/InsightToolkit/Numerics/Statistics/ -ftemplate-depth-50 -Wall -Wno-deprecated CMakeFiles/mean_masked02.dir/mean_masked02.cxx.o -o mean_masked02 -rdynamic -L/usr/local/lib/InsightToolkit -lITKAlgorithms -lITKIO -lITKStatistics -litkNetlibSlatec -lITKNumerics /usr/local/lib/libfftw3.a -lITKNrrdIO -litkgdcm -litkjpeg8 -litkjpeg12 -litkjpeg16 -litkopenjpeg /usr/local/lib/libuuid.so /usr/local/lib/libpng.so /usr/local/lib/libtiff.so -lITKSpatialObject -lITKCommon -litkvnl_inst -litkvnl_algo -litkv3p_netlib -litkvnl -litkvcl -lm -lpthread -lITKMetaIO -litksys -ldl -lITKDICOMParser -lITKEXPAT -lITKniftiio -lITKznz -lz -lm -Wl,-rpath,/usr/local/lib/InsightToolkit:/usr/local/lib
I don't get any error at compile time but the program segfaults because the
third dimension was not initialized. If I change it to this:
for (float z = -rad; z <= rad; z++){
for (float y = -rad; y <= rad; y++){
for (float x = -rad; x <= rad; x++){
float dis = vcl_sqrt( x*x + y*y + z*z);
if (dis <= rad){
off[0] = static_cast<int>(x);
off[1] = static_cast<int>(y);
off[2] = static_cast<int>(z);
it.ActivateOffset(off); //if segfaults comment this!
Why???
//because 3 dim (z, off[2]) was missing!!!!!!!
}
}
}
}
all is fine.
> About your second question:
>
> Could you please post a more precise example of
> what you would like to do for initializing a
> ShapedNeighborhoodIterator in 2D and/or 3D ?
I mean the above initialization of the active neighbours. For 2D there must be
only two for-loops for 3D input it needs three loops. I don't know how I could
create a template function of this for the use as in:
> > int main( int argc, char *argv[] ){
> >
> > if ( argc < 8 ){
> > std::cerr << "Missing parameters. " << std::endl;
> > std::cerr << "Usage: " << std::endl;
> > std::cerr << argv[0]
> > << "ImageDimension inputImageFile outputImageFile
element_radius foreground background maskground"
> > << std::endl;
> > return -1;
> > }
> >
> > unsigned int dim;
> >
> > dim= atoi(argv[1]);
> > argv++; //shift();
> > argc--;
> >
> > switch(dim)
> > {
> > case 2:
> > masked_mean_filter<2>( argc, argv );
> > break;
> > case 3:
> > masked_mean_filter<3>( argc, argv );
> > break;
> > default:
> > std::cerr << "Unsupported dimension" << std::endl;
> > exit( EXIT_FAILURE );
> > }
> > }
> >
Is there any way to do so?
Many thanks,
Lynx
More information about the Insight-users
mailing list