Home | History | Annotate | Download | only in src
      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 #include "precomp.hpp"
     47 
     48 cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); }
     49 
     50 cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_)
     51 {
     52     if (impl_)
     53         CV_XADD(&impl_->ref_counter, 1);
     54 }
     55 
     56 cv::viz::Viz3d& cv::viz::Viz3d::operator=(const Viz3d& other)
     57 {
     58     if (this != &other)
     59     {
     60         release();
     61         impl_ = other.impl_;
     62         if (impl_)
     63             CV_XADD(&impl_->ref_counter, 1);
     64     }
     65     return *this;
     66 }
     67 
     68 cv::viz::Viz3d::~Viz3d() { release(); }
     69 
     70 void cv::viz::Viz3d::create(const String &window_name)
     71 {
     72     if (impl_)
     73         release();
     74 
     75     if (VizStorage::windowExists(window_name))
     76         *this = VizStorage::get(window_name);
     77     else
     78     {
     79         impl_ = new VizImpl(window_name);
     80         impl_->ref_counter = 1;
     81 
     82         // Register the window
     83         VizStorage::add(*this);
     84     }
     85 }
     86 
     87 void cv::viz::Viz3d::release()
     88 {
     89     if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1)
     90     {
     91         delete impl_;
     92         impl_ = 0;
     93     }
     94 
     95     if (impl_ && impl_->ref_counter == 1)
     96         VizStorage::removeUnreferenced();
     97 
     98     impl_ = 0;
     99 }
    100 
    101 void cv::viz::Viz3d::spin() { impl_->spin(); }
    102 void cv::viz::Viz3d::spinOnce(int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); }
    103 bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); }
    104 void cv::viz::Viz3d::close() { impl_->close(); }
    105 
    106 void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* cookie)
    107 { impl_->registerKeyboardCallback(callback, cookie); }
    108 
    109 void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie)
    110 { impl_->registerMouseCallback(callback, cookie); }
    111 
    112 void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3d &pose) { impl_->showWidget(id, widget, pose); }
    113 void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); }
    114 cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); }
    115 void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); }
    116 
    117 void cv::viz::Viz3d::showImage(InputArray image, const Size& window_size) { impl_->showImage(image, window_size); }
    118 
    119 void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3d &pose) { impl_->setWidgetPose(id, pose); }
    120 void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3d &pose) { impl_->updateWidgetPose(id, pose); }
    121 cv::Affine3d cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); }
    122 
    123 void cv::viz::Viz3d::setCamera(const Camera &camera) { impl_->setCamera(camera); }
    124 cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); }
    125 void cv::viz::Viz3d::setViewerPose(const Affine3d &pose) { impl_->setViewerPose(pose); }
    126 cv::Affine3d cv::viz::Viz3d::getViewerPose() { return impl_->getViewerPose(); }
    127 
    128 void cv::viz::Viz3d::resetCameraViewpoint(const String &id) { impl_->resetCameraViewpoint(id); }
    129 void cv::viz::Viz3d::resetCamera() { impl_->resetCamera(); }
    130 
    131 void cv::viz::Viz3d::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) { impl_->convertToWindowCoordinates(pt, window_coord); }
    132 void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) { impl_->converTo3DRay(window_coord, origin, direction); }
    133 
    134 cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); }
    135 void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size); }
    136 cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); }
    137 void cv::viz::Viz3d::saveScreenshot(const String &file) { impl_->saveScreenshot(file); }
    138 void cv::viz::Viz3d::setWindowPosition(const Point& window_position) { impl_->setWindowPosition(window_position); }
    139 void cv::viz::Viz3d::setFullScreen(bool mode) { impl_->setFullScreen(mode); }
    140 void cv::viz::Viz3d::setBackgroundColor(const Color& color, const Color& color2) { impl_->setBackgroundColor(color, color2); }
    141 
    142 void cv::viz::Viz3d::setBackgroundTexture(InputArray image) { impl_->setBackgroundTexture(image); }
    143 void cv::viz::Viz3d::setBackgroundMeshLab() {impl_->setBackgroundMeshLab(); }
    144 
    145 void cv::viz::Viz3d::setRenderingProperty(const String &id, int property, double value) { getWidget(id).setRenderingProperty(property, value); }
    146 double cv::viz::Viz3d::getRenderingProperty(const String &id, int property) { return getWidget(id).getRenderingProperty(property); }
    147 
    148 void cv::viz::Viz3d::setRepresentation(int representation) { impl_->setRepresentation(representation); }
    149 
    150 void cv::viz::Viz3d::setGlobalWarnings(bool enabled) { vtkObject::SetGlobalWarningDisplay(enabled ? 1 : 0); }
    151