star-camera

Camera models
git clone git://git.meso-star.fr/star-camera.git
Log | Files | Refs | README | LICENSE

scam.h (5917B)


      1 /* Copyright (C) 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 SCAM_H
     17 #define SCAM_H
     18 
     19 #include <rsys/rsys.h>
     20 
     21 /* Library symbol management */
     22 #if defined(SCAM_SHARED_BUILD) /* Build shared library */
     23   #define SCAM_API extern EXPORT_SYM
     24 #elif defined(SCAM_STATIC) /* Use/build static library */
     25   #define SCAM_API extern LOCAL_SYM
     26 #else /* Use shared library */
     27   #define SCAM_API extern IMPORT_SYM
     28 #endif
     29 
     30 /* Helper macro that asserts if the invocation of the suvm function `Func'
     31  * returns an error. One should use this macro on scam function calls for
     32  * which no explicit error checking is performed */
     33 #ifndef NDEBUG
     34   #define SCAM(Func) ASSERT(scam_ ## Func == RES_OK)
     35 #else
     36   #define SCAM(Func) scam_ ## Func
     37 #endif
     38 
     39 enum scam_type {
     40   SCAM_ORTHOGRAPHIC,
     41   SCAM_PERSPECTIVE,
     42   SCAM_TYPES_COUNT__,
     43   SCAM_NONE = SCAM_TYPES_COUNT__
     44 };
     45 
     46 /* Samples used to generate a camera ray */
     47 struct scam_sample {
     48   double film[2]; /* Samples on the image plane in [0, 1[^2 */
     49   double lens[2]; /* Samples on the lens */
     50 };
     51 #define SCAM_SAMPLE_NULL__ {{0,0},{0,0}}
     52 static const struct scam_sample SCAM_SAMPLE_NULL = SCAM_SAMPLE_NULL__;
     53 
     54 struct scam_ray {
     55   double org[3];
     56   double dir[3];
     57 };
     58 #define SCAM_RAY_NULL__ {{0,0,0},{0,0,0}}
     59 static const struct scam_ray SCAM_RAY_NULL = SCAM_RAY_NULL__;
     60 
     61 struct scam_orthographic_args {
     62   double position[3]; /* Lens position */
     63   double target[3]; /* Targeted point. target-position = image plane normal */
     64   double up[3]; /* Vector defining the upward orientation */
     65   double height; /* Height of the image plane */
     66   double aspect_ratio;  /* Image plane aspect ratio (width / height) */
     67 };
     68 #define SCAM_ORTHOGRAPHIC_ARGS_DEFAULT__ {                                     \
     69   {0,0,0}, /* Position */                                                      \
     70   {0,1,0}, /* Target */                                                        \
     71   {0,0,1}, /* Up */                                                            \
     72   1.0, /* Height of the image plane */                                         \
     73   1.0, /* Aspect ratio */                                                      \
     74 }
     75 static const struct scam_orthographic_args SCAM_ORTHOGRAPHIC_ARGS_DEFAULT =
     76   SCAM_ORTHOGRAPHIC_ARGS_DEFAULT__;
     77 
     78 struct scam_perspective_args {
     79   double position[3]; /* Lens position */
     80   double target[3]; /* Targeted point. target-position = image plane normal */
     81   double up[3]; /* Vector defining the upward orientation */
     82   double aspect_ratio; /* Image plane aspect ratio (width / height) */
     83   double lens_radius; /* Radius of 0 <=> pinhole */
     84 
     85   /* Vertical field of view in radians. It indirectly defined the focal length*/
     86   double field_of_view;
     87 
     88   /* Distance to focus on. Used when lens_radius != 0. Note that the focal
     89    * distance is not the focal length that is the distance to the focal point
     90    * behind the lens */
     91   double focal_distance;
     92 };
     93 #define SCAM_PERSPECTIVE_ARGS_DEFAULT__ {                                      \
     94   {0,0,0}, /* Position */                                                      \
     95   {0,1,0}, /* Target */                                                        \
     96   {0,0,1}, /* Up */                                                            \
     97   1.0, /* Aspect ratio */                                                      \
     98   0.0, /* Lens radius */                                                       \
     99   1.22173047639603070383, /* Fov ~70 degrees */                                \
    100   1.0 /* Focal distance. Unused for radius == 0 */                             \
    101 }
    102 static const struct scam_perspective_args SCAM_PERSPECTIVE_ARGS_DEFAULT =
    103   SCAM_PERSPECTIVE_ARGS_DEFAULT__;
    104 
    105 /* Forward declaration of external data types */
    106 struct logger;
    107 struct mem_allocator;
    108 
    109 /* Opaque data type */
    110 struct scam;
    111 
    112 /*******************************************************************************
    113  * Star-Camera API
    114  ******************************************************************************/
    115 BEGIN_DECLS
    116 
    117 SCAM_API res_T
    118 scam_create_perspective
    119   (struct logger* logger, /* NULL <=> use builtin logger */
    120    struct mem_allocator* allocator, /* NULL <=> use default allocator */
    121    const int verbose, /* Verbosity level */
    122    struct scam_perspective_args* args,
    123    struct scam** camera);
    124 
    125 SCAM_API res_T
    126 scam_create_orthographic
    127   (struct logger* logger, /* NULL <=> use builtin logger */
    128    struct mem_allocator* allocator, /* NULL <=> use default allocator */
    129    const int verbose, /* Verbosity level */
    130    struct scam_orthographic_args* args,
    131    struct scam** camera);
    132 
    133 SCAM_API res_T
    134 scam_generate_ray
    135   (const struct scam* cam,
    136    const struct scam_sample* sample,
    137    struct scam_ray* ray);
    138 
    139 SCAM_API res_T
    140 scam_get_type
    141   (const struct scam* cam,
    142    enum scam_type* type);
    143 
    144 SCAM_API res_T
    145 scam_ref_get
    146   (struct scam* camera);
    147 
    148 SCAM_API res_T
    149 scam_ref_put
    150   (struct scam* camera);
    151 
    152 SCAM_API res_T
    153 scam_focal_length_to_field_of_view
    154   (const double lens_radius,
    155    const double focal_length,
    156    double* field_of_view);
    157 
    158 SCAM_API res_T
    159 scam_field_of_view_to_focal_length
    160   (const double lens_radius,
    161    const double field_of_view,
    162    double* focal_length);
    163 
    164 SCAM_API res_T
    165 scam_perspective_get_solid_angle
    166   (const struct scam* camera,
    167    double* solid_angle); /* In sr */
    168 
    169 END_DECLS
    170 
    171 #endif /* SCAM_H */