mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 20:50:25 +08:00
fixed crash for windows if console widow is closed or CTRL_C/CTRL_BRAK keys in console are pressed.
This commit is contained in:
parent
1a5dfe421d
commit
56754e907d
@ -114,6 +114,8 @@ namespace cv
|
||||
double getRenderingProperty(const String &id, int property);
|
||||
|
||||
void setRepresentation(int representation);
|
||||
|
||||
void setGlobalWarnings(bool enabled = false);
|
||||
private:
|
||||
|
||||
struct VizImpl;
|
||||
|
@ -155,7 +155,16 @@ namespace cv
|
||||
namespace viz
|
||||
{
|
||||
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
|
||||
{
|
||||
@ -167,7 +176,6 @@ namespace cv
|
||||
|
||||
private:
|
||||
VizStorage(); // Static
|
||||
~VizStorage();
|
||||
|
||||
static void add(const Viz3d& window);
|
||||
static Viz3d& get(const String &window_name);
|
||||
@ -177,6 +185,8 @@ namespace cv
|
||||
|
||||
static VizMap storage;
|
||||
friend class Viz3d;
|
||||
|
||||
static VizStorage init;
|
||||
};
|
||||
|
||||
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); }
|
||||
|
||||
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
|
||||
|
||||
#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;
|
||||
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)
|
||||
{
|
||||
String name = generateWindowName(window_name);
|
||||
VizMap::iterator vm_itr = storage.find(name);
|
||||
CV_Assert(vm_itr != storage.end());
|
||||
VizMap::iterator vm_itr = storage.m.find(name);
|
||||
CV_Assert(vm_itr != storage.m.end());
|
||||
return vm_itr->second;
|
||||
}
|
||||
|
||||
void cv::viz::VizStorage::add(const Viz3d& window)
|
||||
{
|
||||
String window_name = window.getWindowName();
|
||||
VizMap::iterator vm_itr = storage.find(window_name);
|
||||
CV_Assert(vm_itr == storage.end());
|
||||
storage.insert(std::make_pair(window_name, window));
|
||||
VizMap::iterator vm_itr = storage.m.find(window_name);
|
||||
CV_Assert(vm_itr == storage.m.end());
|
||||
storage.m.insert(std::make_pair(window_name, window));
|
||||
}
|
||||
|
||||
bool cv::viz::VizStorage::windowExists(const String &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()
|
||||
{
|
||||
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)
|
||||
storage.erase(pos++);
|
||||
storage.m.erase(pos++);
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
|
@ -72,6 +72,8 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false),
|
||||
setBackgroundMeshLab();
|
||||
}
|
||||
|
||||
cv::viz::Viz3d::VizImpl::~VizImpl() { close(); }
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::TimerCallback::Execute(vtkObject* caller, unsigned long event_id, void* cookie)
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
int ref_counter;
|
||||
|
||||
VizImpl(const String &name);
|
||||
virtual ~VizImpl() {}
|
||||
virtual ~VizImpl();
|
||||
|
||||
bool wasStopped() const;
|
||||
void close();
|
||||
|
Loading…
Reference in New Issue
Block a user