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

virtual void Impala::Core::ImageSet::InterestPointProc::HandleDoneDir ( ImageSet is,
int  dirId 
) [inline, virtual]

Completed given DB_DIR in a "normal" walk.

Reimplemented from Impala::Core::ImageSet::Listener.

Definition at line 218 of file InterestPointProc.h.

References Impala::Core::Feature::FeatureDefinition::AsString(), Impala::Core::Feature::InterestPointFeature::GetFeatureName(), Impala::Util::Database::GetIOBuffer(), Impala::GetTmpPath(), ILOG_ERROR, ILOG_INFO, ILOG_WARN, Impala::MakeString(), Impala::Core::Feature::InterestPointFeature::mClusterInput, Impala::Core::Feature::InterestPointFeature::mClusterInputData, Impala::Core::Feature::InterestPointFeature::mFeatureDefinition, mFeatureTables, mInterestPointFeature, mNoZIP, mSkipThisFolder, mTableInfoString, mTempFilenames, Impala::PathJoin(), Impala::Util::IOBuffer::Read(), Impala::StringReplace(), Impala::Util::IOBuffer::Write(), and Impala::Core::Table::Write().

00219     {
00220         if(mSkipThisFolder) return;
00221         int fileId = is->GetFirstFileId(dirId);
00222 
00223         // Feature table logic
00224         Feature::FeatureDefinition fdef = mInterestPointFeature.mFeatureDefinition;
00225         String tableName = is->GetFilePathFeatureData
00226             (fdef, dirId, false, -1, true, false);
00227         if(mFeatureTables.size() != 0)
00228         {
00229             for(int i = 0; i < mFeatureTables.size(); i++)
00230             {
00231                 Feature::FeatureDefinition tempDef(fdef.AsString());
00232                 if(i != 0)
00233                     tempDef.AddParameter("sub", MakeString(i));
00234                 String tempTableName = is->GetFilePathFeatureData
00235                     (tempDef, dirId, false, -1, true, false);
00236                 mFeatureTables[i]->SetInfo(mTableInfoString);
00237                 Write(mFeatureTables[i], tempTableName, is->GetDatabase(), true);
00238                 //for debugging:
00239                 //Feature::DumpFeatureTableHistogram(mFeatureTables[i], tempDef, dirId);
00240                 delete mFeatureTables[i];
00241                 mFeatureTables[i] = 0;
00242             }
00243             mFeatureTables.clear();
00244         }
00245         
00246         // ZIP-file logic
00247         if(!mNoZIP)
00248         {
00249             String featureName = mInterestPointFeature.GetFeatureName();
00250             String fName = PathJoin(GetTmpPath(), "tmp-" + featureName +
00251                                          "-" + MakeString(dirId) + ".zip");
00252             String txtName = StringReplace(fName, ".zip", ".txt");
00253             String serverName = is->GetFilePathFeatureData
00254                 (featureName + ".zip", dirId, false, -1, true, false);
00255             if (fName == String(""))
00256             {
00257                 ILOG_ERROR("Empty file name");
00258             }
00259             serverName = StringReplace(serverName, ".zip.tab", ".tab.zip");
00260                         
00261             // put it all in fName
00262             std::ofstream fs(txtName.c_str());
00263             for(std::vector<String>::iterator iter = mTempFilenames.begin();
00264                 iter != mTempFilenames.end(); iter++)
00265             {
00266                 fs << (*iter) << std::endl;
00267             }
00268             fs.close();
00269     
00270             String cmd = "zip ";
00271             cmd += fName;
00272             cmd += " -@ <";
00273             cmd += txtName;
00274             //TODO: call toZip.py here? Instead of Shell scripting?
00275             if (serverName != String(""))
00276             {
00277                 // without override, fName will be empty if zip file already
00278                 // exists, so we cannot ZIP!
00279                 system(cmd.c_str());
00280             }
00281 
00282             // cleanup
00283             if(std::remove(txtName.c_str()) != 0) {
00284                 ILOG_WARN("Could not cleanup intermediate file: " << txtName);
00285             }
00286             
00287             // copy ZIP file to its final destination
00288             Util::IOBuffer* zip = new Util::IOBufferFile(fName, true, false);
00289             Util::Database* database = is->GetDatabase();
00290             Util::IOBuffer* destination = database->GetIOBuffer
00291                 (serverName, false, false, "tmp", 0, true);
00292             static const int bufSize = 1024 * 1024;
00293             static unsigned char buffer[bufSize];
00294             while(true)
00295             {
00296                 int bytesread = zip->Read(buffer, bufSize);
00297                 if(bytesread == 0)
00298                     break;
00299                 destination->Write(buffer, bytesread);
00300             }
00301             delete zip;
00302             delete destination; // this will force a write through a channel, if
00303                                 // needed
00304 
00305             // cleanup
00306             if(std::remove(fName.c_str()) != 0) {
00307                 ILOG_WARN("Could not cleanup temporary ZIP file: " << fName);
00308             }
00309         }
00310 
00311         // clusterInput mode
00312         if(mInterestPointFeature.mClusterInput &&
00313            mInterestPointFeature.mClusterInputData)
00314         {
00315             String tableName = is->GetFilePathFeatureData
00316                 (mInterestPointFeature.mClusterInputData->GetFeatureDefinition(),
00317                  dirId, false, -1, true, false);
00318             Write(mInterestPointFeature.mClusterInputData, tableName,
00319                   is->GetDatabase(), true);
00320             delete mInterestPointFeature.mClusterInputData;
00321             mInterestPointFeature.mClusterInputData = 0;
00322         }
00323         
00324         // cleanup
00325         for(std::vector<String>::iterator iter = mTempFilenames.begin();
00326             iter != mTempFilenames.end(); iter++)
00327         {
00328             if(std::remove((*iter).c_str()) != 0)
00329             {
00330                 ILOG_WARN("Could not cleanup intermediate file: " << (*iter));
00331             }
00332         }
00333         mTempFilenames.clear();
00334         ILOG_INFO("HandleDoneDir: " << dirId);
00335     }

Here is the call graph for this function:


Generated on Fri Mar 19 11:14:49 2010 for ImpalaSrc by  doxygen 1.5.1