




下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、ArcGlobe 性能優(yōu)化開(kāi)發(fā)中的重畫(huà)方法的優(yōu)化提本文對(duì) ArcGlobe/Globecontrol出了四種解決方案。對(duì)各 自方案的提出背景及其原理進(jìn)行了簡(jiǎn)短的解釋?zhuān)瑫r(shí)給出了 實(shí)例,值得仔細(xì)研究!Implementation of custom layers for ArcGlobe/GlobeControl would probably be done for real-time applications. Usually, such applications are required to match a very high standard of performance, whethe
2、r it is the ability to display thousands of elements that pertain to one data feed or update objects in a very high frequency.Although efficient, caching your symbol inside a display list is not always enough to get the best performance. The following are the major techniques to a display list.1、opt
3、imize the drawing sequence:Minimizing the computation load inside DrawImmediate2 、 Scaling and aggregating the drawn symbology 3、 Screening out objects outside of the display viewport 4、 Using a global timer to redraw the display、Minimizing the computation load inside DrawImmediateTip:1、個(gè)對(duì)象可能在一個(gè)繪制周期
4、中需要重畫(huà)多次,如果每次都去計(jì)算地心坐標(biāo)和方向?qū)?huì)影響效率。2、解決:當(dāng)我們對(duì)某一個(gè)對(duì)象進(jìn)行更新時(shí),將其地心坐標(biāo)和方向保存。In most cases, the layer's drawing frequency does not match theobject 's update rate. An object is usually subjected to update every several drawin g cycles. For that reason, calculating the object geocentric coordinate and orient
5、ation only when the element gets updated significantly decreases the computations that must be done on each drawing cycle.(弓出背景)To draw the object, you will have to cache itscalculated geocentric coordinate and orientation so it can be used inside theDrawImmediate method.為了去畫(huà)出某個(gè)對(duì)象,你將首先保存其計(jì)算出的地心坐標(biāo)及其方
6、向,使它能夠調(diào) 用內(nèi)部的 DrawImmediate 方法。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 i
7、tem ' s geocentric coordinate to save thecalculation 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 symbolsTip:1、可以通過(guò)一定方法
8、計(jì)算每一個(gè)symbol 的當(dāng)前顯示 scale、 2、當(dāng)某一個(gè)符號(hào)在當(dāng)前顯示小于一定比例的時(shí)候,我們將樣簡(jiǎn)單的符號(hào)如點(diǎn)來(lái)表示它!Usually, one of the first techniques learned in ageographic information system (GIS) class for drawing spatially enabled data is to use aggregated symbology (as scale ratio becomes small when zooming out 可 伸縮性符號(hào) ). 3D drawing is no exce
9、ption. However, in a 3D environment, the scale constantly varies since there is no reference surface that can calculate a's camera of each objectscale accordingly.Therefore, the distance from the globe determines a reference scale(. 相對(duì)比例由全球幕布 globe camera 的距離來(lái) 決定) The distance from the object to
10、 the camera can be calculated both in geographical units and in geocentric units. (對(duì)象到全球幕布的距離在地心坐標(biāo)和地理 坐標(biāo)下都可以計(jì)算)The following shows calculating the scale (magnitude)according to the distance from the camera to the object using geocentric unitsand taking into consideration the elevation exaggeration:這
11、個(gè)例子 show 通過(guò)從幕布到對(duì)象的距離(地心坐標(biāo)下)來(lái) 計(jì)算放大比例,同是考慮到高程的 發(fā)達(dá)!C#double dblObsX, dblObsY , dblObsZ, dMagnitude;/獲取當(dāng)前全球幕布ICamera camera = pGlobeViewer.GlobeDisplay.ActiveViewer.Camera;/Get the camera location in a geocentric coordinate (OpenGL coordsystem).得到地心坐標(biāo)系用于 OpenGL camera.Observer.QueryCoords(out dblObsX, o
12、ut dblObsY);dblObsZ = camera.Observer.Z;/QAIGlobeDisplayRendering globeDisplayRendering =IGlobeDisplayRendering)m_globeDisplay;/得到基本的起始放大點(diǎn) double baseExaggeration = globeDisplayRendering.BaseExaggeration;/double X = 0.0, Y = 0.0, Z = 0.0;X = Convert.ToDouble(rec5);Y = Convert.ToDouble(rec6);Z = Conv
13、ert.ToDouble(rec7);/ m_ipVector3D.SetComponents(dblObsX - X,dblObsY - Y, dblObsZ - Z);/ dMagnitude = m_ipVector3D.Magnitude;/ double scale = dblMagnitude * baseExagFactor;/當(dāng)?shù)玫降谋壤容^小時(shí),可以用一個(gè)符號(hào)表示,只有到達(dá)定比例是才在幕布上 draw 一個(gè)full symbol 。Setting the scale threshold, which determines whetherto draw a full symbo
14、l or an aggregated symbol is up to the developer, usually according to a requirement defined as a geographical distance. In many cases, setting the threshold is done empirically to get the best balance between theaggregated symbols and the full symbol that looks best and gives the best performance.
15、The aggregated symbol can be any type of symbol, cached as a display list or a simpleOpenGL geometry. There is no limit to the number of aggregated symbol levels that 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 O
16、penGL point.if(scale > 2.5)GL.glPointSize(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.Tr
17、anslateAndRotate(X,Y , Z, wksSymbolOrientation,dSymbolAngle);/Scale the object.GL.glScaled(dObjScale, dObjScale, dObjScale);/Draw the object.GL.glCallList(m_intMainSymbolDisplayList);GL.glPopMatrix();。 Screening out objects outside the display viewportTip:1、可以計(jì)算某一個(gè)對(duì)象是否在我們的展示幕布中、 2、當(dāng)不在幕布中時(shí),我們就不讓他顯示Dr
18、awing dynamic objects usually involves a large amount of computation.In addition, drawing a complex full-resolution model that contains a large amount of triangles can take a considerable amount of resources. The camera ' s field of view is limited to a certain degree. Therefore, many objects ge
19、t drawn despite the fact they are not visible inside the viewport. Although OpenGL will not draw these objects, the computation required to draw an object might be quite expensive. For that reason, screening out objects outside the viewport is a good practice to preserve resources and make your code
20、 more efficient.(為什么要這樣做?)To screen out objects, you need to convert the objectcoordinate into the window 's coordinate and test whether it is inside the viewport.There are two ways to convert a coordinate into a window coordinate. You can use the IGlobeViewUtil interface to convert a coordinate
21、 from each of the other coordinate systems used by globe (geographic or geocentric) into the window system or you can useOpenGL to convert from a geocentric coordinate into a window coordinate.(怎么去計(jì)算得到是否在當(dāng)前可是窗體中)通過(guò) OpenGL 的方法從地理坐標(biāo)到地心坐標(biāo)的轉(zhuǎn)換需要你去獲取如下 feed:OpenGL的投影 matrix ,模型 matrix ,及其視角 matrix ,這些 fee
22、d 只 能在 DrawImmediate 方 法 ( globe's custom layer 情況下)及其IGlobeDisplayEvents:BeforeDraw andIGlobeDisplayEvents:AfterDraw 方法下才能獲取。雖然,這 種方法比較快速同時(shí)精度比 較高并且可以用來(lái)估計(jì)外部的快速展示面,但是當(dāng)你轉(zhuǎn)變到 選擇模式下時(shí),投影 matrix 將改 變同時(shí)結(jié)果將出現(xiàn)計(jì)算錯(cuò)誤。所以:建議盡可能的使用 model of ArcObjects 和OpenGL 模式相結(jié)合。使用方法:當(dāng) OpenGL 處于選擇模式下時(shí),我們就使用 IGlobeViewUtil 接口
23、來(lái)把結(jié)果轉(zhuǎn)變到窗體坐標(biāo)。其他情況下通通用 OpenGL 的模式。Calling OpenGL to project a coordinate from geocentricinto a window coordinate system requires you to get from OpenGL the projection matrix, model matrix, and the viewport matrix. This can only be done insidethe DrawImmediatemethod (in the case of a globe's custom
24、 layer) or insideIGlobeDisplayEvents:BeforeDraw andIGlobeDisplayEvents:AfterDraw.Although, using OpenGL to convert from geocentriccoordinates into window coordinates is very fast and accurate (it also allows you to screen out objects outside the clipping planes), when switched into selection mode, t
25、he projection matrix changes and results in erroneous calculations.For that reason, it is possible to use a mixed model ofArcObjects together withOpenGL to test if an object is inside the viewport. WhenOpenGL is in selectionmode, use IGlobeViewUtil to convert into a window coordinate and the rest of
26、 the time, use OpenGL.The following code shows testing an object inside the viewport: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 callinggluPro
27、ject gives unexpected results.if (GL.GL_SELECT = mode)int winX, winY;m_globeViewUtil.GeocentricToWindow(x, y, z, outwinX, out winY);inside = (winX >= m_viewport0 &&winX <= m_viewport2) &&(winY >= m_viewport1 &&winY <= m_view
28、port3);else/Use gluProject to convert into the windowcoordinate.unsafedouble winx, winy, winz;GLU.gluProject(x, y, z,m_modelViewMatrix, m_projMatrix, m_viewport, &winx, &winy,&winz);inside = (winx >= m_viewport0 &&winx <= m_viewport2) &&a
29、mp;amp;(winy >= m_viewport1&& winy <= m_viewport3 &&(winz >= clipNear &&winz <= 1.0);return inside;The following code filters out objects outside of the viewport: C# /Get the OpenGL matrices.GL.glGetDoublev(GL.GL_MODELVIEW_M
30、ATRIX, m_modelViewMatrix);GL.glGetIntegerv(GL.GL_VIEWPORT, m_viewport);GL.glGetDoublev(GL.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 val
31、ue is required for the viewport filtering (since we don 't want to draw an item beyond the clipping planes).IGlobeAdvancedOptions advOpt = m_globeDisplay.AdvancedOptions;double clipNear = advOpt.ClipNear;/Ensure the object is within the viewport.if (!InsideViewport(X, Y , Z, clipNear, mode)conti
32、nue;/Continue with the drawings here.四四、 Using a single timer to redraw the display四四、Tip:1、動(dòng)態(tài)效果的制作方法。使用timer 來(lái)控制2、及其需要注意的問(wèn)題:所以的customer layer 公用一個(gè)timerSince the data managed by a custom layer or in customdrawings is usually dynamic, you need to constantly redraw the globe display toreflect changes
33、to that data. The redraw frequency should be determined by the amount of time it takes each object to update, as well as the amount of objects that you have to address in the application. (引出問(wèn)題,需要?jiǎng)討B(tài)效果)Since Wind ow' s operating system cannot support a truereal-time application, it is usually acc
34、eptable to have a delay of a few milliseconds between the time that an object gets updated and the time that it gets drawn in the globe display.Therefore, having a timer in your application that constantly解決方所以沒(méi)有redraws the display is usually the best solution when your data is dynamic.法:使用 timer )T
35、he timer's elapsed event 通過(guò)進(jìn)程池來(lái)引發(fā),在主線程下執(zhí)行。The timer's elapsed event is raised on a ThreadPoolthread. This means it isexecuted 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 Invoke method to delega
36、te the call to the main thread (where theArcObjects component was created) and prevent making cross apartment calls.(原理)To support the Invoke method, your class needs toimplement theISynchronizeInvoke .NET interface. Alternatively, your class can inherit from theSystem.Windows.Forms.Control .NET int
37、erface. This way, your class automatically supports the Invoke method. (怎么做)The following shows a class inheriting theSystem.Windows.Forms.Control interface:C#/Class definition.public abstract class GlobeCustomLayerBase : Control,ILayer,IGeoDataset,/Class constructor.public GlobeCustomLayerBase()/Ca
38、ll CreateControl to create the handle.this.CreateControl();The following code shows using the 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.Ti
39、mer m_redrawTimer = null;/Initialize the redraw timer.m_redrawTimer = new System.Timers.Timer(200);/Wire the timerm_redrawTimer.Enabled = false;'s elapsed event handler.m_redrawTimer.Elapsed += newElapsedEventHandler(OnRedrawUpdateTimer);/Redraw the timer's elapsehdaenvdelenrt.private void O
40、nRedrawUpdateTimer(object sender,ElapsedEventArgs e)/Since this is the timer' s event handler, it gets executedon a different thread than the main one. Therefore, the Invoke call is required to force the call on the main thread and prevent cross apartment calls.if(m_bTimerIsRunning)base.Invoke(newRedrawEventHandler(OnRedrawEvent);/This method invoked by the timer's elapsed event handler andgets executed on the main thread.void OnRedrawEvent()m_globeDisplay.RefreshViewers();譯: 另外一種可選方案是當(dāng)元素更新時(shí),在一次重新畫(huà),弊端:當(dāng)對(duì)象很多是不停的重畫(huà)將可能把資源全部耗掉。Another alternative is to redraw the globe display e
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 每周少先隊(duì)活動(dòng)方案
- 汽車(chē)區(qū)域活動(dòng)策劃方案
- 歌唱青春活動(dòng)方案
- 毛筆公司活動(dòng)策劃方案
- 氣球編織活動(dòng)策劃方案
- 植樹(shù)及聯(lián)誼活動(dòng)方案
- 漢堡派對(duì)活動(dòng)策劃方案
- 愛(ài)心課件與教案
- 愛(ài)學(xué)校班會(huì)課件
- PFC模擬采場(chǎng)破壞特征與裂隙分布規(guī)律探究
- 市場(chǎng)監(jiān)管新進(jìn)人員培訓(xùn)方案
- BIM基礎(chǔ)知識(shí)培訓(xùn)課件
- 照排人員述職報(bào)告
- 淘寶客服月度工作報(bào)表表格
- 卷材防水層分項(xiàng)工程質(zhì)量檢驗(yàn)評(píng)定表
- 租賃機(jī)械設(shè)備施工方案
- 中建施工現(xiàn)場(chǎng)CI規(guī)范說(shuō)明詳細(xì)
- 鄉(xiāng)鎮(zhèn)衛(wèi)生院組織架構(gòu)圖
- 第九講 全面依法治國(guó)PPT習(xí)概論2023優(yōu)化版教學(xué)課件
- 川16Z117-TY 彩色透水混凝土整體路面構(gòu)造圖集
- 《重慶市建設(shè)工程費(fèi)用定額》電子版
評(píng)論
0/150
提交評(píng)論