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

VisualizationAids.cpp

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00020 #include <ImLib3D/VisualizationAids.hpp>
00021 #include<ImLib3D/Draw.hpp>
00022 
00023 void
00024 IP3D::TransformRectangularGrid(Image3Df& image, const Field3Df& field, const Size3D masksize, bool bAverageField)
00025 {
00026     //Imagesize 
00027     // at the moment I (also) require image size to equal field size
00028     if (image.Size() != field.Size())
00029     {
00030         cout << "field size: " << field.Size() << endl;;
00031         cout << "image size: " << image.Size() << endl;;
00032         ThrowError("IP3D::TransformRectangularGrid ERROR field size must equal image size");
00033     }
00034 
00035     //center of mask 
00036     if (!(masksize.width%2 &&
00037           masksize.height%2 &&
00038           masksize.depth%2))
00039     {
00040         ThrowError("IP3D::TransformRectangularGrid ERROR masksize must have only odd sides (for centering)");
00041     }
00042     Vect3Df center(masksize.width/2, masksize.height/2, masksize.depth/2);
00043 
00044     //Create a subsampled vector field with average vectors:
00045     Field3Df averageField(field.Width()/masksize.width, field.Height()/masksize.height, field.Depth()/masksize.depth);
00046     Field3Df::iteratorXYZ pav;
00047     for (pav=averageField.begin(); pav!=averageField.end(); pav++)
00048     {
00049         if (bAverageField)
00050         {
00051             cout << "Averaging vectors" << endl;
00052             Vect3Df meanVec(0,0,0);
00053             RectZone3Di zone(pav.x*masksize.width, pav.y*masksize.height, pav.z*masksize.depth,
00054                              ((pav.x+1)*masksize.width)-1, ((pav.y+1)*masksize.height)-1, ((pav.z+1)*masksize.depth)-1);
00055             Field3Df::const_iteratorZone p(zone);
00056             for (p=field.begin();p!=field.end();++p)
00057             {
00058                 meanVec += (*p);
00059             }
00060             meanVec/=(masksize.width*masksize.height*masksize.depth);
00061             (*pav) = meanVec;
00062         }
00063         else
00064         {
00065             (*pav) = field(rint(Vect3Df(pav.x*masksize.width, pav.y*masksize.height, pav.z*masksize.depth)+center));
00066         }
00067     }
00068 
00069     //Now draw lines from the endpoints of the vectors
00070     //This must be done in each direction (X, Y and Z)
00071     int x, y, z;
00072 
00073     //x-direction:
00074     cout << "Drawing x-direction connections" << endl;
00075     for (y=0;y<averageField.Height();y++)
00076     {
00077         for (z=0;z<averageField.Depth();z++)
00078         {
00079             Vect3Df P0(averageField(0,y,z));
00080             Vect3Df PB0(Vect3Df(0,y*masksize.height,z*masksize.depth)+center);
00081             for (x=1;x<averageField.Width();x++)
00082             {
00083                 Vect3Df P1(averageField(x,y,z));
00084                 Vect3Df PB1(Vect3Df(x*masksize.width,y*masksize.height,z*masksize.depth)+center);
00085                 Segment3D segment(P0+PB0,P1+PB1);
00086                 IP3D::DrawSegment3D(image, segment, Pen<float>(255), image);
00087                 P0=P1;
00088                 PB0=PB1;
00089             }
00090         }
00091     }
00092 
00093     //y-direction:
00094     cout << "Drawing y-direction connections" << endl;
00095     for (x=0;x<averageField.Width();x++)
00096     {
00097         for (z=0;z<averageField.Depth();z++)
00098         {
00099             Vect3Df P0(averageField(x,0,z));
00100             Vect3Df PB0(Vect3Df(x*masksize.width,0,z*masksize.depth)+center);
00101             for (y=1;y<averageField.Height();y++)
00102             {
00103                 Vect3Df P1(averageField(x,y,z));
00104                 Vect3Df PB1(Vect3Df(x*masksize.width,y*masksize.height,z*masksize.depth)+center);
00105                 Segment3D segment(P0+PB0,P1+PB1);
00106                 IP3D::DrawSegment3D(image, segment,Pen<float>(255), image);
00107                 P0=P1;
00108                 PB0=PB1;
00109             }
00110         }
00111     }
00112 
00113     //z-direction:
00114     cout << "Drawing z-direction connections" << endl;
00115     for (x=0;x<averageField.Width();x++)
00116     {
00117         for (y=0;y<averageField.Height();y++)
00118         {
00119             Vect3Df P0(averageField(x,y,0));
00120             Vect3Df PB0(Vect3Df(x*masksize.width,y*masksize.height,0)+center);
00121             for (z=1;z<averageField.Depth();z++)
00122             {
00123                 Vect3Df P1(averageField(x,y,z));
00124                 Vect3Df PB1(Vect3Df(x*masksize.width,y*masksize.height,z*masksize.depth)+center);
00125                 Segment3D segment(P0+PB0,P1+PB1);
00126                 IP3D::DrawSegment3D(image, segment,Pen<float>(255), image);
00127                 P0=P1;
00128                 PB0=PB1;
00129             }
00130         }
00131     }
00132 }

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