PDA

View Full Version : how to fill Qlist in minimum time



shivendra46d
15th August 2013, 09:18
hello every one, i am new to Qt,
I am trying to draw sound wave plot in sea water, for that i need a large no of points. So i used QList as i dont know how many points will be generated by the mathematical equation that i am using.
here is my code


for(int j = 1 ; j < number_of_rays ; j++)
{
// int a = Incident_angles.at(j-1) + Angle_Difference;
Incident_angles.insert(j, Incident_angles.at(j-1) + Angle_Difference);
//qDebug() << "InCIDENT ANGLE = " << Incident_angles.at(j);
}

for (int j = 0; j < number_of_rays; j++)
{
SRP_X_Cordinate.clear();
SRP_Y_Cordinate.clear();

int factor = -1;
counter = 0;
SRP_X_Cordinate.insert(0,0);
SRP_Y_Cordinate.insert(0,source_depth);

Actual_Incident_Angle = Incident_angles.at(j);
//qDebug() << "InCIDENT ANGLE = " << Incident_angles.at(j);
if (Incident_angles.at(j) > 90)
{
factor = -factor;
Actual_Incident_Angle = 180 - Incident_angles.at(j);
//qDebug() << "Actual_Incident_Angle" << Actual_Incident_Angle;
}

if (SRP_Y_Cordinate.at(0) > 0)
{
if (Incident_angles.at(j)!= 90)
{
Theta_1 = Actual_Incident_Angle*pi/180;

SRP_X_Cordinate.append(( SRP_X_Cordinate.at(counter) + difference_depth*tan(Theta_1)));
SRP_Y_Cordinate.append((SRP_Y_Cordinate.at(counter ) + factor*difference_depth));
//qDebug() << "Inside not equal to 90";
double C1 = Calculate_velocity(SRP_Y_Cordinate.at(counter));// + factor*0.001);
double C2 = Calculate_velocity(SRP_Y_Cordinate.at(counter+1));// + factor*0.001);

double t = Temp_Time + (sqrt(pow((SRP_X_Cordinate.at(counter) - SRP_X_Cordinate.at(counter+1)),2) + pow((SRP_Y_Cordinate.at(counter) - SRP_Y_Cordinate.at(counter+1)),2)))/C1;

Ray_Time.insert(counter, t);
Temp_Time = Ray_Time.at(counter);

Theta_2 = Calculate_Angle(C1, C2, Theta_1);

counter = counter + 1;

while( SRP_X_Cordinate.at(counter) < max_range)
{
qDebug()<<"Theta_1 = "<< Theta_1;
qDebug()<<"Theta_2 = "<< Theta_2;
qDebug()<<"C1 = "<< C1;
qDebug()<<"C2 = "<< C2;
if(Theta_2 < (pi/2 - 0.001))
{
Theta_1 = Theta_2;
SRP_Y_Cordinate.append((SRP_Y_Cordinate.at(counter ) + factor*difference_depth));
SRP_X_Cordinate.append((counter+1, SRP_X_Cordinate.at(counter) + difference_depth*tan(Theta_1)));

if( SRP_Y_Cordinate.at(counter+1) > 0.001 && SRP_Y_Cordinate.at(counter+1) < max_depth)
{
//qDebug()<<"SRP_X_Cordinate.at(counter) theta<90- - .01 = "<< SRP_Y_Cordinate.at(counter);
C1 = C2;
C2 = Calculate_velocity(SRP_Y_Cordinate.at(counter+1));// + factor*0.001);
Ray_Time.insert(counter, Temp_Time + (sqrt(pow((SRP_X_Cordinate.at(counter) - SRP_X_Cordinate.at(counter+1)),2) + pow((SRP_Y_Cordinate.at(counter) - SRP_Y_Cordinate.at(counter+1)),2)))/C1);
Temp_Time = Ray_Time.at(counter);
Theta_2 = Calculate_Angle(C1, C2, Theta_1);
}

else
{
//qDebug()<<"SRP_X_Cordinate.at(counter) theta<90- - .01 else cond = "<< SRP_Y_Cordinate.at(counter);
Theta_2 = Theta_1;
C2 = Calculate_velocity(SRP_Y_Cordinate.at(counter + 1));// + factor*0.001);
factor = - factor;
Ray_Time.insert(counter, Temp_Time + (sqrt(pow((SRP_X_Cordinate.at(counter) - SRP_X_Cordinate.at(counter+1)),2) + pow((SRP_Y_Cordinate.at(counter) - SRP_Y_Cordinate.at(counter+1)),2)))/C2);
}
}
else if(Theta_2 > (pi/2 + 0.0001))
{
qDebug()<<"SRP_X_Cordinate.at(counter) theta>90- - .01 = ";
factor = - factor;
Theta_1 = pi - Theta_2;

SRP_Y_Cordinate.append((SRP_Y_Cordinate.at(counter ) + factor*difference_depth));
SRP_X_Cordinate.append((SRP_X_Cordinate.at(counter ) + difference_depth*tan(Theta_1)));

C1 = C2;
C2 = Calculate_velocity(SRP_Y_Cordinate.at(counter+1));// + factor*0.001);
Ray_Time.insert(counter, Temp_Time + (sqrt(pow((SRP_X_Cordinate.at(counter) - SRP_X_Cordinate.at(counter+1)),2) + pow((SRP_Y_Cordinate.at(counter) - SRP_Y_Cordinate.at(counter+1)),2)))/C1);
Temp_Time = Ray_Time.at(counter);

Theta_2 = Calculate_Angle(C1, C2, Theta_1);
}

else
{
factor = - factor;
Theta_1 = 89*pi/180;
//qDebug()<<"SRP_X_Cordinate.at(counter) theta<90- - .01 = else condition "<< SRP_Y_Cordinate.at(counter);

SRP_Y_Cordinate.append((SRP_Y_Cordinate.at(counter ) + factor*difference_depth));
SRP_X_Cordinate.append((SRP_X_Cordinate.at(counter ) + difference_depth*tan(Theta_1)));

C1 = C2;
C2 = Calculate_velocity(SRP_Y_Cordinate.at(counter+1));// + factor*0.001);
Ray_Time.insert(counter, Temp_Time + (sqrt(pow((SRP_X_Cordinate.at(counter) - SRP_X_Cordinate.at(counter+1)),2) + pow((SRP_Y_Cordinate.at(counter) - SRP_Y_Cordinate.at(counter+1)),2)))/C1);
Temp_Time = Ray_Time.at(counter);

Theta_2 = Calculate_Angle(C1, C2, Theta_1);

}
// qDebug()<<"SRP_X_Cordinate.at(counter) theta<90- - .01 else cond = "<< SRP_Y_Cordinate.at(counter);
counter = counter + 1;
}

/* for( int r = 0; r< counter-1;r++)
{
Ray_Distance.insert(j, Ray_Distance.at(j) + sqrt(pow((SRP_X_Cordinate.at(r) - SRP_X_Cordinate.at(r+1)),2) + pow((SRP_Y_Cordinate.at(r) - SRP_Y_Cordinate.at(r+1)),2)));
}*/
}

else
{
counter = 1;
SRP_X_Cordinate.insert(1,max_range);
SRP_Y_Cordinate.insert(1,source_depth);
}
}

SRP_2D_X_Cordinate.insert(j,SRP_X_Cordinate);
SRP_2D_Y_Cordinate.insert(j,SRP_Y_Cordinate);

//qDebug()<<" counter "<< counter;
Data_points.insert(j,counter);
} /////////////////// END FOR /////////////////////////////////
this all i am doing on a button click and this is taking very long time

ChrisW67
15th August 2013, 09:37
Please edit your post and put your code between
tags.
Then tell us what you expect us to do about it? There are a bunch of completely unknown functions, unknown numbers of loops, no idea what "a very long time", where you have measured the slow points to be, why you do this in a button click event is etc...

shivendra46d
26th August 2013, 12:08
M really sorry that i didnt gave the post in proper format. And thanks that you paid a heed to my problem but i sorted ot the problem , actually i am calculating large no of X and Y coordinates and storing them in list and then retriving these point to draw line in paint event :). Its still complicated i have to disclose all my code thanks any way :)