Exemplo n.º 1
0
        public PeopleOverview()
        {
            InitializeComponent();

            gpe = new GeometryPlotElement();
            gpe.Name = "People";
            gpe.lockMoving = true;
            canvas1.AddElement(gpe);
        }
Exemplo n.º 2
0
        public PeopleOverview(FxMatrixF im)
        {
            InitializeComponent();

            // add building
            ImageElement ie = new ImageElement(im, new ColorMap(ColorMapDefaults.Bones));
            ie.Name = "Katopsi";
            ie.lockMoving = true;
            canvas1.AddElement(ie);

            // add geometry plot
            gpe = new GeometryPlotElement();
            gpe.Name = "People";
            gpe.lockMoving = true;
            canvas1.AddElement(gpe);
        }
Exemplo n.º 3
0
        private void DrawResults()
        {
            // draw points
            GeometryPlotElement plotElement = new GeometryPlotElement();
            foreach (FxVector2f v in sorted_Vertex)
            {
                Circle c = new Circle(v, 2);
                plotElement.AddGeometry(c, false);

                if (false)
                {
                    TextElement text = new TextElement(v.ToString("0.00"));
                    text.Position = v;
                    canvas1.AddElements(text, false);
                }
            }

            // draw regions
            for (int i = 0; i < regionDebugH.Length; i++)
            {
                RegionInfoDebug r = regionDebugH[i];

                Line l = new Line(new FxVector2f(r.start.x, 0), new FxVector2f(r.start.x, 2000));
                l.LineColor = SharpDX.Color.AntiqueWhite;
                l.UseDefaultColor = false;
                plotElement.AddGeometry(l, false);
                l = new Line(new FxVector2f(r.end.x, 2000), new FxVector2f(r.end.x, 0));
                l.LineColor = SharpDX.Color.AntiqueWhite;
                l.UseDefaultColor = false;
                plotElement.AddGeometry(l, false);

            }

            // copy back the results of d_regions
            regionInfo = d_regionInfo;

            for (int i = 0; i < regionInfo.Length; i++)
            {
                RegionInfoDebug r = regionDebugH[(int)Math.Floor((float)i / VerticalRegions)];
                RegionInfo ri = regionInfo[i];

                FxVector2f v_start = sorted_Vertex[ri.VertexOffset];
                FxVector2f v_end = sorted_Vertex[ri.VertexOffset + ri.VertexNum];

                Line l = new Line(new FxVector2f(r.start.x, v_start.Y), new FxVector2f(r.end.x, v_start.Y));
                l.LineColor = SharpDX.Color.GreenYellow;
                l.UseDefaultColor = false;
                plotElement.AddGeometry(l, false);

                l = new Line(new FxVector2f(r.start.x, v_end.Y), new FxVector2f(r.end.x, v_end.Y));
                l.LineColor = SharpDX.Color.HotPink;
                l.UseDefaultColor = false;
                plotElement.AddGeometry(l, false);

            }

            /////// Draw triangles
            threadInfo = d_threadInfo;
            csFace[] faceList = d_FaceList;
            csHalfEdge[] heList = d_HalfEdgeList;

            for (int t = 0; t < threadInfo.Length; t++)
            {
                csThreadInfo tInfo = threadInfo[t];

                for (int f = 0; f < tInfo.lastFaceID.x; f++)
                {
                    csFace face = faceList[f + tInfo.lastFaceID.y];

                    if (face.halfEdgeID < heList.Length)
                    {
                        csHalfEdge he1 = heList[face.halfEdgeID];
                        csHalfEdge he2 = heList[he1.nextEdgeID];
                        csHalfEdge he3 = heList[he2.nextEdgeID];

                        FxVector2f v1 = sorted_Vertex[he1.startVertexID];
                        FxVector2f v2 = sorted_Vertex[he2.startVertexID];
                        FxVector2f v3 = sorted_Vertex[he3.startVertexID];

                        Line l = new Line(v1, v2);
                        l.LineColor = SharpDX.Color.BlanchedAlmond;
                        l.UseDefaultColor = false;
                        l.LineWidth = 0.5f;
                        plotElement.AddGeometry(l, false);

                        l = new Line(v2, v3);
                        l.LineColor = SharpDX.Color.BlanchedAlmond;
                        l.UseDefaultColor = false;
                        l.LineWidth = 0.5f;
                        plotElement.AddGeometry(l, false);

                        l = new Line(v3, v1);
                        l.LineColor = SharpDX.Color.BlanchedAlmond;
                        l.UseDefaultColor = false;
                        l.LineWidth = 0.5f;
                        plotElement.AddGeometry(l, false);
                    }
                }
            }

            canvas1.AddElements(plotElement, false);
            canvas1.ReDraw();
        }
