Exemplo n.º 1
0
        /// <summary>
        /// Performs image denoising using the Block-Matching and 3D-filtering algorithm
        /// (http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf) with several computational optimizations.Noise expected to be a gaussian white noise.
        /// </summary>
        /// <param name="src">Input 8-bit or 16-bit 1-channel image.</param>
        /// <param name="dst">Output image with the same size and type as src.</param>
        /// <param name="h">Parameter regulating filter strength. Big h value perfectly removes noise but also
        /// removes image details, smaller h value preserves details but also preserves some noise.</param>
        /// <param name="templateWindowSize">Size in pixels of the template patch that is used for block-matching. Should be power of 2.</param>
        /// <param name="searchWindowSize">Size in pixels of the window that is used to perform block-matching.
        ///  Affect performance linearly: greater searchWindowsSize - greater denoising time. Must be larger than templateWindowSize.</param>
        /// <param name="blockMatchingStep1">Block matching threshold for the first step of BM3D (hard thresholding),
        /// i.e.maximum distance for which two blocks are considered similar.Value expressed in euclidean distance.</param>
        /// <param name="blockMatchingStep2">Block matching threshold for the second step of BM3D (Wiener filtering),
        /// i.e.maximum distance for which two blocks are considered similar. Value expressed in euclidean distance.</param>
        /// <param name="groupSize">Maximum size of the 3D group for collaborative filtering.</param>
        /// <param name="slidingStep">Sliding step to process every next reference block.</param>
        /// <param name="beta">Kaiser window parameter that affects the sidelobe attenuation of the transform of the
        /// window.Kaiser window is used in order to reduce border effects.To prevent usage of the window, set beta to zero.</param>
        /// <param name="normType">Norm used to calculate distance between blocks. L2 is slower than L1 but yields more accurate results.</param>
        /// <param name="step">Step of BM3D to be executed. Allowed are only BM3D_STEP1 and BM3D_STEPALL.
        /// BM3D_STEP2 is not allowed as it requires basic estimate to be present.</param>
        /// <param name="transformType">Type of the orthogonal transform used in collaborative filtering step.
        /// Currently only Haar transform is supported.</param>
        public static void Bm3dDenoising(
            InputArray src,
            OutputArray dst,
            float h = 1,
            int templateWindowSize       = 4,
            int searchWindowSize         = 16,
            int blockMatchingStep1       = 2500,
            int blockMatchingStep2       = 400,
            int groupSize                = 8,
            int slidingStep              = 1,
            float beta                   = 2.0f,
            NormTypes normType           = NormTypes.L2,
            Bm3dSteps step               = Bm3dSteps.STEPALL,
            TransformTypes transformType = TransformTypes.HAAR)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.xphoto_bm3dDenoising2(
                    src.CvPtr, dst.CvPtr, h, templateWindowSize,
                    searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta,
                    (int)normType, (int)step, (int)transformType));

            GC.KeepAlive(src);
            dst.Fix();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Performs image denoising using the Block-Matching and 3D-filtering algorithm with several computational optimizations. Noise expected to be a gaussian white noise.
 /// </summary>
 /// <param name="src">Input 8-bit or 16-bit 1-channel image.</param>
 /// <param name="dstStep1">Output image of the first step of BM3D with the same size and type as src.</param>
 /// <param name="dstStep2">Output image of the second step of BM3D with the same size and type as src.</param>
 /// <param name="h">Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise.</param>
 /// <param name="templateWindowSize">Size in pixels of the template patch that is used for block-matching. Should be power of 2.</param>
 /// <param name="searchWindowSize">Size in pixels of the window that is used to perform block-matching. Affect performance linearly: greater searchWindowsSize - greater denoising time. Must be larger than templateWindowSize.</param>
 /// <param name="blockMatchingStep1">Block matching threshold for the first step of BM3D (hard thresholding), i.e. maximum distance for which two blocks are considered similar. Value expressed in euclidean distance.</param>
 /// <param name="blockMatchingStep2">Block matching threshold for the second step of BM3D (Wiener filtering), i.e. maximum distance for which two blocks are considered similar. Value expressed in euclidean distance.</param>
 /// <param name="groupSize">Maximum size of the 3D group for collaborative filtering.</param>
 /// <param name="slidingStep">Sliding step to process every next reference block.</param>
 /// <param name="beta">Kaiser window parameter that affects the sidelobe attenuation of the transform of the window. Kaiser window is used in order to reduce border effects. To prevent usage of the window, set beta to zero.</param>
 /// <param name="normType">Norm used to calculate distance between blocks. L2 is slower than L1 but yields more accurate results.</param>
 /// <param name="step">Step of BM3D to be executed. Possible variants are: step 1, step 2, both steps.</param>
 /// <param name="transformType">	Type of the orthogonal transform used in collaborative filtering step. Currently only Haar transform is supported.</param>
 /// <remarks> <c href="http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf"/>   </remarks>
 public static void Bm3dDenoising(
     IInputArray src,
     IInputOutputArray dstStep1,
     IOutputArray dstStep2,
     float h = 1,
     int templateWindowSize       = 4,
     int searchWindowSize         = 16,
     int blockMatchingStep1       = 2500,
     int blockMatchingStep2       = 400,
     int groupSize                = 8,
     int slidingStep              = 1,
     float beta                   = 2.0f,
     NormType normType            = NormType.L2,
     Bm3dSteps step               = Bm3dSteps.All,
     TransformTypes transformType = TransformTypes.Haar)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (InputOutputArray ioaDstStep1 = dstStep1.GetInputOutputArray())
             using (OutputArray oaStep2 = dstStep2.GetOutputArray())
             {
                 cveBm3dDenoising1(iaSrc, ioaDstStep1, oaStep2,
                                   h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2,
                                   groupSize, slidingStep, beta, normType, step, transformType);
             }
 }
