Skip to content

Commit

Permalink
independent utility fns
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Feb 4, 2017
1 parent 737da38 commit 3bee216
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 6 deletions.
20 changes: 20 additions & 0 deletions core/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ static public string ToSecMilli(TimeSpan t)



static public T[] AppendArrays<T>(params object[] args)
{
int count = args.Length;
int N = 0;
for (int i = 0; i < count; ++i)
N += (args[i] as T[]).Length;

T[] result = new T[N];
int cur_offset = 0;
for ( int i = 0; i < count; ++i ) {
T[] c = args[i] as T[];
Array.Copy(c, 0, result, cur_offset, c.Length);
cur_offset += c.Length;
}

return result;
}




// conversion to/from bytes
public static byte[] StructureToByteArray(object obj)
Expand Down
20 changes: 17 additions & 3 deletions mesh/DMesh3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,12 @@ public void SetVertex(int vID, Vector3d vNewPos) {
}
}

public Vector3f GetVertexNormal(int vID) {
return vertices_refcount.isValid(vID) ?
new Vector3f(normals[3 * vID], normals[3 * vID + 1], normals[3 * vID + 2]) : Vector3f.AxisY;
public Vector3f GetVertexNormal(int vID) {
if (normals == null)
return Vector3f.AxisY;
else
return vertices_refcount.isValid(vID) ?
new Vector3f(normals[3 * vID], normals[3 * vID + 1], normals[3 * vID + 2]) : Vector3f.AxisY;
}

public void SetVertexNormal(int vID, Vector3f vNewNormal) {
Expand Down Expand Up @@ -471,6 +474,17 @@ public Index2i GetEdgeV(int eID) {
return edges_refcount.isValid(eID) ?
new Index2i(edges[4 * eID], edges[4 * eID + 1]) : InvalidEdge;
}
public bool GetEdgeV(int eID, ref Vector3d a, ref Vector3d b) {
if ( edges_refcount.isValid(eID) ) {
int iv0 = 3 * edges[4 * eID];
a.x = vertices[iv0]; a.y = vertices[iv0 + 1]; a.z = vertices[iv0 + 2];
int iv1 = 3 * edges[4 * eID + 1];
b.x = vertices[iv1]; b.y = vertices[iv1 + 1]; b.z = vertices[iv1 + 2];
return true;
}
return false;
}

public Index2i GetEdgeT(int eID) {
return edges_refcount.isValid(eID) ?
new Index2i(edges[4 * eID + 2], edges[4 * eID + 3]) : InvalidEdge;
Expand Down
7 changes: 7 additions & 0 deletions mesh/DSubmesh3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public DSubmesh3(DMesh3 mesh, int[] subTriangles)
}


public void MapVerticesToSubmesh(int[] vertices)
{
for (int i = 0; i < vertices.Length; ++i)
vertices[i] = BaseToSubV[vertices[i]];
}


public void ComputeBoundaryInfo(int[] subTriangles) {
ComputeBoundaryInfo(subTriangles, subTriangles.Length);
}
Expand Down
10 changes: 7 additions & 3 deletions mesh/RegionRemesher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class RegionRemesher : Remesher
public DMesh3 BaseMesh;
public DSubmesh3 Region;

// By default is initialized w/ all boundary constraints
// You can add more, but don't screw up!
MeshConstraints bdry_constraints;

int[] cur_base_tris;


Expand All @@ -23,9 +27,9 @@ public RegionRemesher(DMesh3 mesh, int[] regionTris)

// add boundary-edge constraints
// [TODO] actually only want to constrain submesh border edges...
MeshConstraints cons = new MeshConstraints();
MeshConstraintUtil.FixAllBoundaryEdges(cons, Region.SubMesh);
SetExternalConstraints(cons);
bdry_constraints = new MeshConstraints();
MeshConstraintUtil.FixAllBoundaryEdges(bdry_constraints, Region.SubMesh);
SetExternalConstraints(bdry_constraints);
}


Expand Down
8 changes: 8 additions & 0 deletions mesh/Remesher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public Remesher(DMesh3 m) {
}


public DMesh3 Mesh {
get { return mesh; }
}
public MeshConstraints Constraints {
get { return constraints; }
}


//! This object will be modified !!!
public void SetExternalConstraints(MeshConstraints cons)
{
Expand Down
34 changes: 34 additions & 0 deletions queries/MeshQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,39 @@ public static int FindHitTriangle_LinearSearch(DMesh3 mesh, Ray3d ray)
}




public static void EdgeLengthStats(DMesh3 mesh, out double minEdgeLen, out double maxEdgeLen, out double avgEdgeLen, int samples = 0)
{
minEdgeLen = double.MaxValue;
maxEdgeLen = double.MinValue;
avgEdgeLen = 0;
int avg_count = 0;
int MaxID = mesh.MaxEdgeID;

// if we are only taking some samples, use a prime-modulo-loop instead of random
int nPrime = (samples == 0 ) ? 1 : nPrime = 31337;
int max_count = (samples == 0) ? MaxID : samples;

Vector3d a = Vector3d.Zero, b = Vector3d.Zero;
int eid = 0;
int count = 0;
do {
if (mesh.IsEdge(eid)) {
mesh.GetEdgeV(eid, ref a, ref b);
double len = a.Distance(b);
if (len < minEdgeLen) minEdgeLen = len;
if (len > maxEdgeLen) maxEdgeLen = len;
avgEdgeLen += len;
avg_count++;
}
eid = (eid + nPrime) % MaxID;
} while (eid != 0 && count++ < max_count);

avgEdgeLen /= (double)avg_count;
}



}
}

0 comments on commit 3bee216

Please sign in to comment.