Skip to content

Commit 420815d

Browse files
committed
Add some basic provenance tracking for triangles
1 parent a13d8fb commit 420815d

File tree

6 files changed

+105
-60
lines changed

6 files changed

+105
-60
lines changed

Graphics/Implicit/Definitions.hs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module Graphics.Implicit.Definitions (
2727
Triangle(Triangle),
2828
NormedTriangle(NormedTriangle),
2929
TriangleMesh(TriangleMesh),
30+
AnnotatedTriangleMesh(AnnotatedTriangleMesh, unAnnotatedTriangleMesh),
31+
TriangleProvenance(..),
3032
NormedTriangleMesh(NormedTriangleMesh),
3133
Obj2,
3234
Obj3,
@@ -64,12 +66,13 @@ module Graphics.Implicit.Definitions (
6466
toScaleFn,
6567
isScaleID,
6668
quaternionToEuler,
69+
removeTriangleMeshAnnotations,
6770
)
6871
where
6972

7073
import GHC.Generics (Generic)
7174

72-
import Prelude (Ord, Eq, atan2, asin, pi, (>=), signum, abs, (+), (-), RealFloat, (==), ($), flip, Semigroup((<>)), Monoid (mempty), Double, Either(Left, Right), Bool(True, False), (*), (/), fromIntegral, Float, realToFrac)
75+
import Prelude (Ord, Eq, atan2, asin, pi, (>=), signum, abs, (+), (-), RealFloat, (==), ($), flip, Semigroup((<>)), Monoid (mempty), Double, Either(Left, Right), Bool(True, False), (*), (/), fromIntegral, Float, realToFrac, map, fst, Int, seq)
7376

7477
import Graphics.Implicit.FastIntUtil as F (Fastℕ(Fastℕ), fromFastℕ, toFastℕ)
7578

@@ -162,6 +165,18 @@ newtype NormedTriangle = NormedTriangle ((ℝ3, ℝ3), (ℝ3, ℝ3), (ℝ3, ℝ3
162165
-- | A triangle mesh is a bunch of triangles, attempting to be a surface.
163166
newtype TriangleMesh = TriangleMesh [Triangle]
164167

168+
newtype AnnotatedTriangleMesh a = AnnotatedTriangleMesh { unAnnotatedTriangleMesh :: [(Triangle, a)] }
169+
170+
removeTriangleMeshAnnotations :: AnnotatedTriangleMesh a -> TriangleMesh
171+
removeTriangleMeshAnnotations (AnnotatedTriangleMesh l) = TriangleMesh $ map fst l
172+
173+
data TriangleProvenance
174+
= TriangleProvenance_SquareToTri Bool TriangleProvenance
175+
| TriangleProvenance_JoinXAligned TriangleProvenance TriangleProvenance
176+
| TriangleProvenance_JoinYAligned TriangleProvenance TriangleProvenance
177+
| TriangleProvenance_TesselateLoop Int
178+
deriving (Show, Eq, Ord)
179+
165180
-- | A normed triangle mesh is a mesh of normed triangles.
166181
newtype NormedTriangleMesh = NormedTriangleMesh [NormedTriangle]
167182

@@ -174,6 +189,15 @@ instance NFData Triangle where
174189
instance NFData TriangleMesh where
175190
rnf (TriangleMesh xs) = rnf xs
176191

192+
instance NFData a => NFData (AnnotatedTriangleMesh a) where
193+
rnf (AnnotatedTriangleMesh xs) = rnf xs
194+
195+
instance NFData TriangleProvenance where
196+
rnf (TriangleProvenance_SquareToTri b p) = rnf b `seq` rnf p
197+
rnf (TriangleProvenance_JoinXAligned a b) = rnf a `seq` rnf b
198+
rnf (TriangleProvenance_JoinYAligned a b) = rnf a `seq` rnf b
199+
rnf (TriangleProvenance_TesselateLoop n) = rnf n
200+
177201
instance NFData Polytri where
178202
rnf (Polytri (a,b,c)) = rnf (a,b,c)
179203

Graphics/Implicit/Export/Render.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
{-# LANGUAGE ParallelListComp #-}
77

88
-- export getContour and getMesh, which returns the edge of a 2D object, or the surface of a 3D object, respectively.
9-
module Graphics.Implicit.Export.Render (getMesh, getContour) where
9+
module Graphics.Implicit.Export.Render (getMesh, getAnnotatedMesh, getContour) where
1010

1111
import Prelude(error, (-), ceiling, ($), (+), (*), max, div, tail, fmap, reverse, (.), foldMap, min, Int, (<>), (<$>))
1212

13-
import Graphics.Implicit.Definitions (, , Fastℕ, ℝ2, ℝ3, TriangleMesh, Obj2, SymbolicObj2, Obj3, SymbolicObj3, Polyline(Polyline), (⋯/), fromℕtoℝ, fromℕ)
13+
import Graphics.Implicit.Definitions (, , Fastℕ, ℝ2, ℝ3, TriangleMesh, Obj2, SymbolicObj2, Obj3, SymbolicObj3, Polyline(Polyline), (⋯/), fromℕtoℝ, fromℕ, AnnotatedTriangleMesh, removeTriangleMeshAnnotations, TriangleProvenance(..))
1414

1515
import Graphics.Implicit.Export.Symbolic.Rebound2 (rebound2)
1616

@@ -21,6 +21,8 @@ import Graphics.Implicit.ObjectUtil (getBox2, getBox3)
2121
import Data.Foldable(fold)
2222
import Linear ( V3(V3), V2(V2) )
2323

24+
import GHC.Stack
25+
2426
-- Here's the plan for rendering a cube (the 2D case is trivial):
2527

2628
-- (1) We calculate midpoints using interpolate.
@@ -75,7 +77,10 @@ import Graphics.Implicit.Primitives (getImplicit)
7577
default (, Fastℕ, )
7678

7779
getMesh :: ℝ3 -> SymbolicObj3 -> TriangleMesh
78-
getMesh res@(V3 xres yres zres) symObj =
80+
getMesh res symObj = removeTriangleMeshAnnotations $ getAnnotatedMesh res symObj
81+
82+
getAnnotatedMesh :: ℝ3 -> SymbolicObj3 -> AnnotatedTriangleMesh TriangleProvenance
83+
getAnnotatedMesh res@(V3 xres yres zres) symObj =
7984
let
8085
-- Grow bounds a little to avoid sampling at exact bounds
8186
(obj, (p1@(V3 x1 y1 z1), p2)) = rebound3 (getImplicit symObj, getBox3 symObj)

Graphics/Implicit/Export/Render/Definitions.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
-- Released under the GNU AGPLV3+, see LICENSE
33

44
-- We want a type that can represent squares/quads and triangles.
5-
module Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris, Sq)) where
5+
module Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris, Sq), AnnotatedTriSquare(AnnotatedSq, AnnotatedTris)) where
6+
7+
import Prelude (seq)
68

