Exemple #1
0
        public void OnTapGesture(Vector2 posView)
        {
            float touchRange = ccContext.SelectRadius;

            Vector2 pos = CCContext.ViewToModel(posView, ccContext.ModelViewMatrix);

            // Mask draw and erase
            if (activeTool == Tool.MaskDraw || activeTool == Tool.MaskErase)
            {
                bool foreground = activeTool == Tool.MaskDraw;
                CountLayerHelper.MaskDraw(pos, pos, foreground, frameBuffer, maskTexName, ccContext.ImageSize,
                                          unitSphereVertices, ccContext.DrawRadius);

                bUpdateROI          = true;
                bUpdateSeqmentation = true;
                ccContext.RequestRender();
                return;
            }

            // Tap pos in count view spacew
            float radius = CCContext.ViewToModel(touchRange, ccContext.ModelViewMatrix);

            switch (ccContext.CountLayerContext.ActiveTool)
            {
            case CountLayerContext.Tool.TagCreate:
            {
                // Make sure tag is inside ROI
                if ((pos - roiSphere.center).Length < roiSphere.radius)
                {
                    tags.Add(new Tag(pos));
                    bUpdateSeqmentation = true;
                    ccContext.RequestRender();
                }

                break;
            }

            case CountLayerContext.Tool.TagDelete:
            {
                TagSelector selector = TagSelector.Select(tags, pos, radius);

                if (selector != null)
                {
                    Tag tag = selector.GetPrimitive() as Tag;
                    tags.Remove(tag);
                    bUpdateSeqmentation = true;
                    ccContext.RequestRender();
                }
                break;
            }
            }
        }
Exemple #2
0
        public void OnPinch(Vector2 center, Vector2 translation, float scale)
        {
            Matrix4 mat = CCContext.CreateScaleAroundPoint(new Vector3(center.X, center.Y, 0), scale);

            ccContext.ModelViewMatrix = ccContext.ModelViewMatrix * mat;


            // Pan view
            {
                Matrix4 trans = Matrix4.CreateTranslation(translation.X, translation.Y, 0);
                ccContext.ModelViewMatrix = ccContext.ModelViewMatrix * trans;
            }
        }
Exemple #3
0
        // **************************************************************************


        // Filter out everything that isnt in region of interest
        private void UpdateROI()
        {
            Vector2   center  = roiSphere.center;
            float     radius  = roiSphere.radius;
            Rectangle newRect = new Rectangle((int)(center.X - radius), (int)(center.Y - radius), (int)(radius * 2), (int)(radius * 2));

            CCContext.setupTexture(roiMaskTexName, newRect.Size, IntPtr.Zero);
            CCContext.setupTexture(roiTexName, newRect.Size, IntPtr.Zero);
            CCContext.setupTexture(thresholdTexName, newRect.Size, IntPtr.Zero);

//			int channels = 4;
//				segmentationPixelData = new byte[(int)(newRect.Size.Width*newRect.Size.Height*channels)];
            segmentationPixelData = new uint[(int)(newRect.Size.Width * newRect.Size.Height)];

            debugTexture.Size = newRect.Size;

            roiRect = newRect;

            CountLayerHelper.updateROIMask(roiRect, ccContext.ImageSize, frameBuffer, roiMaskTexName, maskTexName);
            CountLayerHelper.updateROIImage(roiRect, frameBuffer, ccContext.ImageTexName, ccContext.ImageSize, roiTexName, roiMaskTexName);
        }
Exemple #4
0
        public void OnDragStarted(Vector2 endPos, Vector2 translation)
        {
            Vector2 vPos = CCContext.ViewToModel(endPos, ccContext.ModelViewMatrix);
            Vector2 vDelta;

            vDelta.X = CCContext.ViewToModel(translation.X, ccContext.ModelViewMatrix);
            vDelta.Y = CCContext.ViewToModel(translation.Y, ccContext.ModelViewMatrix);

            // Mask draw and erase
            if (activeTool == Tool.MaskDraw || activeTool == Tool.MaskErase)
            {
                lastMaskDrawPos = vPos - vDelta;
                bool foreground = activeTool == Tool.MaskDraw;
                CountLayerHelper.MaskDraw(vPos, lastMaskDrawPos, foreground, frameBuffer, maskTexName, ccContext.ImageSize
                                          , unitSphereVertices, ccContext.DrawRadius);
                lastMaskDrawPos = vPos;
                return;
            }

            OnDrag(endPos, translation);
        }
