private static void RenderPresetsToFiles() { using (GameWindow gameWindow = OpenTkSharedResources.CreateGameWindowContext(width, height)) { // Resource creation. screenTriangle = ScreenDrawing.CreateScreenTriangle(); shader = OpenTkSharedResources.shaders["NudSphere"]; // Skip thumbnail generation if the shader didn't compile. if (!shader.LinkStatusIsOk) { return; } // HACK: This isn't a very clean way to pass resources around. NudMatSphereDrawing.LoadMaterialSphereTextures(); Dictionary <NudEnums.DummyTexture, Texture> dummyTextures = RenderTools.CreateNudDummyTextures(); CreateNudSphereShader(); foreach (string file in Directory.EnumerateFiles(MainForm.executableDir + "\\materials", "*.nmt", SearchOption.AllDirectories)) { Nud.Material material = NudMaterialEditor.ReadMaterialListFromPreset(file)[0]; string presetName = Path.GetFileNameWithoutExtension(file); RenderMaterialPresetToFile(presetName, material, dummyTextures); } } }
Mesh3D MergeMeshes(List <Mesh3D> meshes) { if (meshes.Count == 0) { return(null); } Mesh3D fullMesh = new Mesh3D(); List <Point3D> positions = new List <Point3D>(); List <int> triangleIndices = new List <int>(); int offset = 0; foreach (Mesh3D m in meshes) { positions.AddRange(m.Vertices); foreach (int[] face in m.Faces) { triangleIndices.Add(face[0] + offset); triangleIndices.Add(face[1] + offset); triangleIndices.Add(face[2] + offset); } offset = positions.Count; } return(new Mesh3D(positions, triangleIndices)); }
public static List <List <Face> > Cells(this Mesh3D mesh3d) { Dictionary <int, List <Face> > result = new Dictionary <int, List <Face> >(); for (int i = 0; i < mesh3d.CellRelation.Count; i++) { int key = mesh3d.CellRelation[i].FromCell; if (!result.ContainsKey(key)) { result[key] = new List <Face>(); } result[key].Add(mesh3d.Faces[i]); key = mesh3d.CellRelation[i].ToCell; if (!result.ContainsKey(key)) { result[key] = new List <Face>(); } result[key].Add(mesh3d.Faces[i]); } if (result.ContainsKey(-1)) { result.Remove(-1); } return(result.Select(x => x.Value).ToList()); }
public BntxTextureList() { InitializeComponent(); int count = 0; foreach (BNTX bntx in Runtime.BNTXList) { foreach (BRTI tex in bntx.textures) { Bitmap color = new Bitmap(BfresMaterialEditor.textureRGBA(tex.texture, tex.display)); il.Images.Add(color); texturesCol.Add(color); color.Dispose(); string[] row1 = { tex.Height.ToString(), tex.Width.ToString() }; listView1.Items.Add(tex.Text, count++).SubItems.AddRange(row1); } } il.ColorDepth = ColorDepth.Depth32Bit; il.ImageSize = new Size(30, 30); listView1.SmallImageList = il; Rendering.OpenTKSharedResources.InitializeSharedResources(); if (Rendering.OpenTKSharedResources.SetupStatus == Rendering.OpenTKSharedResources.SharedResourceStatus.Initialized) { screenTriangle = Rendering.ScreenDrawing.CreateScreenTriangle(); } }
private void initMesh3d(string file, string layout) { string s = Utils.GetRootPath() + "\\Content\\export\\" + file; if (File.Exists(s) == false) { return; } FieldInfo myf = typeof(MeshInputElements10).GetField(layout); InputElement[] ie = (InputElement[])myf.GetValue(null); Stream stream = File.Open(s, FileMode.Open); BinaryFormatter bFormatter = new BinaryFormatter(); object[] context = new object[] { Game.Device, ie }; bFormatter.Context = new StreamingContext(StreamingContextStates.All, context); mesh3d = (Mesh3D)bFormatter.Deserialize(stream); stream.Close(); mesh3d.inputElements = ie; mesh3d.meshFileName = file; mesh3d.ComputeBoundingBox(); }
public static Entity3D Quad(int w, int h) { Entity3D r = new Entity3D(); Mesh3D mesh = new Mesh3D(6, 4); Vector3 v1 = new Vector3(-w, -h, 0); Vector3 v2 = new Vector3(w, -h, 0); Vector3 v3 = new Vector3(w, h, 0); Vector3 v4 = new Vector3(-w, h, 0); Vector3 z = new Vector3(0, 0, 0); mesh.SetVertex(0, v1, z, z, z, new Vector2(0, 0)); mesh.SetVertex(1, v2, z, z, z, new Vector2(1, 0)); mesh.SetVertex(2, v3, z, z, z, new Vector2(1, 1)); mesh.SetVertex(3, v4, z, z, z, new Vector2(0, 1)); mesh.SetTri(0, 0, 1, 2); mesh.SetTri(1, 2, 3, 0); /* * mesh.SetIndex(0, 0); * mesh.SetIndex(1, 1); * mesh.SetIndex(2, 2); * mesh.SetIndex(3, 2); * mesh.SetIndex(4, 3); * mesh.SetIndex(5, 0); */ mesh.Final( ); r.AddMesh(mesh); return(r); }
/// <summary> /// Create a MeshGeometryVisual3D from an existing HalfEdgeMesh with specified Colors. /// </summary> /// <param name="mesh">The existing HalfEdgeMesh.</param> /// <param name="foreground">The Color for the Triangles of the Mesh.</param> /// <param name="backGround">The Background Color for the Triangles of the Mesh.</param> /// <returns>MeshVisual3D of the HalfEdgeMesh with the specified Materials.</returns> private static MeshVisual3D CreateVisual3DWithoutNormals(this HalfEdgeMesh mesh, Material frontMaterial, Material backMaterial) { if (frontMaterial == default(Material)) { frontMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultForegroundColor)); } if (backMaterial == default(Material)) { backMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultBackgroundColor)); } var mesh3D = new Mesh3D(mesh.Vertices.Select(p => new Point3D(p.X, p.Y, p.Z)), mesh.Triangles.Where(t => t.HalfEdge != null).SelectMany(t => t.VertexIndizes)); var meshVisual = new MeshVisual3D() { Mesh = mesh3D, FaceMaterial = frontMaterial, FaceBackMaterial = backMaterial, EdgeDiameter = 0, VertexRadius = 0 }; return(meshVisual); }
private void RenderDrawables() { var points = new List <Point3D>(); var lines = new List <Point3D>(); var meshes = new List <Mesh3D>(); var xAxes = new List <Point3D>(); var yAxes = new List <Point3D>(); var zAxes = new List <Point3D>(); foreach (KeyValuePair <Guid, RenderDescription> kvp in dynSettings.Controller.RenderDescriptions) { var rd = kvp.Value as RenderDescription; if (rd == null) { continue; } points.AddRange(rd.points.ConvertAll(x => (Point3D)x)); lines.AddRange(rd.lines.ConvertAll(x => (Point3D)x)); meshes.AddRange(rd.meshes.ConvertAll(x => (Mesh3D)x)); xAxes.AddRange(rd.xAxisPoints.ConvertAll(x => (Point3D)x)); yAxes.AddRange(rd.yAxisPoints.ConvertAll(x => (Point3D)x)); zAxes.AddRange(rd.zAxisPoints.ConvertAll(x => (Point3D)x)); } HelixPoints = points; HelixLines = lines; HelixMesh = MergeMeshes(meshes); HelixXAxes = xAxes; HelixYAxes = yAxes; HelixZAxes = zAxes; }
public BNTXEditor() { InitializeComponent(); FilePath = ""; Text = "New Binary Texture"; fw = new FileSystemWatcher(); fw.Path = Path.GetTempPath(); fw.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastAccess | NotifyFilters.LastWrite; fw.EnableRaisingEvents = false; fw.Changed += new FileSystemEventHandler(OnChanged); fw.Filter = ""; MenuItem export = new MenuItem("Export"); export.Click += exportTextureToolStripMenuItem_Click; TextureMenu.MenuItems.Add(export); MenuItem replace = new MenuItem("Replace"); replace.Click += replaceTextureToolStripMenuItem_Click; TextureMenu.MenuItems.Add(replace); OpenTKSharedResources.InitializeSharedResources(); if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Initialized) { screenTriangle = ScreenDrawing.CreateScreenTriangle(); } }
public virtual void Render(Mesh3D m) { foreach (RenderLayer rl in Layers) { rl.Render(m, m.Viz); } }
public MeshGeometry3D CreateMesh() { var mesh = new Mesh3D(Vertices, UVs, Triangles).ToMeshGeometry3D(true, 0, Triangles.ToList()); mesh.CalculateNormals(); return(mesh); }
public override void Render(Mesh3D m, Visualizer v) { m.Material.Bind(); if (Light3D.Active != null) { Light3D.Active.ShadowFB.Cube.Bind(2); } if (FXG.FXOverride != null) { FXG.FXOverride.Bind(); } else { fx.Bind(); } v.SetMesh(m); v.Bind(); v.Visualize(); v.Release(); if (FXG.FXOverride != null) { FXG.FXOverride.Release(); } else { fx.Release(); } if (Light3D.Active != null) { Light3D.Active.ShadowFB.Cube.Release(2); } m.Material.Release(); }
/// affecte ces changements a notre maillage 3D public void applyTo(Mesh3D pMesh) { for (int i = 0; i < pMesh.mPoints.Count; ++i) { pMesh.mPoints[i] = mNodes[i].pos; } }
public Mesh3DLinkIterator(Mesh3D pMesh) { alreadySeen = new List <Edge>(); mMesh = pMesh; currentFaceIndex = 0; currentFaceLinkIndex02 = 0; }
public override ModelVisual3D To3DViz() { MeshBuilder builder = new MeshBuilder(true, true); for (int i = 0; i < connectivity.Count; i++) { List <int> l = connectivity[i]; //builder.AddPolygon(l.Select(idx => pnts[idx].ToPoint3D()).ToList()); if (l.Count == 3) { builder.AddTriangle(pnts[l[0]].ToPoint3D(), pnts[l[1]].ToPoint3D(), pnts[l[2]].ToPoint3D()); } else if (l.Count == 4) { builder.AddQuad(pnts[l[0]].ToPoint3D(), pnts[l[1]].ToPoint3D(), pnts[l[2]].ToPoint3D(), pnts[l[3]].ToPoint3D()); } } Mesh3D m = new Mesh3D(builder.Positions, builder.TriangleIndices); MeshVisual3D mesh = new MeshVisual3D() { Mesh = m }; return(mesh); }
public Vivid.Pick.PickResult CamPick(int x, int y) { Pick.PickResult res = new Pick.PickResult(); Pick.Ray mr = Pick.Picker.CamRay(SceneGraph3D.CurScene.Cams[0], x, y); float cd = 0; bool firstHit = true; Mesh3D hitMesh = null; float cu = 0, cv = 0; foreach (var msh in Meshes) { for (int i = 0; i < msh.TriData.Length; i++) { var td = msh.TriData[i]; var r0 = msh.VertexData[td.V0].Pos; var r1 = msh.VertexData[td.V1].Pos; var r2 = msh.VertexData[td.v2].Pos; r0 = Vector3.TransformPosition(r0, World); r1 = Vector3.TransformPosition(r1, World); r2 = Vector3.TransformPosition(r2, World); Vector3?pr = Pick.Picker.GetTimeAndUvCoord(mr.pos, mr.dir, r0, r1, r2); if (pr == null) { } else { Vector3 cr = (Vector3)pr; if (cr.X < cd || firstHit) { firstHit = false; cd = cr.X; hitMesh = msh; cu = cr.Y; cv = cr.Z; } } } } if (firstHit) { return(null); } res.Dist = cd; res.Node = this; res.Pos = Pick.Picker.GetTrilinearCoordinateOfTheHit(cd, mr.pos, mr.dir); res.Ray = mr; res.UV = new Vector3(cu, cv, 0); res.Mesh = hitMesh; return(res); }
public Model() { mesh3d = null; canHaveRefs = true; staticMesh = true; mass = 10; }
private void DrawGradient(Vector3 topColor, Vector3 bottomColor) { if (screenTriangle == null) { screenTriangle = ScreenDrawing.CreateScreenTriangle(); } ScreenDrawing.DrawQuadGradient(topColor, bottomColor, screenTriangle); }
public static Mesh ToMesh(this Mesh3D mesh3d) { return(new Mesh() { Vertices = mesh3d.Vertices.ToList(), Faces = mesh3d.Faces.ToList(), }); }
public override void Render(Mesh3D m, Visualizer v) { FX.Bind(); v.SetMesh(m); v.Bind(); v.Visualize(); v.Release(); FX.Release(); }
MeshVisual3D MakeMeshVisual3D(Mesh3D mesh) { MeshVisual3D vismesh = new MeshVisual3D { Content = new GeometryModel3D { Geometry = mesh.ToMeshGeometry3D(), Material = Materials.White } }; return(vismesh); }
private void glControl1_Load(object sender, System.EventArgs e) { OpenTKSharedResources.InitializeSharedResources(); if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Initialized) { nut.RefreshGlTexturesByHashId(); pngExportFramebuffer = new Framebuffer(FramebufferTarget.Framebuffer, glControl1.Width, glControl1.Height); screenTriangle = ScreenDrawing.CreateScreenTriangle(); } }
private Mesh3D Cube() { Mesh3D m = new Mesh3D(); Vertex3D v0 = m.AddVertex(new Vertex3D(-1, -1, 1)); Vertex3D v1 = m.AddVertex(new Vertex3D(1, -1, 1)); Vertex3D v2 = m.AddVertex(new Vertex3D(1, 1, 1)); Vertex3D v3 = m.AddVertex(new Vertex3D(-1, 1, 1)); Vertex3D v4 = m.AddVertex(new Vertex3D(-1, -1, -1)); Vertex3D v5 = m.AddVertex(new Vertex3D(1, -1, -1)); Vertex3D v6 = m.AddVertex(new Vertex3D(1, 1, -1)); Vertex3D v7 = m.AddVertex(new Vertex3D(-1, 1, -1)); List<Vertex3D> list = new List<Vertex3D>(); list.Add(v0); list.Add(v1); list.Add(v2); list.Add(v3); m.CreatePolygon(list); list.Clear(); list.Add(v7); list.Add(v6); list.Add(v5); list.Add(v4); m.CreatePolygon(list); list.Clear(); list.Add(v1); list.Add(v0); list.Add(v4); list.Add(v5); m.CreatePolygon(list); list.Clear(); list.Add(v2); list.Add(v1); list.Add(v5); list.Add(v6); m.CreatePolygon(list); list.Clear(); list.Add(v3); list.Add(v2); list.Add(v6); list.Add(v7); m.CreatePolygon(list); list.Clear(); list.Add(v0); list.Add(v3); list.Add(v7); list.Add(v4); m.CreatePolygon(list); return m; }
public override void Render(Mesh3D m, Visualizer v) { // m.Mat.Bind(); fx.Bind( ); v.SetMesh(m); v.Bind( ); v.Visualize( ); v.Release( ); fx.Release( ); //m.Mat.Release(); }
private void SetUpRendering() { // Make sure the shaders and textures are ready for rendering. OpenTKSharedResources.InitializeSharedResources(); if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Initialized) { currentNut.RefreshGlTexturesByHashId(); pngExportFramebuffer = new Framebuffer(FramebufferTarget.Framebuffer, glControl1.Width, glControl1.Height); screenTriangle = ScreenDrawing.CreateScreenTriangle(); } }
private void ComputeBoundingBox(Mesh3D mesh, bool isInitial) { var minmax = mesh.MinMaxWorldCoordinates; Min = new CartesianCoordinate(minmax[0], minmax[2], minmax[4]); Max = new CartesianCoordinate(minmax[1], minmax[3], minmax[5]); if (!isInitial) { FireMinMaxChanged(); } }
private static Framebuffer DrawTextureToNewFbo(Texture2D texture, int width, int height, bool r, bool g, bool b, bool a) { Mesh3D screenTriangle = ScreenDrawing.CreateScreenTriangle(); Framebuffer framebuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height, PixelInternalFormat.Rgba); framebuffer.Bind(); // Draw the specified color channels. GL.Viewport(0, 0, width, height); ScreenDrawing.DrawTexturedQuad(texture, 1, 1, screenTriangle, r, g, b, a); return(framebuffer); }
/// <summary> /// Used to render the verteces. The points form the camera... /// </summary> /// <param name="Mesh"></param> public static void GetVerts(ref Mesh3D Mesh) { if (Program.RenderPoints) { lock (Lck) { if (PointCount != 0) { Mesh.SetVertices(Points, PointCount, false, true); } } } }
internal static void Init() { FreeLineIdx = FreeDepthTestedLineIdx = 0; LineVerts = new Vertex3[128]; DepthTestedLineVerts = new Vertex3[128]; DebugDrawShader = new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "content/shaders/debug_draw.vert"), new ShaderStage(ShaderType.FragmentShader, "content/shaders/debug_draw.frag")); DebugMesh = new Mesh3D(BufferUsage.DynamicDraw); DebugMesh.PrimitiveType = PrimitiveType.Lines; DebugMesh.VAO.SetLabel(OpenGL.ObjectIdentifier.VertexArray, "DebugDraw vertex buffer"); debug_draw.Init((Start, End, DepthEnabled) => AppendLine(Start, End, DepthEnabled)); }
public void SetVertices(Vertex3[] Verts) { this.Vertices = Verts; if (Mesh == null) { Mesh = new Mesh3D(Vertices); } else { Mesh.SetVertices(Vertices); } }
//Main flow of the full 3D scanning problem //This is one way of breaking the problem down. They may be other (better) ways static int Main(string[] args) { CameraModel model = new CameraModel(/*Loaded from device dependent configuration.*/); List <KeyValuePair <Image2D, CameraOrientation> > imageStream = FetchImageStream(); List <Point3D> pointCloud = ImageStreamTo3DPointCloud(imageStream, model); //Optional part Mesh3D mesh = PointCloudTo3DMesh(pointCloud); return(0); }
public void TestMethod1() { Mesh3D m = new Mesh3D(); Vertex3D v1 = m.AddVertex(new Vertex3D(0, 4, 0)); Vertex3D v2 = m.AddVertex(new Vertex3D(2, 4, 0)); Vertex3D v3 = m.AddVertex(new Vertex3D(2, 2, 0)); Vertex3D v4 = m.AddVertex(new Vertex3D(1, 1, 0)); List<Vertex3D> list = new List<Vertex3D>(); list.Add(v2); list.Add(v1); list.Add(v3); m.CreatePolygon(list); List<HEPolygon> p = m.Polys; Assert.AreEqual(p.Count, 1); HEPolygon poly = p[0]; Assert.AreEqual(poly.VertexCount, 3); Assert.IsTrue(poly.OuterComponent == m.Vertices[1].IncidentEdge); Assert.IsTrue(poly.OuterComponent.Next.Origin.Equals(v1)); Assert.IsTrue(poly.OuterComponent.Next.Next.Origin.Equals(v3)); Assert.IsTrue(poly.OuterComponent.Next.Next.Next.Origin.Equals(v2)); Assert.IsTrue(poly.OuterComponent.Prev.Origin.Equals(v3)); list.Clear(); list.Add(v4); list.Add(v3); list.Add(v1); m.CreatePolygon(list); p = m.Polys; poly = p[1]; Assert.AreEqual(p.Count, 2); Assert.IsTrue(poly.OuterComponent == m.Vertices[3].IncidentEdge); Assert.IsTrue(poly.OuterComponent.Next.Origin.Equals(v3)); Assert.IsTrue(poly.OuterComponent.Next.Next.Origin.Equals(v1)); Assert.IsTrue(poly.OuterComponent.Next.Next.Next.Origin.Equals(v4)); }
private void CheckConnectivity(Mesh3D m) { foreach (HalfEdge e in m.HEdges) { Assert.IsTrue(e.Next != null); Assert.IsTrue(e.Prev != null); Assert.IsTrue(e.Normal != null); } }
private Mesh3D CreateQuad() { Mesh3D m = new Mesh3D(); Vertex3D v0 = m.AddVertex(new Vertex3D(-1, -1, 1)); Vertex3D v1 = m.AddVertex(new Vertex3D(1, -1, 1)); Vertex3D v2 = m.AddVertex(new Vertex3D(1, 1, 1)); Vertex3D v3 = m.AddVertex(new Vertex3D(-1, 1, 1)); List<Vertex3D> poly = new List<Vertex3D>(); poly.Add(v0); poly.Add(v1); poly.Add(v2); poly.Add(v3); m.CreatePolygon(poly); return m; }
private Mesh3D CreateSimplePolys() { Mesh3D m = new Mesh3D(); Vertex3D v0 = m.AddVertex(new Vertex3D(0, 0, 0)); Vertex3D v1 = m.AddVertex(new Vertex3D(0, 5, 0)); Vertex3D v2 = m.AddVertex(new Vertex3D(3, 3, 0)); Vertex3D v3 = m.AddVertex(new Vertex3D(5, 0, 0)); Vertex3D v4 = m.AddVertex(new Vertex3D(5, 5, 0)); List<Vertex3D> poly = new List<Vertex3D>(); poly.Add(v0); poly.Add(v2); poly.Add(v1); m.CreatePolygon(poly); poly = new List<Vertex3D>(); poly.Add(v0); poly.Add(v3); poly.Add(v2); m.CreatePolygon(poly); poly = new List<Vertex3D>(); poly.Add(v3); poly.Add(v4); poly.Add(v2); m.CreatePolygon(poly); return m; }
public double __MeanCurvature(Mesh3D m3d, int verticeIndex) { return 0; /* // Initializing all necessary local variables. double meanCurvature = 0.0; double mixedArea = 0; double barycentricArea = 0; Vector3D normalOperator = new Vector3D(); //double[] normalOperator = new double[3]; //for(int i=0; i<3; i++){ // normalOperator[i] = 0.0; //} // no neighbors of this face. if(nbrs == null){ return _infinity; } // If the index point is connected with only one triangle, the index point // is located on the edge of the surface. For example, for the ucf file the // margin of contours might not lap around, therefore the contour might have // boundary. if(nbrs.Count== 1){ return _infinity; } // Orientation Specification: // Look at surface from outside such a way that the pivotal vertex is // located upward. Then I call a triangle in the left is left triangle // and the other triangle in the right is right triangle. // // Up pivotal vertex // * // * * * // * * * // * * * // * * * * * * * * // Left Right // Down // // // 1. Absolute Mean Curvature Computation Algorithm Summary: // Xo - pivot vertex // X1,..,Xj,..,Xn - the first ring neighbor vertices of the vertex o. // n - number of the first ring neighbor vertices of the vertex o. // // Xo // * * * * o // * * * * * * * // * * * * * * * // * * * * O * * * * Xj+1 Xj-1 * Aoj * Boj* Xj+1 // * * * * * * * // * * * * * * * // * * * * * // Xj-1 Xj Xj // // Aoj is angle at the vertex Xj-1 // Boj is angle at the vertex Xj+1 // // // Mean Curvature Normal Operator is calculated by following 2 steps: // First, calculate summation of (cot Aoj + cot Boj)(Xo - Xj) over j // from 1 to n, where Xo is the pivot vertex and Xj's are elements of // first ring neighbors vertices of the pivot vertex. // Second, divide above value by 2*AreaMixed. // // Area Mixed can be calculated by either Barycentric method or // Voronoi method. // 1. Barycentric method calculate AreaMixed by adding one third of each // triangle area. // // 2. Voronoi method is following // if there is obtuse angle at pivot vertex, add half of the triangle // area. // else if there is obtuse angle beside pivot vertex, add one fourth of // triangle area. // else if there is no obtuse angle, add Voronoi area of triangle. // // Finally the Mean Curvature value is computed by taking half of the // magnitude of the Mean Curvature Normal Operator. // 2. Mean Curvature Computation Algorithm Summary: The mean curvature // (non absolute mean curvature) is computed as a summation over the // edges adjacent to a vertex of the angle between the faces adjacent to // the edge multiplied by the edge length, and divided by four times the // area associated with the vertex. // Go over two neighbor faces which are connected to pivotal point // and which share an edge between. for (int i = 0; i < nbrs.Count; i++) { // Obtain vertices which are consist of faces. Point3D vertiesInLeftFace = points[nbrs[i]]; Point3D vertiesInRightFace = points[nbrs[i]]; if (i + 1 == nbrs.Count) { vertiesInRightFace = points[nbrs[0]]; } else{ vertiesInRightFace = points[nbrs[i+1]]; } // This point is also center point. int vertexInCommon1 = -1; // This point is the other end of common edge between two triangles. int vertexInCommon2 = -1; // These two points are not shared between two triangles. int vertexUniqueForLeftFace = -1; int vertexUniqueForRightFace = -1; // Find common vertexes in two adjacent triangles. for(int j=0; j<3; j++){ for(int k=0; k<3; k++){ // If found vertex is pivotal point, save it as vertexInCommon1. // If found vertex is not pivotal point, then this vertex is // the other end of the common edge of two triangle. Save it as // vertexInCommon2. if(vertiesInLeftFace[j] == vertiesInRightFace[k]){ if(vertiesInLeftFace[j] == index){ vertexInCommon1 = vertiesInLeftFace[j]; break; } else{ vertexInCommon2 = vertiesInLeftFace[j]; break; } } else{ // If the vertex is not one of common vertexes, save it as // vertexUniqueForLeftFace. if(k==2){ vertexUniqueForLeftFace = vertiesInLeftFace[j]; } } } } // If two triangles share only center point, the index point is located // on the edge of the surface. For example, for the ucf file the margin // of contours might not lap around, therefore the contour might have // boundary. if(vertexInCommon2 == -1){ return _infinity; } // Now task is finding a vertex which is unique to right triangle. // Go over each vertex in right face and find a vertex which is // not shared with left triangle. then save it as // vertexUniqueForLeftFace. for(int l=0; l<3; l++){ if(vertiesInRightFace[l] == vertexInCommon1 ){ } else if(vertiesInRightFace[l] == vertexInCommon2){ } else{ vertexUniqueForRightFace = vertiesInRightFace[l]; break; } } // Obtain vector represent of vertex locations. double[] pivotalCommonPoint = new double[_dimension]; double[] theOtherCommonPoint = new double[_dimension]; double[] leftUniquePoint = new double[_dimension]; double[] rightUniquePoint = new double[_dimension]; for(int dim=0; dim<_dimension; dim++){ pivotalCommonPoint[dim] = _points.getPoint(vertexInCommon1)[dim]; theOtherCommonPoint[dim] = _points.getPoint(vertexInCommon2)[dim]; leftUniquePoint[dim] = _points.getPoint(vertexUniqueForLeftFace)[dim]; rightUniquePoint[dim] = _points.getPoint(vertexUniqueForRightFace)[dim]; } double[] centerEdgeVector = VectorMathDouble.difference(theOtherCommonPoint, pivotalCommonPoint); if(!_isAbsoluteMeanCurvature){ // The mean curvature (non absolute mean curvature) is computed as a // summation over the edges adjacent to a vertex of the angle between // the faces adjacent to the edge multiplied by the edge length, and // divided by four times the area associated with the vertex. // Reference: // Anupama Jagannathan, "Segmentation and Recognition of 3D Point Clouds // within Graph-theoretic and Thermodynamic Frameworks.", the Department // of Electrical and Computer Engineering, 61-62, 2005. // http://www.ece.neu.edu/faculty/elmiller/laisir/pdfs/jagannathan_phd.pdf // Seungbum Koo, Kunwoo Lee, "Wrap-around operation to make // multi-resolution model of part and assembly.", department of Machanical // and Aerospace Engineering, Seoul National University, 3, 2002, // http://www.ece.tufts.edu/~elmiller/laisr/pdfs/jagannathan_phd.pdf. double[] v1 = VectorMathDouble.difference(leftUniquePoint, pivotalCommonPoint); double[] v2 = VectorMathDouble.difference(rightUniquePoint, pivotalCommonPoint); // Normal vector of the first face. double[] normal1 = VectorMathDouble.cross(v1, centerEdgeVector); // Normal vector of the second face. double[] normal2 = VectorMathDouble.cross(centerEdgeVector, v2); // Dihedral angle between adjacent triangular faces and is computed // as the angle between the corresponding normals. double dihedralAngle = Math.acos(VectorMathDouble.dot(normal1, normal2)/ (VectorMathDouble.magnitude(normal1)*VectorMathDouble.magnitude(normal2))); // Edge is convex edge if the edge type is greater than 0, and edge // is concave edge if the edge type is smaller than 0, and edge is // planner if edge type is 0; double edgeType = VectorMathDouble.dot( VectorMathDouble.cross(normal1, normal2), centerEdgeVector); double edgeVectorEuclideanNorm = VectorMathDouble.magnitude(centerEdgeVector); if(edgeType < 0){ meanCurvature += -1*edgeVectorEuclideanNorm*dihedralAngle; } else if(edgeType > 0){ meanCurvature += edgeVectorEuclideanNorm*dihedralAngle; } else{ meanCurvature += 0; } } // Calculate cot x and cot y where x and y are the angles opposite // common edge in two incident triangles. try { double angleAlpha = VectorMathDouble.vectorAngle(pivotalCommonPoint, leftUniquePoint, theOtherCommonPoint); double angleBetha = VectorMathDouble.vectorAngle(pivotalCommonPoint, rightUniquePoint, theOtherCommonPoint); // angleAlpha, angleTheta, and angleOmega are three angles of left triangles. // Test if any of these angles is obtuse. double angleTheta = VectorMathDouble.vectorAngle(leftUniquePoint, pivotalCommonPoint, theOtherCommonPoint); double angleOmega = VectorMathDouble.vectorAngle(leftUniquePoint, theOtherCommonPoint, pivotalCommonPoint); // Obtain Mean Curvature Normal Operator. double cotAlpha = 1/Math.tan(angleAlpha); double cotBetha = 1/Math.tan(angleBetha); double scalar = (cotAlpha + cotBetha); double[] centerEdgeVectorScalarMultiplied = VectorMathDouble.multiply(centerEdgeVector, scalar); normalOperator = VectorMath.add(normalOperator, centerEdgeVectorScalarMultiplied); // Calculate area of the left triangle. double[] leftEdgeVector = VectorMathDouble.difference(pivotalCommonPoint, leftUniquePoint); double magnitudeOfLeftEdge = VectorMathDouble.magnitude(leftEdgeVector); double[] rightEdgeVector = VectorMathDouble.difference(theOtherCommonPoint, leftUniquePoint); double magnitudeOfRightEdge = VectorMathDouble.magnitude(rightEdgeVector); double areaOfLeftTriangle = Math.sin(angleAlpha)*magnitudeOfLeftEdge*magnitudeOfRightEdge/2.0; if(_areaCalMethod == BARYCENTRIC_AREA){ barycentricArea = barycentricArea + areaOfLeftTriangle/3.0; } else if(_areaCalMethod == VORONOI_AREA){ // Obtuse angle exists at pivot vertex. if(angleTheta > Math.PI/2){ mixedArea = mixedArea + areaOfLeftTriangle/2.0; } // Obtuse angle exists at other vertex beside the pivot vertex. else if(angleAlpha > Math.PI/2 || angleOmega > Math.PI/2){ mixedArea = mixedArea + areaOfLeftTriangle/4.0; } // No obtuse angle exists else{ double magnitudeOfCenterVector = VectorMathDouble.magnitude(centerEdgeVector); double voronoiAreaInATriangle = magnitudeOfLeftEdge* magnitudeOfLeftEdge* (1/Math.tan(angleOmega)) + magnitudeOfCenterVector* magnitudeOfCenterVector* (1/Math.tan(angleAlpha)); mixedArea = mixedArea + voronoiAreaInATriangle/8.0; } } } catch (InappropriateGeometryException ige) { throw new CalculationException( "Unable to calculate curvature of face # " +i + " Reason " + ige.getMessage()); } } if(_areaCalMethod == BARYCENTRIC_AREA){ normalOperator = VectorMathDouble.multiply(normalOperator, 1.0/(2.0*barycentricArea)); meanCurvature = meanCurvature*(1.0/(4.0*barycentricArea)); } else if(_areaCalMethod == VORONOI_AREA){ normalOperator = VectorMathDouble.multiply(normalOperator, 1.0/(2.0*mixedArea)); meanCurvature = meanCurvature*(1.0/(4.0*mixedArea)); } double curvature = meanCurvature; if(_isAbsoluteMeanCurvature){ // The mean curvature value is half of the magnitude of Normal Operator. curvature = VectorMath.magnitude(normalOperator) / 2; } return curvature; * */ }
public double _MeanCurvature(Mesh3D m3d, int index) { double meanCurvature = 0.0; double mixedArea = 0; double barycentricArea = 0; Vector3D normalOperator = new Vector3D(); int[] nbrs = m3d.GetNeighbourVertices(index); HashSet<int> fi = new HashSet<int>(); for (int i = 0; i < nbrs.Length; i++) { int fii = m3d.FindFaceFromEdge(index, nbrs[i]); fi.Add(fii); } int m = fi.Count; int[] vLeft = null; int[] vRight = null; if (m > 1) { vLeft = m3d.Faces.ElementAt(fi.ElementAt(0)); //int[] vRight = m3d.Faces.ElementAt(fi.ElementAt((i + 1) % m)); vRight = m3d.Faces.ElementAt(fi.ElementAt(1)); } else if (m == 1) { //Console.WriteLine(m+" -- "+fi.ElementAt(i) + " - " + fi.ElementAt((i + 1) % m)); vLeft = m3d.Faces.ElementAt(fi.ElementAt(0)); vRight = m3d.Faces.ElementAt(fi.ElementAt(0)); } else { return _infinity; } // This point is also center point. int vertexInCommon1 = -1; // This point is the other end of common edge between two triangles. int vertexInCommon2 = -1; // These two points are not shared between two triangles. int vertexUniqueForLeftFace = -1; int vertexUniqueForRightFace = -1; // Find common vertexes in two adjacent triangles. for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { // If found vertex is pivotal point, save it as vertexInCommon1. // If found vertex is not pivotal point, then this vertex is // the other end of the common edge of two triangle. Save it as // vertexInCommon2. if (vLeft[j] == vRight[k]) { if (vLeft[j] == index) { vertexInCommon1 = vLeft[j]; break; } else { vertexInCommon2 = vLeft[j]; break; } } else { // If the vertex is not one of common vertexes, save it as // vertexUniqueForLeftFace. if (k == 2) { vertexUniqueForLeftFace = vLeft[j]; } } } } // If two triangles share only center point, the index point is located // on the edge of the surface. For example, for the ucf file the margin // of contours might not lap around, therefore the contour might have // boundary. if (vertexInCommon2 == -1) { return _infinity; } // Now task is finding a vertex which is unique to right triangle. // Go over each vertex in right face and find a vertex which is // not shared with left triangle. then save it as // vertexUniqueForLeftFace. for (int l = 0; l < 3; l++) { if (vRight[l] == vertexInCommon1) { } else if (vRight[l] == vertexInCommon2) { } else { vertexUniqueForRightFace = vRight[l]; break; } } if (vertexUniqueForLeftFace == -1) vertexUniqueForLeftFace = vertexInCommon1; // Obtain vector represent of vertex locations. Point3D pivotalCommonPoint = m3d.Vertices.ElementAt(vertexInCommon1); Point3D theOtherCommonPoint = m3d.Vertices.ElementAt(vertexInCommon2); Point3D leftUniquePoint = m3d.Vertices.ElementAt(vertexUniqueForLeftFace); Point3D rightUniquePoint = m3d.Vertices.ElementAt(vertexUniqueForRightFace); Vector3D centerEdgeVector = Vector3D.Subtract(theOtherCommonPoint.ToVector3D(), pivotalCommonPoint.ToVector3D()); if (!_isAbsoluteMeanCurvature) { Vector3D v1 = Vector3D.Subtract(leftUniquePoint.ToVector3D(), pivotalCommonPoint.ToVector3D()); Vector3D v2 = Vector3D.Subtract(rightUniquePoint.ToVector3D(), pivotalCommonPoint.ToVector3D()); // Normal vector of the first face. Vector3D normal1 = Vector3D.CrossProduct(v1, centerEdgeVector); // Normal vector of the second face. Vector3D normal2 = Vector3D.CrossProduct(centerEdgeVector, v2); // Dihedral angle between adjacent triangular faces and is computed // as the angle between the corresponding normals. double dihedralAngle = Math.Acos(Vector3D.DotProduct(normal1, normal2) / (normal1.Length * normal2.Length)); // Edge is convex edge if the edge type is greater than 0, and edge // is concave edge if the edge type is smaller than 0, and edge is // planner if edge type is 0; double edgeType = Vector3D.DotProduct( Vector3D.CrossProduct(normal1, normal2), centerEdgeVector); double edgeVectorEuclideanNorm =centerEdgeVector.Length; if (edgeType < 0) { meanCurvature += -1 * edgeVectorEuclideanNorm * dihedralAngle; } else if (edgeType > 0) { meanCurvature += edgeVectorEuclideanNorm * dihedralAngle; } else { meanCurvature += 0; } } // Calculate cot x and cot y where x and y are the angles opposite // common edge in two incident triangles. try { double angleAlpha = Vector3D.AngleBetween(pivotalCommonPoint.ToVector3D(), leftUniquePoint.ToVector3D()); //theOtherCommonPoint.ToVector3D())); double angleBetha = Vector3D.AngleBetween(pivotalCommonPoint.ToVector3D(), rightUniquePoint.ToVector3D()); //,theOtherCommonPoint); // angleAlpha, angleTheta, and angleOmega are three angles of left triangles. // Test if any of these angles is obtuse. double angleTheta = Vector3D.AngleBetween(leftUniquePoint.ToVector3D(), pivotalCommonPoint.ToVector3D()); //,theOtherCommonPoint); double angleOmega = Vector3D.AngleBetween(leftUniquePoint.ToVector3D(), theOtherCommonPoint.ToVector3D()); //,pivotalCommonPoint); // Obtain Mean Curvature Normal Operator. double cotAlpha = 1 / Math.Tan(angleAlpha); double cotBetha = 1 / Math.Tan(angleBetha); double scalar = (cotAlpha + cotBetha); Vector3D centerEdgeVectorScalarMultiplied = Vector3D.Multiply(centerEdgeVector, scalar); normalOperator = Vector3D.Add(normalOperator, centerEdgeVectorScalarMultiplied); // Calculate area of the left triangle. Vector3D leftEdgeVector = Vector3D.Subtract(pivotalCommonPoint.ToVector3D(), leftUniquePoint.ToVector3D()); double magnitudeOfLeftEdge = leftEdgeVector.Length; Vector3D rightEdgeVector = Vector3D.Subtract(theOtherCommonPoint.ToVector3D(), leftUniquePoint.ToVector3D()); double magnitudeOfRightEdge = rightEdgeVector.Length; double areaOfLeftTriangle = Math.Sin(angleAlpha) * magnitudeOfLeftEdge * magnitudeOfRightEdge / 2.0; if (_areaCalMethod == BARYCENTRIC_AREA) { barycentricArea = barycentricArea + areaOfLeftTriangle / 3.0; } else if (_areaCalMethod == VORONOI_AREA) { // Obtuse angle exists at pivot vertex. if (angleTheta > Math.PI / 2) { mixedArea = mixedArea + areaOfLeftTriangle / 2.0; } // Obtuse angle exists at other vertex beside the pivot vertex. else if (angleAlpha > Math.PI / 2 || angleOmega > Math.PI / 2) { mixedArea = mixedArea + areaOfLeftTriangle / 4.0; } // No obtuse angle exists else { double magnitudeOfCenterVector = centerEdgeVector.Length; double voronoiAreaInATriangle = magnitudeOfLeftEdge * magnitudeOfLeftEdge * (1 / Math.Tan(angleOmega)) + magnitudeOfCenterVector * magnitudeOfCenterVector * (1 / Math.Tan(angleAlpha)); mixedArea = mixedArea + voronoiAreaInATriangle / 8.0; } } } catch (Exception ige) { Console.WriteLine( "Unable to calculate curvature of face # " + index+ " Reason " + ige.Message); } if (_areaCalMethod == BARYCENTRIC_AREA) { normalOperator = Vector3D.Multiply(normalOperator, 1.0 / (2.0 * barycentricArea)); meanCurvature = meanCurvature * (1.0 / (4.0 * barycentricArea)); } else if (_areaCalMethod == VORONOI_AREA) { normalOperator = Vector3D.Multiply(normalOperator, 1.0 / (2.0 * mixedArea)); meanCurvature = meanCurvature * (1.0 / (4.0 * mixedArea)); } double curvature = meanCurvature; if (_isAbsoluteMeanCurvature) { // The mean curvature value is half of the magnitude of Normal Operator. curvature = normalOperator.Length / 2; } return meanCurvature; }
internal MeshGeometry3D AutoSnake(MeshGeometry3D mesh, ref MeshBuilder newmbP) { //Dictionary<Int32, SmileEdge> neighbours = SmileVisual3D.findNeighbours(mesh); Point3DCollection positions = mesh.Positions; Int32Collection triangleIndices = mesh.TriangleIndices; Mesh3D m3d = new Mesh3D(positions, triangleIndices); Vector3DCollection t = new Vector3DCollection(positions.Count); Vector3DCollection b = new Vector3DCollection(positions.Count); Vector3DCollection n = new Vector3DCollection(positions.Count); double eThreshold = -0.5; double nThreshold = 0.8; double minEnergy = 10; double alpha = 1; double betha = 1; double ballon = 1; double lambda = 1; Vector3DCollection e = new Vector3DCollection(positions.Count); Vector3DCollection eInt = new Vector3DCollection(positions.Count); Vector3DCollection eExt = new Vector3DCollection(positions.Count); Vector3DCollection delta = new Vector3DCollection(positions.Count); Vector3DCollection f = new Vector3DCollection(positions.Count); Vector3DCollection tETF = new Vector3DCollection(positions.Count); //Vector3DCollection k = new Vector3DCollection(); //DoubleCollection kH = new DoubleCollection(); Dictionary<int, Double> kH = new Dictionary<int, double>(); MeshBuilder newmbD = new MeshBuilder(false,false); for (int i = 0; i < triangleIndices.Count; i+=3) { for (int a = 0; a < 3; a++) { int vi = triangleIndices[i+a]; if (!kH.ContainsKey(vi)) { double kHi = _MeanCurvature(m3d, vi); kH.Add(vi, kHi); } //Console.WriteLine("start mean"); //kH.Add(kHi); //Console.WriteLine("end mean"); if (a == 2) { int vi1 = triangleIndices[i + a - 1]; int vi2 = triangleIndices[i + a - 2]; double kH3 = 0; kH.TryGetValue(vi, out kH3); double kH2 =0; kH.TryGetValue(vi1, out kH2); double kH1 = 0; kH.TryGetValue(vi2, out kH1); if ((kH3 < eThreshold || kH2 < eThreshold || kH1 < eThreshold)) { newmbD.Positions.Add(positions[vi]); newmbD.Positions.Add(positions[vi1]); newmbD.Positions.Add(positions[vi2]); newmbD.TriangleIndices.Add(i + a); newmbD.TriangleIndices.Add(i + a - 1); newmbD.TriangleIndices.Add(i + a - 2); } if ((kH3 > nThreshold || kH2 > nThreshold || kH1 > nThreshold)) { newmbP.Positions.Add(positions[vi]); newmbP.Positions.Add(positions[vi1]); newmbP.Positions.Add(positions[vi2]); newmbP.TriangleIndices.Add(i + a); newmbP.TriangleIndices.Add(i + a - 1); newmbP.TriangleIndices.Add(i + a - 2); } } int[] nbrs = m3d.GetNeighbourVertices(vi); Vector3DCollection N = new Vector3DCollection(positions.Count); Point3D pi = positions[vi]; int i0 = triangleIndices[i + a ]; if (i + a - 1 >= 0) i0 = triangleIndices[i + a - 1]; Point3D pi0 = positions[i0]; int i1 = vi; if (i + a + i < triangleIndices.Count) i1 = triangleIndices[i + a + 1]; Point3D pi1 = positions[i1]; t.Insert(vi, (pi1 - pi0) / (Point3D.Subtract(pi1, pi0).Length)); //t[i] = (pi1 - pi0) / Math.Sqrt((Point3D.Subtract(pi1, pi0).Length)); n.Insert(vi, SmileVisual3D.CalculateNormal(pi0, pi, pi1)); b.Insert(vi, Vector3D.CrossProduct(t[vi], n[vi])); Vector3D eIntV = new Vector3D(); //eInt[vi]; Vector3D eExtV = new Vector3D(); //eExt[vi]; Vector3D eV = new Vector3D(); //e[vi]; Vector3D sumDeltaNbrs = new Vector3D(); Vector3D sumFNbrs = new Vector3D(); int maxNbrs = (nbrs.Length > 2 ? 2 : nbrs.Length); for (int j = 0; j < maxNbrs; j++) { Point3D nbj = positions[nbrs[j]]; N.Add(nbj.ToVector3D()); } double determinantVi = determinant(N); double kv = 0; kH.TryGetValue(vi, out kv); double jminEnergy = minEnergy; Point3D tempNbj = pi; for (int j = 0; j < maxNbrs; j++) { Point3D nbj = positions[nbrs[j]]; double ku = 0; kH.TryGetValue(nbrs[j], out ku); sumDeltaNbrs += Vector3D.Multiply( (kv - ku) , Vector3D.Divide(Point3D.Subtract(nbj, pi) , (Point3D.Subtract(nbj,pi).Length) ) ); delta.Insert(vi, (1 / determinantVi) * sumDeltaNbrs); f.Insert(vi, Vector3D.Multiply((1 - lambda) , Vector3D.Multiply((1 / determinantVi ), new Vector3D()) ) + Vector3D.Multiply(lambda,delta[vi])); double eIntj = alpha * (Point3D.Subtract(pi0, nbj).Length) + betha * (Point3D.Subtract(pi0, Point3D.Add(pi1, (Vector3D)nbj)).Length); //TODO: crosscheck double eFaej = ballon * (-(f[vi].Length) - Vector3D.DotProduct((f[vi] / f[vi].Length), (Point3D.Subtract(nbj, pi) / Point3D.Subtract(nbj, pi).Length))); //TODO: crosscheck double ePressj = ballon * Vector3D.DotProduct(b[vi], (Point3D.Subtract(pi0, nbj) / Point3D.Subtract(pi0, nbj).Length)); double eExtj = eFaej + ePressj; double ej = eIntj + eExtj; if (j == 0) { eIntV.X = eIntj; eExtV.X = eExtj; eV.X = ej; } if (j == 1) { eIntV.Y = eIntj; eExtV.Y = eExtj; eV.Y = ej; } if (j == 2) { eIntV.Z = eIntj; eExtV.Z = eExtj; eV.Z = ej; } if (ej < jminEnergy) { jminEnergy = ej; tempNbj = nbj; //TODO: snake movement //AddSnakeElement(nbj); } } AddSnakeElement(tempNbj); eInt.Insert(vi, eIntV); eExt.Insert(vi, eExtV); e.Insert(vi, eV); //delta.Insert(vi, (1 / determinant(N[vi])) * sumDeltaNbrs); //TODO:implemenet //f.Insert(vi, n[vi]);// (1 - lambda) * (1 / (Math.Abs(nbrs.Count))) + lambda *delta[i]; //TODO:implemenet tETF.Insert(vi, Vector3D.CrossProduct(delta[vi], n[vi])); } } return newmbD.ToMesh(); /* for (int i = 0; i < positions.Count; i++) { Int32Collection nbrs = neighbours[i].neighbours; Point3D pi = positions[i]; int i0 = i; if (i - 1 >= 0) i0 = i - 1; Point3D pi0 = positions[i0]; int i1 = i; if (i + i < triangleIndices.Count) i = i + 1; Point3D pi1 = positions[i1]; t[i] = (pi1 - pi0) / (Point3D.Subtract(pi1, pi0).Length); //t[i] = (pi1 - pi0) / Math.Sqrt((Point3D.Subtract(pi1, pi0).Length)); n[i] = SmileVisual3D.CalculateNormal(pi0, pi, pi1); b[i] = Vector3D.CrossProduct(t[i], n[i]); Vector3D eIntV = eInt[i]; Vector3D eExtV = eExt[i]; Vector3D eV = e[i]; int maxNbrs = (nbrs.Count > 2 ? 2 : nbrs.Count); for (int j = 0; j < maxNbrs; j++) { Point3D nbj = positions[nbrs[j]]; double eIntj = alpha * (Point3D.Subtract(pi0, nbj).Length) + betha * (Point3D.Subtract(pi0, Point3D.Add(pi1, (Vector3D)nbj)).Length); //TODO: crosscheck delta[i] = n[i];// 1 / determinant(N[i]); //TODO:implemenet f[i] = n[i];// (1 - lambda) * (1 / (Math.Abs(nbrs.Count))) + lambda *delta[i]; //TODO:implemenet double eFaej = ballon * (-(f[i].Length) - Vector3D.DotProduct((f[i] / f[i].Length), (Point3D.Subtract(nbj, pi) / Point3D.Subtract(nbj, pi).Length))); //TODO: crosscheck double ePressj = ballon * Vector3D.DotProduct(b[i], (Point3D.Subtract(pi0, nbj) / Point3D.Subtract(pi0, nbj).Length)); double eExtj = eFaej + ePressj; double ej = eIntj + eExtj; if (j == 0) { eIntV.X = eIntj; eExtV.X = eExtj; eV.X = ej; } if (j == 1) { eIntV.Y = eIntj; eExtV.Y = eExtj; eV.Y = ej; } if (j == 2) { eIntV.Z = eIntj; eExtV.Z = eExtj; eV.Z = ej; } if (ej < minEnergy) { minEnergy = ej; //TODO: snake movement AddSnakeElement(nbj); } eInt[i] = eIntV; eExt[i] = eExtV; e[i] = eV; } tETF[i] = Vector3D.CrossProduct(delta[i], n[i]); } * */ }
private Mesh3D CreatePentagon() { Mesh3D m = new Mesh3D(); Vertex3D v0 = m.AddVertex(new Vertex3D(1, 4, 0)); Vertex3D v1 = m.AddVertex(new Vertex3D(5, 0, 0)); Vertex3D v2 = m.AddVertex(new Vertex3D(3, -4, 0)); Vertex3D v3 = m.AddVertex(new Vertex3D(-1, -4, 0)); Vertex3D v4 = m.AddVertex(new Vertex3D(-3, 0, 0)); List<Vertex3D> poly = new List<Vertex3D>(); poly.Add(v0); poly.Add(v1); poly.Add(v2); poly.Add(v3); poly.Add(v4); m.CreatePolygon(poly); return m; }