Exemplo n.º 3
0
 public static void AddTransformation(this ITransformable transformable, TransformTypes transformType,
                                      int startTime, int endTime, Easing easing, params float[][] floats)
 {
     if (floats == null || floats.Length < 1)
     {
         return;
     }
     endTime = Math.Max(endTime, startTime);
     if (floats.Length < 3)
     {
         transformable.AddTransformation(new TransformationEvent(transformType, easing, startTime, endTime,
                                                                 floats.First(),
                                                                 floats.Last()));
     }
     else
     {
         var duration = endTime - startTime;
         for (var i = 0; i < floats.Length - 1; i++)
         {
             transformable.AddTransformation(new TransformationEvent(transformType, easing,
                                                                     startTime + duration * i,
                                                                     endTime + duration * i, floats[i], floats[i + 1]));
         }
     }
 }
Exemplo n.º 4
0
 public TransformationEvent(TransformTypes type, Easing easing, int starttime, int endtime, float[] startvalues,
                            float[] endvalues)
 {
     Transformtype = type;
     Easing        = easing;
     StartTime     = starttime;
     EndTime       = endtime;
     StartValues   = startvalues;
     EndValues     = endvalues;
 }
Exemplo n.º 5
0
 private static extern void cveBm3dDenoising2(
     IntPtr src,
     IntPtr dst,
     float h,
     int templateWindowSize,
     int searchWindowSize,
     int blockMatchingStep1,
     int blockMatchingStep2,
     int groupSize,
     int slidingStep,
     float beta,
     NormType normType,
     Bm3dSteps step,
     TransformTypes transformType);
Exemplo n.º 6
0
        public Message(QueueCmd command, TransformTypes transformType, Priority priority, string destination, string json)
        {
            MessageType   = MQTypes.MessageRequest;
            Command       = command;
            Priority      = priority;
            TransformType = transformType;
            Destination   = destination;
            if (json != null)
            {
                m_BodyStream = new NetStream(Encoding.UTF8.GetBytes(json));
            }
            //ArrivedTime = DateTime.Now;
            SetArrived();

            ItemBinary = Encoding.UTF8.GetBytes(json);
            //m_BodyStream = new NetStream(Body);
        }
Exemplo n.º 7
0
 public TransformationEvent(TransformTypes type, Easing easing, int starttime, int endtime, float[] startvalues)
     : this(type, easing, starttime, endtime, startvalues, startvalues)
 {
 }
