35 #include <OpenGL/gl.h>
38 #include <vigra/windows.h>
63 double endLat,
double endLong,
double width,
bool straightLine)
81 double endLat,
double endLong,
101 if (startLat == 360.0 - endLat && startLong == 180.0 - endLong)
104 if (startLat == 180.0 && startLong == 90.0)
107 *
this =
GreatCircleArc(startLat, startLong, 180.0, 0.0, visualizationState);
108 GreatCircleArc other(180.0, 0.0, endLat, endLong, visualizationState);
112 *
this =
GreatCircleArc(startLat, startLong, 180.0, 90.0, visualizationState);
113 GreatCircleArc other(180.0, 90.0, endLat, endLong, visualizationState);
120 if (startLat < 90.0 && endLat > 270.0)
125 startLat *= (
M_PI / 180.0);
126 startLong *= (
M_PI / 180.0);
127 endLat *= (
M_PI / 180.0);
128 endLong *= (
M_PI / 180.0);
131 const double sineStartLat = std::sin(startLat);
132 const double sineStartLong = std::sin(startLong);
133 const double sineEndLat = std::sin(endLat);
134 const double sineEndLong = std::sin(endLong);
135 const double cosineStartLat = std::cos(startLat);
136 const double cosineStartLong = std::cos(startLong);
137 const double cosineEndLat = std::cos(endLat);
138 const double cosineEndLong = std::cos(endLong);
148 double p1[3] = {cosineStartLat * sineStartLong, sineStartLat * sineStartLong, cosineStartLong};
149 double p2[3] = {cosineEndLat * sineEndLong, sineEndLat * sineEndLong, cosineEndLong};
156 const double line_v[3] = {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]};
157 const double line_length = sqrt(line_v[0] * line_v[0] + line_v[1] * line_v[1] + line_v[2] * line_v[2]);
160 const double bDifference = 1.0 / (segments - 1.0);
168 for (
unsigned int segment_index = 0; segment_index < segments;
169 segment_index++, b += bDifference)
172 double v[3] = {p1[0] * b + p2[0] * (1.0 - b), p1[1] * b + p2[1] * (1.0 - b), p1[2] * b + p2[2] * (1.0 - b)};
174 double length = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
181 double longitude = std::acos(v[2]);
184 double latitude = std::acos(v[0] / std::sin(longitude));
188 latitude = -latitude + 2 *
M_PI;
194 latitude * 180.0 /
M_PI,
195 longitude * 180.0 /
M_PI);
201 int newSegment = vx / (options.
getWidth() / 3);
202 if ((newSegment < 1 && lastSegment > 1) ||
203 (newSegment > 1 && lastSegment < 1))
207 lastSegment = newSegment;
232 for (
unsigned int i = 0 ; i <
m_lines.size() ; i++) {
247 if(withCross && !
m_lines.empty())
260 double m = (vertices[1].y - vertices[0].y) / (vertices[1].x - vertices[0].x);
261 double b = vertices[1].y - m * vertices[1].x;
263 double d = width / state->
GetScale() / 2.0;
265 double yd = d * sqrt(m*m + 1);
266 double xd = d * sin(atan(m));
268 if (vertices[1].x < vertices[0].x) {
276 bool vertical =
false;
277 if (std::abs(vertices[1].x - vertices[0].x) < 0.00001) {
279 if (vertices[1].y > vertices[0].y) {
286 bool horizontal =
false;
287 if(std::abs(vertices[1].y - vertices[0].y) < 0.00001) {
290 if (vertices[1].x > vertices[0].x) {
299 if (vertical || horizontal) {
300 rect[0].
x = vertices[0].x - xd;
301 rect[0].
y = vertices[0].y + yd;
302 rect[1].
x = vertices[0].x + xd;
303 rect[1].
y = vertices[0].y - yd;
304 rect[2].
x = vertices[1].x + xd;
305 rect[2].
y = vertices[1].y - yd;
306 rect[3].
x = vertices[1].x - xd;
307 rect[3].
y = vertices[1].y + yd;
314 if (preceding != NULL) {
323 double yd_pre = d * sqrt(m_pre*m_pre + 1);
329 rect[1].
x = ((b_pre + yd_pre) - (b + yd)) / (m - m_pre);
330 rect[1].
y = m_pre * rect[1].
x + b_pre + yd_pre;
332 rect[0].
x = ((b_pre - yd_pre) - (b - yd)) / (m - m_pre);
333 rect[0].
y = m_pre * rect[0].
x + b_pre - yd_pre;
343 rect[1].
x = vertices[0].x + xd;
344 rect[1].
y = m * rect[1].
x + b + yd;
346 rect[0].
x = vertices[0].x - xd;
347 rect[0].
y = m * rect[0].
x + b - yd;
357 if (proceeding != NULL) {
367 double yd_pro = d * sqrt(m_pro*m_pro + 1);
373 rect[3].
x = ((b_pro - yd_pro) - (b - yd)) / (m - m_pro);
374 rect[3].
y = m_pro * rect[3].
x + b_pro - yd_pro;
376 rect[2].
x = ((b_pro + yd_pro) - (b + yd)) / (m - m_pro);
377 rect[2].
y = m_pro * rect[2].
x + b_pro + yd_pro;
387 rect[3].
x = vertices[1].x - xd;
388 rect[3].
y = m * rect[3].
x + b - yd;
390 rect[2].
x = vertices[1].x + xd;
391 rect[2].
y = m * rect[2].
x + b + yd;
408 glVertex3d(res1.
x,res1.
y,res1.
z);
409 glVertex3d(res2.
x,res2.
y,res2.
z);
410 glVertex3d(res3.
x,res3.
y,res3.
z);
411 glVertex3d(res4.
x,res4.
y,res4.
z);
438 vx = vertices[point].x;
439 vy = vertices[point].y;
456 glVertex3f(res1.
x,res1.
y,res1.
z);
457 glVertex3f(res2.
x,res2.
y,res2.
z);
459 glVertex3f(res3.
x,res3.
y,res3.
z);
460 glVertex3f(res4.
x,res4.
y,res4.
z);
470 for (std::vector<GreatCircleArc::LineSegment>::const_iterator it =
m_lines.begin();
474 float this_distance = it->squareDistance(point);
475 if (this_distance < distance)
477 distance = this_distance;
488 if (vertices[0] == vertices[1])
497 float t = line_vector.
x == 0 ?
498 (point.
y - vertices[0].y) / line_vector.
y
499 : (point.
x - vertices[0].x) / line_vector.
x;
504 return vertices[0].squareDistance(point);
509 return vertices[1].squareDistance(point);
520 double endLat,
double endLong,
533 double x1, y1, x2, y2;
const double min_segment_angle
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.
StraightLineFromSphericals(double startLat, double startLong, double endLat, double endLong, VisualizationState &m_visualizationState)
Create a straight line from begin to end in spherical coordinates.
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()
void drawLineFromSpherical(double startLat, double startLong, double endLat, double endLong, double width=1.0, bool straightLine=false)
Draw the shortest segment of the great circle crossing two spherical coordinates. ...
float squareDistance(hugin_utils::FDiff2D point) const
Return the square of the minimal distance between the great circle arc and a coordinate on the panora...
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.