本文整理汇总了C#中Octree.AddNode方法的典型用法代码示例。如果您正苦于以下问题:C# Octree.AddNode方法的具体用法?C# Octree.AddNode怎么用?C# Octree.AddNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Octree
的用法示例。
在下文中一共展示了Octree.AddNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawLibGGraphicItem
//.........这里部分代码省略.........
//draw a label at the start of the curve
if (node.DisplayLabels && i == 0)
{
rd.Text.Add(new BillboardTextItem { Text = tag, Position = start });
}
if (selected)
{
rd.SelectedLines.Add(start);
rd.SelectedLines.Add(end);
}
else
{
rd.Lines.Add(start);
rd.Lines.Add(end);
}
}
#endregion
#region draw surface
//var sw = new Stopwatch();
//sw.Start();
var builder = new MeshBuilder();
var points = new Point3DCollection();
var tex = new PointCollection();
var norms = new Vector3DCollection();
var tris = new List<int>();
FloatList triangle_vertices = g.triangle_vertices_threadsafe();
FloatList triangle_normals = g.triangle_normals_threadsafe();
for (int i = 0; i < triangle_vertices.Count; i+=3)
{
var new_point = new Point3D(triangle_vertices[i],
triangle_vertices[i + 1],
triangle_vertices[i + 2]);
var normal = new Vector3D(triangle_normals[i],
triangle_normals[i + 1],
triangle_normals[i + 2]);
//find a matching point
//compare the angle between the normals
//to discern a 'break' angle for adjacent faces
//int foundIndex = -1;
//for (int j = 0; j < points.Count; j++)
//{
// var testPt = points[j];
// var testNorm = norms[j];
// var ang = Vector3D.AngleBetween(normal, testNorm);
// if (new_point.X == testPt.X &&
// new_point.Y == testPt.Y &&
// new_point.Z == testPt.Z &&
// ang > 90.0000)
// {
// foundIndex = j;
// break;
// }
//}
//if (foundIndex != -1)
//{
// tris.Add(foundIndex);
// continue;
//}
tris.Add(points.Count);
points.Add(new_point);
norms.Add(normal);
tex.Add(new System.Windows.Point(0,0));
octree.AddNode(new_point.X, new_point.Y, new_point.Z, node.GUID.ToString());
}
//builder.AddTriangles(points, norms, tex);
builder.Append(points, tris, norms, tex);
//sw.Stop();
//Debug.WriteLine(string.Format("{0} elapsed for drawing geometry.", sw.Elapsed));
//don't add empty meshes
if (builder.Positions.Count > 0)
{
if (selected)
{
rd.SelectedMeshes.Add(builder.ToMesh(true));
}
else
{
rd.Meshes.Add(builder.ToMesh(true));
}
}
#endregion
}
}
示例2: RevitMeshToHelixMesh
/// <summary>
/// Convert a Revit mesh to a Helix mesh for visualization.
/// In order to merge mesh vertices, this method uses a dictionary with a string key formed as x:y:z of the point.
/// This assumes that where vertices are the "same" in the Revit mesh, they will have the same coordinates. This
/// is NOT a safe strategy to use in other mesh-processing contexts where vertices might have small discrepancies.
/// </summary>
/// <param name="rmesh"></param>
/// <param name="octree"></param>
/// <param name="node"></param>
/// <returns></returns>
private static MeshGeometry3D RevitMeshToHelixMesh(Mesh rmesh, Octree.OctreeSearch.Octree octree, NodeModel node)
{
var builder = new MeshBuilder();
var points = new Point3DCollection();
var tex = new PointCollection();
var norms = new Vector3DCollection();
var tris = new List<int>();
//A dictionary which will contain a point, a normal, and an index
//keyed on the location of the point as a hash
var pointDict = new Dictionary<string, PointData>();
for (int i = 0; i < rmesh.NumTriangles; ++i)
{
var tri = rmesh.get_Triangle(i);
//calculate the face normal by
//getting the cross product of two edges
var a = tri.get_Vertex(0);
var b = tri.get_Vertex(1);
var c = tri.get_Vertex(2);
var e1 = b - a;
var e2 = c - a;
var normXYZ = e1.CrossProduct(e2).Normalize();
var normal = new Vector3D(normXYZ.X, normXYZ.Y, normXYZ.Z);
for (int j = 0; j < 3; j++)
{
var pt = RevitPointToWindowsPoint(tri.get_Vertex(j));
var key = pt.X + ":" + pt.Y + ":" + pt.Z;
if (!pointDict.ContainsKey(key))
{
//if the dictionary doesn't contain the key
var pd = new PointData(pt.X,pt.Y,pt.Z);
pd.Normals.Add(normal);
pd.Index = pointDict.Count;
pointDict.Add(key, pd);
tris.Add(pd.Index);
}
else
{
//add an index to our tris array
//add a normal to our internal collection
//for post processing
var data = pointDict[key];
tris.Add(data.Index);
data.Normals.Add(normal);
}
}
}
var lst = pointDict.ToList();
lst.ForEach(x => points.Add(x.Value.Position));
lst.ForEach(x=>octree.AddNode(x.Value.Position.X, x.Value.Position.Y, x.Value.Position.Z, node.GUID.ToString()));
lst.ForEach(x=>tex.Add(x.Value.Tex));
//merge the normals
foreach (var pd in lst)
{
var avg = new Vector3D();
var nList = pd.Value.Normals;
foreach (var n in nList)
{
avg.X += n.X;
avg.Y += n.Y;
avg.Z += n.Z;
}
avg.X = avg.X / nList.Count;
avg.Y = avg.Y / nList.Count;
avg.Z = avg.Z / nList.Count;
norms.Add(avg);
}
builder.Append(points, tris, norms, tex);
Debug.WriteLine(string.Format("Mesh had {0} faces coming in and {1} faces going out.", rmesh.NumTriangles, builder.TriangleIndices.Count / 3));
return builder.ToMesh(true);
}