Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Example7.cpp

00001 #include<ImLib3D/ImLib3D.hpp>
00002 #include<ImLib3D/ImLib3D.hpp>
00003 #include<ImLib3D/TestPatterns.hpp>
00004 #include<algorithm>
00005 #include<functional>
00006 #include<math.h>
00007 
00008 // Demonstrates use of stl algorithms
00009 
00010 // this is a class for accumulating a result sum
00011 struct Adder : public unary_function<double, void>
00012 {
00013     Adder() : sum(0) {}
00014     double sum;
00015     void operator()(double x) { sum += x; }
00016 };
00017 
00018 float myfct(float x){return 10*cos(M_PI*x);}
00019 
00020 int
00021 main(int argc,char **argv)
00022 {
00023     // Declare a floating point image
00024     Image3Df ima(100,100,100);
00025 
00026     // fill example
00027     fill(ima.begin(),ima.end(),3);
00028 
00029     // for_each example
00030     Adder result = for_each(ima.begin(), ima.end(), Adder()); 
00031     cout << "The sum is " << result.sum << endl;
00032 
00033     // another for_each example
00034     for_each(ima.begin(), ima.end(), ptr_fun(myfct)); 
00035 
00036     // a find example
00037     ima(10,10,10)=1000;
00038     Image3Df::iterator a=find(ima.begin(), ima.end(),1000); 
00039     cout << "found value at:" << a.ComputePosition() << endl;
00040 
00041     // a sort example
00042     IP3D::NoiseGaussian(Size3D(10,10,10),ima);
00043     sort(ima.begin(),ima.end());
00044 }

Generated on Fri Jun 17 13:36:01 2005 for ImLib3D by  doxygen 1.4.2