Graphite  Version 3
An experimental 3D geometry processing program
mesh_frame_field.h
Go to the documentation of this file.
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_FRAME_FIELD
41 #define GEOGRAM_MESH_MESH_FRAME_FIELD
42 
43 #include <geogram/basic/common.h>
44 #include <geogram/basic/geometry.h>
46 
51 namespace GEO {
52 
53  class Mesh;
54 
59  class GEOGRAM_API FrameField {
60  public:
64  FrameField() : use_NN_(true) {
65  }
66 
78  void set_use_spatial_search(bool x) {
79  use_NN_ = x;
80  }
81 
97  bool load(
98  const Mesh& M, bool volumetric, const std::string& filename
99  );
100 
101 
113  const Mesh& M, bool volumetric, double sharp_angle_threshold=45.0
114  );
115 
123  index_t get_nearest_frame_index(const double* p) const {
124  geo_assert(use_NN_);
125  return NN_->get_nearest_neighbor(p);
126  }
127 
136  void get_nearest_frame(const double* p, double* f) const {
137  geo_assert(use_NN_);
138  index_t fi = get_nearest_frame_index(p);
139  for(index_t c = 0; c < 9; ++c) {
140  f[c] = frames_[fi * 9 + c];
141  }
142  }
143 
150  const vector<double>& frames() const {
151  return frames_;
152  }
153 
154  /*
155  * \brief Scales one of the vectors of a frame.
156  * \details On exit, the norm of the vector nearest to \p N in
157  * \p frame has a norm equal to \p s.
158  * \param[in,out] frame the frame, as an array of 9 doubles
159  * \param[in] N the vector to be scaled (retrieved in the frame)
160  * \param[in] s scaling factor
161  */
162  static void scale_frame_vector(double* frame, const vec3& N, double s);
163 
172  static void fix_frame(double* frame, const vec3& N);
173 
174  private:
175  NearestNeighborSearch_var NN_;
176  vector<double> frames_;
177  vector<double> centers_;
178  bool use_NN_;
179  };
180 
181 
182 }
183 
184 #endif
#define geo_assert(x)
Verifies that a condition is met.
Definition: assert.h:149
Represents a 3D frame field, i.e. a function that associates a 3d orthonormal basis to each point in ...
void create_from_surface_mesh(const Mesh &M, bool volumetric, double sharp_angle_threshold=45.0)
Creates a frame field that matches a given mesh.
bool load(const Mesh &M, bool volumetric, const std::string &filename)
Loads a frame field from a file.
FrameField()
Constructs a new uninitialized FrameField.
const vector< double > & frames() const
Gets the vector that contains all the frames coordinates.
static void fix_frame(double *frame, const vec3 &N)
Fixes a frame in such a way that it is orthogonal to a given vector.
index_t get_nearest_frame_index(const double *p) const
Gets the index of the frame nearest to a given point.
void get_nearest_frame(const double *p, double *f) const
Gets the frame nearest to a given point.
void set_use_spatial_search(bool x)
Specifies whether a spatial search structure should be created.
Represents a mesh.
Definition: mesh.h:2693
Common include file, providing basic definitions. Should be included before anything else by all head...
Geometric functions in 2d and 3d.
Global Vorpaline namespace.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Abstract interface for nearest neighbor searching.