/* * Scheduler * * Author: Andrew Salamon * Date: Thu Apr 20 2006 * * This class is an adaptor between the mp_alignEyesMex and the interpolator that does the image * rotation. Primarily it does some setup, calls the interpolator, then does some teardown. * Arguments: * pixels: input image (full size) * patchSize: size (width and height) for the rotated face image * xl, xr, yl, yr: eye coordinates * Return value: * The rotated and cropped face. It was allocated with new, so needs to be deleted when the caller is done with it. * * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef __MP_THREADEDGABOR_H__ #define __MP_THREADEDGABOR_H__ #include #include #include "mp_CERT.h" #include "CERT_Task.h" #include "CERT_Loader.h" #include "threadpool.hpp" #include "tqueue.h" /** Scheduler runs multiple CERT objects in separate threads. * */ namespace CERT { class Scheduler { public: Scheduler( const std::vector< std::string > &_paths, int numThreads = 4 ); virtual ~Scheduler(); void start(); bool finished(); ///< returns true when all inputs have been finished. void interrupt(); // These two are called by the threads void run( MP_CERT *cert ); void output(); private: Loader loader; std::vector processors; concurrent_queue available; // std::priority_queue< Task, std::vector, Task::compare > taskBuffer; // concurrent_queue< Task, std::priority_queue< Task, std::vector, Task::compare > > taskBuffer; concurrent_queue< Task, pqueue< Task, std::vector, Task::compare > > taskBuffer; int nextFrame; boost::threadpool::pool certPool; bool _interrupt; bool poolEmpty; private: Scheduler( const Scheduler& ); Scheduler &operator=( const Scheduler& ); std::ostream &mout(); void postProcessTask( Task &task ); public: class exception : public std::runtime_error { public: exception( const std::string &msg ) : std::runtime_error(msg) { } }; }; } // end namespace CERT #endif