Esempio n. 1
0
 void ReadDirectory::execute(DataProvider& provider)
 {
     if (m_files.size() == 0)
         throw OperatorError(*this, "Directory is empty.");
         
     Data* data = 0;
     std::size_t index = m_currentIndex;
     do
     {
         boost::filesystem::path file(m_files[index]);
         index = (index + 1) % m_files.size();
         std::string ext = file.extension().string();
         std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
         if (ext == ".png" || ext == ".jpg" || ext == ".jpeg")
         {
             data = new cvsupport::Image(file.string());
         }
     }
     while (data == 0 && index != m_currentIndex);
     
     m_currentIndex = index;
     
     if (data == 0)
         throw OperatorError(*this, "Found no usable file in selected directory.");
     
     DataContainer container(data);
     Id2DataPair outputDataMapper(OUTPUT, container);
     provider.sendOutputData(outputDataMapper);
 }
Esempio n. 2
0
 void ConstData::execute(DataProvider& provider)
 {
     if (! valuePtr())
         throw InternalError("Value has not been set");
     
     DataContainer data;
     if (m_allocateData)
     {
         data = DataContainer(valuePtr()->clone());
     }
     else
     {
         Data* dataPtr = 0;
         
         if (m_recycleAccess.empty())
         {
             // if this is the first time the operator executes the value must
             // be cloned
             dataPtr = valuePtr()->clone();
         }
         else 
         {         
             // otherwise the value in the recycler can be reused              
             dataPtr = m_recycleAccess.get();
         }
             
         if (dataPtr != valuePtr())
         {
             // if the value was changed by the user since the last execution
             // update it
             delete dataPtr;
             dataPtr = valuePtr()->clone();
         }
         
         // send and remember for the next execution
         data = DataContainer(dataPtr);
         m_recycleAccess.add(data);
     }
     
     Id2DataPair outputDataMapper(OUTPUT, data);
     provider.sendOutputData( outputDataMapper);
 }
Esempio n. 3
0
 void Flicker::execute(DataProvider& provider)
 {
     Id2DataPair inputDataMapper(INPUT);
     provider.receiveInputData(inputDataMapper);
     
     DataContainer container = inputDataMapper.data();
     WriteAccess access(container);
     runtime::Image& image = access.get<runtime::Image>();
     
     switch(image.depth())
     {
     case 1:
         applyFlicker<uint8_t>(m_amount, image);
         break;
     case 2:
         applyFlicker<uint16_t>(m_amount, image);
         break;
     default:
         throw WrongInputType(INPUT, *this);
     }
     
     Id2DataPair outputDataMapper(OUTPUT, container);
     provider.sendOutputData( outputDataMapper);
 }