vision_master.cpp

00001
00002 /***************************************************************************
00003  *  vision_master.cpp - FireVision Vision Master
00004  *
00005  *  Created: Wed May 30 10:52:08 2007
00006  *  Copyright  2006-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #include <fvutils/base/vision_master.h>
00025
00026 using namespace fawkes;
00027 
00028 /** @class VisionMaster <fvutils/base/vision_master.h>
00029  * Vision Master.
00030  * The vision master shall be the entry point for vision plugins. It shall
00031  * allow for requesting cameras that are opened in a central place such that
00032  * the very same camera can be used in multiple plugins.
00033  *
00034  * It shall also be responsible for the central timing of all vision threads.
00035  *
00036  * @author Tim Niemueller
00037  *
00038  * @fn Camera *  VisionMaster::register_for_camera(const char *camera_string, Thread *thread, colorspace_t cspace=YUV422_PLANAR) = 0
00039  * Register thread for camera.
00040  * This will register a relation between the given thread and the camera identified
00041  * by the camera string. If the requested camera has not been opened before this
00042  * is done and the camera is started. If that fails for whatever reason an exception
00043  * is thrown. In that case the thread is not registered with the vision master.
00044  * If the camera is available the thread is registered with the vision master. From
00045  * then on it is woken up whenever new image data is available and it will wait for
00046  * the thread to finished computation on that very image. It is a critical error
00047  * that can not be recovered if the thread fails for whatever reason. If there is
00048  * a critical error condition in the vision thread it must not stop execution
00049  * but just the computation.
00050  * @param camera_string camera that can be used by CameraFactory to open a
00051  * camera.
00052  * @param thread thread to register for this camera
00053  * @param cspace the colorspace in which the images should be provided for the
00054  * camera. Note that using images in different formats at the same time can cause
00055  * a severe performance penalty. The default is to produce YUV422_PLANAR images,
00056  * which is used in the FireVision framework as main image format.
00057  * @return a pointer to the requested camera. Note that this may not be
00058  * of the C++ type that you may expect for the requested camera, but it may
00059  * have layers of indirection. For example when opening a USB camera you could
00060  * get a shared memory camera to share the camera (image) with multiple threads.
00061  * Note that using CS_UNKNOWN shall have the similar result as using
00062  * register_for_raw_camer().
00063  *
00064  * @fn Camera *  VisionMaster::register_for_raw_camera(const char *camera_string, Thread *thread)
00065  * Register thread for camera.
00066  * This will register a relation between the given thread and the camera identified
00067  * by the camera string similar to register_for_camera(). However, unlike
00068  * register_for_camera() this method will provide access to the raw camera
00069  * implementation, without possibly proxies. Once you gathered the camera, you
00070  * can dynamically cast it to the expected camera type (or use the template method
00071  * instead. Raw access to a camera is only granted for a single thread.
00072  * Note that you may not call capture() or dispose() on the camera, this will
00073  * still be done by the vision master, as the camera may be used by other
00074  * threads that registered for the camera with register_for_camera().
00075  * @param camera_string camera that can be used by CameraFactory to open a
00076  * camera.
00077  * @param thread thread to register for this camera
00078  *
00079  * @fn void VisionMaster::unregister_thread(Thread *thread) = 0
00080  * Unregister a thread.
00081  * The thread is unregistered and it is removed from the internal structures. The
00082  * thread is no longer called for new image material that can be processed.
00083  *
00084  * If the unregistered thread was the last thread accessing the camera, it shall
00085  * be held open for a specified time, such that if the thread is just being
00086  * restarted the camera does not have to be re-opened. The time to wait is
00087  * defined by the implementation.
00088  * @param thread thread to unregister
00089  * 
00090  * @fn CameraControl * VisionMaster::acquire_camctrl(const char *cam_string)
00091  * Retrieve a CameraControl for the specified camera string.
00092  * This control (if available) can be used to control certain aspects of the Camera.
00093  * The \p cam_string argument either is the string that has been used to register
00094  * for a particular camera, or it is a string denoting a camera control by itself.
00095  * In the former case the vision master will look if the camera has been registered,
00096  * and then checks if the camera provides a camera control. If so the control is
00097  * returned. Note that it might implement multiple different camera controls. If
00098  * you want a specific camera control use one of the template methods to get a
00099  * correctly typed and verified control. If no camera that matches the \p cam_string
00100  * is found, the vision master will try to instantiate a new camera control using
00101  * the \p cam_string as argument to the CameraControlFactory.
00102  * @param cam_string Camera argument string, see method description for details
00103  * @return a pointer to the requested CameraControl.
00104  * @throws Exception no camera was found matching the \p cam_string and the factory
00105  * could not instantiate a camera control with the given string.
00106  *
00107  * @fn CameraControl * VisionMaster::acquire_camctrl(const char *cam_string, const std::type_info &typeinf)
00108  * Retrieve a CameraControl for the specified camera string and type info.
00109  * This utility method is used by the template methods to instantiate the cameras
00110  * with a specified intended type.
00111  * @param cam_string Camera argument string, see method description for details
00112  * @param typeinf type info for intended camera control type
00113  * @return a pointer to the requested CameraControl.
00114  * @throws Exception no camera was found matching the \p cam_string and the factory
00115  * could not instantiate a camera control with the given string.
00116  *
00117  * @fn void VisionMaster::release_camctrl(CameraControl *cc)
00118  * Release a camera control.
00119  * This has to be called when you are done with the camera control. This will
00120  * release the control and it is no longer valid. The vision master might collect
00121  * the memory that has been used for the control.
00122  * @param cc camera control instance to release
00123  */
00124 
00125 /** Virtual empty destructor. */
00126 VisionMaster::~VisionMaster()
00127 {
00128 }