Skip to content

Commit

Permalink
utility functions, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Aug 4, 2017
1 parent cedf9d0 commit 3a92f8b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
19 changes: 18 additions & 1 deletion math/Frame3f.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,67 +221,84 @@ public float DistanceToPlaneSigned(Vector3f p, int nNormal)
}


///<summary> Map point *into* local coordinates of Frame </summary>
public Vector3f ToFrameP(Vector3f v)
{
v = v - this.origin;
v = Quaternionf.Inverse(this.rotation) * v;
return v;
}
///<summary> Map point *into* local coordinates of Frame </summary>
public Vector3d ToFrameP(Vector3d v)
{
v = v - this.origin;
v = Quaternionf.Inverse(this.rotation) * v;
return v;
}
/// <summary> Map point *from* local frame coordinates into "world" coordinates </summary>
public Vector3f FromFrameP(Vector3f v)
{
return this.rotation * v + this.origin;
}
/// <summary> Map point *from* local frame coordinates into "world" coordinates </summary>
public Vector3d FromFrameP(Vector3d v)
{
return this.rotation * v + this.origin;
}



///<summary> Map vector *into* local coordinates of Frame </summary>
public Vector3f ToFrameV(Vector3f v)
{
return Quaternionf.Inverse(this.rotation) * v;
}
///<summary> Map vector *into* local coordinates of Frame </summary>
public Vector3d ToFrameV(Vector3d v)
{
return Quaternionf.Inverse(this.rotation) * v;
}
/// <summary> Map vector *from* local frame coordinates into "world" coordinates </summary>
public Vector3f FromFrameV(Vector3f v)
{
return this.rotation * v;
}
/// <summary> Map vector *from* local frame coordinates into "world" coordinates </summary>
public Vector3d FromFrameV(Vector3d v)
{
return this.rotation * v;
}



///<summary> Map quaternion *into* local coordinates of Frame </summary>
public Quaternionf ToFrame(Quaternionf q)
{
return Quaternionf.Inverse(this.rotation) * q;
}
/// <summary> Map quaternion *from* local frame coordinates into "world" coordinates </summary>
public Quaternionf FromFrame(Quaternionf q)
{
return this.rotation * q;
}


///<summary> Map ray *into* local coordinates of Frame </summary>
public Ray3f ToFrame(Ray3f r)
{
return new Ray3f(ToFrameP(r.Origin), ToFrameV(r.Direction));
}
/// <summary> Map ray *from* local frame coordinates into "world" coordinates </summary>
public Ray3f FromFrame(Ray3f r)
{
return new Ray3f(FromFrameP(r.Origin), FromFrameV(r.Direction));
}

///<summary> Map frame *into* local coordinates of Frame </summary>
public Frame3f ToFrame(Frame3f f)
{
return new Frame3f(ToFrameP(f.origin), ToFrame(f.rotation));
}
/// <summary> Map frame *from* local frame coordinates into "world" coordinates </summary>
public Frame3f FromFrame(Frame3f f)
{
return new Frame3f(FromFrameP(f.origin), FromFrame(f.rotation));
Expand Down
5 changes: 3 additions & 2 deletions mesh/MeshConstraintUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ public static void FixAllGroupBoundaryEdges(Remesher r, bool bPinVertices)

// for all vertices in loopV, constrain to target
// for all edges in loopV, disable flips and constrain to target
public static void ConstrainVtxLoopTo(MeshConstraints cons, DMesh3 mesh, int[] loopV, IProjectionTarget target)
public static void ConstrainVtxLoopTo(MeshConstraints cons, DMesh3 mesh, int[] loopV, IProjectionTarget target, int setID = -1)
{
VertexConstraint vc = new VertexConstraint(target);
for (int i = 0; i < loopV.Length; ++i)
cons.SetOrUpdateVertexConstraint(loopV[i], vc);

EdgeConstraint ec = new EdgeConstraint(EdgeRefineFlags.NoFlip, target);
ec.TrackingSetID = setID;
for ( int i = 0; i < loopV.Length; ++i ) {
int v0 = loopV[i];
int v1 = loopV[(i + 1) % loopV.Length];
Expand All @@ -117,7 +118,7 @@ public static void ConstrainVtxLoopTo(MeshConstraints cons, DMesh3 mesh, int[] l
}

}
public static void ConstrainVtxLoopTo(Remesher r, int[] loopV, IProjectionTarget target)
public static void ConstrainVtxLoopTo(Remesher r, int[] loopV, IProjectionTarget target, int setID = -1)
{
if (r.Constraints == null)
r.SetExternalConstraints(new MeshConstraints());
Expand Down
10 changes: 10 additions & 0 deletions mesh/MeshNormals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,15 @@ void Compute_FaceAvg_AreaWeighted()




public static void QuickCompute(DMesh3 mesh)
{
MeshNormals normals = new MeshNormals(mesh);
normals.Compute();
normals.CopyTo(mesh);
}



}
}
24 changes: 24 additions & 0 deletions queries/MeshQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,29 @@ public static void EdgeLengthStats(DMesh3 mesh, out double minEdgeLen, out doubl



public static void EdgeLengthStatsFromEdges(DMesh3 mesh, IEnumerable<int> EdgeItr, 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;

Vector3d a = Vector3d.Zero, b = Vector3d.Zero;
foreach ( int eid in EdgeItr ) {
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++;
}
};
avgEdgeLen /= (double)avg_count;
}



}
}
23 changes: 23 additions & 0 deletions spatial/BasicProjectionTargets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,27 @@ public Vector3d Project(Vector3d vPoint, int identifer = -1)
}
}




public class SequentialProjectionTarget : IProjectionTarget
{
public IProjectionTarget[] Targets { get; set; }

public SequentialProjectionTarget() { }
public SequentialProjectionTarget(params IProjectionTarget[] targets)
{
Targets = targets;
}

public Vector3d Project(Vector3d vPoint, int identifier = -1)
{
Vector3d vCur = vPoint;
for ( int i = 0; i < Targets.Length; ++i ) {
vCur = Targets[i].Project(vCur, identifier);
}
return vCur;
}
}

}

0 comments on commit 3a92f8b

Please sign in to comment.