protected void OnBezierPointReplaced(CatPoint point, CatPoint newPoint) { if (point != newPoint) { //for (int i = 0; i < points.Length; i++) // if (points[i] == point) // points[i] = newPoint; for (int i = 0; i < pointsOrdererd.GetLength(1); i++) { for (int j = 0; j < pointsOrdererd.GetLength(0); j++) { if (pointsOrdererd[j, i] == point) { pointsOrdererd[j, i] = newPoint; } } } ParametrizationChanged = true; Changed = true; point.OnChanged -= OnBezierPointChanged; if (owner) { point.DependentUnremovable -= 1; } newPoint.OnChanged += OnBezierPointChanged; if (owner) { newPoint.DependentUnremovable += 1; } newPoint.OnChanged += OnBezierPointChanged; newPoint.OnReplace += OnBezierPointReplaced; } }
protected virtual void AddPoint(CatPoint point, bool generateLater = true) { point.OnDeleted += OnPointDeleted; point.OnChanged += OnPointChanged; point.OnReplace += OnPointReplacement; points.Add(new PointWrapper(point)); }
public virtual void RemovePoint(CatPoint point, bool removeDelegate) { var pt = points.FirstOrDefault(x => x.Point == point); if (pt != null) { RemovePoint(pt, removeDelegate); } }
public SingleGregoryPatch(GregoryPatch parent, AdjacentHalfPatch left, AdjacentHalfPatch right, CatPoint centerPoint) { p00 = left.RightNearest[3]; p00.OnChanged += PointOnChanged; p10 = left.RightNearest[2]; p10.OnChanged += PointOnChanged; p20 = left.RightNearest[1]; p20.OnChanged += PointOnChanged; p30 = left.RightNearest[0]; p30.OnChanged += PointOnChanged; p01 = right.LeftNearest[1]; p01.OnChanged += PointOnChanged; p02 = right.LeftNearest[2]; p02.OnChanged += PointOnChanged; p03 = right.LeftNearest[3]; p03.OnChanged += PointOnChanged; p13 = right.LeftBack[2]; p13.OnChanged += PointOnChanged; p23 = right.P1I; p23.OnChanged += PointOnChanged; p33 = centerPoint; p33.OnChanged += PointOnChanged; p31 = left.RightBack[0]; p31.OnChanged += PointOnChanged; p32 = left.P1I; p32.OnChanged += PointOnChanged; p01P = right.LeftBack[0]; p01P.OnChanged += PointOnChanged; p02P = right.LeftBack[1]; p02P.OnChanged += PointOnChanged; p13P = right.LeftBack[1]; p13P.OnChanged += PointOnChanged; p23P = right.NormalL1; p23P.OnChanged += PointOnChanged; p10P = left.RightBack[2]; p10P.OnChanged += PointOnChanged; p20P = left.RightBack[1]; p20P.OnChanged += PointOnChanged; p31P = left.RightBack[1]; p31P.OnChanged += PointOnChanged; p32P = left.NormalR1; p32P.OnChanged += PointOnChanged; this.parent = parent; parent.PropertyChanged += Parent_PropertyChanged; RecalculateMesh(); }
private void OnPointReplaced(CatPoint point, CatPoint newPoint) { point.OnReplace -= OnPointReplaced; point.DependentUnremovable -= 1; catPoints.Remove(point); if (!catPoints.Contains(newPoint)) { catPoints.Add(newPoint); newPoint.DependentUnremovable += 1; newPoint.OnReplace += OnPointReplaced; } }
private Vector2 IndexOf(CatPoint point) { for (int i = 0; i < pointsOrdererd.GetLength(1); i++) { for (int j = 0; j < pointsOrdererd.GetLength(0); j++) { if (pointsOrdererd[j, i] == point) { return(new Vector2(i, j)); } } } return(new Vector2(-1, -1)); }
private void OnBerensteinPointChanged(CatPoint point) { if (listenToBerensteinChanges) { listenToBerensteinChanges = false; int berensteinPtNumber = berensteinPoints.IndexOf(point); if (berensteinPtNumber < 0 || berensteinPtNumber >= berensteinPoints.Count) { throw new InvalidOperationException("Invalid berenstein point index"); } if (berensteinPtNumber % 3 == 0) { var a = berensteinPtNumber / 3; var b = a + 1; var c = a + 2; var aPt = points[a]; var bPt = points[b]; var cPt = points[c]; bPt.Point.Position = (point.Position * 6 - aPt.Point.Position - cPt.Point.Position) / 4; UpdateBerensteinPoints(); } else { int ber = berensteinPtNumber / 3; // number of berenstein polygon int prev = ber + 1; int next = ber + 2; if (berensteinPtNumber % 3 == 1) { var tmp = prev; prev = next; next = tmp; } var prevPt = points[prev]; var nextPt = points[next]; nextPt.Point.Position = prevPt.Point.Position + (point.Position - prevPt.Point.Position) * (3 / 2.0f); } listenToBerensteinChanges = true; } }
protected virtual void OnPointReplacement(CatPoint point, CatPoint newPoint) { var pt = points.FirstOrDefault(x => x.Point == point); if (pt == null) { throw new Exception("Bad curve was informed about replacement"); } pt.Point.OnChanged -= OnPointChanged; pt.Point.OnDeleted -= OnPointDeleted; pt.Point = newPoint; pt.Point.OnDeleted += OnPointChanged; pt.Point.OnDeleted += OnPointDeleted; pt.Point.OnReplace += OnPointReplacement; }
protected override void AddPoint(CatPoint point, bool generateLater = true) { base.AddPoint(point, generateLater); switch (currentType) { case BezierType.Berenstein: point.Visible = false; break; case BezierType.BSpline: point.Visible = true; break; } if (!generateLater) { GenerateBerensteinPoints(); } }
public bool ContainsNearby(CatPoint prev, CatPoint next) { return(false); int ind; if (pointsOrdererd[0, 0] == prev) { ind = 0; } else if (pointsOrdererd[0, 3] == prev) { ind = 3; } else if (pointsOrdererd[3, 0] == prev) { ind = 12; } else if (pointsOrdererd[3, 3] == prev) { ind = 15; } else { throw new Exception("Something failed"); } switch (ind) { case 0: return(pointsOrdererd[0, 3] == next || pointsOrdererd[3, 0] == next); case 3: return(pointsOrdererd[0, 0] == next || pointsOrdererd[3, 3] == next); case 12: return(pointsOrdererd[0, 0] == next || pointsOrdererd[3, 3] == next); case 15: return(pointsOrdererd[0, 3] == next || pointsOrdererd[3, 0] == next); } return(false); }
public GregoryPatch(PatchCycle cycle, SceneData data) { this.cycle = cycle; this.data = data; centerPoint = data.CreateHiddenCatPoint(new Vector3()); adjacentPatches = new List <AdjacentHalfPatch>(cycle.Patches.Count); for (int i = 0; i < cycle.Patches.Count; i++) { adjacentPatches.Add(new AdjacentHalfPatch(cycle.Patches[i].GetDataBetweenPoints(cycle.Points[i], cycle.Points[(i + 1) % cycle.Points.Count]), data, centerPoint)); } for (int i = 0; i < adjacentPatches.Count; i++) { int l = i - 1; if (l < 0) { l += adjacentPatches.Count; } adjacentPatches[i].leftP1 = adjacentPatches[l].P1I; adjacentPatches[i].rightP1 = adjacentPatches[(i + 1) % adjacentPatches.Count].P1I; } Vector3 sum = new Vector3(); adjacentPatches.ForEach(x => sum += x.Q); sum /= adjacentPatches.Count; centerPoint.Position = sum; adjacentPatches.ForEach(x => x.CalculateP1()); gregoryPatches = new List <SingleGregoryPatch>(cycle.Patches.Count); for (int i = 0; i < adjacentPatches.Count; i++) { gregoryPatches.Add(new SingleGregoryPatch(this, adjacentPatches[i], adjacentPatches[(i + 1) % adjacentPatches.Count], centerPoint)); } }
private void AdjacentHalfPatch_OnChanged(CatPoint sender) { changed = true; }
public HalfPatchData GetDataBetweenPoints(CatPoint first, CatPoint second) { //var firstInd = IndexOf(first); //var secondInd = IndexOf(second); //var back = new CatPoint[4]; //var nearest = new CatPoint[4]; //switch (firstInd) //{ // case 0: // switch (secondInd) // { // case 3: // nearest[0] = points[0]; // nearest[1] = points[1]; // nearest[2] = points[2]; // nearest[3] = points[3]; // back[0] = points[4]; // back[1] = points[5]; // back[2] = points[6]; // back[3] = points[7]; // break; // case 12: // nearest[0] = points[0]; // nearest[1] = points[4]; // nearest[2] = points[8]; // nearest[3] = points[12]; // back[0] = points[1]; // back[1] = points[5]; // back[2] = points[9]; // back[3] = points[13]; // break; // } // break; // case 3: // switch (secondInd) // { // case 0: // nearest[0] = points[3]; // nearest[1] = points[2]; // nearest[2] = points[1]; // nearest[3] = points[0]; // back[0] = points[7]; // back[1] = points[6]; // back[2] = points[5]; // back[3] = points[4]; // break; // case 15: // nearest[0] = points[3]; // nearest[1] = points[7]; // nearest[2] = points[11]; // nearest[3] = points[15]; // back[0] = points[2]; // back[1] = points[6]; // back[2] = points[10]; // back[3] = points[14]; // break; // } // break; // case 12: // switch (secondInd) // { // case 0: // nearest[0] = points[12]; // nearest[1] = points[8]; // nearest[2] = points[4]; // nearest[3] = points[0]; // back[0] = points[13]; // back[1] = points[9]; // back[2] = points[5]; // back[3] = points[1]; // break; // case 15: // nearest[0] = points[12]; // nearest[1] = points[13]; // nearest[2] = points[14]; // nearest[3] = points[15]; // back[0] = points[8]; // back[1] = points[9]; // back[2] = points[10]; // back[3] = points[11]; // break; // } // break; // case 15: // switch (secondInd) // { // case 3: // nearest[0] = points[15]; // nearest[1] = points[11]; // nearest[2] = points[7]; // nearest[3] = points[3]; // back[0] = points[14]; // back[1] = points[10]; // back[2] = points[6]; // back[3] = points[2]; // break; // case 12: // nearest[0] = points[15]; // nearest[1] = points[14]; // nearest[2] = points[13]; // nearest[3] = points[12]; // back[0] = points[11]; // back[1] = points[10]; // back[2] = points[9]; // back[3] = points[8]; // break; // } // break; //} return(null); // new HalfPatchData(back, nearest); }
public override void RemovePoint(CatPoint point, bool removeDelegate) { base.RemovePoint(point, removeDelegate); changed = true; }
public override void RemovePoint(CatPoint point) { base.RemovePoint(point); changed = true; }
protected override void OnPointDeleted(CatPoint point) { base.OnPointDeleted(point); changed = true; }
protected override void OnPointChanged(CatPoint point) { changed = true; }
protected override void AddPoint(CatPoint point, bool generateLater = true) { base.AddPoint(point, generateLater); changed = true; }
private void ConvertToBSpline(SceneData scene) { int widthPoints = UDensity + 3; int heightPoints = VDensity + 3; if (changed || points.Count < 1) { GenerateModel(); } var pts = new Vector3[heightPoints - 2, widthPoints - 2]; for (int i = 0; i < UDensity + 1; i++) { for (int j = 0; j < VDensity + 1; j++) { pts[j, i] = points[i * 3 * (VDensity * 3 + 1) + j * 3]; } } var catPoints = new CatPoint[heightPoints, widthPoints]; var matrix = GetMatrix(false, new Vector3()); if (!Curved) { for (int i = 1; i < widthPoints - 1; i++) { for (int j = 1; j < heightPoints - 1; j++) { var pt = pts[(j - 1), (i - 1)]; catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3()); } } for (int i = 1; i < widthPoints - 1; i++) { int j = 0; var pt = pts[0, i - 1] * 2 - pts[1, i - 1]; catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3()); j = heightPoints - 1; pt = pts[j - 2, i - 1] * 2 - pts[j - 3, i - 1]; catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3()); } for (int j = 1; j < heightPoints - 1; j++) { int i = 0; var pt = pts[j - 1, 0] * 2 - pts[j - 1, 1]; catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3()); i = widthPoints - 1; pt = pts[j - 1, i - 2] * 2 - pts[j - 1, i - 3]; catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3()); } catPoints[0, 0] = scene.CreateCatPoint((matrix * new Vector4(pts[0, 0] * 2 - pts[1, 1])).ClipToVector3()); catPoints[heightPoints - 1, widthPoints - 1] = scene.CreateCatPoint( (matrix * new Vector4(pts[pts.GetLength(0) - 1, pts.GetLength(1) - 1] * 2 - pts[pts.GetLength(0) - 2, pts.GetLength(1) - 2])).ClipToVector3()); catPoints[0, widthPoints - 1] = scene.CreateCatPoint((matrix * new Vector4(pts[0, pts.GetLength(1) - 1] * 2 - pts[1, pts.GetLength(1) - 2])) .ClipToVector3()); catPoints[heightPoints - 1, 0] = scene.CreateCatPoint((matrix * new Vector4(pts[pts.GetLength(0) - 1, 0] * 2 - pts[pts.GetLength(0) - 2, 1])) .ClipToVector3()); } else { int curvePoints = widthPoints - (IsCylinder ? 3 : 0); Real angleStep = CurvatureAngle / curvePoints; Real heightStep = Height / (heightPoints - 1); //r * (4sqrt(2) / (6n)) Real newRadius = Radius * (1 + 2 * System.Math.Sqrt(2) / (3.0 * (double)(UDensity - 2))); for (int i = 0; i < curvePoints; i++) //u { Real angle = Utils.DegToRad(i * angleStep - CurvatureAngle / 2); Real x = newRadius * System.Math.Sin(angle); for (int j = 0; j < heightPoints; j++) //v { Real y = heightStep * j - Height / 2; Real z = newRadius * System.Math.Cos(angle); catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(x, y, z, 1.0)).ClipToVector3()); } } if (IsCylinder) { for (int j = 0; j < heightPoints; j++) { catPoints[j, widthPoints - 3] = catPoints[j, 0]; catPoints[j, widthPoints - 2] = catPoints[j, 1]; catPoints[j, widthPoints - 1] = catPoints[j, 2]; } } } scene.RemoveModel(this); var subArray = new CatPoint[4, 4]; var ptches = new Patch[VDensity, UDensity]; for (int i = 0; i < UDensity; i++) //u { for (int j = 0; j < VDensity; j++) //v { for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { subArray[y, x] = catPoints[j + y, i + x]; } } var patch = new BSplinePatch(subArray) { UPos = i, VPos = j }; scene.AddNewModel(patch); ptches[j, i] = patch; } } var catPointsList = new List <CatPoint>(catPoints.GetLength(0) * catPoints.GetLength(1)); foreach (var catPoint in catPoints) { catPointsList.Add(catPoint); } scene.AddNewModel(new Surface(SurfaceType.BSpline, ptches, catPointsList, scene, IsCylinder, false) { PatchesU = UDensity, PatchesV = VDensity }); }
protected void OnBezierPointChanged(CatPoint point) { Changed = true; }
public virtual void RemovePoint(CatPoint point) { RemovePoint(point, true); }
private void PointOnChanged(CatPoint sender) { changed = true; }
protected virtual void OnPointDeleted(CatPoint point) { RemovePoint(point, false); }
public AdjacentHalfPatch(HalfPatchData halfPatch, SceneData scene, CatPoint centerPoint) { this.data = halfPatch; this.scene = scene; this.centerPoint = centerPoint; LeftNearest = new CatPoint[4]; LeftBack = new CatPoint[3]; RightNearest = new CatPoint[4]; RightBack = new CatPoint[3]; LeftNearest[0] = halfPatch.Nearest[0]; RightNearest[3] = halfPatch.Nearest[3]; for (int i = 0; i < 3; i++) { LeftNearest[i + 1] = scene.CreateHiddenCatPoint(new Vector3()); } RightNearest[0] = LeftNearest[3]; for (int i = 0; i < 2; i++) { RightNearest[i + 1] = scene.CreateHiddenCatPoint(new Vector3()); } for (int i = 0; i < 2; i++) { LeftBack[i] = scene.CreateHiddenCatPoint(new Vector3()); RightBack[i + 1] = scene.CreateHiddenCatPoint(new Vector3()); } LeftBack[2] = RightBack[0] = scene.CreateHiddenCatPoint(new Vector3()); for (int i = 0; i < 4; i++) { halfPatch.Nearest[i].OnChanged += AdjacentHalfPatch_OnChanged; halfPatch.Back[i].OnChanged += AdjacentHalfPatch_OnChanged; } centerPoint.OnChanged += AdjacentHalfPatch_OnChanged; P1I = scene.CreateHiddenCatPoint(new Vector3()); //P1I.W = 6; changed = true; ActualizePositions(); NormalL1 = scene.CreateHiddenCatPoint(new Vector3()); NormalR1 = scene.CreateHiddenCatPoint(new Vector3()); renderPoints = new List <CatPoint> { LeftNearest[0], LeftNearest[1], LeftBack[0], LeftNearest[2], LeftBack[1], LeftNearest[3], LeftBack[2], RightNearest[1], RightBack[1], RightNearest[2], RightBack[2], RightNearest[3], P1I, centerPoint, NormalL1, NormalR1, }; }
protected virtual void OnPointChanged(CatPoint point) { }
protected override void OnPointChanged(CatPoint point) { UpdateBerensteinPoints(); }
public virtual void AddPoint(CatPoint point) { AddPoint(point, false); }
private void ConvertToBezierPatches(SceneData scene) { int widthPoints = UDensity * 3 + 1; int heightPoints = VDensity * 3 + 1; if (changed || points.Count == 0) { GenerateModel(); } var catPoints = new CatPoint[heightPoints, widthPoints]; var matrix = GetMatrix(false, new Vector3()); if (!Curved) { for (int i = 0; i < widthPoints; i++) { for (int j = 0; j < heightPoints; j++) { var pt = points[i * heightPoints + j]; catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3()); } } } else { bool cylinder = System.Math.Abs(CurvatureAngle - 360) < Utils.Eps; for (int i = 0; i < widthPoints - (cylinder ? 1 : 0); i++) { for (int j = 0; j < heightPoints; j++) { Vector3 pt; if (i % 3 != 0) { int ai = i - i % 3; int ci = ai + 3; var p = (points[(ai + 1) * heightPoints + j] + points[(ai + 2) * heightPoints + j]); var b = p - (points[ai * heightPoints + j] + points[ci * heightPoints + j]) / 2; var pot = i % 3 == 1 ? points[ai * heightPoints + j] : points[ci * heightPoints + j]; pt = b * 2 / 3.0 + pot * 1 / 3.0; } else { pt = points[i * heightPoints + j]; } catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3()); } } if (cylinder) { for (int j = 0; j < heightPoints; j++) { catPoints[j, widthPoints - 1] = catPoints[j, 0]; } } } scene.RemoveModel(this); var subArray = new CatPoint[4, 4]; var ptchs = new Patch[VDensity, UDensity]; for (int i = 0; i < UDensity; i++) { for (int j = 0; j < VDensity; j++) { for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { subArray[y, x] = catPoints[j * 3 + y, i * 3 + x]; } } var patch = new BezierPatch(subArray) { UPos = i, VPos = j }; scene.AddNewModel(patch); ptchs[j, i] = patch; } } var catPointsList = new List <CatPoint>(catPoints.GetLength(0) * catPoints.GetLength(1)); foreach (var catPoint in catPoints) { catPointsList.Add(catPoint); } scene.AddNewModel(new Surface(SurfaceType.Bezier, ptchs, catPointsList, scene, IsCylinder, false) { PatchesU = UDensity, PatchesV = VDensity }); }
public ClickData(double distance, CatPoint clicked) { Distance = distance; ClickedModel = clicked; }
public bool ContainsInCorner(CatPoint catPoint) { return(false); return(pointsOrdererd[0, 0] == catPoint || pointsOrdererd[3, 0] == catPoint || pointsOrdererd[0, 3] == catPoint || pointsOrdererd[3, 3] == catPoint); }