In C++ you will need to have a maintained (i.e. updating) planning scene. If you just create a PlanningScene object yourself, this will always be empty and not reflect the current world state. You could create a PlanningSceneMonitor to achieve this, although it would be much faster if you created a MoveGroupCapability for it. An alternative would be to check the generated trajectory beforehand.