Commits

iorodeo  committed 3209f1f

Fixed issue with checking video file dialog return results. Add LockableQueue
to lockable.hpp and removed lockable_queue.hpp. Modified LockableQueue so that
it inherits from Lockable.

  • Participants
  • Parent commits e071f00

Comments (0)

Files changed (10)

File src/gui/CMakeLists.txt

     image_grabber.hpp
     image_logger.hpp
     image_dispatcher.hpp
-    lockable_queue.hpp
     fps_estimator.hpp
     )
 

File src/gui/camera_window.cpp

 #include "mat_to_qimage.hpp"
 #include "stamped_image.hpp"
 #include "lockable.hpp"
-#include "lockable_queue.hpp"
 #include "image_grabber.hpp"
 #include "image_dispatcher.hpp"
 #include "image_logger.hpp"
     const double DEFAULT_IMAGE_DISPLAY_FREQ = 10.0;  
     const QSize PREVIEW_DUMMY_IMAGE_SIZE = QSize(320,256);
     const QSize DEFAULT_HISTOGRAM_IMAGE_SIZE = QSize(256,204);
-    const QString DEFAULT_SAVE_FILE_NAME = QString("bias_video");
+    const QString DEFAULT_VIDEO_FILE_NAME = QString("bias_video");
     QMap<VideoFileFormat, QString> createExtensionMap()
     {
         QMap<VideoFileFormat, QString> map;
 
     void CameraWindow::actionLoggingVideoFileTriggered()
     {
+        // Get current video filename
         if (!currentVideoFileDir_.exists()) 
         {
             currentVideoFileDir_ = defaultVideoFileDir_;
         QString extString = VIDEOFILE_EXTENSION_MAP[videoFileFormat_];
         QString saveFileWithExt = currentVideoFileName_ + "." + extString;
         QFileInfo videoFileInfo(currentVideoFileDir_, saveFileWithExt);
+
+        // Query user for desired video filename and directory
         QString videoFileString = QFileDialog::getSaveFileName(
                 this, 
                 QString("Select Video File"),
                 videoFileInfo.absoluteFilePath()
                 );
         videoFileInfo = QFileInfo(videoFileString);
-        currentVideoFileDir_ = videoFileInfo.dir();
-        currentVideoFileName_ = videoFileInfo.baseName();
+
+        QDir videoFileDir = videoFileInfo.dir();
+        QString videoFileName = videoFileInfo.baseName();
+
+        // Check return results and assign values
+        if (videoFileName.isEmpty())
+        {
+            if (currentVideoFileName_.isEmpty())
+            {
+                videoFileName = DEFAULT_VIDEO_FILE_NAME;
+            }
+            else
+            {
+                videoFileName = currentVideoFileName_;
+            }
+            videoFileDir = currentVideoFileDir_;
+        }
+        if (!videoFileDir.exists())
+        {
+            videoFileDir = defaultVideoFileDir_;
+        }
+
+        currentVideoFileDir_ = videoFileDir;
+        currentVideoFileName_ = videoFileName;
+
         std::cout << "dir:  " << currentVideoFileDir_.absolutePath().toStdString() << std::endl;
         std::cout << "file: " << currentVideoFileName_.toStdString() << std::endl;
     }
 
         setDefaultVideoFileDir();
         currentVideoFileDir_ = defaultVideoFileDir_;
-        currentVideoFileName_ = DEFAULT_SAVE_FILE_NAME;
+        currentVideoFileName_ = DEFAULT_VIDEO_FILE_NAME;
 
         setupCameraMenu();
         setupLoggingMenu();

File src/gui/image_dispatcher.cpp

 #include "image_dispatcher.hpp"
 #include "stamped_image.hpp"
-#include "lockable_queue.hpp"
 #include <iostream>
 
 namespace bias

File src/gui/image_dispatcher.hpp

 {
 
     struct StampedImage;
-    template <class T> class LockableQueue;
 
     class ImageDispatcher : public QObject, public QRunnable, public Lockable<Empty>
     {

File src/gui/image_grabber.cpp

 #include "camera.hpp"
 #include "exception.hpp"
 #include "stamped_image.hpp"
-#include "lockable_queue.hpp"
 #include <iostream>
 #include <QTime>
 #include <opencv2/core/core.hpp>

File src/gui/image_grabber.hpp

 {
 
     struct StampedImage;
-    template <class T> class LockableQueue;
 
     class ImageGrabber : public QObject, public QRunnable, public Lockable<Empty>
     {

File src/gui/image_logger.cpp

 #include "image_logger.hpp"
 #include "exception.hpp"
 #include "stamped_image.hpp"
-#include "lockable_queue.hpp"
 #include <queue>
 #include <iostream>
 #include <opencv2/core/core.hpp>

File src/gui/image_logger.hpp

 {
 
     struct StampedImage;
-    template <class T> class LockableQueue;
 
     class ImageLogger : public QObject, public QRunnable, public Lockable<Empty>
     {

File src/gui/lockable.hpp

 #define BIAS_LOCKABLE_HPP
 
 #include <QMutex>
+#include <queue>
 
 namespace bias
 {
             QMutex mutex_;
             
     };
+
+    template <class T>
+    class LockableQueue : public std::queue<T>, public Lockable<Empty>
+    {
+        // Mixin class for creating lockable queues 
+
+        public:
+
+            LockableQueue() : std::queue<T>() {};
+
+            void clear()
+            {
+                while (!(this -> empty())) 
+                { 
+                    this -> pop();
+                }
+            }
+    };
 }
 
 #endif // #ifndef BIAS_LOCKABLE_HPP

File src/gui/lockable_queue.hpp

-#ifndef BIAS_LOCKABLE_QUEUE_HPP
-#define BIAS_LOCKABLE_QUEUE_HPP
-
-#include <queue>
-#include <QMutex>
-
-namespace bias
-{
-
-    template <class T>
-    class LockableQueue : public std::queue<T>
-    {
-        // Mixin class for creating lockable queues 
-
-        public:
-
-            LockableQueue() : std::queue<T>() {};
-
-            void acquireLock()
-            {
-                mutex.lock();
-            }
-
-            void releaseLock()
-            {
-                mutex.unlock();
-            }
-
-            bool tryLock()
-            {
-                return mutex.tryLock();
-            }
-
-            void clear()
-            {
-                while (!(this -> empty())) 
-                { 
-                    this -> pop();
-                }
-            }
-
-        private:
-            QMutex mutex;
-    };
-
-}
-
-#endif // #ifndef BIAS_LOCKABLE_QUEUE_HPP