Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

PointDescriptorTable.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Feature_PointDescriptorTable_h
00002 #define Impala_Core_Feature_PointDescriptorTable_h
00003 
00004 #include "Core/Array/Arrays.h"
00005 #include "Core/Vector/VectorSet.h"
00006 #include "Core/Column/Find.h"
00007 #include "Core/Column/Copy.h"
00008 #include "Core/Table/Read.h"
00009 #include "Core/Feature/FeatureDefinition.h"
00010 #include "Core/Table/Read.h"
00011 #include "Core/Table/Append.h"
00012 
00013 #include "Core/Geometry/InterestPointListIO.h"
00014 #include "Core/Geometry/InterestPointList.h"
00015 #include "Core/Geometry/InterestCircle.h"
00016 
00017 namespace Impala
00018 {
00019 namespace Core
00020 {
00021 namespace Feature
00022 {
00023 
00024 
00025 typedef Table::TableTem<Column::ColumnTem<Real64>,
00026                         Column::ColumnTem<Real64>,
00027                         Column::ColumnTem<Real64>,
00028                         Column::ColumnTem<Real64>,
00029                         Column::ColumnTem<Real64>,
00030                         Vector::VectorSet<Array::Array2dScalarReal64> >
00031         PointDescriptorTableBaseType;
00032 
00033 
00036 class PointDescriptorTable : public PointDescriptorTableBaseType
00037 {
00038 public:
00039     typedef Column::ColumnTem<Real64> ColumnReal64;
00040     typedef Vector::VectorSet<Array::Array2dScalarReal64> ColumnVectorSet;
00041     typedef Vector::VectorTem<Real64> VectorReal64;
00042 
00043     PointDescriptorTable(FeatureDefinition def=FeatureDefinition("")) :
00044         PointDescriptorTableBaseType(ColumnReal64(0), ColumnReal64(0), 
00045                     ColumnReal64(0), ColumnReal64(0), ColumnReal64(0),
00046                                      ColumnVectorSet(true, 0, 0))
00047     {
00048         mFeatureDef = def;
00049         SetColName(1, "x");
00050         SetColName(2, "y");
00051         SetColName(3, "scale");
00052         SetColName(4, "orientation");
00053         SetColName(5, "cornerness");
00054         SetColName(6, mFeatureDef.GetName());
00055     }
00056 
00057     PointDescriptorTable(FeatureDefinition def, int tableSize, int vecLen) :
00058         PointDescriptorTableBaseType(ColumnReal64(tableSize),
00059                                      ColumnReal64(tableSize), 
00060                                      ColumnReal64(tableSize), 
00061                                      ColumnReal64(tableSize), 
00062                                      ColumnReal64(tableSize), 
00063                                      ColumnVectorSet(true, vecLen, tableSize))
00064     {
00065         mFeatureDef = def;
00066         SetColName(1, "x");
00067         SetColName(2, "y");
00068         SetColName(3, "scale");
00069         SetColName(4, "orientation");
00070         SetColName(5, "cornerness");
00071         SetColName(6, mFeatureDef.GetName());
00072     }
00073 
00074     inline Real64
00075     GetX(int index) const
00076     {
00077         return Get1(index);
00078     }
00079 
00080     inline Real64
00081     GetY(int index) const
00082     {
00083         return Get2(index);
00084     }
00085 
00086     inline Real64
00087     GetScale(int index) const
00088     {
00089         return Get3(index);
00090     }
00091 
00092     inline Real64
00093     GetOrientation(int index) const
00094     {
00095         return Get4(index);
00096     }
00097     
00098     void
00099     SetDescriptor(int index, VectorReal64& v)
00100     {
00101         GetColumn6()->GetVector(index, true) = v;
00102     }
00103     
00104     Real64*
00105     GetDescriptorData(int index)
00106     {
00107         return GetColumn6()->GetVectorData(index);
00108     }
00109 
00110     static PointDescriptorTable*
00111     ImportFromFile(FeatureDefinition def, String filename, int mStripBorder)
00112     {
00113         Core::Geometry::InterestPointList outputPointList;
00114         Sandbox::Koen::ReadPointListFromFile(filename, outputPointList,
00115                               false, mStripBorder);
00116         
00117         PointDescriptorTable* res = new PointDescriptorTable(def);
00118         res->FromPointList(outputPointList);
00119         outputPointList.EraseAndDelete();
00120         return res;
00121     }
00122     
00123     void
00124     ExportToFile(String filename, int mStripBorder, String mOutputFormat)
00125     {
00126         Core::Geometry::InterestPointList outputPointList;
00127         ToPointList(outputPointList);
00128         Sandbox::Koen::WritePointListToFile(filename, outputPointList, true,
00129                              mStripBorder, mOutputFormat);
00130         outputPointList.EraseAndDelete();
00131     }
00132 
00133 /*    static PointDescriptorTable*
00134     MakeFromFile(FeatureDefinition def, String fileName, Util::Database* db)
00135     {
00136         PointDescriptorTable* res = new PointDescriptorTable(def);
00137         Read(res, fileName, db);
00138         return res;
00139     }*/
00140 
00141     FeatureDefinition
00142     GetFeatureDefinition()
00143     {
00144         return mFeatureDef;
00145     }
00146 
00147     void
00148     SetFeatureDefinition(FeatureDefinition def)
00149     {
00150         mFeatureDef = def;
00151     }
00152 
00153     int
00154     GetDescriptorLength()
00155     {
00156         return GetColumn6()->GetVectorLength(0);
00157     }
00158 
00159     void
00160     SetDescriptorLength(int descriptorLength)
00161     {
00162         int storageSize = GetColumn6()->GetStorage()->CH();
00163         Array::Array2dScalarReal64* descriptors = new 
00164              Array::Array2dScalarReal64(descriptorLength, storageSize, 0, 0);
00165         GetColumn6()->SetStorage(descriptors);
00166     }
00167 
00168     void
00169     ReplaceAllDescriptors(Array::Array2dScalarReal64* descriptors)
00170     {
00171         // this call takes ownership of descriptors memory
00172         GetColumn6()->SetStorage(descriptors);
00173     }
00174     
00175     void
00176     FromPointList(Core::Geometry::InterestPointList& pl)
00177     {
00178         if(pl.size() == 0) return;
00179         Reserve(pl.size(), false);
00180         int descriptorLength = (*pl.begin())->mDescriptor.size();
00181         Array::Array2dScalarReal64* descriptors = 0;
00182         if(descriptorLength > 0)
00183             descriptors = new Array::Array2dScalarReal64(descriptorLength, 
00184                                                          pl.size(), 0, 0);
00185 
00186         ILOG_DEBUG("extracting descriptor data");
00187         int idx = 0;
00188         for(Core::Geometry::InterestPointList::iterator it = pl.begin(); 
00189             it != pl.end(); it++)
00190         {
00191             Core::Geometry::InterestPoint* point = *it;
00192             std::string type  = point->geometryType();
00193             if(type != "CircleZ" && type != "RectangleZ" )
00194             {
00195                 ILOG_ERROR("Geometry type mismatch: " << point->geometryType());
00196                 return;
00197             }
00198             
00199             if(type == "CircleZ")
00200             {
00201                 Core::Geometry::InterestCircle* circle = 
00202                     dynamic_cast<Core::Geometry::InterestCircle*>(point);
00203                 Add(point->mX, point->mY, circle->mScale, circle->mOrientation, 
00204                     circle->mCornerness);
00205             }
00206             else if(type == "RectangleZ")
00207             {
00208                 Core::Geometry::InterestRectangleZ* rect = 
00209                     dynamic_cast<Core::Geometry::InterestRectangleZ*>(point);
00210                 Add(point->mX, point->mY, rect->Width(), rect->Height(), 0);
00211             }
00212             
00213             if(descriptorLength > 0)
00214             {
00215                 Vector::VectorTem<Real64> descriptor =
00216                     Vector::VectorTem<Real64>(point->mDescriptor.size());
00217                 Real64* ptr = descriptors->CPB(0, idx);
00218                 for(int j = 0; j < point->mDescriptor.size(); j++)
00219                 {
00220                     *ptr++ = point->mDescriptor[j];
00221                 }
00222             }
00223             idx++;
00224         }
00225         if(descriptorLength > 0)
00226             ReplaceAllDescriptors(descriptors);
00227     }
00228 
00229     void
00230     ToPointList(Core::Geometry::InterestPointList& pl)
00231     {
00232         for(int i = 0; i < Size(); i++)
00233         {
00234             Core::Geometry::InterestCircle* point = 
00235                  new Core::Geometry::InterestCircle(Get1(i), Get2(i), Get5(i));
00236             point->mScale = Get3(i);
00237             point->mOrientation = Get4(i);
00238             VectorReal64 v = Get6(i);
00239             for(int j = 0; j < GetDescriptorLength(); j++)
00240                 point->mDescriptor.push_back(v[j]);
00241             pl.push_back(point);
00242         }
00243     }
00244 
00245     ILOG_VAR_DEC;
00246 
00247 private:
00248 
00249     FeatureDefinition mFeatureDef;
00250 
00251 };
00252 
00253 ILOG_VAR_INIT(PointDescriptorTable, Impala.Core.Feature);
00254 
00255 } // namespace Feature
00256 } // namespace Core
00257 } // namespace Impala
00258 
00259 #endif

Generated on Fri Mar 19 09:31:07 2010 for ImpalaSrc by  doxygen 1.5.1