Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

params.h 13.2 KB
 Laurent Belcour committed Apr 08, 2013 1 2 #pragma once  Laurent Belcour committed May 31, 2013 3 4 5 6 7 8 9 10 #include #include #include #include #include #include #include  Laurent Belcour committed Oct 31, 2013 11 12 #include "common.h"  Laurent Belcour committed Aug 30, 2013 13 /*! \class params  Laurent Belcour committed Apr 08, 2013 14  * \ingroup core  Laurent Belcour committed Aug 30, 2013 15 16  * \brief a static class allowing to change from one parametrization * to another.  Laurent Belcour committed Apr 08, 2013 17  *  Laurent Belcour committed Aug 30, 2013 18 19  * Any function object or data object should have an associated * parametrization.  Laurent Belcour committed Aug 29, 2013 20 21 22 23 24 25  * * We use the following convention to defined the tangent, normal and * bi-normal of the surface: * * The normal is the upper vector (0, 0, 1) * * The tangent direction is along x direction (1, 0, 0) * * The bi-normal is along the y direction (0, 1, 0)  Laurent Belcour committed Apr 08, 2013 26 27 28  */ class params {  Laurent Belcour committed Apr 09, 2013 29  public: // data  Laurent Belcour committed Apr 08, 2013 30   Laurent Belcour committed May 31, 2013 31 32  //! \brief list of all supported parametrization for the input space. //! An unsupported parametrization will go under the name  Laurent Belcour committed Nov 08, 2013 33 34 35 36 37  //! unknown. We use the following notations: //! * The view vector is \f$\vec{v}\f$ //! * The light vector is \f$\vec{l}\f$ //! * The normal vector is \f$\vec{n}\f$ //! * The reflected vector is \f$\vec{r} = 2\mbox{dot}(\vec{v}, \vec{n})\vec{n} - \vec{v}\f$  Laurent Belcour committed May 31, 2013 38 39  enum input {  Laurent Belcour committed Aug 30, 2013 40 41 42 43  RUSIN_TH_PH_TD_PD, /*!< Half-angle parametrization as described in [Rusinkiewicz'98] */ RUSIN_TH_PH_TD, RUSIN_TH_TD_PD, RUSIN_TH_TD, /*!< Half-angle parametrization with no azimutal information */  Laurent Belcour committed Nov 08, 2013 44 45 46 47 48 49  RUSIN_VH_VD, /*!< Half-angle parametrization in vector format. Coordinates are: [\f$\vec{h}_x, \vec{h}_y, \vec{h}_z, \vec{d}_x, \vec{d}_y, \vec{d}_z \f$].*/ RUSIN_VH, /*!< Half-angle parametrization with no difference direction in vector format. Coordinates are: [\f$\vec{h}_x, \vec{h}_y, \vec{h}_z\f$]. */  Laurent Belcour committed Aug 30, 2013 50 51 52  COS_TH_TD, COS_TH,  Laurent Belcour committed Sep 23, 2013 53 54 55  SCHLICK_TK_PK, /*!< Schlick's back vector parametrization */ SCHLICK_VK, /*!< Schlick's back vector */ COS_TK, /*!< Schlick's back vector dot product with the normal */  Laurent Belcour committed Sep 17, 2013 56   Laurent Belcour committed Aug 30, 2013 57 58 59 60 61  STEREOGRAPHIC, /*!< Stereographic projection of the Light and View vectors */ SPHERICAL_TL_PL_TV_PV, /*!< Light and View vectors represented in spherical coordinates */ ISOTROPIC_TV_TL_DPHI, /*!< Light and View vectors represented in spherical coordinates, with the difference of azimutal coordinates in the last component */  Laurent Belcour committed Nov 08, 2013 62 63 64  ISOTROPIC_TV_PROJ_DPHI,/*!< 2D Parametrization where the phi component is projected. Coordinates are: [\f$\theta_v \cos(\Delta\phi), \theta_v \sin(\Delta\phi).\f$]*/  Laurent Belcour committed Nov 08, 2013 65 66 67  ISOTROPIC_TL_TV_PROJ_DPHI,/*!< 3D Parametrization where the phi component is projected. Coordinates are: [\f$\theta_l, \theta_v \cos(\Delta\phi), \theta_v \sin(\Delta\phi).\f$]*/  Laurent Belcour committed Aug 30, 2013 68 69 70 71  ISOTROPIC_TD_PD, /*!< Difference between two directions such as R and H */ CARTESIAN, /*!< Light and View vectors represented in cartesian coordinates */  Laurent Belcour committed Aug 30, 2013 72  UNKNOWN_INPUT /*!< Default behaviour. Only use this is you do not fit BRDF data */  Laurent Belcour committed May 31, 2013 73 74 75 76 77 78 79  }; //! \brief list of all supported parametrization for the output space. //! An unsupported parametrization will go under the name //! unknown. enum output {  Laurent Belcour committed Oct 14, 2013 80 81 82 83 84  INV_STERADIAN, /*!< Output values in inverse steradian (sr-1). This is the standard definition for a BRDF. */ INV_STERADIAN_COSINE_FACTOR, /*!< Output values in inverse steradian (sr-1) weighted by the cosine factor of the output direction. */  Laurent Belcour committed May 31, 2013 85 86 87 88 89  ENERGY, RGB_COLOR, XYZ_COLOR, UNKNOWN_OUTPUT };  Laurent Belcour committed Apr 09, 2013 90 91 92  public: // methods  Laurent Belcour committed Apr 17, 2013 93  //! \brief parse a string to provide a parametrization type.  Laurent Belcour committed Jun 10, 2013 94  static params::input parse_input(const std::string& txt);  Laurent Belcour committed Jun 07, 2013 95   Laurent Belcour committed Jun 10, 2013 96 97 98  //! \brief look for the string associated with a parametrization //! type. static std::string get_name(const params::input param);  Laurent Belcour committed Jun 07, 2013 99   Laurent Belcour committed Apr 17, 2013 100 101 102 103 104 105 106 107 108 109 110 111 112  //! \brief parse a string to provide a parametrization type. static params::output parse_output(const std::string& txt) { if(txt == std::string("ENERGY")) { return params::ENERGY; } else { return params::UNKNOWN_OUTPUT; } }  Laurent Belcour committed Apr 17, 2013 113 114  //! \brief static function for input type convertion. This //! function allocate the resulting vector.  Laurent Belcour committed Apr 17, 2013 115 116  static double* convert(const double* invec, params::input intype, params::input outtype)  Laurent Belcour committed Apr 09, 2013 117  {  Laurent Belcour committed Apr 17, 2013 118 119 120 121 122  int dim = dimension(outtype); // Get the size of the output vector if(dim > 0) { double* outvec = new double[dim];  Laurent Belcour committed May 23, 2013 123  double temvec[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // Temp CARTESIAN vectors  Laurent Belcour committed Apr 17, 2013 124 125 126 127 128 129 130 131 132 133 134  to_cartesian(invec, intype, temvec); from_cartesian(temvec, outtype, outvec); return outvec; } else { return NULL; } }  Laurent Belcour committed Apr 17, 2013 135 136  //! \brief static function for input type convertion. The outvec //! resulting vector should be allocated with the correct  Laurent Belcour committed Apr 17, 2013 137  //! output size.  Laurent Belcour committed Apr 17, 2013 138 139  static void convert(const double* invec, params::input intype, params::input outtype, double* outvec)  Laurent Belcour committed Apr 17, 2013 140  {  Laurent Belcour committed Sep 17, 2013 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168  // The convertion is done using the cartesian parametrization as // an intermediate one. If the two parametrizations are equals // there is no need to perform the conversion. if(intype == outtype) { int dim = dimension(outtype); for(int i=0; i= 0.0 && out[5] >= 0.0); #endif  Laurent Belcour committed Apr 17, 2013 239  }  Laurent Belcour committed Jun 10, 2013 240 241 242 243 244 245 246 247 248 249 250 251 252  //! \brief from the 4D definition of a classical vector parametrization, //! export the cartesian coordinates. static void classical_to_cartesian(double theta_l, double phi_l, double theta_v, double phi_v, double* out) { out[0] = cos(phi_l)*sin(theta_l); out[1] = sin(phi_l)*sin(theta_l); out[2] = cos(theta_l); out[3] = cos(phi_v)*sin(theta_v); out[4] = sin(phi_v)*sin(theta_v); out[5] = cos(theta_v); }  Laurent Belcour committed Apr 17, 2013 253   Laurent Belcour committed Aug 29, 2013 254 255 256 257 258 259  //! \brief rotate a cartesian vector with respect to the normal of //! theta degrees. static void rotate_normal(double* vec, double theta) { const double cost = cos(theta); const double sint = sin(theta);  Laurent Belcour committed Apr 17, 2013 260   Laurent Belcour committed Aug 29, 2013 261  const double temp = cost * vec[0] + sint * vec[1];  Laurent Belcour committed Jul 12, 2013 262   Laurent Belcour committed Aug 29, 2013 263 264 265  vec[1] = cost * vec[1] - sint * vec[0]; vec[0] = temp; }  Laurent Belcour committed Apr 17, 2013 266   Laurent Belcour committed Aug 29, 2013 267 268 269 270 271 272  //! \brief rotate a cartesian vector with respect to the bi-normal of //! theta degrees. static void rotate_binormal(double* vec, double theta) { const double cost = cos(theta); const double sint = sin(theta);  Laurent Belcour committed Apr 17, 2013 273   Laurent Belcour committed Aug 29, 2013 274  const double temp = cost * vec[0] + sint * vec[2];  Laurent Belcour committed Jul 12, 2013 275   Laurent Belcour committed Aug 29, 2013 276 277 278  vec[2] = cost * vec[2] - sint * vec[0]; vec[0] = temp; }  Laurent Belcour committed May 31, 2013 279   Laurent Belcour committed Jun 10, 2013 280  static void print_input_params();  Laurent Belcour committed May 31, 2013 281   Laurent Belcour committed Apr 08, 2013 282 };  Laurent Belcour committed Jul 17, 2013 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341  /*! \brief A parametrized object. Allow to define function object (either data * or functions that are defined over an input space and output space. This * Object allowas to change the parametrization of the input or output space. */ class parametrized { public: parametrized() : _in_param(params::UNKNOWN_INPUT), _out_param(params::UNKNOWN_OUTPUT) { } //! \brief provide the input parametrization of the object. virtual params::input parametrization() const { return _in_param; } //! \brief provide the input parametrization of the object. virtual params::input input_parametrization() const { return _in_param; } //! \brief provide the outout parametrization of the object. virtual params::output output_parametrization() const { return _out_param; } //! \brief can set the input parametrization of a non-parametrized //! object. Print an error if it is already defined. virtual void setParametrization(params::input new_param) { //! \todo Here is something strange happening. The equality between //! those enums is not correct for UNKNOWN_INPUT if(_in_param == new_param) { return; } else if(_in_param == params::UNKNOWN_INPUT) { _in_param = new_param; } else { std::cout << "<> an input parametrization is already defined: " << params::get_name(_in_param) << std::endl; std::cout << "<> trying to change to: " << params::get_name(new_param) << std::endl; } } //! \brief can set the output parametrization of a non-parametrized //! function. Throw an exception if it tries to erase a previously //! defined one. virtual void setParametrization(params::output new_param) { if(_out_param == new_param) { return; }  Laurent Belcour committed Aug 20, 2013 342  else if(_out_param == params::UNKNOWN_OUTPUT)  Laurent Belcour committed Jul 17, 2013 343 344 345 346 347 348 349 350 351  { _out_param = new_param; } else { std::cout << "<> an output parametrization is already defined: " << std::endl; } }  Laurent Belcour committed Oct 29, 2013 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374  /* DIMENSION OF THE INPUT AND OUTPUT DOMAIN */ //! Provide the dimension of the input space of the function virtual int dimX() const { return _nX ; } //! Provide the dimension of the output space of the function virtual int dimY() const { return _nY ; } //! Set the dimension of the input space of the function virtual void setDimX(int nX) { _nX = nX ; } //! Set the dimension of the output space of the function virtual void setDimY(int nY) { _nY = nY ; } /* DEFINITION DOMAIN OF THE FUNCTION */ //! \brief Set the minimum value the input can take virtual void setMin(const vec& min) ; //! \brief Set the maximum value the input can take virtual void setMax(const vec& max) ; //! \brief Get the minimum value the input can take  Laurent Belcour committed Oct 31, 2013 375  virtual vec min() const ;  Laurent Belcour committed Oct 29, 2013 376 377  //! \brief Get the maximum value the input can take  Laurent Belcour committed Oct 31, 2013 378  virtual vec max() const ;  Laurent Belcour committed Oct 29, 2013 379 380   Laurent Belcour committed Jul 17, 2013 381 382 383 384  protected: // Input and output parametrization params::input _in_param ; params::output _out_param ;  Laurent Belcour committed Oct 29, 2013 385 386 387 388  // Dimension of the function & domain of definition. int _nX, _nY ; vec _min, _max ;  Laurent Belcour committed Jul 17, 2013 389 };