Ejemplo n.º 1
0
        /// <summary>
        /// 创建并加载点云
        /// </summary>
        /// <returns></returns>
        IRenderModelPoint CreatePointCloud()
        {
            //准备容器
            IModel         model         = new ResourceFactory().CreateModel();
            IDrawGroup     drawGroup     = new DrawGroup();
            IDrawPrimitive drawPrimitive = new DrawPrimitive();
            IFloatArray    verList       = new FloatArray();  //点集
            IUInt32Array   colorList     = new UInt32Array(); //点色

            //点坐标
            float x = 3.3f, y = 4.4f, z = 5.5f;
            //点色
            byte a = 128, r = 255, g = 255, b = 255;
            uint col = (uint)(b | g << 8 | r << 16 | a << 24); //argb => uint

            for (int i = 0; i < 10; i++)
            {
                verList.Append(x);
                verList.Append(y);
                verList.Append(z);
                colorList.Append(col);
            }

            //塞入容器
            drawPrimitive.VertexArray          = verList;
            drawPrimitive.ColorArray           = colorList;
            drawPrimitive.Material.EnableBlend = false;                                     //关闭融合
            drawPrimitive.Material.EnableLight = false;                                     //关闭光照
            drawPrimitive.PrimitiveMode        = gviPrimitiveMode.gviPrimitiveModeLineList; //设置绘制模式为点
            drawGroup.AddPrimitive(drawPrimitive);                                          //塞入渲染组
            model.AddGroup(drawGroup);                                                      //塞入model
            axRenderControl.ObjectManager.AddModel("modelName", model);                     //塞入三维对象,与modelPoint通过名称匹配

            //创建modelPoint,用于索引模型
            IModelPoint mp = (IModelPoint) new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);

            mp.SpatialCRS    = (SpatialCRS)CRSFactory.CreateFromWKT("wkt");                     //设置坐标系
            mp.ModelEnvelope = model.Envelope;                                                  // 排除不显示BUG
            mp.SetCoords(3.3, 4.4, 5.5, 0, 0);
            mp.ModelName = "modelName";                                                         //匹配模型
            return(axRenderControl.ObjectManager.CreateRenderModelPoint(mp, null, Guid.Empty)); //创建完成
        }
