Skip to content

Commit aa0496a

Browse files
committed
gradient sample trace
1 parent f5cb3aa commit aa0496a

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

mjpc/planners/sample_gradient/planner.cc

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,19 @@ const Trajectory* SampleGradientPlanner::BestTrajectory() {
475475

476476
// visualize planner-specific traces
477477
void SampleGradientPlanner::Traces(mjvScene* scn) {
478-
// sample color
479-
float color[4];
480-
color[0] = 1.0;
481-
color[1] = 1.0;
482-
color[2] = 1.0;
483-
color[3] = 1.0;
478+
// noisy sample: white
479+
float white[4];
480+
white[0] = 1.0;
481+
white[1] = 1.0;
482+
white[2] = 1.0;
483+
white[3] = 1.0;
484+
485+
// gradient sample: orange
486+
float orange[4];
487+
orange[0] = 1.0;
488+
orange[1] = 0.5;
489+
orange[2] = 0.0;
490+
orange[3] = 1.0;
484491

485492
// width of a sample trace, in pixels
486493
double width = GetNumberOrDefault(3, model, "agent_sample_width");
@@ -494,26 +501,31 @@ void SampleGradientPlanner::Traces(mjvScene* scn) {
494501

495502
// check sizes
496503
int num_trajectory = num_trajectory_;
504+
int num_gradient = num_gradient_;
505+
int num_noisy = num_trajectory - num_gradient;
497506

498507
// traces between Newton and Cauchy points
499508
for (int k = 1; k < num_trajectory; k++) {
500509
// plot sample
501510
for (int i = 0; i < best->horizon - 1; i++) {
502511
if (scn->ngeom + task->num_trace > scn->maxgeom) break;
503512
for (int j = 0; j < task->num_trace; j++) {
513+
// index
514+
int idx = trajectory_order[k];
515+
504516
// initialize geometry
505517
mjv_initGeom(&scn->geoms[scn->ngeom], mjGEOM_LINE, zero3, zero3, zero9,
506-
color);
518+
idx < num_noisy ? white : orange);
507519

508520
// make geometry
509521
mjv_makeConnector(
510522
&scn->geoms[scn->ngeom], mjGEOM_LINE, width,
511-
trajectory[k].trace[3 * task->num_trace * i + 3 * j],
512-
trajectory[k].trace[3 * task->num_trace * i + 1 + 3 * j],
513-
trajectory[k].trace[3 * task->num_trace * i + 2 + 3 * j],
514-
trajectory[k].trace[3 * task->num_trace * (i + 1) + 3 * j],
515-
trajectory[k].trace[3 * task->num_trace * (i + 1) + 1 + 3 * j],
516-
trajectory[k].trace[3 * task->num_trace * (i + 1) + 2 + 3 * j]);
523+
trajectory[idx].trace[3 * task->num_trace * i + 3 * j],
524+
trajectory[idx].trace[3 * task->num_trace * i + 1 + 3 * j],
525+
trajectory[idx].trace[3 * task->num_trace * i + 2 + 3 * j],
526+
trajectory[idx].trace[3 * task->num_trace * (i + 1) + 3 * j],
527+
trajectory[idx].trace[3 * task->num_trace * (i + 1) + 1 + 3 * j],
528+
trajectory[idx].trace[3 * task->num_trace * (i + 1) + 2 + 3 * j]);
517529

518530
// increment number of geometries
519531
scn->ngeom += 1;

0 commit comments

Comments
 (0)