star-2d

Contour structuring for efficient 2D geometric queries
git clone git://git.meso-star.fr/star-2d.git
Log | Files | Refs | README | LICENSE

s2d_line_segments.h (3510B)


      1 /* Copyright (C) 2016-2021, 2023 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #ifndef S2D_LINE_SEGMENTS_H
     17 #define S2D_LINE_SEGMENTS_H
     18 
     19 #include "s2d.h"
     20 
     21 #include "s2d_buffer.h"
     22 
     23 #include <rsys/dynamic_array_u32.h>
     24 #include <rsys/dynamic_array_float.h>
     25 #include <rsys/ref_count.h>
     26 
     27 /* Generate the index buffer data type */
     28 #define BUFFER_NAME index_buffer
     29 #define BUFFER_DARRAY darray_u32
     30 #include "s2d_buffer.h"
     31 
     32 /* Generate the vertex buffer data type */
     33 #define BUFFER_NAME vertex_buffer
     34 #define BUFFER_DARRAY darray_float
     35 #include "s2d_buffer.h"
     36 
     37 enum buffer_type {
     38   INDEX_BUFFER = BIT(0),
     39   VERTEX_BUFFER = BIT(1)
     40 };
     41 
     42 /* Filter function and its associated user defined data */
     43 struct hit_filter {
     44   s2d_hit_filter_function_T func;
     45   void* data;
     46 };
     47 
     48 struct line_segments { /* Segmented contour */
     49   struct index_buffer* indices;
     50   struct vertex_buffer* attribs[S2D_ATTRIBS_COUNT__];
     51   enum s2d_type attribs_type[S2D_ATTRIBS_COUNT__];
     52   struct darray_float cdf;
     53   struct hit_filter filter;
     54 
     55   int resize_mask; /* Combination of buffer_type */
     56   int update_mask; /* Combination of buffer_type */
     57   struct s2d_device* dev;
     58   ref_T ref;
     59 };
     60 
     61 extern LOCAL_SYM res_T
     62 line_segments_create
     63   (struct s2d_device* dev,
     64    struct line_segments** lines);
     65 
     66 extern LOCAL_SYM void
     67 line_segments_ref_get
     68   (struct line_segments* lines);
     69 
     70 extern LOCAL_SYM void
     71 line_segments_ref_put
     72   (struct line_segments* lines);
     73 
     74 extern LOCAL_SYM void
     75 line_segments_clear
     76   (struct line_segments* lines);
     77 
     78 extern LOCAL_SYM size_t
     79 line_segments_get_nsegments
     80   (const struct line_segments* lines);
     81 
     82 extern LOCAL_SYM size_t
     83 line_segments_get_nverts
     84   (const struct line_segments* lines);
     85 
     86 extern LOCAL_SYM uint32_t*
     87 line_segments_get_ids
     88   (struct line_segments* lines);
     89 
     90 extern LOCAL_SYM float*
     91 line_segments_get_pos
     92   (struct line_segments* lines);
     93 
     94 extern LOCAL_SYM float*
     95 line_segments_get_attr
     96   (struct line_segments* lines,
     97    const enum s2d_attrib_usage usage);
     98 
     99 /* Compute line segments Cumulative Distribution Function */
    100 extern LOCAL_SYM res_T
    101 line_segments_compute_cdf
    102   (struct line_segments* line);
    103 
    104 extern LOCAL_SYM float
    105 line_segments_compute_length
    106   (struct line_segments* lines);
    107 
    108 extern LOCAL_SYM float
    109 line_segments_compute_area
    110   (struct line_segments* lines,
    111    const char flip_contour);
    112 
    113 extern LOCAL_SYM res_T
    114 line_segments_setup_indexed_vertices
    115   (struct line_segments* lines,
    116    const unsigned ntris,
    117    void (*get_indices)(const unsigned isegment, unsigned ids[2], void* ctx),
    118    const unsigned nverts,
    119    struct s2d_vertex_data attribs[],
    120    const unsigned nattribs,
    121    void* data);
    122 
    123 extern LOCAL_SYM void
    124 line_segments_compute_aabb
    125   (struct line_segments* lines,
    126    float lower[2],
    127    float upper[2]);
    128 
    129 extern LOCAL_SYM void
    130 line_segments_copy_indexed_vertices
    131   (const struct line_segments* src,
    132    struct line_segments* dst);
    133 
    134 #endif /* S2D_LINE_SEGMENTS_H */
    135