Changes between Version 13 and Version 14 of MapGuideRfc26


Ignore:
Timestamp:
Aug 14, 2007, 12:48:20 AM (17 years ago)
Author:
yangm
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideRfc26

    v13 v14  
    6868== Proposed Solution ==
    6969
    70 Modify Stylization project to support the stylization of the elevation data, with surface style. New classes will be introduced to handle that style information, such as color, band, surface, hillshade and etc.
     70Modify Stylization project to support the stylization of the elevation data with surface style. Here, introduce some key classes for stylizing elevation data, also called grid data.
     71They are !GridStylizer, !GridData, !GridStyleHandler, !GridColorHandler and !GridApplyStatusReporter.
     72
     73=== !GridStylizer ===
     74This class only for stylization with grid data and grid styles. !GridStylizer takes a grid, a grid color style, and a grid surface style. Then it applies the color style on the grid and writes the result into the color band of the grid. Moreover, it also applies the surface style on the grid and writes the result into the elevation band of the grid.
     75
     76{{{
     77class GridStylizer
     78{
     79public:
     80    ///<summary>
     81    /// Stylizes a grid base on the given surface style and color style.
     82    /// It applies the surface style to generate a new elevation band to show
     83    /// 3d surface. And it also applies the color style to generate a new
     84    /// color band to show the texture of the 3d surface.
     85    ///</summary>
     86    ///<param name="pGrid">
     87    /// A grid is a set of bands. The stylizer read band data from the grid
     88    /// and write the result into the color band and elevation band.
     89    ///</param>
     90    ///<param name="pSurfaceStyle">
     91    /// The pointer of GridSurfaceStyle, which specifies how to calculate the elevation.
     92    ///</param>
     93    ///<param name="pColorStyle">
     94    /// The pointer of GridColorStyle, which specifies how to stylize each pixel.
     95    ///</param>
     96    ///</param>
     97    ///<param name="fOpacity">
     98    /// Opacity of this Grid Layer
     99    ///</param>
     100    ///<returns>
     101    /// Returns true to indicate the stylization transaction completes successfully.
     102    /// Returns false to indicate the stylization transaction encouters some errors and
     103    /// has been interruptted.
     104    ///</returns>
     105    STYLIZATION_API bool ApplyStyles(
     106                                     GridData *pGrid,
     107                                     const MdfModel::GridSurfaceStyle *pSurfaceStyle,
     108                                     const MdfModel::GridColorStyle *pColorStyle,
     109                                     double fOpacity = 1.0);
     110 
     111    ///<summary>
     112    /// Stylizes a grid base on the given color style and default color.
     113    /// It applies the color style to generate a new color band to show
     114    /// the texture of the 3d surface. And also it will set the transparent
     115    /// pixel to the default color.
     116    ///</summary>
     117    ///<param name="pGrid">
     118    /// A grid is a set of bands. The stylizer read band data from the grid
     119    /// and write the result into the color band.
     120    ///</param>
     121    ///<param name="pColorStyle">
     122    /// The pointer of GridColorStyle, which specifies how to stylize each pixel.
     123    ///</param>
     124    ///<param name="sDefaultColor">
     125    /// The default color for the tansparent pixel.
     126    ///</param>
     127    ///<returns>
     128    /// Returns true to indicate the stylization transaction completes successfully.
     129    /// Returns false to indicate the stylization transaction encouters some errors and
     130    /// has been interruptted.
     131    ///</returns>
     132    STYLIZATION_API bool ApplyColorStyle(
     133                                         GridData *pGrid,
     134                                         const MdfModel::GridColorStyle *pStyle,
     135                                         const MdfModel::MdfString &sDefaultColor);
     136
     137    ///<summary>
     138    /// Stylizes a grid base on the given surface style.
     139    /// It applies the surface style to generate a new elevation band to show
     140    /// 3d surface.
     141    ///</summary>
     142    ///<param name="pGrid">
     143    /// A grid is a set of bands. The stylizer read band data from the grid
     144    /// and write the result into the color band and elevation band.
     145    ///</param>
     146    ///<param name="pSurfaceStyle">
     147    /// The pointer of GridSurfaceStyle, which specifies how to calculate the elevation.
     148    ///</param>
     149    ///<returns>
     150    /// Returns true to indicate the stylization transaction completes successfully.
     151    /// Returns false to indicate the stylization transaction encouters some errors and
     152    /// has been interruptted.
     153    ///</returns>
     154    STYLIZATION_API bool ApplySurfaceStyle(
     155                                           GridData *pGrid,
     156                                           const MdfModel::GridSurfaceStyle *pStyle);
     157
     158    ///<summary>
     159    /// Applied the hillshade effect to a gis band
     160    ///</summary>
     161    ///<param name="pColorBand">
     162    /// It is the input and ouput, we read color from it, and apply hillshade, then write
     163    /// back to it.
     164    ///</param>
     165    ///<param name="pHS">
     166    /// It describes how to apply hillshade to the gis band.
     167    ///</param>
     168    ///<returns>
     169    /// Returns true to indicate the stylization transaction completes successfully.
     170    /// Returns false to indicate the stylization transaction encouters some errors and
     171    /// has been interruptted.
     172    ///</returns>
     173    STYLIZATION_API static bool ApplyHillShade(
     174                                               Band* pColorBand,
     175                                               const MdfModel::HillShade *pHS);
     176
     177}
     178}}}
     179
     180=== !GridData ===
     181This class is a collection of all kinds of information from elevation data, such as bands, hillshade, bounding box and etc. Those grid data are populated from FdoIRaster.
     182
     183{{{
     184class GridData
     185{
     186public:   
     187    typedef std::vector<Band*>        GISGRIDVECTOR;   
     188
     189public:   
     190    ///<summary>
     191    /// Because all the bands in the same grid have the same original point extent and count,
     192    /// so this information is kept in the GridData class.   
     193    ///</summary>
     194    STYLIZATION_API                     GridData(   const Point2D&  point,
     195                                                    double          xExtent,
     196                                                    double          yExtent,
     197                                                    unsigned int    nXCount,
     198                                                    unsigned int    nYCount);
     199    /// <summary>
     200    ///   Populates the GridData from an FdoIRaster
     201    /// </summary>
     202    STYLIZATION_API void                     ReadRaster(RS_Raster*       pRaster,
     203                                                        FdoString*       pBandName,
     204                                                        unsigned long    cols,
     205                                                        unsigned long    rows,
     206                                                        double           xMin,
     207                                                        double           yMin,
     208                                                        double           xMax,
     209                                                        double           yMax,
     210                                                        bool             bAlignment);
     211
     212
     213
     214    ///<summary>
     215    /// Get the Band with band name. If it is not in the grid, return NULL.
     216    ///</summary>   
     217    STYLIZATION_API Band*            GetBand(const MdfModel::MdfString& name) const;       
     218
     219    ///<summary>
     220    /// Get the Band with the band index. If it is not in the grid, return NULL.
     221    /// The index of the Band maybe will changed after some insert operation,
     222    /// so please don't keep the band index to get the band next time.
     223    /// In the most case, please you'd better get the Band with the band name.
     224    /// You can use this method and GetBandCount method to iterator the grid get all
     225    /// the bands.
     226    ///</summary>
     227    STYLIZATION_API Band*            GetBand(unsigned int index) const;
     228    STYLIZATION_API inline size_t       GetBandCount() const;                                           
     229
     230    ///<summary>
     231    /// This method is used to create a new band in the grid, the band name
     232    /// will be set as the name parament. And this band will be insert to the grid.
     233    /// If the name is duplicated, this method will return NULL.
     234    ///</summary>
     235    STYLIZATION_API Band*            CreateBand(Band::BandDataType dataType, const MdfModel::MdfString& name);
     236
     237    ///<summary>
     238    /// Insert a band into the grid. Because a band is identity with it's name in the grid,
     239    /// so please make sure the name of band is not empty before insert it to the grid,
     240    /// or this method will return false. And if there is a band in the grid has the same name
     241    /// with the insert band, it will return false too.
     242    ///</summary>
     243    STYLIZATION_API bool                InsertBand( Band* pBand);
     244
     245    ///<summary>
     246    /// If the elevation band is a band in the grid, set the elevation band
     247    /// with the band name and index of the band in the grid.
     248    ///</summary>
     249    STYLIZATION_API bool                SetElevationBand(const MdfModel::MdfString& name);
     250    STYLIZATION_API bool                SetElevationBand(unsigned int index);
     251   
     252    ///<summary>
     253    /// If the elevation band is not a band in the grid, use this method to set the
     254    /// elevation band for the grid.
     255    ///</summary>
     256    STYLIZATION_API inline void         SetElevationBand(Band* pBand);
     257
     258    ///<summary>
     259    /// Get the elevation band in this grid.
     260    ///</summary>
     261    STYLIZATION_API inline Band*     GetElevationBand() const;
     262
     263    ///<summary>
     264    /// Get a band for stylization use. If it is empty, we will create one band (double type).   
     265    ///</summary>
     266    STYLIZATION_API Band*            GetElevationBandDataForStylization();
     267
     268    ///<summary>
     269    /// Get the draped color band in this grid.
     270    ///</summary>
     271    STYLIZATION_API  Band*            GetDrapedColorBand() const;
     272
     273    ///<summary>
     274    /// Create a draped color band in this grid.
     275    /// In some cases, the draped color band is not required for the grid.
     276    /// So we just offer this method to create the drpaed color band when it is required.
     277    ///</summary>
     278    STYLIZATION_API  void                CreateDrapedColorBand();
     279
     280    ///<summary>
     281    /// Get the color band in this grid.
     282    ///</summary>
     283    STYLIZATION_API Band*            GetColorBand() const;
     284                                           
     285    ///<summary>
     286    /// Function to retrieve the band that stores the hillshade values. It is in float format.
     287    ///</summary>
     288    STYLIZATION_API const Band*      GetCacheHillShadeBand(const MdfModel::HillShade *pHS) const;
     289
     290    ///<summary>
     291    /// Function to set the band that stores the hillshade values. It is in float format.
     292    ///</summary>
     293    STYLIZATION_API bool                SetCacheHillShadeBand(
     294                                                              const MdfModel::HillShade *pHS,
     295                                                              Band                   *pHSBand);
     296
     297    ///<summary>
     298    /// Set the raw color band without hillshade effect if the color band includes effect.
     299    ///</summary>
     300    STYLIZATION_API bool                SetNoHillShadeColorBand(Band *pNoHillShadeColorBand);
     301
     302    ///<summary>
     303    /// Get the raw color band without hillshade effect if the color band includes effect.
     304    ///</summary>
     305    STYLIZATION_API const Band*      GetNoHillShadeColorBand() const;
     306
     307    ///<summary>
     308    /// Get the raw color band without hillshade effect if the color band includes effect.
     309    ///</summary>
     310    STYLIZATION_API Band*            GetNoHillShadeColorBand();
     311
     312    ///<summary>
     313    /// Get the geometry information for the bands in this grid.   
     314    ///</summary>
     315    STYLIZATION_API inline double       GetXUnitDistance() const;
     316
     317    STYLIZATION_API inline double       GetYUnitDistance() const;
     318
     319    STYLIZATION_API inline double       GetInvScaledDX() const;
     320
     321    STYLIZATION_API inline double       GetInvScaledDY() const;
     322
     323    STYLIZATION_API inline unsigned int GetXCount() const;
     324                                   
     325    STYLIZATION_API inline unsigned int GetYCount() const;
     326
     327    STYLIZATION_API inline double       GetXExtent () const;
     328                                 
     329    STYLIZATION_API inline double       GetYExtent () const;
     330                                           
     331
     332    STYLIZATION_API inline const Point2D&            GetOriginalPoint2D() const;                                           
     333
     334    STYLIZATION_API inline MdfModel::Box2D            GetBoundingBox() const;
     335
     336    STYLIZATION_API inline void         SetCoordSysUnitLength(double dUnitLength);
     337
     338    STYLIZATION_API inline double       GetCoordSysUnitLength() const;
     339
     340    STYLIZATION_API Band::BandDataType  GetGridDataType(RS_Raster* pRaster,
     341                                                        bool bBandDataType = true) const;
     342}
     343}}}
     344
     345=== !GridStyleHandler ===
     346Class !GridStyleHandler is the base class of all the grid style handlers. This class provides the common interface to visit each pixel of the band and do the different operations, such as to stylize the band.
     347
     348{{{
     349class GridStyleHandler
     350{
     351public:
     352    ///<summary>
     353    /// Function to clear the data info of the handler.
     354    ///</summary>
     355    virtual void Clear() = 0;
     356
     357    ///<summary>
     358    /// Function to visit each pixel.
     359    ///</summary>
     360    virtual void Visit(unsigned int x, unsigned int y) = 0;
     361
     362    ///<summary>
     363    /// Finished visiting all the pixels
     364    ///</summary>
     365    virtual void Finished(bool bSuccessful) {bSuccessful;}
     366
     367    ///<summary>
     368    /// Set GridStatusReporter
     369    ///</summary>
     370    virtual void SetStatusReporter(GridStatusReporter *pReporter) = 0;
     371
     372    ///<summary>
     373    /// Function to visit all pixels.
     374    ///</summary>
     375    virtual bool Visit() = 0;
     376};
     377}}}
     378There are several derived classes of !GridStyleHandler:
     379[[BR]]!GridStyleColorHandler is used to handle the MdfModel::!GridColorStyle.
     380[[BR]]!GridStyleSurfaceColorHandler is used to set the transparent color to the default color. And it also set the invalid pixel to the default color.
     381[[BR]]!GridStyleSurfaceHandler is used to handle the MdfModel::!GridSurfaceStyle.
     382
     383=== !GridColorHandler ===
     384This base class provides the uniform interface for getting the color on each pixel when stylizing the band
     385
     386{{{
     387class GridColorHandler
     388{
     389public:
     390    ///<summary>
     391    /// Function to initialize the GridColorHandler object.
     392    ///</summary>
     393    ///<param name = "pRules">
     394    /// The rules includes the detail info.
     395    ///</param>
     396    ///<param name = "pGrid">
     397    /// The grid that the styles are applied on.
     398    ///</param>
     399    ///<returns>
     400    /// Returns true if it is intialized successfully.
     401    /// Othrewise, returns false.
     402    ///</returns>
     403    virtual bool Initialize(const MdfModel::RuleCollection *pRules, const GridData *pGrid) = 0;
     404
     405    ///<summary>
     406    /// Function to get the color on the pixel.
     407    ///</summary>
     408    ///<param name = "color">
     409    /// [Out] Stores the result color.
     410    ///</param>
     411    ///<param name = "x">
     412    /// The X axis position of the pixel
     413    ///</param>
     414    ///<param name = "y">
     415    /// The Y axis position of the pixel
     416    ///</param>
     417    ///<returns>
     418    /// Returns true if it gets the corresponding color.
     419    /// Othrewise, returns false.
     420    ///</returns>
     421    virtual bool GetColor(Color &color, unsigned int x, unsigned int y) = 0;
     422
     423    ///<summary>
     424    /// Function to clear the data info of the handler.
     425    ///</summary>
     426    virtual void Clear() = 0;
     427
     428    ///<summary>
     429    /// Function to create the corresponding color handler according to the different pRules.
     430    ///</summary>
     431    ///<param name = "pRules">
     432    /// The rules includes the detail info.
     433    ///</param>
     434    ///<param name = "pGrid">
     435    /// The grid that the styles are applied on.
     436    ///</param>
     437    ///<returns>
     438    /// Returns the pointer to the new created GridColorHandler.
     439    /// Caller must be responsible to release it.
     440    /// Returns NULL if the handlers fail to initialize.
     441    ///</returns>
     442    static GridColorHandler* Create(const MdfModel::RuleCollection *pRules, const GridData *pGrid);
     443
     444    ///<summary>
     445    /// Function to create the GridColorBandHandler.
     446    ///</summary>
     447    ///<param name = "pRules">
     448    /// The rules includes the detail info.
     449    ///</param>
     450    ///<param name = "pGrid">
     451    /// The grid that the styles are applied on.
     452    ///</param>
     453    ///<returns>
     454    /// Returns the pointer to the new created GridColorBandHandler.
     455    /// Caller must be responsible to release it.
     456    /// Returns NULL if the handlers fail to initialize.
     457    ///</returns>
     458    static GridColorBandHandler* CreateBandHandler(const MdfModel::RuleCollection *pRules, const GridData *pGrid);
     459
     460    ///<summary>
     461    /// Function to create the GridColorBandsHandler.
     462    ///</summary>
     463    ///<param name = "pRules">
     464    /// The rules includes the detail info.
     465    ///</param>
     466    ///<param name = "pGrid">
     467    /// The grid that the styles are applied on.
     468    ///</param>
     469    ///<returns>
     470    /// Returns the pointer to the new created GridColorBandsHandler.
     471    /// Caller must be responsible to release it.
     472    /// Returns NULL if the handlers fail to initialize.
     473    ///</returns>
     474    static GridColorBandsHandler* CreateBandsHandler(const MdfModel::RuleCollection *pRules, const GridData *pGrid);
     475
     476    ///<summary>
     477    /// Function to create the GridColorThemeHandler.
     478    ///</summary>
     479    ///<param name = "pRules">
     480    /// The rules includes the theme info.
     481    ///</param>
     482    ///<param name = "pGrid">
     483    /// The grid that the styles are applied on.
     484    ///</param>
     485    ///<returns>
     486    /// Returns the pointer to the new created GridColorThemeHandler.
     487    /// Caller must be responsible to release it.
     488    /// Returns NULL if the handlers fail to initialize.
     489    ///</returns>
     490    static GridColorThemeHandler* CreateThemeHandler(const MdfModel::RuleCollection *pRules, const GridData *pGrid);
     491
     492    ///<summary>
     493    /// Function to create the GridColorNullHandler.
     494    ///</summary>
     495    ///<param name = "pRules">
     496    /// The rules includes the detail info.
     497    ///</param>
     498    ///<param name = "pGrid">
     499    /// The grid that the styles are applied on.
     500    ///</param>
     501    ///<returns>
     502    /// Returns the pointer to the new created GridColorNullHandler.
     503    /// Caller must be responsible to release it.
     504    /// Returns NULL if the handlers fail to initialize.
     505    ///</returns>
     506    static GridColorNullHandler* CreateNullHandler(const MdfModel::RuleCollection *pRules, const GridData *pGrid);
     507};
     508}}}
     509There are several derived classes of !GridColorHandler:
     510[[BR]]!GridColorBandsHandler is used to handle the situation when the !GridColor's type is Bands. It gets the channel data from the three !ChannelBands and merge them to a color value.
     511[[BR]]!GridColorBandHandler is used to handle the situation when the !GridColor's type is Band. It gets the band's value and return it as the color value.
     512[[BR]]!GridColorNullHandler is used to handle the situation when there is no rule.
     513[[BR]]!GridColorThemeHandler is used to handle the situtation when stylizer themes a band according to the aspect, slope, or height value.It calculates the geometry value and searchs the corresponding color in its generated hash table.
     514
     515=== !GridApplyStatusReporter ===
     516
     517An implementation of !GridStatusReporter. This class will delegate all the status change events to the stylizer's reactors.
     518
     519{{{
     520class GridApplyStatusReporter : public GridStatusReporter
     521{
     522public:
     523    ///<summary>
     524    /// Initializes this class by the three arguments.
     525    ///</summary>
     526    ///<param name="stylizer">The the stylizer which is applying style.</param>
     527    ///<param name="pixelCount">The count of the total pixels of the grid.</param>
     528    void            Init(GridStylizer *stylizer, double pixelCount);
     529
     530    ///<summary>
     531    /// Indicates the transaction has been started.
     532    /// This class will notify the stylizer's reactors that
     533    /// the stylizer begins to apply the styles.
     534    ///</summary>
     535    virtual void     Begin();
     536
     537    ///<summary>
     538    /// Indicates the transaction has been finished successfully.
     539    /// This class will notify the stylizer's reactors that
     540    /// the stylizer has finished applying styles.
     541    ///</summary>
     542    virtual void     Commit();
     543
     544    ///<summary>
     545    /// Indicates the transaction encountered some error and has been terminated.
     546    /// This class will notify the stylizer's reactors that
     547    /// the stylizer failed to apply styles for some unknown reasons.
     548    ///</summary>
     549    virtual void     Rollback();
     550
     551    ///<summary>
     552    /// Call this function when finishing a step.
     553    /// And check the returned value.
     554    /// If the returned value is true, that means the Step() function has been handled successfully.
     555    /// Otherwise, false means encountering some exceptions.
     556    ///</summary>
     557    virtual bool     Step(int stepSize = 1);
     558
     559    ///<summary>
     560    /// If isTerminate is TRUE, then Step() will return FALSE to let the stylizer stop applying.
     561    /// It just sets a flag. And the flag will show its influence when
     562    /// calling Step() next time.
     563    ///</summary>
     564    void             SetTerminate(bool isTerminate);
     565
     566    ///<summary>
     567    /// Returns m_isTerminate.
     568    ///</summary>
     569    bool             IsTerminate() const;
     570}
     571}}}
     572Some new classes will be introduced to handle Band, Color, !ChannelBand, Theme and etc individually.
    71573
    72574== Implications ==