示例#1
0
        public override bool Draw(out IModelPoint mp, out IModel fmodel, out IModel smodel)
        {
            int            index      = -1;
            IDrawPrimitive primitive  = null;
            IDoubleArray   vArray     = null;
            IUInt16Array   indexArray = null;
            IFloatArray    array3     = null;
            IDoubleArray   norms      = null;

            base.Draw(out mp, out fmodel, out smodel);
            try
            {
                object renderInfo = (base._renderType == RenderType.Texture) ? ((object)base._tcNames) : ((object)base._colors);
                int[]  numArray   = new int[2];
                numArray[1] = 1;
                if (!base.NewEmptyModel(numArray, base._renderType, renderInfo, out fmodel))
                {
                    return(false);
                }
                primitive = fmodel.GetGroup(0).GetPrimitive(0);
                if (DrawGeometry.ConvertPolygon(base._vtx, 0.0, 0, out vArray, out indexArray, out array3, out norms))
                {
                    for (index = 0; index < vArray.Length; index++)
                    {
                        primitive.VertexArray.Append((float)vArray.Array[index]);
                    }
                    for (index = 0; index < indexArray.Length; index++)
                    {
                        primitive.IndexArray.Append(indexArray.Array[index]);
                    }
                    double naN = double.NaN;
                    double ty  = double.NaN;
                    for (index = 0; index < (vArray.Length / 3); index++)
                    {
                        base.GetTexcoord(vArray.Array[index * 3], vArray.Array[(index * 3) + 1], out naN, out ty);
                        primitive.TexcoordArray.Append((float)naN);
                        primitive.TexcoordArray.Append((float)ty);
                    }
                    for (index = 0; index < norms.Length; index++)
                    {
                        primitive.NormalArray.Append((float)norms.Array[index]);
                    }
                }
                primitive = fmodel.GetGroup(0).GetPrimitive(1);
                if (DrawGeometry.ConvertPolygon(base._vtx, -this._depth, 1, out vArray, out indexArray, out array3, out norms))
                {
                    for (index = 0; index < vArray.Length; index++)
                    {
                        primitive.VertexArray.Append((float)vArray.Array[index]);
                    }
                    for (index = 0; index < indexArray.Length; index++)
                    {
                        primitive.IndexArray.Append(indexArray.Array[index]);
                    }
                    for (index = 0; index < (vArray.Length / 3); index++)
                    {
                        float num2 = (float)vArray.Array[index * 3];
                        primitive.TexcoordArray.Append(num2);
                        num2 = (float)vArray.Array[(index * 3) + 1];
                        primitive.TexcoordArray.Append(num2);
                    }
                    for (index = 0; index < norms.Length; index++)
                    {
                        primitive.NormalArray.Append((float)norms.Array[index]);
                    }
                }
                int           num5 = base._vtx.Length / 2;
                List <ushort> list = new List <ushort>();
                for (index = 0; index < num5; index++)
                {
                    primitive.VertexArray.Append((float)base._vtx[index * 2]);
                    primitive.VertexArray.Append((float)base._vtx[(index * 2) + 1]);
                    primitive.VertexArray.Append(0f);
                    list.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                    primitive.VertexArray.Append((float)base._vtx[index * 2]);
                    primitive.VertexArray.Append((float)base._vtx[(index * 2) + 1]);
                    primitive.VertexArray.Append(-((float)this._depth));
                    list.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                    primitive.TexcoordArray.Append((index * 4f) / ((float)(num5 - 1)));
                    primitive.TexcoordArray.Append(0f);
                    primitive.TexcoordArray.Append((index * 4f) / ((float)(num5 - 1)));
                    primitive.TexcoordArray.Append((float)this._depth);
                    primitive.NormalArray.Append((float)Math.Sin((6.2831853071795862 * index) / 24.0));
                    primitive.NormalArray.Append((float)Math.Cos((6.2831853071795862 * index) / 24.0));
                    primitive.NormalArray.Append(0f);
                    primitive.NormalArray.Append((float)Math.Sin((6.2831853071795862 * index) / 24.0));
                    primitive.NormalArray.Append((float)Math.Cos((6.2831853071795862 * index) / 24.0));
                    primitive.NormalArray.Append(0f);
                }
                for (index = 0; index < (num5 - 1); index++)
                {
                    primitive.IndexArray.Append(list[index * 2]);
                    primitive.IndexArray.Append(list[((index + 1) * 2) + 1]);
                    primitive.IndexArray.Append(list[(index * 2) + 1]);
                    primitive.IndexArray.Append(list[index * 2]);
                    primitive.IndexArray.Append(list[(index + 1) * 2]);
                    primitive.IndexArray.Append(list[((index + 1) * 2) + 1]);
                }
                return(true);
            }
            catch (Exception exception)
            {
                return(false);
            }
        }
