mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
initial shared pointer implementation for Viz3d, singleton VizAccessor, cv::viz::get function initial implementation
This commit is contained in:
@@ -85,3 +85,58 @@ namespace cv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Viz accessor implementation
|
||||
|
||||
cv::viz::VizAccessor * cv::viz::VizAccessor::instance_ = 0;
|
||||
bool cv::viz::VizAccessor::is_instantiated_ = false;
|
||||
cv::viz::VizMap cv::viz::VizAccessor::viz_map_;
|
||||
|
||||
cv::viz::VizAccessor::VizAccessor() {}
|
||||
|
||||
cv::viz::VizAccessor::~VizAccessor()
|
||||
{
|
||||
is_instantiated_ = false;
|
||||
}
|
||||
|
||||
cv::viz::VizAccessor * cv::viz::VizAccessor::getInstance()
|
||||
{
|
||||
if (is_instantiated_)
|
||||
{
|
||||
std::cout << "HERE" << std::endl;
|
||||
instance_ = new VizAccessor();
|
||||
is_instantiated_ = true;
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
cv::viz::Viz3d cv::viz::VizAccessor::get(const String & window_name)
|
||||
{
|
||||
VizMap::iterator vm_itr = viz_map_.find(window_name);
|
||||
bool exists = vm_itr != viz_map_.end();
|
||||
if (exists) return vm_itr->second;
|
||||
else return viz_map_.insert(VizPair(window_name, Viz3d(window_name))).first->second;
|
||||
}
|
||||
|
||||
void cv::viz::VizAccessor::add(Viz3d window)
|
||||
{
|
||||
String window_name = window.getWindowName();
|
||||
VizMap::iterator vm_itr = viz_map_.find(window_name);
|
||||
bool exists = vm_itr != viz_map_.end();
|
||||
if (exists) return ;
|
||||
viz_map_.insert(std::pair<String,Viz3d>(window_name, window));
|
||||
}
|
||||
|
||||
void cv::viz::VizAccessor::remove(const String &window_name)
|
||||
{
|
||||
VizMap::iterator vm_itr = viz_map_.find(window_name);
|
||||
bool exists = vm_itr != viz_map_.end();
|
||||
if (!exists) return ;
|
||||
viz_map_.erase(vm_itr);
|
||||
}
|
||||
|
||||
cv::viz::Viz3d cv::viz::get(const String &window_name)
|
||||
{
|
||||
return cv::viz::VizAccessor::getInstance()->get(window_name);
|
||||
}
|
||||
@@ -2,8 +2,44 @@
|
||||
#include "viz3d_impl.hpp"
|
||||
|
||||
|
||||
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(new VizImpl(window_name)) {}
|
||||
cv::viz::Viz3d::~Viz3d() { delete impl_; }
|
||||
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); }
|
||||
|
||||
cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_)
|
||||
{
|
||||
if (impl_) CV_XADD(&impl_->ref_counter, 1);
|
||||
}
|
||||
|
||||
cv::viz::Viz3d& cv::viz::Viz3d::operator=(const Viz3d& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
release();
|
||||
impl_ = other.impl_;
|
||||
if (impl_) CV_XADD(&impl_->ref_counter, 1);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
cv::viz::Viz3d::~Viz3d() { release(); }
|
||||
|
||||
void cv::viz::Viz3d::create(const String &window_name)
|
||||
{
|
||||
if (impl_) release();
|
||||
impl_ = new VizImpl(window_name);
|
||||
impl_->ref_counter = 1;
|
||||
// Register the window
|
||||
// cv::viz::VizAccessor::getInstance()->add(*this);
|
||||
}
|
||||
|
||||
void cv::viz::Viz3d::release()
|
||||
{
|
||||
if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1)
|
||||
{
|
||||
cv::viz::VizAccessor::getInstance()->remove(getWindowName());
|
||||
delete impl_;
|
||||
impl_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); }
|
||||
|
||||
@@ -55,4 +91,5 @@ void cv::viz::Viz3d::convertToWindowCoordinates(const Point3d &pt, Point3d &wind
|
||||
void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) { impl_->converTo3DRay(window_coord, origin, direction); }
|
||||
|
||||
cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); }
|
||||
void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); }
|
||||
void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); }
|
||||
cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); }
|
||||
@@ -86,7 +86,7 @@ cv::viz::Viz3d::VizImpl::~VizImpl ()
|
||||
if (interactor_ != NULL)
|
||||
interactor_->DestroyTimer (timer_id_);
|
||||
|
||||
renderer_->Clear();
|
||||
if (renderer_) renderer_->Clear();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -968,6 +968,11 @@ void cv::viz::Viz3d::VizImpl::setWindowName (const std::string &name)
|
||||
window_->SetWindowName (name.c_str ());
|
||||
}
|
||||
|
||||
cv::String cv::viz::Viz3d::VizImpl::getWindowName() const
|
||||
{
|
||||
return (window_ ? window_->GetWindowName() : "");
|
||||
}
|
||||
|
||||
void cv::viz::Viz3d::VizImpl::setWindowPosition (int x, int y) { window_->SetPosition (x, y); }
|
||||
void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize (xw, yw); }
|
||||
cv::Size cv::viz::Viz3d::VizImpl::getWindowSize() const { return Size(window_->GetSize()[0], window_->GetSize()[1]); }
|
||||
|
||||
@@ -11,6 +11,8 @@ public:
|
||||
typedef cv::Ptr<VizImpl> Ptr;
|
||||
typedef Viz3d::KeyboardCallback KeyboardCallback;
|
||||
typedef Viz3d::MouseCallback MouseCallback;
|
||||
|
||||
int ref_counter;
|
||||
|
||||
VizImpl (const String &name);
|
||||
virtual ~VizImpl ();
|
||||
@@ -142,6 +144,7 @@ public:
|
||||
void setWindowSize (int xw, int yw);
|
||||
void setFullScreen (bool mode);
|
||||
void setWindowName (const String &name);
|
||||
String getWindowName() const;
|
||||
void setBackgroundColor (const Color& color);
|
||||
|
||||
void spin ();
|
||||
|
||||
Reference in New Issue
Block a user