[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [marble/gsoc-2012-replaceatlas] src/lib: Create a CylindricalProjection class which inherits Abstrac
From:       Cezar Mocan <mocancezar () gmail ! com>
Date:       2012-06-01 13:10:01
Message-ID: 20120601131001.4B0B4A60BB () git ! kde ! org
[Download RAW message or body]

Git commit 47a898e6292c9056289bbe4b4d14664eb93f2466 by Cezar Mocan.
Committed on 01/06/2012 at 15:09.
Pushed by mocan into branch 'gsoc-2012-replaceatlas'.

Create a CylindricalProjection class which inherits AbstractProjection and is \
inherited by MercatorProjection and EquirectProjection

M  +2    -0    src/lib/CMakeLists.txt
A  +61   -0    src/lib/Projections/CylindricalProjection.cpp     [License: LGPL]
A  +59   -0    src/lib/Projections/CylindricalProjection.h     [License: LGPL]
M  +13   -7    src/lib/Projections/EquirectProjection.cpp
M  +10   -7    src/lib/Projections/EquirectProjection.h
M  +12   -6    src/lib/Projections/MercatorProjection.cpp
M  +7    -7    src/lib/Projections/MercatorProjection.h

http://commits.kde.org/marble/47a898e6292c9056289bbe4b4d14664eb93f2466

diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 1208f5f..a7a4ad1 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -111,6 +111,7 @@ set(marblewidget_SRCS
     ViewportParams.cpp
     ViewParams.cpp
     Projections/AbstractProjection.cpp
+	Projections/CylindricalProjection.cpp
     Projections/SphericalProjection.cpp
     Projections/EquirectProjection.cpp
     Projections/MercatorProjection.cpp
@@ -348,6 +349,7 @@ else (APPLE AND QTONLY)
     TileCreatorDialog.h
     ViewportParams.h
     Projections/AbstractProjection.h
+	Projections/CylindricalProjection.h
     Projections/SphericalProjection.h
     Projections/EquirectProjection.h
     Projections/MercatorProjection.h
diff --git a/src/lib/Projections/CylindricalProjection.cpp \
b/src/lib/Projections/CylindricalProjection.cpp new file mode 100644
index 0000000..c103a68
--- /dev/null
+++ b/src/lib/Projections/CylindricalProjection.cpp
@@ -0,0 +1,61 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2007       Inge Wallin  <ingwa@kde.org>
+// Copyright 2007-2009  Torsten Rahn  <rahn@kde.org>
+// Copyright 2012		Cezar Mocan	<mocancezar@gmail.com>
+//
+
+// Local
+#include "CylindricalProjection.h"
+
+// Marble
+#include "ViewportParams.h"
+
+using namespace Marble;
+
+CylindricalProjection::CylindricalProjection()
+    : AbstractProjection(),
+	d( 0 )
+{
+}
+
+
+CylindricalProjection::~CylindricalProjection()
+{
+}
+
+
+QPainterPath CylindricalProjection::mapShape( const ViewportParams *viewport ) const
+{
+    // Convenience variables
+    int  width  = viewport->width();
+    int  height = viewport->height();
+
+    qreal  yTop;
+    qreal  yBottom;
+    qreal  xDummy;
+
+    // Get the top and bottom coordinates of the projected map.
+    screenCoordinates( 0.0, maxLat(), viewport, xDummy, yTop );
+    screenCoordinates( 0.0, minLat(), viewport, xDummy, yBottom );
+
+    // Don't let the map area be outside the image
+	if ( yTop < 0 )
+        yTop = 0;
+    if ( yBottom > height )
+        yBottom =  height;
+
+    QPainterPath mapShape;
+    mapShape.addRect(
+                    0,
+                    yTop,
+                    width,
+                    yBottom - yTop );
+
+    return mapShape;
+}
diff --git a/src/lib/Projections/CylindricalProjection.h \
b/src/lib/Projections/CylindricalProjection.h new file mode 100644
index 0000000..affd1e6
--- /dev/null
+++ b/src/lib/Projections/CylindricalProjection.h
@@ -0,0 +1,59 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2007       Inge Wallin  <ingwa@kde.org>
+// Copyright 2007-2009  Torsten Rahn  <rahn@kde.org>
+// Copyright 2012		Cezar Mocan	<mocancezar@gmail.com>
+//
+
+#ifndef MARBLE_CYLINDRICALPROJECTION_H
+#define MARBLE_CYLINDRICALPROJECTION_H
+
+/** @file
+ * This file contains the headers for CylindricalProjection.
+ *
+ */
+
+#include "AbstractProjection.h"
+
+namespace Marble 
+{
+
+class CylindricalProjectionPrivate;
+
+/**
+ * @short A base class for the Equirectangular and Mercator projections in Marble
+ */
+
+class CylindricalProjection : public AbstractProjection
+{
+    // Not a QObject so far because we don't need to send signals.	
+  public:
+	
+	CylindricalProjection();
+
+	virtual ~CylindricalProjection();
+
+    virtual bool repeatableX() const { return true; };
+
+    virtual bool traversablePoles()  const { return false; }
+    virtual bool traversableDateLine()  const { return false; }
+
+    virtual SurfaceType surfaceType() const { return Cylindrical; }
+
+    virtual QPainterPath mapShape( const ViewportParams *viewport ) const;
+
+ private:
+    Q_DISABLE_COPY( CylindricalProjection )
+    CylindricalProjectionPrivate  * d;
+
+};
+
+}
+
+#endif
+
diff --git a/src/lib/Projections/EquirectProjection.cpp \
b/src/lib/Projections/EquirectProjection.cpp index 3216f75..4566d4f 100644
--- a/src/lib/Projections/EquirectProjection.cpp
+++ b/src/lib/Projections/EquirectProjection.cpp
@@ -21,7 +21,7 @@ using namespace Marble;
 
 
 EquirectProjection::EquirectProjection()
-    : AbstractProjection(),
+    : CylindricalProjection(),
       d( 0 )
 {
     setRepeatX( repeatableX() );
@@ -33,10 +33,13 @@ EquirectProjection::~EquirectProjection()
 {
 }
 
+/*
 bool EquirectProjection::repeatableX() const
 {
     return true;
 }
+*/
+
 
 qreal EquirectProjection::maxValidLat() const
 {
@@ -62,7 +65,7 @@ bool EquirectProjection::screenCoordinates( const qreal lon, const \
qreal lat,  const qreal centerLat = viewport->centerLatitude();
 
     qreal  rad2Pixel = 2.0 * viewport->radius() / M_PI;
- 
+
     // Let (x, y) be the position on the screen of the point.
     x = ( width  / 2.0 + ( lon - centerLon ) * rad2Pixel );
     y = ( height / 2.0 - ( lat - centerLat ) * rad2Pixel );
@@ -341,6 +344,7 @@ bool EquirectProjection::mapCoversViewport( const ViewportParams \
*viewport ) con  return true;
 }
 
+/*
 QPainterPath EquirectProjection::mapShape( const ViewportParams *viewport ) const
 {
     // Convenience variables
@@ -348,12 +352,13 @@ QPainterPath EquirectProjection::mapShape( const ViewportParams \
*viewport ) cons  int  width  = viewport->width();
     int  height = viewport->height();
 
-    // Calculate translation of center point
-    const qreal centerLat = viewport->centerLatitude();
+	qreal  yTop; 
+	qreal  yBottom;
+	qreal  xDummy;
 
-    int yCenterOffset = (int)( centerLat * (qreal)( 2 * radius ) / M_PI );
-    int yTop          = height / 2 - radius + yCenterOffset;
-    int yBottom       = yTop + 2 * radius;
+	// Get the top and bottom coordinates of the projected map
+    screenCoordinates( 0.0, maxLat(), viewport, xDummy, yTop );
+    screenCoordinates( 0.0, minLat(), viewport, xDummy, yBottom );
 
     // Don't let the map area be outside the image
     if ( yTop < 0 )
@@ -370,3 +375,4 @@ QPainterPath EquirectProjection::mapShape( const ViewportParams \
*viewport ) cons  
     return mapShape;
 }
+*/
diff --git a/src/lib/Projections/EquirectProjection.h \
b/src/lib/Projections/EquirectProjection.h index ca22966..dbd990e 100644
--- a/src/lib/Projections/EquirectProjection.h
+++ b/src/lib/Projections/EquirectProjection.h
@@ -22,7 +22,7 @@
  */
 
 
-#include "AbstractProjection.h"
+#include "CylindricalProjection.h"
 
 
 namespace Marble
@@ -34,7 +34,7 @@ class EquirectProjectionPrivate;
  * @short A class to implement the Equirectangular projection used by the "Flat Map" \
                view.
  */
 
-class EquirectProjection : public AbstractProjection
+class EquirectProjection : public CylindricalProjection
 {
     // Not a QObject so far because we don't need to send signals.
  public:
@@ -46,14 +46,17 @@ class EquirectProjection : public AbstractProjection
 
     virtual ~EquirectProjection();
 
-    virtual bool repeatableX() const;
+//    virtual bool repeatableX() const;
     virtual qreal  maxValidLat() const;
     virtual qreal  minValidLat() const;
 
-    virtual bool traversablePoles()  const { return false; }
-    virtual bool traversableDateLine()  const { return false; }
+//    virtual bool traversablePoles()  const { return false; }
+//    virtual bool traversableDateLine()  const { return false; }
+
+
+//    virtual SurfaceType surfaceType() const { return Cylindrical; }
+
 
-    virtual SurfaceType surfaceType() const { return Cylindrical; }
 
     virtual PreservationType preservationType() const { return NoPreservation; }
 
@@ -103,7 +106,7 @@ class EquirectProjection : public AbstractProjection
 
     bool mapCoversViewport( const ViewportParams *viewport ) const;
 
-    virtual QPainterPath mapShape( const ViewportParams *viewport ) const;
+//    virtual QPainterPath mapShape( const ViewportParams *viewport ) const;
 
  private:
     Q_DISABLE_COPY( EquirectProjection )
diff --git a/src/lib/Projections/MercatorProjection.cpp \
b/src/lib/Projections/MercatorProjection.cpp index fb63e21..cc21206 100644
--- a/src/lib/Projections/MercatorProjection.cpp
+++ b/src/lib/Projections/MercatorProjection.cpp
@@ -23,7 +23,7 @@
 using namespace Marble;
 
 MercatorProjection::MercatorProjection()
-    : AbstractProjection(),
+    : CylindricalProjection(),
       d( 0 )
 {
     setRepeatX( repeatableX() );
@@ -35,10 +35,13 @@ MercatorProjection::~MercatorProjection()
 {
 }
 
+/*
 bool MercatorProjection::repeatableX() const
 {
     return true;
 }
+*/
+
 
 qreal MercatorProjection::maxValidLat() const
 {
@@ -314,8 +317,7 @@ GeoDataLatLonAltBox MercatorProjection::latLonAltBox( const \
QRect& screenRect,  }
     }
     else {
-        // We need a point on the screen at maxLat that definitely
-        // gets displayed:
+        // We need a point on the screen at maxLat that definitely gets displayed:
         qreal averageLatitude = ( latLonAltBox.north() + latLonAltBox.south() ) / \
2.0;  
         GeoDataCoordinates maxLonPoint( +M_PI, averageLatitude, \
GeoDataCoordinates::Radian ); @@ -359,10 +361,11 @@ bool \
MercatorProjection::mapCoversViewport( const ViewportParams *viewport ) con  return \
true;  }
 
+/*
 QPainterPath MercatorProjection::mapShape( const ViewportParams *viewport ) const
 {
     // Convenience variables
-    //int  radius = viewport->radius();
+    int  radius = viewport->radius();
     int  width  = viewport->width();
     int  height = viewport->height();
 
@@ -370,11 +373,12 @@ QPainterPath MercatorProjection::mapShape( const ViewportParams \
*viewport ) cons  qreal  yBottom;
     qreal  xDummy;
 
-    // Get the top and bottom y coordinates of the projected map.
+    // Get the top and bottom coordinates of the projected map.
     screenCoordinates( 0.0, maxLat(), viewport, xDummy, yTop );
     screenCoordinates( 0.0, minLat(), viewport, xDummy, yBottom );
 
-    if ( yTop < 0 )
+    // Don't let the map area be outside the image
+	if ( yTop < 0 )
         yTop = 0;
     if ( yBottom > height )
         yBottom =  height;
@@ -388,3 +392,5 @@ QPainterPath MercatorProjection::mapShape( const ViewportParams \
*viewport ) cons  
     return mapShape;
 }
+*/
+
diff --git a/src/lib/Projections/MercatorProjection.h \
b/src/lib/Projections/MercatorProjection.h index 9d1e736..30fbb0a 100644
--- a/src/lib/Projections/MercatorProjection.h
+++ b/src/lib/Projections/MercatorProjection.h
@@ -22,7 +22,7 @@
  */
 
 
-#include "AbstractProjection.h"
+#include "CylindricalProjection.h"
 
 namespace Marble
 {
@@ -33,7 +33,7 @@ class MercatorProjectionPrivate;
  * @short A class to implement the Mercator projection.
  */
 
-class MercatorProjection : public AbstractProjection
+class MercatorProjection : public CylindricalProjection
 {
     // Not a QObject so far because we don't need to send signals.
  public:
@@ -45,14 +45,14 @@ class MercatorProjection : public AbstractProjection
 
     virtual ~MercatorProjection();
 
-    virtual bool repeatableX() const;
+//    virtual bool repeatableX() const;
     virtual qreal  maxValidLat() const;
     virtual qreal  minValidLat() const;
 
-    virtual bool traversablePoles() const { return false; }
-    virtual bool traversableDateLine() const { return false; }
+//    virtual bool traversablePoles() const { return false; }
+//    virtual bool traversableDateLine() const { return false; }
 
-    virtual SurfaceType surfaceType() const { return Cylindrical; }
+//    virtual SurfaceType surfaceType() const { return Cylindrical; }	
 
     virtual PreservationType preservationType() const { return Conformal; }
 
@@ -102,7 +102,7 @@ class MercatorProjection : public AbstractProjection
 
     bool  mapCoversViewport( const ViewportParams *viewport ) const;
 
-    virtual QPainterPath mapShape( const ViewportParams *viewport ) const;
+//    virtual QPainterPath mapShape( const ViewportParams *viewport ) const;
 
  private:
     Q_DISABLE_COPY( MercatorProjection )


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic