public static void SaveMeshGenerationData(string filePath, int[] gridSize, Dictionary <int, Vector3> cells) { var stride = sizeof(int) + 3 * sizeof(float); var size = 3 * sizeof(int) + stride * cells.Count; using (var mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Create, null, size)) { using (var accessor = mmf.CreateViewAccessor(0, size)) { long pos = 0; for (var i = 0; i < 3; ++i) { accessor.Write(pos, gridSize[i]); pos += sizeof(int); } foreach (var cell in cells) { accessor.Write(pos, cell.Key); pos += sizeof(int); TreeUtility.MmvaWriteVector3(cell.Value, accessor, ref pos); } } } }
private Vector3?GetCellValue(Vector3Int pos) { var dx = pos.x - voxelData.gridSize[0]; var dy = pos.y - voxelData.gridSize[1]; var dz = pos.z - voxelData.gridSize[2]; if (dx < 0 && dy < 0 && dz < 0) { var flat = TreeUtility.Flatten(pos, voxelData.gridSize); return(voxelData.cells.TryGetValue(flat, out var val) ? val : (Vector3?)null); } var neighborOffset = new Vector3Int(Math.Max(dx + 1, 0), Math.Max(dy + 1, 0), Math.Max(dz + 1, 0)); var neighborData = NeighborData[neighborOffset]; if (neighborData.cells.Count == 0) { return(null); } var nPos = (Vector3Int.one - neighborOffset) * pos; var nFlat = TreeUtility.Flatten(nPos, neighborData.gridSize); return(neighborData.cells.TryGetValue(nFlat, out var nVal) ? nVal : (Vector3?)null); }
public void FlushMeshGenerationData(string outputDirectory) { if (outputPoints.Count == 0) { return; } var data = outputPoints.ToDictionary(x => x.Key, x => x.Value.Position); EditorTreeUtility.SaveMeshGenerationData( Path.Combine(outputDirectory, $"{nodeRecord.Identifier}.meshdata"), cellsPerAxis, data); bool IsEdgeCell(int id) { var xyz = TreeUtility.Unflatten(id, cellsPerAxis); return((xyz.x == 0) || (xyz.y == 0) || (xyz.z == 0)); } var edgeData = data .Where(x => IsEdgeCell(x.Key)) .ToDictionary(x => x.Key, x => x.Value); if (edgeData.Count == 0) { return; } EditorTreeUtility.SaveMeshGenerationData( Path.Combine(outputDirectory, $"{nodeRecord.Identifier}.meshedge"), cellsPerAxis, edgeData); }
public NodeProcessorDispatcher(string outputPath, TreeImportSettings settings) { this.outputPath = outputPath; Settings = settings; var pcExtensions = new List <string> { TreeUtility.NodeFileExtension, TreeUtility.IndexFileExtension }; if (Directory.Exists(outputPath)) { var matchingFiles = Directory .EnumerateFiles(outputPath, "*.*", SearchOption.TopDirectoryOnly) .Where(x => Path.GetExtension(x) != null && pcExtensions.Contains(Path.GetExtension(x).ToLowerInvariant())) .ToList(); foreach (var file in matchingFiles) { File.Delete(file); } } Directory.CreateDirectory(outputPath); outputTmpPath = Path.Combine(outputPath, "tmp"); Directory.CreateDirectory(outputTmpPath); points = new PointCloudPoint[settings.chunkSize]; var maxArraySize = TreeUtility.CalculateMaxArraySize(UnsafeUtility.SizeOf <PointCloudPoint>()); PublicMaxSizeBuffer = new PointCloudPoint[maxArraySize]; }
public void TestByIsCancel() { var buttons = TreeUtility.LogicalTree((AppVar)_ctrl).ByType <Button>(); AppVar button5 = ButtonSearcher.ByIsCancel(buttons).Single(); Assert.AreEqual(button5, _ctrl._button5); }
public void TestLogicalTree() { AppVar button1 = Searcher.ByBinding(TreeUtility.LogicalTree(_ctrl), "Button1Command").Single(); Assert.AreEqual(button1, _ctrl._button1); Assert.AreEqual(0, TreeUtility.LogicalTree((AppVar)_ctrl._listView).ByType <ListViewItem>().Count); }
public void TestByCommandParameterText() { var buttons = TreeUtility.LogicalTree((AppVar)_ctrl).ByType <Button>(); AppVar button4 = ButtonSearcher.ByCommandParameterText(buttons, "A").Single(); Assert.AreEqual(button4, _ctrl._button4); }
public static void LoadMeshGenerationData(string filePath, MeshGenerationData output) { output.Clear(); var size = new FileInfo(filePath).Length; var stride = sizeof(int) + 3 * sizeof(float); var count = (size - 3 * sizeof(int)) / stride; using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var mmf = MemoryMappedFile.CreateFromFile(fs, null, size, MemoryMappedFileAccess.Read, HandleInheritability.None, false)) { using (var accessor = mmf.CreateViewAccessor(0, size, MemoryMappedFileAccess.Read)) { long pos = 0; for (var i = 0; i < 3; ++i) { accessor.Read(pos, out int tmp); output.gridSize[i] = tmp; pos += sizeof(int); } for (var i = 0; i < count; ++i) { accessor.Read(pos, out int key); pos += sizeof(int); var val = TreeUtility.MmvaReadVector3(accessor, ref pos); output.cells.Add(key, val); } } } } }
public void TestByCommand() { var buttons = TreeUtility.LogicalTree((AppVar)_ctrl).ByType <Button>(); AppVar button2 = ButtonSearcher.ByCommand(buttons, ApplicationCommands.Close).Single(); Assert.AreEqual(button2, _ctrl._button2); button2 = ButtonSearcher.ByCommand(buttons, typeof(ApplicationCommands).FullName, "Close").Single(); Assert.AreEqual(button2, _ctrl._button2); }
public void TestByCommandParameterEnum() { var buttons = TreeUtility.LogicalTree((AppVar)_ctrl).ByType <Button>(); AppVar button4 = ButtonSearcher.ByCommandParameter(buttons, CommandPrameterType.A).Single(); Assert.AreEqual(button4, _ctrl._button4); button4 = ButtonSearcher.ByCommandParameter(buttons, new ExplicitAppVar(_app.Copy(CommandPrameterType.A))).Single(); Assert.AreEqual(button4, _ctrl._button4); }
public void TestByCommandParameter() { var buttons = TreeUtility.LogicalTree((AppVar)_ctrl).ByType <Button>(); AppVar button1 = ButtonSearcher.ByCommandParameter(buttons, "button1").Single(); Assert.AreEqual(button1, _ctrl._button1); button1 = ButtonSearcher.ByCommandParameter(buttons, new ExplicitAppVar(_app.Copy("button1"))).Single(); Assert.AreEqual(button1, _ctrl._button1); }
public void Run() { TreeNode treeNode = TreeUtility.CreateMinimalBinarySearchTree(TreeUtility.arraySorted_UniqueElements); //((BinarySearchTreeNode)treeNode).Print(); TreeUtility.arraySorted_UniqueElements.Print("Input for CreateMinimalBinarySearchTree:"); var binarySearchTree2 = BinarySearchTreeNode.CreateMinimalBinarySearchTree(TreeUtility.arraySorted_UniqueElements); binarySearchTree2.Print(); }
/// <inheritdoc/> protected override NodeRecord CreateChildRecord(byte index) { var childId = NodeRecord.Identifier + index.ToString(); var parentCenter = NodeRecord.Bounds.center; var parentSize = NodeRecord.Bounds.size; var quarterSize = NodeRecord.Bounds.size * 0.25f; var childSize = parentSize * 0.5f; var centerOffset = Vector3.Scale(quarterSize, TreeUtility.GetOctreeOffsetVector(index)); var bounds = new Bounds(parentCenter + centerOffset, childSize); return(new OctreeNodeRecord(childId, bounds, 0)); }
protected override void Render(HtmlTextWriter writer) { IContentAdapterProvider adapters = Engine.Resolve <IContentAdapterProvider>(); if (Nodes == null) { Nodes = new BranchHierarchyBuilder(SelectedItem, RootNode, true) .Children((item) => adapters.ResolveAdapter <NodeAdapter>(item).GetChildren(item, Interfaces.Managing)) .Build(); } TreeUtility.Write(Nodes, SelectedItem, adapters, Filter, SelectableTypes, SelectableExtensions, excludeRoot: false, target: Target, writer: writer); }
public void UpdateVolatileData() { builderVerts.Clear(); foreach (var cell in cells) { var coord = TreeUtility.Unflatten(cell.Key, gridSize); builderVerts.Add(coord, new Vert() { position = cell.Value }); } }
protected void InitializeMinimal() { ProjectRoot = CreateProjectRootItem(); ProjectRoot.AddWwiseItemChild(BuildObjectTypeTree(WwiseObjectType.Event)); ProjectRoot.AddWwiseItemChild(BuildObjectTypeTree(WwiseObjectType.Switch)); ProjectRoot.AddWwiseItemChild(BuildObjectTypeTree(WwiseObjectType.State)); ProjectRoot.AddWwiseItemChild(BuildObjectTypeTree(WwiseObjectType.Soundbank)); ProjectRoot.AddWwiseItemChild(BuildObjectTypeTree(WwiseObjectType.AuxBus)); ProjectRoot.AddWwiseItemChild(BuildObjectTypeTree(WwiseObjectType.AcousticTexture)); TreeUtility.TreeToList(ProjectRoot, Data); }
public override PointCloudVerticalHistogram GenerateHistogram(PointCloudBounds bounds) { var fileName = Path.GetFileName(FilePath); long currentOffset = header.PointDataOffset; long processed = 0; long count = header.PointDataCount; if (header.VersionMajor > 1 || header.VersionMajor == 1 && header.VersionMinor >= 4) { if (count == 0) { count = (long)header.PointDataCountLong; } } var result = new PointCloudVerticalHistogram(bounds); using (var file = MemoryMappedFile.CreateFromFile(FilePath ?? throw new Exception("Input file not found."), FileMode.Open)) { var batchIndex = 0; var maxArraySize = TreeUtility.CalculateMaxArraySize(header.PointDataSize); var totalBatchCount = Mathf.CeilToInt((float)count / maxArraySize); while (processed < count) { var batchCount = Math.Min(maxArraySize, count - processed); var batchSize = batchCount * header.PointDataSize; using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read)) { unsafe { batchIndex++; var progressBarTitle = $"Generating histogram ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})"; var hst = PointImportJobs.GenerateHistogramLas(view, batchCount, header, bounds, progressBarTitle); result.AddData(hst.regions); } } processed += batchCount; currentOffset += batchSize; } } return(result); }
private void InitializeData(string filePath) { this._treeUtility = new TreeUtility(); this._troubleshootingWizardUiService = new WizardUIService(); this._instructionTree = _treeUtility.BuildTree(filePath); if (this._instructionTree != null) { this._currentNode = _instructionTree.Root; this._testResult = true; this._outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } this.ToggleYesNoState(false); }
public void TestBinding() { AppVar button1 = Searcher.ByBinding(TreeUtility.LogicalTree(_ctrl), "Button1Command").Single(); Assert.IsTrue(button1.Equals(_ctrl._button1)); var collection = Searcher.ByBinding(TreeUtility.LogicalTree(_ctrl), "DataText"); Assert.AreEqual(2, collection.Count); var textBox = Searcher.ByBinding(TreeUtility.LogicalTree(_ctrl), "DataText", new ExplicitAppVar(_ctrl.DataContext)).Single(); Assert.IsTrue(textBox.Equals(_ctrl._textBox)); }
///<inheritdoc/> public override bool ConvertPoints(NodeProcessorDispatcher target, TransformationData transformationData) { var fileName = Path.GetFileName(FilePath); long currentOffset = header.PointDataOffset; long processed = 0; long count = header.PointDataCount; if (header.VersionMajor > 1 || header.VersionMajor == 1 && header.VersionMinor >= 4) { if (count == 0) { count = (long)header.PointDataCountLong; } } using (var file = MemoryMappedFile.CreateFromFile(FilePath, FileMode.Open)) { var batchIndex = 0; var maxArraySize = TreeUtility.CalculateMaxArraySize(header.PointDataSize); var totalBatchCount = Mathf.CeilToInt((float)count / maxArraySize); while (processed < count) { var batchCount = Math.Min(maxArraySize, count - processed); var batchSize = batchCount * header.PointDataSize; using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read)) { batchIndex++; var progressBarTitle = $"Converting ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})"; var targetBuffer = target.PublicMaxSizeBuffer; PointImportJobs.ConvertLasData(view, targetBuffer, header.PointDataSize, (int)batchCount, ref header, transformationData, progressBarTitle); target.AddChunk(targetBuffer, (int)batchCount); } processed += batchCount; currentOffset += batchSize; } } return(true); }
public override void UpdateSearchResults(string searchString, WwiseObjectType objectType) { SearchRoot = new AkWwiseTreeViewItem(ProjectRoot); if (objectType != WwiseObjectType.None) { SearchRoot = new AkWwiseTreeViewItem(ProjectRoot); var objectRoot = new AkWwiseTreeViewItem(wwiseObjectFolders[objectType]); TreeUtility.CopyTree(wwiseObjectFolders[objectType], objectRoot); SearchRoot.AddWwiseItemChild(objectRoot); } else { TreeUtility.CopyTree(ProjectRoot, SearchRoot); } FilterTree(SearchRoot, searchString); }
private void FireSearch(object sender, System.Timers.ElapsedEventArgs e) { if (SearchRoot == null) { SearchRoot = new AkWwiseTreeViewItem(ProjectRoot); } SearchRoot.children.Clear(); SearchItems = new List <AkWwiseTreeViewItem>(new[] { SearchRoot }); TreeUtility.TreeToList(SearchRoot, SearchItems); AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) => { AddSearchResults(AkWaapiUtilities.ParseObjectInfo(items)); }; AkWaapiUtilities.Search(searchString, searchObjectTypeFilter, waapiWwiseObjectOptions, callback); }
public Bounds AlignBounds(TreeImportSettings settings, Bounds bounds) { var origin = bounds.min.y; var step = EditorTreeUtility.GetStepAtTreeLevel(bounds, settings, settings.meshDetailLevel); var alignedBounds = TreeUtility.GetRoundedAlignedBounds(bounds, bounds.min, step); var alignedOrigin = alignedBounds.min.y; var peak = FindPeak(); var targetCenter = origin + (bounds.size.y / Resolution) * (peak + 0.5f); var tmpDst = float.MaxValue; var actualCenter = 0f; for (var i = 0; i < (int)(alignedBounds.size.y / step); ++i) { var pos = alignedOrigin + (i + 0.5f) * step; var dst = Mathf.Abs(targetCenter - pos); if (dst < tmpDst) { actualCenter = pos; tmpDst = dst; } else { Debug.Log($"Break at i ({actualCenter:F4})"); break; } } var diff = targetCenter - actualCenter; if (diff > 0) { diff -= step; } var height = bounds.max.y - bounds.min.y; var alignedMin = alignedBounds.min; alignedMin.y += diff; alignedBounds.min = alignedMin; Debug.Log($"origin: {origin:F4}, AO: {alignedBounds.min.y:F4}, height: {height:F4}, step: {step:F4}, TC: {targetCenter:F4}, AC: {actualCenter:F4}"); return(alignedBounds); }
public void TestType() { AppVar target = _ctrl; var collection = Searcher.ByType(TreeUtility.LogicalTree(target), typeof(Button).FullName); Assert.AreEqual(2, collection.Count); collection = Searcher.ByType <Button>(TreeUtility.LogicalTree(target)); Assert.AreEqual(2, collection.Count); collection = Searcher.ByType <ButtonBase>(TreeUtility.LogicalTree(target)); Assert.AreEqual(3, collection.Count); var list = Searcher.ByType(TreeUtility.LogicalTree(target), typeof(ListView).FullName).Single(); Assert.AreEqual(list, _ctrl._listView); list = Searcher.ByType <ListView>(TreeUtility.LogicalTree(target)).Single(); Assert.AreEqual(list, _ctrl._listView); }
/// <inheritdoc/> protected override void PassPointToChild(PointCloudPoint point) { var childIndex = TreeUtility.GetQuadtreeChildIndex(NodeRecord.Bounds, point.Position); if (ChildFileCounts[childIndex] == 0 && ChildCounts[childIndex] == 0) { var childRecord = CreateChildRecord(childIndex); ChildNodeRecords.Add(childRecord); } ChildBuffers[childIndex][ChildCounts[childIndex]++] = point; if (ChildCounts[childIndex] == Settings.chunkSize) { FlushChildFile(childIndex); } }
protected PointCloudVerticalHistogram GenerateHistogramDefault(DefaultHeaderData headerData, PointCloudBounds bounds) { var fileName = Path.GetFileName(FilePath); long currentOffset = headerData.DataOffset; long processed = 0; var result = new PointCloudVerticalHistogram(bounds); using (var file = MemoryMappedFile.CreateFromFile(FilePath ?? throw new Exception("Input file not found."), FileMode.Open)) { var batchIndex = 0; var maxArraySize = TreeUtility.CalculateMaxArraySize(headerData.DataStride); var totalBatchCount = Mathf.CeilToInt((float)headerData.DataCount / maxArraySize); while (processed < headerData.DataCount) { var batchCount = Math.Min(maxArraySize, headerData.DataCount - processed); var batchSize = batchCount * headerData.DataStride; using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read)) { unsafe { batchIndex++; var progressBarTitle = $"Calculating bounds ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})"; var batchHistogram = PointImportJobs.GenerateHistogram(view, batchCount, headerData.DataStride, headerData.Elements, bounds, progressBarTitle); result.AddData(batchHistogram.regions); } } processed += batchCount; currentOffset += batchSize; } } return(result); }
public void UpdateForNode(NodeRecord record, float minimumDistance, bool alignDistance = false) { nodeRecord = record; if (alignDistance) { var newDist = Mathf.Min(rootBounds.size.x, rootBounds.size.z) / settings.rootNodeSubdivision; while (0.5f * newDist > settings.minPointDistance) { newDist *= 0.5f; } minimumDistance = newDist; } cellStep = minimumDistance; alignedBounds = TreeUtility.GetRoundedAlignedBounds(nodeRecord.Bounds, rootBounds.min, minimumDistance); EditorTreeUtility.CalculateGridSize(alignedBounds, minimumDistance, cellsPerAxis); }
public override void ProcessRequest(HttpContext context) { string target = context.Request["target"] ?? Targets.Preview; var selection = new SelectionUtility(context.Request, N2.Context.Current); ContentItem selectedItem = selection.SelectedItem; context.Response.ContentType = "text/plain"; ItemFilter filter = Engine.EditManager.GetEditorFilter(context.User); IContentAdapterProvider adapters = Engine.Resolve <IContentAdapterProvider>(); var node = new TreeHierarchyBuilder(selectedItem, 2) .Children((item) => adapters.ResolveAdapter <NodeAdapter>(item).GetChildren(item, Interfaces.Managing)) .Build(); string selectableTypes = context.Request["selectableTypes"]; string selectableExtensions = context.Request["selectableExtensions"]; TreeUtility.Write(node, selectedItem, adapters, filter, selectableTypes, selectableExtensions, excludeRoot: true, target: target, writer: context.Response.Output); }
/// <summary> /// Default <see cref="ConvertPoints"/> implementation for formats using <see cref="DefaultHeaderData"/>. /// </summary> /// <param name="headerData">Data extracted from file header.</param> /// <param name="target">Target processor dispatcher to which transformed points should be passed.</param> /// <param name="transformationData">Data used for transformation of the points.</param> /// <returns>True if conversion finished successfully, false otherwise.</returns> protected bool ConvertPointsDefault(DefaultHeaderData headerData, NodeProcessorDispatcher target, TransformationData transformationData) { var fileName = Path.GetFileName(FilePath); long currentOffset = headerData.DataOffset; long processed = 0; using (var file = MemoryMappedFile.CreateFromFile(FilePath, FileMode.Open)) { var batchIndex = 0; var maxArraySize = TreeUtility.CalculateMaxArraySize(headerData.DataStride); var totalBatchCount = Mathf.CeilToInt((float)headerData.DataCount / maxArraySize); while (processed < headerData.DataCount) { var batchCount = Math.Min(maxArraySize, headerData.DataCount - processed); var batchSize = batchCount * headerData.DataStride; using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read)) { batchIndex++; var progressBarTitle = $"Converting ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})"; var targetBuffer = target.PublicMaxSizeBuffer; PointImportJobs.ConvertData(view, targetBuffer, headerData.Elements, transformationData, headerData.DataStride, batchCount, progressBarTitle); target.AddChunk(targetBuffer, (int)batchCount); } processed += batchCount; currentOffset += batchSize; } } return(true); }
/// <summary> /// Default <see cref="CalculateBounds"/> implementation for formats using <see cref="DefaultHeaderData"/>. /// </summary> /// <param name="headerData">Data extracted from file header.</param> /// <returns>Bounds of points in given file.</returns> protected PointCloudBounds CalculateBoundsDefault(DefaultHeaderData headerData) { var fileName = Path.GetFileName(FilePath); long currentOffset = headerData.DataOffset; long processed = 0; var result = PointCloudBounds.Empty; using (var file = MemoryMappedFile.CreateFromFile(FilePath, FileMode.Open)) { var batchIndex = 0; var maxArraySize = TreeUtility.CalculateMaxArraySize(headerData.DataStride); var totalBatchCount = Mathf.CeilToInt((float)headerData.DataCount / maxArraySize); while (processed < headerData.DataCount) { var batchCount = Math.Min(maxArraySize, headerData.DataCount - processed); var batchSize = batchCount * headerData.DataStride; using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read)) { batchIndex++; var progressBarTitle = $"Calculating bounds ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})"; var batchBounds = PointImportJobs.CalculateBounds(view, batchCount, headerData.DataStride, headerData.Elements, progressBarTitle); result.Encapsulate(batchBounds); } processed += batchCount; currentOffset += batchSize; } } return(result); }