Loading...
Searching...
No Matches
PlannerData.cpp
1/*********************************************************************
2* Software License Agreement (BSD License)
3*
4* Copyright (c) 2012, Rice University
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions
9* are met:
10*
11* * Redistributions of source code must retain the above copyright
12* notice, this list of conditions and the following disclaimer.
13* * Redistributions in binary form must reproduce the above
14* copyright notice, this list of conditions and the following
15* disclaimer in the documentation and/or other materials provided
16* with the distribution.
17* * Neither the name of the Rice University nor the names of its
18* contributors may be used to endorse or promote products derived
19* from this software without specific prior written permission.
20*
21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32* POSSIBILITY OF SUCH DAMAGE.
33*********************************************************************/
34
35/* Author: Ryan Luna */
36
37#include "ompl/control/PlannerData.h"
38
40 : base::PlannerData(std::static_pointer_cast<base::SpaceInformation>(siC)), siC_(siC)
41{
42}
43
45{
46 freeMemory();
47}
48
50{
52}
53
55{
56 unsigned int index = vertexIndex(st);
57 if (index == INVALID_INDEX)
58 return false;
59
60 std::map<unsigned int, const base::PlannerDataEdge *> edgeMap;
61 getEdges(index, edgeMap);
62
63 for (auto &edgemapit : edgeMap)
64 {
65 // Before deleting the edge, free the control associated with it, if it was decoupled
66 auto *ctrl =
67 const_cast<Control *>(static_cast<const PlannerDataEdgeControl *>(edgemapit.second)->getControl());
68 auto it = decoupledControls_.find(ctrl);
69 if (it != decoupledControls_.end())
70 {
71 siC_->freeControl(*it);
72 decoupledControls_.erase(it);
73 }
74 }
75
77}
78
79bool ompl::control::PlannerData::removeEdge(unsigned int v1, unsigned int v2)
80{
82}
83
86{
87 unsigned int index1, index2;
88 index1 = vertexIndex(v1);
89 index2 = vertexIndex(v2);
90
91 if (index1 == INVALID_INDEX || index2 == INVALID_INDEX)
92 return false;
93
94 // Before deleting the edge, free the control associated with it, if it was decoupled
95 auto &edge = static_cast<PlannerDataEdgeControl &>(getEdge(index1, index2));
96 auto *ctrl = const_cast<Control *>(edge.getControl());
97 auto it = decoupledControls_.find(ctrl);
98 if (it != decoupledControls_.end())
99 {
100 siC_->freeControl(*it);
101 decoupledControls_.erase(it);
102 }
103
104 return ompl::base::PlannerData::removeEdge(index1, index2);
105}
106
108{
110
111 freeMemory();
112 decoupledControls_.clear();
113}
114
116{
118
119 for (unsigned int i = 0; i < numVertices(); ++i)
120 {
121 for (unsigned int j = 0; j < numVertices(); ++j)
122 {
123 if (edgeExists(i, j))
124 {
125 auto &edge = static_cast<PlannerDataEdgeControl &>(getEdge(i, j));
126 // If this edge's control is not in the decoupled list, clone it and add it
127 auto *ctrl = const_cast<Control *>(edge.getControl());
128 if (decoupledControls_.find(ctrl) == decoupledControls_.end())
129 {
130 Control *clone = siC_->cloneControl(ctrl);
131 decoupledControls_.insert(clone);
132 // Replacing the shallow control pointer with our shiny new clone
133 edge.c_ = clone;
134 }
135 }
136 }
137 }
138}
139
141{
142 return siC_;
143}
144
146{
147 return true;
148}
149
150void ompl::control::PlannerData::freeMemory()
151{
152 for (auto decoupledControl : decoupledControls_)
153 siC_->freeControl(decoupledControl);
154}
Base class for a vertex in the PlannerData structure. All derived classes must implement the clone an...
Definition PlannerData.h:59
virtual void clear()
Clears the entire data structure.
virtual bool removeVertex(const PlannerDataVertex &st)
Removes the vertex associated with the given data. If the vertex does not exist, false is returned....
virtual bool removeEdge(unsigned int v1, unsigned int v2)
Removes the edge between vertex indexes v1 and v2. Success is returned.
virtual void decoupleFromPlanner()
Creates a deep copy of the states contained in the vertices of this PlannerData structure so that whe...
A shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract control.
Definition Control.h:48
Representation of an edge in PlannerData for planning with controls. This structure encodes a specifi...
Definition PlannerData.h:61
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique,...
bool removeVertex(const base::PlannerDataVertex &st) override
Removes the vertex associated with the given data. If the vertex does not exist, false is returned....
PlannerData(const SpaceInformationPtr &siC)
Constructor. Accepts a SpaceInformationPtr for the space planned in.
void decoupleFromPlanner() override
Creates a deep copy of the states contained in the vertices of this PlannerData structure so that whe...
void clear() override
Clears the entire data structure.
const SpaceInformationPtr & getSpaceInformation() const
Return the instance of SpaceInformation used in this PlannerData.
bool hasControls() const override
Returns true if this PlannerData instance has controls associated with it.
~PlannerData() override
Destructor.
bool removeEdge(unsigned int v1, unsigned int v2) override
Removes the edge between vertex indexes v1 and v2. Success is returned.
A shared pointer wrapper for ompl::control::SpaceInformation.
Space information containing necessary information for planning with controls. setup() needs to be ca...
STL namespace.