public void createCubeObject(FeatureMapData featureMapData, string name, float pixel) { gameObject.name = name; textureFeature = new Texture2D(1, 1); Color[] pixels = new Color[1]; pixels[0] = new Color(pixel, pixel, pixel, 1); textureFeature.SetPixels(pixels); textureFeature.Apply(); gameObject.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", textureFeature); gameObject.transform.position = new Vector3(featureMapData.getCoordX(), featureMapData.getCoordY(), featureMapData.getCoordZ()); gameObject.transform.Rotate(0, 0, 0, Space.Self); gameObject.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * 30; }
public StructHelper makeFeature(GameObject fetureTemplate, GameObject featurePredictionsTemplate, Dictionary <string, Dictionary <string, ushort[][]> > feature) { FeatureMapData featureMapData = new FeatureMapData(); int index; int counter; GameObject go; initStructObjects(); featureMapData.setCoordX(0); featureMapData.setCoordY(0); featureMapData.setCoordZ(0); int counterLayers = 0; int scalingFactor = 40; var labels = new List <string>(feature["labels"].Keys); foreach (KeyValuePair <string, Dictionary <string, ushort[][]> > layer in feature) { counter = 0; counterLayers = counterLayers + 1; featureMapData.setCoordScale(scalingFactor / counterLayers); Tuple <int, int> divisors = closestDivisors(layer.Value.Count); featureMapData.setCoordY(0); featureMapData.setCoordX(0); featureMapData.setCoordZ(featureMapData.getCoordZ() - 200); foreach (KeyValuePair <string, ushort[][]> featureMap in layer.Value) { featureMapData.setHeight(featureMap.Value.GetLength(0)); featureMapData.setWidth(featureMap.Value.GetLength(0)); featureMapData.setName(featureMap.Key); featureMapData.setCoordY(featureMapData.getCoordY() + featureMapData.getWidth() + featureMapData.getWidth()); if (featureMapData.getName().Contains("fc") || featureMapData.getName().Contains("dense") || featureMapData.getName().Contains("pred")) { index = 0; divisors = closestDivisors(featureMap.Value[0].Length); var name = featureMapData.getName(); var featureMaps = featureMap.Value[0]; featureMapData.setCoordX(0); featureMapData.setCoordY(0); for (int i = 0; i < divisors.Item1; i++) { featureMapData.setCoordX(featureMapData.getCoordX() + 60); featureMapData.setCoordY(0); for (int j = 0; j < divisors.Item2; j++) { go = GameObject.Instantiate(featurePredictionsTemplate); go.name = featureMapData.getName(); CubeCreator cube = go.AddComponent <CubeCreator>(); featureMapData.setCoordY(featureMapData.getCoordY() + 60); if (featureMapData.getName().Contains("pred")) { cube.createCube(featureMapData, name + "_" + labels[index], featureMaps[index]); structHelper.LastLayersPredictions.Add(name + "_" + index.ToString(), cube); } else { cube.createCube(featureMapData, name + "_" + index.ToString(), featureMaps[index]); structHelper.LastLayersPredictions.Add(name + "_" + index.ToString(), cube); } index++; } } } else { go = GameObject.Instantiate(fetureTemplate); go.name = featureMapData.getName(); PlaneCreator plane = go.GetComponent <PlaneCreator>(); plane.createPlane(featureMapData, featureMap.Value); structHelper.convLayers.Add(featureMap.Key, plane); } counter++; if (counter == divisors.Item2) { featureMapData.setCoordY(0); featureMapData.setCoordX(featureMapData.getCoordX() + featureMapData.getHeight() + featureMapData.getHeight()); counter = 0; } } } var parent = GameObject.Find("BackCamera").GetComponent <Camera>().transform.position = new Vector3(800, 800, featureMapData.getCoordZ() - 70); return(structHelper); }
public void PlaneObject(FeatureMapData featureMapData, ushort[][] featureMap) { scale = featureMapData.getCoordScale(); gameObject.name = featureMapData.getName(); height = featureMapData.getHeight(); width = featureMapData.getWidth(); textureFeature = new Texture2D(featureMapData.getHeight(), featureMapData.getWidth()); Color[] pixels = new Color[featureMapData.getHeight() * featureMapData.getWidth()]; int index = 0; int max = -10000; int min = 10000; for (int k = 0; k < height; k++) { for (int l = 0; l < width; l++) { if (featureMap[k][l] > max) { max = featureMap[k][l]; } if (featureMap[k][l] < min) { min = featureMap[k][l]; } } } for (int i = 0; i < featureMap.GetLength(0); i++) { for (int j = 0; j < featureMap.GetLength(0); j++) { float normalizedValue = ((float)featureMap[i][j] - min) / (max - min); pixels[index] = new Color(normalizedValue, normalizedValue, normalizedValue, 1); index++; } } textureFeature.SetPixels(pixels); textureFeature.Apply(); gameObject.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", textureFeature); /// you will not need this in update gameObject.transform.position = new Vector3(featureMapData.getCoordX(), featureMapData.getCoordY(), featureMapData.getCoordZ()); gameObject.transform.Rotate(-90, 180, 0, Space.Self); gameObject.transform.localScale = new Vector3(width / 10f, 1.0f, height / 10f); }