Skip to content

Commit

Permalink
added area-extrusion, renamed loop-extrusion
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Sep 19, 2017
1 parent 59dc231 commit 56d5cfd
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 8 deletions.
4 changes: 3 additions & 1 deletion geometry3Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<Compile Include="io\StandardMeshReader.cs" />
<Compile Include="io\StandardMeshWriter.cs" />
<Compile Include="mesh_generators\VoxelSurfaceGenerator.cs" />
<Compile Include="mesh_ops\MeshExtrudeFaces.cs" />
<Compile Include="mesh_ops\MeshInsertUVPolyCurve.cs" />
<Compile Include="mesh_ops\MeshLocalParam.cs" />
<Compile Include="mesh_ops\LaplacianMeshSmoother.cs" />
Expand All @@ -153,11 +154,12 @@
<Compile Include="mesh\MeshMeasurements.cs" />
<Compile Include="mesh\MeshTransforms.cs" />
<Compile Include="mesh_generators\PlaneGenerators.cs" />
<Compile Include="mesh_ops\MeshExtrusion.cs" />
<Compile Include="mesh_ops\MeshExtrudeLoop.cs" />
<Compile Include="mesh_ops\MeshICP.cs" />
<Compile Include="mesh_ops\MeshIterativeSmooth.cs" />
<Compile Include="mesh_ops\MeshLoopClosure.cs" />
<Compile Include="mesh_ops\MeshLoopSmooth.cs" />
<Compile Include="mesh_ops\MeshOps.cs" />
<Compile Include="mesh_ops\SimpleHoleFiller.cs" />
<Compile Include="mesh_selection\MeshBoundaryLoops.cs" />
<Compile Include="mesh_selection\MeshConnectedComponents.cs" />
Expand Down
96 changes: 96 additions & 0 deletions mesh_ops/MeshExtrudeFaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace g3
{
public class MeshExtrudeFaces
{
public DMesh3 Mesh;
public int[] Triangles;

// arguments

public SetGroupBehavior Group = SetGroupBehavior.AutoGenerate;

// set new position based on original loop vertex position, normal, and index
public Func<Vector3d, Vector3f, int, Vector3d> ExtrudedPositionF;

// outputs
public List<Index2i> EdgePairs;
public MeshVertexSelection ExtrudeVertices;
public int[] JoinTriangles;
public int SetGroupID;


public MeshExtrudeFaces(DMesh3 mesh, int[] triangles, bool bForceCopyArray = false)
{
Mesh = mesh;
if (bForceCopyArray)
Triangles = (int[])triangles.Clone();
else
Triangles = triangles;

ExtrudedPositionF = (pos, normal, idx) => {
return pos + Vector3d.AxisY;
};
}

public MeshExtrudeFaces(DMesh3 mesh, IEnumerable<int> triangles)
{
Mesh = mesh;
Triangles = triangles.ToArray();

ExtrudedPositionF = (pos, normal, idx) => {
return pos + Vector3d.AxisY;
};
}



public virtual ValidationStatus Validate()
{
// [todo] check that boundary is ok


return ValidationStatus.Ok;
}


public virtual bool Extrude()
{
MeshEditor editor = new MeshEditor(Mesh);

MeshNormals normals = null;
bool bHaveNormals = Mesh.HasVertexNormals;
if (!bHaveNormals) {
normals = new MeshNormals(Mesh);
normals.Compute();
}

editor.SeparateTriangles(Triangles, true, out EdgePairs);

ExtrudeVertices = new MeshVertexSelection(Mesh);
ExtrudeVertices.SelectTriangleVertices(Triangles);

Vector3d[] NewVertices = new Vector3d[ExtrudeVertices.Count];
int k = 0;
foreach (int vid in ExtrudeVertices) {
Vector3d v = Mesh.GetVertex(vid);
Vector3f n = (bHaveNormals) ? Mesh.GetVertexNormal(vid) : (Vector3f)normals.Normals[vid];
NewVertices[k++] = ExtrudedPositionF(v, n, vid);
}
k = 0;
foreach (int vid in ExtrudeVertices)
Mesh.SetVertex(vid, NewVertices[k++]);


SetGroupID = Group.GetGroupID(Mesh);
JoinTriangles = editor.StitchUnorderedEdges(EdgePairs, SetGroupID);

return true;
}


}
}
9 changes: 7 additions & 2 deletions mesh_ops/MeshExtrusion.cs → mesh_ops/MeshExtrudeLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

namespace g3
{
public class MeshExtrusion
/// <summary>
/// Assumption is that Loop is a boundary loop on Mesh.
/// Operation makes a duplicate loop of vertices, at location defind by PositionF,
/// then stitches input and new loops together with a ring of triangles.
/// </summary>
public class MeshExtrudeLoop
{
public DMesh3 Mesh;
public EdgeLoop Loop;
Expand All @@ -19,7 +24,7 @@ public class MeshExtrusion
public EdgeLoop NewLoop;


public MeshExtrusion(DMesh3 mesh, EdgeLoop loop)
public MeshExtrudeLoop(DMesh3 mesh, EdgeLoop loop)
{
Mesh = mesh;
Loop = loop;
Expand Down
2 changes: 1 addition & 1 deletion mesh_ops/MeshLoopClosure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Close_Flat()
//Frame3f plane = new Frame3f((Vector3f)topPt);

// extrude loop to this plane
MeshExtrusion extrude = new MeshExtrusion(Mesh, fill_loop);
MeshExtrudeLoop extrude = new MeshExtrudeLoop(Mesh, fill_loop);
extrude.PositionF = (v, n, i) => {
return FlatClosePlane.ProjectToPlane((Vector3f)v, 1);
};
Expand Down
42 changes: 42 additions & 0 deletions mesh_ops/MeshOps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;

namespace g3
{

public struct SetGroupBehavior
{
public enum Modes
{
Ignore = 0,
AutoGenerate = 1,
UseConstant = 2
};
Modes Mode;
int SetGroupID;

public SetGroupBehavior(Modes mode, int id = 0) {
Mode = mode;
SetGroupID = id;
}

public int GetGroupID(DMesh3 mesh)
{
if (Mode == Modes.Ignore)
return -1;
else if (Mode == Modes.AutoGenerate)
return mesh.AllocateTriangleGroup();
else
return SetGroupID;
}

public static SetGroupBehavior Ignore { get { return new SetGroupBehavior(Modes.Ignore, 0); } }
public static SetGroupBehavior AutoGenerate { get { return new SetGroupBehavior(Modes.AutoGenerate, 0); } }
public static SetGroupBehavior SetTo(int groupID) { return new SetGroupBehavior(Modes.UseConstant, groupID); }
}


public static class MeshOps
{

}
}
6 changes: 4 additions & 2 deletions mesh_selection/MeshVertexSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ private void remove(int vID)
Selected.Remove(vID);
}

public int Count {
get { return Selected.Count; }
}

public bool IsSelected(int vID)
{
public bool IsSelected(int vID) {
return Selected.Contains(vID);
}

Expand Down
3 changes: 1 addition & 2 deletions queries/MeshValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public enum ValidationStatus
Ok,

NotAVertex,

NotBoundaryVertex,
NotBoundaryEdge,

Expand All @@ -19,7 +18,7 @@ public enum ValidationStatus
DuplicateTriangles,

NearDegenerateMeshEdges,
NearDenegerateInputGeometry
NearDenegerateInputGeometry,
}


Expand Down

0 comments on commit 56d5cfd

Please sign in to comment.