All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
RealVectorStateProjections.cpp
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 #include "ompl/base/spaces/RealVectorStateProjections.h"
38 #include "ompl/util/Exception.h"
39 #include "ompl/tools/config/MagicConstants.h"
40 #include <cstring>
41 
43 namespace ompl
44 {
45  namespace base
46  {
47  static inline void checkSpaceType(const StateSpace *m)
48  {
49  if (!dynamic_cast<const RealVectorStateSpace*>(m))
50  throw Exception("Expected real vector state space for projection");
51  }
52  }
53 }
55 
57  const ProjectionMatrix::Matrix &projection) :
58  ProjectionEvaluator(space)
59 {
60  checkSpaceType(space_);
61  projection_.mat = projection;
62  setCellSizes(cellSizes);
63 }
64 
66  const ProjectionMatrix::Matrix &projection) :
67  ProjectionEvaluator(space)
68 {
69  checkSpaceType(space_);
70  projection_.mat = projection;
71  setCellSizes(cellSizes);
72 }
73 
75  const ProjectionMatrix::Matrix &projection) :
76  ProjectionEvaluator(space)
77 {
78  checkSpaceType(space_);
79  projection_.mat = projection;
80 }
81 
83  const ProjectionMatrix::Matrix &projection) :
84  ProjectionEvaluator(space)
85 {
86  checkSpaceType(space_);
87  projection_.mat = projection;
88 }
89 
91  const std::vector<unsigned int> &components) :
92  ProjectionEvaluator(space), components_(components)
93 {
94  checkSpaceType(space_);
95  setCellSizes(cellSizes);
96 }
97 
99  const std::vector<unsigned int> &components) :
100  ProjectionEvaluator(space), components_(components)
101 {
102  checkSpaceType(space_);
103  setCellSizes(cellSizes);
104 }
105 
107  ProjectionEvaluator(space), components_(components)
108 {
109  checkSpaceType(space_);
110 }
111 
113  ProjectionEvaluator(space), components_(components)
114 {
115  checkSpaceType(space_);
116 }
117 
119 {
120  const RealVectorBounds &bounds = space_->as<RealVectorStateSpace>()->getBounds();
121  cellSizes_.resize(components_.size());
122  for (unsigned int i = 0 ; i < cellSizes_.size() ; ++i)
123  cellSizes_[i] = (bounds.high[components_[i]] - bounds.low[components_[i]]) / magic::PROJECTION_DIMENSION_SPLITS;
124 }
125 
127 {
128  return projection_.mat.size1();
129 }
130 
132 {
133  projection_.project(state->as<RealVectorStateSpace::StateType>()->values, projection);
134 }
135 
137 {
138  return components_.size();
139 }
140 
142 {
143  for (unsigned int i = 0 ; i < components_.size() ; ++i)
144  projection(i) = state->as<RealVectorStateSpace::StateType>()->values[components_[i]];
145 }
146 
148  ProjectionEvaluator(space)
149 {
150  checkSpaceType(space_);
151  setCellSizes(cellSizes);
152 }
153 
155  ProjectionEvaluator(space)
156 {
157  checkSpaceType(space_);
158 }
159 
161  ProjectionEvaluator(space)
162 {
163  checkSpaceType(space_);
164  setCellSizes(cellSizes);
165 }
166 
168  ProjectionEvaluator(space)
169 {
170  checkSpaceType(space_);
171 }
172 
174 {
175  const RealVectorBounds &bounds = space_->as<RealVectorStateSpace>()->getBounds();
176  cellSizes_.resize(getDimension());
177  for (unsigned int i = 0 ; i < cellSizes_.size() ; ++i)
178  cellSizes_[i] = (bounds.high[i] - bounds.low[i]) / magic::PROJECTION_DIMENSION_SPLITS;
179 }
180 
182 {
183  copySize_ = getDimension() * sizeof(double);
185 }
186 
188 {
189  return space_->getDimension();
190 }
191 
193 {
194  memcpy(&projection(0), state->as<RealVectorStateSpace::StateType>()->values, copySize_);
195 }