| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | #ifndef GEOGRAM_MESH_MESH_PARAM_VALIDATOR | ||
| 41 | #define GEOGRAM_MESH_MESH_PARAM_VALIDATOR | ||
| 42 | |||
| 43 | #include <geogram/basic/common.h> | ||
| 44 | #include <geogram/parameterization/mesh_segmentation.h> | ||
| 45 | #include <geogram/basic/geometry.h> | ||
| 46 | #include <geogram/basic/attributes.h> | ||
| 47 | |||
| 48 | /** | ||
| 49 | * \file geogram/mesh/mesh_param_validator.h | ||
| 50 | * \brief A class to test the validity of a parameterized chart. | ||
| 51 | */ | ||
| 52 | |||
| 53 | namespace GEO { | ||
| 54 | |||
| 55 | class Mesh; | ||
| 56 | |||
| 57 | /** | ||
| 58 | * \brief Tests whether texture coordinates attached to a surface mesh | ||
| 59 | * define a valid parameterization. | ||
| 60 | */ | ||
| 61 | class GEOGRAM_API ParamValidator { | ||
| 62 | public: | ||
| 63 | /** | ||
| 64 | * \brief ParamValidator constructor. | ||
| 65 | */ | ||
| 66 | ParamValidator(); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * \brief ParamValidator destructor. | ||
| 70 | */ | ||
| 71 | ~ParamValidator(); | ||
| 72 | |||
| 73 | /** | ||
| 74 | * \brief Forbids copy. | ||
| 75 | */ | ||
| 76 | ParamValidator(const ParamValidator& rhs) = delete; | ||
| 77 | |||
| 78 | /** | ||
| 79 | * \brief Forbids copy. | ||
| 80 | */ | ||
| 81 | ParamValidator& operator=(const ParamValidator& rhs) = delete; | ||
| 82 | |||
| 83 | /** | ||
| 84 | * \brief Tests whether a Mesh and associated texture | ||
| 85 | * coordinates defines a valid parameterization. | ||
| 86 | * \param[in] chart a reference to the Mesh | ||
| 87 | * \details The mesh this chart belongs to is supposed to have a | ||
| 88 | * 2d vector attribute "tex_coord" attached to the | ||
| 89 | * vertices of the mesh with the texture coordinates. | ||
| 90 | * \retval true if texture coordinates define a valid parameterization. | ||
| 91 | * \retval false otherwise. | ||
| 92 | */ | ||
| 93 | bool chart_is_valid(Mesh& chart); | ||
| 94 | |||
| 95 | /** | ||
| 96 | * \brief Computes the scaling induced by the parameterization. | ||
| 97 | * \return the ratio between the maximum area scaling and minimum | ||
| 98 | * area scaling of the triangles. | ||
| 99 | * \param[in] chart a reference to the chart | ||
| 100 | */ | ||
| 101 | double chart_scaling(Mesh& chart); | ||
| 102 | |||
| 103 | /** | ||
| 104 | * \brief Computes the filling and overlapping ratio of a | ||
| 105 | * parameterized chart. | ||
| 106 | * \details The filling and overlapping ratio are stored in this | ||
| 107 | * ParamValidator and can be subsequently queried with fill_ratio() | ||
| 108 | * and overlap_ratio() respectively. | ||
| 109 | */ | ||
| 110 | void compute_fill_and_overlap_ratio(Mesh& chart); | ||
| 111 | |||
| 112 | /** | ||
| 113 | * \brief Gets the computed filling ratio. | ||
| 114 | * \details chart_is_valid() or compute_fill_and_overlap_ration() | ||
| 115 | * need to be called before. | ||
| 116 | * \return The ratio between the area used by the triangles in | ||
| 117 | * parameter space and the total area of the bounding rectangle. | ||
| 118 | */ | ||
| 119 | double fill_ratio() const { | ||
| 120 | ✗ | return fill_ratio_; | |
| 121 | } | ||
| 122 | |||
| 123 | /** | ||
| 124 | * \brief Gets the computed overlap ratio. | ||
| 125 | * \details chart_is_valid() or compute_fill_and_overlap_ration() | ||
| 126 | * need to be called before. | ||
| 127 | * \return The ratio between the area that correspond to overlapping | ||
| 128 | * triangles in parameter space and the total area of the bounding | ||
| 129 | * rectangle. | ||
| 130 | */ | ||
| 131 | double overlap_ratio() const { | ||
| 132 | ✗ | return overlap_ratio_; | |
| 133 | } | ||
| 134 | |||
| 135 | /** | ||
| 136 | * \brief Gets the maximum overlapping ratio. | ||
| 137 | * \details If the overlapping ratio is greater than this threshold | ||
| 138 | * then chart_is_valid() returns false. | ||
| 139 | * \return the maximum ratio between the area that correspond | ||
| 140 | * to overlapping triangles in parameter space and the total area of | ||
| 141 | * the bounding rectangle. | ||
| 142 | */ | ||
| 143 | double get_max_overlap_ratio() const { | ||
| 144 | return max_overlap_ratio_; | ||
| 145 | } | ||
| 146 | |||
| 147 | /** | ||
| 148 | * \brief Sets the maximum overlapping ratio. | ||
| 149 | * \param[in] x the maximum ratio between the area that correspond | ||
| 150 | * to overlapping triangles in parameter space and the total area of | ||
| 151 | * the bounding rectangle. | ||
| 152 | * \details If the overlapping ratio is greater than this threshold | ||
| 153 | * then chart_is_valid() returns false. | ||
| 154 | */ | ||
| 155 | void set_max_overlap_ratio(double x) { | ||
| 156 | max_overlap_ratio_ = x; | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 160 | * \brief Gets the maximum scaling. | ||
| 161 | * \details If the scaling is greater than this threshold then | ||
| 162 | * chart_is_valid() returns false. | ||
| 163 | * \return the maximum scaling between the area of a facet in | ||
| 164 | * parameter space and the area of the facet in 3D, | ||
| 165 | * relative to the mimium scaling evaluated on all the | ||
| 166 | * facets of the mesh. | ||
| 167 | */ | ||
| 168 | double get_max_scaling() const { | ||
| 169 | return max_scaling_; | ||
| 170 | } | ||
| 171 | |||
| 172 | /** | ||
| 173 | * \brief Sets the maximum scaling. | ||
| 174 | * \details If the scaling is greater than this threshold then | ||
| 175 | * chart_is_valid() returns false. | ||
| 176 | * \param[in] x the maximum scaling between the area of a facet | ||
| 177 | * in parameter space and the area of the facet in 3D, relative | ||
| 178 | * to the mimium scaling evaluated on all the facets of the mesh. | ||
| 179 | */ | ||
| 180 | void set_max_scaling(double x) { | ||
| 181 | max_scaling_ = x; | ||
| 182 | } | ||
| 183 | |||
| 184 | /** | ||
| 185 | * \brief Gets the minimum filling ratio. | ||
| 186 | * \details If the filling ratio is greater than this threshold then | ||
| 187 | * chart_is_valid() returns false. | ||
| 188 | * \return the minimum ratio between the area taken by the facets in | ||
| 189 | * parameter space and the total area of the bounding rectangle. | ||
| 190 | */ | ||
| 191 | double get_min_fill_ratio() const { | ||
| 192 | return min_fill_ratio_; | ||
| 193 | |||
| 194 | } | ||
| 195 | |||
| 196 | /** | ||
| 197 | * \brief Sets the minimum filling ratio. | ||
| 198 | * \details If the filling ratio is greater than this threshold then | ||
| 199 | * chart_is_valid() returns false. | ||
| 200 | * \param[in] x the minimum ratio between the area taken by the | ||
| 201 | * facets in parameter space and the total area of the bounding | ||
| 202 | * rectangle. | ||
| 203 | */ | ||
| 204 | void set_min_fill_ratio(double x) { | ||
| 205 | min_fill_ratio_ = x; | ||
| 206 | } | ||
| 207 | |||
| 208 | /** | ||
| 209 | * \brief Enables or disables messages. | ||
| 210 | * \param[in] x if true, messages are displayed on the console | ||
| 211 | * with charts statistics. Default is non-verbose. | ||
| 212 | */ | ||
| 213 | void set_verbose(bool x) { | ||
| 214 | ✗ | verbose_ = x; | |
| 215 | } | ||
| 216 | |||
| 217 | protected: | ||
| 218 | |||
| 219 | /** | ||
| 220 | * \brief Initializes the software rasterizer for a chart. | ||
| 221 | * \param[in] mesh a reference to the chart. | ||
| 222 | * \param[in] tex_coord a vector attribute of dimension 2 attached | ||
| 223 | * to the facet corners of the chart with the texture coordinates. | ||
| 224 | */ | ||
| 225 | void begin_rasterizer(Mesh& mesh, Attribute<double>& tex_coord); | ||
| 226 | |||
| 227 | /** | ||
| 228 | * \brief Terminates the software rasterizer. | ||
| 229 | * \details This counts the pixels to evaluate the filling and | ||
| 230 | * overlapping ratio. | ||
| 231 | */ | ||
| 232 | void end_rasterizer(); | ||
| 233 | |||
| 234 | /** | ||
| 235 | * \brief Rasterizes a triangle. | ||
| 236 | * \details This updates pixel counts for evaluating the filling | ||
| 237 | * and overlapping ratio. | ||
| 238 | * \param[in] p1 , p2 , p3 the 2d coordinates of the vertices of the | ||
| 239 | * triangle. | ||
| 240 | */ | ||
| 241 | void rasterize_triangle( | ||
| 242 | const vec2& p1, const vec2& p2, const vec2& p3 | ||
| 243 | ); | ||
| 244 | |||
| 245 | /** | ||
| 246 | * \brief Transforms a 2d point from parameter space to | ||
| 247 | * raterizer coordinates. | ||
| 248 | * \param[in] p the parameter-space 2d coordinates of the point. | ||
| 249 | * \param[out] x , y the integer rasterizer-space coordinates. | ||
| 250 | */ | ||
| 251 | void transform(const vec2& p, int& x, int& y); | ||
| 252 | |||
| 253 | private: | ||
| 254 | /** | ||
| 255 | * \brief Width and height of the rasterizer, in pixels. | ||
| 256 | */ | ||
| 257 | int graph_size_; | ||
| 258 | |||
| 259 | /** | ||
| 260 | * \brief A pointer to rasterizer's memory, a 2d array of | ||
| 261 | * graph_size_ times graph_size_ pixels. | ||
| 262 | */ | ||
| 263 | Numeric::uint8* graph_mem_; | ||
| 264 | |||
| 265 | /** | ||
| 266 | * \brief A pointer to an array of dimension graph_size_ with | ||
| 267 | * the left X pixel coordinate of the scanline, | ||
| 268 | */ | ||
| 269 | int* x_left_; | ||
| 270 | |||
| 271 | /** | ||
| 272 | * \brief A pointer to an array of dimension graph_size_ with | ||
| 273 | * the right X pixel coordinate of the scanline, | ||
| 274 | */ | ||
| 275 | int* x_right_; | ||
| 276 | |||
| 277 | /** | ||
| 278 | * \brief Viewport lower-left corner x coordinate. | ||
| 279 | */ | ||
| 280 | double user_x_min_; | ||
| 281 | |||
| 282 | /** | ||
| 283 | * \brief Viewport lower-left corner y coordinate. | ||
| 284 | */ | ||
| 285 | double user_y_min_; | ||
| 286 | |||
| 287 | /** | ||
| 288 | * \brief Viewport width. | ||
| 289 | */ | ||
| 290 | double user_width_; | ||
| 291 | |||
| 292 | /** | ||
| 293 | * \brief Viewport height. | ||
| 294 | */ | ||
| 295 | double user_height_; | ||
| 296 | |||
| 297 | /** | ||
| 298 | * \brief Viewport size, i.e. max(width,height). | ||
| 299 | */ | ||
| 300 | double user_size_; | ||
| 301 | |||
| 302 | /** | ||
| 303 | * \brief The computed filling ratio. | ||
| 304 | */ | ||
| 305 | double fill_ratio_; | ||
| 306 | |||
| 307 | /** | ||
| 308 | * \brief The computed overlapping ratio. | ||
| 309 | */ | ||
| 310 | double overlap_ratio_; | ||
| 311 | |||
| 312 | /** | ||
| 313 | * \brief Maximum tolerated overlapping ratio. | ||
| 314 | */ | ||
| 315 | double max_overlap_ratio_; | ||
| 316 | |||
| 317 | /** | ||
| 318 | * \brief Maximum tolerated facet scaling. | ||
| 319 | */ | ||
| 320 | double max_scaling_; | ||
| 321 | |||
| 322 | /** | ||
| 323 | * \brief Minimum required filling ratio. | ||
| 324 | */ | ||
| 325 | double min_fill_ratio_; | ||
| 326 | |||
| 327 | /** | ||
| 328 | * \brief If true, displays statistics on the logger. | ||
| 329 | */ | ||
| 330 | bool verbose_; | ||
| 331 | }; | ||
| 332 | |||
| 333 | } | ||
| 334 | |||
| 335 | #endif | ||
| 336 |