@@ -22,19 +22,21 @@ function estimate_hermite(f, v0, v1)
2222 return (x0, ForwardDiff. gradient (f,x0))
2323end
2424
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 }
3032
3133 orig = origin (bounds)
3234 width = widths (bounds)
33- scale = width ./ Point (nc )
35+ scale = width ./ Point (samples )
3436 # Compute vertices
3537 dc_verts = []
3638 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 ]
3840 idx = Point (x,y,z)
3941 o = Point (x,y,z) .* scale + orig
4042
@@ -69,7 +71,7 @@ function dual_contours(f, bounds::HyperRectangle, nc::NTuple{3,Int})
6971
7072 # Construct faces
7173 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 ]
7375
7476 idx = Point (x,y,z)
7577 if ! haskey (vindex,idx)
@@ -101,6 +103,24 @@ function dual_contours(f, bounds::HyperRectangle, nc::NTuple{3,Int})
101103 end
102104
103105 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)
105122end
106123
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