/* -*- C++ -*- * Copyright ©2004 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ // Transformation to convert between globe coordinates and map space // (i.e. the main projection function) // f() should throw an exception if the point is not visible in this projection // f_edge() can be used to find a map point on the edge between // visible (first parameter) and invisible (second parameter) // g() should throw an exception if the point is not on the projected surface #ifndef XFMAP_H #define XFMAP_H #include #include "magellan/vectors.h" #include "magellan/plugin.h" // The plugininfo class XfMap; #include "magellan/plugininfo_map.h" // Useful tools #include "magellan/configlexer.h" #include "magellan/parsertools.h" #include "magellan/values.h" typedef enum { Vis_VISIBLE, // Edge is fully visible Vis_NOTVISIBLE, // Edge is fully invisible Vis_CROSSING // Edge is partially visible } Visibility; // Opaque class to maintain tracing state class TraceState { public: virtual ~TraceState() { } }; // Class to hold the relevant information for a trace point class TracePoint : public dvec2 { public: // Ordinary point TracePoint(const dvec2& v) : dvec2(v), lambda(0.0), entering(false), leaving(false) { } // Ordinary point TracePoint(double x, double y) : dvec2(), lambda(0.0), entering(false), leaving(false) { (*this)[0] = x; (*this)[0] = y; } // Edge point TracePoint(const dvec2& v, double l, bool e /* True if entering */) : dvec2(v), lambda(l), entering(e), leaving(!e) { } // Edge point TracePoint(double x, double y, double l, bool e /* True if entering */) : dvec2(), lambda(l), entering(e), leaving(!e) { (*this)[0] = x; (*this)[1] = y; } double lambda; bool entering; bool leaving; bool isedge(void) const { return entering || leaving; } }; typedef std::vector TracePointCollection; typedef std::back_insert_iterator TPCInsertIterator; class XfMap : public Plugin { public: XfMap() { } // Forward: map a 3-vec on the globe to a 2-vec on the map virtual bool f(dvec2&, const dvec3&) const = 0; // Backward: map a 2-vec on the map to a 3-vec on the globe virtual bool g(dvec3&, const dvec2&) const = 0; // Functions for handling lines passing the edges of the // projection. These functions take a 3D point as input, and add // 2D points to the vector. // Initialise a path trace at a given point virtual TraceState* initpath(TPCInsertIterator it, const dvec3& point) const { return new TraceState(); } // Takes 3D points as input. Map and insert the relevant 2D points // (including start and end), if any, using the iterator. Should // use f(), ideally. virtual void pathpoint(TraceState* state, TPCInsertIterator it, const dvec3& point) const/* = 0*/ { } // Terminate a path (state is invalid afterwards) virtual void endpath(TraceState* state) const { delete state; } // Add segments of a path around the edge of the projection // between two given lambda values. Neither start nor end points // are added by this function (so if there is a single line // segment between start and end, this function will do nothing) virtual void tracepath(TPCInsertIterator it, double startlambda, double endlambda) const/* = 0*/ { } protected: virtual ~XfMap() { } }; #endif