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

String Impala::Core::Feature::ReadBINDESC1FromBuffer ( Matrix::Mat *&  points,
Matrix::Mat *&  descriptors,
Util::IOBuffer *  buffer,
bool  readPoints,
bool  readDescriptors 
)

Definition at line 144 of file PointDescriptorIO.h.

References Impala::Util::StringParser::GetDouble(), Impala::Util::StringParser::GetString(), ILOG_DEBUG, ILOG_ERROR, ILOG_VAR, Impala::Core::Matrix::MatE(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::mData, Impala::Util::IOBuffer::Read(), Impala::Util::IOBuffer::ReadLine(), and Impala::Util::IOBuffer::Seek().

Referenced by Impala::Core::Feature::PointDescriptorTable::ImportFromBuffer(), and ReadCodebookFromBuffer().

00145 {
00146     ILOG_VAR(Core.Feature.PointDescriptorIO.ReadBINDESC1FromBuffer);
00147 
00148     using namespace Impala::Core::Matrix;    
00149     char buf[9];
00150     for (int i=0 ; i<9 ; i++)
00151         buf[i] = 0;
00152     buffer->Read(buf, 8);
00153     
00154     if(String(buf) == "BINDESC1")
00155     {
00156         /* Format BINDESC1
00157            -----------------------
00158            First 8 bytes: BINDESC1
00159            Second 8 bytes: data type (CIRCLE is typical)
00160            Next 16 bytes: 4 integers:
00161                             elementsPerPoint = values[0]
00162                             dimensionCount = values[1]
00163                             pointCount = values[2]
00164                             bytesPerElement = values[3]
00165         */
00166         int elementsPerPoint = 0;
00167         int dimensionCount = 0;
00168         int pointCount = 0;
00169         int bytesPerElement = 8;
00170     
00171         String dataType = "UNKNOWN ";
00172         
00173         char buf[9];
00174         for (int i=0 ; i<9 ; i++)
00175             buf[i] = 0;
00176         
00177         ILOG_DEBUG("Reading header...");
00178         
00179         // read dataType
00180         buffer->Read(buf, 8);
00181         dataType = String(buf);
00182     
00183         buffer->Read(&elementsPerPoint, 4);
00184         buffer->Read(&dimensionCount, 4);
00185         buffer->Read(&pointCount, 4);
00186         buffer->Read(&bytesPerElement, 4);
00187         ILOG_DEBUG("Read full header");
00188         if(bytesPerElement != 8)
00189         {
00190             ILOG_ERROR("Can only read BINDESC1 with 8 bytes per element (double)");
00191             return "";
00192         }
00193     
00194         if(!readPoints)
00195         {
00196             buffer->Seek(elementsPerPoint * pointCount * bytesPerElement, SEEK_CUR);
00197         }
00198         else
00199         {
00200             points = MatCreate<Mat>(pointCount, elementsPerPoint);
00201             buffer->Read(points->mData, elementsPerPoint * pointCount * bytesPerElement);
00202         }
00203     
00204         if(readDescriptors)
00205         {
00206             descriptors = MatCreate<Mat>(pointCount, dimensionCount);
00207             if(dimensionCount > 0)
00208                 buffer->Read(descriptors->mData, dimensionCount * pointCount * 
00209                              bytesPerElement);
00210         }
00211 
00212         return dataType;
00213     }
00214     else if(String(buf).substr(0, 5) == "KOEN1")
00215     {
00216         /* Format KOEN version 1.0
00217            -----------------------
00218            First line:  KOEN1 (format version)
00219            Second line: Descriptor dimensionality count (0 if only interest items)
00220            Third line:  Number of interest items
00221         */
00222         buffer->Seek(0, SEEK_SET);
00223         
00224         // first line: KOEN1
00225         String header = buffer->ReadLine();
00226         if(header != String("KOEN1"))
00227         {
00228             ILOG_ERROR("Unsupported region format: " << header);
00229             return "";
00230         }
00231     
00232         // second line: dimensionality
00233         int dimensionCount = Util::StringParser(buffer->ReadLine()).GetInt();
00234         int pointCount = Util::StringParser(buffer->ReadLine()).GetInt();
00235         ILOG_DEBUG("Reading file; dimensionCount = " << dimensionCount << "; pointCount = " << pointCount);
00236         if(readPoints)
00237             points = MatCreate<Mat>(pointCount, 5);
00238         if(readDescriptors) 
00239             descriptors = MatCreate<Mat>(pointCount, dimensionCount);
00240 
00241         for(int i = 0; i < pointCount; i++)
00242         {
00243             String line = buffer->ReadLine();
00244             Util::StringParser sp2(line);
00245             String region = sp2.GetString(';');
00246             if(readPoints)
00247             {
00248                 if(region.substr(0, 8) == "<CIRCLE ")
00249                 {
00250                     Util::StringParser sp(region);
00251                     String temp = sp.GetString(' ');   // ignore <CIRCLE
00252                     *MatE(points, i, 0) = sp.GetDouble(' ');
00253                     *MatE(points, i, 1) = sp.GetDouble(' ');
00254                     *MatE(points, i, 2) = sp.GetDouble(' ');
00255                     *MatE(points, i, 3) = sp.GetDouble(' ');
00256                     *MatE(points, i, 4) = sp.GetDouble('>');
00257                 }
00258                 else
00259                 {
00260                     ILOG_ERROR("Unsupported region: " << region);
00261                     throw "Unsupported serialization type!";
00262                 }
00263             }
00264     
00265             if(readDescriptors)
00266             {
00267                 String descriptor = sp2.GetString(';');
00268                 Util::StringParser sp3(descriptor);
00269                 if(dimensionCount > 0)
00270                 {
00271                     for(int j = 0; j < dimensionCount; j++)
00272                     {
00273                         *MatE(descriptors, i, j) = sp3.GetDouble();
00274                     }
00275                 }
00276             }
00277         }
00278         return "CIRCLE";
00279     }
00280     else
00281     {
00282         ILOG_ERROR("Unknown format to read point descriptors from: " << String(buf));
00283         return "ERROR";
00284     }
00285 }

Here is the call graph for this function:


Generated on Thu Jan 13 09:19:03 2011 for ImpalaSrc by  doxygen 1.5.1