Skip to content
Snippets Groups Projects
Commit 83bec038 authored by Andrea Censi's avatar Andrea Censi
Browse files

No commit message

No commit message
parent b17c2757
No related branches found
No related tags found
No related merge requests found
......@@ -82,7 +82,8 @@ int main(int argc, const char * argv[]) {
} else have_alpha = 0;
if(have_alpha) {
double beta = alpha - ld->theta[i];
/* Recall that alpha points outside the surface */
double beta = (alpha+M_PI) - ld->theta[i];
add_sigma = p.sigma / cos(beta);
} else {
sm_error("Because lambertian is active, I need either true_alpha[] or alpha[]");
......
......@@ -11,6 +11,8 @@ struct raytracer_params {
bool load_env_from_json(Environment& env, JO jo);
double cosine_between_angles(double a1, double a2);
int main(int argc, const char** argv)
{
......@@ -84,7 +86,14 @@ int main(int argc, const char** argv)
ld->valid[i] = 1;
ld->readings[i] = rho;
ld->true_alpha[i] = normalize_0_2PI(alpha-ld->true_pose[2]);
double relative_alpha = alpha-ld->true_pose[2];
/* Make sure alpha points out of the wall */
if( cosine_between_angles(relative_alpha, ld->theta[i]) > 0) {
relative_alpha += M_PI;
}
ld->true_alpha[i] = normalize_0_2PI(relative_alpha);
} else {
ld->valid[i] = 0;
......@@ -130,6 +139,10 @@ int main(int argc, const char** argv)
return false; \
}
double cosine_between_angles(double a1, double a2) {
return cos(a1)*cos(a2)+sin(a1)*sin(a2);
}
bool load_env_from_json(Environment& env, JO jo_map) {
jo_expect_object(jo_map);
......
......@@ -245,6 +245,11 @@ int ld_valid_fields(LDP ld) {
return 0;
}
if(!is_nan(ld->readings_sigma[i]) && ld->readings_sigma[i] < 0) {
sm_error("Ray #%d: has invalid readings_sigma %f \n", i, ld->readings_sigma[i]);
return 0;
}
}
/* Checks that there is at least 10% valid rays */
int num_valid = count_equal(ld->valid, ld->nrays, 1);
......
......@@ -234,8 +234,12 @@ LDP ld_from_json_stream(FILE*file) {
jo = json_read_stream(file);
if(!jo) {
if(!feof(file))
if(!feof(file)) {
fprintf(stderr, " (!)\n");
sm_error("Invalid JSON found.\n");
}
fprintf(stderr, " EOF\n");
return 0;
}
......@@ -246,7 +250,7 @@ LDP ld_from_json_stream(FILE*file) {
}
jo_free(jo);
fprintf(stderr, "j");
fprintf(stderr, "l");
return ld;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment