Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

PoseClusteringPairwiseMapMatcher.h (Maintainer: Eva Lange)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Eva Lange $
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       //set the name for DefaultParamHandler error messages
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       // compute the bounding boxes of the grid cells and initialize the grid transformation
00149       if (grid_.size() == 0)
00150       {
00151         initGridTransformation(*(element_map_[SCENE]));
00152       }
00153       
00154       // clear pairs
00155       all_element_pairs_.clear();
00156 
00157       // assign each element of the scene map to the grid cells and build a pointer map for each grid cell
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       // initialize a pointer map with the elements of the first (model or reference) map
00164       PeakConstReferenceMapType model_pointer_map(element_map_[MODEL]->begin(), element_map_[MODEL]->end());
00165 
00166       // compute the matching of each scene's grid cell elements and all the elements of the model map
00167       computeMatching_(model_pointer_map,scene_grid_maps);
00168     }
00169 
00170   protected:
00171    virtual void updateMembers_()
00172     {
00173       Base::updateMembers_();
00174       
00175       //create pairfinder if it does not exist or if it changed
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       //update pairfinder parameters if necessary
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       //update superimposer
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       //update superimposer parameters if necessary
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         // same model map for all superpositions
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       // iterate over all grid cells of the scene map
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             // ???? copy array to vector -- but the old Grid class will be replaced anyway
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       //       for (UInt i = 0; i < scene_grid_maps.size(); ++i)
00305       //       {
00306       //         V_buildGrid_("scene_grid_maps["<<i<<"].size(): "<<scene_grid_maps[i].size()<<'\n');
00307       //
00308       //         for (UInt j = 0; j < scene_grid_maps[i].size(); ++j)
00309       //         {
00310       //           V_buildGrid_(((scene_grid_maps[i])[j]).getPosition());
00311       //         }
00312       //       }
00313 #undef V_buildGrid_
00314 
00315     }
00316   }
00317   ; // PoseClusteringPairwiseMapMatcher
00318 } // namespace OpenMS
00319 
00320 #endif  // OPENMS_ANALYSIS_MAPMATCHING_POSECLUSTERINGPAIRWISEMAPMATCHER_H

Generated Tue Apr 1 15:36:37 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1