@@ -203,7 +203,10 @@ def draw_ray_curve_and_intersections(
203203 filename : str ,
204204) -> None :
205205 """
206- Draws rays, curves, and intersections on an image and saves it.
206+ Draws rays, curves, and intersections on an image and saves it.<br>
207+ Rays are blue.<br>
208+ Curves are green.<br>
209+ Intersection points are red.
207210
208211 Args:
209212 dots_lists (List[Node]): List of nodes representing intersections.
@@ -230,6 +233,7 @@ def draw_ray_curve_and_intersections(
230233def sampling_edges (
231234 l_ch_f : List [Curve ],
232235 img_pre : np .ndarray ,
236+ img_in : np .ndarray ,
233237) -> Tuple [List [Chain ], List [Node ], int ]:
234238 """
235239 Samples Devernay curves using ray directions. Implements Algorithm 6 in the supplementary material.
@@ -248,35 +252,40 @@ def sampling_edges(
248252 center = (config .cy , config .cx )
249253
250254 # Build rays from the center using the configured number of rays (config.nr)
251- l_rays = build_rays (height , width , center )
255+ rays = build_rays (height , width , center )
252256
253257 # Compute intersections between rays and curves, returning nodes and chains.
254258 l_nodes_s , l_ch_s = intersections_between_rays_and_devernay_curves (
255- l_rays , l_ch_f , center , height , width
259+ rays , l_ch_f , center , height , width
256260 )
257- generate_virtual_center_chain (l_ch_s , l_nodes_s , height , width )
258261
259- # Calculate average ring count based on intersections along the rays.
260- counts = []
261- for ray in l_rays :
262- count = 0
263- for curve in l_ch_f :
264- if ray .geometry .intersects (curve .geometry ):
265- inter = ray .geometry .intersection (curve .geometry )
266- if not inter .is_empty :
267- count += 1
268- counts .append (count )
269- average_ring_count = int (round (np .mean (counts ))) if counts else 0
262+ # Compute average ring count based on the number of intersection points (nodes) per ray
263+ average_ring_count = len (l_nodes_s ) / config .nr if l_nodes_s else 0
264+ average_ring_count = int (round (average_ring_count ))
265+
266+ # call by reference, modifies the list of chains and nodes
267+ generate_virtual_center_chain (l_ch_s , l_nodes_s , height , width )
270268
271269 # Debug purposes, not illustrated in the paper
272270 if config .debug :
273271 img_draw = np .zeros ((height , width , 3 ), dtype = np .uint8 )
272+
273+ # save with empty background
274274 draw_ray_curve_and_intersections (
275275 l_nodes_s ,
276- l_rays ,
276+ rays ,
277277 l_ch_f ,
278278 img_draw ,
279279 f"{ config .output_dir } /dots_curve_and_rays.png" ,
280280 )
281281
282+ # save with preprocess image
283+ draw_ray_curve_and_intersections (
284+ l_nodes_s ,
285+ rays ,
286+ l_ch_f ,
287+ img_in ,
288+ f"{ config .output_dir } /dots_curve_and_rays_pre.png" ,
289+ )
290+
282291 return l_ch_s , l_nodes_s , average_ring_count
0 commit comments