All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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  {
49 
54  template<typename T>
56  {
57  };
58 
60  template<>
62  {
63  typedef StateSampler Sampler;
64  typedef StateSamplerPtr SamplerPtr;
65 
66  SamplerPtr allocStateSampler(const SpaceInformation *si)
67  {
68  return si->allocStateSampler();
69  }
70 
71  };
72 
73  template<>
74  struct SamplerSelector<ValidStateSampler>
75  {
76  typedef ValidStateSampler Sampler;
77  typedef ValidStateSamplerPtr SamplerPtr;
78 
79  SamplerPtr allocStateSampler(const SpaceInformation *si)
80  {
81  return si->allocValidStateSampler();
82  }
83  };
87  template<typename T>
89  {
90  public:
91 
94 
97 
99  StateSamplerArray(const SpaceInformationPtr &si) : si_(si.get())
100  {
101  }
102 
104  StateSamplerArray(const SpaceInformation *si) : si_(si)
105  {
106  }
107 
108  ~StateSamplerArray(void)
109  {
110  }
111 
114  Sampler* operator[](std::size_t index) const
115  {
116  return samplers_[index].get();
117  }
118 
120  void resize(std::size_t count)
121  {
122  if (samplers_.size() > count)
123  samplers_.resize(count);
124  else
125  if (samplers_.size() < count)
126  {
127  std::size_t c = samplers_.size();
128  samplers_.resize(count);
129  for (std::size_t i = c ; i < count ; ++i)
130  samplers_[i] = ss_.allocStateSampler(si_);
131  }
132  }
133 
135  std::size_t size(void) const
136  {
137  return samplers_.size();
138  }
139 
141  void clear(void)
142  {
143  resize(0);
144  }
145 
146  private:
147 
148  const SpaceInformation *si_;
149  SamplerSelector<T> ss_;
150  std::vector<SamplerPtr> samplers_;
151 
152  };
153  }
154 }
155 
156 #endif
std::size_t size(void) const
Get the count of samplers currently available.
A boost 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(void) const
Allocate a uniform state sampler for the state space.
StateSamplerArray(const SpaceInformation *si)
Constructor.
SamplerSelector< T >::Sampler Sampler
The type of sampler allocated.
A boost 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.
Sampler * operator[](std::size_t index) const
Access operator for a specific sampler. For performance reasons, the bounds are not checked...
StateSamplerArray(const SpaceInformationPtr &si)
Constructor.
Depending on the type of state sampler, we have different allocation routines.
void clear(void)
Clear all allocated samplers.
Abstract definition of a state space sampler.
Definition: StateSampler.h:66
void resize(std::size_t count)
Create or release some state samplers.