ompl/extensions/triangle/src/PropositionalTriangularDecomposition.cpp
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2013, Rice University
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Rice University nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: Matt Maly */
00036 
00037 #include "ompl/extensions/triangle/PropositionalTriangularDecomposition.h"
00038 #include "ompl/extensions/triangle/TriangularDecomposition.h"
00039 #include "ompl/control/planners/ltl/PropositionalDecomposition.h"
00040 #include "ompl/control/planners/ltl/World.h"
00041 #include "ompl/util/RandomNumbers.h"
00042 #include "ompl/base/State.h"
00043 #include "ompl/base/StateSampler.h"
00044 #include "ompl/base/spaces/RealVectorBounds.h"
00045 #include <ostream>
00046 #include <set>
00047 #include <vector>
00048 
00049 namespace ob = ompl::base;
00050 namespace oc = ompl::control;
00051 
00052 namespace
00053 {
00054     /* PropositionalTriangularDecomposition creates a WrapperDecomposition under-the-hood
00055        (which represents a triangulation over the given bounds that uses
00056        PropositionalTriangularDecomposition's user-defined project and sample methods)
00057        and hands it upward to the PropositionalDecomposition superclass constructor. */
00058     class WrapperDecomposition : public oc::TriangularDecomposition
00059     {
00060     public:
00061         typedef TriangularDecomposition::Polygon Polygon;
00062         typedef TriangularDecomposition::Vertex Vertex;
00063         WrapperDecomposition(const oc::Decomposition* decomp,
00064                              const ob::RealVectorBounds& bounds,
00065                              const std::vector<Polygon>& holes,
00066                              const std::vector<Polygon>& props);
00067         virtual ~WrapperDecomposition(void) {}
00068         virtual void project(const ob::State* s, std::vector<double>& coord) const;
00069         virtual void sampleFromRegion(int rid, ompl::RNG& rng, std::vector<double>& coord) const;
00070         virtual void sampleFullState(const ob::StateSamplerPtr& sampler,
00071             const std::vector<double>& coord, ob::State* s) const;
00072     protected:
00073         const oc::Decomposition* decomp_;
00074     };
00075 }
00076 
00077 oc::PropositionalTriangularDecomposition::PropositionalTriangularDecomposition(
00078     const ob::RealVectorBounds& bounds, const std::vector<Polygon>& holes, const std::vector<Polygon>& props)
00079     : PropositionalDecomposition(DecompositionPtr(new WrapperDecomposition(this, bounds, holes, props))),
00080       triDecomp_(static_cast<TriangularDecomposition*>(decomp_.get()))
00081 {
00082 }
00083 
00084 int oc::PropositionalTriangularDecomposition::getNumProps(void) const
00085 {
00086     return triDecomp_->getNumRegionsOfInterest();
00087 }
00088 
00089 oc::World oc::PropositionalTriangularDecomposition::worldAtRegion(int triID)
00090 {
00091     int numProps = getNumProps();
00092     World world(numProps);
00093     for (int p = 0; p < numProps; ++p)
00094         world[p] = false;
00095     if (triID == -1) return world;
00096     int prop = triDecomp_->getRegionOfInterestAt(triID);
00097     if (prop >= 0) world[prop] = true;
00098     return world;
00099 }
00100 
00101 void oc::PropositionalTriangularDecomposition::setup(void)
00102 {
00103     triDecomp_->setup();
00104 }
00105 
00106 void oc::PropositionalTriangularDecomposition::addHole(const Polygon& hole)
00107 {
00108     triDecomp_->addHole(hole);
00109 }
00110 
00111 void oc::PropositionalTriangularDecomposition::addProposition(const Polygon& prop)
00112 {
00113     triDecomp_->addRegionOfInterest(prop);
00114 }
00115 
00116 const std::vector<oc::PropositionalTriangularDecomposition::Polygon>&
00117     oc::PropositionalTriangularDecomposition::getHoles(void) const
00118 {
00119     return triDecomp_->getHoles();
00120 }
00121 
00122 const std::vector<oc::PropositionalTriangularDecomposition::Polygon>&
00123     oc::PropositionalTriangularDecomposition::getPropositions(void) const
00124 {
00125     return triDecomp_->getAreasOfInterest();
00126 }
00127 
00128 void oc::PropositionalTriangularDecomposition::print(std::ostream& out) const
00129 {
00130     triDecomp_->print(out);
00131 }
00132 
00133 namespace
00134 {
00135     WrapperDecomposition::WrapperDecomposition(const oc::Decomposition* decomp,
00136                                                const ob::RealVectorBounds& bounds,
00137                                                const std::vector<Polygon>& holes,
00138                                                const std::vector<Polygon>& props)
00139         : oc::TriangularDecomposition(bounds, holes, props),
00140           decomp_(decomp)
00141     {
00142     }
00143 
00144     void WrapperDecomposition::project(const ob::State* s, std::vector<double>& coord) const
00145     {
00146         decomp_->project(s, coord);
00147     }
00148 
00149     void WrapperDecomposition::sampleFromRegion(int rid,
00150                                                 ompl::RNG& rng,
00151                                                 std::vector<double>& coord) const
00152     {
00153         decomp_->sampleFromRegion(rid, rng, coord);
00154     }
00155 
00156     void WrapperDecomposition::sampleFullState(const ob::StateSamplerPtr& sampler,
00157                                                const std::vector<double>& coord,
00158                                                ob::State* s) const
00159     {
00160         decomp_->sampleFullState(sampler, coord, s);
00161     }
00162 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines