版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、ArcGlobe 性能优化开发本文对 ArcGlobe/Globecontrol中的重画方法的优化提出了四种解决方案。对各自方案的提出背景及其原理进行了简短的解释,同时给出了实例,值得仔细研究!Implementation of custom layers for ArcGlobe/GlobeControl wouldprobably be done for real-time applications. Usually, such applications arerequired to match a very high standard of performance, whether it
2、 is the abilityto display thousands of elements that pertain to one data feed or updateobjects in a very high frequency.Although efficient, caching your symbol inside a display list is not alwaysenough to get the best performance. The following are the major techniques toa displaylist.optimize the d
3、rawing sequence:1、 Minimizing the computation load inside DrawImmediate2 、 Scaling and aggregating the drawn symbology3、 Screening out objects outside of the display viewport4、 Using a global timer to redraw the display一一、Minimizing the computation load inside DrawImmediate一一、Tip :1、 一个对象可能在一个绘制周期中需
4、要重画多次,如果每一次都去计算地心坐标和方向将会影响效率。2、 解决:当我们对某一个对象进行更新时,将其地心坐标和方向保存。In most cases, the layer s drawing frequency does not match theobject s update rate. An object is usually subjected to updateevery severaldrawin g cycles. For that reason, calculating the object s geocentriccoordinate and orientation only
5、 when the element gets updated significantlydecreases the computations that must be done on each drawingcycle.(引出背景)To draw the object, you will have to cache itscalculated geocentriccoordinate and orientation so it can be used inside theDrawImmediatemethod.为了去画出某个对象,你将首先保存其计算出的地心坐标及其方向,使它能够调用内部的 Dr
6、awImmediate方法。The following code shows how to minimize the computation load:C#public bool AddItem(long zipCode, double lat, double lon)double X = 0.0, Y = 0.0, Z = 0.0;. . .DataRow r = m_table.Rows.Find(zipCode);if (null != r) /If the record with this ZIP Code already exists./Cache the item s geocen
7、tric coordinate to save the calculation inside methodDrawImmediate ().globeViewUtil.GeographicToGeocentric(lon, lat, 1000.0, out X,out Y, out Z);/Update the record.r3 = lat;r4 = lon;r5 = X;r6 = Y;r7 = Z;lock (m_table)r.AcceptChanges();. . .二二、Scaling and aggregating symbols二二、Tip:1、可以通过一定方法计算每一个symb
8、ol 的当前显示scale、2、当某一个符号在当前显示小于一定比例的时候,我们将一样简单的符号如点来表示它!Usually, one of the first techniques learned in ageographic informationsystem (GIS) class for drawing spatially enabled data is to use aggregatedsymbology (as scale ratio becomes small when zooming out 可伸缩性符号 ). 3Ddrawing is no exception. However
9、, in a 3D environment, the scale constantlyvaries since there is no reference surface that can calculate ascale accordingly.Therefore, the distance from the globe s camera of each objectdetermines areference scale(.相对比例由全球幕布globe camera 的距离来决定)The distance fromthe object to the camera can be calcula
10、ted both in geographical units and ingeocentric units. (对象到全球幕布的距离在地心坐标和地理坐标下都可以计算)The following shows calculating the scale (magnitude)according to thedistance from the camera to the object using geocentric unitsand taking intoconsideration the elevation exaggeration:这个例子show 通过从幕布到对象的距离(地心坐标下)来计算放
11、大比例,同是考虑到高程的发达!C#double dblObsX, dblObsY , dblObsZ, dMagnitude;/获取当前全球幕布ICamera camera =pGlobeViewer.GlobeDisplay.ActiveViewer.Camera;/Get the camera location in a geocentric coordinate (OpenGL coordsystem).得到地心坐标系用于 OpenGL camera.Observer.QueryCoords(out dblObsX, out dblObsY); dblObsZ = camera.Obse
12、rver.Z; /QAIGlobeDisplayRendering globeDisplayRendering = IGlobeDisplayRendering)m_globeDisplay;/得到基本的起始放大点 double baseExaggeration = globeDisplayRendering.BaseExaggeration; /double X = 0.0, Y = 0.0, Z = 0.0;X = Convert.ToDouble(rec5);Y = Convert.ToDouble(rec6);Z = Convert.ToDouble(rec7);/m_ipVector
13、3D.SetComponents(dblObsX - X,dblObsY - Y ,dblObsZ - Z);/dMagnitude = m_ipVector3D.Magnitude;/double scale = dblMagnitude * baseExagFactor;/当得到的比例比较小时,可以用一个符号表示,只有到达一定比例是才在幕布上draw 一个full symbol 。Setting the scale threshold, which determines whether to draw a full symbolor an aggregated symbol is up t
14、o the developer, usually according to arequirement defined as a geographical distance. In many cases, setting thethreshold is done empirically to get the best balance between theaggregatedsymbols and the full symbol that looks best and gives the best performance. Theaggregated symbol can be any type
15、 of symbol, cached as a display list or a simpleOpenGL geometry. There is no limit to the number ofaggregated symbol levelsthat can be set to an object.The following code shows how to set the scale threshold:C#/If far away from the object, draw it as a simple OpenGL point.if(scale > 2.5)GL.gl
16、PointSize(5.0f);GL.glColor3ub(0, 255, 0);GL.glBegin(GL.GL_POINTS);GL.glVertex3f(Convert.ToSingle(X),Convert.ToSingle(Y),Convert.ToSingle(Z);GL.glEnd();else /When close enough, draw the full symbol.GL.glPushMatrix();/Translate and orient the object into place. TranslateAndRotate(X,Y , Z, wksSymbolOri
17、entation,dSymbolAngle);/Scale the object.GL.glScaled(dObjScale, dObjScale, dObjScale); /Draw the object.GL.glCallList(m_intMainSymbolDisplayList);GL.glPopMatrix();三三。Screening out objects outside the display viewport三三。Tip :1、可以计算某一个对象是否在我们的展示幕布中、2、当不在幕布中时,我们就不让他显示Drawing dynamic objects usually inv
18、olves a largeamount of computation.In addition, drawing a complex full-resolution model that contains a large amountof triangles can take a considerable amount of resources. The camera s field ofview is limited to a certain degree. Therefore, many objects get drawn despite thefact they are not visib
19、le inside the viewport. Although OpenGL will not draw theseobjects, the computation required to draw an object might be quite expensive. Forthat reason, screening out objects outside the viewport is a good practice topreserve resources and make your code more efficient.(为什么要这样做?)To screen out object
20、s, you need to convert the objectcoordinate into thewindow s coordinate and test whether it is inside the viewport.There are two waysto convert a coordinate into a window coordinate. You can usethe IGlobeViewUtilinterface to convert a coordinate from each of the other coordinate systems usedby globe
21、 (geographic or geocentric) into the window system or you can useOpenGL to convert from a geocentric coordinate into a window coordinate.(怎么去计算得到是否在当前可是窗体中)通过OpenGL 的方法从地理坐标到地心坐标的转换需要你去获取如下feed: OpenGL的投影matrix ,模型matrix ,及其视角 matrix ,这些 feed 只能在DrawImmediate 方法 ( globes custom layer 情况下)及其IGlobeDis
22、playEvents:BeforeDraw andIGlobeDisplayEvents:AfterDraw方法下才能获取。虽然,这种方法比较快速同时精度比较高并且可以用来估计外部的快速展示面,但是当你转变到选择模式下时,投影matrix 将改变同时结果将出现计算错误。所以:建议尽可能的使用model of ArcObjects 和OpenGL 模式相结合。使用方法:当OpenGL 处于选择模式下时,我们就使用 IGlobeViewUtil接口来把结果转变到窗体坐标。其他情况下通通用OpenGL 的模式。Calling OpenGL to project a coordinate from g
23、eocentricinto a windowcoordinate system requires you to get from OpenGL the projection matrix, modelmatrix, and the viewport matrix. This can only be done inside the DrawImmediatemethod (in the case of a globe IGlobeDisplayEvents:BeforeDraw and s custom layer) or insideIGlobeDisplayEvents:AfterDraw.
24、Although, using OpenGL to convert from geocentric coordinates into windowcoordinates is very fast and accurate (it also allows you to screen out objectsoutside the clipping planes), when switched into selection mode, the projectionmatrix changes and results in erroneous calculations.For that reason,
25、 it is possible to use a mixed model of ArcObjects together withOpenGL to test if an object is inside the viewport. When OpenGL is in selectionmode, use IGlobeViewUtil to convert into a window coordinateand the rest of thetime, use OpenGL.The following code shows testing an object inside the viewpor
26、t:C#private bool InsideViewport(double x, double y, double z,double clipNear,uint mode)bool inside = true;/In selection mode, the projection matrix is changed./Therefore, use the GlobeViewUtil because callinggluProject givesunexpected results.if (GL.GL_SELECT = mode)int winX, winY;m_globeViewUtil.Ge
27、ocentricToWindow(x, y, z, out winX, out winY);inside = (winX >= m_viewport0 &&winX <= m_viewport2) &&(winY >= m_viewport1 && winY <= m_viewport3);else/Use gluProject to convert into the window scoordinate.unsafedouble winx,
28、winy, winz;GLU.gluProject(x, y, z,m_modelViewMatrix,m_projMatrix,m_viewport,&winx, &winy,&winz);inside = (winx >= m_viewport0 && winx <= m_viewport2) &&(winy >= m_viewport1 && winy <= m_viewport3 &
29、;amp;&(winz >= clipNear &&winz <= 1.0);return inside;The following code filters out objects outside of theviewport:C#/Get the OpenGL matrices.GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX,m_modelViewMatrix);GL.glGetIntegerv(GL.GL_VIEWPORT, m_viewport);GL.glGetDoublev(G
30、L.GL_PROJECTION_MATRIX,m_projMatrix);/Get the OpenGL rendering mode.uint mode;unsafeint m;GL.glGetIntegerv(GL.GL_RENDER_MODE, &m);mode = (uint)m;/Get the globe s near clipping plane. The ClipNear value is requiredfor the viewport filtering(since we don t want to draw an item beyond the clipp
31、ing planes).IGlobeAdvancedOptions advOpt = m_globeDisplay.AdvancedOptions; double clipNear = advOpt.ClipNear; /Ensure the object is within the viewport.if (!InsideViewport(X, Y , Z, clipNear, mode)continue;/Continue with the drawings here. . .四四、Using a single timer to redraw the display四四、Tip:1、动态效
32、果的制作方法。使用2、及其需要注意的问题:所以的timer 来控制customer layer公用一个timerSince the data managed by a custom layer or in custom drawings is usuallydynamic, you need to constantly redraw the globe display toreflect changes tothat data. The redraw frequency should be determined by the amount of time ittakes each object
33、 to update, as well as the amount of objects that you have toaddress in the application.(引出问题,需要动态效果)Since Wind ow s operating system cannot support a true real-time application,it is usually acceptable to have a delay of a few milliseconds between the time thatan object gets updated and the time th
34、at it gets drawn in the globe display.Therefore, having a timer in your application that constantly redraws the display isusually the best solution when your data is dynamic. (解决方法:使用 timer )The timer's elapsed event通过进程池来引发,所以没有在主线程下执行。The timer's elapsed event is raised on a ThreadPool thr
35、ead. This means it is sexecuted on another thread that is not the main thread. The solution is to treat anArcObjects component like a user interface (UI) control by using the Invokemethod to delegate the call to the main thread (where the ArcObjects componentwas created) and prevent making cross apa
36、rtment calls.(原理)To support the Invoke method, your class needs to implement theISynchronizeInvoke .NET interface. Alternatively, your class can inherit from theSystem.Windows.Forms.Control .NET interface. This way, your class automaticallysupports the Invoke method. (怎么做)The following shows a class
37、 inheriting the System.Windows.Forms.Control interface:C#/Class definition.public abstract class GlobeCustomLayerBase : Control,ILayer,IGeoDataset,. . ./Class constructor.public GlobeCustomLayerBase()/Call CreateControl to create the handle.this.CreateControl();. . .The following code shows using th
38、e timer to redraw theGlobeDisplay:C#/Redraw delegate invokes the timer's event handler on the main thread.private delegate void RedrawEventHandler();/Set the layer s redraw timer.private System.Timers.Timer m_redrawTimer = null; /Initialize the redraw timer.m_redrawTimer = new System.Timers.Time
39、r(200); m_redrawTimer.Enabled = false;/Wire the timer s elapsed event handler. m_redrawTimer.Elapsed += new ElapsedEventHandler(OnRedrawUpdateTimer);/Redraw the timer s elapsedhandlerevent.private void OnRedrawUpdateTimer(object sender,ElapsedEventArgs e)/Since this is the timer s event handler, it
40、gets executedon adifferent thread than themain one. Therefore, the Invoke call is required to force the call onthe main threadand prevent cross apartment calls.if(m_bTimerIsRunning)base.Invoke(newRedrawEventHandler(OnRedrawEvent);/This method invoked by the timer s elapsed event handler andgetsexecuted on themain thread.void OnRedrawEvent()m_globeDisplay.RefreshViewers();译:另外一种可选方案是当元素更新时,在一次重新画,弊端:当对象很多是不停的重画将可能把资源全部耗掉。Another alternative is to redraw the globe display each time an
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 一年级数学计算题专项练习1000题汇编
- 2024年个人房产抵押贷款协议范本
- 文书模板-《劳务用工合同》
- 2024年度安置性质房产购买协议典范
- 2024老年专家返聘协议详细条款
- 2024年度建筑资产转让协议样例
- 2024精简型牛肉购销协议文本
- 2024年定制保证代理协议指南
- 办公用品买卖协议简化范例2024
- DB11∕T 1600-2018 萱草生产栽培技术规程
- 2023燃气工程分包合同正规版
- 20以内进位加法100题(精心整理6套-可打印A4)
- 陕西师范大学学位英语试题
- 中小学反恐风险评估报告
- 品牌营销策略和品牌策略
- 视力矫正商业计划书
- 医学课件:临床决策分析
- 幼儿园优质公开课:中班音乐韵律《打喷嚏的小老鼠》课件
- 质量管理体系品质保证体系图
- 人教版(新插图)三年级上册数学 第9课时 用乘除两步计算 解决-归总问题 教学课件
- 《现代汉语》考试复习题库及答案
评论
0/150
提交评论