1 // -*- c-basic-offset: 4 -*-
2 /** @file GLPreviewFrame.h
3  *
4  *  @author James Legg and Pablo d'Angelo <pablo.dangelo@web.de>
5  *  @author Darko Makreshanski
6  *
7  *  This is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU General Public
9  *  License as published by the Free Software Foundation; either
10  *  version 2 of the License, or (at your option) any later version.
11  *
12  *  This software is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public
18  *  License along with this software. If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef _GLPREVIEWFRAME_H
24 #define _GLPREVIEWFRAME_H
25 
26 class GLRenderer;
27 class wxToolBar;
28 class wxToggleButton;
29 class wxCheckBox;
30 class wxTextCtrl;
31 class wxBitmapButton;
32 class wxSpinButton;
33 class wxScrolledWindow;
34 class wxBoxSizer;
35 class wxStaticBoxSizer;
36 class wxStaticText;
37 class wxSlider;
38 class GLViewer;
39 class GLPreview;
40 class GLOverview;
41 class ViewState;
42 class wxSpinEvent;
43 class wxChoice;
44 //forward declaration for wxInfoBar works only for wxGTK
45 //for other systems wxInfoBar is defined as preprocessor macro and not as class
46 //class wxInfoBar;
47 #include <wx/infobar.h>
48 
49 class MeshManager;
50 
51 class ToolHelper;
52 class PreviewToolHelper;
53 class PanosphereOverviewToolHelper;
54 class PlaneOverviewToolHelper;
55 class Tool;
56 class PreviewTool;
57 class PreviewCropTool;
58 class DragTool;
59 class OverviewDragTool;
60 class PanosphereOverviewCameraTool;
61 class PlaneOverviewCameraTool;
62 class PreviewDragTool;
63 class PreviewIdentifyTool;
64 class PreviewDifferenceTool;
65 class PreviewPanoMaskTool;
66 class PreviewControlPointTool;
67 class PreviewLayoutLinesTool;
68 class PreviewColorPickerTool;
69 class PreviewEditCPTool;
70 class PreviewCameraTool;
71 
72 class PanosphereOverviewProjectionGridTool;
73 class PreviewProjectionGridTool;
74 class PanosphereSphereTool;
75 
76 class PanosphereOverviewOutlinesTool;
77 class PlaneOverviewOutlinesTool;
78 
79 class PreviewGuideTool;
80 
81 class GLPreviewFrame;
82 
83 class GLwxAuiManager;
84 class GLwxAuiFloatingFrame;
85 
86 #include <wx/string.h>
87 #include <wx/frame.h>
88 #include <wx/aui/aui.h>
89 #include <wx/clrpicker.h>
90 #include "hugin/GuiLevel.h"
91 
92 #include <iostream>
93 
94 // the image toggle buttons need a special event handler to trap mouse enter and
95 // leave events.
96 class ImageToogleButtonEventHandler : public wxEvtHandler
97 {
98 public:
99     ImageToogleButtonEventHandler(unsigned int image_number,
100                                   wxToggleButton* identify_button_in,
101                                   HuginBase::Panorama * m_pano);
102     void OnChange(wxCommandEvent &e);
103     void AddIdentifyTool(PreviewIdentifyTool** identify_tool_in);
104 protected:
105     void OnEnter(wxMouseEvent & e);
106     void OnLeave(wxMouseEvent & e);
107 private:
108     DECLARE_EVENT_TABLE()
109     unsigned int image_number;
110     std::vector<PreviewIdentifyTool**> identify_tools;
111     wxToggleButton* m_identify_button;
112     HuginBase::Panorama * m_pano;
113 };
114 
115 class ImageGroupButtonEventHandler : public wxEvtHandler
116 {
117 public:
118     ImageGroupButtonEventHandler(unsigned int image_number, GLPreviewFrame* frame_in, HuginBase::Panorama* m_pano);
119     void OnChange(wxCommandEvent &e);
120     void AddDragTool(DragTool** drag_tool_in);
121     void AddIdentifyTool(PreviewIdentifyTool** identify_tool_in);
122 protected:
123     void OnEnter(wxMouseEvent & e);
124     void OnLeave(wxMouseEvent & e);
125 private:
126     DECLARE_EVENT_TABLE()
127     unsigned int image_number;
128     std::vector<DragTool**> drag_tools;
129     std::vector<PreviewIdentifyTool**> identify_tools;
130     GLPreviewFrame* frame;
131     HuginBase::Panorama * m_pano;
132 };
133 
134 
135 /**
136  * subclass for a floating frame of the dock manager
137  */
138 class GLwxAuiFloatingFrame : public wxAuiFloatingFrame {
139 public:
140     GLwxAuiFloatingFrame(wxWindow* parent,
141                    GLwxAuiManager* owner_mgr,
142                    const wxAuiPaneInfo& pane,
143                    wxWindowID id = wxID_ANY,
144                    long style = wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
145 //                                wxFRAME_NO_TASKBAR |
146                                 wxFRAME_FLOAT_ON_PARENT |
147                                 wxCLIP_CHILDREN
148                    ) : wxAuiFloatingFrame(parent, (wxAuiManager*) owner_mgr, pane, id, style) {}
149 
150 
151     void OnActivate(wxActivateEvent& evt);
152     void OnMoveFinished();
153 //    void OnClose(wxCloseEvent& event);
154 
155     DECLARE_EVENT_TABLE()
156 
157 };
158 
159 /**
160  * customized subclass of the dock manager, created just for the purpose to create a workaround for the bug that exists while using wxAUI and OpenGL
161  * the bug is similar to the one described here http://www.kirix.com/forums/viewtopic.php?f=15&t=175
162  */
163 class GLwxAuiManager : public wxAuiManager {
164 public:
GLwxAuiManager(GLPreviewFrame * frame,GLPreview * preview,GLOverview * overview)165     GLwxAuiManager(GLPreviewFrame* frame, GLPreview * preview, GLOverview * overview) : frame(frame), preview(preview), overview(overview) {}
166     GLwxAuiFloatingFrame* CreateFloatingFrame(wxWindow* parent, const wxAuiPaneInfo& p);
getPreviewFrame()167     GLPreviewFrame * getPreviewFrame() {return frame;}
getGLPreview()168     GLPreview * getGLPreview() {return preview;}
getGLOverview()169     GLOverview * getGLOverview() {return overview;}
170 
171 private:
172     GLPreviewFrame * frame;
173     GLPreview * preview;
174     GLOverview * overview;
175 };
176 
177 
178 
179 /** The OpenGL preview frame
180  *
181  *  Contains the GLViewer and various controls for it.
182  *
183  *  it is not created with XRC, because it is highly dynamic, buttons
184  *  have to be added etc.
185  */
186 class GLPreviewFrame : public wxFrame, public HuginBase::PanoramaObserver
187 {
188 public:
189 
190     /** ctor.
191      */
192     GLPreviewFrame(wxFrame * frame, HuginBase::Panorama &pano);
193 
194     /** dtor.
195      */
196     virtual ~GLPreviewFrame();
197     /** store position and size of window in wxConfig */
198     void StorePositionAndSize();
199 
200     virtual void panoramaChanged(HuginBase::Panorama &pano);
201     virtual void panoramaImagesChanged(HuginBase::Panorama &pano, const HuginBase::UIntSet &changed);
202 
203     void MakePreviewTools(PreviewToolHelper * helper);
204     void MakePanosphereOverviewTools(PanosphereOverviewToolHelper * helper);
205     void MakePlaneOverviewTools(PlaneOverviewToolHelper* helper);
206 
207     void SetImageButtonColour(unsigned int image_nr, unsigned char red,
208                               unsigned char green, unsigned char blue);
209     void SetStatusMessage(wxString message);
210     /** fills the blend wxChoice with all valid blend modes and restore the last used one
211      */
212     void FillBlendChoice();
213     /** loads the layout of the OpenGL windows and restores it */
214     void LoadOpenGLLayout();
215     /** init previews */
216     void InitPreviews();
217     /** sets the gui level */
218     void SetGuiLevel(GuiLevel newLevel);
219 
getAuiManager()220     GLwxAuiManager* getAuiManager() {return m_mgr;}
getPreview()221     GLPreview* getPreview() {return m_GLPreview;}
getOverview()222     GLOverview* getOverview() {return m_GLOverview;}
223 
224     void PauseResize();
225     void ContinueResize();
CanResize()226     bool CanResize() {return GLresize;}
227 
228     /** Display an updated version of the preview images.
229      *  Redraws happen automatically when the panorama changes, and when the
230      *  preview's internal real time sliders are used. This is only needed
231      *  occasionally, such as when a image finishes loading and its place holder
232      *  can be replaced with the real image.
233      */
234     void redrawPreview();
235     /** reset zoom level for preview window */
236     void ResetPreviewZoom();
237     /** set status if projection hints should be shown or not*/
238     void SetShowProjectionHints(bool new_value);
239     void OnShowEvent(wxShowEvent& e);
240 
241     bool individualDragging();
242     void ToggleImageInDragGroup(unsigned int image_nr, bool update_check_box = true);
243     void RemoveImageFromDragGroup(unsigned int image_nr, bool update_check_box = true);
244     void AddImageToDragGroup(unsigned int image_nr, bool update_check_box = true);
245     void SetDragGroupImages(HuginBase::UIntSet imageDragGroup_in, bool update_check_box = true);
246     HuginBase::UIntSet GetDragGroupImages();
247     void ClearDragGroupImages(bool update_check_box = true);
248     /** updates the global white balance
249      * @param redFactor multiplies all WhiteBalanceRed of individuel images with this factor
250      * @param blueFactor multiplies all WhiteBalanceBlue of individuel images with this factor
251      */
252     void UpdateGlobalWhiteBalance(double redFactor, double blueFactor);
253     void UpdateIdentifyTools(std::set<unsigned int> new_image_set);
254 
255     wxColour GetPreviewBackgroundColor();
256 
257 protected:
258 
259     bool GLresize = true;
260 
261     void OnClose(wxCloseEvent& e);
262 
263     void OnOverviewToggle(wxCommandEvent& e);
264 
265     void OnCenterHorizontally(wxCommandEvent & e);
266     void OnFitPano(wxCommandEvent& e);
267     void OnStraighten(wxCommandEvent & e);
268     void OnShowAll(wxCommandEvent & e);
269     void OnShowNone(wxCommandEvent & e);
270     void OnPhotometric(wxCommandEvent & e);
271     void OnIdentify(wxCommandEvent &e);
272     void OnAutocrop(wxCommandEvent &e);
273     void OnStackAutocrop(wxCommandEvent &e);
274     void OnControlPoint(wxCommandEvent &e);
275     void OnNumTransform(wxCommandEvent & e);
276     void OnChangeFOV(wxScrollEvent & e);
277     void OnTrackChangeFOV(wxScrollEvent & e);
278     void OnExposureChanged(wxCommandEvent & e);
279     void OnProjParameterChanged(wxCommandEvent & e);
280     /** event handler for reset projection parameters */
281     void OnProjParameterReset(wxCommandEvent & e);
282     /** event handler for switch on/off grid on preview */
283     void OnSwitchPreviewGrid(wxCommandEvent & e);
284     /** user wants to quit program */
285     void OnUserExit(wxCommandEvent & e);
286 
287     void OnDefaultExposure( wxCommandEvent & e );
288     void OnDecreaseExposure( wxSpinEvent & e );
289     void OnIncreaseExposure( wxSpinEvent & e );
290     void OnRangeCompressionIncrease(wxSpinEvent & e);
291     void OnRangeCompressionDecrease(wxSpinEvent & e);
292     void OnRangeCompressionChanged(wxCommandEvent& e);
293 
294     void OnBlendChoice(wxCommandEvent & e);
295     void OnDragChoice(wxCommandEvent & e);
296 
297     void KeyDown(wxKeyEvent & e);
298     void KeyUp(wxKeyEvent & e);
299 
300     void DragChoiceLayout( int index );
301     void OnProjectionChoice(wxCommandEvent & e);
302     void OnOverviewModeChoice(wxCommandEvent & e);
303     /** event handler for changed roi */
304     void OnROIChanged(wxCommandEvent & e);
305     /** event handler to reset crop area */
306     void OnResetCrop(wxCommandEvent & e);
307     void OnHFOVChanged(wxCommandEvent & e);
308     void OnVFOVChanged(wxCommandEvent & e);
309     /** event handler when user hides the infobar */
310     void OnHideProjectionHints(wxCommandEvent &e);
311     // No HDR display yet
312     // void OnOutputChoice(wxCommandEvent & e);
313     // update tools according to blend mode choice
314     void updateBlendMode();
315     /** event handler for full screen */
316     void OnFullScreen(wxCommandEvent &e);
317     /** event handler for selection of new mode */
318     void OnSelectMode(wxNotebookEvent &e);
319     /** event handler for blocking changing mode when panorama contains no images*/
320     void OnToolModeChanging(wxNotebookEvent &e);
321     /** event handler for change scale of layout mode */
322     void OnLayoutScaleChange(wxScrollEvent &e);
323     /** event handler when starting color picker */
324     void OnColorPicker(wxCommandEvent &e);
325     /** event handler when starting edit cp tool */
326     void OnEditCPTool(wxCommandEvent &e);
327     /** event handler when user changes background color */
328     void OnPreviewBackgroundColorChanged(wxColourPickerEvent & e);
329     /** event handler when user selects different guide */
330     void OnGuideChanged(wxCommandEvent &e);
331     /** event handler to show main frame */
332     void OnShowMainFrame(wxCommandEvent &e);
333     // assistant related event handler
334     void OnLoadImages( wxCommandEvent & e );
335     void OnAlign( wxCommandEvent & e );
336     void OnCreate( wxCommandEvent & e );
337     void OnLensTypeChanged (wxCommandEvent & e);
338     void OnFocalLengthChanged(wxCommandEvent & e);
339     void OnCropFactorChanged(wxCommandEvent & e);
340 
341     /** handler for creating cp in pano space */
342     void OnCreateCP(wxCommandEvent & e);
343     /** handler to remove cp */
344     void OnRemoveCP(wxCommandEvent & e);
345     /** handle menu close event */
346     void OnMenuClose(wxMenuEvent & e);
347     /** handle context menu on select all button */
348     void OnSelectContextMenu(wxContextMenuEvent& e);
349     /** handle all options of select all context menu */
350     void OnSelectAllMenu(wxCommandEvent& e);
351     void OnSelectMedianMenu(wxCommandEvent& e);
352     void OnSelectDarkestMenu(wxCommandEvent& e);
353     void OnSelectBrightestMenu(wxCommandEvent& e);
354     void OnSelectKeepSelection(wxCommandEvent& e);
355     void OnSelectResetSelection(wxCommandEvent& e);
356 private:
357     /** changes the visibility of the group check boxes
358      * @param isShown true if the group checkboxes should be visible
359      */
360     void EnableGroupCheckboxes(bool isShown);
361     /** updates the mode of the overview window
362      *  @param newMode overview mode which should be setted
363      *  @return true, of mode was successful changed to desired mode
364      */
365     bool UpdateOverviewMode(int newMode);
366     /** update display of ROI */
367     void UpdateRoiDisplay(const HuginBase::PanoramaOptions opts);
368     /** The dock manager */
369     GLwxAuiManager * m_mgr;
370 
371     void SetMode(int newMode);
372     HuginBase::Panorama & m_pano;
373 
374     GLPreview * m_GLPreview;
375     GLOverview * m_GLOverview;
376 
377     GuiLevel m_guiLevel;
378 
379     ViewState* m_view_state;
380 
381     int m_mode;
382     int non_layout_blend_mode;
383     wxToggleButton* m_identify_togglebutton;
384     wxToggleButton* m_colorpicker_togglebutton;
385     wxToggleButton* m_editCP_togglebutton;
386     wxNotebook* m_tool_notebook;
387     wxPanel* m_projection_panel;
388     wxSlider * m_HFOVSlider;
389     wxSlider * m_VFOVSlider;
390     wxTextCtrl * m_HFOVText;
391     wxTextCtrl * m_VFOVText;
392     wxTextCtrl * m_ROILeftTxt;
393     wxTextCtrl * m_ROIRightTxt;
394     wxTextCtrl * m_ROITopTxt;
395     wxTextCtrl * m_ROIBottomTxt;
396     wxChoice * m_BlendModeChoice;
397     wxChoice * m_DragModeChoice;
398     wxChoice * m_ProjectionChoice;
399     wxChoice * m_OverviewModeChoice;
400     wxChoice * m_GuideChoiceCrop;
401     wxChoice * m_GuideChoiceDrag;
402     wxChoice * m_GuideChoiceProj;
403     // No HDR display yet.
404     // wxChoice * m_outputModeChoice;
405     wxTextCtrl * m_exposureTextCtrl;
406     wxBitmapButton * m_defaultExposureBut;
407     wxSpinButton * m_exposureSpinBut;
408     wxTextCtrl* m_rangeCompressionTextCtrl;
409     wxSpinButton* m_rangeCompressionSpinBut;
410     /// Bar for context sensitive projection information.
411     wxInfoBar * m_infoBar;
412     //assistant related controls
413     wxStaticText * m_imagesText;
414     wxButton * m_alignButton;
415     wxButton * m_createButton;
416     wxChoice   * m_lensTypeChoice;
417     wxTextCtrl * m_focalLengthText;
418     wxTextCtrl * m_cropFactorText;
419     wxButton   * m_loadLensButton;
420     wxMenu* m_filemenuSimple;
421     wxMenu* m_filemenuAdvanced;
422     wxMenu* m_selectAllMenu;
423     wxButton* m_selectAllButton;
424     enum SelectAllMode
425     {
426         SELECT_ALL_IMAGES = 0,
427         SELECT_MEDIAN_IMAGES = 1,
428         SELECT_BRIGHTEST_IMAGES = 2,
429         SELECT_DARKEST_IMAGES = 3,
430     };
431     SelectAllMode m_selectAllMode;
432     bool m_selectKeepSelection;
433 
434     int m_degDigits;
435 
436     wxColour m_preview_background_color;
437 
438     wxString m_choices[3];
439     int m_oldProjFormat;
440     // index of difference mode
441     int m_differenceIndex;
442 
443     wxScrolledWindow * m_ButtonPanel;
444     wxBoxSizer * m_ButtonSizer;
445     wxStaticBoxSizer * m_ToggleButtonSizer;
446 
447     wxBoxSizer * m_topsizer;
448     wxBoxSizer * m_projParamSizer;
449     wxPanel* m_overviewCommandPanel;
450     std::vector<wxStaticText *> m_projParamNamesLabel;
451     std::vector<wxTextCtrl *>   m_projParamTextCtrl;
452     std::vector<wxSlider *>     m_projParamSlider;
453 
454     std::vector<wxToggleButton *> m_ToggleButtons;
455     std::vector<wxCheckBox *> m_GroupToggleButtons;
456     std::vector<wxPanel *> m_ToggleButtonPanel;
457     std::vector<ImageToogleButtonEventHandler *> toogle_button_event_handlers;
458     std::vector<ImageGroupButtonEventHandler *> toggle_group_button_event_handlers;
459 
460     DECLARE_EVENT_TABLE()
461 
462     // tools
463     PreviewToolHelper *preview_helper;
464 
465     PreviewCropTool *crop_tool;
466     HuginBase::UIntSet imageDragGroup;
467     PreviewDragTool *drag_tool;
468     PreviewCameraTool *camera_tool;
469     PreviewColorPickerTool *color_picker_tool;
470     PreviewEditCPTool* edit_cp_tool;
471 
472     PreviewIdentifyTool *identify_tool;
473     PreviewIdentifyTool *panosphere_overview_identify_tool;
474     PreviewIdentifyTool *plane_overview_identify_tool;
475 
476     PreviewDifferenceTool *difference_tool;
477     PreviewDifferenceTool *plane_difference_tool;
478     PreviewDifferenceTool *panosphere_difference_tool;
479 
480     PreviewControlPointTool *preview_control_point_tool;
481     PreviewControlPointTool *panosphere_control_point_tool;
482     PreviewControlPointTool *plane_control_point_tool;
483 
484     PreviewPanoMaskTool *pano_mask_tool;
485 
486     bool m_showProjectionHints;
487     PreviewLayoutLinesTool *m_preview_layoutLinesTool;
488     PreviewLayoutLinesTool *m_panosphere_layoutLinesTool;
489     PreviewLayoutLinesTool *m_plane_layoutLinesTool;
490 
491     PanosphereOverviewProjectionGridTool * overview_projection_grid;
492     PreviewProjectionGridTool * preview_projection_grid;
493     PanosphereSphereTool * panosphere_sphere_tool;
494 
495     PanosphereOverviewToolHelper *panosphere_overview_helper;
496 
497     PlaneOverviewToolHelper *plane_overview_helper;
498 
499     OverviewDragTool *overview_drag_tool;
500 
501     PanosphereOverviewCameraTool *panosphere_overview_camera_tool;
502     PlaneOverviewCameraTool *plane_overview_camera_tool;
503 
504     PanosphereOverviewOutlinesTool *overview_outlines_tool;
505     PlaneOverviewOutlinesTool *plane_overview_outlines_tool;
506 
507     PreviewGuideTool *preview_guide_tool;
508 
509     void TurnOffTools(std::set<Tool*> tools);
510 
511 #ifdef __WXGTK__
512     bool loadedLayout;
513 #endif
514 
515     /** check, if panorama has non-zero translation plane parameters
516      *  @returns true, if panorama has non-zero translation parameters
517      */
518     bool HasNonZeroTranslationPlaneParameters();
519     /** resets all translation plane parameters to zero */
520     void ResetTranslationPlaneParameters();
521     void CleanButtonColours();
522     /** Tell the user anything suspicious about the projection choice.
523      * If nothing is suspicious, any previous message is removed.
524      * In wxWidgets 2.9, this appears as an wxInfoBar. Older versions do not
525      * have this. so the status bar is used instead.
526      */
527     void ShowProjectionWarnings();
528 };
529 
530 
531 #endif // _GLPREVIEWFRAME_H
532