コード例 #1
0
ファイル: GridTransform.cs プロジェクト: abordt/Viking
 public GridTransform(SerializationInfo info, StreamingContext context)
 {
     _mapPoints = info.GetValue("_mapPoints", typeof(MappingGridVector2[])) as MappingGridVector2[];
     _TriangleIndiciesCache = info.GetValue("_TriangleIndiciesCache", typeof(int[])) as int[];
     _CachedMappedBounds = (GridRectangle)info.GetValue("_CachedMappedBounds", typeof(GridRectangle));
     _CachedControlBounds = (GridRectangle)info.GetValue("_CachedControlBounds", typeof(GridRectangle));
     LastModified = info.GetDateTime("LastModified");
 }
コード例 #2
0
        protected ReferencePointBasedTransform(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            if (info == null)
                throw new ArgumentNullException();

            _mapPoints = info.GetValue("_mapPoints", typeof(MappingGridVector2[])) as MappingGridVector2[];
            MappedBounds = (GridRectangle)info.GetValue("MappedBounds", typeof(GridRectangle));
            ControlBounds = (GridRectangle)info.GetValue("ControlBounds", typeof(GridRectangle));
        }
コード例 #3
0
ファイル: GridTransform.cs プロジェクト: abordt/Viking
        /// <summary>
        /// Use this to set points and triangles so we don't have to run the delaunay algorithm.
        /// </summary>
        /// <param name="points"></param>
        /// <param name="triangleIndicies"></param>
        public void SetPointsAndTriangles(MappingGridVector2[] points, int[] triangleIndicies)
        {
            #if DEBUG
            //Check for duplicate points
            for (int i = 1; i < points.Length; i++)
            {
                Debug.Assert(points[i - 1].ControlPoint != points[i].ControlPoint, "Duplicate Points found in transform.  This breaks Delaunay.");
            }
            #endif
            _mapPoints = points;
            _TriangleIndiciesCache = triangleIndicies;

            this._CachedMappedBounds = MappingGridVector2.CalculateMappedBounds(this.mapPoints);
            this._CachedControlBounds = MappingGridVector2.CalculateControlBounds(this.mapPoints);
        }
コード例 #4
0
        public void ThreadPoolCallback(Object threadContext)
        {
            List<MappingGridVector2> newPointsList = new List<MappingGridVector2>(iPoints.Length);

            foreach(int iPoint in iPoints)
            {
                MappingGridVector2 UnmappedPoint = warpingTransform.MapPoints[iPoint];
                GridVector2 newControl;
                bool TransformSuccess = fixedTransform.TryTransform(UnmappedPoint.ControlPoint, out newControl);
                if (TransformSuccess)
                {
                    newPointsList.Add( new MappingGridVector2(newControl, UnmappedPoint.MappedPoint) );
                }
                else
                {
                    this.AllPointsTransformed = false;
                    //In this case we need to test each edge connecting this point to other points.
                    List<int> MovingEdgeIndicies = warpingTransform.Edges[iPoint];

                    //Find out which of these edge points intersect triangles in the fixed warp.  If they are inside the control warp
                    //triangle mesh we find the point where the edge intersects the fixed warp mesh.
                    for (int iEdge = 0; iEdge < MovingEdgeIndicies.Count; iEdge++)
                    {
                        int iEdgePoint = MovingEdgeIndicies[iEdge];

                        GridLineSegment ctrlLine = new GridLineSegment(UnmappedPoint.ControlPoint, this.warpingTransform.MapPoints[iEdgePoint].ControlPoint);
                        GridLineSegment mapLine = new GridLineSegment(UnmappedPoint.MappedPoint, this.warpingTransform.MapPoints[iEdgePoint].MappedPoint);

                        GridLineSegment foundCtrlLine; //Control line found in nearest line call
                        GridLineSegment foundMapLine; //Corresponding map line found in nearest line call
                        GridVector2 intersect;

                        //Find out if there is a line in the fixed transform we intersect with.
                        double distance = fixedTransform.ConvexHullIntersection(ctrlLine, UnmappedPoint.ControlPoint, out foundCtrlLine, out foundMapLine, out intersect);
                        if (distance == double.MaxValue)
                            continue;

                        if (fixedTransform.GetTransform(this.warpingTransform.MapPoints[iEdgePoint].ControlPoint) == null)
                            continue;

                        //Translate from the fixed transform map space into control space.
                        GridVector2 newCtrlPoint;
                        {

                            //Determine how far along the mapping line on the fixed transfrom is the intersect point.
                            double mapLineDistance = GridVector2.Distance(foundMapLine.A, intersect);
                            double mapLineFraction = mapLineDistance / foundMapLine.Length;

                            //How far along the corresponding control line are we?
                            double ctrlLineDistance = foundCtrlLine.Length * mapLineFraction;

                            newCtrlPoint = foundCtrlLine.Direction; //Get unit vector describing direction and scale it
                            newCtrlPoint.Scale(ctrlLineDistance);
                            newCtrlPoint = newCtrlPoint + foundCtrlLine.A;
                        }

                        //Now we must find out where the point on the warping transform is by checking how far along the mapping line on the warping transform we were.
                        GridVector2 newMapPoint;
                        {
                            //Figure out where the transformed point lies in the moving transform mapped space.
                            //Make sure we measure from the same origin on both mapped and control lines
                            double CtrlLineDistance = GridVector2.Distance(ctrlLine.A, intersect);
                            double fraction = CtrlLineDistance / ctrlLine.Length;

                            Debug.Assert(fraction <= 1.0 && fraction >= 0.0);
                            if (fraction > 1f)
                                fraction = 1f;
                            else if (fraction < 0f)
                                fraction = 0f;

                            double mappedDistance = mapLine.Length * fraction;

                            newMapPoint = mapLine.Direction;
                            newMapPoint.Scale(mappedDistance);
                            newMapPoint = newMapPoint + mapLine.A;
                        }

                        newPointsList.Add(new MappingGridVector2(newCtrlPoint, newMapPoint));
                    }

                }
            }

            MappingGridVector2.RemoveDuplicates(newPointsList);
            newPoints = newPointsList.ToArray();
            DoneEvent.Set();
        }
コード例 #5
0
 public TriangulationViewModel(MappingGridVector2[] mapPoints, int[] triangleIndicies)
 {
     this.MapPoints = mapPoints;
     this.TriangleIndicies = triangleIndicies;
 }
コード例 #6
0
 public TriangulationViewModel(TriangulationTransform Mapping)
 {
     this.MapPoints = Mapping.MapPoints;
     this.TriangleIndicies = Mapping.TriangleIndicies;
 }