Home | History | Annotate | Download | only in viz
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                           License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
     14 // Third party copyrights are property of their respective owners.
     15 //
     16 // Redistribution and use in source and binary forms, with or without modification,
     17 // are permitted provided that the following conditions are met:
     18 //
     19 //   * Redistribution's of source code must retain the above copyright notice,
     20 //     this list of conditions and the following disclaimer.
     21 //
     22 //   * Redistribution's in binary form must reproduce the above copyright notice,
     23 //     this list of conditions and the following disclaimer in the documentation
     24 //     and/or other materials provided with the distribution.
     25 //
     26 //   * The name of the copyright holders may not be used to endorse or promote products
     27 //     derived from this software without specific prior written permission.
     28 //
     29 // This software is provided by the copyright holders and contributors "as is" and
     30 // any express or implied warranties, including, but not limited to, the implied
     31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     32 // In no event shall the Intel Corporation or contributors be liable for any direct,
     33 // indirect, incidental, special, exemplary, or consequential damages
     34 // (including, but not limited to, procurement of substitute goods or services;
     35 // loss of use, data, or profits; or business interruption) however caused
     36 // and on any theory of liability, whether in contract, strict liability,
     37 // or tort (including negligence or otherwise) arising in any way out of
     38 // the use of this software, even if advised of the possibility of such damage.
     39 //
     40 // Authors:
     41 //  * Ozan Tonkal, ozantonkal (at) gmail.com
     42 //  * Anatoly Baksheev, Itseez Inc.  myname.mysurname <> mycompany.com
     43 //
     44 //M*/
     45 
     46 #ifndef __OPENCV_VIZ_TYPES_HPP__
     47 #define __OPENCV_VIZ_TYPES_HPP__
     48 
     49 #include <string>
     50 #include <opencv2/core.hpp>
     51 #include <opencv2/core/affine.hpp>
     52 
     53 namespace cv
     54 {
     55     namespace viz
     56     {
     57 
     58 //! @addtogroup viz
     59 //! @{
     60 
     61         /** @brief This class a represents BGR color.
     62         */
     63         class Color : public Scalar
     64         {
     65         public:
     66             Color();
     67             Color(double gray);
     68             Color(double blue, double green, double red);
     69 
     70             Color(const Scalar& color);
     71 
     72             operator Vec3b() const;
     73 
     74             static Color black();
     75             static Color blue();
     76             static Color green();
     77             static Color cyan();
     78 
     79             static Color red();
     80             static Color magenta();
     81             static Color yellow();
     82             static Color white();
     83 
     84             static Color gray();
     85 
     86             static Color mlab();
     87 
     88             static Color navy();
     89             static Color olive();
     90             static Color maroon();
     91             static Color teal();
     92             static Color rose();
     93             static Color azure();
     94             static Color lime();
     95             static Color gold();
     96             static Color brown();
     97             static Color orange();
     98             static Color chartreuse();
     99             static Color orange_red();
    100             static Color purple();
    101             static Color indigo();
    102 
    103             static Color pink();
    104             static Color cherry();
    105             static Color bluberry();
    106             static Color raspberry();
    107             static Color silver();
    108             static Color violet();
    109             static Color apricot();
    110             static Color turquoise();
    111             static Color celestial_blue();
    112             static Color amethyst();
    113 
    114             static Color not_set();
    115         };
    116 
    117         /** @brief This class wraps mesh attributes, and it can load a mesh from a ply file. :
    118         */
    119         class CV_EXPORTS Mesh
    120         {
    121         public:
    122             Mat cloud, colors, normals;
    123 
    124             //! Raw integer list of the form: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...)
    125             //! where n is the number of points in the poligon, and id is a zero-offset index into an associated cloud.
    126             Mat polygons;
    127 
    128             Mat texture, tcoords;
    129 
    130             /** @brief Loads a mesh from a ply file.
    131 
    132             @param file File name (for now only PLY is supported)
    133              */
    134             static Mesh load(const String& file);
    135         };
    136 
    137         /** @brief This class wraps intrinsic parameters of a camera.
    138 
    139         It provides several constructors that can extract the intrinsic parameters from field of
    140         view, intrinsic matrix and projection matrix. :
    141          */
    142         class CV_EXPORTS Camera
    143         {
    144         public:
    145 
    146             /** @brief Constructs a Camera.
    147 
    148             @param fx Horizontal focal length.
    149             @param fy Vertical focal length.
    150             @param cx x coordinate of the principal point.
    151             @param cy y coordinate of the principal point.
    152             @param window_size Size of the window. This together with focal length and principal
    153             point determines the field of view.
    154              */
    155             Camera(double fx, double fy, double cx, double cy, const Size &window_size);
    156             /** @overload
    157             @param fov Field of view (horizontal, vertical)
    158             @param window_size Size of the window. Principal point is at the center of the window
    159             by default.
    160             */
    161             explicit Camera(const Vec2d &fov, const Size &window_size);
    162             /** @overload
    163             @param K Intrinsic matrix of the camera.
    164             @param window_size Size of the window. This together with intrinsic matrix determines
    165             the field of view.
    166             */
    167             explicit Camera(const Matx33d &K, const Size &window_size);
    168             /** @overload
    169             @param proj Projection matrix of the camera.
    170             @param window_size Size of the window. This together with projection matrix determines
    171             the field of view.
    172             */
    173             explicit Camera(const Matx44d &proj, const Size &window_size);
    174 
    175             const Vec2d & getClip() const { return clip_; }
    176             void setClip(const Vec2d &clip) { clip_ = clip; }
    177 
    178             const Size & getWindowSize() const { return window_size_; }
    179             void setWindowSize(const Size &window_size);
    180 
    181             const Vec2d& getFov() const { return fov_; }
    182             void setFov(const Vec2d& fov) { fov_ = fov; }
    183 
    184             const Vec2d& getPrincipalPoint() const { return principal_point_; }
    185             const Vec2d& getFocalLength() const { return focal_; }
    186 
    187             /** @brief Computes projection matrix using intrinsic parameters of the camera.
    188 
    189             @param proj Output projection matrix.
    190              */
    191             void computeProjectionMatrix(Matx44d &proj) const;
    192 
    193             /** @brief Creates a Kinect Camera.
    194 
    195             @param window_size Size of the window. This together with intrinsic matrix of a Kinect Camera
    196             determines the field of view.
    197              */
    198             static Camera KinectCamera(const Size &window_size);
    199 
    200         private:
    201             void init(double fx, double fy, double cx, double cy, const Size &window_size);
    202 
    203             Vec2d clip_;
    204             Vec2d fov_;
    205             Size window_size_;
    206             Vec2d principal_point_;
    207             Vec2d focal_;
    208         };
    209 
    210         /** @brief This class represents a keyboard event.
    211         */
    212         class CV_EXPORTS KeyboardEvent
    213         {
    214         public:
    215             enum { NONE = 0, ALT = 1, CTRL = 2, SHIFT = 4 };
    216             enum Action { KEY_UP = 0, KEY_DOWN = 1 };
    217 
    218             /** @brief Constructs a KeyboardEvent.
    219 
    220             @param action Signals if key is pressed or released.
    221             @param symbol Name of the key.
    222             @param code Code of the key.
    223             @param modifiers Signals if alt, ctrl or shift are pressed or their combination.
    224              */
    225             KeyboardEvent(Action action, const String& symbol, unsigned char code, int modifiers);
    226 
    227             Action action;
    228             String symbol;
    229             unsigned char code;
    230             int modifiers;
    231         };
    232 
    233         /** @brief This class represents a mouse event.
    234         */
    235         class CV_EXPORTS MouseEvent
    236         {
    237         public:
    238             enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ;
    239             enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ;
    240 
    241             /** @brief Constructs a MouseEvent.
    242 
    243             @param type Type of the event. This can be **MouseMove**, **MouseButtonPress**,
    244             **MouseButtonRelease**, **MouseScrollDown**, **MouseScrollUp**, **MouseDblClick**.
    245             @param button Mouse button. This can be **NoButton**, **LeftButton**, **MiddleButton**,
    246             **RightButton**, **VScroll**.
    247             @param pointer Position of the event.
    248             @param modifiers Signals if alt, ctrl or shift are pressed or their combination.
    249              */
    250             MouseEvent(const Type& type, const MouseButton& button, const Point& pointer, int modifiers);
    251 
    252             Type type;
    253             MouseButton button;
    254             Point pointer;
    255             int modifiers;
    256         };
    257 
    258 //! @} viz
    259 
    260     } /* namespace viz */
    261 } /* namespace cv */
    262 
    263 //! @cond IGNORED
    264 
    265 //////////////////////////////////////////////////////////////////////////////////////////////////////
    266 /// cv::viz::Color
    267 
    268 inline cv::viz::Color::Color() : Scalar(0, 0, 0) {}
    269 inline cv::viz::Color::Color(double _gray) : Scalar(_gray, _gray, _gray) {}
    270 inline cv::viz::Color::Color(double _blue, double _green, double _red) : Scalar(_blue, _green, _red) {}
    271 inline cv::viz::Color::Color(const Scalar& color) : Scalar(color) {}
    272 
    273 inline cv::viz::Color::operator cv::Vec3b() const { return cv::Vec3d(val); }
    274 
    275 inline cv::viz::Color cv::viz::Color::black()   { return Color(  0,   0,   0); }
    276 inline cv::viz::Color cv::viz::Color::green()   { return Color(  0, 255,   0); }
    277 inline cv::viz::Color cv::viz::Color::blue()    { return Color(255,   0,   0); }
    278 inline cv::viz::Color cv::viz::Color::cyan()    { return Color(255, 255,   0); }
    279 inline cv::viz::Color cv::viz::Color::red()     { return Color(  0,   0, 255); }
    280 inline cv::viz::Color cv::viz::Color::yellow()  { return Color(  0, 255, 255); }
    281 inline cv::viz::Color cv::viz::Color::magenta() { return Color(255,   0, 255); }
    282 inline cv::viz::Color cv::viz::Color::white()   { return Color(255, 255, 255); }
    283 inline cv::viz::Color cv::viz::Color::gray()    { return Color(128, 128, 128); }
    284 
    285 inline cv::viz::Color cv::viz::Color::mlab()    { return Color(255, 128, 128); }
    286 
    287 inline cv::viz::Color cv::viz::Color::navy()       { return Color(0,     0, 128); }
    288 inline cv::viz::Color cv::viz::Color::olive()      { return Color(0,   128, 128); }
    289 inline cv::viz::Color cv::viz::Color::maroon()     { return Color(0,     0, 128); }
    290 inline cv::viz::Color cv::viz::Color::teal()       { return Color(128, 128,   0); }
    291 inline cv::viz::Color cv::viz::Color::rose()       { return Color(128,   0, 255); }
    292 inline cv::viz::Color cv::viz::Color::azure()      { return Color(255, 128,   0); }
    293 inline cv::viz::Color cv::viz::Color::lime()       { return Color(0,   255, 191); }
    294 inline cv::viz::Color cv::viz::Color::gold()       { return Color(0,   215, 255); }
    295 inline cv::viz::Color cv::viz::Color::brown()      { return Color(0,    75, 150); }
    296 inline cv::viz::Color cv::viz::Color::orange()     { return Color(0,   165, 255); }
    297 inline cv::viz::Color cv::viz::Color::chartreuse() { return Color(0,   255, 128); }
    298 inline cv::viz::Color cv::viz::Color::orange_red() { return Color(0,    69, 255); }
    299 inline cv::viz::Color cv::viz::Color::purple()     { return Color(128,   0, 128); }
    300 inline cv::viz::Color cv::viz::Color::indigo()     { return Color(130,   0,  75); }
    301 
    302 inline cv::viz::Color cv::viz::Color::pink()           { return Color(203, 192, 255); }
    303 inline cv::viz::Color cv::viz::Color::cherry()         { return Color( 99,  29, 222); }
    304 inline cv::viz::Color cv::viz::Color::bluberry()       { return Color(247, 134,  79); }
    305 inline cv::viz::Color cv::viz::Color::raspberry()      { return Color( 92,  11, 227); }
    306 inline cv::viz::Color cv::viz::Color::silver()         { return Color(192, 192, 192); }
    307 inline cv::viz::Color cv::viz::Color::violet()         { return Color(226,  43, 138); }
    308 inline cv::viz::Color cv::viz::Color::apricot()        { return Color(177, 206, 251); }
    309 inline cv::viz::Color cv::viz::Color::turquoise()      { return Color(208, 224,  64); }
    310 inline cv::viz::Color cv::viz::Color::celestial_blue() { return Color(208, 151,  73); }
    311 inline cv::viz::Color cv::viz::Color::amethyst()       { return Color(204, 102, 153); }
    312 
    313 inline cv::viz::Color cv::viz::Color::not_set()        { return Color(-1, -1, -1); }
    314 
    315 //! @endcond
    316 
    317 #endif
    318