79
-- Points/Numbers, and the concept of an array of triangles.
8-
import Graphics.Implicit.Definitions(, ℝ2, ℝ3, TriangleMesh)
10+
import Graphics.Implicit.Definitions(, ℝ2, ℝ3, TriangleMesh, AnnotatedTriangleMesh)
911

1012
-- So we can use Parallel on this type.
1113
import Control.DeepSeq (NFData, rnf)
@@ -14,7 +16,14 @@ data TriSquare =
1416
Sq (ℝ3,ℝ3,ℝ3) ℝ2 ℝ2
1517
| Tris TriangleMesh
1618

19+
data AnnotatedTriSquare a =
20+
AnnotatedSq (ℝ3,ℝ3,ℝ3) ℝ2 ℝ2 a
21+
| AnnotatedTris (AnnotatedTriangleMesh a)
22+
1723
instance NFData TriSquare where
1824
rnf (Sq b z xS yS) = rnf (b,z,xS,yS)
1925
rnf (Tris tris) = rnf tris
2026

27+
instance NFData a => NFData (AnnotatedTriSquare a) where
28+
rnf (AnnotatedSq b z xS yS a) = rnf (b,z,xS,yS) `seq` rnf a
29+
rnf (AnnotatedTris tris) = rnf tris

Graphics/Implicit/Export/Render/HandleSquares.hs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
module Graphics.Implicit.Export.Render.HandleSquares (mergedSquareTris) where
66

7-
import Prelude((+), foldMap, (<>), ($), fmap, concat, (.), (==), compare, error, otherwise, concatMap)
7+
import Prelude((+), foldMap, (<>), ($), fmap, concat, (.), (==), compare, error, otherwise, concatMap, Bool(..))
88

9-
import Graphics.Implicit.Definitions (TriangleMesh(TriangleMesh), Triangle(Triangle))
9+
import Graphics.Implicit.Definitions (TriangleMesh(TriangleMesh), Triangle(Triangle), AnnotatedTriangleMesh (AnnotatedTriangleMesh, unAnnotatedTriangleMesh), TriangleProvenance(..))
1010

