00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00027
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
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
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
00070
00071 int x, y, z;
00072
00073
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
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
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 }