Two methods for creating a 3D pipeline in Skyline (C #)
The skyline software mainly includes TerraBuilder, TerraExplorer, and TerraGate. TerraBuilder uses images and dem to generate terrain and make it into a three-dimensional Earth or a three-dimensional plane. TerraExplorer is used for editing and browsing (key part). TerraGate is mainly used for network functions. In other words, Terrabuilder is the data production source, and TerraExplorer is the data visualization window.
(1) Secondary Development Preparation
Open vs2010, right-click the toolbar, add a tab, create a skyline control group, create a group, right-click it, and select an item.
Add com components related to skyline
After adding the widget, you will get the following control:
TE3DWindow is a three-dimensional window, TEInformationWindow is a tree Information Directory window, And TENavigationMap is an eagleeye window.
(2) pipeline generation
// Interface Usage
TECoClass = new TerraExplorerClass ();
MTerraExplorer = (ITerraExplorer5) TECoClass;
MPlane = (IPlane5) TECoClass;
MNavigation = (ITENavigationMap5) TECoClass;
MRender = (IRender5) TECoClass;
MMenue = (IMenu) TECoClass;
MObjectManager = (IObjectManager5) TECoClass;
MInformationTee = (IInformationTree5) TECoClass;
// Load the 3D ball
MTerraExplorer. LoadEx (@ "C: \ globe. fly", "", "", 0); // or mpt file, which can be generated using Terrabuilder.
There are two main ways to generate the Pipeline Code:
1. single pipe segment
Int iGround = mInformationTee. CreateGroup ("Pipeline", 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;
}
// Here is the code for creating 3Dobject, creating a cylinder, You can map, enter the coordinates of one end, pipe diameter, pipe length, cylindrical shape approaching the number of sides of the polygon, etc.
MTerra3DRegbase = mObjectManager. CreateCylinder (x1, y1, z1, pipeRadius, pipeLength, segmentNum, lineColor, fillOpacity, fillColor, HeightStyleCode. encode, iGround ,"");
MTerra3DRegbase. SetPosition (x1, y1, z1, finYaw, 90-( double) oPitch, 0.0, 7 );
}
2. the advantage of adding layers is that layers are managed in groups. There are many display types of layers, such as spherical, cylindrical, and 3D models at each point, you can change the attributes of a layer.
// Create a layer Group
Int iGround = mInformationTee. CreateGroup ("pipeline 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 ();
// Create featurelayer
ILayer6 CylindresLayer = sgworld. creator. createNewFeatureLayer ("first pipeline section", LayerGeometryType. LGT_POINT, "FileName = pipes" + DateTime. now. day + ". shp; TEPlugName = OGR; ", iGround );
// Sdsdsd. Streaming = false;
// Edit the layer attribute. It is similar to setting the field attribute in the shp file. Each vertex can get a different value and assign it to the attribute of the layer.
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;
// Edit the attribute, as shown in figure
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 ops", 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]");
// Create a pipe segment peripheral
ILayer6 SpheresLayer = sgworld. creator. createNewFeatureLayer ("pipe segment connection", LayerGeometryType. LGT_POINT, "FileName = connectors" + DateTime. now. day + ". shp; TEPlugName = OGR; ", iGround );
// SpheresLayer. Streaming= False;
SpheresLayer. Refresh ();
SpheresLayer. performanceinfo. Attributes. CreateAttribute ("Yaw", AttributeTypeCode. AT_DOUBLE, 0 );
SpheresLayer. performanceinfo. Attributes. CreateAttribute ("Pitch", AttributeTypeCode. AT_DOUBLE, 0 );
SpheresLayer. performanceinfo. 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 ());
// Create a point
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 );
// Draw a pipe segment
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 );
// Tube end peripheral
Var radius1 = piperadus * 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 );
// Draw a connection bend (ball instead) and place it if there is a connection
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 ();
Similarly, load a 3D model:
Note that after the mpt is loaded, the pipeline cannot be displayed when it is loaded as a layer. It can only be seen on the basis of the fly file.