zoukankan      html  css  js  c++  java
  • WorldWind源码剖析系列:四叉树瓦片类QuadTile

    四叉树瓦片类QuadTile提供了对影像和地形数据的四叉树访问模型。该类的类图如下。

     

    四叉树瓦片类QuadTile提供的主要字段、属性和方法简要描述如下:

    public QuadTileSet QuadTileSet;//四叉树瓦片集合类

    public double West;//瓦片的西边界,角度为单位

    public double East;//瓦片的东边界

    public double North;//瓦片的北边界

    public double South;//瓦片的南边界

    public Angle CenterLatitude;//瓦片中心纬度,弧度为单位

    public Angle CenterLongitude;//瓦片中心经度

    public double LatitudeSpan;//瓦片纬度范围,角度为单位

    public double LongitudeSpan;//瓦片经度范围

    public int Level; //瓦片所属层级

    public int Row; //瓦片所属行号

    public int Col; //瓦片所属列号

    public bool isInitialized;//瓦片是否被初始化

    public BoundingBox BoundingBox; //瓦片的包围盒

    public GeoSpatialDownloadRequest DownloadRequest; //瓦片的下载请求

    protected Texture[] textures; //瓦片的纹理数组

    protected static int vertexCount = 40;//子平面格网中的点数

    protected static int vertexCountElevated = 40; //子地形格网中的点数

    protected QuadTile northWestChild;//西北角子瓦片

    protected QuadTile southWestChild; //西南角子瓦片

    protected QuadTile northEastChild; //东的北角子瓦片

    protected QuadTile southEastChild; //东南角子瓦片

    protected CustomVertex.PositionNormalTextured[] northWestVertices;

    protected CustomVertex.PositionNormalTextured[] southWestVertices;

    protected CustomVertex.PositionNormalTextured[] northEastVertices;

    protected CustomVertex.PositionNormalTextured[] southEastVertices;

    protected short[] vertexIndexes;//顶点索引数组

    protected Point3d localOrigin;//Add this offset to get world coordinates

    protected bool m_isResetingCache;//是否重置缓冲区

    protected float verticalExaggeration;//竖直放大倍数

    protected bool isDownloadingTerrain;//是否正在下载地形数据

    public bool WaitingForDownload = false;//是否等待下载

    public bool IsDownloadingImage = false;//是否正在下载影像数据

    double meshBaseRadius = 0;.//格网基本半径大小

    protected byte m_CurrentOpacity = 255;//当前的不透明度

    public string ImageFilePath = null;//影像纹理的路径

    protected CustomVertex.PositionColored[] downloadRectangle = new CustomVertex.PositionColored[5];//下载的影像或地形区域的矩形标记区

    static Effect grayscaleEffect = null;//DirectX 3D的效果变量

    构造函数public QuadTile(double south, double north, double west, double east, int level, QuadTileSet quadTileSet)用东、西、南、北四个边界,瓦片层级以及所包含的四叉树瓦片集合来实例化一个瓦片对象。其中,需要调用double radCosLat = radius * Math.Cos(latRadians);计算出纬度值为latRadians处的纬度圈的半径,调用MathEngine.GetRowFromLatitude(South, North - South);根据瓦片的起始边界和瓦片尺寸大小计算出瓦片所在的行号和列号。

    public virtual void ResetCache()虚函数用来重置缓冲区。

    private QuadTile ComputeChild(double childSouth, double childNorth, double childWest, double childEast)方法根据指定的位置计算子四叉树瓦片,内部实际是直接调用构造函数QuadTile实例化一个四叉树瓦片对象并返回。

    public virtual void ComputeChildren(DrawArgs drawArgs)方法根据具体的绘制参数计算子四叉树瓦片。内部调用了ComputeChild()函数来完成具体功能。

    public virtual void Update(DrawArgs drawArgs) 方法根据具体的绘制参数更新渲染场景的地形和影像瓦片数据,内部递归地调用自身。

    public virtual void CreateTileMesh()方法为当前格网构建平面格网和地形格网。内部实际上是用过调CreateElevatedMesh()和CreateFlatMesh()方法实现。

    protected virtual void CreateFlatMesh()用来构建没有地形起伏的平面格网。

    protected virtual void CreateElevatedMesh()用来构建具有地形起伏的地形格网。内部实际通过调用protected void CreateElevatedMesh(ChildLocation corner, CustomVertex.PositionNormalTextured[] vertices,double meshBaseRadius, float[,] heightData)函数实现具体功能。

    private void calculate_normals(ref CustomVertex.PositionNormalTextured[] vertices, short[] indices)计算格网顶点的法线,以便启用光照。

    private Point3d ProjectOnMeshBase(Point3d p)私用方法用来将点p投影到各瓦网基准平面。

    public virtual bool Render(DrawArgs drawArgs)方法根据具体的绘制参数完成场景的渲染和绘制功能。

    public void RenderDownloadRectangle(DrawArgs drawArgs, int color, Vector3 referenceCenter)用一个带有颜色的矩形区域标记下载的影像或地形区域。

    void Render(Device device, CustomVertex.PositionNormalTextured[] verts, QuadTile child)方法利用可选择的下载索引器来渲染四叉树瓦片的某一个子瓦片,被函数bool Render(DrawArgs drawArgs)调用。

    void device_DeviceReset(object sender, EventArgs e)方法实现DirectX 3D渲染是的图形绘制设备重置。内部要调用Assembly类的虚函数GetManifestResourceStream()来载入相应的纹理效果文件并返回一个流。

  • 相关阅读:
    js创建map
    [POJ 1911] 棋盘
    [POJ 2176] Folding
    [POJ 1014] Dividing
    [洛谷P3486]POI2009 KON-Ticket Inspector
    [洛谷P1131] ZJOI2007 时态同步
    [洛谷P1133] 教主的花园
    [洛谷P1095]NOIP2007 普及组T3 守望者的逃离
    [POJ1187] 陨石的秘密
    [POJ1772] Substract
  • 原文地址:https://www.cnblogs.com/rainbow70626/p/4587721.html
Copyright © 2011-2022 走看看