Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        // Should be called from GL thread
        public void RenderUpdate(RectangleF rect)
        {
            //if (bUpdateImage) {
            //	bUpdateImage = false;

            //	Console.WriteLine("CountLayerContext UPDATE IMAGE");

            //	CCContext.setupTexture (maskTexName, ccContext.ImageSize, IntPtr.Zero);

            //	int[] oldViewPort = new int[4];
            //	GL.GetInteger (GetPName.Viewport, oldViewPort);
            //	GL.Viewport (0, 0, ccContext.ImageSize.Width, ccContext.ImageSize.Height);
            //	int fboOld = GLHelper.bindFrameBuffer (frameBuffer, maskTexName);

            //	// Clear texture
            //	GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            //	GL.Clear (ClearBufferMask.ColorBufferBit);

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

            //	bUpdateROI = true;
            //	bUpdateROIThreshold = true;
            //	bUpdateSeqmentation = true;
            //}


            //if (bUpdateROI) {
            //	bUpdateROI = false;
            //	Console.WriteLine("CountLayerContext UPDATE ROI");
            //	UpdateROI();
            //	bUpdateROIThreshold = true;
            //}

            List <Tag> tagsCopy = null;

            lock (tags) {
                tagsCopy = new List <Tag>(tags);
            }

            //if (bLateUpdateSegmentation) {

            //	bLateUpdateSegmentation = false;
            //	Console.WriteLine("CountLayerContext LATE UPDATE SEGMENTATION");

            //	// End running calc region task
            //	if (cCalcRegionTokenSource != null) {
            //		cCalcRegionTokenSource.Cancel ();
            //		calcRegionTask = null;
            //	}

            //	if(bUpdateROIThreshold && tagsCopy.Count == 0)
            //	{
            //		CountLayerHelper.GetROIThreshold(roiRect, segmentationPixelData, roiThresholdMin, roiThresholdMax, frameBuffer, roiTexName);
            //		bUpdateROIThreshold = false;
            //	}

            //	CountLayerHelper.UpdateThresholds (tagsCopy, roiRect, frameBuffer, roiTexName);

            //	GLHelper.GetError ();

            //	// Stop region task
            //	CountLayerHelper.UpdateSegmentation (tagsCopy, roiRect, frameBuffer, thresholdTexName, roiTexName,
            //	                             segmentationPixelData, roiThresholdMin, roiThresholdMax);

            //	GLHelper.GetError ();

            //	// Start calc region task
            //	regions.Clear();
            //	incommingRegions.Clear();
            //	CountLayerHelper.SCalcRegionTask calcRegionTaskData = new CountLayerHelper.SCalcRegionTask ();
            //	calcRegionTaskData.pixelData = segmentationPixelData;
            //	calcRegionTaskData.roiRect = roiRect;
            //	calcRegionTaskData.tags = tagsCopy.ToArray();
            //	calcRegionTaskData.debugTexture = debugTexture;
            //	calcRegionTaskData.debugTexture.Clear ();
            //	calcRegionTaskData.bDebugDrawEDM = false;
            //	calcRegionTaskData.bDebugDrawRegions = false;
            //	calcRegionTaskData.startTime = DateTime.Now;
            //	calcRegionTaskData.regions = new List<Region>();
            //	calcRegionTaskData.regionAdded += delegate(object sender, EventArgs e) {

            //		lock(incommingRegions) {
            //			incommingRegions.Add (sender as Region);
            //		};
            //		ccContext.RequestRender ();
            //		//					if (CountLayerUpdated != null) {
            //		//						CountLayerUpdated (tags.Count, regions.Count);
            //		//					}
            //	};

            //	cCalcRegionTokenSource = new CancellationTokenSource ();
            //	CancellationToken cToken = cCalcRegionTokenSource.Token;

            //	calcRegionTask = Task.Factory.StartNew<CountLayerHelper.SCalcRegionTask> (() => CountLayerHelper.calcRegions (cToken, calcRegionTaskData), cToken);
            //	calcRegionTask.ContinueWith (task => {
            //		// Request render so we can get task result in render thread
            //		ccContext.RequestRender ();
            //	});
            //}

            //// Handle incomming regions
            //lock(incommingRegions) {
            //	if(incommingRegions.Count > 0) {
            //		regions.AddRange(incommingRegions);
            //		incommingRegions.Clear();
            //	}
            //};


            //// Trigger segmentation update next frame
            //if(bUpdateSeqmentation) {
            //	bUpdateSeqmentation = false;
            //	bLateUpdateSegmentation = true;
            //	Console.WriteLine("CountLayerContext UPDATE SEGMENTATION");
            //	ccContext.RequestRender ();
            //}

            //// Check calc region task
            //if (calcRegionTask != null && calcRegionTask.IsCompleted) { //calcRegionTaskComplete)
            //	CountLayerHelper.SCalcRegionTask taskData = calcRegionTask.Result;

            //	ICollection<Region> result = taskData.regions;

            //	TimeSpan span = DateTime.Now.Subtract(taskData.startTime);
            //	Console.WriteLine("CountLayerContext REGION RESULT (duration:"+span.TotalSeconds+")");

            //	regions.Clear ();
            //	regions.AddRange (result);
            //	calcRegionTask = null;

            //	if (CountLayerUpdated != null) {
            //		CountLayerUpdated (tagsCopy.Count, regions.Count);
            //	}
            //}

            // RENDERING !!!

            // Clear background
            GLHelper.GetError();
            GL.ClearColor(1.0f, 0.0f, 0.0f, 1);
            GLHelper.GetError();
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GLHelper.GetError();

            Matrix4 mat = ccContext.ModelViewMatrix * ccContext.ProjectionMatrix;

            // Draw image
            {
                Rectangle imageRect = new Rectangle(0, 0, (int)ccContext.ImageSize.Width, (int)ccContext.ImageSize.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;
            //	if (activeTool == Tool.ROIEdit) {
            //		bool selected = selectedPrim != null && selectedPrim.GetPrimitive () == roiSphere;
            //		outlineColor = selected ? ColorHelper.ColorToVec(ColorHelper.ROIEdgeSelected) : ColorHelper.ColorToVec(ColorHelper.ROIEdgeActive);
            //		bgColor = ColorHelper.ColorToVec(ColorHelper.ROIBackgroundActive);
            //		outlineWidth = 2;
            //	}
            //	CountLayerHelper.DrawROI (rect, roiSphere.center, roiSphere.radius, roiRect, roiMaskTexName, outlineColor, outlineWidth, bgColor, ccContext.ModelViewMatrix, ccContext.ProjectionMatrix);
            //}

//			// Draw debug texture
//			bool bDragDebugTexture = false;
//			if (bDragDebugTexture) {
//				debugTexture.prepareForRender ();
////				GLHelper.DrawSprite(debugTexName, roiRect, mat);
////				GLHelper.DrawSprite(roiTexName, roiRect, mat);
//				GLHelper.DrawSprite (roiMaskTexName, roiRect, mat);
//			}

            //{
            //	CountLayerHelper.DrawRegions (regions, ccContext.ModelViewMatrix, ccContext.ProjectionMatrix);
            //}

            // Draw tags
            {
                Tag selectedTag = selectedPrim != null?selectedPrim.GetPrimitive() as Tag : null;

                bool  layerActive = activeTool == Tool.TagCreate || activeTool == Tool.TagDelete;
                float tagSize     = ccContext.TagSize;
                CountLayerHelper.drawTags(tagsCopy, selectedTag, layerActive, ccContext.ModelViewMatrix, ccContext.ProjectionMatrix, tagSize);
            }

            if (bRequestSaveImage)
            {
                bRequestSaveImage = false;
                CreateSaveImage(tagsCopy);
            }
        }