11-
import Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris, Sq))
11+
import Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris, Sq), AnnotatedTriSquare(AnnotatedTris, AnnotatedSq))
1212
import Linear ( V2(V2), (*^), (^*) )
1313

1414
import GHC.Exts (groupWith)
@@ -57,75 +57,75 @@ import Data.List (sortBy)
5757
5858
-}
5959

60-
mergedSquareTris :: [TriSquare] -> TriangleMesh
60+
mergedSquareTris :: [AnnotatedTriSquare TriangleProvenance] -> AnnotatedTriangleMesh TriangleProvenance
6161
mergedSquareTris sqTris =
6262
let
6363
-- We don't need to do any work on triangles. They'll just be part of
6464
-- the list of triangles we give back. So, the triangles coming from
6565
-- triangles...
66-
triTriangles :: [Triangle]
67-
triTriangles = [tri | Tris tris <- sqTris, tri <- unmesh tris ]
66+
triTriangles :: [(Triangle, TriangleProvenance)]
67+
triTriangles = [tri | AnnotatedTris tris <- sqTris, tri <- unAnnotatedTriangleMesh tris ]
6868
-- We actually want to work on the quads, so we find those
69-
squaresFromTris :: [TriSquare]
70-
squaresFromTris = [ Sq x y z q | Sq x y z q <- sqTris ]
69+
squaresFromTris :: [AnnotatedTriSquare TriangleProvenance]
70+
squaresFromTris = [ AnnotatedSq x y z q a | AnnotatedSq x y z q a <- sqTris ]
7171

7272
unmesh (TriangleMesh m) = m
7373

7474
-- Collect squares that are on the same plane.
75-
planeAligned = groupWith (\(Sq basis z _ _) -> (basis,z)) squaresFromTris
75+
planeAligned = groupWith (\(AnnotatedSq basis z _ _ a) -> (basis,z,a)) squaresFromTris
7676
-- For each plane:
7777
-- Select for being the same range on X and then merge them on Y
7878
-- Then vice versa.
79-
joined :: [[TriSquare]]
79+
joined :: [[AnnotatedTriSquare TriangleProvenance]]
8080
joined = fmap
81-
( concatMap joinXaligned . groupWith (\(Sq _ _ xS _) -> xS)
82-
. concatMap joinYaligned . groupWith (\(Sq _ _ _ yS) -> yS)
83-
. concatMap joinXaligned . groupWith (\(Sq _ _ xS _) -> xS))
81+
( concatMap joinXaligned . groupWith (\(AnnotatedSq _ _ xS _ _) -> xS)
82+
. concatMap joinYaligned . groupWith (\(AnnotatedSq _ _ _ yS _) -> yS)
83+
. concatMap joinXaligned . groupWith (\(AnnotatedSq _ _ xS _ _) -> xS))
8484
planeAligned
8585
-- Merge them back together, and we have the desired reult!
8686
finishedSquares = concat joined
8787

8888
in
8989
-- merge them to triangles, and combine with the original triangles.
90-
TriangleMesh $ triTriangles <> foldMap squareToTri finishedSquares
90+
AnnotatedTriangleMesh $ triTriangles <> foldMap squareToTri finishedSquares
9191

9292
-- And now for the helper functions that do the heavy lifting...
9393

94-
joinXaligned :: [TriSquare] -> [TriSquare]
95-
joinXaligned quads@((Sq b z xS _):_) =
94+
joinXaligned :: [AnnotatedTriSquare TriangleProvenance] -> [AnnotatedTriSquare TriangleProvenance]
95+
joinXaligned quads@((AnnotatedSq b z xS _ _):_) =
9696
let
9797
orderedQuads = sortBy
98-
(\(Sq _ _ _ (V2 ya _)) (Sq _ _ _ (V2 yb _)) -> compare ya yb)
98+
(\(AnnotatedSq _ _ _ (V2 ya _) _) (AnnotatedSq _ _ _ (V2 yb _) _) -> compare ya yb)
9999
quads
100-
mergeAdjacent (pres@(Sq _ _ _ (V2 y1a y2a)) : next@(Sq _ _ _ (V2 y1b y2b)) : others)
101-
| y2a == y1b = mergeAdjacent (Sq b z xS (V2 y1a y2b) : others)
102-
| y1a == y2b = mergeAdjacent (Sq b z xS (V2 y1b y2a) : others)
100+
mergeAdjacent (pres@(AnnotatedSq _ _ _ (V2 y1a y2a) a1) : next@(AnnotatedSq _ _ _ (V2 y1b y2b) a2) : others)
101+
| y2a == y1b = mergeAdjacent (AnnotatedSq b z xS (V2 y1a y2b) (TriangleProvenance_JoinXAligned a1 a2) : others)
102+
| y1a == y2b = mergeAdjacent (AnnotatedSq b z xS (V2 y1b y2a) (TriangleProvenance_JoinXAligned a1 a2) : others)
103103
| otherwise = pres : mergeAdjacent (next : others)
104104
mergeAdjacent a = a
105105
in
106106
mergeAdjacent orderedQuads
107-
joinXaligned (Tris _:_) = error "Tried to join y aligned triangles."
107+
joinXaligned (AnnotatedTris _:_) = error "Tried to join y aligned triangles."
108108
joinXaligned [] = []
109109

