~ubuntu-branches/ubuntu/lucid/meshlab/lucid

« back to all changes in this revision

Viewing changes to meshlab/src/meshlabplugins/filter_mls/mlsplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-10-08 16:40:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091008164041-0c2ealqv8b8uc20c
Tags: 1.2.2-1
* New upstream version
* Do not build filter_isoparametrization because liblevmar dependency
  is not (yet) in Debian
* Fix compilation with gcc-4.4, thanks to Jonathan Liu for the patch
  (closes: #539544)
* rules: Add compiler variables to the qmake call (for testing with new
  GCC versions)
* io_3ds.pro: Make LIBS and INCLUDEPATH point to Debian version of lib3ds
* io_epoch.pro: Make LIBS point to Debian version of libbz2
* control:
  - Move Homepage URL to the source package section
  - Update to standards-version 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
 
85
85
// ST() must return the very short string describing each filtering action
86
86
// (this string is used also to define the menu entry)
87
 
const QString MlsPlugin::filterName(FilterIDType filterId)
 
87
const QString MlsPlugin::filterName(FilterIDType filterId) const
88
88
{
89
89
        switch(filterId) {
90
90
                case FP_APSS_PROJECTION         : return QString("MLS projection (APSS)");
124
124
 
125
125
// Info() must return the longer string describing each filtering action
126
126
// (this string is used in the About plugin dialog)
127
 
const QString MlsPlugin::filterInfo(FilterIDType filterId)
 
127
const QString MlsPlugin::filterInfo(FilterIDType filterId) const
128
128
{
129
129
        QString str = "";
130
130
        if (filterId & _PROJECTION_)
178
178
// - the string shown in the dialog
179
179
// - the default value
180
180
// - a possibly long string describing the meaning of that parameter (shown as a popup help in the dialog)
181
 
void MlsPlugin::initParameterSet(QAction* action, MeshDocument& md, FilterParameterSet& parlst)
182
 
//void ExtraSamplePlugin::initParList(QAction *action, MeshModel &m, FilterParameterSet &parlst)
 
181
void MlsPlugin::initParameterSet(QAction* action, MeshDocument& md, RichParameterSet& parlst)
 
182
//void ExtraSamplePlugin::initParList(QAction *action, MeshModel &m, RichParameterSet &parlst)
183
183
{
184
184
        int id = ID(action);
185
185
        MeshModel *target = md.mm();
186
186
 
187
187
        if (id == FP_SELECT_SMALL_COMPONENTS)
188
188
        {
189
 
                parlst.addFloat("NbFaceRatio",
 
189
                parlst.addParam(new RichFloat("NbFaceRatio",
190
190
                                                                                0.1f,
191
191
                                                                                "Small component ratio",
192
192
                                                                                "This ratio (between 0 and 1) defines the meaning of <i>small</i> as the threshold ratio between the number of faces"
193
 
                                                                                "of the largest component and the other ones. A larger value will select more components.");
194
 
                parlst.addBool( "NonClosedOnly",
 
193
                                                                                "of the largest component and the other ones. A larger value will select more components."));
 
194
                parlst.addParam(new RichBool( "NonClosedOnly",
195
195
                                                                                false,
196
196
                                                                                "Select only non closed components",
197
 
                                                                                "");
 
197
                                                                                ""));
198
198
                return;
199
199
        }
200
200
        else if (id == FP_RADIUS_FROM_DENSITY)
201
201
        {
202
 
                parlst.addInt("NbNeighbors",
 
202
                parlst.addParam(new RichInt("NbNeighbors",
203
203
                                                                        16,
204
204
                                                                        "Number of neighbors",
205
 
                                                                        "Number of neighbors used to estimate the local density. Larger values lead to smoother variations.");
 
205
                                                                        "Number of neighbors used to estimate the local density. Larger values lead to smoother variations."));
206
206
                return;
207
207
        }
208
208
 
209
209
        if ((id & _PROJECTION_))
210
210
        {
211
 
                parlst.addMesh( "ControlMesh", target, "Point set",
212
 
                                                                                "The point set (or mesh) which defines the MLS surface.");
213
 
                parlst.addMesh( "ProxyMesh", target, "Proxy Mesh",
214
 
                                                                                "The mesh that will be projected/resampled onto the MLS surface.");
 
211
                parlst.addParam(new RichMesh( "ControlMesh", target,&md, "Point set",
 
212
                                                                                "The point set (or mesh) which defines the MLS surface."));
 
213
                parlst.addParam(new RichMesh( "ProxyMesh", target, &md, "Proxy Mesh",
 
214
                                                                                "The mesh that will be projected/resampled onto the MLS surface."));
215
215
        }
216
216
        if ((id & _PROJECTION_) || (id & _COLORIZE_))
217
217
        {
218
 
                parlst.addBool( "SelectionOnly",
 
218
                parlst.addParam(new RichBool( "SelectionOnly",
219
219
                                                                                target->cm.sfn>0,
220
220
                                                                                "Selection only",
221
 
                                                                                "If checked, only selected vertices will be projected.");
 
221
                                                                                "If checked, only selected vertices will be projected."));
222
222
        }
223
223
 
224
224
        if ( (id & _APSS_) || (id & _RIMLS_) )
225
225
        {
226
 
                parlst.addFloat("FilterScale",
 
226
                parlst.addParam(new RichFloat("FilterScale",
227
227
                                                                                2.0,
228
228
                                                                                "MLS - Filter scale",
229
229
                                                                                "Scale of the spatial low pass filter.\n"
230
 
                                                                                "It is relative to the radius (local point spacing) of the vertices.");
231
 
                parlst.addFloat("ProjectionAccuracy",
 
230
                                                                                "It is relative to the radius (local point spacing) of the vertices."));
 
231
                parlst.addParam(new RichFloat("ProjectionAccuracy",
232
232
                                                                                1e-4f,
233
233
                                                                                "Projection - Accuracy (adv)",
234
234
                                                                                "Threshold value used to stop the projections.\n"
235
 
                                                                                "This value is scaled by the mean point spacing to get the actual threshold.");
236
 
                parlst.addInt(  "MaxProjectionIters",
 
235
                                                                                "This value is scaled by the mean point spacing to get the actual threshold."));
 
236
                parlst.addParam(new RichInt(  "MaxProjectionIters",
237
237
                                                                                15,
238
238
                                                                                "Projection - Max iterations (adv)",
239
 
                                                                                "Max number of iterations for the projection.");
 
239
                                                                                "Max number of iterations for the projection."));
240
240
        }
241
241
 
242
242
        if (id & _APSS_)
243
243
        {
244
 
                parlst.addFloat("SphericalParameter",
 
244
                parlst.addParam(new RichFloat("SphericalParameter",
245
245
                                                                                1,
246
246
                                                                                "MLS - Spherical parameter",
247
247
                                                                                "Control the curvature of the fitted spheres: 0 is equivalent to a pure plane fit,"
248
248
                                                                                "1 to a pure spherical fit, values between 0 and 1 gives intermediate results,"
249
249
                                                                                "while others real values might give interresting results, but take care with extreme"
250
 
                                                                                "settings !");
 
250
                                                                                "settings !"));
251
251
                if (!(id & _COLORIZE_))
252
 
                        parlst.addBool( "AccurateNormal",
 
252
                        parlst.addParam(new RichBool( "AccurateNormal",
253
253
                                                                                true,
254
254
                                                                                "Accurate normals",
255
255
                                                                                "If checked, use the accurate MLS gradient instead of the local approximation"
256
 
                                                                                "to compute the normals.");
 
256
                                                                                "to compute the normals."));
257
257
        }
258
258
 
259
259
        if (id & _RIMLS_)
260
260
        {
261
 
                parlst.addFloat("SigmaN",
 
261
                parlst.addParam(new RichFloat("SigmaN",
262
262
                                                                                0.75,
263
263
                                                                                "MLS - Sharpness",
264
264
                                                                                "Width of the filter used by the normal refitting weight."
265
265
                                                                                "This weight function is a Gaussian on the distance between two unit vectors:"
266
 
                                                                                "the current gradient and the input normal. Therefore, typical value range between 0.5 (sharp) to 2 (smooth).");
267
 
                parlst.addInt(  "MaxRefittingIters",
 
266
                                                                                "the current gradient and the input normal. Therefore, typical value range between 0.5 (sharp) to 2 (smooth)."));
 
267
                parlst.addParam(new RichInt(  "MaxRefittingIters",
268
268
                                                                                3,
269
269
                                                                                "MLS - Max fitting iterations",
270
 
                                                                                "Max number of fitting iterations. (0 or 1 is equivalent to the standard IMLS)");
 
270
                                                                                "Max number of fitting iterations. (0 or 1 is equivalent to the standard IMLS)"));
271
271
        }
272
272
 
273
273
        if (id & _PROJECTION_)
274
274
        {
275
 
                parlst.addInt(  "MaxSubdivisions",
 
275
                parlst.addParam(new RichInt(  "MaxSubdivisions",
276
276
                                                                                0,
277
277
                                                                                "Refinement - Max subdivisions",
278
 
                                                                                "Max number of subdivisions.");
279
 
                parlst.addFloat("ThAngleInDegree",
 
278
                                                                                "Max number of subdivisions."));
 
279
                parlst.addParam(new RichFloat("ThAngleInDegree",
280
280
                                                                                2,
281
281
                                                                                "Refinement - Crease angle (degree)",
282
 
                                                                                "Threshold angle between two faces controlling the refinement.");
 
282
                                                                                "Threshold angle between two faces controlling the refinement."));
283
283
        }
284
284
 
285
285
        if (id & _AFRONT_)
293
293
                if (id & _APSS_)
294
294
                        lst << "ApproxMean";
295
295
 
296
 
                parlst.addEnum("CurvatureType", CT_MEAN,
 
296
                parlst.addParam(new RichEnum("CurvatureType", CT_MEAN,
297
297
                        lst,
298
298
                        "Curvature type",
299
299
                        QString("The type of the curvature to plot.")
300
 
                        + ((id & _APSS_) ? "<br>ApproxMean uses the radius of the fitted sphere as an approximation of the mean curvature." : ""));
 
300
                        + ((id & _APSS_) ? "<br>ApproxMean uses the radius of the fitted sphere as an approximation of the mean curvature." : "")));
301
301
//              if ((id & _APSS_))
302
 
//                      parlst.addBool( "ApproxCurvature",
 
302
//                      parlst.addParam(new RichBool( "ApproxCurvature",
303
303
//                                                                              false,
304
304
//                                                                              "Approx mean curvature",
305
305
//                                                                              "If checked, use the radius of the fitted sphere as an approximation of the mean curvature.");
307
307
 
308
308
        if (id & _MCUBE_)
309
309
        {
310
 
                parlst.addInt(  "Resolution",
 
310
                parlst.addParam(new RichInt(  "Resolution",
311
311
                                                                                200,
312
312
                                                                                "Grid Resolution",
313
313
                                                                                "The resolution of the grid on which we run the marching cubes."
314
 
                                                                                "This marching cube is memory friendly, so you can safely set large values up to 1000 or even more.");
 
314
                                                                                "This marching cube is memory friendly, so you can safely set large values up to 1000 or even more."));
315
315
        }
316
316
}
317
317
 
361
361
        }
362
362
}
363
363
 
364
 
bool MlsPlugin::applyFilter(QAction* filter, MeshDocument& md, FilterParameterSet& par, vcg::CallBackPos* cb)
 
364
bool MlsPlugin::applyFilter(QAction* filter, MeshDocument& md, RichParameterSet& par, vcg::CallBackPos* cb)
365
365
{
366
366
        int id = ID(filter);
367
367
 
409
409
                                // clone the control mesh
410
410
                                MeshModel* ref = par.getMesh("ControlMesh");
411
411
                                pPoints = new MeshModel();
412
 
                                pPoints->updateDataMask(ref->currentDataMask);
 
412
                                pPoints->updateDataMask(ref);
413
413
                                vcg::tri::Append<CMeshO,CMeshO>::Mesh(pPoints->cm, ref->cm, false, true);  // the last true means "copy all vertices"
414
414
                                vcg::tri::UpdateBounding<CMeshO>::Box(pPoints->cm);
415
415
                                pPoints->cm.Tr = ref->cm.Tr;
523
523
                                                c = apss->approxMeanCurvature(p);
524
524
                                        else
525
525
                                        {
526
 
                                                grad = mls->gradient(p);
527
 
                                                hess = mls->hessian(p);
528
 
                                                implicits::WeingartenMap<float> W(grad,hess);
529
 
 
530
 
                                                mesh->cm.vert[i].PD1() = W.K1Dir();
531
 
                                                mesh->cm.vert[i].PD2() = W.K2Dir();
532
 
                                                mesh->cm.vert[i].K1() =  W.K1();
533
 
                                                mesh->cm.vert[i].K2() =  W.K2();
534
 
 
535
 
                                                switch(ct)
 
526
                                                int errorMask;
 
527
                                                grad = mls->gradient(p, &errorMask);
 
528
                                                if (errorMask == MLS_OK && grad.Norm() > 1e-8)
536
529
                                                {
537
 
                                                        case CT_MEAN: c = W.MeanCurvature(); break;
538
 
                                                        case CT_GAUSS: c = W.GaussCurvature(); break;
539
 
                                                        case CT_K1: c = W.K1(); break;
540
 
                                                        case CT_K2: c = W.K2(); break;
541
 
                                                        default: assert(0 && "invalid curvature type");
 
530
                                                  hess = mls->hessian(p);
 
531
                                                  implicits::WeingartenMap<float> W(grad,hess);
 
532
 
 
533
                                                  mesh->cm.vert[i].PD1() = W.K1Dir();
 
534
                                                  mesh->cm.vert[i].PD2() = W.K2Dir();
 
535
                                                  mesh->cm.vert[i].K1() =  W.K1();
 
536
                                                  mesh->cm.vert[i].K2() =  W.K2();
 
537
 
 
538
                                                  switch(ct)
 
539
                                                  {
 
540
                                                          case CT_MEAN: c = W.MeanCurvature(); break;
 
541
                                                          case CT_GAUSS: c = W.GaussCurvature(); break;
 
542
                                                          case CT_K1: c = W.K1(); break;
 
543
                                                          case CT_K2: c = W.K2(); break;
 
544
                                                          default: assert(0 && "invalid curvature type");
 
545
                                                  }
542
546
                                                }
 
547
                                                assert(!math::IsNAN(c) && "You should never try to compute Histogram with Invalid Floating points numbers (NaN)");
543
548
                                        }
544
549
                                        mesh->cm.vert[i].Q() = c;
545
550
                                        minc = std::min(c,minc);