00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <algorithm>
00042
00043 #include <qgarlib/Dist8cBlackCCImage.H>
00044 #include <qgarlib/GenImage.H>
00045
00046
00047
00048 namespace qgar
00049 {
00050
00051
00052
00053
00054
00055 Dist8cBlackCCImage::Dist8cBlackCCImage(const BinaryImage& anImg)
00056
00057 : GreyLevelImage(anImg)
00058
00059 {
00060
00061 int pixsize = _width * _height;
00062
00063 BinaryImage::value_type* pMapCurr = _pPixMap;
00064
00065
00066 for (int iCnt = 0 ; iCnt < _width ; ++iCnt)
00067 {
00068 *pMapCurr = 0;
00069 ++pMapCurr;
00070 }
00071
00072
00073 for (int iCnt = 1 ; iCnt < (_height - 1) ; ++iCnt, pMapCurr += _width)
00074 {
00075 *pMapCurr = 0;
00076 *(pMapCurr + _width - 1) = 0;
00077 }
00078
00079
00080 for (int iCnt = 0 ; iCnt < _width ; ++iCnt)
00081 {
00082 *pMapCurr = 0;
00083 ++pMapCurr;
00084 }
00085
00086
00087 pMapCurr = _pPixMap + _width + 1;
00088
00089 for (int iCnt = 1 ; iCnt < _height ; ++iCnt)
00090 {
00091 for (int jCnt = 1 ; jCnt < _width; ++jCnt, ++pMapCurr)
00092 {
00093 if (*pMapCurr != 0)
00094 {
00095 *pMapCurr = 1 + std::min(std::min(*(pMapCurr - 1),
00096 *(pMapCurr - _width - 1)),
00097 std::min(*(pMapCurr - _width),
00098 *(pMapCurr - _width + 1)));
00099 }
00100 }
00101
00102 ++pMapCurr;
00103 }
00104
00105
00106 pMapCurr = _pPixMap + pixsize - _width - 2;
00107
00108 for (int iCnt = _height - 2 ; iCnt >= 0 ; --iCnt)
00109 {
00110 for (int jCnt = _width - 2; jCnt >= 0 ; --jCnt, --pMapCurr)
00111 {
00112 if (*pMapCurr != 0)
00113 {
00114 BinaryImage::value_type m =
00115 1 + std::min(std::min(*(pMapCurr + 1),
00116 *(pMapCurr + _width + 1)),
00117 std::min(*(pMapCurr + _width),
00118 *(pMapCurr + _width - 1)));
00119
00120 *pMapCurr = std::min(m, *pMapCurr);
00121 }
00122 }
00123
00124 --pMapCurr;
00125 }
00126
00127 }
00128
00129
00130
00131 }