Loading...
Searching...
No Matches
StateSamplerArray.h
1/*********************************************************************
2* Software License Agreement (BSD License)
3*
4* Copyright (c) 2010, 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: Ioan Sucan */
36
37#ifndef OMPL_BASE_STATE_SAMPLER_ARRAY_
38#define OMPL_BASE_STATE_SAMPLER_ARRAY_
39
40#include "ompl/base/SpaceInformation.h"
41#include "ompl/base/StateSampler.h"
42#include "ompl/base/ValidStateSampler.h"
43#include <vector>
44
45namespace ompl
46{
47 namespace base
48 {
53 template <typename T>
55 {
56 };
57
59 template <>
61 {
62 using Sampler = StateSampler;
63 using SamplerPtr = StateSamplerPtr;
64
65 SamplerPtr allocStateSampler(const SpaceInformation *si)
66 {
67 return si->allocStateSampler();
68 }
69 };
70
71 template <>
72 struct SamplerSelector<ValidStateSampler>
73 {
74 using Sampler = ValidStateSampler;
75 using SamplerPtr = ValidStateSamplerPtr;
76
77 SamplerPtr allocStateSampler(const SpaceInformation *si)
78 {
79 return si->allocValidStateSampler();
80 }
81 };
83
86 template <typename T>
88 {
89 public:
92
95
97 StateSamplerArray(const SpaceInformationPtr &si) : si_(si.get())
98 {
99 }
100
103 {
104 }
105
106 ~StateSamplerArray() = default;
107
110 Sampler *operator[](std::size_t index) const
111 {
112 return samplers_[index].get();
113 }
114
116 void resize(std::size_t count)
117 {
118 if (samplers_.size() > count)
119 samplers_.resize(count);
120 else if (samplers_.size() < count)
121 {
122 samplers_.resize(count);
123 for (auto &sampler : samplers_)
124 sampler = ss_.allocStateSampler(si_);
125 }
126 }
127
129 std::size_t size() const
130 {
131 return samplers_.size();
132 }
133
135 void clear()
136 {
137 resize(0);
138 }
139
140 private:
141 const SpaceInformation *si_;
143 std::vector<SamplerPtr> samplers_;
144 };
145 }
146}
147
148#endif
A shared pointer wrapper for ompl::base::SpaceInformation.
The base class for space information. This contains all the information about the space planning is d...
Class to ease the creation of a set of samplers. This is especially useful for multi-threaded planner...
Sampler * operator[](std::size_t index) const
Access operator for a specific sampler. For performance reasons, the bounds are not checked.
StateSamplerArray(const SpaceInformation *si)
Constructor.
StateSamplerArray(const SpaceInformationPtr &si)
Constructor.
typename SamplerSelector< T >::SamplerPtr SamplerPtr
Pointer to the type of sampler allocated.
void clear()
Clear all allocated samplers.
std::size_t size() const
Get the count of samplers currently available.
typename SamplerSelector< T >::Sampler Sampler
The type of sampler allocated.
void resize(std::size_t count)
Create or release some state samplers.
A shared pointer wrapper for ompl::base::StateSampler.
Abstract definition of a state space sampler.
A shared pointer wrapper for ompl::base::ValidStateSampler.
This namespace contains sampling based planning routines shared by both planning under geometric cons...
Main namespace. Contains everything in this library.
Depending on the type of state sampler, we have different allocation routines.