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 
45 namespace ompl
46 {
47  namespace base
48  {
53  template <typename T>
55  {
56  };
57 
59  template <>
60  struct SamplerSelector<StateSampler>
61  {
62  typedef StateSampler Sampler;
63  typedef StateSamplerPtr SamplerPtr;
64 
65  SamplerPtr allocStateSampler(const SpaceInformation *si)
66  {
67  return si->allocStateSampler();
68  }
69  };
70 
71  template <>
72  struct SamplerSelector<ValidStateSampler>
73  {
74  typedef ValidStateSampler Sampler;
75  typedef ValidStateSamplerPtr SamplerPtr;
76 
77  SamplerPtr allocStateSampler(const SpaceInformation *si)
78  {
79  return si->allocValidStateSampler();
80  }
81  };
86  template <typename T>
88  {
89  public:
92 
95 
97  StateSamplerArray(const SpaceInformationPtr &si) : si_(si.get())
98  {
99  }
100 
102  StateSamplerArray(const SpaceInformation *si) : si_(si)
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  std::size_t c = samplers_.size();
123  samplers_.resize(count);
124  for (std::size_t i = c; i < count; ++i)
125  samplers_[i] = ss_.allocStateSampler(si_);
126  }
127  }
128 
130  std::size_t size() const
131  {
132  return samplers_.size();
133  }
134 
136  void clear()
137  {
138  resize(0);
139  }
140 
141  private:
142  const SpaceInformation *si_;
143  SamplerSelector<T> ss_;
144  std::vector<SamplerPtr> samplers_;
145  };
146  }
147 }
148 
149 #endif
A shared pointer wrapper for ompl::base::ValidStateSampler.
A shared pointer wrapper for ompl::base::StateSampler.
Class to ease the creation of a set of samplers. This is especially useful for multi-threaded planner...
StateSamplerPtr allocStateSampler() const
Allocate a uniform state sampler for the state space.
ValidStateSamplerPtr allocValidStateSampler() const
Allocate an instance of a valid state sampler for this space. If setValidStateSamplerAllocator() was ...
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
StateSamplerArray(const SpaceInformation *si)
Constructor.
SamplerSelector< T >::Sampler Sampler
The type of sampler allocated.
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...
SamplerSelector< T >::SamplerPtr SamplerPtr
Pointer to the type of sampler allocated.
StateSamplerArray(const SpaceInformationPtr &si)
Constructor.
Depending on the type of state sampler, we have different allocation routines.
std::size_t size() const
Get the count of samplers currently available.
void resize(std::size_t count)
Create or release some state samplers.
void clear()
Clear all allocated samplers.
Sampler * operator[](std::size_t index) const
Access operator for a specific sampler. For performance reasons, the bounds are not checked...