MultiMarker.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
00003  *
00004  * Copyright 2007-2012 VTT Technical Research Centre of Finland
00005  *
00006  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
00007  *          <http://www.vtt.fi/multimedia/alvar.html>
00008  *
00009  * ALVAR is free software; you can redistribute it and/or modify it under the
00010  * terms of the GNU Lesser General Public License as published by the Free
00011  * Software Foundation; either version 2.1 of the License, or (at your option)
00012  * any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful, but WITHOUT
00015  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with ALVAR; if not, see
00021  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
00022  */
00023 
00024 #ifndef MULTIMARKER_H
00025 #define MULTIMARKER_H
00026 
00033 #include "Alvar.h"
00034 #include "Rotation.h"
00035 #include "MarkerDetector.h"
00036 #include "Camera.h"
00037 #include "Filter.h"
00038 #include "FileFormat.h"
00039 #include <tf/LinearMath/Vector3.h>
00040 #include <Eigen/StdVector>
00041 
00042 namespace alvar {
00043 
00047 class ALVAR_EXPORT MultiMarker {
00048 
00049 
00050 private:
00051 
00052         bool SaveXML(const char* fname);
00053         bool SaveText(const char* fname);
00054         bool LoadText(const char* fname);
00055         bool LoadXML(const char* fname);
00056 
00057 public:
00058     // The marker information is stored in all three tables using 
00059         // the indices-order given in constructor. 
00060         // One idea is that the same 'pointcloud' could contain feature 
00061         // points after marker-corner-points. This way they would be
00062         // optimized simultaneously with marker corners...
00063         std::map<int, CvPoint3D64f> pointcloud;
00064         std::vector<int> marker_indices; // The marker id's to be used in marker field (first being the base)
00065         std::vector<int> marker_status;  // 0: not in point cloud, 1: in point cloud, 2: used in GetPose()
00066     std::vector< std::vector<tf::Vector3> > rel_corners; //The coords of the master marker relative to each child marker in marker_indices
00067 
00068         int pointcloud_index(int marker_id, int marker_corner, bool add_if_missing=false);
00069         int get_id_index(int id, bool add_if_missing=false);
00070 
00071         double _GetPose(MarkerIterator &begin, MarkerIterator &end, Camera* cam, Pose& pose, IplImage* image);
00072 
00073         int _SetTrackMarkers(MarkerDetectorImpl &marker_detector, Camera* cam, Pose& pose, IplImage *image);
00074         int master_id;  //The id of the first marker specified in the XML file 
00075 
00076 
00078         virtual void Reset();
00079 
00084         bool Save(const char* fname, FILE_FORMAT format = FILE_FORMAT_DEFAULT);
00085 
00090         bool Load(const char* fname, FILE_FORMAT format = FILE_FORMAT_DEFAULT);
00091 
00095         MultiMarker(std::vector<int>& indices);
00096 
00098         MultiMarker() {}
00099 
00108         template <class M>
00109         double GetPose(const std::vector<M, Eigen::aligned_allocator<M> >* markers, Camera* cam, Pose& pose, IplImage* image = 0)
00110         {
00111                 MarkerIteratorImpl<M> begin(markers->begin());
00112                 MarkerIteratorImpl<M> end(markers->end());
00113                 return _GetPose(begin, end,
00114                                                 cam, pose, image);
00115         }
00116 
00119         template <class M>
00120         double Update(const std::vector<M, Eigen::aligned_allocator<M> >* markers, Camera* cam, Pose& pose, IplImage* image = 0)
00121         {
00122                 if(markers->size() < 1) return -1.0;
00123 
00124                 return GetPose(markers, cam, pose, image);
00125         }
00126 
00129         void PointCloudReset();
00130 
00137         void PointCloudCorners3d(double edge_length, Pose &pose, CvPoint3D64f corners[4]);
00138 
00144         void PointCloudAdd(int marker_id, double edge_length, Pose &pose);
00145 
00148         void PointCloudCopy(const MultiMarker *m);
00149 
00152         bool PointCloudIsEmpty() {
00153                 return pointcloud.empty();
00154         }
00155 
00157         size_t Size() {
00158                 return marker_indices.size();
00159         }
00160 
00168         void PointCloudGet(int marker_id, int point,
00169         double &x, double &y, double &z);
00170 
00174         bool IsValidMarker(int marker_id);
00175 
00176         std::vector<int> getIndices(){
00177                 return marker_indices;
00178         }
00179 
00180         int getMasterId(){
00181                 return master_id;
00182         }
00183 
00190         template <class M>
00191         int SetTrackMarkers(MarkerDetector<M> &marker_detector, Camera* cam, Pose& pose, IplImage *image=0) {
00192     return _SetTrackMarkers(marker_detector, cam, pose, image);
00193         }
00194 };
00195 
00196 } // namespace alvar
00197 
00198 #endif


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Feb 16 2017 03:23:02