Exemplo n.º 4
0
        private void ellipseDetectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                // load image
                imMat = FxMatrixF.Load(ofd.FileName);
                ieEllipseImage = new ImageElement(imMat, new ColorMap(ColorMapDefaults.Jet));
                ieEllipseImage.lockMoving = true;
                canvas_ellipse.AddElement(ieEllipseImage);

                // add plot element 
                gpeEllipseImage = new GeometryPlotElement();
                canvas_ellipse.AddElement(gpeEllipseImage);


                var contours = new FxContour(imMat<0.2f);

                WriteLine("Num Contours : " + contours.NumChains);

                int i = 0;
                float pe_pos_y = ieEllipseImage._Position.y;
                foreach (var cont in contours.ChainList)
                {
                    // draw the rectanges in main image
                    FxVector2f start = cont.RectStart ;
                    FxVector2f end = start + cont.RectSize;
                    FxMaths.Geometry.Rectangle r = new FxMaths.Geometry.Rectangle(start, end);
                    gpeEllipseImage.AddGeometry(r, false);


                    // draw the centroids 
                    FxVector2f cen = cont.GetCentroid();
                    var l = new FxMaths.Geometry.Line(cen - new FxVector2f(0, 2), cen + new FxVector2f(0, 2));
                    l.LineWidth = 0.5f;
                    gpeEllipseImage.AddGeometry(l, false);
                    l = new FxMaths.Geometry.Line(cen - new FxVector2f(2, 0), cen + new FxVector2f(2, 0));
                    l.LineWidth = 0.5f;
                    gpeEllipseImage.AddGeometry(l, false);


                    // add the numbering of the contours
                    var t = new TextElement(i.ToString());
                    t._Position = cen;
                    t.FontColor = SharpDX.Color.Green;
                    t._TextFormat.fontSize = 16.0f;
                    canvas_ellipse.AddElement(t);

                    // show the chain vector in plot
                    {
                        FxVectorF vec_i = new FxVectorF(cont.Count);
                        FxVectorF vec_r = new FxVectorF(cont.Count);
                        vec_i[0] = cont[0].i;
                        vec_r[0] = cont[0].r;
                        for (int j = 1; j < cont.Count; j++)
                        {
                            vec_i[j] = vec_i[j - 1] + cont[j].i;
                            vec_r[j] = vec_r[j - 1] + cont[j].r;
                        }

                        // show  the plot of this vector
                        var pe = new PloterElement(vec_i, PlotType.Lines, System.Drawing.Color.Blue);
                        pe._Position.x = ieEllipseImage._Position.x + ieEllipseImage.Size.x;
                        pe._Position.y = pe_pos_y;
                        pe.AddPlot(vec_r, PlotType.Lines, System.Drawing.Color.Red);
                        pe.CenterYOrigin();
                        pe.FitPlots();
                        canvas_ellipse.AddElement(pe);

                        // update the y of pe for the next one
                        pe_pos_y += pe.Size.y;

                        // debug the ellipse

                        for (int j = 0; j < cont.Count; j++)
                        {
                            imMat[(int)(vec_r[j] + cont.StartPoint.x), (int)(vec_i[j] + cont.StartPoint.y)] = 0.8f/contours.NumChains + 0.1f;
                        }
                        ieEllipseImage.UpdateInternalImage(imMat, new ColorMap(ColorMapDefaults.Jet));

                    }



                    i++;
                }

                canvas_ellipse.ReDraw();
            }
        }
Exemplo n.º 5
0
        private void toolStripButton_eclipse_SelectSubRegion_Click(object sender, EventArgs e)
        {
            if (toolStripButton_eclipse_SelectSubRegion.Checked)
            {
                toolStripButton_eclipse_SelectSubRegion.Checked = false;

                // clean old geometry element
                if(gpeEllipseImage!=null)
                    gpeEllipseImage.ClearGeometry(true);

                if (rect != null)
                {
                    rect.Dispose();
                    rect = null;
                }
            }
            else
            {

                toolStripButton_eclipse_SelectSubRegion.Checked = true;

                // init geometry plot
                if (gpeEllipseImage == null)
                {
                    gpeEllipseImage = new GeometryPlotElement();
                    canvas_ellipse.AddElement(gpeEllipseImage);
                    gpeEllipseImage.Position = ieEllipseImage._Position;
                }
                else
                    gpeEllipseImage.ClearGeometry(true);


                if (rect != null)
                {
                    rect.Dispose();
                    rect = null;
                }
            }
        }
