The way that I find the easiest is like suggested: creating your own "vector" and "repainting" it.
In fact, a Path
is simply a collection of Pose
s. Normally, only one path is displayed; therefore, if you send a new one, whatever was displayed before gets erased. So, you can create one path object locally, and keep adding new points to it.
Here is a skeleton of an algorithm that should do what you want:
nav_msgs::Path pathMsg;
while (node.ok())
{
ros::spinOnce();
geometry_msgs::PoseStamped poseMsg;
// Fill the poseMsg with whatever pose you want (the point on your path)
pathMsg.poses.push_back(poseMsg);
pathPublisher.publish(pathMsg);
// Waits a little before adding another pose to the path
rate.sleep();
} // end loop