示例#2
0
        public static bool ConvertPolygon(double[] vtx, double height, int flag, out IDoubleArray VArray, out IUInt16Array IndexArray, out IFloatArray TextureArrayU1V1, out IDoubleArray Norms)
        {
            bool flag2;

            VArray           = new DoubleArrayClass();
            IndexArray       = new UInt16ArrayClass();
            TextureArrayU1V1 = new FloatArrayClass();
            IFloatArray array = null;

            Norms = new DoubleArrayClass();
            IPolygon polygon = null;
            ITriMesh o       = null;

            try
            {
                if (((vtx == null) || ((vtx.Length % 2) != 0)) || (vtx.Length < 8))
                {
                    return(false);
                }
                polygon = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                if (polygon == null)
                {
                    return(false);
                }
                int num = vtx.Length / 2;
                for (int i = 0; i < num; i++)
                {
                    IPoint pointValue = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                    if (flag == 1)
                    {
                        pointValue.X = vtx[i * 2];
                        pointValue.Y = vtx[(i * 2) + 1];
                        pointValue.Z = height;
                    }
                    else
                    {
                        pointValue.X = vtx[((num - i) - 1) * 2];
                        pointValue.Y = vtx[(((num - i) - 1) * 2) + 1];
                        pointValue.Z = height;
                    }
                    polygon.ExteriorRing.AppendPoint(pointValue);
                }
                if (!polygon.IsClosed)
                {
                    polygon.Close();
                }
                o = geoConvertor.PolygonToTriMesh(polygon);
                if (o == null)
                {
                    return(false);
                }
                if (!o.BatchExport(ref VArray, ref IndexArray, ref TextureArrayU1V1, ref array, ref Norms))
                {
                    return(false);
                }
                flag2 = true;
            }
            catch (Exception)
            {
                flag2 = false;
            }
            finally
            {
                if (polygon != null)
                {
                    Marshal.ReleaseComObject(polygon);
                }
                if (o != null)
                {
                    Marshal.ReleaseComObject(o);
                }
            }
            return(flag2);
        }