Exemplo n.º 6
0
        internal void DrawPoints(Canvas canvas)
        {
            GeometryPlotElement plot = new GeometryPlotElement();
            foreach (FxVector2f vec in listAllVertex)
            {

                plot.AddGeometry(new Circle(vec, 5));

            }
            canvas.AddElement(plot);
        }
Exemplo n.º 7
0
        public void RunTheAlgorithm(Canvas canvas)
        {
            float time;
            TimeStatistics.StartClock();
            FXConstantBuffer<csMergeVThreadParam> cbMVTP;
            csMergeVThreadParam local_cbMVTP;

            FXConstantBuffer<csMergeHThreadParam> cbMHTP;
            csMergeHThreadParam local_cbMHTP;

            /////////////////////////////   Create regions

            WriteLine("============== Split =================");

            bitonicSort.Split(MaxPointsPerRegion);

            //time = TimeStatistics.ClockLap("Split regions");

            /////////////////////////////   Triangulate the regions

            #region Triangulation of the regions
            WriteLine("============== Triangulation =================");

            #region Exec

            #region Bind and update the threadParam constant buffer

            FXConstantBuffer<cbThreadParam> cbTP;
            cbThreadParam local_cbTP;

            // init the cb
            local_cbTP.maxFacesPerThread = (uint)maxFacesPerThread;
            local_cbTP.maxHalfEdgePerThread = (uint)maxHalfEdgePerThread;
            local_cbTP.maxBoundaryNodesPerThread = (uint)maxBoundaryNodesPerThread;
            local_cbTP.RegionsNum = (uint)NumRegions;

            /// Bind the constant buffer with local buffer
            cbTP = CSSubRegions.m_effect.GetConstantBufferByName<cbThreadParam>("threadParam");

            // update the value of cb
            cbTP.UpdateValue(local_cbTP);

            #endregion

            CSSubRegions.Execute(kenrelNum, 1);

            #endregion

            //time = TimeStatistics.ClockLap("Triangulate");
            #endregion

            /////////////////////////////   Merge Vertical

            #region Vertical Merging

            local_cbMVTP = new csMergeVThreadParam();
            local_cbMVTP.ThreadNum = (uint)mergeVthreadNum;
            local_cbMVTP.ThreadNumPerRow = (uint)(mergeVXthreadNum);
            local_cbMVTP.HorizontalThreadNum = (uint)(mergeVYthreadNum);
            local_cbMVTP.stackMaxSize = stackMaxSize;
            local_cbMVTP.depth = (uint)0;

            /// Bind the constant buffer with local buffer
            cbMVTP = CSVMerging.m_effect.GetConstantBufferByName<csMergeVThreadParam>("threadParam");

            // update the value of cb
            cbMVTP.UpdateValue(local_cbMVTP);

            WriteLine("============== Vertical Merging =================");

            int maxDepth = (int)Math.Ceiling(Math.Log(mergeVXthreadNum + 1, 2));

            WriteLine("maxDepth:" + maxDepth.ToString());

            for (int i = 0; i < maxDepth; i++)
            {
                // calc the number the number of the thread that we need for the merging
                int threadNumX = (int)Math.Ceiling((float)mergeVXthreadNum / Math.Pow(2, i + 1));
                int kernelNumX = (int)Math.Ceiling((float)threadNumX / MergeVXThread);

                // calc the number the number of the thread that we need for the merging
                int threadNumY = (int)Math.Ceiling((float)mergeVYthreadNum / Math.Pow(2, i + 1));
                int kernelNumY = (int)Math.Ceiling((float)threadNumY / MergeVYThread);

                //WriteLine("threadNumX:" + threadNumX.ToString() + "    kernelNumX:" + kernelNumX.ToString());
                //WriteLine("mergeVYkernelNum:" + mergeVYkernelNum.ToString() + "    mergeVXkernelNum:" + mergeVXkernelNum.ToString());

                local_cbMVTP.depth = (uint)i;

                // update the value of cb
                cbMVTP.UpdateValue(local_cbMVTP);

                #region Exec

                CSVMerging.Execute(kernelNumX, mergeVYkernelNum);

                #endregion

            }

            #endregion

            /////////////////////////////   Merge Horizontal

            #region Horizontal Merge

            WriteLine("============== Horizontal Merging =================");

            maxDepth = (int)Math.Ceiling(Math.Log(mergeHthreadNum + 1, 2));

            WriteLine("maxDepth:" + maxDepth.ToString());

            local_cbMHTP = new csMergeHThreadParam();
            local_cbMHTP.depth = (uint)0;
            local_cbMHTP.stackMaxSize = stackMaxSize;
            local_cbMHTP.ThreadNum = (uint)mergeHthreadNum;
            local_cbMHTP.ThreadNumPerRow = local_cbMVTP.ThreadNumPerRow;

            /// Bind the constant buffer with local buffer
            cbMHTP = CSHMerging.m_effect.GetConstantBufferByName<csMergeHThreadParam>("threadParam");

            // update the value of cb
            cbMHTP.UpdateValue(local_cbMHTP);

            for (int i = 0; i < maxDepth; i++)
            {
                // calc the number the number of the thread that we need for the merging
                int threadNum = (int)Math.Ceiling((float)mergeHthreadNum / Math.Pow(2, i + 1));
                int kernelNum = (int)Math.Ceiling((float)threadNum / MergeThread);

                //WriteLine("threadNum:" + threadNum.ToString() + "    kernelNum:" + kernelNum.ToString());

                local_cbMHTP.depth = (uint)i;

                // update the value of cb
                cbMHTP.UpdateValue(local_cbMHTP);

                #region Exec H

                CSHMerging.Execute(kernelNum, 1);

                #endregion

                //break;
            }
            #endregion

            /////////////////////////////  Read result  the regions

            #region Read the threadInfo buffer

            csThreadInfo[] csThreadListResult = new csThreadInfo[ThreadInfoListBuffer.Description.SizeInBytes / ThreadInfoListBuffer.Description.StructureByteStride];
            FXResourceVariable.ReadBuffer<csThreadInfo>(Engine.g_device, stagingThreadInfoListBuffer, ThreadInfoListBuffer, ref csThreadListResult);

            #endregion

            time = TimeStatistics.ClockLap("ExecFinish:");
            WriteLine("ExecFinish:" + time.ToString());

            #if true

            #region Read the threadInfo buffer

            IVertex<float>[] listPoints = new IVertex<float>[NumVertex];
            FXResourceVariable.ReadBufferVector<float>(Engine.g_device, stagingInputPointsBuffer, InputPoints, ref listPoints);

            #endregion

            #region Read the HalfEdge buffer

            csHalfEdge[] csHalfEdgeListResult = new csHalfEdge[HalfEdgeListBuffer.Description.SizeInBytes / HalfEdgeListBuffer.Description.StructureByteStride];
            FXResourceVariable.ReadBuffer<csHalfEdge>(Engine.g_device, stagingHalfEdgeListBuffer, HalfEdgeListBuffer, ref csHalfEdgeListResult);

            #endregion

            #region Read the boundary buffer

            csBoundaryNode[] csBoundaryListResult = new csBoundaryNode[BoundaryListBuffer.Description.SizeInBytes / BoundaryListBuffer.Description.StructureByteStride];
            FXResourceVariable.ReadBuffer<csBoundaryNode>(Engine.g_device, stagingBoundaryListBuffer, BoundaryListBuffer, ref csBoundaryListResult);

            #endregion

            #region Read the FaceList buffer

            csFace[] csFaceListResult = new csFace[maxFacesPerThread * NumRegions];
            FXResourceVariable.ReadBuffer<csFace>(Engine.g_device, stagingFaceListBuffer, FaceListBuffer, ref csFaceListResult);

            #endregion

            time = TimeStatistics.ClockLap("ExecFinish:");
            WriteLine("ExecFinish:" + time.ToString());

            #region show Result to 2d Canvas

            if (canvas != null)
            {
                Color[] lineColor = { Color.Aqua, Color.Beige, Color.Aqua, Color.Red, Color.Orchid };
                // pass all regions
                for (int i = 0; i < NumRegions; i++)
                {
                    //if (i < 0 * (local_cbMVTP.ThreadNumPerRow + 1))
                    //  continue;
                    //if (i > 10 * (local_cbMVTP.ThreadNumPerRow + 1))
                    //  continue;

                    // pass all the faces pre region
                    for (int j = maxFacesPerThread * i; j < maxFacesPerThread * (i + 1); j++)
                    {

                        csFace tmpFace = csFaceListResult[j];

                        if (tmpFace.halfEdgeID != uint.MaxValue)
                        {
                            GeometryPlotElement trianglesPlot = new GeometryPlotElement();
                            canvas.AddElement(trianglesPlot, false);
                            float lineWidth = 1.5f;

                            //csHalfEdge he = csHalfEdgeListResult[tmpFace.halfEdgeID + i * maxHalfEdgePerThread];
                            int he1ID = (int)tmpFace.halfEdgeID;
                            csHalfEdge he = csHalfEdgeListResult[he1ID];
                            int vert1ID = (int)he.startVertexID;
                            IVertex<float> vert1 = listPoints[vert1ID];

                            // move to next edge
                            int he2ID = (int)he.nextEdgeID;
                            he = csHalfEdgeListResult[he2ID];
                            int vert2ID = (int)he.startVertexID;
                            IVertex<float> vert2 = listPoints[vert2ID];

                            // move to next edgex
                            int he3ID = (int)he.nextEdgeID;
                            he = csHalfEdgeListResult[he3ID];
                            int vert3ID = (int)he.startVertexID;
                            IVertex<float> vert3 = listPoints[vert3ID];

                            FxMaths.Geometry.Line line = new FxMaths.Geometry.Line(vert1, vert2);
                            line.UseDefaultColor = false;
                            line.LineColor = lineColor[2];
                            line.LineWidth = lineWidth;
                            trianglesPlot.AddGeometry(line, false);

                            line = new FxMaths.Geometry.Line(vert2, vert3);
                            line.UseDefaultColor = false;
                            line.LineColor = lineColor[2];
                            line.LineWidth = lineWidth;
                            trianglesPlot.AddGeometry(line, false);

                            line = new FxMaths.Geometry.Line(vert3, vert1);
                            line.UseDefaultColor = false;
                            line.LineColor = lineColor[2];
                            line.LineWidth = lineWidth;
                            trianglesPlot.AddGeometry(line, false);

                            if (false)// || he1ID == 1755525 || he2ID == 1755525 || he3ID == 1755525)
                            {
                                FxMaths.GUI.TextElement text1;
                                float fontSize = 7;
                                FxVector2f tmp1, tmp2, tmp3;
                                tmp1 = vert1 as FxVector2f? ?? new FxVector2f(0, 0);
                                tmp2 = vert2 as FxVector2f? ?? new FxVector2f(0, 0);
                                tmp3 = vert3 as FxVector2f? ?? new FxVector2f(0, 0);

                                text1 = new TextElement(vert1ID.ToString() + "->" + tmp1.ToString("0.00"));
                                text1.Position = vert1 as FxVector2f? ?? new FxVector2f(0, 0);
                                text1._TextFormat.fontSize = fontSize;
                                canvas.AddElement(text1, false);

                                text1 = new TextElement(vert2ID.ToString() + "->" + tmp2.ToString("0.00"));
                                text1.Position = vert2 as FxVector2f? ?? new FxVector2f(0, 0);
                                text1._TextFormat.fontSize = fontSize;
                                canvas.AddElement(text1, false);

                                text1 = new TextElement(vert3ID.ToString() + "->" + tmp3.ToString("0.00"));
                                text1.Position = vert3 as FxVector2f? ?? new FxVector2f(0, 0);
                                text1._TextFormat.fontSize = fontSize;
                                canvas.AddElement(text1, false);

                                text1 = new TextElement(he1ID.ToString());
                                text1.FontColor = new Color4(Color.Brown.R, Color.Brown.G, Color.Brown.B, 1.0f);
                                text1._TextFormat.fontSize = fontSize;
                                text1.Position = (2 * tmp1 + 2 * tmp2 + tmp3) / 5.0f;
                                canvas.AddElement(text1, false);

                                text1 = new TextElement(he2ID.ToString());
                                text1.FontColor = new Color4(Color.Brown.R, Color.Brown.G, Color.Brown.B, 1.0f);
                                text1._TextFormat.fontSize = fontSize;
                                text1.Position = (tmp1 + 2 * tmp2 + 2 * tmp3) / 5.0f;
                                canvas.AddElement(text1, false);

                                text1 = new TextElement(he3ID.ToString());
                                text1.FontColor = new Color4(Color.Brown.R, Color.Brown.G, Color.Brown.B, 1.0f);
                                text1._TextFormat.fontSize = fontSize;
                                text1.Position = (2 * tmp1 + tmp2 + 2 * tmp3) / 5.0f;
                                canvas.AddElement(text1, false);

                                text1 = new TextElement(j.ToString());
                                text1.FontColor = new Color4(Color.Yellow.R, Color.Yellow.G, Color.Yellow.B, 1.0f);
                                text1._TextFormat.fontSize = fontSize;
                                text1.Position = (tmp1 + tmp2 + tmp3) / 3.0f;
                                canvas.AddElement(text1, false);
                            }

                        }
                    }

                }

                canvas.ReDraw();
            }

            #endregion

            #endif
        }