110-
joinYaligned :: [TriSquare] -> [TriSquare]
111-
joinYaligned quads@((Sq b z _ yS):_) =
110+
joinYaligned :: [AnnotatedTriSquare TriangleProvenance] -> [AnnotatedTriSquare TriangleProvenance]
111+
joinYaligned quads@((AnnotatedSq b z _ yS _):_) =
112112
let
113113
orderedQuads = sortBy
114-
(\(Sq _ _ (V2 xa _) _) (Sq _ _ (V2 xb _) _) -> compare xa xb)
114+
(\(AnnotatedSq _ _ (V2 xa _) _ _) (AnnotatedSq _ _ (V2 xb _) _ _) -> compare xa xb)
115115
quads
116-
mergeAdjacent (pres@(Sq _ _ (V2 x1a x2a) _) : next@(Sq _ _ (V2 x1b x2b) _) : others)
117-
| x2a == x1b = mergeAdjacent (Sq b z (V2 x1a x2b) yS : others)
118-
| x1a == x2b = mergeAdjacent (Sq b z (V2 x1b x2a) yS : others)
116+
mergeAdjacent (pres@(AnnotatedSq _ _ (V2 x1a x2a) _ a1) : next@(AnnotatedSq _ _ (V2 x1b x2b) _ a2) : others)
117+
| x2a == x1b = mergeAdjacent (AnnotatedSq b z (V2 x1a x2b) yS (TriangleProvenance_JoinYAligned a1 a2) : others)
118+
| x1a == x2b = mergeAdjacent (AnnotatedSq b z (V2 x1b x2a) yS (TriangleProvenance_JoinYAligned a1 a2) : others)
119119
| otherwise = pres : mergeAdjacent (next : others)
120120
mergeAdjacent a = a
121121
in
122122
mergeAdjacent orderedQuads
123-
joinYaligned (Tris _:_) = error "Tried to join y aligned triangles."
123+
joinYaligned (AnnotatedTris _:_) = error "Tried to join y aligned triangles."
124124
joinYaligned [] = []
125125

126126
-- Deconstruct a square into two triangles.
127-
squareToTri :: TriSquare -> [Triangle]
128-
squareToTri (Sq (b1,b2,b3) z (V2 x1 x2) (V2 y1 y2)) =
127+
squareToTri :: AnnotatedTriSquare TriangleProvenance -> [(Triangle, TriangleProvenance)]
128+
squareToTri (AnnotatedSq (b1,b2,b3) z (V2 x1 x2) (V2 y1 y2) ann) =
129129
let
130130
zV = b3 ^* z
131131
(x1V, x2V) = (x1 *^ b1, x2 *^ b1)
@@ -135,8 +135,8 @@ squareToTri (Sq (b1,b2,b3) z (V2 x1 x2) (V2 y1 y2)) =
135135
c = zV + x1V + y2V
136136
d = zV + x2V + y2V
137137
in
138-
[Triangle (a,b,c), Triangle (c,b,d)]
139-
squareToTri (Tris t) = unmesh t
138+
[(Triangle (a,b,c), TriangleProvenance_SquareToTri False ann), (Triangle (c,b,d), TriangleProvenance_SquareToTri True ann)]
139+
squareToTri (AnnotatedTris t) = unmesh t
140140
where
141-
unmesh (TriangleMesh a) = a
141+
unmesh (AnnotatedTriangleMesh a) = a
142142

Graphics/Implicit/Export/Render/TesselateLoops.hs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module Graphics.Implicit.Export.Render.TesselateLoops (tesselateLoop) where
66

