00001
00002
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "PreviewGuideTool.h"
00028 #ifdef __WXMAC__
00029 #include <OpenGL/gl.h>
00030 #else
00031 #include <GL/gl.h>
00032 #endif
00033
00034 PreviewGuideTool::PreviewGuideTool(PreviewToolHelper *helper) : PreviewTool(helper)
00035 {
00036 }
00037
00038 void PreviewGuideTool::Activate()
00039 {
00040 helper->NotifyMe(PreviewToolHelper::REALLY_DRAW_OVER_IMAGES, this);
00041 }
00042
00043 void DrawThirds(const vigra::Rect2D roi)
00044 {
00045 double width3 = (double) roi.width()/3.0;
00046 double height3 = (double) roi.height()/3.0;
00047 glBegin(GL_LINES);
00048 glVertex2f((double)roi.left()+width3,roi.top());
00049 glVertex2f((double)roi.left()+width3,roi.bottom());
00050 glVertex2f((double)roi.left()+2.0*width3,roi.top());
00051 glVertex2f((double)roi.left()+2.0*width3,roi.bottom());
00052 glVertex2f(roi.left(), (double)roi.top()+height3);
00053 glVertex2f(roi.right(),(double)roi.top()+height3);
00054 glVertex2f(roi.left(), (double)roi.top()+2.0*height3);
00055 glVertex2f(roi.right(),(double)roi.top()+2.0*height3);
00056 glEnd();
00057 };
00058
00059 void DrawGoldenRatio(const vigra::Rect2D roi)
00060 {
00061 double width = (double) roi.width();
00062 double height = (double) roi.height();
00063 glBegin(GL_LINES);
00064 glVertex2f((double)roi.left()+width*0.382,roi.top());
00065 glVertex2f((double)roi.left()+width*0.382,roi.bottom());
00066 glVertex2f((double)roi.left()+width*0.618,roi.top());
00067 glVertex2f((double)roi.left()+width*0.618,roi.bottom());
00068 glVertex2f(roi.left(), (double)roi.top()+height*0.382);
00069 glVertex2f(roi.right(),(double)roi.top()+height*0.382);
00070 glVertex2f(roi.left(), (double)roi.top()+height*0.618);
00071 glVertex2f(roi.right(),(double)roi.top()+height*0.618);
00072 glEnd();
00073 };
00074
00075 void DrawDiagonal(const vigra::Rect2D roi)
00076 {
00077 glBegin(GL_LINES);
00078 glVertex2f(roi.left(), roi.top());
00079 glVertex2f(roi.right(), roi.bottom());
00080 glVertex2f(roi.left(), roi.bottom());
00081 glVertex2f(roi.right(), roi.top());
00082 glVertex2f(roi.left(), roi.top()+roi.height()/2.0);
00083 glVertex2f(roi.right(), roi.top()+roi.height()/2.0);
00084 glVertex2f(roi.left()+roi.width()/2.0, roi.top());
00085 glVertex2f(roi.left()+roi.width()/2.0, roi.bottom());
00086 glEnd();
00087 };
00088
00089 void DrawTriangle(const vigra::Rect2D roi, const bool up)
00090 {
00091 double w=roi.width();
00092 double h=roi.height();
00093 double x=w/(1+pow(w/h,2));
00094 double y=h/(1+pow(w/h,2));
00095 glBegin(GL_LINES);
00096 if(up)
00097 {
00098 glVertex2f(roi.left(), roi.bottom());
00099 glVertex2f(roi.right(), roi.top());
00100 glVertex2f(roi.right()-x, roi.top()+y);
00101 glVertex2f(roi.right(), roi.bottom());
00102 glVertex2f(roi.left()+x, roi.bottom()-y);
00103 glVertex2f(roi.left(), roi.top());
00104 }
00105 else
00106 {
00107 glVertex2f(roi.left(), roi.top());
00108 glVertex2f(roi.right(), roi.bottom());
00109 glVertex2f(roi.right()-x, roi.bottom()-y);
00110 glVertex2f(roi.right(), roi.top());
00111 glVertex2f(roi.left()+x, roi.top()+y);
00112 glVertex2f(roi.left(), roi.bottom());
00113 }
00114 glEnd();
00115 };
00116
00117 void DrawDiagonalMethod(const vigra::Rect2D roi)
00118 {
00119 double w=roi.width();
00120 double h=roi.height();
00121 glBegin(GL_LINES);
00122 glVertex2f(roi.left(), roi.top());
00123 if(w>h)
00124 {
00125 glVertex2f(roi.left()+h, roi.bottom());
00126 }
00127 else
00128 {
00129 glVertex2f(roi.right(), roi.top()+w);
00130 };
00131 glVertex2f(roi.left(), roi.bottom());
00132 if(w>h)
00133 {
00134 glVertex2f(roi.left()+h, roi.top());
00135 }
00136 else
00137 {
00138 glVertex2f(roi.right(), roi.bottom()-w);
00139 };
00140 glVertex2f(roi.right(), roi.top());
00141 if(w>h)
00142 {
00143 glVertex2f(roi.right()-h, roi.bottom());
00144 }
00145 else
00146 {
00147 glVertex2f(roi.left(), roi.top()+w);
00148 };
00149 glVertex2f(roi.right(), roi.bottom());
00150 if(w>h)
00151 {
00152 glVertex2f(roi.right()-h, roi.top());
00153 }
00154 else
00155 {
00156 glVertex2f(roi.left(), roi.bottom()-w);
00157 };
00158 glEnd();
00159 };
00160
00161 void PreviewGuideTool::ReallyAfterDrawImagesEvent()
00162 {
00163 if(m_guide==NONE)
00164 {
00165 return;
00166 };
00167 HuginBase::PanoramaOptions *opts = helper->GetViewStatePtr()->GetOptions();
00168 vigra::Rect2D roi = opts->getROI();
00169 glDisable(GL_TEXTURE_2D);
00170 glColor3f(1,1,0);
00171 switch(m_guide)
00172 {
00173 case THIRDS:
00174 DrawThirds(roi);
00175 break;
00176 case GOLDENRATIO:
00177 DrawGoldenRatio(roi);
00178 break;
00179 case DIAGONAL:
00180 DrawDiagonal(roi);
00181 break;
00182 case TRIANGLE_DOWN:
00183 DrawTriangle(roi,false);
00184 break;
00185 case TRIANGLE_UP:
00186 DrawTriangle(roi,true);
00187 break;
00188 case DIAGONAL_METHOD:
00189 DrawDiagonalMethod(roi);
00190 break;
00191 };
00192 glEnable(GL_TEXTURE_2D);
00193 }
00194
00195 void PreviewGuideTool::SetGuideStyle(const Guides newGuideStyle)
00196 {
00197 m_guide=newGuideStyle;
00198 helper->GetViewStatePtr()->Redraw();
00199 };
00200
00201 const PreviewGuideTool::Guides PreviewGuideTool::GetGuideStyle() const
00202 {
00203 return m_guide;
00204 };
00205