Program Listing for File ProjectionEvaluator.h

Return to documentation for file (src/ompl/base/ProjectionEvaluator.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_BASE_PROJECTION_EVALUATOR_
#define OMPL_BASE_PROJECTION_EVALUATOR_

#include "ompl/base/State.h"
#include "ompl/util/ClassForward.h"
#include "ompl/util/Console.h"
#include "ompl/base/GenericParam.h"
#include "ompl/base/spaces/RealVectorBounds.h"

#include <vector>
#include <valarray>
#include <iostream>
#include <Eigen/Core>

namespace ompl
{
    namespace base
    {
        class ProjectionMatrix
        {
        public:
            using Matrix = Eigen::MatrixXd;

            static Matrix ComputeRandom(unsigned int from, unsigned int to, const std::vector<double> &scale);

            static Matrix ComputeRandom(unsigned int from, unsigned int to);

            void computeRandom(unsigned int from, unsigned int to, const std::vector<double> &scale);

            void computeRandom(unsigned int from, unsigned int to);

            void project(const double *from, Eigen::Ref<Eigen::VectorXd> to) const;

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

            Matrix mat;

        public:
            EIGEN_MAKE_ALIGNED_OPERATOR_NEW
        };

        OMPL_CLASS_FORWARD(StateSpace);


        OMPL_CLASS_FORWARD(ProjectionEvaluator);

        class ProjectionEvaluator
        {
        public:
            // non-copyable
            ProjectionEvaluator(const ProjectionEvaluator &) = delete;
            ProjectionEvaluator &operator=(const ProjectionEvaluator &) = delete;

            ProjectionEvaluator(const StateSpace *space);

            ProjectionEvaluator(const StateSpacePtr &space);

            virtual ~ProjectionEvaluator();

            virtual unsigned int getDimension() const = 0;

            virtual void project(const State *state, Eigen::Ref<Eigen::VectorXd> projection) const = 0;

            virtual void setCellSizes(const std::vector<double> &cellSizes);

            void setCellSizes(unsigned int dim, double cellSize);

            void mulCellSizes(double factor);

            bool userConfigured() const;

            const std::vector<double> &getCellSizes() const
            {
                return cellSizes_;
            }

            double getCellSizes(unsigned int dim) const;

            void checkCellSizes() const;

            void inferCellSizes();

            virtual void defaultCellSizes();

            void checkBounds() const;

            bool hasBounds() const
            {
                return !bounds_.low.empty();
            }

            void setBounds(const RealVectorBounds &bounds);

            const RealVectorBounds &getBounds() const
            {
                return bounds_;
            }

            void inferBounds();

            virtual void setup();

            void computeCoordinates(const Eigen::Ref<Eigen::VectorXd> &projection,
                                    Eigen::Ref<Eigen::VectorXi> coord) const;

            void computeCoordinates(const State *state, Eigen::Ref<Eigen::VectorXi> coord) const
            {
                Eigen::VectorXd projection(getDimension());
                project(state, projection);
                computeCoordinates(projection, coord);
            }

            ParamSet &params()
            {
                return params_;
            }

            const ParamSet &params() const
            {
                return params_;
            }

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

            virtual void printProjection(const Eigen::Ref<Eigen::VectorXd> &projection,
                                         std::ostream &out = std::cout) const;

        protected:
            void estimateBounds();

            const StateSpace *space_;

            std::vector<double> cellSizes_;

            RealVectorBounds bounds_;

            RealVectorBounds estimatedBounds_;

            bool defaultCellSizes_;

            bool cellSizesWereInferred_;

            ParamSet params_;
        };

        class SubspaceProjectionEvaluator : public ProjectionEvaluator
        {
        public:
            SubspaceProjectionEvaluator(const StateSpace *space, unsigned int index,
                                        ProjectionEvaluatorPtr projToUse = ProjectionEvaluatorPtr());

            void setup() override;

            unsigned int getDimension() const override;

            void project(const State *state, Eigen::Ref<Eigen::VectorXd> projection) const override;

        protected:
            unsigned int index_;

            ProjectionEvaluatorPtr proj_;

            ProjectionEvaluatorPtr specifiedProj_;
        };
    }  // namespace base
}  // namespace ompl

#endif