Program Listing for File SpaceInformation.h

Return to documentation for file (src/ompl/control/SpaceInformation.h)

/*********************************************************************
* Software License Agreement (BSD License)
*
*  Copyright (c) 2010, Rice University
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the Rice University nor the names of its
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Ioan Sucan */

#ifndef OMPL_CONTROL_SPACE_INFORMATION_
#define OMPL_CONTROL_SPACE_INFORMATION_

#include <utility>

#include "ompl/base/SpaceInformation.h"
#include "ompl/control/ControlSpace.h"
#include "ompl/control/ControlSampler.h"
#include "ompl/control/DirectedControlSampler.h"
#include "ompl/control/StatePropagator.h"
#include "ompl/control/Control.h"
#include "ompl/util/ClassForward.h"

namespace ompl
{
    namespace control
    {

        OMPL_CLASS_FORWARD(SpaceInformation);

        using StatePropagatorFn =
            std::function<void(const base::State *, const Control *, const double, base::State *)>;

        class SpaceInformation : public base::SpaceInformation
        {
        public:
            SpaceInformation(const base::StateSpacePtr &stateSpace, ControlSpacePtr controlSpace);

            ~SpaceInformation() override = default;

            const ControlSpacePtr &getControlSpace() const
            {
                return controlSpace_;
            }

            Control *allocControl() const
            {
                return controlSpace_->allocControl();
            }

            void freeControl(Control *control) const
            {
                controlSpace_->freeControl(control);
            }

            void copyControl(Control *destination, const Control *source) const
            {
                controlSpace_->copyControl(destination, source);
            }

            Control *cloneControl(const Control *source) const
            {
                Control *copy = controlSpace_->allocControl();
                controlSpace_->copyControl(copy, source);
                return copy;
            }

            void printControl(const Control *control, std::ostream &out = std::cout) const
            {
                controlSpace_->printControl(control, out);
            }

            bool equalControls(const Control *control1, const Control *control2) const
            {
                return controlSpace_->equalControls(control1, control2);
            }

            void nullControl(Control *control) const
            {
                controlSpace_->nullControl(control);
            }

            ControlSamplerPtr allocControlSampler() const
            {
                return controlSpace_->allocControlSampler();
            }

            void setMinMaxControlDuration(unsigned int minSteps, unsigned int maxSteps)
            {
                minSteps_ = minSteps;
                maxSteps_ = maxSteps;
            }

            void setMinControlDuration(unsigned int minSteps)
            {
                minSteps_ = minSteps;
            }

            void setMaxControlDuration(unsigned int maxSteps)
            {
                maxSteps_ = maxSteps;
            }

            unsigned int getMinControlDuration() const
            {
                return minSteps_;
            }

            unsigned int getMaxControlDuration() const
            {
                return maxSteps_;
            }

            DirectedControlSamplerPtr allocDirectedControlSampler() const;

            void setDirectedControlSamplerAllocator(const DirectedControlSamplerAllocator &dcsa);

            void clearDirectedSamplerAllocator();

            const StatePropagatorPtr &getStatePropagator() const
            {
                return statePropagator_;
            }

            void setStatePropagator(const StatePropagatorFn &fn);

            void setStatePropagator(const StatePropagatorPtr &sp);

            void setPropagationStepSize(double stepSize)
            {
                stepSize_ = stepSize;
            }

            double getPropagationStepSize() const
            {
                return stepSize_;
            }
            void propagate(const base::State *state, const Control *control, int steps, base::State *result) const;

            bool canPropagateBackward() const;

            unsigned int propagateWhileValid(const base::State *state, const Control *control, int steps,
                                             base::State *result) const;

            void propagate(const base::State *state, const Control *control, int steps,
                           std::vector<base::State *> &result, bool alloc) const;

            unsigned int propagateWhileValid(const base::State *state, const Control *control, int steps,
                                             std::vector<base::State *> &result, bool alloc) const;

            void printSettings(std::ostream &out = std::cout) const override;

            void setup() override;

        protected:
            void declareParams();

            ControlSpacePtr controlSpace_;

            StatePropagatorPtr statePropagator_;

            unsigned int minSteps_{0};

            unsigned int maxSteps_{0};

            DirectedControlSamplerAllocator dcsa_;

            double stepSize_{0.};
        };
    }
}

#endif