fixed crash for windows if console widow is closed or CTRL_C/CTRL_BRAK keys in console are pressed.
This commit is contained in:
@@ -114,6 +114,8 @@ namespace cv
|
|||||||
double getRenderingProperty(const String &id, int property);
|
double getRenderingProperty(const String &id, int property);
|
||||||
|
|
||||||
void setRepresentation(int representation);
|
void setRepresentation(int representation);
|
||||||
|
|
||||||
|
void setGlobalWarnings(bool enabled = false);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct VizImpl;
|
struct VizImpl;
|
||||||
|
@@ -155,7 +155,16 @@ namespace cv
|
|||||||
namespace viz
|
namespace viz
|
||||||
{
|
{
|
||||||
typedef std::map<String, vtkSmartPointer<vtkProp> > WidgetActorMap;
|
typedef std::map<String, vtkSmartPointer<vtkProp> > WidgetActorMap;
|
||||||
typedef std::map<String, Viz3d> VizMap;
|
|
||||||
|
struct VizMap
|
||||||
|
{
|
||||||
|
typedef std::map<String, Viz3d> type;
|
||||||
|
typedef type::iterator iterator;
|
||||||
|
|
||||||
|
type m;
|
||||||
|
~VizMap();
|
||||||
|
void replace_clear();
|
||||||
|
};
|
||||||
|
|
||||||
class VizStorage
|
class VizStorage
|
||||||
{
|
{
|
||||||
@@ -167,7 +176,6 @@ namespace cv
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
VizStorage(); // Static
|
VizStorage(); // Static
|
||||||
~VizStorage();
|
|
||||||
|
|
||||||
static void add(const Viz3d& window);
|
static void add(const Viz3d& window);
|
||||||
static Viz3d& get(const String &window_name);
|
static Viz3d& get(const String &window_name);
|
||||||
@@ -177,6 +185,8 @@ namespace cv
|
|||||||
|
|
||||||
static VizMap storage;
|
static VizMap storage;
|
||||||
friend class Viz3d;
|
friend class Viz3d;
|
||||||
|
|
||||||
|
static VizStorage init;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/norm(v); }
|
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/norm(v); }
|
||||||
|
@@ -146,3 +146,5 @@ void cv::viz::Viz3d::setRenderingProperty(const String &id, int property, double
|
|||||||
double cv::viz::Viz3d::getRenderingProperty(const String &id, int property) { return getWidget(id).getRenderingProperty(property); }
|
double cv::viz::Viz3d::getRenderingProperty(const String &id, int property) { return getWidget(id).getRenderingProperty(property); }
|
||||||
|
|
||||||
void cv::viz::Viz3d::setRepresentation(int representation) { impl_->setRepresentation(representation); }
|
void cv::viz::Viz3d::setRepresentation(int representation) { impl_->setRepresentation(representation); }
|
||||||
|
|
||||||
|
void cv::viz::Viz3d::setGlobalWarnings(bool enabled) { vtkObject::SetGlobalWarningDisplay(enabled ? 1 : 0); }
|
||||||
|
@@ -67,36 +67,70 @@ cv::Affine3d cv::viz::makeCameraPose(const Vec3d& position, const Vec3d& focal_p
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// VizStorage implementation
|
/// VizStorage implementation
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static BOOL WINAPI ConsoleHandlerRoutine(DWORD /*dwCtrlType*/)
|
||||||
|
{
|
||||||
|
vtkObject::GlobalWarningDisplayOff();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_console_handler()
|
||||||
|
{
|
||||||
|
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO hOutInfo;
|
||||||
|
if (GetConsoleScreenBufferInfo(hOut, &hOutInfo))
|
||||||
|
SetConsoleCtrlHandler(ConsoleHandlerRoutine, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void register_console_handler() {}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
cv::viz::VizStorage cv::viz::VizStorage::init;
|
||||||
cv::viz::VizMap cv::viz::VizStorage::storage;
|
cv::viz::VizMap cv::viz::VizStorage::storage;
|
||||||
void cv::viz::VizStorage::unregisterAll() { storage.clear(); }
|
|
||||||
|
void cv::viz::VizMap::replace_clear() { type().swap(m); }
|
||||||
|
cv::viz::VizMap::~VizMap() { replace_clear(); }
|
||||||
|
|
||||||
|
cv::viz::VizStorage::VizStorage()
|
||||||
|
{
|
||||||
|
register_console_handler();
|
||||||
|
}
|
||||||
|
void cv::viz::VizStorage::unregisterAll() { storage.replace_clear(); }
|
||||||
|
|
||||||
cv::viz::Viz3d& cv::viz::VizStorage::get(const String &window_name)
|
cv::viz::Viz3d& cv::viz::VizStorage::get(const String &window_name)
|
||||||
{
|
{
|
||||||
String name = generateWindowName(window_name);
|
String name = generateWindowName(window_name);
|
||||||
VizMap::iterator vm_itr = storage.find(name);
|
VizMap::iterator vm_itr = storage.m.find(name);
|
||||||
CV_Assert(vm_itr != storage.end());
|
CV_Assert(vm_itr != storage.m.end());
|
||||||
return vm_itr->second;
|
return vm_itr->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::viz::VizStorage::add(const Viz3d& window)
|
void cv::viz::VizStorage::add(const Viz3d& window)
|
||||||
{
|
{
|
||||||
String window_name = window.getWindowName();
|
String window_name = window.getWindowName();
|
||||||
VizMap::iterator vm_itr = storage.find(window_name);
|
VizMap::iterator vm_itr = storage.m.find(window_name);
|
||||||
CV_Assert(vm_itr == storage.end());
|
CV_Assert(vm_itr == storage.m.end());
|
||||||
storage.insert(std::make_pair(window_name, window));
|
storage.m.insert(std::make_pair(window_name, window));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cv::viz::VizStorage::windowExists(const String &window_name)
|
bool cv::viz::VizStorage::windowExists(const String &window_name)
|
||||||
{
|
{
|
||||||
String name = generateWindowName(window_name);
|
String name = generateWindowName(window_name);
|
||||||
return storage.find(name) != storage.end();
|
return storage.m.find(name) != storage.m.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::viz::VizStorage::removeUnreferenced()
|
void cv::viz::VizStorage::removeUnreferenced()
|
||||||
{
|
{
|
||||||
for(VizMap::iterator pos = storage.begin(); pos != storage.end();)
|
for(VizMap::iterator pos = storage.m.begin(); pos != storage.m.end();)
|
||||||
if(pos->second.impl_->ref_counter == 1)
|
if(pos->second.impl_->ref_counter == 1)
|
||||||
storage.erase(pos++);
|
storage.m.erase(pos++);
|
||||||
else
|
else
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
@@ -72,6 +72,8 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false),
|
|||||||
setBackgroundMeshLab();
|
setBackgroundMeshLab();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cv::viz::Viz3d::VizImpl::~VizImpl() { close(); }
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void cv::viz::Viz3d::VizImpl::TimerCallback::Execute(vtkObject* caller, unsigned long event_id, void* cookie)
|
void cv::viz::Viz3d::VizImpl::TimerCallback::Execute(vtkObject* caller, unsigned long event_id, void* cookie)
|
||||||
{
|
{
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
int ref_counter;
|
int ref_counter;
|
||||||
|
|
||||||
VizImpl(const String &name);
|
VizImpl(const String &name);
|
||||||
virtual ~VizImpl() {}
|
virtual ~VizImpl();
|
||||||
|
|
||||||
bool wasStopped() const;
|
bool wasStopped() const;
|
||||||
void close();
|
void close();
|
||||||
|
Reference in New Issue
Block a user