77
import Prelude(sum, (-), pure, ($), length, (==), zip, init, tail, reverse, (<), (/), null, (<>), head, (*), abs, (>), (&&), (+), foldMap)
88

9-
import Graphics.Implicit.Definitions (, , Obj3, ℝ3, TriangleMesh(TriangleMesh), Triangle(Triangle))
9+
import Graphics.Implicit.Definitions (, , Obj3, ℝ3, TriangleMesh(TriangleMesh), Triangle(Triangle), AnnotatedTriangleMesh(AnnotatedTriangleMesh), TriangleProvenance(..))
1010

11-
import Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris))
11+
import Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris), AnnotatedTriSquare(AnnotatedTris))
1212

1313
import Graphics.Implicit.Export.Util (centroid)
1414

@@ -17,11 +17,11 @@ import Linear ( cross, Metric(norm), (^*), (^/) )
1717

1818
-- de-compose a loop into a series of triangles or squares.
1919
-- FIXME: res should be ℝ3.
20-
tesselateLoop :: -> Obj3 -> [[ℝ3]] -> [TriSquare]
20+
tesselateLoop :: -> Obj3 -> [[ℝ3]] -> [AnnotatedTriSquare TriangleProvenance]
2121

2222
tesselateLoop _ _ [] = []
2323

24-
tesselateLoop _ _ [[a,b],[_,c],[_,_]] = [Tris $ TriangleMesh [Triangle (a,b,c)]]
24+
tesselateLoop _ _ [[a,b],[_,c],[_,_]] = [AnnotatedTris $ AnnotatedTriangleMesh [(Triangle (a,b,c), TriangleProvenance_TesselateLoop 0)]]
2525

2626

