public bool initializeTraining(double modelSize) { if (_numSamples <= 0 || _numPoints <= 0) { return(false); } // Copy the label _trainingData = new CXYVector[_numSamples]; int i, k, l, s; for (k = 0; k < _numSamples; k++) { _trainingData[k] = new CXYVector(_numPoints, ((CSample)_sample[k]).points); } // create a normal shape /* Create A Circle Shape * Use This To Transform The "Center" Point Of The Mean Sample To Origin * The Mean Sample Orientation Will Be Fix Using Manual Orientation */ double radius = modelSize; _normalShape = new CXYVector(_numPoints); for (i = 1; i < 2 * _normalShape.size; i += 2) { double angle = (i * System.Math.PI) / _normalShape.size; _normalShape[i / 2] = new CVector2(radius * System.Math.Sin(angle), radius * System.Math.Cos(angle)); } // Make First Sample As The Mean Sample _mean = new CXYVector(_trainingData[0]); // Create the weight diagonal matrix // the matrix is reduced to vector _weight = new double[_numPoints]; for (k = 0; k < _numPoints; k++) { double sumVar = 0.0; for (l = 0; l < _numPoints; l++) { double sigX = 0.0; double sigX2 = 0.0; for (s = 0; s < _numSamples; s++) { CVector2 tv = _trainingData[s][k].substractCopy(_trainingData[s][l]); double delta = tv.length2(); sigX += Math.Sqrt(delta); sigX2 += delta; } sumVar += (sigX2 - ((sigX * sigX) / _numSamples)) / _numSamples; } _weight[k] = 1.0 / sumVar; } _energy = 100000; return(true); }
private int calculateMovement(CXYVector xdX) { int size = _ASMResult.size; int detectedEdgeCnt = 0; for (int i = 0; i < size; i++) { xdX[i] = CVector2.vNormal(_ASMResult[(i + size - 1) % size], _ASMResult[i], _ASMResult[(i + 1) % size]); double dx = xdX[i][0]; double dy = xdX[i][1]; scanForEdge(_ASMResult[i][0], _ASMResult[i][1], ref dx, ref dy); if (dx != 0 && dy != 0) { detectedEdgeCnt++; } xdX[i][0] = dx; xdX[i][1] = dy; xdX[i].add(_ASMResult[i]); } return(detectedEdgeCnt); }
public void moveSelectedPoint(double x, double y) { int i; CVector2 buff = new CVector2(x, y); if (_activeSampleIdx == -1) { return; } for (i = 0; i < _numPoints; i++) { if (_isSelected[i]) { activeSample[i].add(buff); } } }
public object ReadYaml(IParser parser, Type xtype) { IType result; parser.ReadMappingStart(); // read name property var typeName = parser.SafeReadScalarProperty(s_typeName); var type = Serialization.GetTypeFromRedTypeStr(typeName); if (type == null) { throw new InvalidDataException(); } if (IsArray(type)) { var innertype = type.GetGenericArguments()[0]; var list = (IList)Activator.CreateInstance( typeof(List <>).MakeGenericType( new Type[] { innertype }), BindingFlags.Instance | BindingFlags.Public, binder: null, args: null, culture: null); if (list is null) { throw new InvalidDataException(); } // read values parser.SafeReadScalarValue(s_valueName); if (parser.Current.GetType() != _sequenceStartType) { throw new InvalidDataException("Invalid YAML content."); } parser.MoveNext(); // skip the sequence start do { var x = ReadYaml(parser, innertype); list.Add(x); } while (parser.Current.GetType() != _sequenceEndType); parser.MoveNext(); // skip the mapping end (or crash) var array = (IArray)Activator.CreateInstance( typeof(CArray <>).MakeGenericType( new Type[] { innertype }), BindingFlags.Instance | BindingFlags.Public, binder: null, args: null, culture: null); if (array is null) { throw new InvalidDataException(); } array.SetItems(list); result = array is IType o ? o : throw new JsonException(); } else { if (typeof(IPrimitive).IsAssignableFrom(type)) { result = Parse(parser.SafeReadScalarProperty(s_valueName), type); } else { parser.SafeReadScalarValue(s_valueName); parser.ReadMappingStart(); switch (Serialization.GetEnumFromType(type)) { case ETweakType.CColor: { result = new CColor { Red = byte.Parse(parser.SafeReadScalarProperty(nameof(CColor.Red))), Green = byte.Parse(parser.SafeReadScalarProperty(nameof(CColor.Green))), Blue = byte.Parse(parser.SafeReadScalarProperty(nameof(CColor.Blue))), Alpha = byte.Parse(parser.SafeReadScalarProperty(nameof(CColor.Alpha))), }; break; } case ETweakType.CEulerAngles: { result = new CEulerAngles { Pitch = float.Parse(parser.SafeReadScalarProperty(nameof(CEulerAngles.Pitch))), Yaw = float.Parse(parser.SafeReadScalarProperty(nameof(CEulerAngles.Yaw))), Roll = float.Parse(parser.SafeReadScalarProperty(nameof(CEulerAngles.Roll))), }; break; } case ETweakType.CQuaternion: { result = new CQuaternion { I = float.Parse(parser.SafeReadScalarProperty(nameof(CQuaternion.I))), J = float.Parse(parser.SafeReadScalarProperty(nameof(CQuaternion.J))), K = float.Parse(parser.SafeReadScalarProperty(nameof(CQuaternion.K))), R = float.Parse(parser.SafeReadScalarProperty(nameof(CQuaternion.R))), }; break; } case ETweakType.CVector2: { result = new CVector2 { X = float.Parse(parser.SafeReadScalarProperty(nameof(CVector2.X))), Y = float.Parse(parser.SafeReadScalarProperty(nameof(CVector2.Y))) }; break; } case ETweakType.CVector3: { result = new CVector3 { X = float.Parse(parser.SafeReadScalarProperty(nameof(CVector3.X))), Y = float.Parse(parser.SafeReadScalarProperty(nameof(CVector3.Y))), Z = float.Parse(parser.SafeReadScalarProperty(nameof(CVector3.Z))) }; break; } default: throw new ArgumentOutOfRangeException(); } parser.MoveNext(); // skip the mapping end (or crash) } } parser.MoveNext(); // skip the mapping end (or crash) return(result); }
public ParticleEmitter2(BinaryReader br) { TotalSize = br.ReadUInt32(); long end = br.BaseStream.Position + TotalSize; ObjSize = br.ReadUInt32(); Name = br.ReadCString(Constants.SizeName); ObjectId = br.ReadInt32(); ParentId = br.ReadInt32(); Flags = (GENOBJECTFLAGS)br.ReadUInt32(); LoadTracks(br); NodeSize = br.ReadInt32(); Type = (PARTICLE_EMITTER_TYPE)br.ReadInt32(); Speed = br.ReadSingle(); Variation = br.ReadSingle(); Latitude = br.ReadSingle(); Longitude = br.ReadSingle(); Gravity = br.ReadSingle(); ZSource = br.ReadSingle(); Lifespan = br.ReadSingle(); EmissionRate = br.ReadSingle(); Length = br.ReadSingle(); Width = br.ReadSingle(); Rows = br.ReadInt32(); Cols = br.ReadInt32(); ParticleType = (PARTICLE_TYPE)br.ReadInt32(); if (ParticleType > 0 && !Enum.IsDefined(typeof(PARTICLE_TYPE), ParticleType)) { throw new Exception("Unknown PARTICLE_TYPE"); } TailLength = br.ReadSingle(); MiddleTime = br.ReadSingle(); StartColor = new CVector3(br); MiddleColor = new CVector3(br); EndColor = new CVector3(br); StartAlpha = br.ReadByte() / 255f; MiddleAlpha = br.ReadByte() / 255f; EndAlpha = br.ReadByte() / 255f; StartScale = br.ReadSingle(); MiddleScale = br.ReadSingle(); EndScale = br.ReadSingle(); LifespanUVAnimStart = br.ReadUInt32(); LifespanUVAnimEnd = br.ReadUInt32(); LifespanUVAnimRepeat = br.ReadUInt32(); DecayUVAnimStart = br.ReadUInt32(); DecayUVAnimEnd = br.ReadUInt32(); DecayUVAnimRepeat = br.ReadUInt32(); TailUVAnimStart = br.ReadUInt32(); TailUVAnimEnd = br.ReadUInt32(); TailUVAnimRepeat = br.ReadUInt32(); TailDecayUVAnimStart = br.ReadUInt32(); TailDecayUVAnimEnd = br.ReadUInt32(); TailDecayUVAnimRepeat = br.ReadUInt32(); BlendMode = (PARTICLE_BLEND_MODE)br.ReadUInt32(); TextureId = br.ReadUInt32(); PriorityPlane = br.ReadInt32(); ReplaceableId = br.ReadUInt32(); GeometryMdl = br.ReadCString(Constants.SizeFileName); RecursionMdl = br.ReadCString(Constants.SizeFileName); TwinkleFPS = br.ReadSingle(); TwinkleOnOff = br.ReadSingle(); TwinkleScaleMin = br.ReadSingle(); TwinkleScaleMax = br.ReadSingle(); IvelScale = br.ReadSingle(); TumbleX = new CVector2(br); TumbleY = new CVector2(br); TumbleZ = new CVector2(br); Drag = br.ReadSingle(); Spin = br.ReadSingle(); WindVector = new CVector3(br); WindTime = br.ReadSingle(); FollowSpeed1 = br.ReadSingle(); FollowScale1 = br.ReadSingle(); FollowSpeed2 = br.ReadSingle(); FollowScale2 = br.ReadSingle(); NrOfSplines = br.ReadInt32(); for (int i = 0; i < NrOfSplines; i++) { Splines.Add(new CVector3(br)); } Squirts = br.ReadUInt32(); // 1 for footsteps and impact spell effects while (br.BaseStream.Position < end && !br.AtEnd()) { string tagname = br.ReadString(4); switch (tagname) { case "KP2S": SpeedKeys = new Track <float>(br); break; case "KP2R": VariationKeys = new Track <float>(br); break; case "KP2G": GravityKeys = new Track <float>(br); break; case "KP2W": WidthKeys = new Track <float>(br); break; case "KP2N": LengthKeys = new Track <float>(br); break; case "KVIS": VisibilityKeys = new Track <float>(br); break; case "KP2E": EmissionRateKeys = new Track <float>(br); break; case "KP2L": LatitudeKeys = new Track <float>(br); break; case "KLIF": LifespanKeys = new Track <float>(br); break; case "KPLN": LongitudeKeys = new Track <float>(br); break; case "KP2Z": ZSourceKeys = new Track <float>(br); break; default: br.BaseStream.Position -= 4; return; } } }
public void addPoint(CVector2 newPoint) { addPoint(newPoint[0], newPoint[1]); }
public int addPoint(CVector2 newPoint) { return(addPoint(newPoint[0], newPoint[1])); }