Ejemplo n.º 2
0
        private IModel CreateModel(float lenght, float width, float height, uint color)
        {
            IModel         model        = new ResourceFactory().CreateModel();
            IDrawGroup     group        = new DrawGroup();
            IDrawPrimitive primitive    = new DrawPrimitive();
            IFloatArray    vertexArray  = new FloatArray();
            IFloatArray    textureArray = new FloatArray();
            IUInt32Array   colorArray   = new UInt32Array();

            #region
            //顶点数组3个为一组(三角面1)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            //顶点数组3个为一组(三角面2)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            //顶点数组3个为一组(三角面3)
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面4)
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面5)
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面6)
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面7)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            //顶点数组3个为一组(三角面8)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面9)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面10)
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面11)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面12)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght);

            #endregion

            #region
            //颜色数组1个为一组
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            #endregion

            #region
            //纹理数组2个为一组
            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);
            #endregion

            primitive.ColorArray    = colorArray;
            primitive.TexcoordArray = textureArray;
            primitive.VertexArray   = vertexArray;

            IDrawMaterial material = new DrawMaterial();
            material.EnableLight = true;
            primitive.Material   = material;
            group.AddPrimitive(primitive);
            //光照效果,跟法向有关
            group.ComputeNormal();
            model.AddGroup(group);
            return(model);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 参数化建模
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDriveModel_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (polyline != null)
                {
                    center = polyline.Envelope.Center;
                    IModelPoint mp = new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    mp.SpatialCRS = datasetCRS;
                    mp.Position   = center;

                    IModel         model     = new ResourceFactory().CreateModel();
                    IDrawGroup     group     = new DrawGroup();
                    IDrawPrimitive primitive = new DrawPrimitive();
                    IDrawMaterial  material  = new DrawMaterial();
                    material.TextureName = (strMediaPath + @"\shp\road\textrure.jpg");
                    material.CullMode    = gviCullFaceMode.gviCullNone;
                    material.WrapModeS   = gviTextureWrapMode.gviTextureWrapRepeat;
                    material.WrapModeT   = gviTextureWrapMode.gviTextureWrapRepeat;
                    IFloatArray va = new FloatArray();
                    IFloatArray ta = new FloatArray();
                    // 逐点外扩
                    for (int i = 0; i < polyline.PointCount; i++)
                    {
                        #region 单独处理最后一个点
                        if (i == polyline.PointCount - 1)
                        {
                            curPoint  = polyline.GetPoint(i);
                            vecCurPos = curPoint.Position;
                            // 最后一个点重用最后的方向向量
                            vecTarget = vecDirect.CrossProduct(vecZ);
                            vecTarget.Normalize();
                            vecTarget.MultiplyByScalar(width / 2);
                            vecP = vecCurPos.Add(vecTarget);
                            vecTarget.MultiplyByScalar(-1);
                            vecQ = vecCurPos.Add(vecTarget);
                            // 设置外扩点
                            P          = curPoint.Clone() as IPoint;
                            P.Position = vecP;
                            Q          = curPoint.Clone() as IPoint;
                            Q.Position = vecQ;
                            // 把点坐标加进顶点数组
                            va.Append((float)(vecP.X - center.X));
                            va.Append((float)(vecP.Y - center.Y));
                            va.Append((float)(vecP.Z - center.Z));
                            va.Append((float)(vecQ.X - center.X));
                            va.Append((float)(vecQ.Y - center.Y));
                            va.Append((float)(vecQ.Z - center.Z));
                            // 加纹理坐标
                            ta.Append(0);  //P点纹理
                            if (i == 0)
                            {
                                lastV = 0.0;
                            }
                            else
                            {
                                lastV = lastV + length / 10;  //v方向上每隔10米重复一次
                            }
                            ta.Append((float)lastV);
                            ta.Append(1);  //Q点纹理
                            ta.Append((float)lastV);

                            {
                                ISimplePointSymbol ps = new SimplePointSymbol();
                                ps.FillColor = System.Drawing.Color.Yellow;
                                ps.Size      = 5;
                                rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId));
                                rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId));
                            }

                            break;
                        }
                        #endregion

                        // 当不是最后一个点时:
                        curPoint   = polyline.GetPoint(i);
                        nextPoint  = polyline.GetPoint(i + 1);
                        vecCurPos  = curPoint.Position;
                        vecNextPos = nextPoint.Position;
                        // 运算
                        vecNextPos.MultiplyByScalar(-1);
                        vecDirect = vecCurPos.Add(vecNextPos);  //方向向量
                        vecZ.Set(0, 0, 1);
                        vecTarget = vecDirect.CrossProduct(vecZ);
                        vecTarget.Normalize();
                        vecTarget.MultiplyByScalar(width / 2);
                        vecP = vecCurPos.Add(vecTarget);
                        vecTarget.MultiplyByScalar(-1);
                        vecQ = vecCurPos.Add(vecTarget);
                        // 设置外扩点
                        P          = curPoint.Clone() as IPoint;
                        P.Position = vecP;
                        Q          = curPoint.Clone() as IPoint;
                        Q.Position = vecQ;
                        // 把点坐标加进顶点数组
                        va.Append((float)(vecP.X - center.X));
                        va.Append((float)(vecP.Y - center.Y));
                        va.Append((float)(vecP.Z - center.Z));
                        va.Append((float)(vecQ.X - center.X));
                        va.Append((float)(vecQ.Y - center.Y));
                        va.Append((float)(vecQ.Z - center.Z));
                        // 加纹理坐标
                        ta.Append(0);  //P点纹理
                        if (i == 0)
                        {
                            lastV = 0.0;
                        }
                        else
                        {
                            lastV = lastV + length / 5; //v方向上每隔10米重复一次
                        }
                        length = vecDirect.Length;      //计算长度给奇数点用
                        ta.Append((float)lastV);
                        ta.Append(1);                   //Q点纹理
                        ta.Append((float)lastV);

                        {
                            ISimplePointSymbol ps = new SimplePointSymbol();
                            ps.FillColor = System.Drawing.Color.Yellow;
                            ps.Size      = 5;
                            rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId));
                            rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId));
                        }
                    }
                    // 计算索引坐标
                    IUInt16Array ia = new UInt16Array();
                    for (int i = 0; i < va.Length / 6 - 1; i++)
                    {
                        ia.Append((ushort)(2 * i));
                        ia.Append((ushort)(2 * i + 1));
                        ia.Append((ushort)(2 * i + 2));
                        ia.Append((ushort)(2 * i + 1));
                        ia.Append((ushort)(2 * i + 3));
                        ia.Append((ushort)(2 * i + 2));
                    }
                    primitive.VertexArray   = va;
                    primitive.TexcoordArray = ta;
                    primitive.IndexArray    = ia;
                    primitive.Material      = material;
                    group.AddPrimitive(primitive);
                    model.AddGroup(group);

                    // 在内存中临时存储模型
                    string modelName = fid.ToString();
                    this.axRenderControl1.ObjectManager.AddModel(modelName, model);
                    mp.ModelName     = modelName;
                    mp.ModelEnvelope = model.Envelope;
                    // 可视化临时模型
                    IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId);
                    rmp.MaxVisibleDistance = 100000;
                    rmp.MouseSelectMask    = gviViewportMask.gviViewNone;
                    rModelpointToDelList.Add(rmp);
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }