Skip to content

Commit

Permalink
Renamed class ImageView as ImagePanel
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemcpaulo committed Jun 12, 2015
1 parent af6856b commit d8dd1a7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 51 deletions.
26 changes: 13 additions & 13 deletions include/xv/ImageView.hpp → include/xv/ImagePanel.hpp
Expand Up @@ -19,7 +19,7 @@ namespace xv{
class Image;

/** @brief Class used to display images and as container of widgets. */
class ImageView : public wxPanel
class ImagePanel : public wxPanel
{
friend Widget;
public:
Expand All @@ -28,10 +28,10 @@ namespace xv{
static const cv::Scalar PADDING_COLOR;

/// Default constructor
ImageView();
ImagePanel();

/// Constructor inherited from wxPanel
ImageView(wxWindow * parent,
ImagePanel(wxWindow * parent,
wxWindowID id = wxID_ANY,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
Expand Down Expand Up @@ -105,19 +105,19 @@ namespace xv{
inline void createBitmap();
void setBestSizeFit();

friend void operator>>(cv::VideoCapture &videoCapture, ImageView &imageView){
imageView.m_mutex.Lock();
videoCapture >> imageView.m_cvMat;
imageView.m_mutex.Unlock();
imageView.render();
friend void operator>>(cv::VideoCapture &videoCapture, ImagePanel &imagePanel){
imagePanel.m_mutex.Lock();
videoCapture >> imagePanel.m_cvMat;
imagePanel.m_mutex.Unlock();
imagePanel.render();
}

/// use the xv::Image to display a cv::Mat
friend void operator<<(ImageView &imageView, cv::Mat& mat){
imageView.m_mutex.Lock();
imageView.m_cvMat = mat.clone();
imageView.m_mutex.Unlock();
imageView.render();
friend void operator<<(ImagePanel &imagePanel, cv::Mat& mat){
imagePanel.m_mutex.Lock();
imagePanel.m_cvMat = mat.clone();
imagePanel.m_mutex.Unlock();
imagePanel.render();
};

double m_scale = 1;
Expand Down
4 changes: 2 additions & 2 deletions include/xv/VideoCapture.hpp
Expand Up @@ -15,7 +15,7 @@

namespace xv{

class ImageView;
class ImagePanel;

/** @brief Analogue to cv::VideoCapture but providing a GUI with file picker and display of properties */
class VideoCapture : public wxPanel
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace xv{
void VideoCapture::operator>>(cv::Mat& mat){ m_videoCapture >> mat; };

/// Retrieves a image frame from the opened media into an xv::Image
friend void operator>>(VideoCapture&, ImageView&);
friend void operator>>(VideoCapture&, ImagePanel&);

#pragma endregion cv::VideoCapture

Expand Down
6 changes: 3 additions & 3 deletions include/xv/VideoPlayer.hpp
Expand Up @@ -9,7 +9,7 @@

namespace xv{

class ImageView;
class ImagePanel;

/** @brief Class to control the playback and processing of media obtained from VideoCapture
*/
Expand All @@ -35,7 +35,7 @@ class VideoPlayer : public wxPanel
int getCurrentFrameIdx();

/// Get the xv::Image instance used for rendering
ImageView& getImage();
ImagePanel& getImage();

#pragma region control

Expand Down Expand Up @@ -120,7 +120,7 @@ class VideoPlayer : public wxPanel


cv::VideoCapture* m_videoCapture = NULL;
ImageView* m_image;
ImagePanel* m_image;
wxButton* m_playButton;
wxSlider* m_slider;
wxStaticText
Expand Down
6 changes: 3 additions & 3 deletions include/xv/Widget.hpp
Expand Up @@ -19,15 +19,15 @@ namespace xv {
#endif

class Point;
class ImageView;
class ImagePanel;
int distance(gui_point_t, gui_point_t);


/** @brief Base class for all Widgets
*/

class Widget{
friend ImageView;
friend ImagePanel;
public:

/// Display widget in input mode (with OK/Cancel buttons)
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace xv {
virtual ~Widget() = 0;

/// Pointer to the parent image used to display the widget
ImageView *m_image = NULL;
ImagePanel *m_image = NULL;

/// The contours of area occupied by the widget
std::vector<gui_point_t> m_contour;
Expand Down
52 changes: 26 additions & 26 deletions src/ImageView.cpp → src/ImagePanel.cpp
Expand Up @@ -4,21 +4,21 @@
#include "opencv2/imgproc/imgproc.hpp"
#include <wx/settings.h>
#include "xv/Widget.hpp"
#include "xv/ImageView.hpp"
#include "xv/ImagePanel.hpp"
using namespace xv;

BEGIN_EVENT_TABLE(ImageView, wxPanel)
EVT_PAINT(ImageView::paintEvent)
EVT_SIZE(ImageView::sizeEvent)
EVT_ERASE_BACKGROUND(ImageView::onEraseBackground)
EVT_LEFT_DOWN(ImageView::onMouseDown)
EVT_LEFT_UP(ImageView::onMouseUp)
EVT_MOTION(ImageView::onMouseMove)
BEGIN_EVENT_TABLE(ImagePanel, wxPanel)
EVT_PAINT(ImagePanel::paintEvent)
EVT_SIZE(ImagePanel::sizeEvent)
EVT_ERASE_BACKGROUND(ImagePanel::onEraseBackground)
EVT_LEFT_DOWN(ImagePanel::onMouseDown)
EVT_LEFT_UP(ImagePanel::onMouseUp)
EVT_MOTION(ImagePanel::onMouseMove)
END_EVENT_TABLE()

const cv::Scalar ImageView::PADDING_COLOR(0, 0, 0);
const cv::Scalar ImagePanel::PADDING_COLOR(0, 0, 0);

void ImageView::onMouseDown(wxMouseEvent& evt)
void ImagePanel::onMouseDown(wxMouseEvent& evt)
{
wxPoint evtPoint(evt.GetPosition());
gui_point_t point = getPixelInterpolation(gui_point_t(evtPoint.x, evtPoint.y));
Expand All @@ -30,7 +30,7 @@ void ImageView::onMouseDown(wxMouseEvent& evt)
}
}

void ImageView::onMouseUp(wxMouseEvent& evt)
void ImagePanel::onMouseUp(wxMouseEvent& evt)
{
wxPoint evtPoint(evt.GetPosition());
gui_point_t point = getPixelInterpolation(gui_point_t(evtPoint.x, evtPoint.y));
Expand All @@ -47,7 +47,7 @@ void ImageView::onMouseUp(wxMouseEvent& evt)
}
}

void ImageView::purge()
void ImagePanel::purge()
{
for (std::list<xv::Widget*>::iterator i = m_widgets.begin(); i != m_widgets.end();){
if (!(*i)->m_image){
Expand All @@ -61,7 +61,7 @@ void ImageView::purge()
render();
}

void ImageView::onMouseMove(wxMouseEvent& evt)
void ImagePanel::onMouseMove(wxMouseEvent& evt)
{
wxPoint evtPoint(evt.GetPosition());
gui_point_t point = getPixelInterpolation(gui_point_t(evtPoint.x, evtPoint.y));
Expand All @@ -79,7 +79,7 @@ void ImageView::onMouseMove(wxMouseEvent& evt)
render(99);//render if not rendered in the last 99 ms
}

gui_point_t ImageView::getPixelInterpolation(gui_point_t point)
gui_point_t ImagePanel::getPixelInterpolation(gui_point_t point)
{
int x = point.x / m_scale - m_hBorder / m_scale;
int y = point.y / m_scale - m_vBorder / m_scale;
Expand All @@ -97,17 +97,17 @@ gui_point_t ImageView::getPixelInterpolation(gui_point_t point)
return gui_point_t(x, y);
}

void ImageView::onEraseBackground(wxEraseEvent&)
void ImagePanel::onEraseBackground(wxEraseEvent&)
{
//avoids flickering
}

ImageView::ImageView() : wxPanel()
ImagePanel::ImagePanel() : wxPanel()
{
}


ImageView::ImageView(wxWindow *parent,
ImagePanel::ImagePanel(wxWindow *parent,
wxWindowID id,
const wxPoint &pos,
const wxSize &size,
Expand All @@ -118,20 +118,20 @@ ImageView::ImageView(wxWindow *parent,
SetBackgroundColour(*wxBLACK);
}

void ImageView::operator<<(const cv::Mat& cvMat)
void ImagePanel::operator<<(const cv::Mat& cvMat)
{

}

void ImageView::paintEvent(wxPaintEvent & evt)
void ImagePanel::paintEvent(wxPaintEvent & evt)
{
m_mutex.Lock();
wxBufferedPaintDC dc(this, m_bitmap);
m_mutex.Unlock();
m_lastPaintTime = std::chrono::steady_clock::now();
}

void ImageView::createBitmap()
void ImagePanel::createBitmap()
{
m_mutex.Lock();
//create a blank bitmap
Expand All @@ -155,12 +155,12 @@ void ImageView::createBitmap()
m_mutex.Unlock();
}

void ImageView::sizeEvent(wxSizeEvent& evt){
void ImagePanel::sizeEvent(wxSizeEvent& evt){
createBitmap();
Refresh();
}

void ImageView::setBestSizeFit()
void ImagePanel::setBestSizeFit()
{
int cols, newCols, rows, newRows;
m_hBorder = 0; m_vBorder = 0; m_scale = 1;
Expand Down Expand Up @@ -191,13 +191,13 @@ void ImageView::setBestSizeFit()
cv::copyMakeBorder(m_renderMat, m_renderMat, m_vBorder, m_vBorder, m_hBorder, m_hBorder, cv::BORDER_ISOLATED, PADDING_COLOR);
}

void ImageView::Refresh(bool eraseBackground, const wxRect *rect)
void ImagePanel::Refresh(bool eraseBackground, const wxRect *rect)
{
wxPanel::Refresh(eraseBackground);

}

void ImageView::render(int ms)
void ImagePanel::render(int ms)
{
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastPaintTime).count() < ms)
Expand All @@ -208,7 +208,7 @@ void ImageView::render(int ms)


/// Simple rendering/display of widget without user input
void ImageView::operator << (Widget &widget){
void ImagePanel::operator << (Widget &widget){
if (std::find(this->m_widgets.begin(), this->m_widgets.end(), &widget) == this->m_widgets.end()){
if (!widget.m_positioned)//center widget with undefined value in the image
widget.center();
Expand All @@ -223,7 +223,7 @@ void ImageView::operator << (Widget &widget){
};

///widgets for user input
void ImageView::operator >> (Widget &widget){
void ImagePanel::operator >> (Widget &widget){
if (std::find(this->m_widgets.begin(), this->m_widgets.end(), &widget) == this->m_widgets.end()){
if (!widget.m_positioned)//center widget with undefined value in the image
widget.setPosition(gui_point_t(m_cvMat.rows / 2, m_cvMat.cols/2));
Expand Down
6 changes: 3 additions & 3 deletions src/VideoPlayer.cpp
Expand Up @@ -9,7 +9,7 @@
#include <windows.h>

#include "xv/VideoPlayer.hpp"
#include "xv/ImageView.hpp"
#include "xv/ImagePanel.hpp"

using namespace xv;
using namespace std;
Expand Down Expand Up @@ -61,7 +61,7 @@ void VideoPlayer::init()
m_videoCapture = new cv::VideoCapture();
m_thread = new Thread(this);

m_image = new ImageView(this);
m_image = new ImagePanel(this);
m_playButton = new wxButton(this, wxID_ANY, _("Play"));
m_playButton->Bind(wxEVT_BUTTON, &VideoPlayer::onPlayClick, this);

Expand Down Expand Up @@ -308,7 +308,7 @@ int VideoPlayer::getCurrentFrameIdx()
return m_videoCapture->get(cv::CAP_PROP_POS_FRAMES);
}

ImageView& VideoPlayer::getImage()
ImagePanel& VideoPlayer::getImage()
{
return *m_image;
}
2 changes: 1 addition & 1 deletion src/Widget.cpp
@@ -1,5 +1,5 @@
#pragma once //header only mode
#include "xv/ImageView.hpp"
#include "xv/ImagePanel.hpp"
#include "xv/Widget.hpp"
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
Expand Down

0 comments on commit d8dd1a7

Please sign in to comment.