Форум » C/C++ для начинающих (C/C++ for beginners) » Array filtering » Ответить

Array filtering

ramees: float R[c]= {3.1 , 7.2, 7.1 , 7.2 , 02.2 , 02.3 }; float G[c]= {6.1 , 1.2, 1.1 , 1.2 , 01.2 , 01.3 }; float B[c]= {1.1 , 6.2, 6.1 , 6.2 , 03.2 , 03.3 }; this three array value i like to separate it pls help . see below for my code it's only working on one way when i change value , it's outputs are wrong i just wrote it i don't no how to do this in professional way . please show me a good way and what i need to do to become a good programmer (writing style) my code code details #include <iostream> using namespace std; void DivF( float fr , float fg , float fb, float sr , float sg , float sb, int& fId , int& sId ){ float* frIn = &fr; float* fbIn = &fb; float* fgIn = &fg; float* srIn = &sr; float* sbIn = &sb; float* sgIn = &sg; if(*frIn > *fgIn && *frIn > *fbIn && *fgIn < *fbIn){ // r max , g min , b mid fId = 1; }else if(*frIn > *fgIn && *frIn > *fbIn && *fgIn > *fbIn){ // r max , b min , g mid fId = 2; }else if(*fgIn > *frIn && *fgIn > *fbIn && *frIn < *fbIn){ // g max , r min , b mid fId = 3; }else if(*fgIn > *frIn && *fgIn > *fbIn && *frIn > *fbIn){ // g max , b min , r mid fId = 4; }else if(*fbIn > *frIn && *fbIn > *fgIn && *fgIn < *frIn){ // b max , g min , r mid fId = 5; }else if(*fbIn > *frIn && *fbIn > *fgIn && *fgIn > *frIn){ // b max , r min , g mid fId = 6; }else if(*frIn == *fgIn && *frIn < *fbIn ){ // r == g < b fId = 7; }else if(*frIn == *fbIn && *frIn < *fgIn ){ // r == b < g fId = 8; }else if(*fgIn == *fbIn && *fbIn < *frIn ){ // g == b < r fId = 9; }else if(*fgIn == *fbIn && *fbIn == *frIn ){ // g == b == r fId = 10; } if(*srIn > *sgIn && *srIn > *sbIn && *sgIn < *sbIn){ // r max , g min , b mid sId = 1; }else if(*srIn > *sgIn && *srIn > *sbIn && *sgIn > *sbIn){ // r max , b min , g mid sId = 2; }else if(*sgIn > *srIn && *sgIn > *sbIn && *srIn < *sbIn){ // g max , r min , b mid sId = 3; }else if(*sgIn > *srIn && *sgIn > *sbIn && *srIn > *sbIn){ // g max , b min , r mid sId = 4; }else if(*sbIn > *srIn && *sbIn > *sgIn && *sgIn < *srIn){ // b max , g min , r mid sId = 5; }else if(*sbIn > *srIn && *sbIn > *sgIn && *sgIn > *srIn){ // b max , r min , g mid sId = 6; }else if(*srIn == *sgIn && *srIn < *sbIn ){ // r == g < b sId = 7; }else if(*srIn == *sbIn && *srIn < *sgIn ){ // r == b < g sId = 8; }else if(*sgIn == *sbIn && *sbIn < *srIn ){ // g == b < r sId = 9; }else if(*sgIn == *sbIn && *sbIn == *srIn ){ // g == b == r sId = 10; } } const int c = 6; const int C = 1000; int main(){ float R[c]= {3.1 , 7.2, 7.1 , 7.2 , 02.2 , 02.3 }; float G[c]= {6.1 , 1.2, 1.1 , 1.2 , 01.2 , 01.3 }; float B[c]= {1.1 , 6.2, 6.1 , 6.2 , 03.2 , 03.3 }; float *rIn = R; float *gIn = G; float *bIn = B; const int C = 10000; float fr = 0; float *FR = &fr; float fg = 0; float *FG = &fg; float fb = 0; float *FB = &fb; float sr = 0; float *SR = &sr; float sg = 0; float *SG = &sg; float sb = 0; float *SB = &sb; int fId = 0; int sId = 0; static int Q = 0; // total array size int tSize = c; // total arySize Counter synchronizer pointer int Tcp = 0; int*cp = &Tcp; // any of (noise or normal array ) int Done = 0; float *AryR; AryR = new float [C]; float *AryG; AryG = new float [C]; float *AryB; AryB = new float [C]; int h = 1; int*H = &h; // for loop static int ID pointer need to reset after one row finsh int Ip = 0; int *IP = &Ip; // a pointer for controling normal pixel and noise pixel int CR = 0; int *cR = &CR; int PP = 0; int *pP = &PP; int QQ = 0; while (PP < c){ switch(h){ case 1: *FR = *rIn++; *FG = *gIn++; *FB = *bIn++; *SR = *rIn++; *SG = *gIn++; *SB = *bIn++; *cp += 1; break; case 2: *SR = *rIn++; *SG = *gIn++; *SB = *bIn++; *cp += 1; break; case 3: *SR = *rIn++; *SG = *gIn++; *SB = *bIn++; *cp += 1; h = 1; break; case 5 : h = 1; break; case 6 : h = 2; CR = 2; QQ = 1; *SR = *FR; *SG = *FG; *SB = *FB; break; case 7 : h = 2; CR = 1; QQ = 1; *SR = *FR; *SG = *FG; *SB = *FB; break; } DivF(fr , fg , fb , sr , sg , sb, fId , sId); if(h == 1){ if(fId == sId){ // save first pixel for(int i = Ip ; i<c;i++){ AryR = fr; AryG = fg; AryB = fb; *FR = *SR; *FG = *SG; *FB = *SB; // loop pointer *IP += 1; // First Switch pointer h = 2; // control pointer *cR = 1; break; } }else if (fId != sId ){ // noise array first pixel for(int i = Ip ; i<c;i++){ AryR = fr; AryG = fg; AryB = fb; *FR = *SR; *FG = *SG; *FB = *SB; *IP += 1; h = 2; *cR = 2; if(Tcp +1 == tSize){ h = 6; } break; } } }else if(h == 2 ){ // second pixel save if(CR == 1 && fId == sId && Tcp + 1 == tSize && QQ == 1){ sId = 0; Tcp += 1; } if(CR == 1 && fId != sId){ *cR = 3; // normal array complete execute to further for(int i = Ip ; i<c;i++){ AryR = fr; AryG = fg; AryB = fb; *IP += 1; break; } *FR = *SR; *FG = *SG; *FB = *SB; } if(CR == 2 && fId == sId ){ *cR = 4; // noise array complete execute to further if(Tcp +1 == tSize && QQ == 1 ){ // last one pixel noise for(int i = Ip ; i<c;i++){ AryR = fr; AryG = fg; AryB = fb; *IP += 1; QQ = 0; break; } PP = 10; } } if(CR != 4 && fId == sId){ // gp normal save for(int i = Ip ; i<c;i++){ AryR = fr; AryG = fg; AryB = fb; *FR = *SR; *FG = *SG; *FB = *SB; if(Tcp +1 == tSize){ h = 7; }else{ *IP += 1; h = 2; } break; } }else if (fId != sId ){ if(CR == 2){ // second noise pixel save for(int i = Ip ; i<c;i++){ AryR = fr; AryG = fg; AryB = fb; *FR = *SR; *FG = *SG; *FB = *SB; *IP += 1; h = 2; if(Tcp +1 == tSize){ h = 6; } break; } } } } if(CR == 3){ // normal to break std::cout<<"haha"<<std::endl; cout<< *IP <<endl; int Ai; cout<<"Normal GP "<<endl; for( Ai = 0; Ai < *IP ; Ai++){ cout<<"R :"<<AryR[Ai]<<endl; cout<<"G :"<<AryG[Ai]<<endl; cout<<"B :"<<AryB[Ai]<<endl; } Q++; cout<< "Group :"<< Q <<endl; *IP = 0; *cR = 0; if(tSize == Tcp ){ PP = c ; }else if(Tcp +1 == tSize){ h = 7; }else { h = 3; } }else if(CR == 4){ // noise to break std::cout<<"bbbababa"<<std::endl; cout<< *IP <<endl; int AI; cout<<"Noise GP "<<endl; for( AI = 0; AI < *IP ; AI++){ cout<<"R :"<<AryR[AI]<<endl; cout<<"G :"<<AryG[AI]<<endl; cout<<"B :"<<AryB[AI]<<endl; } Q++; cout<< " noise Group :"<< Q <<endl; *IP = 0; *cR = 0; if(tSize == Tcp ){ PP = c ; }else if(Tcp +1 == tSize){ h = 1; }else { h = 5; } } }// while end return 0; }

