程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Skyline創建三維管線兩種方式(C#)

Skyline創建三維管線兩種方式(C#)

編輯:C#入門知識

Skyline創建三維管線兩種方式(C#)


先簡單說一說skyline軟件的系統,skyline軟件主要有TerraBuilder,TerraExplorer以及TerraGate。TerraBuilder主要是采用圖像,dem等生成地形,制作成三維地球或三維平面;TerraExplorer的功能是編輯和浏覽(關鍵部分);TerraGate主要是網絡功能。換句話說,Terrabuilder是數據制作源,TerraExplorer是數據可視化窗口。

(一)二次開發准備

打開vs2010,在工具欄處右鍵,添加選項卡,建立skyline控件組,在建好的組內,右鍵選擇項

\

添加skyline有關的com組件

\

添加完成後,將會得到如下控件:

\

 

TE3DWindow是三維浏覽窗口,TEInformationWindow是樹信息目錄窗口,TENavigationMap是鷹眼窗口。

(二)管線生成

//接口的使用

TECoClass = new TerraExplorerClass();

mTerraExplorer = (ITerraExplorer5)TECoClass;

mPlane = (IPlane5)TECoClass;

mNavigation = (ITENavigationMap5)TECoClass;

mRender = (IRender5)TECoClass;

mMenue = (IMenu)TECoClass;

mObjectManager = (IObjectManager5)TECoClass;

mInformationTee = (IInformationTree5)TECoClass;

//加載三維球

mTerraExplorer.LoadEx(@"C:\globe.fly", "", "", 0);//或者mpt文件,可以使用Terrabuilder生成。



管線繪制的代碼生成主要有兩種方式:

1.單管段

int iGround = mInformationTee.CreateGroup("管線", 0);

 

double x1 = 0, y1 = 0, z1 = 0, x2, y2, z2;

double pipeLength;

double fillOpacity = 0.7;

double pipeRadius = 2;

object oYaw, oPitch;

double finYaw;

while (sdr.Read())

{

x1 = Convert.ToDouble(sdr["x1"].ToString());

y1 = Convert.ToDouble(sdr["y1"].ToString());

z1 = Convert.ToDouble(sdr["z1"].ToString());

x2 = Convert.ToDouble(sdr["x2"].ToString());

y2 = Convert.ToDouble(sdr["y2"].ToString());

z2 = Convert.ToDouble(sdr["z2"].ToString());

pipeLength = mCoordSys.GetDistanceEx(x1, y1, z1, x2, y2, z2);

mCoordSys.GetAimingAngles(x1, y1, z1, x2, y2, z2, out oYaw, out oPitch);

if ((double)oYaw < 180)

{

finYaw = (double)oYaw + 180;

}

else

{

finYaw = (double)oYaw - 180;

}

//這裡是創建3Dobject的代碼,創建圓柱體,可以進行貼圖,輸入一端的坐標,管徑,管長度,圓柱形狀逼近多邊形的邊數等

mTerra3DRegbase = mObjectManager.CreateCylinder(x1, y1, z1, pipeRadius, pipeLength, segmentNum, lineColor, fillOpacity, fillColor, HeightStyleCode.HSC_TERRAIN_ABSOLUTE, iGround, "");

mTerra3DRegbase.SetPosition(x1, y1, z1, finYaw, 90 - (double)oPitch, 0.0, 7);

}

\

2.以圖層方式添加,優勢在於成組進行圖層管理,圖層的顯示類型有很多種類,比如每個點位顯示球形,圓柱形,3D模型等等,圖層的屬性中可以進行一定的更改。

\

//創建圖層組

int iGround = mInformationTee.CreateGroup("管線layer", 0); ;

double x1 = 0, y1 = 0, z1 = 0;

double x2 = 0, y2 = 0, z2 = 0;

double pipeLength;

double pipeRadius = 2;

List Aname = new List();

IPosition6 currCoord, nextCoord;

SGWorld sgworld = new SGWorld();

//創建featurelayer

ILayer6 CylindresLayer = sgworld.Creator.CreateNewFeatureLayer("第一管線段", LayerGeometryType.LGT_POINT, "FileName=pipes" + DateTime.Now.Day + ".shp;TEPlugName=OGR;", iGround);

//sdsdsd.Streaming = false;

//編輯layer屬性,類似於在shp文件中設置字段屬性,每一個點可以取得不同的值,再將其賦值給圖層的屬性中

CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Yaw", AttributeTypeCode.AT_DOUBLE, 0);

CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Pitch", AttributeTypeCode.AT_DOUBLE, 0);

CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Roll", AttributeTypeCode.AT_DOUBLE, 0);

CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Texture", AttributeTypeCode.AT_TEXT, 1024);

CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Rotate", AttributeTypeCode.AT_DOUBLE, 100);

CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("RadiusX", AttributeTypeCode.AT_DOUBLE, 0);

CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Height", AttributeTypeCode.AT_DOUBLE, 0);

CylindresLayer.Visibility.MaxVisibilityDistance = 5000;

//編輯屬性對應,如上圖

CylindresLayer.FeatureGroups.Point.DisplayAs = ObjectTypeCode.OT_CYLINDER;

CylindresLayer.FeatureGroups.Point.SetProperty("Number of sides", 16);

CylindresLayer.FeatureGroups.Point.SetProperty("Line Opacity", 0);

CylindresLayer.FeatureGroups.Point.SetProperty("Fill Opacity", 100);

CylindresLayer.FeatureGroups.Point.SetProperty("Yaw", "[Yaw]");

CylindresLayer.FeatureGroups.Point.SetProperty("Roll", "[Roll]");

CylindresLayer.FeatureGroups.Point.SetProperty("Pitch", "[Pitch]");

CylindresLayer.FeatureGroups.Point.SetProperty("Texture File", "[Texture]");

CylindresLayer.FeatureGroups.Point.SetProperty("Rotate", "[Rotate]");

CylindresLayer.FeatureGroups.Point.SetProperty("Radius X", "[RadiusX]");

CylindresLayer.FeatureGroups.Point.SetProperty("Height", "[Height]");

//創建管段端外圍

ILayer6 SpheresLayer = sgworld.Creator.CreateNewFeatureLayer("管段連接", LayerGeometryType.LGT_POINT, "FileName=connectors" + DateTime.Now.Day + ".shp;TEPlugName=OGR;", iGround);

//SpheresLayer.Streaming= false;

SpheresLayer.Refresh();

SpheresLayer.DataSourceInfo.Attributes.CreateAttribute("Yaw", AttributeTypeCode.AT_DOUBLE, 0);

SpheresLayer.DataSourceInfo.Attributes.CreateAttribute("Pitch", AttributeTypeCode.AT_DOUBLE, 0);

SpheresLayer.DataSourceInfo.Attributes.CreateAttribute("Roll", AttributeTypeCode.AT_DOUBLE, 0);

SpheresLayer.FeatureGroups.Point.DisplayAs = ObjectTypeCode.OT_SPHERE;

SpheresLayer.FeatureGroups.Point.SetProperty("Yaw", "[Yaw]");

SpheresLayer.FeatureGroups.Point.SetProperty("Roll", "[Roll]");

SpheresLayer.FeatureGroups.Point.SetProperty("Pitch", "[Pitch]");

SpheresLayer.FeatureGroups.Point.SetProperty("Segment density", 16);

SpheresLayer.FeatureGroups.Point.SetProperty("Line Opacity", 0);

SpheresLayer.FeatureGroups.Point.SetProperty("Fill Opacity", 100);

SpheresLayer.FeatureGroups.Point.SetProperty("Radius", pipeRadius);

SpheresLayer.FeatureGroups.Point.SetProperty("Texture File", Application.StartupPath+@"\pipeTextureCyan2.bmp");

SpheresLayer.Visibility.MaxVisibilityDistance = 5000;

while (sdr.Read())

{

x1 = Convert.ToDouble(sdr["x1"].ToString());

y1 = Convert.ToDouble(sdr["y1"].ToString());

z1 = Convert.ToDouble(sdr["z1"].ToString());

x2 = Convert.ToDouble(sdr["x2"].ToString());

y2 = Convert.ToDouble(sdr["y2"].ToString());

z2 = Convert.ToDouble(sdr["z2"].ToString());

//創建點位

currCoord = sgworld.Creator.CreatePosition(x1, y1, z1);

nextCoord = sgworld.Creator.CreatePosition(x2, y2, z2);

currCoord = currCoord.AimTo(nextCoord);

currCoord.ChangeAltitudeType(AltitudeTypeCode.ATC_TERRAIN_RELATIVE); // Relative to terrain

pipeLength = currCoord.DistanceTo(nextCoord);

//管段繪制

var pitch = -90 + currCoord.Pitch;

CylindresLayer.FeatureGroups.Point.CreateFeature(new double[] { currCoord.X, currCoord.Y, currCoord.Altitude }, currCoord.Yaw + ";" + pitch + ";" + currCoord.Roll + ";" + texture + ";" + FixTextureAngle(pitch, 16) + ";" + pipeRadius + ";" + pipeLength);

//管端外圍

var radius1 = pipeRadius * 1.1;

CylindresLayer.FeatureGroups.Point.CreateFeature(new double[] { currCoord.X, currCoord.Y, currCoord.Altitude }, currCoord.Yaw + ";" + pitch + ";" + currCoord.Roll + ";" + Application.StartupPath+@"\pipeTextureCyan.bmp" + ";" + FixTextureAngle(pitch, 16) + ";" + radius1 + ";" + radius1);

CylindresLayer.FeatureGroups.Point.CreateFeature(new double[] { nextCoord.X, nextCoord.Y, nextCoord.Altitude }, (180 + currCoord.Yaw) + ";" + pitch + ";" + currCoord.Roll + ";" + Application.StartupPath+@"\pipeTextureCyan.bmp" + ";" + FixTextureAngle(pitch, 16) + ";" + radius1 + ";" + radius1);

//繪制連接彎管(球代替),判斷有連接則放置

string a1 = sdr["A1"].ToString();

string a2 = sdr["A2"].ToString();

if (Aname.Contains(a1))

{

currCoord.Altitude -= pipeRadius;

SpheresLayer.FeatureGroups.Point.CreateFeature(new double[] { currCoord.X, currCoord.Y, currCoord.Altitude }, currCoord.Yaw + ";" + currCoord.Pitch + ";" + currCoord.Roll);

Aname.Remove(a1);

}

else

{

Aname.Add(a1);

}

if (Aname.Contains(a2))

{

nextCoord.Altitude -= pipeRadius;

SpheresLayer.FeatureGroups.Point.CreateFeature(new double[] { nextCoord.X, nextCoord.Y, nextCoord.Altitude }, nextCoord.Yaw + ";" + nextCoord.Pitch + ";" + nextCoord.Roll);

Aname.Remove(a2);

}

else

{

Aname.Add(a2);

}

}

CylindresLayer.Save();

SpheresLayer.Save();

\

類似的,加載三維模型:

\

需要注意的是,在加載mpt之後,以圖層方式加載管線顯示不出來,只有在fly文件基礎上才能看到。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved