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 #ifndef OPENMS_ANALYSIS_MAPMATCHING_POSECLUSTERINGPAIRWISEMAPMATCHER_H
00029 #define OPENMS_ANALYSIS_MAPMATCHING_POSECLUSTERINGPAIRWISEMAPMATCHER_H
00030
00031 #include <OpenMS/ANALYSIS/MAPMATCHING/BasePairwiseMapMatcher.h>
00032 #include <OpenMS/ANALYSIS/MAPMATCHING/PoseClusteringShiftSuperimposer.h>
00033 #include <OpenMS/ANALYSIS/MAPMATCHING/PoseClusteringAffineSuperimposer.h>
00034 #include <OpenMS/ANALYSIS/MAPMATCHING/BaseSuperimposer_impl.h>
00035 #include <OpenMS/ANALYSIS/MAPMATCHING/BasePairFinder.h>
00036 #include <OpenMS/ANALYSIS/MAPMATCHING/SimplePairFinder.h>
00037 #include <OpenMS/ANALYSIS/MAPMATCHING/BasePairFinder_impl.h>
00038 #include <OpenMS/KERNEL/DPeakConstReferenceArray.h>
00039 #include <OpenMS/CONCEPT/Factory.h>
00040 #include <OpenMS/DATASTRUCTURES/StringList.h>
00041
00042
00043 #define V_PoseClusteringPairwiseMapMatcher(bla) // std::cout << bla << std::endl;
00044
00045
00046
00047 namespace OpenMS
00048 {
00071 template < typename MapT = FeatureMap< > >
00072 class PoseClusteringPairwiseMapMatcher
00073 : public BasePairwiseMapMatcher<MapT>
00074 {
00075 public:
00079 enum Maps
00080 {
00081 MODEL = 0,
00082 SCENE = 1
00083 };
00084
00086 typedef BasePairwiseMapMatcher<MapT> Base;
00087
00088 typedef typename Base::PointMapType PointMapType;
00089 typedef typename Base::ElementType ElementType;
00090 typedef typename Base::PositionType PositionType;
00091 typedef typename Base::CoordinateType CoordinateType;
00092
00093 typedef DPeakConstReferenceArray< PointMapType > PeakConstReferenceMapType;
00094
00095 using Base::param_;
00096 using Base::defaults_;
00097 using Base::subsections_;
00098 using Base::element_map_;
00099 using Base::grid_;
00100 using Base::all_element_pairs_;
00101 using Base::bounding_box_scene_map_;
00102 using Base::box_size_;
00103 using Base::number_buckets_;
00104
00105
00107 PoseClusteringPairwiseMapMatcher()
00108 : Base(),
00109 superimposer_(0),
00110 pair_finder_(0)
00111 {
00112
00113 Base::setName(getProductName());
00114
00115 defaults_.setValue("pairfinder:type", "DelaunayPairFinder","The pair finder used ");
00116 defaults_.setValidStrings("pairfinder:type",Factory<BasePairFinder<PointMapType> >::registeredProducts());
00117 defaults_.setValue("superimposer:type", "poseclustering_affine","The superimposer used ");
00118 StringList superimposer_list = Factory<BaseSuperimposer<PeakConstReferenceMapType> >::registeredProducts();
00119 superimposer_list.push_back("none");
00120 defaults_.setValidStrings("superimposer:type",superimposer_list);
00121 subsections_.push_back("debug");
00122 subsections_.push_back("pairfinder");
00123 subsections_.push_back("superimposer");
00124
00125 Base::defaultsToParam_();
00126 }
00127
00129 virtual ~PoseClusteringPairwiseMapMatcher()
00130 {
00131 }
00132
00134 static BasePairwiseMapMatcher<MapT>* create()
00135 {
00136 return new PoseClusteringPairwiseMapMatcher();
00137 }
00138
00140 static const String getProductName()
00141 {
00142 return "poseclustering_pairwise";
00143 }
00144
00146 virtual void run()
00147 {
00148
00149 if (grid_.size() == 0)
00150 {
00151 initGridTransformation(*(element_map_[SCENE]));
00152 }
00153
00154
00155 all_element_pairs_.clear();
00156
00157
00158 PeakConstReferenceMapType scene_pointer_map(element_map_[SCENE]->begin(), element_map_[SCENE]->end());
00159 UInt number_grid_cells = grid_.size();
00160 std::vector<PeakConstReferenceMapType> scene_grid_maps(number_grid_cells);
00161 buildGrid_(scene_pointer_map,scene_grid_maps);
00162
00163
00164 PeakConstReferenceMapType model_pointer_map(element_map_[MODEL]->begin(), element_map_[MODEL]->end());
00165
00166
00167 computeMatching_(model_pointer_map,scene_grid_maps);
00168 }
00169
00170 protected:
00171 virtual void updateMembers_()
00172 {
00173 Base::updateMembers_();
00174
00175
00176 if (pair_finder_==0 || pair_finder_->getName()!=param_.getValue("pairfinder:type"))
00177 {
00178 delete pair_finder_;
00179 pair_finder_ = Factory<BasePairFinder<PeakConstReferenceMapType> >::create(param_.getValue("pairfinder:type"));
00180 }
00181
00182 Param param_copy = param_.copy("pairfinder:",true);
00183 param_copy.remove("type");
00184 if (!(pair_finder_->getParameters()==param_copy))
00185 {
00186 pair_finder_->setParameters(param_copy);
00187 }
00188
00189
00190 String type = param_.getValue("superimposer:type");
00191 if (superimposer_==0)
00192 {
00193 if (type != "none")
00194 {
00195 delete superimposer_;
00196 superimposer_ = Factory<BaseSuperimposer<PeakConstReferenceMapType> >::create(type);
00197 }
00198 }
00199 else
00200 {
00201 if (type == "none")
00202 {
00203 delete superimposer_;
00204 }
00205 else if (superimposer_->getName()!=type)
00206 {
00207 delete superimposer_;
00208 superimposer_ = Factory<BaseSuperimposer<PeakConstReferenceMapType> >::create(type);
00209 }
00210 }
00211
00212 if (superimposer_!=0)
00213 {
00214 Param param_copy = param_.copy("superimposer:",true);
00215 param_copy.remove("type");
00216 if (!(superimposer_->getParameters()==param_copy))
00217 {
00218 superimposer_->setParameters(param_copy);
00219 }
00220 }
00221 }
00222
00224 BaseSuperimposer<PeakConstReferenceMapType>* superimposer_;
00226 BasePairFinder< PeakConstReferenceMapType >* pair_finder_;
00227
00229 void computeMatching_(const PeakConstReferenceMapType& model_map, const std::vector<PeakConstReferenceMapType>& scene_grid_maps)
00230 {
00231 #define V_computeMatching_(bla) V_PoseClusteringPairwiseMapMatcher(bla)
00232
00233 pair_finder_->setElementMap(MODEL, model_map);
00234
00235 if (superimposer_ !=0 )
00236 {
00237
00238 superimposer_->setElementMap(MODEL, model_map);
00239 }
00240
00241 String shift_buckets_file;
00242 if (param_.exists("debug:shift_buckets_file"))
00243 {
00244 shift_buckets_file = param_.getValue("debug:shift_buckets_file");
00245 }
00246 String element_buckets_file;
00247 if (param_.exists("debug:feature_buckets_file"))
00248 {
00249 element_buckets_file = param_.getValue("debug:feature_buckets_file");
00250 }
00251
00252
00253 for (UInt i = 0; i < scene_grid_maps.size(); ++i)
00254 {
00255 if (scene_grid_maps[i].size() > 0)
00256 {
00257 if ( superimposer_ != 0 )
00258 {
00259 V_computeMatching_("PoseClusteringPairwiseMapMatcher: superimposer \"pose_clustering\", start superimposer");
00260
00261 superimposer_->setElementMap(SCENE, scene_grid_maps[i]);
00262 superimposer_->run();
00263
00264 grid_[i].getMappings().resize(2);
00265 for ( UInt dim = 0; dim < 2; ++dim )
00266 {
00267 grid_[i].getMappings()[dim] = superimposer_->getTransformation(dim);
00268 pair_finder_->setTransformation(dim, superimposer_->getTransformation(dim));
00269 }
00270 }
00271 else
00272 {
00273 V_computeMatching_("PoseClusteringPairwiseMapMatcher: algorithm \"simple\", skip superimposer");
00274 }
00275
00276
00277 pair_finder_->setElementPairs(all_element_pairs_);
00278 pair_finder_->setElementMap(SCENE, scene_grid_maps[i]);
00279
00280 V_computeMatching_("PoseClusteringPairwiseMapMatcher: start pairfinder");
00281 pair_finder_->findElementPairs();
00282 }
00283 }
00284 #undef V_computeMatching_
00285
00286 }
00287
00288
00290 void buildGrid_(const PeakConstReferenceMapType& scene_map, std::vector<PeakConstReferenceMapType>& scene_grid_maps)
00291 {
00292 #define V_buildGrid_(bla) V_PoseClusteringPairwiseMapMatcher(bla)
00293 V_buildGrid_("PoseClusteringPairwiseMapMatcher: buildGrid_(): starting...");
00294
00295 for (UInt i = 0; i < scene_map.size(); ++i)
00296 {
00297 CoordinateType x = scene_map[i].getRT() - bounding_box_scene_map_.min()[RawDataPoint2D::RT];
00298 CoordinateType y = scene_map[i].getMZ() - bounding_box_scene_map_.min()[RawDataPoint2D::MZ];
00299
00300 UInt grid_index = (int)(x / box_size_[RawDataPoint2D::RT]) + (int)(y / box_size_[RawDataPoint2D::MZ]) * (int)(number_buckets_[RawDataPoint2D::RT]);
00301 scene_grid_maps[grid_index].push_back(scene_map[i]);
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 #undef V_buildGrid_
00314
00315 }
00316 }
00317 ;
00318 }
00319
00320 #endif // OPENMS_ANALYSIS_MAPMATCHING_POSECLUSTERINGPAIRWISEMAPMATCHER_H