示例#3
0
        public override bool Draw(out IModelPoint mp, out IModel fmodel, out IModel smodel)
        {
            int            index      = -1;
            IDrawPrimitive primitive  = null;
            IDoubleArray   vArray     = null;
            IUInt16Array   indexArray = null;
            IFloatArray    array3     = null;
            IDoubleArray   norms      = null;

            base.Draw(out mp, out fmodel, out smodel);
            try
            {
                object renderInfo = (base._renderType == RenderType.Texture) ? ((object)base._tcNames) : ((object)base._colors);
                int[]  numArray   = new int[2];
                numArray[1] = 1;
                if (!base.NewEmptyModel(numArray, base._renderType, renderInfo, out fmodel))
                {
                    return(false);
                }
                //绘制底部
                primitive = fmodel.GetGroup(0).GetPrimitive(0);
                if (DrawGeometry.ConvertPolygon(this._vtx2, 0.0, 0, out vArray, out indexArray, out array3, out norms))
                {
                    for (index = 0; index < vArray.Length; index++)
                    {
                        primitive.VertexArray.Append((float)vArray.Array[index]);
                    }
                    for (index = 0; index < indexArray.Length; index++)
                    {
                        primitive.IndexArray.Append(indexArray.Array[index]);
                    }
                    for (index = 0; index < (vArray.Length / 3); index++)
                    {
                        float num2 = (float)vArray.Array[index * 3];
                        primitive.TexcoordArray.Append(num2);
                        num2 = (float)vArray.Array[(index * 3) + 1];
                        primitive.TexcoordArray.Append(num2);
                    }
                    for (index = 0; index < norms.Length; index++)
                    {
                        primitive.NormalArray.Append((float)norms.Array[index]);
                    }
                }
                double        num3 = 0.0;
                int           num4 = base._vtx.Length / 2;
                List <ushort> list = new List <ushort>();
                primitive = fmodel.GetGroup(0).GetPrimitive(1);
                for (index = 0; index < num4; index++)
                {
                    primitive.VertexArray.Append((float)base._vtx[index * 2]);
                    primitive.VertexArray.Append((float)base._vtx[(index * 2) + 1]);
                    primitive.VertexArray.Append((float)(this._terrainLine[index] - base._hBottom));
                    list.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                    primitive.VertexArray.Append((float)this._vtx2[index * 2]);
                    primitive.VertexArray.Append((float)this._vtx2[(index * 2) + 1]);
                    primitive.VertexArray.Append(0f);
                    list.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                    num3 = (index == 0) ? num3 : (num3 += this._segLenth[index - 1]);
                    primitive.TexcoordArray.Append((float)num3);
                    primitive.TexcoordArray.Append((float)(this._terrainLine[index] - base._hBottom));
                    primitive.TexcoordArray.Append((float)num3);
                    primitive.TexcoordArray.Append(0f);
                    IVector3 vector = new Vector3Class
                    {
                        X = base._vtx[index * 2],
                        Y = base._vtx[(index * 2) + 1],
                        Z = 0.0
                    };
                    vector.Normalize();
                    primitive.NormalArray.Append((float)vector.X);
                    primitive.NormalArray.Append((float)vector.Y);
                    primitive.NormalArray.Append((float)vector.Z);
                    //工程开挖挖洞效果贴图模型出错,添加法向量数组,使其与顶点数组数量一致
                    primitive.NormalArray.Append((float)vector.X);
                    primitive.NormalArray.Append((float)vector.Y);
                    primitive.NormalArray.Append((float)vector.Z);
                }
                for (index = 0; index < (num4 - 1); index++)
                {
                    primitive.IndexArray.Append(list[index * 2]);
                    primitive.IndexArray.Append(list[(index * 2) + 1]);
                    primitive.IndexArray.Append(list[((index + 1) * 2) + 1]);
                    primitive.IndexArray.Append(list[index * 2]);
                    primitive.IndexArray.Append(list[((index + 1) * 2) + 1]);
                    primitive.IndexArray.Append(list[(index + 1) * 2]);
                }
                return(true);
            }
            catch (Exception exception)
            {
                return(false);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                         new esriLicenseExtensionCode[] { });

            Dictionary <string, Vertex> nodeDict = new Dictionary <string, Vertex>();
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            IWorkspace        workspace        = workspaceFactory.OpenFromFile(@"C:\Users\hellocomrade\NHDPlusV21_GL_04.gdb", 0);
            IFeatureWorkspace iFtrWs           = workspace as IFeatureWorkspace;

            if (null != iFtrWs)
            {
                IFeatureClass fcLine  = iFtrWs.OpenFeatureClass("NHD_Flowline");
                IFeatureClass fcPoint = iFtrWs.OpenFeatureClass("Hydro_Net_Junctions");
                System.Diagnostics.Debug.Assert(null != fcLine && null != fcPoint);

                var fldLst = new List <string> {
                    "OBJECTID", "FlowDir", "FTYPE", "V0001E_MA", "V0001E_MM", "V0001E_01", "V0001E_02", "V0001E_03", "V0001E_04", "V0001E_05", "V0001E_06", "V0001E_07", "V0001E_08", "V0001E_09", "V0001E_10", "V0001E_11", "V0001E_12"
                };
                Dictionary <string, int> fldDict = new Dictionary <string, int>();
                fldLst.ForEach(fldName => fldDict.Add(fldName, fcLine.FindField(fldName)));

                int lineFtrId = -1;
                //Find field index for oid in Hydro_Net_Junctions feature class
                int    pntFtrIdIdx = fcPoint.FindField("OBJECTID");
                string pntFtrId    = null;

                /*
                 * It has been observed that the most time consuming part of this script is on spatial query.
                 * We could take the same approach we had on Arcpy through fcLine.Search() with a spatial filter.
                 * However, it will make us have the same granularity as using arcpy.
                 * Instead, we took a different route here by using IFeatureIndex and IIndexQuery2
                 */
                IGeoDataset       geoLineDS = (IGeoDataset)fcLine;
                ISpatialReference srLine    = geoLineDS.SpatialReference;
                IFeatureIndex     lineIdx   = new FeatureIndexClass();
                lineIdx.FeatureClass = fcLine;
                lineIdx.Index(null, geoLineDS.Extent);
                IIndexQuery2 queryLineByIdx = lineIdx as IIndexQuery2;

                IFeatureIndex pointIdx = new FeatureIndexClass();
                pointIdx.FeatureClass = fcPoint;
                pointIdx.Index(null, ((IGeoDataset)fcPoint).Extent);
                IIndexQuery2 queryPointByIdx = pointIdx as IIndexQuery2;

                //Get a cursor on Hydro_Net_Junctions as the iterator
                IFeatureCursor pntCur        = fcPoint.Search(null, false);
                IFeature       pnt           = pntCur.NextFeature();
                IFeature       line          = null;
                IFeature       otherPnt      = null;
                List <string>  requiredTypes = new List <string> {
                    "StreamRiver", "ArtificialPath"
                };

                /*
                 * ITopologicalOpeartor is good for two geometries comparing with each other. It doesn't fit
                 * very well for our situation, which check the geometric relationships between a geometry
                 * against a feature class that may have more than 100K geometries.
                 */
                //ITopologicalOperator optor = null;

                /*
                 * It's a shame that we have to reference to a Server API in order to calcuate Geodesic
                 * distances for a polyline with lon/lat as coordinates.
                 *
                 * We could do Haversine ourselves, but we have to believe ESRI could definitely does a
                 * better job there, well, hard to figure out how to get this simple task done in an intutive
                 * way though...
                 */
                IGeometryServer2 geoOperator = new GeometryServerClass();

                IPolyline             polyLine = null;
                List <DownstreamNode> dsLst    = null;
                int[]         lineIds          = null;
                int[]         pntIds           = null;
                object        idobjs;
                object        idobjs1;
                PolylineArray tmpArr   = null;
                IDoubleArray  lengths  = null;
                double        lineLen  = 0.0;
                double        v        = 0.0;
                ILinearUnit   unit     = new LinearUnitClass();
                var           range    = Enumerable.Range(3, 14);
                int           count    = 0;
                int           incoming = 0;
                while (null != pnt)
                {
                    //get ftr id of the current vertex
                    pntFtrId = pnt.get_Value(pntFtrIdIdx).ToString();
                    //optor = pnt.Shape as ITopologicalOperator;

                    /*
                     * This should return feature ids that interects with the given geometry in the feature
                     * class having the index built.
                     */
                    queryLineByIdx.IntersectedFeatures(pnt.Shape, out idobjs);
                    lineIds = idobjs as int[];
                    if (null != lineIds && lineIds.Length > 0)
                    {
                        foreach (int id in lineIds)
                        {
                            line      = fcLine.GetFeature(id);
                            lineFtrId = int.Parse(line.get_Value(fldDict["OBJECTID"]).ToString());
                            if ("1" == line.get_Value(fldDict["FlowDir"]).ToString() && true == requiredTypes.Contains(line.get_Value(fldDict["FTYPE"]).ToString()))
                            {
                                polyLine = line.Shape as IPolyline;
                                if (isSamePoint(polyLine.FromPoint, pnt.Shape as IPoint))
                                {
                                    queryPointByIdx.IntersectedFeatures(line.Shape, out idobjs1);
                                    pntIds = idobjs1 as int[];
                                    if (null != pntIds && 2 == pntIds.Length)
                                    {
                                        foreach (int pid in pntIds)
                                        {
                                            otherPnt = fcPoint.GetFeature(pid);
                                            if (false == isSamePoint(otherPnt.Shape as IPoint, pnt.Shape as IPoint))
                                            {
                                                tmpArr = new PolylineArrayClass();
                                                tmpArr.Add(polyLine);
                                                lengths = geoOperator.GetLengthsGeodesic(srLine, tmpArr as IPolylineArray, unit);
                                                if (0 == lengths.Count)
                                                {
                                                    continue;
                                                }
                                                lineLen = lengths.get_Element(0) * 3.28084;
                                                //var velos = from idx in range select double.Parse(line.get_Value(fldDict[fldLst[idx]]).ToString());
                                                List <double> velos = new List <double>();
                                                foreach (int idx in range)
                                                {
                                                    v = double.Parse(line.get_Value(fldDict[fldLst[idx]]).ToString());
                                                    velos.Add(v == 0 ? 0 : lineLen / v);
                                                }
                                                if (null == dsLst)
                                                {
                                                    dsLst = new List <DownstreamNode>();
                                                }
                                                dsLst.Add(new DownstreamNode(pid, id, velos));
                                            }
                                        }
                                    }
                                }
                                else // pnt at the end of the polyline
                                {
                                    ++incoming;
                                }
                            }
                        }
                    }
                    if (null != dsLst || incoming > 0)
                    {
                        nodeDict.Add(pntFtrId, new Vertex(int.Parse(pntFtrId), incoming, dsLst));
                    }
                    pnt = pntCur.NextFeature();
                    if (++count % 1000 == 0)
                    {
                        Console.WriteLine("Processing Count: " + count);
                    }
                    incoming = 0;
                    dsLst    = null;
                }//end of while(null != pnt)
                ReleaseCOMObj(pntCur);
            }
            ReleaseCOMObj(workspaceFactory);
            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
示例#5
0
        public override bool Draw(out IModelPoint mp, out IModel fmodel, out IModel smodel)
        {
            List <ushort>  list2      = new List <ushort>();
            IPolygon       polygon    = null;
            IPolygon       polygon2   = null;
            IPolygon       polygon3   = null;
            IPoint         pointValue = null;
            ITriMesh       mesh       = null;
            IDoubleArray   vArray     = null;
            IUInt16Array   indexArray = null;
            IFloatArray    array3     = null;
            IFloatArray    array4     = null;
            IDoubleArray   norms      = null;
            IDrawGroup     group      = null;
            IDrawPrimitive primitive  = null;
            IDrawPrimitive primitive2 = null;
            IDrawPrimitive primitive3 = null;
            double         naN        = double.NaN;
            double         ty         = double.NaN;

            base.Draw(out mp, out fmodel, out smodel);
            try
            {
                int           num;
                int           num2;
                List <Vector> list;
                polygon  = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon2 = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon3 = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                if (this._route.Count > 2)
                {
                    list = Maths.DisperseLine(this._route, this._pillarSection.Diameter);
                }
                else
                {
                    list = this._route;
                }
                double[] vtxs = this._pillarSection.GetVtxs();
                SystemLog.Instance.Log("顶点个数:" + vtxs.Length);
                double[] numArray = new double[list.Count];
                for (num = 0; num < list.Count; num++)
                {
                    if (num == 0)
                    {
                        numArray[num] = 0.0;
                    }
                    else
                    {
                        numArray[num] = (list[num] - list[num - 1]).Length + numArray[num - 1];
                    }
                }
                object renderInfo = (this._renderType == RenderType.Texture) ? ((object)this._tcNames) : ((object)this._colors);
                int[]  index      = new int[3];
                index[1] = 1;
                index[2] = 2;
                if (!base.NewEmptyModel(index, this._renderType, renderInfo, out fmodel))
                {
                    return(false);
                }
                group = fmodel.GetGroup(0);
                SystemLog.Instance.Log("开始计算正交向量:" + DateTime.Now.ToLongTimeString());
                primitive = group.GetPrimitive(0);
                for (num = 0; num < list.Count; num++)
                {
                    Vector vector;
                    Vector vector2;
                    Vector vector3;
                    if (num == 0)
                    {
                        vector = list[num + 1] - list[num];
                    }
                    else if (num == (list.Count - 1))
                    {
                        vector = list[num] - list[num - 1];
                    }
                    else
                    {
                        vector = ((list[num] - list[num - 1])).UnitVector() + ((list[num + 1] - list[num])).UnitVector();
                    }
                    Maths.GenerateComplementBasis(vector, out vector2, out vector3);
                    vector2 = -vector2;
                    num2    = 0;
                    while (num2 <= this._pillarSection.SegCount)
                    {
                        Vector vector6;
                        Vector vector7;
                        (((vtxs[num2 * 2] - this._pillarSection.OffsetX) * vector2) + ((vtxs[(num2 * 2) + 1] - this._pillarSection.OffsetY) * vector3)).UnitVector();
                        Vector vector4 = list[num] + ((Vector)((vtxs[num2 * 2] * vector2) + (vtxs[(num2 * 2) + 1] * vector3)));
                        Vector vector5 = (Vector)(vector4 * 1.01);
                        if (num == 0)
                        {
                            pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pointValue.SetCoords(vector4.X, vector4.Y, vector4.Z, 0.0, 0);
                            polygon.ExteriorRing.AppendPoint(pointValue);
                            pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pointValue.SetCoords(vector5.X, vector5.Y, vector5.Z, 0.0, 0);
                            polygon3.ExteriorRing.AppendPoint(pointValue);
                        }
                        else if (num == (list.Count - 1))
                        {
                            pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pointValue.SetCoords(vector4.X, vector4.Y, vector4.Z, 0.0, 0);
                            polygon2.ExteriorRing.AppendPoint(pointValue);
                        }
                        primitive.VertexArray.Append((float)vector4.X);
                        primitive.VertexArray.Append((float)vector4.Y);
                        primitive.VertexArray.Append((float)vector4.Z);
                        list2.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                        primitive.VertexArray.Append((float)vector4.X);
                        primitive.VertexArray.Append((float)vector4.Y);
                        primitive.VertexArray.Append((float)vector4.Z);
                        list2.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                        if (this._renderType == RenderType.Texture)
                        {
                            primitive.TexcoordArray.Append((float)(num2 * 1.0));
                            primitive.TexcoordArray.Append((float)(num * 1.0));
                            primitive.TexcoordArray.Append((float)(num2 * 1.0));
                            primitive.TexcoordArray.Append((float)(num * 1.0));
                        }
                        if (num2 == 0)
                        {
                            vector6 = new Vector(vtxs[num2 * 2] - vtxs[(this._pillarSection.SegCount - 1) * 2], vtxs[(num2 * 2) + 1] - vtxs[((this._pillarSection.SegCount - 1) * 2) + 1], 0.0).UnitVector();
                            vector7 = new Vector(vtxs[(num2 + 1) * 2] - vtxs[num2 * 2], vtxs[((num2 + 1) * 2) + 1] - vtxs[(num2 * 2) + 1], 0.0).UnitVector();
                        }
                        else if (num2 == this._pillarSection.SegCount)
                        {
                            vector6 = new Vector(vtxs[num2 * 2] - vtxs[(num2 - 1) * 2], vtxs[(num2 * 2) + 1] - vtxs[((num2 - 1) * 2) + 1], 0.0).UnitVector();
                            vector7 = new Vector(vtxs[2] - vtxs[num2 * 2], vtxs[3] - vtxs[(num2 * 2) + 1], 0.0).UnitVector();
                        }
                        else
                        {
                            vector6 = new Vector(vtxs[num2 * 2] - vtxs[(num2 - 1) * 2], vtxs[(num2 * 2) + 1] - vtxs[((num2 - 1) * 2) + 1], 0.0).UnitVector();
                            vector7 = new Vector(vtxs[(num2 + 1) * 2] - vtxs[num2 * 2], vtxs[((num2 + 1) * 2) + 1] - vtxs[(num2 * 2) + 1], 0.0).UnitVector();
                        }
                        Vector vector8 = new Vector(vector6.Y, -vector6.X, vector6.Z);
                        primitive.NormalArray.Append((float)vector8.X);
                        primitive.NormalArray.Append((float)vector8.Y);
                        primitive.NormalArray.Append((float)vector8.Z);
                        vector8 = new Vector(vector7.Y, -vector7.X, vector7.Z);
                        primitive.NormalArray.Append((float)vector8.X);
                        primitive.NormalArray.Append((float)vector8.Y);
                        primitive.NormalArray.Append((float)vector8.Z);
                        num2++;
                    }
                }
                SystemLog.Instance.Log("结束计算正交向量:" + DateTime.Now.ToLongTimeString());
                SystemLog.Instance.Log("开始添加索引数组:" + DateTime.Now.ToLongTimeString());
                for (num = 0; num < (list.Count - 1); num++)
                {
                    for (num2 = 0; num2 < this._pillarSection.SegCount; num2++)
                    {
                        primitive.IndexArray.Append(list2[((num * ((this._pillarSection.SegCount + 1) * 2)) + (num2 * 2)) + 1]);
                        primitive.IndexArray.Append(list2[((num + 1) * ((this._pillarSection.SegCount + 1) * 2)) + ((num2 + 1) * 2)]);
                        primitive.IndexArray.Append(list2[(((num + 1) * ((this._pillarSection.SegCount + 1) * 2)) + (num2 * 2)) + 1]);
                        primitive.IndexArray.Append(list2[((num * ((this._pillarSection.SegCount + 1) * 2)) + (num2 * 2)) + 1]);
                        primitive.IndexArray.Append(list2[(num * ((this._pillarSection.SegCount + 1) * 2)) + ((num2 + 1) * 2)]);
                        primitive.IndexArray.Append(list2[((num + 1) * ((this._pillarSection.SegCount + 1) * 2)) + ((num2 + 1) * 2)]);
                    }
                }
                SystemLog.Instance.Log("结束添加索引数组:" + DateTime.Now.ToLongTimeString());
                SystemLog.Instance.Log("开始画底面顶面和线框:" + DateTime.Now.ToLongTimeString());
                vArray     = new DoubleArrayClass();
                indexArray = new UInt16ArrayClass();
                array3     = new FloatArrayClass();
                norms      = new DoubleArrayClass();
                primitive2 = group.GetPrimitive(1);
                polygon.ExteriorRing.ReverseOrientation();
                mesh = DrawGeometry.geoConvertor.PolygonToTriMesh(polygon);
                if ((mesh != null) && mesh.BatchExport(ref vArray, ref indexArray, ref array3, ref array4, ref norms))
                {
                    for (num = 0; num < vArray.Length; num++)
                    {
                        primitive2.VertexArray.Append((float)vArray.Array[num]);
                    }
                    for (num = 0; num < indexArray.Length; num++)
                    {
                        primitive2.IndexArray.Append(indexArray.Array[num]);
                    }
                    for (num = 0; num < norms.Length; num++)
                    {
                        primitive2.NormalArray.Append((float)norms.Array[num]);
                    }
                    if (this._renderType == RenderType.Texture)
                    {
                        for (num = 0; num < (vArray.Length / 3); num++)
                        {
                            this.GetTexcoord(vArray.Array[num * 3], vArray.Array[(num * 3) + 1], out naN, out ty);
                            primitive2.TexcoordArray.Append((float)naN);
                            primitive2.TexcoordArray.Append((float)ty);
                        }
                    }
                }
                vArray     = new DoubleArrayClass();
                indexArray = new UInt16ArrayClass();
                array3     = new FloatArrayClass();
                norms      = new DoubleArrayClass();
                primitive3 = group.GetPrimitive(2);
                mesh       = DrawGeometry.geoConvertor.PolygonToTriMesh(polygon2);
                if ((mesh != null) && mesh.BatchExport(ref vArray, ref indexArray, ref array3, ref array4, ref norms))
                {
                    for (num = 0; num < vArray.Length; num++)
                    {
                        primitive3.VertexArray.Append((float)vArray.Array[num]);
                    }
                    for (num = 0; num < indexArray.Length; num++)
                    {
                        primitive3.IndexArray.Append(indexArray.Array[num]);
                    }
                    for (num = 0; num < norms.Length; num++)
                    {
                        primitive3.NormalArray.Append((float)norms.Array[num]);
                    }
                    if (this._renderType == RenderType.Texture)
                    {
                        for (num = 0; num < (vArray.Length / 3); num++)
                        {
                            this.GetTexcoord(vArray.Array[num * 3], vArray.Array[(num * 3) + 1], out naN, out ty);
                            primitive3.TexcoordArray.Append((float)naN);
                            primitive3.TexcoordArray.Append((float)ty);
                        }
                    }
                }
                SystemLog.Instance.Log("结束画底面顶面和线框:" + DateTime.Now.ToLongTimeString());
                SystemLog.Instance.Log("结束调用Draw:" + DateTime.Now.ToLongTimeString());
                return(true);
            }
            catch (Exception exception)
            {
                SystemLog.Instance.Log(exception);
                return(false);
            }
        }
示例#6
0
        /// <summary>
        /// Updates the NALayer based on the current controls.
        /// This will update the solver settings for the solver referenced by the NALayer.
        /// </summary>
        private void UpdateNALayer(INALayer naLayer)
        {
            ILayer                      layer            = naLayer as ILayer;
            INAContext                  naContext        = naLayer.Context;
            INetworkDataset             networkDataset   = naContext.NetworkDataset;
            INALocator2                 naLocator        = naContext.Locator as INALocator2;
            INASolver                   naSolver         = naContext.Solver;
            INASolverSettings           naSolverSettings = naSolver as INASolverSettings2;
            INARouteSolver2             routeSolver      = naSolver as INARouteSolver2;
            INAClosestFacilitySolver    cfSolver         = naSolver as INAClosestFacilitySolver;
            INAODCostMatrixSolver       odSolver         = naSolver as INAODCostMatrixSolver;
            INAServiceAreaSolver2       saSolver         = naSolver as INAServiceAreaSolver2;
            INAVRPSolver                vrpSolver        = naSolver as INAVRPSolver;
            INALocationAllocationSolver laSolver         = naSolver as INALocationAllocationSolver;

            // Set Layer properties
            layer.Name = txtLayerName.Text;
            naLocator.MaxSnapTolerance   = Convert.ToDouble(txtMaxSearchTolerance.Text);
            naLocator.SnapToleranceUnits = (esriUnits)cboMaxSearchToleranceUnits.SelectedIndex;

            // Set Solver properties
            if (routeSolver != null)  // ROUTE LAYER
            {
                // INARouteSolver
                routeSolver.FindBestSequence  = chkRouteFindBestSequence.Checked;
                routeSolver.PreserveFirstStop = chkRoutePreserveFirstStop.Checked;
                routeSolver.PreserveLastStop  = chkRoutePreserveLastStop.Checked;
                routeSolver.UseTimeWindows    = chkRouteUseTimeWindows.Checked;
                routeSolver.UseStartTime      = chkRouteUseStartTime.Checked;
                routeSolver.StartTime         = System.Convert.ToDateTime(txtRouteStartTime.Text);
                routeSolver.OutputLines       = (esriNAOutputLineType)cboRouteOutputLines.SelectedIndex;

                // INASolverSettings
                naSolverSettings.ImpedanceAttributeName    = cboRouteImpedance.Text;
                naSolverSettings.UseHierarchy              = chkRouteUseHierarchy.Checked;
                naSolverSettings.IgnoreInvalidLocations    = chkRouteIgnoreInvalidLocations.Checked;
                naSolverSettings.RestrictUTurns            = (esriNetworkForwardStarBacktrack)cboRouteRestrictUTurns.SelectedIndex;
                naSolverSettings.AccumulateAttributeNames  = GetCheckedAttributeNamesFromControl(chklstRouteAccumulateAttributeNames);
                naSolverSettings.RestrictionAttributeNames = GetCheckedAttributeNamesFromControl(chklstRouteRestrictionAttributeNames);
            }

            else if (cfSolver != null)  // CLOSEST FACILITY LAYER
            {
                if (txtCFDefaultCutoff.Text.Length == 0)
                {
                    cfSolver.DefaultCutoff = null;
                }
                else
                {
                    cfSolver.DefaultCutoff = Convert.ToDouble(txtCFDefaultCutoff.Text);
                }

                if (txtCFDefaultTargetFacilityCount.Text.Length == 0)
                {
                    cfSolver.DefaultTargetFacilityCount = 1;
                }
                else
                {
                    cfSolver.DefaultTargetFacilityCount = Convert.ToInt32(txtCFDefaultTargetFacilityCount.Text);
                }

                cfSolver.TravelDirection = (esriNATravelDirection)cboCFTravelDirection.SelectedIndex;
                cfSolver.OutputLines     = (esriNAOutputLineType)cboCFOutputLines.SelectedIndex;

                // INASolverSettings
                naSolverSettings.ImpedanceAttributeName    = cboCFImpedance.Text;
                naSolverSettings.UseHierarchy              = chkCFUseHierarchy.Checked;
                naSolverSettings.IgnoreInvalidLocations    = chkCFIgnoreInvalidLocations.Checked;
                naSolverSettings.RestrictUTurns            = (esriNetworkForwardStarBacktrack)cboCFRestrictUTurns.SelectedIndex;
                naSolverSettings.AccumulateAttributeNames  = GetCheckedAttributeNamesFromControl(chklstCFAccumulateAttributeNames);
                naSolverSettings.RestrictionAttributeNames = GetCheckedAttributeNamesFromControl(chklstCFRestrictionAttributeNames);
            }

            else if (odSolver != null)  // OD COST MATRIX LAYER
            {
                if (txtODDefaultCutoff.Text.Length == 0)
                {
                    odSolver.DefaultCutoff = null;
                }
                else
                {
                    odSolver.DefaultCutoff = Convert.ToDouble(txtODDefaultCutoff.Text);
                }

                if (txtODDefaultTargetDestinationCount.Text.Length == 0)
                {
                    odSolver.DefaultTargetDestinationCount = null;
                }
                else
                {
                    odSolver.DefaultTargetDestinationCount = Convert.ToInt32(txtODDefaultTargetDestinationCount.Text);
                }

                odSolver.OutputLines = (esriNAOutputLineType)cboODOutputLines.SelectedIndex;

                // INASolverSettings
                naSolverSettings.ImpedanceAttributeName    = cboODImpedance.Text;
                naSolverSettings.UseHierarchy              = chkODUseHierarchy.Checked;
                naSolverSettings.IgnoreInvalidLocations    = chkODIgnoreInvalidLocations.Checked;
                naSolverSettings.RestrictUTurns            = (esriNetworkForwardStarBacktrack)cboODRestrictUTurns.SelectedIndex;
                naSolverSettings.AccumulateAttributeNames  = GetCheckedAttributeNamesFromControl(chklstODAccumulateAttributeNames);
                naSolverSettings.RestrictionAttributeNames = GetCheckedAttributeNamesFromControl(chklstODRestrictionAttributeNames);
            }

            else if (saSolver != null)  // SERVICE AREA SOLVER
            {
                IDoubleArray defaultBreaks = saSolver.DefaultBreaks;
                defaultBreaks.RemoveAll();
                string breaks = txtSADefaultBreaks.Text.Trim();
                breaks.Replace("  ", " ");
                string[] values = breaks.Split(' ');
                for (int iBreak = values.GetLowerBound(0); iBreak <= values.GetUpperBound(0); iBreak++)
                {
                    defaultBreaks.Add(System.Convert.ToDouble(values.GetValue(iBreak)));
                }
                saSolver.DefaultBreaks   = defaultBreaks;
                saSolver.TravelDirection = (esriNATravelDirection)cboSATravelDirection.SelectedIndex;

                saSolver.OutputPolygons            = (esriNAOutputPolygonType)cboSAOutputPolygons.SelectedIndex;
                saSolver.OverlapPolygons           = chkSAOverlapPolygons.Checked;
                saSolver.SplitPolygonsAtBreaks     = chkSASplitPolygonsAtBreaks.Checked;
                saSolver.MergeSimilarPolygonRanges = chkSAMergeSimilarPolygonRanges.Checked;
                saSolver.TrimOuterPolygon          = chkSATrimOuterPolygon.Checked;
                saSolver.TrimPolygonDistance       = Convert.ToDouble(this.txtSATrimPolygonDistance.Text);
                saSolver.TrimPolygonDistanceUnits  = (esriUnits)cboSATrimPolygonDistanceUnits.SelectedIndex;

                if (cboSAOutputLines.SelectedIndex == 0)
                {
                    saSolver.OutputLines = (esriNAOutputLineType)cboSAOutputLines.SelectedIndex;
                }
                else // Does not support Straight lines, so not in combobox, up by one to account for this
                {
                    saSolver.OutputLines = (esriNAOutputLineType)(cboSAOutputLines.SelectedIndex + 1);
                }

                saSolver.OverlapLines       = chkSAOverlapLines.Checked;
                saSolver.SplitLinesAtBreaks = chkSASplitLinesAtBreaks.Checked;
                saSolver.IncludeSourceInformationOnLines = this.chkSAIncludeSourceInformationOnLines.Checked;

                // INASolverSettings
                naSolverSettings.ImpedanceAttributeName    = cboSAImpedance.Text;
                naSolverSettings.IgnoreInvalidLocations    = chkSAIgnoreInvalidLocations.Checked;
                naSolverSettings.RestrictUTurns            = (esriNetworkForwardStarBacktrack)cboSARestrictUTurns.SelectedIndex;
                naSolverSettings.AccumulateAttributeNames  = GetCheckedAttributeNamesFromControl(chklstSAAccumulateAttributeNames);
                naSolverSettings.RestrictionAttributeNames = GetCheckedAttributeNamesFromControl(chklstSARestrictionAttributeNames);
            }
            else if (vrpSolver != null)
            {
                naSolverSettings.ImpedanceAttributeName = cboVRPTimeAttribute.Text;
                naSolverSettings.AccumulateAttributeNames.RemoveAll();
                IStringArray strArray = naSolverSettings.AccumulateAttributeNames;
                strArray.RemoveAll();
                strArray.Add(cboVRPDistanceAttribute.Text);
                naSolverSettings.AccumulateAttributeNames = strArray;

                vrpSolver.CapacityCount  = Convert.ToInt32(txtVRPCapacityCount.Text);
                vrpSolver.DefaultDate    = Convert.ToDateTime(txtVRPDefaultDate.Text);
                vrpSolver.TimeFieldUnits = ((esriNetworkAttributeUnits)cboVRPTimeFieldUnits.SelectedIndex) + 20;

                // there cannot be unknown units for a VRP, so the index is offset by 1
                vrpSolver.DistanceFieldUnits               = (esriNetworkAttributeUnits)cboVRPDistanceFieldUnits.SelectedIndex + 1;
                naSolverSettings.RestrictUTurns            = (esriNetworkForwardStarBacktrack)cboVRPAllowUTurns.SelectedIndex;
                vrpSolver.OutputLines                      = (esriNAOutputLineType)cboVRPOutputShapeType.SelectedIndex;
                vrpSolver.TimeWindowViolationPenaltyFactor = cboVRPTimeWindow.SelectedIndex;
                vrpSolver.ExcessTransitTimePenaltyFactor   = cboVRPTransitTime.SelectedIndex;

                naSolverSettings.UseHierarchy = chkVRPUseHierarchy.Checked;

                naSolverSettings.RestrictionAttributeNames = GetCheckedAttributeNamesFromControl(chklstVRPRestrictionAttributeNames);
            }
            else if (laSolver != null)  // Location-Allocation LAYER
            {
                if (txtLACutOff.Text.Length == 0)
                {
                    laSolver.DefaultCutoff = null;
                }
                else if (Convert.ToDouble(txtLACutOff.Text) == 0.0)
                {
                    laSolver.DefaultCutoff = null;
                }
                else
                {
                    laSolver.DefaultCutoff = Convert.ToDouble(txtLACutOff.Text);
                }

                if (txtLAFacilitiesToLocate.Text.Length == 0)
                {
                    laSolver.NumberFacilitiesToLocate = 1;
                }
                else
                {
                    laSolver.NumberFacilitiesToLocate = Convert.ToInt32(txtLAFacilitiesToLocate.Text);
                }

                laSolver.ProblemType                 = (esriNALocationAllocationProblemType)cboLAProblemType.SelectedIndex;
                laSolver.ImpedanceTransformation     = (esriNAImpedanceTransformationType)cboLAImpTransformation.SelectedIndex;
                laSolver.TransformationParameter     = Convert.ToDouble(txtLAImpParameter.Text);
                laSolver.TargetMarketSharePercentage = Convert.ToDouble(txtLATargetMarketShare.Text);
                laSolver.TravelDirection             = (esriNATravelDirection)cboLATravelDirection.SelectedIndex;
                laSolver.OutputLines                 = (esriNAOutputLineType)cboLAOutputLines.SelectedIndex;

                //// INASolverSettings
                naSolverSettings.ImpedanceAttributeName    = cboLAImpedance.Text;
                naSolverSettings.UseHierarchy              = chkLAUseHierarchy.Checked;
                naSolverSettings.AccumulateAttributeNames  = GetCheckedAttributeNamesFromControl(chklstLAAccumulateAttributeNames);
                naSolverSettings.RestrictionAttributeNames = GetCheckedAttributeNamesFromControl(chklstLARestrictionAttributeNames);
                naSolverSettings.IgnoreInvalidLocations    = chkLAIgnoreInvalidLocations.Checked;
            }
        }