Exemplo n.º 8
0
        public void MouseDown(MouseEventArgs e)
        {
            if (e == null)
                throw new ArgumentNullException("The argument object is 'null'");
            if (e.Button == MouseButtons.Left && Enabled && !IsSuspended)
            {

                if (Selection.SelectedItems.Count > 0)
                {
                    //let the tracker tell us if anything was hit
                    Point gripPoint = this.Controller.View.Tracker.Hit(e.Location);
                    Cursor c = null;
                    changing = false;

                    #region determine and set the corresponding cursor
                    switch (gripPoint.X)
                    {
                        case -1:
                            switch (gripPoint.Y)
                            {
                                case -1:
                                    c = Cursors.SizeNWSE;
                                    transform = TransformTypes.NW;
                                    //the origin is the right-bottom of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 0:
                                    c = Cursors.SizeWE;
                                    transform = TransformTypes.W;
                                    //the origin is the right-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 1:
                                    c = Cursors.SizeNESW;
                                    transform = TransformTypes.SW;
                                    //the origin is the right-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                            }
                            break;
                        case 0:
                            switch (gripPoint.Y)
                            {
                                case -1:
                                    c = Cursors.SizeNS;
                                    transform = TransformTypes.N;
                                    //the origin is the center-bottom of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 1:
                                    c = Cursors.SizeNS;
                                    transform = TransformTypes.S;
                                    //the origin is the left-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                            }
                            break;
                        case 1:
                            switch (gripPoint.Y)
                            {
                                case -1:
                                    c = Cursors.SizeNESW;
                                    transform = TransformTypes.NE;
                                    //the origin is the left-bottom of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 0:
                                    c = Cursors.SizeWE;
                                    transform = TransformTypes.E;
                                    //the origin is the left-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 1:
                                    c = Cursors.SizeNWSE;
                                    transform = TransformTypes.SE;
                                    //the origin is the left-top of the tracker rectangle plus the little tracker offset
                                    ox = this.Controller.View.Tracker.Rectangle.X + ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Y + ViewBase.TrackerOffset;

                                    changing = true;
                                    break;
                            }
                            break;
                    }

                    #endregion

                    if (changing)
                    {
                        //the point where the scaling or dragging of the tracker started
                        initialPoint = e.Location;
                        //recursive location of the dragging location
                        lastPoint = initialPoint;
                        //start the tool
                        this.ActivateTool();
                        //set the cursor corresponding to the grip
                        Controller.View.CurrentCursor = c;
                        //create a new collection for the transforming entities
                        transformers = new Hashtable();
                        //the points of the connectors
                        Point[] points = null;
                        //the entity bone
                        EntityBone bone;
                        //take the flat selection and keep the current state as a reference for the transformation
                        //until the mouseup pins down the final scaling
                        foreach (IDiagramEntity entity in Selection.FlattenedSelectionItems)
                        {
                            bone = new EntityBone();

                            if (entity is IShape)
                            {
                                IShape shape = entity as IShape;
                                if (shape.Connectors.Count > 0)
                                {
                                    points = new Point[shape.Connectors.Count];
                                    for (int m = 0; m < shape.Connectors.Count; m++)
                                    {
                                        points[m] = shape.Connectors[m].Point;
                                    }
                                }
                                else
                                    points = null;
                                bone.Rectangle = entity.Rectangle;
                                bone.ConnectorPoints = points;
                            }
                            else if (entity is IConnection)
                            {
                                IConnection con = entity as IConnection;
                                points = new Point[2] { Point.Empty, Point.Empty };
                                //Only non-attached connection connectors have to be scaled
                                //Attached connectors will move with their parent.
                                if (con.From.AttachedTo == null)
                                    points[0] = con.From.Point;
                                if (con.To.AttachedTo == null)
                                    points[1] = con.To.Point;
                                //We define a connection as a bone with empty rectangle
                                //One could use some additional members to label it but it's only overhead at this point.
                                bone.Rectangle = Rectangle.Empty;
                                bone.ConnectorPoints = points;
                            }
                            transformers.Add(entity, bone);
                        }
                    }
                }

            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Handles the mouse down event
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        public bool MouseDown(MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("The argument object is 'null'");
            }
            if (e.Button == MouseButtons.Left && Enabled && !IsSuspended)
            {
                if (Selection.SelectedItems.Count > 0)
                {
                    //let the tracker tell us if anything was hit
                    Point  gripPoint = this.Controller.View.Tracker.Hit(e.Location);
                    Cursor c         = null;
                    changing = false;

                    #region determine and set the corresponding cursor
                    switch (gripPoint.X)
                    {
                    case -1:
                        switch (gripPoint.Y)
                        {
                        case -1:
                            c         = Cursors.SizeNWSE;
                            transform = TransformTypes.NW;
                            //the origin is the right-bottom of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                            oy       = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 0:
                            c         = Cursors.SizeWE;
                            transform = TransformTypes.W;
                            //the origin is the right-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 1:
                            c         = Cursors.SizeNESW;
                            transform = TransformTypes.SW;
                            //the origin is the right-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;
                        }
                        break;

                    case 0:
                        switch (gripPoint.Y)
                        {
                        case -1:
                            c         = Cursors.SizeNS;
                            transform = TransformTypes.N;
                            //the origin is the center-bottom of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 1:
                            c         = Cursors.SizeNS;
                            transform = TransformTypes.S;
                            //the origin is the left-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;
                        }
                        break;

                    case 1:
                        switch (gripPoint.Y)
                        {
                        case -1:
                            c         = Cursors.SizeNESW;
                            transform = TransformTypes.NE;
                            //the origin is the left-bottom of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;
                            oy       = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 0:
                            c         = Cursors.SizeWE;
                            transform = TransformTypes.E;
                            //the origin is the left-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 1:
                            c         = Cursors.SizeNWSE;
                            transform = TransformTypes.SE;
                            //the origin is the left-top of the tracker rectangle plus the little tracker offset
                            ox = this.Controller.View.Tracker.Rectangle.X + ViewBase.TrackerOffset;
                            oy = this.Controller.View.Tracker.Rectangle.Y + ViewBase.TrackerOffset;

                            changing = true;
                            break;
                        }
                        break;
                    }

                    #endregion


                    if (changing)
                    {
                        #region Changing/transforming
                        //the point where the scaling or dragging of the tracker started
                        initialPoint = e.Location;
                        //recursive location of the dragging location
                        lastPoint = initialPoint;
                        //start the tool
                        this.ActivateTool();
                        //set the cursor corresponding to the grip
                        Controller.View.CurrentCursor = c;
                        //create a new collection for the transforming entities
                        transformers = new Hashtable();
                        //the points of the connectors
                        Point[] points = null;
                        //the entity bone
                        EntityBone bone;
                        //take the flat selection and keep the current state as a reference for the transformation
                        //until the mouseup pins down the final scaling
                        foreach (IDiagramEntity entity in Selection.FlattenedSelectionItems)
                        {
                            if (!entity.Resizable)
                            {
                                continue;                   //only take what's resizable
                            }
                            bone = new EntityBone();

                            if (entity is IShape)
                            {
                                IShape shape = entity as IShape;
                                if (shape.Connectors.Count > 0)
                                {
                                    points = new Point[shape.Connectors.Count];
                                    for (int m = 0; m < shape.Connectors.Count; m++)
                                    {
                                        points[m] = shape.Connectors[m].Point;
                                    }
                                }
                                else
                                {
                                    points = null;
                                }
                                bone.Rectangle       = entity.Rectangle;
                                bone.ConnectorPoints = points;
                            }
                            else if (entity is IConnection)
                            {
                                IConnection con = entity as IConnection;
                                points = new Point[2] {
                                    Point.Empty, Point.Empty
                                };
                                //Only non-attached connection connectors have to be scaled
                                //Attached connectors will move with their parent.
                                if (con.From.AttachedTo == null)
                                {
                                    points[0] = con.From.Point;
                                }
                                if (con.To.AttachedTo == null)
                                {
                                    points[1] = con.To.Point;
                                }
                                //We define a connection as a bone with empty rectangle
                                //One could use some additional members to label it but it's only overhead at this point.
                                bone.Rectangle       = Rectangle.Empty;
                                bone.ConnectorPoints = points;
                            }
                            transformers.Add(entity, bone);
                        }
                        #endregion

                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 10
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Sets the cursor depending on whether it's over a Tracker grip or
        /// not.
        /// </summary>
        /// <param name="e">MouseEventArgs</param>
        // ------------------------------------------------------------------
        bool UpdateCursor(MouseEventArgs e)
        {
            // Don't do anything if there isn't a Tracker!
            if (Controller.View.Tracker == null)
            {
                if (IsActive && Enabled)
                {
                    //RestoreCursor();
                }
                else
                {
                    // If we changed the cursor from the mouse being moved,
                    // and we aren't active, then the base class won't have
                    // any history of the previous cursor, so we use our own.
                    // We change the cursor on a mouse move even if this tool
                    // isn't active because we want to give visual feedback
                    // on what clicking on a grip will do.
                    if (previousCursor != null)
                    {
                        Cursor = previousCursor;
                    }
                }
                cursorChanged  = false;
                previousCursor = null;
                return(false);
            }

            // If we're not active AND another tool is active, then don't do
            // anything.  We don't want to change the cursor during a drag-drop
            // event even if the mouse moves over a grip!
            //if ((!IsActive) && (Controller.ActiveTool != null))
            //{
            //    if (previousCursor != null)
            //    {
            //        Cursor = previousCursor;
            //        cursorChanged = false;
            //    }
            //    return false;
            //}

            bool gripHit = false;
            //let the tracker tell us if anything was hit
            Point  gripPoint = this.Controller.View.Tracker.Hit(e.Location);
            Cursor c         = null;


            #region determine and set the corresponding cursor
            switch (gripPoint.X)
            {
            case -1:
                switch (gripPoint.Y)
                {
                case -1:
                    c         = Cursors.SizeNWSE;
                    transform = TransformTypes.NW;
                    //the origin is the right-bottom of the rectangle
                    ox      = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                    oy      = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                    gripHit = true;
                    break;

                case 0:
                    c         = Cursors.SizeWE;
                    transform = TransformTypes.W;
                    //the origin is the right-top of the rectangle
                    ox      = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                    oy      = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                    gripHit = true;
                    break;

                case 1:
                    c         = Cursors.SizeNESW;
                    transform = TransformTypes.SW;
                    //the origin is the right-top of the rectangle
                    ox      = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                    oy      = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                    gripHit = true;
                    break;
                }
                break;

            case 0:
                switch (gripPoint.Y)
                {
                case -1:
                    c         = Cursors.SizeNS;
                    transform = TransformTypes.N;
                    //the origin is the center-bottom of the rectangle
                    ox      = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                    oy      = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                    gripHit = true;
                    break;

                case 1:
                    c         = Cursors.SizeNS;
                    transform = TransformTypes.S;
                    //the origin is the left-top of the rectangle
                    ox      = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                    oy      = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                    gripHit = true;
                    break;
                }
                break;

            case 1:
                switch (gripPoint.Y)
                {
                case -1:
                    c         = Cursors.SizeNESW;
                    transform = TransformTypes.NE;
                    //the origin is the left-bottom of the rectangle
                    ox      = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;
                    oy      = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                    gripHit = true;
                    break;

                case 0:
                    c         = Cursors.SizeWE;
                    transform = TransformTypes.E;
                    //the origin is the left-top of the rectangle
                    ox      = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                    oy      = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                    gripHit = true;
                    break;

                case 1:
                    c         = Cursors.SizeNWSE;
                    transform = TransformTypes.SE;
                    //the origin is the left-top of the tracker rectangle plus the little tracker offset
                    ox = this.Controller.View.Tracker.Rectangle.X + ViewBase.TrackerOffset;
                    oy = this.Controller.View.Tracker.Rectangle.Y + ViewBase.TrackerOffset;

                    gripHit = true;
                    break;
                }
                break;
            }

            #endregion

            if (gripHit)
            {
                if (Cursor != c)
                {
                    previousCursor = Cursor;
                    Cursor         = c;
                    cursorChanged  = true;
                }
            }
            else if (cursorChanged)
            {
                Cursor         = Cursors.Default;
                previousCursor = null;
                cursorChanged  = false;
            }
            return(gripHit);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Build a list of all the classes in an FGD, without resolving inheritance.
        /// </summary>
        private List <Definition> GetFlatClassList(List <string> raw)
        {
            var flat = new List <Definition>();

            int blockStart = 0;

            while (blockStart < raw.Count)
            {
                int blockLength = GetBlockLength(raw, blockStart);

                List <string> block = raw.GetRange(blockStart, blockLength);

                var def = new Definition()
                {
                    DefinitionCollection = this,
                    Saveability          = Saveability.All
                };

                int blockOffset = 0;
                while (blockOffset < block.Count - 1)
                {
                    if (block[blockOffset].StartsWith("@"))
                    {
                        List <string> header = block.GetRange(blockOffset, block.IndexOf("[", blockOffset));

                        string type = header[0].Substring(1).ToLower();
                        if (type == "pointclass")
                        {
                            def.ClassType = ClassType.Point;
                            def.RenderableTransformability = Transformability.Translate;
                        }
                        else if (type == "solidclass")
                        {
                            def.ClassType = ClassType.Solid;
                            def.RenderableSources.Add(RenderableSource.Solids, "");
                            def.RenderableTransformability = Transformability.All;
                        }
                        else
                        {
                            def.ClassType   = ClassType.Base;
                            def.Saveability = Saveability.None;
                            def.RenderableTransformability = Transformability.None;
                        }

                        int classnameStart  = header.IndexOf("=") + 1;
                        int classnameLength = header.IndexOf(":") - classnameStart;
                        if (classnameLength < 0)
                        {
                            classnameLength = header.Count - classnameStart;
                        }
                        def.ClassName = String.Join("", header.GetRange(classnameStart, classnameLength));

                        int descriptionStart = header.IndexOf(":") + 1;
                        if (descriptionStart > 0)
                        {
                            int descriptionLength = header.Count - descriptionStart;
                            def.Description = String.Join(" ", header.GetRange(descriptionStart, descriptionLength));
                            def.Description = def.Description.TrimStart('\"').TrimEnd('\"');
                        }

                        if (header.Contains("base"))
                        {
                            List <string> vals = ExtractHeaderProperty("base", header);

                            foreach (string value in vals)
                            {
                                def.BaseNames.Add(value);
                            }
                        }

                        if (header.Contains("color"))
                        {
                            List <string> vals = ExtractHeaderProperty("color", header);

                            Int32.TryParse(vals[0], out int red);
                            Int32.TryParse(vals[1], out int green);
                            Int32.TryParse(vals[2], out int blue);

                            var color = new Color4()
                            {
                                R = red / 255.0f,
                                G = green / 255.0f,
                                B = blue / 255.0f,
                                A = 1.0f
                            };

                            def.Color = color;
                        }
                        else
                        {
                            // Color can't be assigned null, so there's no easy
                            // way to determine whether the FGD provided a color
                            // or not; since FGDs don't have any facility for
                            // dictating alpha, however, setting it to 0 works.
                            def.Color = new Color4(0.0f, 0.0f, 0.0f, 0.0f);
                        }

                        if (header.Contains("flags"))
                        {
                            List <string> flags = ExtractHeaderProperty("flags", header);

                            if (flags.Contains("Angle"))
                            {
                                def.KeyValsTemplate.Add("angles", new Option()
                                {
                                    TransformType = TransformType.Angles
                                });
                            }
                        }

                        if (header.Contains("iconsprite"))
                        {
                            List <string> path = ExtractHeaderProperty("iconsprite", header);

                            def.RenderableSources.Add(RenderableSource.Sprite, path[0]);
                        }

                        if (header.Contains("offset"))
                        {
                            List <string> vals = ExtractHeaderProperty("offset", header);

                            var offset = new Vector3();
                            Single.TryParse(vals[0], out offset.X);
                            Single.TryParse(vals[1], out offset.Y);
                            Single.TryParse(vals[2], out offset.Z);

                            def.Offset = offset;
                        }

                        if (header.Contains("size"))
                        {
                            List <string> vals = ExtractHeaderProperty("size", header);

                            var size = new Aabb();

                            // Size defined by custom min and max.
                            if (vals.Count == 6)
                            {
                                var min = new Vector3();
                                Single.TryParse(vals[0], out min.X);
                                Single.TryParse(vals[1], out min.Y);
                                Single.TryParse(vals[2], out min.Z);

                                var max = new Vector3();
                                Single.TryParse(vals[3], out max.X);
                                Single.TryParse(vals[4], out max.Y);
                                Single.TryParse(vals[5], out max.Z);

                                size.Min = min;
                                size.Max = max;
                            }
                            // Size defined by width, depth, and height.
                            else
                            {
                                Single.TryParse(vals[0], out float width);
                                Single.TryParse(vals[1], out float depth);
                                Single.TryParse(vals[2], out float height);

                                size.Max = new Vector3()
                                {
                                    X = width / 2.0f,
                                    Y = depth / 2.0f,
                                    Z = height / 2.0f
                                };

                                size.Min = -size.Max;
                            }

                            def.Size = size;

                            def.RenderableSources.Add(RenderableSource.Size, String.Empty);
                        }

                        if (header.Contains("sprite"))
                        {
                            List <string> path = ExtractHeaderProperty("sprite", header);

                            def.RenderableSources.Add(RenderableSource.Sprite, path[0]);
                        }

                        if (header.Contains("studio"))
                        {
                            List <string> paths = ExtractHeaderProperty("studio", header);

                            string path = paths.Count > 0 ? paths[0] : null;

                            def.RenderableSources.Add(RenderableSource.Model, path);
                        }

                        if (header.Contains("instance"))
                        {
                            string value = ExtractHeaderProperty("instance", header)[0];

                            def.RenderableSources.Add(RenderableSource.Key, value);

                            def.Saveability = Saveability.Entity;
                        }

                        blockOffset += header.Count;
                    }
                    else if (block[blockOffset].ToLower() == "spawnflags")
                    {
                        blockOffset = block.IndexOf("[", blockOffset);

                        int closeBracket = FindClosingDelimiter(block, blockOffset);

                        while (blockOffset != closeBracket)
                        {
                            if (block[blockOffset] != "[")
                            {
                                var flag = new Spawnflag();

                                string flagKey = block[blockOffset];
                                blockOffset += 2;

                                flag.Description = block[blockOffset].TrimStart('\"').TrimEnd('\"');
                                blockOffset++;

                                bool hasDefault = block[blockOffset] == ":" && block[blockOffset + 1] != ":";
                                if (hasDefault)
                                {
                                    blockOffset++;
                                    flag.Default = block[blockOffset];
                                    blockOffset++;
                                }

                                bool hasRemarks = block[blockOffset] == ":" && block[blockOffset + 1].StartsWith("\"");
                                if (hasRemarks)
                                {
                                    blockOffset++;
                                    flag.Remarks = block[blockOffset].TrimStart('\"').TrimEnd('\"');
                                    blockOffset++;
                                }

                                def.Flags.Add(flagKey, flag);
                            }
                            else
                            {
                                blockOffset++;
                            }
                        }

                        blockOffset++;
                    }
                    else if (block[blockOffset + 1] == "(")
                    {
                        var option = new Option();

                        string key = block[blockOffset].ToLower();
                        blockOffset += 2;

                        option.Type  = block[blockOffset].ToLower();
                        blockOffset += 3;

                        int choicesFirst = -1;
                        int choicesLast  = -1;
                        if (option.Type == "choices")
                        {
                            choicesFirst = block.IndexOf("[", blockOffset);
                            choicesLast  = FindClosingDelimiter(block, choicesFirst);

                            foreach ((string k, string v) in ExtractChoices(block, choicesFirst))
                            {
                                option.Choices.Add(k, v);
                            }
                        }

                        if (TransformTypeOverrides.ContainsKey(key))
                        {
                            option.TransformType = TransformTypeOverrides[key];
                        }
                        else if (TransformTypes.ContainsKey(option.Type))
                        {
                            option.TransformType = TransformTypes[option.Type];
                        }
                        else
                        {
                            option.TransformType = TransformType.None;
                        }

                        option.Description = block[blockOffset].TrimStart('\"').TrimEnd('\"');
                        blockOffset++;

                        // If there's nothing after the description, there's no
                        // more work to do for this option.
                        if (block[blockOffset] != ":")
                        {
                            if (def.KeyValsTemplate.ContainsKey(key))
                            {
                                def.KeyValsTemplate[key] = option;
                            }
                            else
                            {
                                def.KeyValsTemplate.Add(key, option);
                            }

                            if (choicesLast > -1)
                            {
                                blockOffset = choicesLast;
                            }
                            continue;
                        }
                        blockOffset++;

                        // If there is a colon after the description, there's at
                        // least space for a default value, even if it's blank.
                        bool defaultIsBlank = block[blockOffset] == ":" || block[blockOffset] == "=";
                        if (!defaultIsBlank)
                        {
                            option.Default = block[blockOffset].TrimStart('\"').TrimEnd('\"');
                            blockOffset++;
                        }

                        bool hasRemarks = block[blockOffset] == ":" && block[blockOffset + 1].StartsWith("\"");
                        if (hasRemarks)
                        {
                            blockOffset++;
                            option.Remarks = block[blockOffset].TrimStart('\"').TrimEnd('\"');
                            blockOffset++;
                        }

                        if (def.KeyValsTemplate.ContainsKey(key))
                        {
                            def.KeyValsTemplate[key] = option;
                        }
                        else
                        {
                            def.KeyValsTemplate.Add(key, option);
                        }
                    }
                    else
                    {
                        blockOffset++;
                    }
                }

                if (def.ClassType == ClassType.Point && !def.KeyValsTemplate.ContainsKey("origin"))
                {
                    def.KeyValsTemplate.Add("origin", new Option()
                    {
                        TransformType = TransformType.Position
                    });
                }

                if (!def.KeyValsTemplate.ContainsKey("classname"))
                {
                    def.KeyValsTemplate.Add("classname", new Option());
                }

                flat.Add(def);

                blockStart += blockLength;
            }

            return(flat);
        }
Exemplo n.º 12
0
    // ------------------------------------------------------------------
    /// <summary>
    /// Sets the cursor depending on whether it's over a Tracker grip or
    /// not.
    /// </summary>
    /// <param name="e">MouseEventArgs</param>
    // ------------------------------------------------------------------
    bool UpdateCursor(MouseEventArgs e) {
      // Don't do anything if there isn't a Tracker!
      if (Controller.View.Tracker == null) {
        if (IsActive && Enabled) {
          //RestoreCursor();
        } else {
          // If we changed the cursor from the mouse being moved,
          // and we aren't active, then the base class won't have
          // any history of the previous cursor, so we use our own.
          // We change the cursor on a mouse move even if this tool
          // isn't active because we want to give visual feedback
          // on what clicking on a grip will do.
          if (previousCursor != null) {
            Cursor = previousCursor;
          }
        }
        cursorChanged = false;
        previousCursor = null;
        return false;
      }

      // If we're not active AND another tool is active, then don't do
      // anything.  We don't want to change the cursor during a drag-drop
      // event even if the mouse moves over a grip!
      //if ((!IsActive) && (Controller.ActiveTool != null))
      //{
      //    if (previousCursor != null)
      //    {
      //        Cursor = previousCursor;
      //        cursorChanged = false;
      //    }
      //    return false;
      //}

      bool gripHit = false;
      //let the tracker tell us if anything was hit
      Point gripPoint = this.Controller.View.Tracker.Hit(e.Location);
      Cursor c = null;


      #region determine and set the corresponding cursor
      switch (gripPoint.X) {
        case -1:
          switch (gripPoint.Y) {
            case -1:
              c = Cursors.SizeNWSE;
              transform = TransformTypes.NW;
              //the origin is the right-bottom of the rectangle
              ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
              oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
              gripHit = true;
              break;
            case 0:
              c = Cursors.SizeWE;
              transform = TransformTypes.W;
              //the origin is the right-top of the rectangle
              ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
              oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
              gripHit = true;
              break;
            case 1:
              c = Cursors.SizeNESW;
              transform = TransformTypes.SW;
              //the origin is the right-top of the rectangle
              ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
              oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
              gripHit = true;
              break;
          }
          break;
        case 0:
          switch (gripPoint.Y) {
            case -1:
              c = Cursors.SizeNS;
              transform = TransformTypes.N;
              //the origin is the center-bottom of the rectangle
              ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
              oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
              gripHit = true;
              break;
            case 1:
              c = Cursors.SizeNS;
              transform = TransformTypes.S;
              //the origin is the left-top of the rectangle
              ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
              oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
              gripHit = true;
              break;
          }
          break;
        case 1:
          switch (gripPoint.Y) {
            case -1:
              c = Cursors.SizeNESW;
              transform = TransformTypes.NE;
              //the origin is the left-bottom of the rectangle
              ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;
              oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
              gripHit = true;
              break;
            case 0:
              c = Cursors.SizeWE;
              transform = TransformTypes.E;
              //the origin is the left-top of the rectangle
              ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
              oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
              gripHit = true;
              break;
            case 1:
              c = Cursors.SizeNWSE;
              transform = TransformTypes.SE;
              //the origin is the left-top of the tracker rectangle plus the little tracker offset
              ox = this.Controller.View.Tracker.Rectangle.X + ViewBase.TrackerOffset;
              oy = this.Controller.View.Tracker.Rectangle.Y + ViewBase.TrackerOffset;

              gripHit = true;
              break;
          }
          break;
      }

      #endregion

      if (gripHit) {
        if (Cursor != c) {
          previousCursor = Cursor;
          Cursor = c;
          cursorChanged = true;
        }
      } else if (cursorChanged) {
        Cursor = Cursors.Default;
        previousCursor = null;
        cursorChanged = false;
      }
      return gripHit;
    }