@@ -22,19 +22,21 @@ function estimate_hermite(f, v0, v1)
22
22
return (x0, ForwardDiff. gradient (f,x0))
23
23
end
24
24
25
- # Input:
26
- # f = implicit function
27
- # df = gradient of f
28
- # nc = resolution
29
- function dual_contours (f, bounds:: HyperRectangle , nc:: NTuple{3,Int} )
25
+
26
+ function dual_contours (f:: Function ,
27
+ bounds:: HyperRectangle ,
28
+ samples:: NTuple{3,Int} = (128 ,128 ,128 ),
29
+ iso= 0.0 ,
30
+ MT:: Type{M} = SimpleMesh{Point{3 ,Float64},Face{3 ,Int}},
31
+ eps= 0.00001 ) where {ST,FT,M<: AbstractMesh }
30
32
31
33
orig = origin (bounds)
32
34
width = widths (bounds)
33
- scale = width ./ Point (nc )
35
+ scale = width ./ Point (samples )
34
36
# Compute vertices
35
37
dc_verts = []
36
38
vindex = Dict ()
37
- for x in 0 : nc [1 ], y in 0 : nc [2 ], z in 0 : nc [3 ]
39
+ for x in 0 : samples [1 ], y in 0 : samples [2 ], z in 0 : samples [3 ]
38
40
idx = Point (x,y,z)
39
41
o = Point (x,y,z) .* scale + orig
40
42
@@ -69,7 +71,7 @@ function dual_contours(f, bounds::HyperRectangle, nc::NTuple{3,Int})
69
71
70
72
# Construct faces
71
73
dc_faces = Face[]
72
- for x in 0 : nc [1 ], y in 0 : nc [2 ], z in 0 : nc [3 ]
74
+ for x in 0 : samples [1 ], y in 0 : samples [2 ], z in 0 : samples [3 ]
73
75
74
76
idx = Point (x,y,z)
75
77
if ! haskey (vindex,idx)
@@ -101,6 +103,24 @@ function dual_contours(f, bounds::HyperRectangle, nc::NTuple{3,Int})
101
103
end
102
104
103
105
end
104
- return HomogenousMesh ([Point (v[1 ]. .. ) for v in dc_verts], dc_faces)
106
+ return MT ([Point (v[1 ]. .. ) for v in dc_verts], dc_faces)
107
+ end
108
+
109
+ struct DualContours{T} <: AbstractMeshingAlgorithm
110
+ iso:: T
111
+ eps:: T
112
+ end
113
+
114
+ DualContours (iso:: T1 = 0.0 , eps:: T2 = 1e-3 ) where {T1, T2} = DualContours {promote_type(T1, T2)} (iso, eps)
115
+
116
+ function (:: Type{MT} )(df:: SignedDistanceField , method:: DualContours ):: MT where {MT <: AbstractMesh }
117
+ dual_contours (df, method. iso, MT, method. eps)
118
+ end
119
+
120
+ function (:: Type{MT} )(f:: Function , h:: HyperRectangle , size:: NTuple{3,Int} , method:: DualContours ):: MT where {MT <: AbstractMesh }
121
+ dual_contours (f, h, size, method. iso, MT, method. eps)
105
122
end
106
123
124
+ function (:: Type{MT} )(f:: Function , h:: HyperRectangle , method:: DualContours ; size:: NTuple{3,Int} = (128 ,128 ,128 )):: MT where {MT <: AbstractMesh }
125
+ dual_contours (f, h, size, method. iso, MT, method. eps)
126
+ end
0 commit comments