public void When_CreatingSimpleCubeBigGraph_ExpectRightWidth(Structure structure) { Component simpleCubeBig = structure.components[0]; NodeGraph simpleCubeBigGraph = ComponentGraphGenerator.GenerateComponentNodeGraph(simpleCubeBig); Assert.AreEqual(7, simpleCubeBigGraph.GetEdgeWidth(0)); }
public void When_CreatingNodegraphFromSimpleCube_Expect_Result(Structure structure) { Component simpleCube = structure.components[0]; NodeGraph nodegraph = ComponentGraphGenerator.GenerateComponentNodeGraph(simpleCube); NodeGraph expectedNodegraph = CreateNodegraphSimpleCube(); Assert.AreEqual(expectedNodegraph, nodegraph); }
public void When_CreatingSimpleLeftTurnGraph_ExpectRightWidths(Structure structure) { Component SimpleLeftTurn = structure.components[0]; NodeGraph SimpleLeftTurnGraph = ComponentGraphGenerator.GenerateComponentNodeGraph(SimpleLeftTurn); Assert.AreEqual(1, SimpleLeftTurnGraph.GetEdgeWidth(0)); Assert.AreEqual(Math.Sqrt(0.5), SimpleLeftTurnGraph.GetEdgeWidth(1)); Assert.AreEqual(1, SimpleLeftTurnGraph.GetEdgeWidth(2)); }
public void When_GenerateComponentNodeGraphFromComponentWithUnevenFloorVertices_Expect_NodeGraph(Structure structure) { Component component = structure.components[0]; NodeGraph nodeGraph = ComponentGraphGenerator.GenerateComponentNodeGraph(component); Vect3 node1coordinate = new Vect3(-0.5, -0.5, 0); Vect3 node2coordinate = new Vect3(7.5, -0.5, 0); Edge resultEdge = new Edge(1, 0); resultEdge.index = 0; resultEdge.width = 1; Assert.AreEqual(2, nodeGraph.Nodes.Count); Assert.AreEqual(1, nodeGraph.Edges.Count); Assert.That(nodeGraph.Nodes.Exists(n => n.coordinate == node1coordinate)); Assert.That(nodeGraph.Nodes.Exists(n => n.coordinate == node2coordinate)); Assert.Contains(resultEdge, nodeGraph.Edges); }
// Start is called before the first frame update void Start() { // Build Up Structure AssimpInterpreter interpreter = new AssimpInterpreter(); structure = interpreter.Interpret(AssetDatabase.GetAssetPath(files.modelFile)); VoxelGridGraphGenerator.outerLayerLimit = voxelStrategy.peelFactor; VoxelGridGraphGenerator.VoxelDistanceThreshold = voxelStrategy.GraphVoxelDeviationThreshold; VoxelGridGraphGenerator.mergeThreshold = voxelStrategy.mergeThreshold; VoxelGrid.DefaultComponentWiseResolutionDivider = voxelStrategy.ComponentResDivider; structureMiddlePoint = Utilities.GetStructureMiddlePoint(structure); bool draw = drawNodeGraph.drawNodes || drawNodeGraph.drawEdges; List <NodeGraph> nodeGraphs = new List <NodeGraph>(); List <VoxelGrid> voxelGrids = new List <VoxelGrid>(); List <(DistanceGrid, VoxelGrid)> skeletonGrids = new List <(DistanceGrid, VoxelGrid)>(); if (graphStrategy.strategy == Strategy.Voxel) { if (voxelStrategy.voxelScope == VoxelScope.component) { foreach (var component in structure.components) { gridTimer.Start(); VoxelGrid voxelGrid = new VoxelGrid(component); gridTimer.Stop(); gridProcessingTimer.Start(); if (draw || drawVoxels.fillInternalVolume || drawVoxels.skeletalize) { voxelGrid.FillInternalVolume(component); } gridProcessingTimer.Stop(); if (draw) { graphGenerationTimer.Start(); nodeGraphs.Add(VoxelGridGraphGenerator.GenerateNodeGraph(component)); graphGenerationTimer.Stop(); } if (drawVoxels.drawVoxels) { gridProcessingTimer.Start(); if (drawVoxels.skeletalize) { skeletonGrids.Add((VoxelGridGraphGenerator.GenerateSkeletalGrid(voxelGrid), voxelGrid)); } else if (drawVoxels.peel) { skeletonGrids.Add((VoxelGridGraphGenerator.GeneratePeeledGrid(voxelGrid), voxelGrid)); } gridProcessingTimer.Stop(); } voxelGrids.Add(voxelGrid); } } else if (voxelStrategy.voxelScope == VoxelScope.structure) { gridTimer.Start(); VoxelGrid voxelGrid = new VoxelGrid(structure, plane1Normal: Vect3.Right, plane2Normal: Vect3.Up, plane3Normal: Vect3.Forward); gridTimer.Stop(); gridProcessingTimer.Start(); if (draw || drawVoxels.fillInternalVolume || drawVoxels.skeletalize || drawVoxels.peel) { voxelGrid.FillInternalVolume(structure); } gridProcessingTimer.Stop(); if (draw) { graphGenerationTimer.Start(); nodeGraphs.Add(VoxelGridGraphGenerator.GenerateNodeGraph(structure)); graphGenerationTimer.Stop(); } if (drawVoxels.drawVoxels) { gridProcessingTimer.Start(); if (drawVoxels.skeletalize) { skeletonGrids.Add((VoxelGridGraphGenerator.GenerateSkeletalGrid(voxelGrid), voxelGrid)); } if (drawVoxels.peel) { skeletonGrids.Add((VoxelGridGraphGenerator.GeneratePeeledGrid(voxelGrid), voxelGrid)); } gridProcessingTimer.Stop(); } voxelGrids.Add(voxelGrid); } } else if (graphStrategy.strategy == Strategy.Mesh) { foreach (Nodegraph_Generator.Component component in structure.components) { graphGenerationTimer.Start(); nodeGraphs.Add(ComponentGraphGenerator.GenerateComponentNodeGraph(component)); graphGenerationTimer.Stop(); } if (meshStrategy.drawCollisions) { drawTimer.Start(); drawer.DrawCollisions(nodeGraphs, structureMiddlePoint); drawTimer.Stop(); } if (meshStrategy.unifyGraph) { graphGenerationTimer.Start(); NodeGraph nodeGraph = GraphUnifier.UnifyGraphs(nodeGraphs); graphGenerationTimer.Stop(); nodeGraphs.Clear(); nodeGraphs.Add(nodeGraph); } } else if (graphStrategy.strategy == Strategy.XML) { graphGenerationTimer.Start(); nodeGraphs.Add(XMLCreator.readXML <NodeGraph>(AssetDatabase.GetAssetPath(files.XMLFile))); graphGenerationTimer.Stop(); } drawTimer.Start(); if (drawStructure.drawFaces || drawStructure.drawVertices) { drawer.DrawStructure(drawStructure, structure, structureMiddlePoint); } if (drawOBBs.oBBType == OBBType.components) { foreach (var voxelGrid in voxelGrids) { foreach (var oBB in voxelGrid.componentOBBs.Values) { drawer.DrawOBB(oBB, drawOBBs, structureMiddlePoint); } } } else if (drawOBBs.oBBType == OBBType.voxelGrid) { foreach (var voxelGrid in voxelGrids) { drawer.DrawOBB(voxelGrid.orientedBbox, drawOBBs, structureMiddlePoint); } } if (drawVoxels.drawVoxels) { if (drawVoxels.skeletalize || drawVoxels.peel) { foreach (var skeletonGrid in skeletonGrids) { drawer.DrawSkeletonGrid(skeletonGrid.Item1, skeletonGrid.Item2, structureMiddlePoint); } } else { foreach (var voxelGrid in voxelGrids) { drawer.DrawVoxelGrid(voxelGrid, structureMiddlePoint); } } } if (drawNodeGraph.drawNodes || drawNodeGraph.drawEdges) { foreach (NodeGraph nodeGraph in nodeGraphs) { drawer.DrawNodeGraph(drawNodeGraph, nodeGraph, structureMiddlePoint); } } drawTimer.Stop(); if (graphStrategy.writeXML && !(graphStrategy.strategy == Strategy.XML)) { if (nodeGraphs.Count == 1) { string filename = System.IO.Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(files.modelFile)); filename += ".xml"; XMLCreator.writeXML(nodeGraphs[0], System.IO.Path.Combine("Assets", "XML", filename)); } else { string filename = System.IO.Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(files.modelFile)); int counter = 1; foreach (NodeGraph nodeGraph in nodeGraphs) { string subfilename = filename + (counter++) + ".xml"; XMLCreator.writeXML(nodeGraphs[0], System.IO.Path.Combine("Assets", "XML", subfilename)); } } } ReportProcessTimes(); }