void Execute(Vector2 _p) { if (!ImpPlugin.Imp_Execute(_p.x, _p.y)) { Debug.LogError("Could not execute imp : " + _p.ToString()); return; } ImpPlugin.Imp_CopyQ(q_handle.AddrOfPinnedObject()); if (templateMesh) { Vector3[] vertices = templateMesh.mesh.vertices; for (long v = 0; v < vertices.Length; ++v) { long i = v * 3; vertices[v] = new Vector3(q_data[i + 0] * ModelScaleFactor, q_data[i + 1] * ModelScaleFactor, q_data[i + 2] * ModelScaleFactor); } templateMesh.mesh.vertices = vertices; templateMesh.mesh.RecalculateBounds(); templateMesh.mesh.RecalculateNormals(); } }
void Execute(Vector2 _p) { if (!ImpPlugin.Imp_Execute(_p.x, _p.y)) { Debug.LogError("Could not execute imp : " + _p.ToString()); return; } ImpPlugin.Imp_BackProjectImageExecute(_p.x, _p.y); //ImpPlugin.Imp_CopyQ(q_handle.AddrOfPinnedObject()); }
private IEnumerator CallPluginAtEndOfFrames() { while (true) { // Wait until all frame rendering is done yield return(new WaitForEndOfFrame()); // Issue a plugin event with arbitrary integer identifier. // The plugin can distinguish between different // things it needs to do based on this ID. // For our simple plugin, it does not matter which ID we pass here. GL.IssuePluginEvent(ImpPlugin.GetRenderEventFunc(), 1); } }
bool BuildILamp(MeshFilter[] meshes, string filename2d, string filenameNd) { if (ImpType == ImpTypeEnum.ILamp) { ImpPlugin.Imp_Create_ILamp(); ImpPlugin.Imp_ILamp_Setup(ILampParams.KdTreeCount, ILampParams.NumNeighbours, ILampParams.KnnSearchChecks); } else { ImpPlugin.Imp_Create_Rbp(); ImpPlugin.Imp_Rbf_Setup((ushort)(RbfParams.Function), RbfParams.Constant); } System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; if (RunLamp) { ImpPlugin.BuildNdFile(meshes, filenameNd, 1.0f / ModelScaleFactor); if (!ImpPlugin.Imp_ExecuteLamp(filenameNd, filename2d)) { Debug.LogError("Could not run lamp for " + filename2d + ' ' + filenameNd); enabled = false; return(false); } } if (!ImpPlugin.Imp_LoadInputFiles(filename2d, filenameNd)) { Debug.LogError("Could not load input files: " + filename2d + ' ' + FileNameNd); enabled = false; return(false); } if (!ImpPlugin.Imp_Build()) { Debug.LogError("Could not build imp"); enabled = false; return(false); } return(true); }
private void CreateTextureAndPassToPlugin() { // Create a texture Texture2D tex = new Texture2D(256, 256, TextureFormat.ARGB32, false); //Texture2D tex = new Texture2D(256, 256, TextureFormat.RGB24, false); // Set point filtering just so we can see the pixels clearly tex.filterMode = FilterMode.Point; // Call Apply() so it's actually uploaded to the GPU tex.Apply(); // Set texture onto our material material.mainTexture = tex; // Pass texture pointer to the plugin int channels = (tex.format == TextureFormat.ARGB32) ? 4 : 3; ImpPlugin.SetTextureFromUnity(tex.GetNativeTexturePtr(), tex.width, tex.height, channels); }
void Execute(Vector2 _p) { if (!ImpPlugin.Imp_Execute(_p.x, _p.y)) { Debug.LogError("Could not execute imp : " + _p.ToString()); return; } ImpPlugin.Imp_CopyQ(q_handle.AddrOfPinnedObject()); // // Computing laplace meshes blend // int currentImp = ImpPlugin.Imp_GetCurrent(); { ImpPlugin.Imp_SetCurrent(levelIndex + 1); // +1 is because the level 0 is for baseMeshes if (!ImpPlugin.Imp_Execute(_p.x, _p.y)) { Debug.LogError("Could not execute imp : " + _p.ToString()); return; } ImpPlugin.Imp_CopyQ(q_handle_laplace.AddrOfPinnedObject()); } ImpPlugin.Imp_SetCurrent(currentImp); Vector3[] vertTarget = laplaceMeshes[levelIndex].MeshList[meshTargetIndex].mesh.vertices; Vector3[] vertResult = templateMesh.mesh.vertices; for (long v = 0; v < templateMesh.mesh.vertexCount; ++v) { Vector3 vertBlend = q_data[v] * ModelScaleFactor; Vector3 vertBlendLaplace = q_data_laplace[v] * ModelScaleFactor; vertResult[v] = vertBlend - vertBlendLaplace + vertTarget[v]; } templateMesh.mesh.vertices = vertResult; templateMesh.mesh.RecalculateBounds(); templateMesh.mesh.RecalculateNormals(); }
void Update() { if (Input.GetKeyDown(KeyCode.LeftControl)) { controlKeyPressed = true; if (impUI) { impUI.MouseTarget(controlKeyPressed); } } else if (Input.GetKeyUp(KeyCode.LeftControl)) { controlKeyPressed = false; if (impUI) { impUI.MouseTarget(controlKeyPressed); } } if (controlKeyPressed) { p = new Vector2( ImpPlugin.LinearInterpolation(Input.mousePosition.x, 0, Screen.width, MinCoords.x, MaxCoords.x), ImpPlugin.LinearInterpolation(Input.mousePosition.y, 0, Screen.height, MinCoords.y, MaxCoords.y)); if (p.x > ImpPlugin.Imp_MinX() && p.x < ImpPlugin.Imp_MaxX() && p.y > ImpPlugin.Imp_MinY() && p.y < ImpPlugin.Imp_MaxY()) { Execute(p); } } if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)) { Execute(p); } }
public void Setup(List <Vector2> Vertices2d, Vector2 MinCoords, Vector2 MaxCoords) { if (Vertices2d.Count < 1) { return; } thumbnails = new UnityEngine.UI.Image[sprites.Length]; for (int i = 0; i < thumbnails.Length; ++i) { thumbnails[i] = Instantiate <UnityEngine.UI.Image>(thumbnailTemplate, this.transform); thumbnails[i].name = sprites[i].name; thumbnails[i].sprite = sprites[i]; Rect rect = thumbnails[i].rectTransform.rect; Vector2 v = Vertices2d[i]; Vector2 pos = new Vector2( ImpPlugin.LinearInterpolation(v.x, MinCoords.x, MaxCoords.x, rect.width / 2.0f, Screen.width - rect.width), ImpPlugin.LinearInterpolation(v.y, MinCoords.y, MaxCoords.y, rect.height / 2.0f, Screen.height - rect.height)); thumbnails[i].rectTransform.anchoredPosition = pos; } }
void StartImp() { if (ImpType == ImpTypeEnum.ILamp) { ImpPlugin.Imp_Create_ILamp(); ImpPlugin.Imp_ILamp_Setup(ILampParams.KdTreeCount, ILampParams.NumNeighbours, ILampParams.KnnSearchChecks); } else { ImpPlugin.Imp_Create_Rbp(); ImpPlugin.Imp_Rbf_Setup((ushort)(RbfParams.Function), RbfParams.Constant); } System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; if (!ImpPlugin.Imp_ExecutePcaImages(FileNameImageList, FileNameNd)) { Debug.LogError("Could not execute pca for images: " + FileNameImageList); enabled = false; return; } if (!ImpPlugin.Imp_ExecuteLamp(FileNameNd, FileName2d)) { Debug.LogError("Could not run lamp for " + FileNameNd + ' ' + FileName2d); enabled = false; return; } if (!ImpPlugin.Imp_LoadInputFiles(FileName2d, FileNameNd)) { Debug.LogError("Could not load input files: " + FileName2d + ' ' + FileNameNd); enabled = false; return; } if (!ImpPlugin.Imp_Build()) { Debug.LogError("Could not build imp"); enabled = false; return; } using (System.IO.TextReader reader = System.IO.File.OpenText(FileName2d)) { string line; while ((line = reader.ReadLine()) != null) { string[] v_str = line.Split(); float x, y = 0; if (float.TryParse(v_str[0], out x) && float.TryParse(v_str[1], out y)) { vertices2d.Add(new Vector2(x, y)); } } reader.Close(); } if (ImpPlugin.Imp_Execute(vertices2d[0].x, vertices2d[0].y)) { if (q_data == null) // q_data.Count must be (3 * vertices.Length) { q_data = new float[ImpPlugin.Imp_QRows() * ImpPlugin.Imp_QCols()]; q_handle = GCHandle.Alloc(q_data, GCHandleType.Pinned); } } else { Debug.LogError("Could not run imp"); enabled = false; return; } impUI = (ImpUI)FindObjectOfType(typeof(ImpUI)); if (impUI) { impUI.Setup(vertices2d, MinCoords, MaxCoords); } }
void Start() { if (templateMesh == null) { Debug.LogError("Template Mesh is null. Did you forget to fill inspector fields?"); enabled = false; return; } // // Check if the number of meshes and vertices matches // foreach (var m in baseMeshes) { if (m == null) { Debug.LogError("Mesh is null. Did you forget to fill inspector fields?"); enabled = false; return; } } foreach (var ml in laplaceMeshes) { if (baseMeshes.Length != ml.MeshList.Length) { Debug.LogError("The number of meshes does not match: " + baseMeshes.Length + " != " + ml.MeshList.Length); enabled = false; return; } if (ml.MeshList[0] == null) { Debug.LogError("Mesh is null. Did you forget to fill inspector fields?"); enabled = false; return; } var vertCount = ml.MeshList[0].mesh.vertexCount; for (int i = 1; i < ml.MeshList.Length; ++i) { if (ml.MeshList[i] == null) { Debug.LogError("Mesh null. Did you forget to fill inspector fields?"); enabled = false; return; } if (vertCount != ml.MeshList[i].mesh.vertexCount) { Debug.LogError("The number of vertices does not match: " + ml.MeshList[i].name); enabled = false; return; } } } //Debug.Log("Building ILamp for base meshes: " + FileNameNd); if (!BuildILamp(baseMeshes, FileName2d, FileNameNd)) { enabled = false; return; } foreach (var ml in laplaceMeshes) { //Debug.Log("Building ILamp for laplace meshes: " + ml.FileName); if (!BuildILamp(ml.MeshList, FileName2d, ml.FileName)) { enabled = false; return; } } ImpPlugin.Imp_SetCurrent(0); using (System.IO.TextReader reader = System.IO.File.OpenText(FileName2d)) { string line; while ((line = reader.ReadLine()) != null) { string[] v_str = line.Split(); float x, y = 0; if (float.TryParse(v_str[0], out x) && float.TryParse(v_str[1], out y)) { vertices2d.Add(new Vector2(x, y)); } } reader.Close(); } if (ImpPlugin.Imp_Execute(vertices2d[0].x, vertices2d[0].y)) { if (q_data == null) // q_data.Count must be (3 * vertices.Length) { //q_data = new float[ImpPlugin.Imp_QRows() * ImpPlugin.Imp_QCols()]; q_data = new Vector3[templateMesh.mesh.vertexCount]; q_handle = GCHandle.Alloc(q_data, GCHandleType.Pinned); } if (q_data_laplace == null) { q_data_laplace = new Vector3[templateMesh.mesh.vertexCount]; q_handle_laplace = GCHandle.Alloc(q_data_laplace, GCHandleType.Pinned); } } else { Debug.LogError("Could not run imp"); enabled = false; return; } impUI = (ImpUI)FindObjectOfType(typeof(ImpUI)); if (impUI) { impUI.Setup(vertices2d, MinCoords, MaxCoords); } }
void Update() { // // Fixing possible OutOfRange // levelIndex = levelIndex % laplaceMeshes.Count; meshTargetIndex = meshTargetIndex % laplaceMeshes[levelIndex].MeshList.Length; if (Input.GetKeyDown(KeyCode.LeftControl)) { controlKeyPressed = true; if (impUI) { impUI.MouseTarget(controlKeyPressed); } } else if (Input.GetKeyUp(KeyCode.LeftControl)) { controlKeyPressed = false; if (impUI) { impUI.MouseTarget(controlKeyPressed); } } if (controlKeyPressed) { p = new Vector2( ImpPlugin.LinearInterpolation(Input.mousePosition.x, 0, Screen.width, MinCoords.x, MaxCoords.x), ImpPlugin.LinearInterpolation(Input.mousePosition.y, 0, Screen.height, MinCoords.y, MaxCoords.y)); if (p.x > ImpPlugin.Imp_MinX() && p.x < ImpPlugin.Imp_MaxX() && p.y > ImpPlugin.Imp_MinY() && p.y < ImpPlugin.Imp_MaxY()) { Execute(p); } } else { MeshRenderer target = templateMesh.GetComponent <MeshRenderer>(); int v = 0; for (var key = KeyCode.Alpha1; key <= KeyCode.Alpha9; ++key) { if (Input.GetKeyDown(key)) { p = vertices2d[v % vertices2d.Count]; MeshRenderer source = baseMeshes[v % vertices2d.Count].GetComponent <MeshRenderer>(); if (target && source) { target.sharedMaterial = source.sharedMaterial; } meshTargetIndex = v % laplaceMeshes.Count; Execute(p); } ++v; } if (Input.GetKeyDown(KeyCode.Alpha0)) { target.sharedMaterial = wireframe; } } // +1 is because of laplaceMeshes + baseMeshes for (var key = KeyCode.Keypad0; key <= KeyCode.Keypad0 + laplaceMeshes.Count + 1; ++key) { if (Input.GetKeyDown(key)) { ImpPlugin.Imp_SetCurrent(key - KeyCode.Keypad0); } } switch (levelIndex) { default: case 0: laplaceIterations = 0; break; case 1: laplaceIterations = 2; break; case 2: laplaceIterations = 5; break; case 3: laplaceIterations = 10; break; case 4: laplaceIterations = 25; break; case 5: laplaceIterations = 50; break; case 6: laplaceIterations = 100; break; } if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)) { Execute(p); } //Execute(p); }
void Update() { if (Input.GetKeyDown(KeyCode.LeftControl)) { controlKeyPressed = true; if (impUI) { impUI.MouseTarget(controlKeyPressed); } } else if (Input.GetKeyUp(KeyCode.LeftControl)) { controlKeyPressed = false; if (impUI) { impUI.MouseTarget(controlKeyPressed); } } if (controlKeyPressed) { p = new Vector2( ImpPlugin.LinearInterpolation(Input.mousePosition.x, 0, Screen.width, MinCoords.x, MaxCoords.x), ImpPlugin.LinearInterpolation(Input.mousePosition.y, 0, Screen.height, MinCoords.y, MaxCoords.y)); if (p.x > ImpPlugin.Imp_MinX() && p.x < ImpPlugin.Imp_MaxX() && p.y > ImpPlugin.Imp_MinY() && p.y < ImpPlugin.Imp_MaxY()) { Execute(p); } } else { MeshRenderer target = templateMesh.GetComponent <MeshRenderer>(); int v = 0; for (var key = KeyCode.Alpha1; key <= KeyCode.Alpha9; ++key) { if (Input.GetKeyDown(key)) { p = vertices2d[v % vertices2d.Count]; MeshRenderer source = baseMeshes[v % vertices2d.Count].GetComponent <MeshRenderer>(); if (target && source) { target.sharedMaterial = source.sharedMaterial; } } ++v; } if (Input.GetKeyDown(KeyCode.Alpha0)) { target.sharedMaterial = wireframe; } } if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)) { Execute(p); } }