Exemple #5
0
        public void OnDrag(Vector2 endPos, Vector2 translation)
        {
            Vector2 vPos = CCContext.ViewToModel(endPos, ccContext.ModelViewMatrix);

            // Mask draw and erase
            if (activeTool == Tool.MaskDraw || activeTool == Tool.MaskErase)
            {
                bool foreground = activeTool == Tool.MaskDraw;
                CountLayerHelper.MaskDraw(vPos, lastMaskDrawPos, foreground, frameBuffer, maskTexName, ccContext.ImageSize,
                                          unitSphereVertices, ccContext.DrawRadius);
                lastMaskDrawPos = vPos;

                bUpdateROI = true;
                ccContext.RequestRender();

                return;
            }

            // Drag primitive
            if (selectedPrim != null)
            {
                Vector2 vDelta;
                vDelta.X = CCContext.ViewToModel(translation.X, ccContext.ModelViewMatrix);
                vDelta.Y = CCContext.ViewToModel(translation.Y, ccContext.ModelViewMatrix);

                selectedPrim.DragTo(vPos, vDelta);
                ccContext.RequestRender();

                return;
            }

            // Pan view
            {
                Matrix4 trans = Matrix4.CreateTranslation(translation.X, translation.Y, 0);
                ccContext.ModelViewMatrix = ccContext.ModelViewMatrix * trans;
            }
        }
Exemple #6
0
        public bool OnSelect(Vector2 posView)
        {
            float touchRange = ccContext.SelectRadius;

            Vector2 p      = CCContext.ViewToModel(posView, ccContext.ModelViewMatrix);
            float   radius = CCContext.ViewToModel(touchRange, ccContext.ModelViewMatrix);

            switch (activeTool)
            {
            case Tool.ROIEdit:
            {
                selectedPrim = SphereSelector.Select(roiSphere, p, radius, true, true);
                if (selectedPrim != null)
                {
                    ccContext.RequestRender();
                    return(true);
                }
                break;
            }

            case Tool.TagCreate:
            case Tool.TagDelete:
            {
                selectedPrim = TagSelector.Select(tags, p, radius);
                if (selectedPrim != null)
                {
                    ccContext.RequestRender();
                    Console.WriteLine("selected:" + selectedPrim.GetPrimitive());
                    return(true);
                }
                break;
            }
            }

            return(false);
        }
Exemple #7
0
        public CountLayerContext(CCContext ccContext)
        {
            this.ccContext = ccContext;

            this.unitSphereVertices = GLHelper.CreateSphereVertices(Vector2.Zero, 1.0f, true);
        }
Exemple #8
0
        private void CreateSaveImage(ICollection <Tag> tagArray)
        {
            if (SaveCountResult == null)
            {
                return;
            }

            Size size          = ccContext.ImageSize;
            uint outputTexName = 0;

            // Generate texture
            GL.GenTextures(1, out outputTexName);
            CCContext.setupTexture(outputTexName, size, IntPtr.Zero);

            // Setup viewport
            int[] oldViewPort = new int[4];
            GL.GetInteger(GetPName.Viewport, oldViewPort);
            GL.Viewport(0, 0, size.Width, size.Height);
            int fboOld = GLHelper.bindFrameBuffer(frameBuffer, outputTexName);

            GL.Disable(EnableCap.Blend);

            Matrix4 projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, (float)size.Width, 0, (float)size.Height, -1.0f, 1.0f);
//			Matrix4 projectionMatrix = ccContext.ProjectionMatrix;
            Matrix4 modelViewMatrix = Matrix4.Identity;

            // Draw image
            {
                Matrix4   mat       = modelViewMatrix * projectionMatrix;
                Rectangle imageRect = new Rectangle(0, 0, (int)size.Width, (int)size.Height);
                GLHelper.DrawSprite(ccContext.ImageTexName, imageRect, mat);
            }

            // Draw ROI
            Vector4    outlineColor = ColorHelper.ColorToVec(ColorHelper.ROIEdge);
            Vector4    bgColor      = ColorHelper.ColorToVec(ColorHelper.ROIBackground);
            float      outlineWidth = 1.0f;
            RectangleF rect         = new RectangleF(PointF.Empty, new SizeF(size));

            CountLayerHelper.DrawROI(rect, roiSphere.center, roiSphere.radius, roiRect, roiMaskTexName, outlineColor, outlineWidth, bgColor, modelViewMatrix, projectionMatrix);

            // Regions
            CountLayerHelper.DrawRegions(regions, modelViewMatrix, projectionMatrix);

            // Draw tags
            {
                float tagSize = 16;
                CountLayerHelper.drawTags(tagArray, null, true, modelViewMatrix, projectionMatrix, tagSize);
            }

            // allocate array and read pixels into it.
            int myDataLength = size.Width * size.Height * 4;

            byte[] buffer = new byte[myDataLength];
            GL.ReadPixels(0, 0, size.Width, size.Height, PixelFormat.Rgba, PixelType.UnsignedByte, buffer);

            // Call save image event
            SaveCountResult(buffer, size, tags.Count, regions.Count);

            buffer = null;

            GL.DeleteTextures(1, ref outputTexName);

            // unbind framebuffer
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fboOld);
            GL.Viewport(oldViewPort[0], oldViewPort[1], oldViewPort[2], oldViewPort[3]);
        }