protected override void UpdateForChangedParams() { base.UpdateForChangedParams(); if (depth != _oldDepth || reducedResolution != _oldreducedResolution || _oldFullResolution != fullResolution || IsInitialized() == false || _featureMaps == null) { InitFeatureMaps(); _oldreducedResolution = reducedResolution; _oldFullResolution = fullResolution; _oldDepth = depth; } if (_fullResGrid == null) { _fullResGrid = new GridShape(new Vector3(0, 0, this.ZPosition() - fullresOffset), fullResolution, new Vector2(pixelSpacing, pixelSpacing)); } _fullResGrid.position = new Vector3(0, 0, -fullresOffset); _fullResGrid.spacing = new Vector2(pixelSpacing, pixelSpacing); _fullResGrid.resolution = fullResolution; }
private void InitGrids() { _pixelGrid = new GridShape(position, _shape, Get2DSpacing()); _outputGrid = new GridShape(_outputPosition, _shape, Get2DSpacing()); _allCalcFilterGrids = new List <Shape>(); Vector2 safeSpacing = new Vector2(0.0f, 0.0f); if (_convShape.x > 1) { safeSpacing = (_shape.x - 1) / (float)(_convShape.x - 1) * Get2DSpacing(); } _filterGrid = new GridShape(_outputPosition, _convShape, safeSpacing); Vector3[] allCalcPositions; if (_outputShape == _shape) //means stride == 1 { allCalcPositions = _pixelGrid.GetVertices(true); } else { _outputGrid = new GridShape(_outputPosition, _outputShape, Get2DSpacing() * stride.x); allCalcPositions = _outputGrid.GetVertices(true); } for (int i = 0; i < allCalcPositions.Length; i++) { _allCalcFilterGrids.Add(new GridShape(allCalcPositions[i], _convShape, safeSpacing)); } }
/// <summary> /// Returns Grids in the shape of the conv filter, usually serving as out connections of the according layer. /// </summary> /// <param name="outputShape">Calculated integer 2d featuremap shape of this layer, taking into account stride and padding.</param> /// <param name="theoreticalOutputShape">Calculated float 2d featuremap shape of this layer, taking into account stride and padding. Can contain fractional part because of stride division.</param> /// <param name="stride"></param> /// <param name="allCalcs">Interpolation parameter for all calc view</param> /// <returns></returns> public List <Shape> GetFilterGrids(Vector2Int outputShape, Vector2 theoreticalOutputShape, Vector2Int stride, float allCalcs) { //check if requested outputshape is same as existing, reinit allcalgrids if not if (outputShape != this._outputShape || stride != this.stride || this._theoreticalOutputShape != theoreticalOutputShape && outputShape != new Vector2Int(0, 0)) { this._outputShape = outputShape; this._theoreticalOutputShape = theoreticalOutputShape; this._outputPosition = position + GetOutputGridOffset(theoreticalOutputShape, outputShape); this.stride = stride; InitGrids(); } if (allCalcs == 0) { List <Shape> filterGrids = new List <Shape>(); filterGrids.Add(_filterGrid); return(filterGrids); } else { List <Shape> filterGrids = new List <Shape>(); foreach (GridShape gr in _allCalcFilterGrids) { gr.spacing /= (_shape.x - 1) / (float)(_convShape.x - 1); GridShape interpolated = gr.InterpolatedGrid(((GridShape)_filterGrid), 1.0f - allCalcs); filterGrids.Add(interpolated); } return(filterGrids); } }
/// <summary> /// Returns the vertices of the grid used for the full res visualization /// </summary> /// <returns></returns> private Vector3[] fullResGridVerts() { int root = Mathf.CeilToInt(Mathf.Sqrt(fullDepth)); GridShape grid = new GridShape(CenterPosition(), new Vector2Int(root, root), new Vector2(filterSpread, filterSpread)); return(grid.GetVertices(false)); }
private Vector3[] GetInterpolatedFilterPositions() { int filterNumGridShape = Mathf.CeilToInt(Mathf.Sqrt(filterNum)); Vector3[] gridPositions = GridShape.ScaledUnitGrid(filterNumGridShape, filterNumGridShape, Vector3.zero, spacing.x); Vector3[] linePositions = LineShape.ScaledUnitLine(filterNum, Vector3.zero, new Vector3(1, 0, 0), spacing.x); Vector3[] filterPositions = Shape.InterpolateShapes(linePositions, gridPositions, 1.0f); // TOFO: Maybe integrate lineToGrid parameter, but for now only grid return(filterPositions); }
public GridShape InterpolatedGrid(GridShape target, float alpha) { if (this.resolution != target.resolution) { throw new System.Exception("Grid Resolution has to match!"); } Vector3 pos = this.position * (1.0f - alpha) + target.position * alpha; Vector2 spacing = this.spacing * (1.0f - alpha) + target.spacing * alpha; return(new GridShape(pos, this.resolution, spacing)); }
/// <inheritdoc /> public bool Equals([AllowNull] Polar other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Domain == other.Domain || Domain != null && Domain.Equals(other.Domain) ) && ( Equals(Sector, other.Sector) || Sector != null && other.Sector != null && Sector.SequenceEqual(other.Sector) ) && ( Hole == other.Hole || Hole != null && Hole.Equals(other.Hole) ) && ( BgColor == other.BgColor || BgColor != null && BgColor.Equals(other.BgColor) ) && ( RadialAxis == other.RadialAxis || RadialAxis != null && RadialAxis.Equals(other.RadialAxis) ) && ( AngularAxis == other.AngularAxis || AngularAxis != null && AngularAxis.Equals(other.AngularAxis) ) && ( GridShape == other.GridShape || GridShape != null && GridShape.Equals(other.GridShape) ) && ( UiRevision == other.UiRevision || UiRevision != null && UiRevision.Equals(other.UiRevision) )); }
/// <summary> /// Returns a List of Shapes representing the pixels of the feature maps. /// </summary> /// <returns></returns> protected override List <Shape> GetPointShapes() { UpdateNodes(); List <Shape> pixelGrids = new List <Shape>(); for (int i = 0; i < _nodePositions.Count; i++) { GridShape dummyGrid = new GridShape(_nodePositions[i], new Vector2Int(1, 1), new Vector2(0.0f, 0.0f)); pixelGrids.Add(dummyGrid); } return(pixelGrids); }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Domain != null) { hashCode = hashCode * 59 + Domain.GetHashCode(); } if (Sector != null) { hashCode = hashCode * 59 + Sector.GetHashCode(); } if (Hole != null) { hashCode = hashCode * 59 + Hole.GetHashCode(); } if (BgColor != null) { hashCode = hashCode * 59 + BgColor.GetHashCode(); } if (RadialAxis != null) { hashCode = hashCode * 59 + RadialAxis.GetHashCode(); } if (AngularAxis != null) { hashCode = hashCode * 59 + AngularAxis.GetHashCode(); } if (GridShape != null) { hashCode = hashCode * 59 + GridShape.GetHashCode(); } if (UiRevision != null) { hashCode = hashCode * 59 + UiRevision.GetHashCode(); } return(hashCode); } }
/// <summary> /// As we require much less vertices and line polygons when the edge bundling is turned up to 1.0, the mesh is calculated differently (in this function). /// </summary> /// <param name="verts"></param> /// <param name="lineInds"></param> /// <param name="inputFilterPoints"></param> void AddFullyBundledLines(List <Vector3> verts, List <int> lineInds, List <List <Shape> > inputFilterPoints) { Vector3 posDiff = new Vector3(0, 0, -zOffset); Vector3 zPos = new Vector3(0, 0, ZPosition()); Vector3 end_vert0 = _nodePositions[0]; Vector3 edgeBundleCenter = GetEdgeBundleCenter(end_vert0, 1f); verts.Add(edgeBundleCenter); int bundle_center_ind = verts.Count - 1; //for each of this Layers Points for (int h = 0; h < _nodePositions.Count; h++) { //line endpoint Vector3 end_vert = _nodePositions[h]; verts.Add(end_vert + zPos); int end_ind = verts.Count - 1; lineInds.Add(end_ind); lineInds.Add(bundle_center_ind); } //for each input feature map for (int i = 0; i < inputFilterPoints.Count; i++) { //for each input conv grid List <Shape> featureMapGrids = inputFilterPoints[i]; for (int j = 0; j < featureMapGrids.Count; j++) { GridShape gridShape = (GridShape)featureMapGrids[j]; //scale shape spacing by collapse input gridShape.spacing *= (1.0f - collapseInput); Vector3[] start_verts = gridShape.GetVertices(true); //for each conv point for (int k = 0; k < start_verts.Length; k++) { lineInds.Add(bundle_center_ind); verts.Add(start_verts[k] + zPos + posDiff); lineInds.Add(verts.Count - 1); } } } }
public bool DoesShapeIntersectOthers(GridShape rd) { List <Vector2Int> indices = new List <Vector2Int>(); rd.GetIndicesInShape(ref indices, Buffer); foreach (Vector2Int vi in indices) { foreach (GridShape gs in m_Shapes) { if (gs.isPointInShape(vi)) { return(true); } } } return(false); }
public Shape GetInputGrid(float allCalcs) { if (allCalcs == 0) { return(new GridShape(position, _shape, new Vector2(0, 0))); } else if (allCalcs == 1.0f) { return(_pixelGrid); } else { GridShape degenerate = new GridShape(position, _shape, new Vector2(0, 0)); GridShape interpolated = degenerate.InterpolatedGrid(_pixelGrid, allCalcs); return(interpolated); } }
//List<double> times = new List<double>(); //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); public CAGraph(CA parent, ValueTuple <ushort, ushort, ushort> size, GridShape shape) : base(CAEntityType.Graph) { this.Parent = parent; this.Shape = shape; AgentCells = new List <ValueTuple <ushort, ushort, ushort> >(); Updates = new List <ValueTuple <ushort, ushort, ushort> >(); Dimensions = new ValueTuple <ushort, ushort, ushort>(size.Item1, size.Item2, size.Item3); Cells = new CAGraphCell[size.Item1, size.Item2, size.Item3]; for (ushort i = 0; i < Cells.GetLength(0); i++) { for (ushort j = 0; j < Cells.GetLength(1); j++) { for (ushort k = 0; k < Cells.GetLength(2); k++) { Cells[i, j, k] = new CAGraphCell(this, new ValueTuple <ushort, ushort, ushort>(i, j, k)); } } } }
protected void AddNodes(List <Vector3> verts, List <int> inds, List <int> fullResInds, List <int> lineInds) { base.AddNodes(verts, inds); if (showOriginalResolution) { Vector3[] v = _fullResGrid.GetVertices(true); verts.AddRange(v); for (int i = 0; i < v.Length; i++) { fullResInds.Add(verts.Count - v.Length + i); } GridShape centerGrid = _featureMaps[_featureMaps.Count / 2].GetPixelGrid(); float[] bbox = centerGrid.GetBbox(); float[] zpos = { 0, -fullresOffset }; List <int> lineStartEndInds = new List <int>(); foreach (float z in zpos) { verts.Add(new Vector3(bbox[0], bbox[1], centerGrid.position.z + z)); lineStartEndInds.Add(verts.Count - 1); verts.Add(new Vector3(bbox[0], bbox[3], centerGrid.position.z + z)); lineStartEndInds.Add(verts.Count - 1); verts.Add(new Vector3(bbox[2], bbox[1], centerGrid.position.z + z)); lineStartEndInds.Add(verts.Count - 1); verts.Add(new Vector3(bbox[2], bbox[3], centerGrid.position.z + z)); lineStartEndInds.Add(verts.Count - 1); } for (int i = 0; i < 4; i++) { lineInds.Add(lineStartEndInds[i]); lineInds.Add(lineStartEndInds[i + 4]); } } }
/// <summary> /// Calculates the position of the nodes according to parameters. /// </summary> /// <returns></returns> protected Vector3[] GetInterpolatedNodePositions() { int reducedDepthGridShape = Mathf.CeilToInt(Mathf.Sqrt(reducedDepth)); Vector3[] gridPositions = GridShape.ScaledUnitGrid(reducedDepthGridShape, reducedDepthGridShape, new Vector3(0, 0, 0), filterSpread); Vector3[] linePositionsX = LineShape.ScaledUnitLine(reducedDepth, new Vector3(0, 0, 0), new Vector3(1, 0, 0), filterSpread * (reducedDepthGridShape / (float)reducedDepth)); Vector3[] linePositionsZ = LineShape.ScaledUnitLine(reducedDepth, new Vector3(0, 0, 0), new Vector3(0, 0, 1), filterSpread * (reducedDepthGridShape / (float)reducedDepth)); Vector3[] linePositions = Shape.InterpolateShapes(linePositionsX, linePositionsZ, lineXToZ); Vector3[] circlePositions = CircleShape.ScaledUnitCircle(reducedDepth, new Vector3(0, 0, 0), filterSpread); Vector3[] filterPositions = null; if (lineCircleGrid < 1.0f) { filterPositions = Shape.InterpolateShapes(linePositions, circlePositions, lineCircleGrid); } else if (lineCircleGrid <= 2.0f) { filterPositions = Shape.InterpolateShapes(circlePositions, gridPositions, lineCircleGrid - 1.0f); } return(filterPositions); }
private List <GridShape> GetLineBetweenPoints(Vector2Int a, Vector2Int b) { List <GridShape> result = new List <GridShape>(); List <Vector2Int> allPoints = GetPointsOnLine(a, b); foreach (Vector2Int vi in allPoints) { GridShape gs = new GridShape(); gs.shape = HallwayShape; gs.position = vi; int size = Random.Range(HallwayMinSize, HallwayMaxSize); gs.width = size; if (!HallWayUniformSize) { size = Random.Range(HallwayMinSize, HallwayMaxSize); } gs.height = size; result.Add(gs); } return(result); }
public CAGraph(CA parent, ValueTuple <ushort, ushort, ushort> size, GridShape shape, List <ValueTuple <ushort, ushort, ushort> > agents, CAGraphCell[,,] cells, Dictionary <string, dynamic> properties) : base(CAEntityType.Graph, properties) { Parent = parent; Shape = shape; AgentCells = agents.ConvertAll(x => new ValueTuple <ushort, ushort, ushort>(x.Item1, x.Item2, x.Item3)); Updates = new List <ValueTuple <ushort, ushort, ushort> >(); Dimensions = new ValueTuple <ushort, ushort, ushort>(size.Item1, size.Item2, size.Item3); Cells = new CAGraphCell[size.Item1, size.Item2, size.Item3]; for (ushort i = 0; i < size.Item1; i++) { for (ushort j = 0; j < size.Item2; j++) { for (ushort k = 0; k < size.Item3; k++) { //if(i == 500 && j == 500) //{ // Console.WriteLine(); //} Cells[i, j, k] = cells[i, j, k].Copy(this); } } } }
private void SetShapeData() { Random.InitState(noiseGraph.m_MasterNode.Seed); //may not need this m_Area = new int[m_NoiseParentSize.x, m_NoiseParentSize.y]; m_Shapes = new List <GridShape>(); for (int i = 0; i < m_MaxShapeCount; i++) { GridShape rd = new GridShape(); rd.shape = m_Shape; rd.width = (int)Random.Range(m_ShapeSizeMin.x, m_ShapeSizeMax.x); rd.height = (int)Random.Range(m_ShapeSizeMin.y, m_ShapeSizeMax.y); rd.position.x = Mathf.FloorToInt(Mathf.Lerp((rd.width * 0.5f), m_Area.GetLength(0) - (rd.width * 0.5f) - 1, Random.Range(0.0f, 1.0f))); rd.position.y = Mathf.FloorToInt(Mathf.Lerp((rd.height * 0.5f), m_Area.GetLength(1) - (rd.height * 0.5f) - 1, Random.Range(0.0f, 1.0f))); bool m_shouldAdd = true; switch (m_PlacementMode) { default: case PlacementMode.AlwaysPlace: break; case PlacementMode.DiscardFailedPlace: if (DoesShapeIntersectOthers(rd)) { m_shouldAdd = false; } break; } if (m_shouldAdd) { m_Shapes.Add(rd); } } }
public override void UpdateData(bool withOutputs = true) { m_NoiseParentSize = noiseGraph.Size; m_Input = GetPort("m_Input").GetInputValue <List <GridShape> >(); m_result = new float[m_NoiseParentSize.x * m_NoiseParentSize.y]; Random.InitState(noiseGraph.Seed); if (m_Input == null) { return; } //construct mst List <EdgeData> allEdges = new List <EdgeData>(); for (int starts = 0; starts < m_Input.Count; starts++) { for (int ends = 0; ends < starts; ends++) { if (starts == ends) { continue; } EdgeData ed = new EdgeData(); ed.a = starts; ed.b = ends; ed.weight = Vector2Int.Distance(m_Input[starts].position, m_Input[ends].position); allEdges.Add(ed); } } List <int> processedIndices = new List <int>(); List <EdgeData> minimumEdges = new List <EdgeData>(); processedIndices.Add(Random.Range(0, m_Input.Count)); for (int i = 0; i < m_Input.Count - 1; i++) { float lowDistance = Mathf.Infinity; EdgeData target = null; foreach (EdgeData ed in allEdges) { if (processedIndices.Contains(ed.a) ^ processedIndices.Contains(ed.b)) { if (ed.weight <= lowDistance) { lowDistance = ed.weight; target = ed; } } } minimumEdges.Add(target); allEdges.Remove(target); if (!processedIndices.Contains(target.a)) { processedIndices.Add(target.a); } if (!processedIndices.Contains(target.b)) { processedIndices.Add(target.b); } } for (int i = 0; i < AdditionalConnectionsToMake; i++) { float lowDistance = Mathf.Infinity; EdgeData target = null; foreach (EdgeData ed in allEdges) { if (ed.weight <= lowDistance) { lowDistance = ed.weight; target = ed; } } if (target == null) { break; } minimumEdges.Add(target); allEdges.Remove(target); } foreach (EdgeData ed in minimumEdges) { GridShape a = m_Input[ed.a]; GridShape b = m_Input[ed.b]; Vector2Int startPos = a.position; Vector2Int endPos = b.position; bool axisAlignedPlaced = false; switch (RoomPositionSample) { case HallwayAttach.RandomInside: startPos = a.GetRandomIndexInShape(); endPos = b.GetRandomIndexInShape(); break; case HallwayAttach.AxisAligned: axisAlignedPlaced = ConnectGridsAxisAligned(a, b, ref startPos, ref endPos); break; } //will need to support multiple lines here for proper axis aligned. if (axisAlignedPlaced) { continue; } m_Shapes = GetLineBetweenPoints(startPos, endPos); List <Vector2Int> m_targetPositions = new List <Vector2Int>(); foreach (GridShape gs in m_Shapes) { gs.GetIndicesInShape(ref m_targetPositions); } foreach (Vector2Int pos in m_targetPositions) { if (GridToArray(pos) < m_result.Length && GridToArray(pos) >= 0) { m_result[GridToArray(pos)] = MapValue; } } } base.UpdateData(withOutputs); }
private bool ConnectGridsAxisAligned(GridShape startShape, GridShape endShape, ref Vector2Int startPos, ref Vector2Int endPos) { //we pad with min hallway size to cover our bases - not always going to work out //KPD TODO revisit padding here. Vector2Int minA = new Vector2Int(startShape.MinX() + HallwayMinSize, startShape.MinY() + HallwayMinSize); Vector2Int maxA = new Vector2Int(startShape.MaxX() - HallwayMinSize, startShape.MaxY() - HallwayMinSize); Vector2Int minB = new Vector2Int(endShape.MinX() + HallwayMinSize, endShape.MinY() + HallwayMinSize); Vector2Int maxB = new Vector2Int(endShape.MaxX() - HallwayMinSize, endShape.MaxY() - HallwayMinSize); startPos = new Vector2Int(Random.Range(minA.x, maxA.x), Random.Range(minA.y, maxA.y)); endPos = new Vector2Int(Random.Range(minB.x, maxB.x), Random.Range(minB.y, maxB.y)); bool overlapOnX = (minA.x <= maxB.x && maxA.x >= minB.x); bool overlapOnY = (minA.y <= maxB.y && maxA.y >= minB.y); if (overlapOnX && overlapOnY) { return(false); //already overlapping on both axes. } if (overlapOnX) { startPos.x = Random.Range(Mathf.Max(minA.x, minB.x), Mathf.Min(maxA.x, maxB.x)); startPos.y = Random.Range(minA.y, maxA.y); endPos.x = startPos.x; endPos.y = Random.Range(minB.y, maxB.y); return(false); } else if (overlapOnY) { startPos.y = Random.Range(Mathf.Max(minA.y, minB.y), Mathf.Min(maxA.y, maxB.y)); startPos.x = Random.Range(minA.x, maxA.x); endPos.y = startPos.y; endPos.x = Random.Range(minB.x, maxB.x); return(false); } //at this point we need a bend, so we make the joint int jointX = startPos.x; int jointY = endPos.y; //and then do all the work to get and set these 2 paths. m_Shapes = GetLineBetweenPoints(startPos, new Vector2Int(jointX, jointY)); m_Shapes.AddRange(GetLineBetweenPoints(new Vector2Int(jointX, jointY), endPos)); List <Vector2Int> m_targetPositions = new List <Vector2Int>(); foreach (GridShape gs in m_Shapes) { gs.GetIndicesInShape(ref m_targetPositions); } foreach (Vector2Int pos in m_targetPositions) { if (GridToArray(pos) < m_result.Length && GridToArray(pos) >= 0) { m_result[GridToArray(pos)] = MapValue; } } //returning true tells the calling method that it doesn't need to generate it's path //as we've done it above. return(true); }
override public void CalcMesh() { if (input == null) { base.CalcMesh(); return; } _mesh.subMeshCount = 2; //POINTS List <Vector3> verts = new List <Vector3>(); List <Color> cols = new List <Color>(); List <float> activations = new List <float>(); List <int> inds = new List <int>(); Vector3 posDiff = new Vector3(0, 0, -zOffset); Vector3 zPos = new Vector3(0, 0, ZPosition()); AddNodes(verts, inds); for (int i = 0; i < verts.Count; i++) { if (_activationTensorPerEpoch.ContainsKey(epoch)) { int[] index = Util.GetSampleMultiDimIndices(_activationTensorShape, i, GlobalManager.Instance.testSample); Array activationTensor = _activationTensorPerEpoch[epoch]; float tensorVal = (float)activationTensor.GetValue(index); activations.Add(tensorVal); tensorVal *= pointBrightness; cols.Add(new Color(tensorVal, tensorVal, tensorVal, 1f)); //cols.Add(Color.white); } else { cols.Add(Color.black); } } if (showOriginalDepth) { AddFullResNodes(verts, inds); } int diff = verts.Count - cols.Count; for (int i = 0; i < diff; i++) { cols.Add(Color.black); } //LINES Vector2Int inputShape = new Vector2Int(1, 1); if (collapseInput != 1.0f) { inputShape = new Vector2Int(_inputLayer.GetOutputShape().x, _inputLayer.GetOutputShape().y); } //Input Layer Points, each inner List only contains one point List <List <Shape> > inputFilterPoints = _inputLayer.GetLineStartShapes(inputShape, new Vector2Int(1, 1), new Vector2(1, 1), new Vector2Int(1, 1), 0.0f); List <int> lineInds = new List <int>(); if (edgeBundle == 1f) { AddFullyBundledLines(verts, lineInds, inputFilterPoints); diff = verts.Count - cols.Count; for (int i = 0; i < diff; i++) { cols.Add(Color.black); } } else { //for each of this Layers Points for (int h = 0; h < _nodePositions.Count; h++) { //line endpoint Vector3 end_vert = _nodePositions[h]; verts.Add(end_vert + zPos); cols.Add(Color.black); int end_ind = verts.Count - 1; Vector3 edgeBundleCenter = GetEdgeBundleCenter(end_vert, edgeBundle); int bundle_center_ind = 0; if (edgeBundle > 0) { verts.Add(edgeBundleCenter); cols.Add(Color.black); bundle_center_ind = verts.Count - 1; } //for each input feature map for (int i = 0; i < inputFilterPoints.Count; i++) { //for each input conv grid List <Shape> featureMapGrids = inputFilterPoints[i]; for (int j = 0; j < featureMapGrids.Count; j++) { GridShape gridShape = (GridShape)featureMapGrids[j]; //scale shape spacing by collapse input gridShape.spacing *= (1.0f - collapseInput); Vector3[] start_verts = gridShape.GetVertices(true); //for each conv point for (int k = 0; k < start_verts.Length; k++) { lineInds.Add(end_ind); if (edgeBundle > 0) { lineInds.Add(bundle_center_ind); lineInds.Add(bundle_center_ind); } verts.Add(start_verts[k] + zPos + posDiff); if (_tensorPerEpoch.ContainsKey(epoch)) { Array tensor = _tensorPerEpoch[epoch]; int[] index = { i *k, h }; if (_inputLayer.GetType().Equals(typeof(FCLayer))) { index[0] = j; } float activationMult = 1f; if (GlobalManager.Instance.multWeightsByActivations) { activationMult = activations[j]; } float tensorVal = (float)tensor.GetValue(index) * weightBrightness * activationMult; cols.Add(new Color(tensorVal, tensorVal, tensorVal, 1f)); } else { cols.Add(Color.black); } lineInds.Add(verts.Count - 1); } } } } } _mesh.SetVertices(verts); _mesh.SetColors(cols); _mesh.SetIndices(inds.ToArray(), MeshTopology.Points, 0); _mesh.SetIndices(lineInds.ToArray(), MeshTopology.Lines, 1); Debug.Log("vertcount: " + verts.Count); }
override public void CalcMesh() { if (input == null) { base.CalcMesh(); return; } _mesh.subMeshCount = 2; List <Vector3> verts = new List <Vector3>(); List <Color> cols = new List <Color>(); List <int> inds = new List <int>(); Vector3 posDiff = new Vector3(0, 0, -zOffset); Vector3 zPos = new Vector3(0, 0, ZPosition()); AddNodes(verts, inds); for (int i = 0; i < verts.Count; i++) { if (_activationTensorPerEpoch.ContainsKey(epoch)) { int[] index = Util.GetSampleMultiDimIndices(_activationTensorShape, i, GlobalManager.Instance.testSample); Array activationTensor = _activationTensorPerEpoch[epoch]; float tensorVal = (float)activationTensor.GetValue(index) * pointBrightness; cols.Add(new Color(tensorVal, tensorVal, tensorVal, 1f)); //cols.Add(Color.white); } else { cols.Add(Color.black); } } List <List <Shape> > inputFilterPoints = _inputLayer.GetLineStartShapes(convShape, _featureMapResolution, _featureMapTheoreticalResolution, stride, allCalculations); List <int> lineInds = new List <int>(); //TODO: reuse generated vert positions //for each output feature map for (int h = 0; h < _featureMaps.Count; h++) { //line endpoints GridShape inputGrid = (GridShape)_featureMaps[h].GetInputGrid(allCalculations); Vector3[] end_verts = inputGrid.GetVertices(true); Vector3[] edgeBundleCenters = new Vector3[end_verts.Length]; for (int i = 0; i < edgeBundleCenters.Length; i++) { edgeBundleCenters[i] = GetEdgeBundleCenter(end_verts[i], edgeBundle); } //for each input conv grid List <Shape> featureMapGrids = inputFilterPoints[h]; for (int j = 0; j < featureMapGrids.Count; j++) { GridShape gridShape = (GridShape)featureMapGrids[j]; Vector3[] start_verts = gridShape.GetVertices(true); if (j >= end_verts.Length) { continue; } verts.Add(end_verts[j] + zPos); int start_ind = verts.Count - 1; int bundle_center_ind = 0; if (edgeBundle > 0) { verts.Add(edgeBundleCenters[j]); bundle_center_ind = verts.Count - 1; } for (int k = 0; k < start_verts.Length; k++) { verts.Add(start_verts[k] + zPos + posDiff); lineInds.Add(start_ind); if (edgeBundle > 0) { lineInds.Add(bundle_center_ind); lineInds.Add(bundle_center_ind); } lineInds.Add(verts.Count - 1); } } } _mesh.SetVertices(verts); int diff = verts.Count - cols.Count; for (int i = 0; i < diff; i++) { cols.Add(Color.black); } _mesh.SetColors(cols); _mesh.SetIndices(inds.ToArray(), MeshTopology.Points, 0); _mesh.SetIndices(lineInds.ToArray(), MeshTopology.Lines, 1); }
override public void CalcMesh() { Debug.Log(name); if (input == null) { base.CalcMesh(); return; } _mesh.subMeshCount = 3; List <Vector3> verts = new List <Vector3>(); List <Color> cols = new List <Color>(); List <float> activations = new List <float>(); List <int> inds = new List <int>(); List <int> lineInds = new List <int>(); List <int> polyInds = new List <int>(); Vector3 posDiff = new Vector3(0, 0, -zOffset); Vector3 zPos = new Vector3(0, 0, ZPosition()); AddNodes(verts, inds); for (int i = 0; i < verts.Count; i++) { if (_activationTensorPerEpoch.ContainsKey(epoch)) { int[] index = Util.GetSampleMultiDimIndices(_activationTensorShape, i, GlobalManager.Instance.testSample); Array activationTensor = _activationTensorPerEpoch[epoch]; float tensorVal = (float)activationTensor.GetValue(index); if (allCalculations > 0) { activations.Add(tensorVal); } tensorVal *= pointBrightness; cols.Add(new Color(tensorVal, tensorVal, tensorVal, 1f)); //cols.Add(Color.white); } else { cols.Add(Color.black); } } List <List <Shape> > inputFilterPoints = _inputLayer.GetLineStartShapes(convShape, _featureMapResolution, _featureMapTheoreticalResolution, stride, allCalculations); inputFilterPoints = _inputLayer.GetLineStartShapes(convShape, _featureMapResolution, _featureMapTheoreticalResolution, stride, allCalculations, this.convLocation); //TODO: reuse generated vert positions //for each output feature map for (int h = 0; h < _featureMaps.Count; h++) { //line endpoints GridShape inputGrid = (GridShape)_featureMaps[h].GetInputGrid(allCalculations); Vector3[] end_verts = inputGrid.GetVertices(true); Vector3[] edgeBundleCenters = new Vector3[end_verts.Length]; for (int i = 0; i < edgeBundleCenters.Length; i++) { edgeBundleCenters[i] = GetEdgeBundleCenter(end_verts[i], edgeBundle); } //for each input feature map for (int i = 0; i < inputFilterPoints.Count; i++) { //for each input conv grid List <Shape> featureMapGrids = inputFilterPoints[i]; for (int j = 0; j < featureMapGrids.Count; j++) { GridShape gridShape = (GridShape)featureMapGrids[j]; Vector3[] start_verts = gridShape.GetVertices(true); verts.Add(end_verts[j] + zPos); cols.Add(Color.black); int start_ind = verts.Count - 1; int bundle_center_ind = 0; if (edgeBundle > 0) { verts.Add(edgeBundleCenters[j]); cols.Add(Color.black); bundle_center_ind = verts.Count - 1; } for (int k = 0; k < start_verts.Length; k++) { verts.Add(start_verts[k] + zPos + posDiff); if (_weightTensorPerEpoch.ContainsKey(epoch)) { Array tensor = _weightTensorPerEpoch[epoch]; int kernelInd1 = k % convShape.x; int kernelInd2 = k / convShape.y; int[] index = { kernelInd1, kernelInd2, 0, h }; float activationMult = 1f; if (allCalculations > 0 && GlobalManager.Instance.multWeightsByActivations) { activationMult = activations[j]; } float tensorVal = (float)tensor.GetValue(index) * weightBrightness * activationMult; cols.Add(new Color(tensorVal, tensorVal, tensorVal, 1f)); } else { cols.Add(Color.black); } lineInds.Add(start_ind); if (edgeBundle > 0) { lineInds.Add(bundle_center_ind); lineInds.Add(bundle_center_ind); } lineInds.Add(verts.Count - 1); } } } } if (showOriginalDepth) { AllFeatureMapsDisplay allFeatureMapsDisplay = new AllFeatureMapsDisplay(new Vector3(0, fullResHeight, ZPosition()), fullDepth, lineCircleGrid, new Vector2(allFiltersSpacing, allFiltersSpacing)); allFeatureMapsDisplay.AddPolysToLists(verts, polyInds); GridShape firstFeatureMapGrid = _featureMaps[_featureMaps.Count - 1].GetPixelGrid(); allFeatureMapsDisplay.AddLinesToLists(verts, lineInds, firstFeatureMapGrid.BboxV(zPos.z)); } //fill with dummy colors int diff = verts.Count - cols.Count; Debug.Log("diff " + diff + " polyInds " + polyInds.Count + " inds " + inds.Count + " lineInds " + lineInds.Count + " cols " + cols.Count + " verts " + verts.Count); for (int i = 0; i < diff; i++) { cols.Add(Color.white); } _mesh.SetVertices(verts); _mesh.SetColors(cols); _mesh.SetIndices(inds.ToArray(), MeshTopology.Points, 0); _mesh.SetIndices(lineInds.ToArray(), MeshTopology.Lines, 1); _mesh.SetIndices(polyInds.ToArray(), MeshTopology.Triangles, 2); }