-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathConwayPoly.cs_backup.cs
executable file
·1646 lines (1412 loc) · 60.8 KB
/
ConwayPoly.cs_backup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using Wythoff;
using UnityEngine;
namespace Conway {
/// <summary>
/// A class for manifold meshes which uses the Halfedge data structure.
/// </summary>
public class ConwayPoly {
#region constructors
public ConwayPoly() {
Halfedges = new MeshHalfedgeList(this);
Vertices = new MeshVertexList(this);
Faces = new MeshFaceList(this);
}
public ConwayPoly(Polyhedron source) : this() {
// Add vertices
Vertices.Capacity = source.VertexCount;
foreach (var p in source.Vertices) {
Vertices.Add(new Vertex(p.getVector3()));
}
// Add faces (and construct halfedges and store in hash table)
foreach (Wythoff.Face face in source.faces) {
var v = new Vertex[face.points.Count];
for (int i = 0; i < face.points.Count; i++) {
v[i] = Vertices[face.points[i]];
}
if (!Faces.Add(v)) {
// Failed. Let's try flipping the face
Array.Reverse(v);
Faces.Add(v);
}
}
// Find and link halfedge pairs
Halfedges.MatchPairs();
}
public ConwayPoly(List<Vector3> positions, List<List<int>> faces) {
// Add vertices
Vertices.Capacity = positions.Count;
foreach (var p in positions) {
Vertices.Add(new Vertex(p));
}
// Add faces (and construct halfedges and store in hash table)
foreach (var face in faces) {
var v = new Vertex[face.Count];
for (int i = 0; i < face.Count; i++) {
v[i] = Vertices[face[i]];
}
if (!Faces.Add(v)) {
// Failed. Let's try flipping the face
Array.Reverse(v);
Faces.Add(v);
}
}
// Find and link halfedge pairs
Halfedges.MatchPairs();
}
/// <summary>
/// Constructor to build a custom mesh from Unity's mesh type
/// </summary>
/// <param name="source">the Rhino mesh</param>
public ConwayPoly(UnityEngine.Mesh source) : this() {
// Add vertices
Vertices.Capacity = source.vertexCount;
foreach (var p in source.vertices) {
Vertices.Add(new Vertex(p));
}
// Add faces (and construct halfedges and store in hash table)
for (int i = 0; i < source.triangles.Length; i += 3) {
var v = new List<Vertex> {
Vertices[source.triangles[i]],
Vertices[source.triangles[i + 1]],
Vertices[source.triangles[i + 2]]
};
Faces.Add(v);
}
// Find and link halfedge pairs
Halfedges.MatchPairs();
}
private ConwayPoly(IEnumerable<Vector3> verticesByPoints, IEnumerable<IEnumerable<int>> facesByVertexIndices) : this() {
InitIndexed(verticesByPoints, facesByVertexIndices);
Vertices.CullUnused();
}
private void InitIndexed(IEnumerable<Vector3> verticesByPoints, IEnumerable<IEnumerable<int>> facesByVertexIndices) {
// Add vertices
foreach (var p in verticesByPoints) {
Vertices.Add(new Vertex(p));
}
// Add faces
foreach (IEnumerable<int> indices in facesByVertexIndices) {
Faces.Add(indices.Select(i => Vertices[i]));
}
// Find and link halfedge pairs
Halfedges.MatchPairs();
}
public ConwayPoly Duplicate() {
// Export to face/vertex and rebuild
return new ConwayPoly(ListVerticesByPoints(), ListFacesByVertexIndices());
}
#endregion
#region properties
public MeshHalfedgeList Halfedges { get; private set; }
public MeshVertexList Vertices { get; set; }
public MeshFaceList Faces { get; private set; }
public bool IsValid {
get {
if (Halfedges.Count == 0) {
return false;
}
if (Vertices.Count == 0) {
return false;
}
if (Faces.Count == 0) {
return false;
}
// TODO: beef this up (check for a valid mesh)
return true;
}
}
// TODO
// public BoundingBox BoundingBox {
// get {
// if (!IsValid) {
// return BoundingBox.Empty;
// }
//
// List<Vector> points = new List<Vector>();
// foreach (var v in this.Vertices) {
// points.Add(v.Position);
// }
//
// BoundingBox result = new BoundingBox(points);
// result.MakeValid();
// return result;
// }
// }
#endregion
#region conway methods
public ConwayPoly Foo(float offset) {
var vertexPoints = new List<Vector3>();
var faceIndices = new List<IEnumerable<int>>();
for (int i = 0; i < Faces.Count; i++) {
var face = Faces[i];
int c = vertexPoints.Count;
//vertexPoints.AddRange(face.GetVertices().Select(v => v.Position));
var faceIndex = new List<int>();
for (int ii = 0; ii < face.GetVertices().Count; ii++) {
// faceIndex.Add(c+ii);
}
c = vertexPoints.Count;
vertexPoints.AddRange(face.GetVertices().Select(v => v.Position + face.Centroid - face.Centroid * offset));
faceIndex = new List<int>();
for (int ii = 0; ii < face.GetVertices().Count; ii++) {
faceIndex.Add(c+ii);
}
faceIndices.Add(faceIndex);
}
return new ConwayPoly(vertexPoints, faceIndices);
}
public ConwayPoly KisN(float offset, int sides) {
// vertices and faces to vertices
var newVerts = Faces.Select(f => f.Centroid + f.Normal * offset);
var vertexPoints = Enumerable.Concat(Vertices.Select(v => v.Position), newVerts);
// vertex lookup
var vlookup = new Dictionary<string, int>();
int originalVerticesCount = Vertices.Count;
for (int i = 0; i < originalVerticesCount; i++) {
vlookup.Add(Vertices[i].Name, i);
}
// create new tri-faces (like a fan)
var faceIndices = new List<IEnumerable<int>>(); // faces as vertex indices
for (int i = 0; i < Faces.Count; i++) {
if (Faces[i].Sides != sides) {
faceIndices.Add(ListFacesByVertexIndices()[i]);
} else {
foreach (var edge in Faces[i].GetHalfedges()) {
// create new face from edge start, edge end and centroid
faceIndices.Add(
new[] {vlookup[edge.Prev.Vertex.Name], vlookup[edge.Vertex.Name], i + originalVerticesCount}
);
}
}
}
return new ConwayPoly(vertexPoints, faceIndices);
}
// TODO
// See http://elfnor.com/conway-polyhedron-operators-in-sverchok.html
// and https://en.wikipedia.org/wiki/Conway_polyhedron_notation
//
// chamfer
// gyro
// whirl
// propellor
// snub (=gyro(dual))
/// <summary>
/// Conway's dual operator
/// </summary>
/// <returns>the dual as a new mesh</returns>
public ConwayPoly Dual() {
// Create vertices from faces
List<Vector3> vertexPoints = new List<Vector3>(Faces.Count);
foreach (var f in Faces) {vertexPoints.Add(f.Centroid);}
// Create sublist of non-boundary vertices
var naked = new Dictionary<string, bool>(Vertices.Count); // vertices (name, boundary?)
var hlookup = new Dictionary<string, int>(Halfedges.Count); // boundary halfedges (name, index of point in new mesh)
foreach (var he in Halfedges) {
if (!naked.ContainsKey(he.Vertex.Name)) { // if not in dict, add (boundary == true)
naked.Add(he.Vertex.Name, he.Pair == null);
} else if (he.Pair == null) { // if in dict and belongs to boundary halfedge, set true
naked[he.Vertex.Name] = true;
}
if (he.Pair == null) {
// if boundary halfedge, add mid-point to vertices and add to lookup
hlookup.Add(he.Name, vertexPoints.Count);
vertexPoints.Add(he.Midpoint);
}
}
// List new faces by their vertex indices
// (i.e. old vertices by their face indices)
Dictionary<string, int> flookup = new Dictionary<string, int>();
for (int i = 0; i < Faces.Count; i++) {
flookup.Add(Faces[i].Name, i);
}
var faceIndices = new List<List<int>>(Vertices.Count);
foreach (var v in Vertices) {
List<int> fIndex = new List<int>();
foreach (var f in v.GetVertexFaces()) {
fIndex.Add(flookup[f.Name]);
}
if (naked[v.Name]) { // Handle boundary vertices...
var h = v.Halfedges;
if (h.Count > 0) {
// Add points on naked edges and the naked vertex
fIndex.Add(hlookup[h.Last().Name]);
fIndex.Add(vertexPoints.Count);
fIndex.Add(hlookup[h.First().Next.Name]);
vertexPoints.Add(v.Position);
}
}
faceIndices.Add(fIndex);
}
return new ConwayPoly(vertexPoints, faceIndices.ToArray());
}
public ConwayPoly Kebab(float r = 0.3333f, float h = 0.2f) // A kebab is a mixed up gyro... Geddit?
{
var vertexPoints = new List<Vector3>();
var faceIndices = new List<IEnumerable<int>>();
// Loop through old faces
for (int i = 0; i < Faces.Count; i++)
{
var oldFace = Faces[i];
var thisFaceIndices = new List<int>();
// Loop through each vertex on old face and create a new face for each
for (int j = 0; j < oldFace.GetHalfedges().Count; j++)
{
var edges = oldFace.GetHalfedges();
vertexPoints.Add(oldFace.Centroid);
int centroidIndex = vertexPoints.Count - 1;
var seedVertex = edges[j].Vertex;
vertexPoints.Add(seedVertex.Position);
var seedVertexIndex = vertexPoints.Count - 1;
var oneThirdVertex = edges[j].Prev.OneThirdPoint;
vertexPoints.Add(oneThirdVertex);
int oneThirdIndex = vertexPoints.Count - 1;
var prevThirdVertex = edges[j].OneThirdPoint;
vertexPoints.Add(prevThirdVertex);
int prevThirdIndex = vertexPoints.Count - 1;
var prevTwoThirdVertex = edges[j].Prev.TwoThirdsPoint;
vertexPoints.Add(prevTwoThirdVertex);
int prevTwoThirdIndex = vertexPoints.Count - 1;
thisFaceIndices.Add(centroidIndex);
thisFaceIndices.Add(oneThirdIndex);
thisFaceIndices.Add(seedVertexIndex);
thisFaceIndices.Add(prevTwoThirdIndex);
thisFaceIndices.Add(prevThirdIndex);
}
faceIndices.Add(thisFaceIndices);
}
return new ConwayPoly(vertexPoints, faceIndices);
}
public ConwayPoly Gyro(float r = 0.3333f, float scale = 0.8f)
{
// Happy accidents - skip n new faces - offset just the centroid?
var vertexPoints = new List<Vector3>();
var faceIndices = new List<IEnumerable<int>>();
// Loop through old faces
for (int i = 0; i < Faces.Count; i++)
{
var oldFace = Faces[i];
// Loop through each vertex on old face and create a new face for each
for (int j = 0; j < oldFace.GetHalfedges().Count; j++)
{
var thisFaceIndices = new List<int>();
var edges = oldFace.GetHalfedges();
//vertexPoints.Add(oldFace.Centroid * (1 + scale));
vertexPoints.Add(oldFace.Centroid);
int centroidIndex = vertexPoints.Count - 1;
var seedVertex = edges[j].Vertex;
vertexPoints.Add(seedVertex.Position);
var seedVertexIndex = vertexPoints.Count - 1;
var oneThirdVertex = edges[j].OneThirdPoint;
vertexPoints.Add(oneThirdVertex);
int oneThirdIndex = vertexPoints.Count - 1;
var prevThirdVertex = edges[j].Next.TwoThirdsPoint;
vertexPoints.Add(prevThirdVertex);
int prevThirdIndex = vertexPoints.Count - 1;
var prevTwoThirdVertex = edges[j].Next.OneThirdPoint;
vertexPoints.Add(prevTwoThirdVertex);
int PrevTwoThirdIndex = vertexPoints.Count - 1;
thisFaceIndices.Add(centroidIndex);
thisFaceIndices.Add(oneThirdIndex);
thisFaceIndices.Add(seedVertexIndex);
thisFaceIndices.Add(prevThirdIndex);
thisFaceIndices.Add(PrevTwoThirdIndex);
faceIndices.Add(thisFaceIndices);
}
}
var poly = new ConwayPoly(vertexPoints, faceIndices);
//AdjustXYZ(3);
return poly;
}
/// <summary>
/// Conway's ambo operator
/// </summary>
/// <returns>the ambo as a new mesh</returns>
public ConwayPoly Ambo() {
// Create points at midpoint of unique halfedges (edges to vertices) and create lookup table
var vertexPoints = new List<Vector3>(); // vertices as points
var hlookup = new Dictionary<string, int>();
int count = 0;
foreach (var edge in Halfedges) {
// if halfedge's pair is already in the table, give it the same index
if (edge.Pair != null && hlookup.ContainsKey(edge.Pair.Name)) {
hlookup.Add(edge.Name, hlookup[edge.Pair.Name]);
} else { // otherwise create a new vertex and increment the index
hlookup.Add(edge.Name, count++);
vertexPoints.Add(edge.Midpoint);
}
}
var faceIndices = new List<IEnumerable<int>>(); // faces as vertex indices
// faces to faces
foreach (var face in Faces) {
faceIndices.Add(face.GetHalfedges().Select(edge => hlookup[edge.Name]));
}
// vertices to faces
foreach (var vertex in Vertices) {
var he = vertex.Halfedges;
if (he.Count == 0) continue; // no halfedges (naked vertex, ignore)
var list = he.Select(edge => hlookup[edge.Name]); // halfedge indices for vertex-loop
if (he[0].Next.Pair == null) {
// Handle boundary vertex, add itself and missing boundary halfedge
list = list.Concat(new[] {vertexPoints.Count, hlookup[he[0].Next.Name]});
vertexPoints.Add(vertex.Position);
}
faceIndices.Add(list);
}
return new ConwayPoly(vertexPoints, faceIndices);
}
/// <summary>
/// Conway's kis operator
/// </summary>
/// <returns>the kis as a new mesh</returns>
public ConwayPoly Kis(float offset=0, bool excludeTriangles=false) {
// vertices and faces to vertices
var newVerts = Faces.Select(f => f.Centroid + f.Normal * offset);
var vertexPoints = Enumerable.Concat(Vertices.Select(v => v.Position), newVerts);
// vertex lookup
Dictionary<string, int> vlookup = new Dictionary<string, int>();
int n = Vertices.Count;
for (int i = 0; i < n; i++) {
vlookup.Add(Vertices[i].Name, i);
}
// create new tri-faces (like a fan)
var faceIndices = new List<IEnumerable<int>>(); // faces as vertex indices
for (int i = 0; i < Faces.Count; i++) {
if (Faces[i].Sides <= 3 && excludeTriangles) {
faceIndices.Add(ListFacesByVertexIndices()[i]);
} else {
foreach (var edge in Faces[i].GetHalfedges()) {
// create new face from edge start, edge end and centroid
faceIndices.Add(
new[] {vlookup[edge.Prev.Vertex.Name], vlookup[edge.Vertex.Name], i + n}
);
}
}
}
return new ConwayPoly(vertexPoints, faceIndices);
}
/**
* Computes the "medial" polyhedron of this polyhedron. Adds vertices at the
* face centroids and edge midpoints. Each face is split into 2n triangles,
* where n is the number of vertices in the face. These triangles share a
* vertex at the face's centroid.
*
* @return The medial polyhedron.
*/
// public ConwayPoly medial() {
// return this.medial(2);
// }
// public ConwayPoly exalt() {
// return this.needle().needle();
// }
//
// public ConwayPoly yank() {
// return this.zip().zip();
// }
/**
* Computes the "chamfer" polyhedron of this polyhedron. Truncates edges
* and replaces them with hexagonal faces.
*
* @return The chamfer polyhedron.
*/
public ConwayPoly Chamfer() {
return Dual().Subdivide().Dual();
}
/**
* Computes the "subdivide" polyhedron of this polyhedron. Adds vertices at
* the midpoints of edges, and creates new triangular faces around original
* vertices. Equivalent to ambo without removing the original vertices.
*
* @return The subdivide polyhedron.
*/
public ConwayPoly Subdivide() {
var vertexPoints = Enumerable.Concat(
Vertices.Select(v => v.Position),
Halfedges.Select(e => e.Midpoint)
).ToList();
var vlookup = new Dictionary<Vector3, int>();
for (int i = 0; i < vertexPoints.Count; i++) {
vlookup[vertexPoints[i]] = i;
}
var faceIndices = new List<IEnumerable<int>>();
foreach (var face in Faces)
{
var newFace = new int[face.GetHalfedges().Count];
var list = face.GetHalfedges();
for (var index = 0; index < list.Count; index++)
{
var edge = list[index];
faceIndices.Add(
new[]
{
// Happy accident: reverse order of these
vlookup[edge.Midpoint], // Happy accident - try adding Prev instead
vlookup[edge.Vertex.Position],
vlookup[edge.Next.Midpoint]
}
);
var v = edge.Midpoint;
vertexPoints.Add(v);
newFace[index] = vertexPoints.Count - 1;
}
// faceIndices.Add(
// face.GetHalfedges().Select(e => vlookup[e.Midpoint]) // Happy accident: miss out the middle face or vertex faces
// );
faceIndices.Add(newFace);
}
return new ConwayPoly(vertexPoints, faceIndices);
}
/**
* Computes the "loft" polyhedron of this polyhedron. Adds a smaller
* version of this face, with n trapezoidal faces connecting the inner
* smaller version and the outer original version, where n is the number
* of vertices the face has.
*
* @return The loft polyhedron.
*/
// public ConwayPoly loft()
// {
// return loft(-1, true);
// }
/**
* Computes the "loft" polyhedron of this polyhedron, except only faces
* with the specified number of sides are lofted.
*
* @param n The number of sides a face needs to have loft applied to it.
* @return The polyhedron with loft applied to faces with n sides.
*/
// public ConwayPoly loft(int n)
// {
// return loft(n, false);
// }
/**
* A helper method which implements the loft operation, both the version
* parametrized on the number of sides of affected faces and the one
* without the parameter. If the "ignore" flag is set to true, every face
* is modified.
*
* @param n The number of sides a face needs to have loft applied
* to it.
* @param ignore True if we want to ignore the parameter n.
* @return The loft polyhedron.
*/
// private ConwayPoly loft(int n, bool ignore) {
// ConwayPoly loftPolyhedron = new ConwayPoly();
// foreach (var vertexPos in Vertices) {
// loftPolyhedron.Vertices.Add(vertexPos);
// }
//
// // Generate new vertices
// var newVertices = new Dictionary<Face, int[]>();
// int vertexIndex = loftPolyhedron.Vertices.Count;
// foreach (var face in Faces) {
// if (ignore || face.GetVertices().Count == n) {
// Face shrunk = new Face(face.GetVertices().Count);
// int[] newFaceVertices = new int[face.GetVertices().Count];
//
// Vector3 centroid = face.Centroid;
// for (int i = 0; i < face.GetVertices().Count; i++) {
// int index = face.getVertexIndex(i);
// var vertex = Vertices[index];
// var newVertex = VectorMath.interpolate(vertex, centroid, 0.3);
//
// loftPolyhedron.Vertices.Add(newVertex);
// newFaceVertices[i] = vertexIndex;
// shrunk.setVertexIndex(i, vertexIndex);
// vertexIndex++;
// }
//
// newVertices[face] = newFaceVertices;
// loftPolyhedron.Faces.Add(shrunk);
// }
// }
//
// // Generate new faces
// foreach (var face in Faces) {
// if (newVertices.ContainsKey(face)) {
// int[] newFaceVertices = newVertices[face];
// int prevIndex = face.getVertexIndex(face.GetVertices().Count - 1);
// int newPrevIndex = newFaceVertices[face.GetVertices().Count - 1];
// for (int i = 0; i < face.GetVertices().Count; i++) {
// int currIndex = face.getVertexIndex(i);
// int newCurrIndex = newFaceVertices[i];
//
// Face trapezoid = new Face(4);
// trapezoid.setAllVertexIndices(prevIndex, currIndex, newCurrIndex, newPrevIndex);
// loftPolyhedron.Faces.Add(trapezoid);
//
// prevIndex = currIndex;
// newPrevIndex = newCurrIndex;
// }
// } else {
// // Keep original face
// loftPolyhedron.Faces.Add(face);
// }
// }
//
// loftPolyhedron.setVertexNormalsToFaceNormals();
// return loftPolyhedron;
// }
/**
* Compute the "quinto" polyhedron of this polyhedron. Equivalent to an
* ortho but truncating the vertex at the center of original faces. This
* creates a small copy of the original face (but rotated).
*
* @return The quinto polyhedron.
*/
// public ConwayPoly quinto() {
// ConwayPoly quintoPolyhedron = new ConwayPoly();
// foreach (var vertexPos in Vertices) {
// quintoPolyhedron.Vertices.Add(vertexPos);
// }
//
// // Create new vertices at the midpoint of each edge and toward the
// // face's centroid
// var edgeToVertex = PolyhedraUtils.addEdgeToCentroidVertices(this, quintoPolyhedron);
//
// int vertexIndex = quintoPolyhedron.Vertices.Count;
// var midptVertices = new Dictionary<Halfedge, int>();
// foreach (var edge in this.Halfedges) {
// quintoPolyhedron.Vertices.Add(new Vertex(edge.Midpoint));
// midptVertices[edge] = vertexIndex++;
// }
//
// // Generate new faces
// foreach (var face in Faces) {
// Face centralFace = new Face(face.GetVertices().Count);
// var edges = face.GetHalfedges();
//
// int[] prevEnds = edges[edges.Count - 1].getEnds();
// int prevVertex = edgeToVertex[prevEnds[0]][prevEnds[1]];
// int prevMidpt = midptVertices[edges[edges.Count - 1]];
// int centralIndex = 0;
// foreach (var currEdge in edges) {
// int[] currEnds = currEdge.getEnds();
// int currVertex = edgeToVertex[currEnds[0]][currEnds[1]];
// int currMidpt = midptVertices[currEdge];
//
// Face pentagon = new Face(5);
// pentagon.setAllVertexIndices(prevVertex, prevMidpt, currEnds[0], currMidpt, currVertex);
// quintoPolyhedron.Faces.Add(pentagon);
//
// centralFace.setVertexIndex(centralIndex++, currVertex);
//
// // Update previous vertex indices
// prevVertex = currVertex;
// prevMidpt = currMidpt;
// }
// quintoPolyhedron.Faces.Add(centralFace);
// }
//
// quintoPolyhedron.setVertexNormalsToFaceNormals();
// return quintoPolyhedron;
// }
/**
* Computes the "joined-lace" polyhedron of this polyhedron. Like lace, but
* old edges are replaced by quadrilateral faces instead of two triangular
* faces.
*
* @return The joined-lace polyhedron.
*/
// public ConwayPoly joinedLace() {
// return this.lace(-1, true, true);
// }
/**
* Computes the "lace" polyhedron of this polyhedron. Like loft, but has
* on each face an antiprism of the original face instead of a prism.
*
* @return The lace polyhedron.
*/
// public ConwayPoly lace() {
// return this.lace(-1, true, false);
// }
/**
* Computes the "lace" polyhedron of this polyhedron, except the operation
* is only applied to faces with the specified number of sides.
*
* @param n The number of sides a face needs to have lace applied to it.
* @return The polyhedron with lace applied to faces with n sides.
*/
// public ConwayPoly lace(int n) {
// return this.lace(n, false, false);
// }
/**
* A helper method for implementing lace, parametrized lace, and
* joined-lace.
*
* @param n The number of sides a face needs to have lace applied
* to it.
* @param ignore True if we want to ignore the parameter n.
* @param joined True if we want to compute joined-lace.
* @return The lace polyhedron.
*/
// private ConwayPoly lace(int n, bool ignore, bool joined) {
// ConwayPoly lacePolyhedron = new ConwayPoly();
// foreach (var vertexPos in Vertices) {
// lacePolyhedron.Vertices.Add(vertexPos);
// }
//
// // Generate new vertices
// var edgeToVertex = PolyhedraUtils.addEdgeToCentroidVertices(this, lacePolyhedron);
//
// if (joined) {
// PolyhedraUtils.addRhombicFacesAtEdges(this, lacePolyhedron, edgeToVertex);
// }
//
// // Generate new faces
// foreach (var face in Faces) {
// if (ignore || face.GetVertices().Count == n) {
// Face twist = new Face(face.GetVertices().Count);
// var edges = face.GetHalfedges();
//
// for (int i = 0; i < edges.Count; i++) {
// // Build face at center of each original face
// int[] ends = edges[i].getEnds();
// int newVertex = edgeToVertex[ends[0]][ends[1]];
// twist.setVertexIndex(i, newVertex);
//
// // Always generate triangles from vertices to central face
// int nextInd = (i + 1) % edges.Count;
// int[] nextEnds = edges[nextInd].getEnds();
// int nextNewVertex = edgeToVertex[nextEnds[0]][nextEnds[1]];
//
// Face smallTriangle = new Face(3);
// smallTriangle.setAllVertexIndices(nextNewVertex, newVertex, ends[1]);
// lacePolyhedron.Faces.Add(smallTriangle);
// }
//
// lacePolyhedron.Faces.Add(twist);
//
// if (!joined) {
// // If not joined, generate triangle faces
// foreach (var edge in edges) {
// int[] ends = edge.getEnds();
// int currVertex = edgeToVertex[ends[0]][ends[1]];
//
// Face largeTriangle = new Face(3);
// largeTriangle.setAllVertexIndices(currVertex,
// ends[0], ends[1]);
//
// lacePolyhedron.Faces.Add(largeTriangle);
// }
// }
// } else {
// // Keep original face
// lacePolyhedron.Faces.Add(face);
// }
// }
//
// lacePolyhedron.setVertexNormalsToFaceNormals();
// return lacePolyhedron;
// }
/**
* Computes the "stake" polyhedron of this polyhedron. Like lace, but
* instead of having a central face, there is a central vertex and
* quadrilaterals around the center.
*
* @return The stake polyhedron.
*/
// public ConwayPoly stake() {
// return this.stake(-1, true);
// }
/**
* Computes the "stake" polyhedron of this polyhedron, but only performs
* the operation on faces with n sides.
*
* @param n The number of sides a face needs to have stake applied to it.
* @return The polyhedron with stake applied to faces with n sides.
*/
// public ConwayPoly stake(int n) {
// return this.stake(n, false);
// }
/**
* A helper method for implementing stake and parametrized stake.
*
* @param n The number of sides a face needs to have stake applied
* to it.
* @param ignore True if we want to ignore the parameter n.
* @return The stake polyhedron.
*/
// private ConwayPoly stake(int n, bool ignore) {
// ConwayPoly stakePolyhedron = new ConwayPoly();
// foreach (var vertexPos in Vertices) {
// stakePolyhedron.Vertices.Add(vertexPos);
// }
//
// // Generate new vertices
// var edgeToVertex = PolyhedraUtils.addEdgeToCentroidVertices(this, stakePolyhedron);
//
// int vertexIndex = stakePolyhedron.Vertices.Count;
// foreach (var face in Faces) {
// if (ignore || face.GetVertices().Count == n) {
// Vector3 centroid = face.Centroid;
// stakePolyhedron.Vertices.Add(new Vertex(centroid));
// int centroidIndex = vertexIndex++;
//
// var edges = face.GetHalfedges();
//
// // Generate the quads and triangles on this face
// for (int i = 0; i < edges.Count; i++) {
// int[] ends = edges[i].getEnds();
// int currVertex = edgeToVertex[ends[0]][ends[1]];
// int[] nextEnds = edges[(i + 1) % edges.Count].getEnds();
// int nextVertex = edgeToVertex[nextEnds[0]][nextEnds[1]];
//
// Face triangle = new Face(3);
// Face quad = new Face(4);
// triangle.setAllVertexIndices(currVertex, ends[0], ends[1]);
// quad.setAllVertexIndices(nextVertex, centroidIndex,
// currVertex, ends[1]);
//
// stakePolyhedron.Faces.Adds(triangle, quad);
// }
// } else {
// // Keep original face
// stakePolyhedron.Faces.Add(face);
// }
// }
//
// stakePolyhedron.setVertexNormalsToFaceNormals();
// return stakePolyhedron;
// }
/**
* Computes the "edge-medial" polyhedron of this polyhedron. Places a
* vertex at the centroid of every face, and subdivides each edge into
* n segments, with edges from these subdivision points to the centroid.
*
* For example, the "edge-medial-3" operator corresponds to n = 3.
*
* @param n The number of subdivisions on each edge.
* @return The edge-medial polyhedron with n subdivisions per edge.
*/
// public ConwayPoly edgeMedial(int n) {
// return medial(n, true);
// }
/**
* Computes the "joined-medial" polyhedron of this polyhedron. The same as
* medial, but with rhombic faces im place of original edges.
*
* @return The joined-medial polyhedron.
*/
// public ConwayPoly joinedMedial() {
// ConwayPoly medialPolyhedron = new ConwayPoly();
// foreach (var vertexPos in Vertices) {
// medialPolyhedron.Vertices.Add(vertexPos);
// }
//
// // Generate new vertices and rhombic faces on original edges
// var edgeToVertex = PolyhedraUtils.addEdgeToCentroidVertices(this, medialPolyhedron);
// PolyhedraUtils.addRhombicFacesAtEdges(this, medialPolyhedron, edgeToVertex);
//
// // Generate triangular faces
// int vertexIndex = medialPolyhedron.Vertices.Count;
// foreach (var face in faces) {
// Vector3 centroid = face.Centroid;
// medialPolyhedron.Vertices.Add(new Vertex(centroid));
//
// var edges = face.GetHalfedges();
// int[] prevEnds = edges[edges.Length - 1].getEnds();
// int prevVertex = edgeToVertex[prevEnds[0]][prevEnds[1]];
// foreach (var edge in edges) {
// int[] ends = edge.getEnds();
// int currVertex = edgeToVertex[ends[0]][ends[1]];
//
// Face triangle1 = new Face(3);
// Face triangle2 = new Face(3);
// triangle1.setAllVertexIndices(vertexIndex, ends[0], currVertex);
// triangle2.setAllVertexIndices(vertexIndex, prevVertex, ends[0]);
//
// medialPolyhedron.Faces.Adds(triangle1, triangle2);
//
// prevVertex = currVertex;
// }
//
// vertexIndex++;
// }
//
// medialPolyhedron.setVertexNormalsToFaceNormals();
// return medialPolyhedron;
// }
/**
* Generalized medial, parametrized on the number of subdivisions on each
* edge. The regular medial operation corresponds to n = 2 subdivisions.
*
* @param n The number of subdivisions on each edge.
* @return The medial polyhedron with n subdivisions per edge.
*/
// public ConwayPoly medial(int n) {
// return medial(n, false);
// }
/**
* A helper method for computing edge-medial and medial (parametrized).
*
* @param n The number of subdivisions per edge.
* @param edge True if computing edge-medial, false if regular medial.
* @return The medial polyhedron subjected to the input constraints.
*/
// private ConwayPoly medial(int n, bool edge) {
// ConwayPoly medialPolyhedron = new ConwayPoly();
// foreach (var vertexPos in Vertices) {
// medialPolyhedron.Vertices.Add(vertexPos);
// }
//
// // Create new vertices on edges
// var newVertices = PolyhedraUtils.subdivideEdges(this, medialPolyhedron, n);
//
// int vertexIndex = medialPolyhedron.Vertices.Count;