我构造了一个类,动态加入一个结构:
struct point
{
int serial;
int x;
int y;
int grey;
}
CArray m_array<point,&point>;
经过计算,得到一个数组,
但是利用GetSize()得到的值,与m_array的实际值并不相符,在输出值的时候
总比GetSize()的值要小,这是为什么:
哪位大师知道?
struct point
{
int serial;
int x;
int y;
int grey;
}
CArray m_array<point,&point>;
经过计算,得到一个数组,
但是利用GetSize()得到的值,与m_array的实际值并不相符,在输出值的时候
总比GetSize()的值要小,这是为什么:
哪位大师知道?
for (int i=0;i < 10;i++)
myArray.Add( CPoint(i, 2*i) );// Modify all the points in the array.
for (i=0;i < myArray.GetSize();i++)
{
CPoint& pt = myArray.ElementAt(i);
pt.x = 0;
}
outcome=fopen("C:\\alldata.txt","w");//
point apoint;//云团中点
int threshold=220;//选取的阈值,我们暂时取211,
//int m=0;//标识第几个云团
m_ayuntuan.RemoveAll();
which=0;//如果没有则认为是第一个云团序号
int how_many=0;//用来测度云团个数
int now_which=0;
for(int j=1;j<299;j++)
for(int i=1;i<399;i++)
{
if(m_data[j*400+i]>=threshold)
{
if(m_data[(j-1)*400+i-1]>=threshold||
m_data[(j-1)*400+i]>=threshold||
m_data[(j-1)*400+i+1]>=threshold||
m_data[j*400+i-1]>=threshold)//Is_One(i,j))//if the pixel next to top,top_left,top_right,left
{
apoint.serial=now_which;
apoint.x=i;
apoint.y=j;
apoint.gray=m_data[j*400+i];
m_ayuntuan.Add(apoint);
fprintf(outcome,"%d %d %d %d\n",apoint.serial ,apoint.x ,
apoint.y ,apoint.gray );
how_many++; }
else
{
// int now_which=0;
int m_now=m_ayuntuan.GetSize();
for(int w=0;w<m_now;w++)//使现有的云团序号增一
{
if(now_which<m_ayuntuan[w].serial)
now_which=m_ayuntuan[w].serial;
else
;
} now_which++;//另开辟一新云团
apoint.serial=now_which;
apoint.x=i;
apoint.y=j;
apoint.gray=m_data[j*400+i];
m_ayuntuan.Add(apoint);
fprintf(outcome,"%d %d %d %d\n",apoint.serial ,apoint.x ,
apoint.y ,apoint.gray );
how_many++;
}
}
else
;
}
int total=m_ayuntuan.GetSize();//云团点集总数
int sum_yuntuan=0;//云团个数
for(int w=0;w<total;w++)//使现有的云团序号增一
{
if(sum_yuntuan<m_ayuntuan[w].serial)
sum_yuntuan=m_ayuntuan[w].serial;
else
;
}
fprintf(outcome,"the total by added=%d",how_many);
fprintf(outcome,"the total point:%d,the total yuntuan:%d",total,sum_yuntuan);
fclose(outcome);
int test=sum_yuntuan;
//对数据集进行处理,以求出其各种特征量
//判断是否边界点,并提取出边界点集
/////看用CARRAY作出的结果是否一致:
FILE *outcome1;
outcome1=fopen("C:\\allarray.txt","w");//open the file and change the name
for(int ll=0;ll<total;ll++)
fprintf(outcome1,"%d,%d,%d,%d\n",m_ayuntuan[ll].serial,m_ayuntuan[ll].x,
m_ayuntuan[ll].y,m_ayuntuan[ll].gray);
fprintf(outcome1,"%d,%d",total,sum_yuntuan);
fclose(outcome1);代码大致如上,我用fprintf输出的值是对的,符合GetSize()的个数,但在程序
计算中及用TRACE()语句查看均有够那么多,比如本来应该有500个,它只取前四百个,看来我只能把它输出后,再读入进行处理了.