2727
{-
@@ -67,12 +67,12 @@ tesselateLoop _ _ [[a,_],[b,_],[c,_],[d,_]] | centroid [a,c] == centroid [b,d] =
6767
-- | Create a pair of triangles from a quad.
6868
-- FIXME: magic number
6969
tesselateLoop res obj [[a,_],[b,_],[c,_],[d,_]] | obj (centroid [a,c]) < res/30 =
70-
pure $ Tris $ TriangleMesh [Triangle (a,b,c), Triangle (a,c,d)]
70+
pure $ AnnotatedTris $ AnnotatedTriangleMesh [(Triangle (a,b,c), TriangleProvenance_TesselateLoop 1), (Triangle (a,c,d), TriangleProvenance_TesselateLoop 2)]
7171

7272
-- Fallback case: make fans
7373

7474
-- FIXME: magic numbers.
75-
tesselateLoop res obj pathSides = pure $ Tris $ TriangleMesh $
75+
tesselateLoop res obj pathSides = pure $ AnnotatedTris $ AnnotatedTriangleMesh $
7676
let
7777
path' = foldMap init pathSides
7878
(early_tris,path) = shrinkLoop 0 path' res obj
@@ -89,16 +89,16 @@ tesselateLoop res obj pathSides = pure $ Tris $ TriangleMesh $
8989
mid' = mid - normal ^* (midval/deriv)
9090
midval' = obj mid'
9191
in if abs midval' < abs midval
92-
then early_tris <> [Triangle (a,b,mid') | (a,b) <- zip path (tail path <> [head path]) ]
93-
else early_tris <> [Triangle (a,b,mid) | (a,b) <- zip path (tail path <> [head path]) ]
92+
then early_tris <> [(Triangle (a,b,mid'), TriangleProvenance_TesselateLoop 3) | (a,b) <- zip path (tail path <> [head path]) ]
93+
else early_tris <> [(Triangle (a,b,mid), TriangleProvenance_TesselateLoop 4) | (a,b) <- zip path (tail path <> [head path]) ]
9494

9595

96-
shrinkLoop :: -> [ℝ3] -> -> Obj3 -> ([Triangle], [ℝ3])
96+
shrinkLoop :: -> [ℝ3] -> -> Obj3 -> ([(Triangle, TriangleProvenance)], [ℝ3])
9797

9898
shrinkLoop _ path@[a,b,c] res obj =
9999
if abs (obj $ centroid [a,b,c]) < res/50
100100
then
101-
( [Triangle (a,b,c)], [])
101+
( [(Triangle (a,b,c), TriangleProvenance_TesselateLoop 5)], [])
102102
else
103103
([], path)
104104

@@ -107,7 +107,7 @@ shrinkLoop n path@(a:b:c:xs) res obj | n < genericLength path =
107107
if abs (obj (centroid [a,c])) < res/50
108108
then
109109
let (tris,remainder) = shrinkLoop 0 (a:c:xs) res obj
110-
in (Triangle (a,b,c):tris, remainder)
110+
in ((Triangle (a,b,c), TriangleProvenance_TesselateLoop 6):tris, remainder)
111111
else
112112
shrinkLoop (n+1) (b:c:xs <> [a]) res obj
113113

Graphics/Implicit/Export/SymbolicObj3.hs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@
55
-- The purpose of this function is to symbolicaly compute triangle meshes using the symbolic system where possible.
66
-- Otherwise we coerce it into an implicit function and apply our modified marching cubes algorithm.
77

8-
module Graphics.Implicit.Export.SymbolicObj3 (symbolicGetMesh) where
8+
module Graphics.Implicit.Export.SymbolicObj3 (symbolicGetMesh, symbolicGetAnnotatedMesh) where
99

10-
import Prelude(pure, zip, length, filter, (>), ($), null, (<>), foldMap, (.), (<$>))
10+
import Prelude(pure, zip, length, filter, (>), ($), null, (<>), foldMap, (.), (<$>), unlines, zipWith, show, map, snd)
1111

12-
import Graphics.Implicit.Definitions (, ℝ3, SymbolicObj3(Shared3), SharedObj(UnionR), Triangle, TriangleMesh(TriangleMesh))
13-
import Graphics.Implicit.Export.Render (getMesh)
12+
import Graphics.Implicit.Definitions (, ℝ3, SymbolicObj3(Shared3), SharedObj(UnionR), Triangle, TriangleMesh(TriangleMesh), AnnotatedTriangleMesh(AnnotatedTriangleMesh,unAnnotatedTriangleMesh), removeTriangleMeshAnnotations, TriangleProvenance)
13+
import Graphics.Implicit.Export.Render (getAnnotatedMesh)
1414
import Graphics.Implicit.ObjectUtil (getBox3)
1515
import Graphics.Implicit.MathUtil(box3sWithin)
1616

1717
import Control.Arrow(first, second)
1818

19+
import Debug.Trace
20+
1921
symbolicGetMesh :: -> SymbolicObj3 -> TriangleMesh
20-
symbolicGetMesh res inputObj@(Shared3 (UnionR r objs)) = TriangleMesh $
22+
symbolicGetMesh res inputObj = removeTriangleMeshAnnotations $ trace annotations mesh
23+
where mesh = symbolicGetAnnotatedMesh res inputObj
24+
annotations = unlines $ zipWith (\n a -> show n <> "\t" <> show a) [1..] $ map snd $ unAnnotatedTriangleMesh mesh
25+
26+
symbolicGetAnnotatedMesh :: -> SymbolicObj3 -> AnnotatedTriangleMesh TriangleProvenance
27+
symbolicGetAnnotatedMesh res inputObj@(Shared3 (UnionR r objs)) = AnnotatedTriangleMesh $
2128
let
2229
boxes = getBox3 <$> objs
2330
boxedObjs = zip boxes objs
@@ -31,14 +38,14 @@ symbolicGetMesh res inputObj@(Shared3 (UnionR r objs)) = TriangleMesh $
3138

3239
(dependants, independents) = sepFree boxedObjs
3340
in if null independents
34-
then unmesh $ getMesh (pure res) inputObj
41+
then unAnnotatedTriangleMesh $ getAnnotatedMesh (pure res) inputObj
3542
else if null dependants
36-
then foldMap (unmesh . symbolicGetMesh res) independents
37-
else foldMap (unmesh . symbolicGetMesh res) independents
38-
<> unmesh (symbolicGetMesh res (Shared3 (UnionR r dependants)))
43+
then foldMap (unAnnotatedTriangleMesh . symbolicGetAnnotatedMesh res) independents
44+
else foldMap (unAnnotatedTriangleMesh . symbolicGetAnnotatedMesh res) independents
45+
<> unAnnotatedTriangleMesh (symbolicGetAnnotatedMesh res (Shared3 (UnionR r dependants)))
3946

4047
-- | If all that fails, coerce and apply marching cubes :(
41-
symbolicGetMesh res obj = getMesh (pure res) obj
48+
symbolicGetAnnotatedMesh res obj = getAnnotatedMesh (pure res) obj
4249

4350
unmesh :: TriangleMesh -> [Triangle]
4451
unmesh (TriangleMesh m) = m

0 commit comments

Comments
 (0)