Ответов - 8

Сыроежка: Please elaborate what you mean by separating. It is not clear what you are trying to do.

ramees: sorry my mistake please Run the code below it will work u can see what i need float R[c]= {3.1 , 7.2, 7.1 , 7.2 , 02.2 , 02.3 }; float G[c]= {6.1 , 1.2, 1.1 , 1.2 , 01.2 , 01.3 }; float B[c]= {1.1 , 6.2, 6.1 , 6.2 , 03.2 , 03.3 }; i need out put like this not matching value Group group 1 3.1 6.1 1.1 matching value group 2 7.2 1.2 6.2 7.2 1.2 6.2 7.1 1.1 6.1 7.2 1.2 6.2 matching value group 3 02.2 01.2 03.2 02.3 01.3 03.3

Сыроежка: I am sorry. I have not understood what is "matching value group" and "non-matching value group". How are these groups formed?


ramees: float R[c]= {3.1 , 5.22 }; float G[c]= {1.1 , 1.5 }; float B[c]= {6.1 , 6.2 }; you can see this array have 2 value in row (R : 3.1 ,5.22) , (G : 1.1 ,1.5) ,(B : 6.1 ,6.2) in colum 1 (R : 3.1 , G : 1.1 , B :6.1) in colum 2 (R : 5.22 , G : 1.5 , B :6.2) u can see { DivF } Function in my code that i posted in my older post. in this function i pass in Two coulm same time to compere (High , Mid ,Low) i code all possible combination with if statement . than { void DivF( float fr , float fg , float fb, float sr , float sg , float sb, int& fId , int& sId } function set referanced int& fId = a value / int& fIs = a value than i checked (fId==sId) if it ture set to mached group . else nonmatched group than each group saved to dynamic array and "cout" than so on......... my code its working but when i change my array value it boooooooooom. i hop u can understand please show me how this can don in a professional way ...... thank u

Сыроежка: I do not understand how you counted four matching columns in your ptrvious example matching value group 2 7.2 1.2 6.2 7.2 1.2 6.2 7.1 1.1 6.1 7.2 1.2 6.2 Why is column 7.1 1.1 6.1 duplicated in this group?

ramees: sorry my mistake please Run the code below it will work u can see what i need float R[c]= {3.1 , 7.2, 7.1 , 7.2 , 02.2 , 02.3 }; float G[c]= {6.1 , 1.2, 1.1 , 1.2 , 01.2 , 01.3 }; float B[c]= {1.1 , 6.2, 6.1 , 6.2 , 03.2 , 03.3 }; i need out put like this not matching value Group group 1 3.1 6.1 1.1 matching value group 2 7.2 1.2 6.2 7.1 1.1 6.1 7.2 1.2 6.2 matching value group 3 02.2 01.2 03.2 02.3 01.3 03.3

Сыроежка: I am sorry but this code is so bad so unclear that I have no desire to deep into it. You should write code that is self-documented.

ramees: ok



полная версия страницы