00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef PCL_POINT_REPRESENTATION_H_
00038 #define PCL_POINT_REPRESENTATION_H_
00039
00040 #include "pcl/point_types.h"
00041 #include "pcl/win32_macros.h"
00042
00043 namespace pcl
00044 {
00046
00051 template <typename PointT>
00052 class PointRepresentation
00053 {
00054 protected:
00056 int nr_dimensions_;
00058 std::vector<float> alpha_;
00059
00060 public:
00062 PointRepresentation () : nr_dimensions_ (0), alpha_ (0) {}
00063
00068 virtual void copyToFloatArray (const PointT &p, float * out) const = 0;
00069
00073 virtual bool
00074 isValid (const PointT &p) const
00075 {
00076 float *temp = new float[nr_dimensions_];
00077 copyToFloatArray (p, temp);
00078 bool is_valid = true;
00079 for (int i = 0; i < nr_dimensions_; ++i)
00080 {
00081 if (!pcl_isfinite (temp[i]))
00082 {
00083 is_valid = false;
00084 break;
00085 }
00086 }
00087 delete [] temp;
00088 return (is_valid);
00089 }
00090
00095 template <typename OutputType> void
00096 vectorize (const PointT &p, OutputType &out) const
00097 {
00098 float *temp = new float[nr_dimensions_];
00099 copyToFloatArray (p, temp);
00100 if (alpha_.empty ())
00101 {
00102 for (int i = 0; i < nr_dimensions_; ++i)
00103 out[i] = temp[i];
00104 }
00105 else
00106 {
00107 for (int i = 0; i < nr_dimensions_; ++i)
00108 out[i] = temp[i] * alpha_[i];
00109 }
00110 delete [] temp;
00111 }
00112
00116
00117
00118 void
00119 setRescaleValues (const float * rescale_array)
00120 {
00121 alpha_.resize (nr_dimensions_);
00122 for (int i = 0; i < nr_dimensions_; ++i)
00123 alpha_[i] = rescale_array[i];
00124 }
00125
00127 inline int getNumberOfDimensions () const { return (nr_dimensions_); }
00128 };
00129
00131
00133 template <typename PointDefault>
00134 class DefaultPointRepresentation : public PointRepresentation <PointDefault>
00135 {
00136 using PointRepresentation <PointDefault>::nr_dimensions_;
00137
00138 typedef boost::shared_ptr<DefaultPointRepresentation<PointDefault> > Ptr;
00139
00140 public:
00141 DefaultPointRepresentation ()
00142 {
00143
00144 nr_dimensions_ = sizeof (PointDefault) / sizeof (float);
00145
00146 if (nr_dimensions_ > 3) nr_dimensions_ = 3;
00147 }
00148
00149 inline Ptr makeShared () const { return Ptr (new DefaultPointRepresentation<PointDefault> (*this)); }
00150
00151 virtual void
00152 copyToFloatArray (const PointDefault &p, float * out) const
00153 {
00154
00155 const float * ptr = (float *)&p;
00156 for (int i = 0; i < nr_dimensions_; ++i)
00157 {
00158 out[i] = ptr[i];
00159 }
00160 }
00161 };
00162
00163 template <>
00164 class DefaultPointRepresentation <PointXYZ> : public PointRepresentation <PointXYZ>
00165 {
00166 public:
00167 DefaultPointRepresentation ()
00168 {
00169 nr_dimensions_ = 3;
00170 }
00171
00172 virtual void
00173 copyToFloatArray (const PointXYZ &p, float * out) const
00174 {
00175 out[0] = p.x;
00176 out[1] = p.y;
00177 out[2] = p.z;
00178 }
00179 };
00180
00181 template <>
00182 class DefaultPointRepresentation <PointXYZI> : public PointRepresentation <PointXYZI>
00183 {
00184 public:
00185 DefaultPointRepresentation ()
00186 {
00187 nr_dimensions_ = 3;
00188 }
00189
00190 virtual void
00191 copyToFloatArray (const PointXYZI &p, float * out) const
00192 {
00193 out[0] = p.x;
00194 out[1] = p.y;
00195 out[2] = p.z;
00196
00197 }
00198 };
00199
00200 template <>
00201 class DefaultPointRepresentation <PointNormal> : public PointRepresentation <PointNormal>
00202 {
00203 public:
00204 DefaultPointRepresentation ()
00205 {
00206 nr_dimensions_ = 3;
00207 }
00208
00209 virtual void
00210 copyToFloatArray (const PointNormal &p, float * out) const
00211 {
00212 out[0] = p.x;
00213 out[1] = p.y;
00214 out[2] = p.z;
00215 }
00216 };
00217
00218 template <>
00219 class DefaultPointRepresentation <PFHSignature125> : public PointRepresentation <PFHSignature125>
00220 {
00221 public:
00222 DefaultPointRepresentation ()
00223 {
00224 nr_dimensions_ = 125;
00225 }
00226
00227 virtual void
00228 copyToFloatArray (const PFHSignature125 &p, float * out) const
00229 {
00230 for (int i = 0; i < nr_dimensions_; ++i)
00231 out[i] = p.histogram[i];
00232 }
00233 };
00234
00235 template <>
00236 class DefaultPointRepresentation <FPFHSignature33> : public PointRepresentation <FPFHSignature33>
00237 {
00238 public:
00239 DefaultPointRepresentation ()
00240 {
00241 nr_dimensions_ = 33;
00242 }
00243
00244 virtual void
00245 copyToFloatArray (const FPFHSignature33 &p, float * out) const
00246 {
00247 for (int i = 0; i < nr_dimensions_; ++i)
00248 out[i] = p.histogram[i];
00249 }
00250 };
00251 }
00252
00253 #endif // #ifndef PCL_POINT_REPRESENTATION_H_