/// <summary> /// Reads incoming Json and parses it to the right implementation /// </summary> /// <param name="reader">Reader that has json</param> /// <param name="objectType">objectType to which should be converted</param> /// <param name="existingValue">A potentially existing value</param> /// <param name="serializer">Serializer that is in use</param> /// <returns>parsed object</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jsonObject = JObject.Load(reader); //logger.Debug(objectType); var graphItemType = default(object); if (objectType == typeof(IVertex)) { graphItemType = new Vertex(); } else if (objectType == typeof(IEdge)) { graphItemType = new Edge(); } else if (objectType == typeof(IVertexValue)) { graphItemType = new VertexValue(); } else if (objectType == typeof(IVertexProperties)) { graphItemType = new VertexProperties(); } else if (objectType == typeof(IEdgeProperties)) { graphItemType = new EdgeProperties(); } else { throw (new Exceptions.NotSupportedDatabaseException("Not supported GraphDatabase. Titan or OrientDB are supported.")); } serializer.Populate(jsonObject.CreateReader(), graphItemType); return(graphItemType); }
// // Follows Procedure in CLRS on page 648: // Initializes all weights to a specified upper bound: positive infinity // void InitializeSingleSource(int upperBound) { int numVerts = graph.NumVertices(); shortPathEst = new VertexValue[numVerts]; for (int i = 0; i < numVerts; i++) { shortPathEst[i] = new VertexValue(upperBound, NIL); } // Gives us a starting point to begin search at the start node shortPathEst[startNode].d = 0; // start-node.d = 0 }
public override void LoadRaw() { if (RawLoaded) { return; } var mode = this; var data = cache.GetRawFromID(mode.RawID); var ms = new MemoryStream(data); var reader = new EndianReader(ms, IO.EndianFormat.Big); var validParts = new Dictionary <int, mode.ModelSection>(); LoadFixups(); if (mode.IndexInfoList.Count == 0) { throw new Exception("Geometry contains no faces"); } #region Read Vertices for (int i = 0; i < mode.ModelSections.Count; i++) { var section = mode.ModelSections[i]; if (section.Submeshes.Count == 0) { continue; } if (section.VertsIndex >= 0 && section.VertsIndex < mode.VertInfoList.Count) { reader.SeekTo(mode.VertInfoList[section.VertsIndex].Offset); } if (cache.vertexNode == null) { throw new NotSupportedException("No vertex definitions found for " + cache.Version.ToString()); } #region Get Vertex Definition XmlNode formatNode = null; foreach (XmlNode node in cache.vertexNode.ChildNodes) { if (Convert.ToInt32(node.Attributes["type"].Value, 16) == section.VertexFormat) { formatNode = node; break; } } if (formatNode == null) { throw new NotSupportedException("Format " + section.VertexFormat.ToString() + " not found in definition for " + cache.Version.ToString()); } #endregion mode.ModelSection validPart; if (validParts.TryGetValue(section.VertsIndex, out validPart)) { section.Vertices = validPart.Vertices; continue; } else { validParts.Add(section.VertsIndex, section); } section.Vertices = new Vertex[mode.VertInfoList[section.VertsIndex].VertexCount]; #region Get Vertices for (int j = 0; j < mode.VertInfoList[section.VertsIndex].VertexCount; j++) { section.Vertices[j] = new Vertex(reader, formatNode); ModelFunctions.DecompressVertex(ref section.Vertices[j], mode.BoundingBoxes[0]); #region fixups var vert = section.Vertices[j]; VertexValue v; #region rigid fix if (section.NodeIndex != 255 && !mode.Flags.Values[18]) { vert.Values.Add(new VertexValue(new Vector(section.NodeIndex, 0, 0, 0), VertexValue.ValueType.Int8_N4, "blendindices", 0)); vert.Values.Add(new VertexValue(new Vector(1, 0, 0, 0), VertexValue.ValueType.Int8_N4, "blendweight", 0)); } #endregion #region flag 18 fix if (mode.Flags.Values[18]) { VertexValue w; var hasWeights = vert.TryGetValue("blendweight", 0, out w); if (!hasWeights) { w = new VertexValue(new Vector(1, 0, 0, 0), VertexValue.ValueType.Int8_N4, "blendweight", 0); } if (vert.TryGetValue("blendindices", 0, out v)) { v.Data.A = w.Data.A == 0 ? 0 : mode.NodeIndexGroups[i].NodeIndices[(int)v.Data.A].Index; v.Data.B = w.Data.B == 0 ? 0 : mode.NodeIndexGroups[i].NodeIndices[(int)v.Data.B].Index; v.Data.C = w.Data.C == 0 ? 0 : mode.NodeIndexGroups[i].NodeIndices[(int)v.Data.C].Index; v.Data.D = w.Data.D == 0 ? 0 : mode.NodeIndexGroups[i].NodeIndices[(int)v.Data.D].Index; } else { v = new VertexValue(new Vector(0, 0, 0, 0), VertexValue.ValueType.Int8_N4, "blendindices", 0); v.Data.A = mode.NodeIndexGroups[i].NodeIndices[0].Index; vert.Values.Add(v); vert.Values.Add(w); } } #endregion #region rigid_boned fix if (!vert.TryGetValue("blendweight", 0, out v) && vert.TryGetValue("blendindices", 0, out v)) { var q = new Vector( v.Data.A == 0 ? 0 : 1, v.Data.B == 0 ? 0 : 1, v.Data.C == 0 ? 0 : 1, v.Data.D == 0 ? 0 : 1); vert.Values.Add(new VertexValue(q, VertexValue.ValueType.Int8_N4, "blendweight", 0)); } #endregion #endregion } #endregion } #endregion validParts.Clear(); #region Read Indices for (int i = 0; i < mode.ModelSections.Count; i++) { var section = mode.ModelSections[i]; if (section.Submeshes.Count == 0) { continue; } if (section.FacesIndex >= 0 && section.FacesIndex < mode.IndexInfoList.Count) { reader.SeekTo(mode.IndexInfoList[section.FacesIndex].Offset); } mode.ModelSection validPart; if (validParts.TryGetValue(section.FacesIndex, out validPart)) { section.Indices = validPart.Indices; continue; } else { validParts.Add(section.FacesIndex, section); } section.Indices = new int[section.TotalFaceCount]; for (int j = 0; j < section.TotalFaceCount; j++) { section.Indices[j] = (mode.VertInfoList[section.VertsIndex].VertexCount > 0xFFFF) ? reader.ReadInt32() : reader.ReadUInt16(); } } #endregion LoadModelExtras(); mode.RawLoaded = true; }