Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
VSDM.h
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 EXPLORAGRAM_OPTIMAL_TRANSPORT_VSDM
41 #define EXPLORAGRAM_OPTIMAL_TRANSPORT_VSDM
42 
45 #include <geogram/voronoi/RVD.h>
47 #include <geogram/NL/nl_matrix.h>
48 
49 namespace GEO {
50  class Mesh;
51  class ProgressTask;
52 
67  public:
73  VSDM(Mesh* S, Mesh* T);
74 
78  virtual ~VSDM();
79 
85  void set_affinity(double x) {
86  affinity_ = x;
87  }
88 
93  void optimize(index_t nb_iter);
94 
100  void set_progress(ProgressTask* progress) {
101  progress_ = progress;
102  }
103 
113  void set_subdivision_surface(Mesh* mesh, index_t nb_subdiv);
114 
126  static void funcgrad_CB(index_t n, double* x, double& f, double* g);
127 
139  static void newiteration_CB(
140  index_t n, const double* x, double f, const double* g, double gnorm
141  );
142 
143  protected:
148  static VSDM* instance() {
149  return instance_;
150  }
151 
162  virtual void funcgrad(index_t n, double* x, double& f, double* g);
163 
169  virtual void newiteration();
170 
182  void add_funcgrad_affinity(index_t n, double* x, double& f, double* g);
183 
190 
191  protected:
192  Delaunay_var delaunay_;
194  Mesh* S_;
195  Mesh* T_;
196  double affinity_;
197  double affinity_scaling_;
198  ProgressTask* progress_;
199  static VSDM* instance_;
200  Optimizer_var optimizer_;
201  index_t nb_iter_;
202  index_t cur_iter_;
203 
204  NLSparseMatrix L_;
205  vector<double> temp_V1_;
206  vector<double> temp_V2_;
207 
208  NLMatrix subd_matrix_;
209  Mesh* subd_;
210  vector<double> subd_g_;
211  };
212 
213 }
214 
215 #endif
Class and functions to compute restricted Voronoi diagrams and extract information from them.
Represents a mesh.
Definition: mesh.h:2693
Tracks the progress of a task.
Definition: progress.h:240
Voronoi Square Distance Minimization.
Definition: VSDM.h:66
void set_progress(ProgressTask *progress)
Sets an optional progress bar to track progress during calls of optimize()
Definition: VSDM.h:100
static void newiteration_CB(index_t n, const double *x, double f, const double *g, double gnorm)
The callback for each iteration of the optimizer.
virtual ~VSDM()
VSDM destructor.
void set_subdivision_surface(Mesh *mesh, index_t nb_subdiv)
Sets a subdivision surface.
static void compute_graph_Laplacian(Mesh *S, NLSparseMatrix *L)
Computes the graph Laplacian of a surface mesh.
void optimize(index_t nb_iter)
Optimizes the fitting.
static void funcgrad_CB(index_t n, double *x, double &f, double *g)
The callback to evaluate the objective function, used by the optimizer.
static VSDM * instance()
Gets the instance.
Definition: VSDM.h:148
VSDM(Mesh *S, Mesh *T)
VSDM constructor.
virtual void newiteration()
Updates the progress bar (if specified) and graphics.
void add_funcgrad_affinity(index_t n, double *x, double &f, double *g)
Adds the value and gradient of the affinity to the currently evaluated objective function.
void set_affinity(double x)
Sets the affinity.
Definition: VSDM.h:85
virtual void funcgrad(index_t n, double *x, double &f, double *g)
Evaluates the objective function and its gradient.
Abstract interface for Delaunay.
#define EXPLORAGRAM_API
Linkage declaration for exploragram symbols.
Definition: defs.h:18
Included by all headers in exploragram.
Global Vorpaline namespace.
Definition: basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Internal OpenNL functions to manipulate sparse matrices.
Abstract base class for numerical optimizers, used to minimize a multivariate function.
The base class for abstract matrices.
Definition: nl_matrix.h:80