1 // -*- c-basic-offset: 4 -*-
2 /** @file PreviewPanoMaskTool.cpp
3  *
4  *  @author James Legg
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This software is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public
17  *  License along with this software. If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifdef _WIN32
23 #include "wx/msw/wrapwin.h"
24 #endif
25 #include <wx/platform.h>
26 #include "PreviewPanoMaskTool.h"
27 #ifdef __WXMAC__
28 #include <OpenGL/gl.h>
29 #else
30 #include <GL/gl.h>
31 #endif
32 
PreviewPanoMaskTool(PreviewToolHelper * helper)33 PreviewPanoMaskTool::PreviewPanoMaskTool(PreviewToolHelper *helper)
34     : PreviewTool(helper)
35 {
36 }
37 
Activate()38 void PreviewPanoMaskTool::Activate()
39 {
40     // we draw to the sentcil buffer the desired shape, and enable the stencil
41     // test before the images are rendered. After they have all been drawn, we
42     // turn off stenciling so the other tools can draw of the complete area.
43     helper->NotifyMe(PreviewToolHelper::REALLY_DRAW_OVER_IMAGES, this);
44 }
45 
BeforeDrawImagesEvent()46 void PreviewPanoMaskTool::BeforeDrawImagesEvent()
47 {
48 }
49 
ReallyAfterDrawImagesEvent()50 void PreviewPanoMaskTool::ReallyAfterDrawImagesEvent()
51 {
52     switch (helper->GetViewStatePtr()->GetOptions()->getProjection())
53     {
54         case HuginBase::PanoramaOptions::SINUSOIDAL:
55             helper->GetViewStatePtr()->GetTextureManager()->DisableTexture();
56             glColor3f(0.0, 0.0, 0.0);
57             {
58                 // Under a sinusodial projection, we mask off the sides.
59                 OutputProjectionInfo *info = helper->GetViewStatePtr()->
60                                                             GetProjectionInfo();
61                 double x, y;
62                 glBegin(GL_QUAD_STRIP);
63                     for (double p = -90; p < 90; p += 1.0)
64                     {
65                         info->AngularToImage(x, y, -180.0, p);
66                         glVertex2d(x, y); glVertex2d(0.0, y);
67                     }
68                 glEnd();
69                 double width = helper->GetViewStatePtr()->GetOptions()->
70                                                               getSize().width();
71                 glBegin(GL_QUAD_STRIP);
72                     for (double p = -90; p < 90; p += 1.0)
73                     {
74                         info->AngularToImage(x, y, -180.0, p);
75                         glVertex2d(width - x, y); glVertex2d(width, y);
76                     }
77                 glEnd();
78             }
79             glEnable(GL_TEXTURE_2D);
80             glColor3f(1.0, 1.0, 1.0);
81             break;
82         case HuginBase::PanoramaOptions::ALBERS_EQUAL_AREA_CONIC:
83             // Under a albers equal area conic projection, we mask a circle
84             // segment with a hole in the middle. The dimensions and centre
85             // are depended on the projection parameters.
86             helper->GetViewStatePtr()->GetTextureManager()->DisableTexture();
87             glColor3f(0.0, 0.0, 0.0);
88             glStencilFunc(GL_EQUAL, 1, 1);
89             glEnable(GL_TEXTURE_2D);
90             glColor3f(1.0, 1.0, 1.0);
91             break;
92         default:
93             // most projections don't need any of this.
94             // Always pass the stencil test.
95             glStencilFunc(GL_ALWAYS, 1, 1);
96             break;
97     }
98 }
99 
100