// mapfragment.hpp -- map fragment // // Written by Frederic Bouvier, started October 2001. // // Copyright (C) 2001 Frederic Bouvier - fredb@users.sourceforge.net // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: mapfragment.hpp,v 1.4 2005/05/09 07:02:09 fredb Exp $ #ifndef _mapfragment_hpp_ #define _mapfragment_hpp_ #include #include #include #include "teximage.hpp" #include "marker.hpp" class FGSD_MapTriangulation; class FGSD_MapFragment { public: static const size_t TEX_SIZE; struct Point { Point(){} Point( double x_, double y_ ) : x(x_), y(y_) {} Point operator -( const Point &right ) const { return Point( x - right.x, y - right.y ); } double x; double y; }; typedef std::list Contour; public: FGSD_MapFragment(); ~FGSD_MapFragment(); void drawOrtho( double __zLevel ) const; void drawTransformed( double xm, double ym, double xM, double yM ) const; void drawOutline() const; void drawContour() const; void boundingBox( double &x1, double &y1, double &x2, double &y2 ) const; bool isOver( double x, double y ) const; size_t width() const; size_t height() const; size_t realWidth() const; size_t realHeight() const; size_t nbMarkers() const; void addMarker( const FGSD_Marker & ); void setMarker( size_t n, const FGSD_Marker & ); void cleanTextures(); void loadImage( const char *__fileName = 0 ); void createDummyImage( int width, int height ); void putSubImage( FGSD_Image *image, int x, int y ); void initContour(); void refreshTesselation( bool grid ); void load( const char *__fileName ); void save( const char *__fileName ); void saveImage( const char *__fileName ); int markerHitTest( double x, double y, double r ); bool hitContour( double x, double y, double zLevel, Contour::iterator &pos, bool &edge ); void changeContourPointPosition( Contour::iterator pos, double x, double y ); void selectEdge( Contour::iterator pos ); void unselectEdge(); bool insertPointToContour( double x, double y ); bool removePointFromContour( Contour::iterator pos ); bool initMatrix(); void rotate( bool plus ); int orientation() const; bool regular() const; static void initTextures(); bool isValid() const; const char *path() const; private: void drawOrthoMap_0( double __zLevel ) const; void drawOrthoMap_90( double __zLevel ) const; void drawOrthoMap_180( double __zLevel ) const; void drawOrthoMap_270( double __zLevel ) const; double transformX( double x, double y ) const; double transformY( double x, double y ) const; void retrieveTexture( unsigned char *buffer, int w, unsigned char *tmp, size_t i, size_t j, size_t lines, size_t columns ); private: std::string _imageFileName; std::string _fileName; FGSD_TexImage **_textures; int _orientation; size_t _nx; size_t _bx; size_t _ny; size_t _by; FGSD_Marker _markers[ 4 ]; size_t _nbMarkers; // Transformation matrix coefficients double _ma; double _mb; double _mc; double _md; double _tx; double _ty; static GLuint _markerName; static bool _markerInit; FGSD_MapTriangulation &_tri; Contour _contour; Contour::iterator _edgeSelected; }; inline size_t FGSD_MapFragment::width() const { return (_nx - 1) * TEX_SIZE + _bx; } inline size_t FGSD_MapFragment::height() const { return (_ny - 1) * TEX_SIZE + _by; } inline size_t FGSD_MapFragment::nbMarkers() const { return _nbMarkers; } inline bool FGSD_MapFragment::isValid() const { return _nbMarkers == 3; } inline const char *FGSD_MapFragment::path() const { return _fileName.c_str(); } inline int FGSD_MapFragment::orientation() const { return _orientation; } inline bool FGSD_MapFragment::regular() const { return _orientation == 0 || _orientation == 180; } inline size_t FGSD_MapFragment::realWidth() const { return regular() ? width() : height(); } inline size_t FGSD_MapFragment::realHeight() const { return regular() ? height() : width(); } inline void FGSD_MapFragment::selectEdge( Contour::iterator pos ) { _edgeSelected = pos; } inline void FGSD_MapFragment::unselectEdge() { selectEdge( _contour.end() ); } #endif