35 #include <OpenGL/gl.h>
38 #include <vigra/windows.h>
63 double endLat,
double endLong,
double width)
74 double endLat,
double endLong,
94 if (startLat == 360.0 - endLat && startLong == 180.0 - endLong)
97 if (startLat == 180.0 && startLong == 90.0)
100 *
this =
GreatCircleArc(startLat, startLong, 180.0, 0.0, visualizationState);
101 GreatCircleArc other(180.0, 0.0, endLat, endLong, visualizationState);
105 *
this =
GreatCircleArc(startLat, startLong, 180.0, 90.0, visualizationState);
106 GreatCircleArc other(180.0, 90.0, endLat, endLong, visualizationState);
113 if (startLat < 90.0 && endLat > 270.0)
118 startLat *= (
M_PI / 180.0);
119 startLong *= (
M_PI / 180.0);
120 endLat *= (
M_PI / 180.0);
121 endLong *= (
M_PI / 180.0);
124 double sineStartLat = std::sin(startLat);
125 double sineStartLong = std::sin(startLong);
126 double sineEndLat = std::sin(endLat);
127 double sineEndLong = std::sin(endLong);
128 double cosineStartLat = std::cos(startLat);
129 double cosineStartLong = std::cos(startLong);
130 double cosineEndLat = std::cos(endLat);
131 double cosineEndLong = std::cos(endLong);
141 double p1[3] = {cosineStartLat * sineStartLong, sineStartLat * sineStartLong, cosineStartLong};
142 double p2[3] = {cosineEndLat * sineEndLong, sineEndLat * sineEndLong, cosineEndLong};
150 const double line_v[3] = {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]};
151 const double line_length = sqrt(line_v[0] * line_v[0] + line_v[1] * line_v[1] + line_v[2] * line_v[2]);
154 const double bDifference = 1.0 / double(segments);
162 for (
unsigned int segment_index = 0; segment_index < segments;
163 segment_index++, b1 += bDifference, b2 -= bDifference)
166 double v[3] = {p1[0] * b1 + p2[0] * b2, p1[1] * b1 + p2[1] * b2, p1[2] * b1 + p2[2] * b2};
168 double length = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
175 double longitude = std::acos(v[2]);
178 double latitude = std::acos(v[0] / std::sin(longitude));
182 latitude = -latitude + 2 *
M_PI;
188 latitude * 180.0 /
M_PI,
189 longitude * 180.0 /
M_PI);
195 int newSegment = vx / (options.
getWidth() / 3);
196 if ((newSegment < 1 && lastSegment > 1) ||
197 (newSegment > 1 && lastSegment < 1))
201 lastSegment = newSegment;
226 for (
unsigned int i = 0 ; i <
m_lines.size() ; i++) {
241 if(withCross && !
m_lines.empty())
246 std::vector<GreatCircleArc::LineSegment>::const_iterator it;
262 double d = width / state->
GetScale() / 2.0;
264 double yd = d * sqrt(m*m + 1);
265 double xd = d * sin(atan(m));
275 bool vertical =
false;
285 bool horizontal =
false;
298 if (vertical || horizontal) {
313 if (preceding != NULL) {
322 double yd_pre = d * sqrt(m_pre*m_pre + 1);
328 rect[1].
x = ((b_pre + yd_pre) - (b + yd)) / (m - m_pre);
329 rect[1].
y = m_pre * rect[1].
x + b_pre + yd_pre;
331 rect[0].
x = ((b_pre - yd_pre) - (b - yd)) / (m - m_pre);
332 rect[0].
y = m_pre * rect[0].
x + b_pre - yd_pre;
343 rect[1].
y = m * rect[1].
x + b + yd;
346 rect[0].
y = m * rect[0].
x + b - yd;
356 if (proceeding != NULL) {
366 double yd_pro = d * sqrt(m_pro*m_pro + 1);
372 rect[3].
x = ((b_pro - yd_pro) - (b - yd)) / (m - m_pro);
373 rect[3].
y = m_pro * rect[3].
x + b_pro - yd_pro;
375 rect[2].
x = ((b_pro + yd_pro) - (b + yd)) / (m - m_pro);
376 rect[2].
y = m_pro * rect[2].
x + b_pro + yd_pro;
387 rect[3].
y = m * rect[3].
x + b - yd;
390 rect[2].
y = m * rect[2].
x + b + yd;
407 glVertex3d(res1.
x,res1.
y,res1.
z);
408 glVertex3d(res2.
x,res2.
y,res2.
z);
409 glVertex3d(res3.
x,res3.
y,res3.
z);
410 glVertex3d(res4.
x,res4.
y,res4.
z);
437 vx = vertices[point].x;
438 vy = vertices[point].y;
455 glVertex3f(res1.
x,res1.
y,res1.
z);
456 glVertex3f(res2.
x,res2.
y,res2.
z);
458 glVertex3f(res3.
x,res3.
y,res3.
z);
459 glVertex3f(res4.
x,res4.
y,res4.
z);
469 for (std::vector<GreatCircleArc::LineSegment>::const_iterator it =
m_lines.begin();
473 float this_distance = it->squareDistance(point);
474 if (this_distance < distance)
476 distance = this_distance;
487 if (vertices[0] == vertices[1])
496 float t = line_vector.
x == 0 ?
497 (point.
y - vertices[0].y) / line_vector.
y
498 : (point.
x - vertices[0].x) / line_vector.
x;
503 return vertices[0].squareDistance(point);
508 return vertices[1].squareDistance(point);
const double min_segment_angle
void drawLineFromSpherical(double startLat, double startLong, double endLat, double endLong, double width=1.0)
Draw the shortest segment of the great circle crossing two spherical coordinates. ...
GreatCircles()
constructor
void doGL(double width, VisualizationState *state, LineSegment *preceding=NULL, LineSegment *proceeding=NULL) const
Draw a meshed line.
VisualizationState * m_visualizationState
void doGLcross(int point, double cscale, VisualizationState *state) const
Specify the line to OpenGL. Must be within a glBegin/glEnd pair.
#define DEBUG_ASSERT(cond)
include file for the hugin project
VisualizationState * m_visualizationState
void setVisualizationState(VisualizationState *visualizationState)
Set the ViewState to use for information on output projection and preview display.
MeshManager * GetMeshManager()
const unsigned int max_segments
Declare GreatCircles class.
virtual MeshInfo::Coord3D GetCoord3D(hugin_utils::FDiff2D &)=0
GreatCircleArc()
Create a bad great circle arc.
TDiff2D< double > FDiff2D
hugin_utils::FDiff2D vertices[2]
unsigned int getWidth() const
include file for the hugin project
std::vector< LineSegment > m_lines
virtual HuginBase::PanoramaOptions * GetOptions()
float squareDistance(hugin_utils::FDiff2D point) const
Return the square of the minimal distance between the great circle arc and a coorinate on the panoram...
All variables of a source image.
a class to handle a 3D point
void draw(bool withCross=true, double width=1.0) const
Draw the great circle arc on the fast preview.
float squareDistance(hugin_utils::FDiff2D point) const
Get the square of the minimal distance to a point.
T squareDistance(TDiff2D< T > other) const
Return square of the distance to another point.