1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
|
#include "config_mesh_3.h"
#include "Mesh_3_plugin_cgal_code.h"
#include <CGAL/Real_timer.h>
#include <C3t3_type.h>
#include <CGAL/Mesh_3/polylines_to_protect.h>
#include <CGAL/Bbox_3.h>
#include <Scene_c3t3_item.h>
#include <vector>
#include "Mesh_function.h"
#include "Facet_extra_criterion.h"
#include <CGAL/Mesh_3/Detect_features_in_image.h>
#include <CGAL/Mesh_3/Detect_features_on_image_bbox.h>
using namespace CGAL::Three;
typedef Tr::Bare_point Bare_point;
Meshing_thread* cgal_code_mesh_3(QList<const SMesh*> pMeshes,
const Polylines_container& polylines,
const SMesh* pBoundingMesh,
QString filename,
const double facet_angle,
const double facet_sizing,
const double facet_min_sizing,
const double facet_approx,
const double tet_sizing,
const double tet_min_sizing,
const double edge_size,
const double edge_min_size,
const double edge_distance,
const double tet_shape,
bool protect_features,
bool protect_borders,
const double sharp_edges_angle,
const int manifold,
const bool surface_only)
{
if(pMeshes.empty() && nullptr == pBoundingMesh) return 0;
std::cerr << "Meshing file \"" << qPrintable(filename) << "\"\n";
std::cerr << " angle: " << facet_angle << std::endl
<< " edge size bound: " << edge_size << std::endl
<< " edge min size bound: " << edge_min_size << std::endl
<< " edge distance bound: " << edge_distance << std::endl
<< " facets size bound: " << facet_sizing << std::endl
<< " approximation bound: " << facet_approx << std::endl;
if (!surface_only)
std::cerr << " tetrahedra size bound: " << tet_sizing << std::endl;
std::cerr << "Build AABB tree...";
CGAL::Real_timer timer;
timer.start();
// Create domain
Polyhedral_mesh_domain* p_domain = nullptr;
if (surface_only || nullptr == pBoundingMesh)
p_domain = new Polyhedral_mesh_domain(pMeshes.begin(), pMeshes.end());
else if(pMeshes.empty())
p_domain = new Polyhedral_mesh_domain(*pBoundingMesh);
else
p_domain = new Polyhedral_mesh_domain(pMeshes.begin(), pMeshes.end(),
*pBoundingMesh);
// Features
if(polylines.empty()) {
if(protect_features) {
//includes detection of borders in the surface case
p_domain->detect_features(sharp_edges_angle);
}
else if (protect_borders) {
p_domain->detect_borders();
}
} else {
p_domain->add_features(polylines.begin(), polylines.end());
protect_features = true; // so that it will be passed in make_mesh_3
}
std::cerr << " done (" << timer.time() * 1000 << " ms)" << std::endl;
Scene_c3t3_item* p_new_item = new Scene_c3t3_item(surface_only);
if(polylines.empty()) {
if(protect_features) {
p_new_item->set_sharp_edges_angle(sharp_edges_angle);
}
else if (protect_borders) {
p_new_item->set_detect_borders(true);
}
}
QString tooltip = QString("<div>From \"") + filename +
QString("\" with the following mesh parameters"
"<ul>"
"<li>Angle: %1</li>"
"<li>Edge size bound: %2</li>"
"<li>Edge min size bound: %3</li>"
"<li>Edge distance bound: %4</li>"
"<li>Facets size bound: %5</li>"
"<li>Approximation bound: %6</li>")
.arg(facet_angle)
.arg(edge_size)
.arg(edge_min_size)
.arg(edge_distance)
.arg(facet_sizing)
.arg(facet_approx);
if (!surface_only)
tooltip += QString("<li>Tetrahedra size bound: %1</li>" )
.arg(tet_sizing);
tooltip += "</ul></div>";
p_new_item->setProperty("toolTip",tooltip);
Mesh_parameters param;
param.facet_angle = facet_angle;
param.facet_sizing = facet_sizing;
param.facet_approx = facet_approx;
param.tet_sizing = tet_sizing;
param.facet_min_sizing = facet_min_sizing;
param.tet_min_sizing = tet_min_sizing;
param.tet_shape = tet_shape;
param.edge_sizing = edge_size;
param.edge_min_sizing = edge_min_size;
param.edge_distance = edge_distance;
param.manifold = manifold;
param.protect_features = protect_features || protect_borders;
param.use_sizing_field_with_aabb_tree = polylines.empty() && protect_features;
param.image_3_ptr = nullptr;
param.weights_ptr = nullptr;
typedef ::Mesh_function<Polyhedral_mesh_domain,
Mesh_fnt::Polyhedral_domain_tag> Mesh_function;
Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(),
p_domain, param);
return new Meshing_thread(p_mesh_function, p_new_item);
}
Meshing_thread* cgal_code_mesh_3(const QList<const SMesh*> pMeshes,
const QList<std::pair<int, int> >& incident_subdomains,
QString filename,
const double facet_angle,
const double facet_sizing,
const double facet_min_sizing,
const double facet_approx,
const double tet_sizing,
const double tet_min_sizing,
const double edge_size,
const double edge_min_size,
const double edge_distance,
const double tet_shape,
bool protect_features,
bool protect_borders,
const double sharp_edges_angle,
const int manifold,
const bool surface_only)
{
if (pMeshes.empty() && incident_subdomains.empty()) return 0;
std::cerr << "Meshing file \"" << qPrintable(filename) << "\"\n";
std::cerr << " angle: " << facet_angle << std::endl
<< " edge size bound: " << edge_size << std::endl
<< " edge min size bound: " << edge_min_size << std::endl
<< " edge distance bound: " << edge_distance << std::endl
<< " facets size bound: " << facet_sizing << std::endl
<< " approximation bound: " << facet_approx << std::endl;
if (!surface_only)
std::cerr << " tetrahedra size bound: " << tet_sizing << std::endl;
CGAL::Real_timer timer;
timer.start();
std::vector<SMesh> patches;
std::transform(pMeshes.begin(), pMeshes.end(),
std::back_inserter(patches),
[](const SMesh* sm) {
return *sm;
});
// Create domain
Polyhedral_complex_mesh_domain* p_domain
= new Polyhedral_complex_mesh_domain(patches.begin(),
patches.end(),
incident_subdomains.begin(),
incident_subdomains.end());
// Features
if (protect_features) {
//includes detection of borders in the surface case
p_domain->detect_features(sharp_edges_angle);
}
else if (protect_borders) {
p_domain->detect_borders();
}
Scene_c3t3_item* p_new_item = new Scene_c3t3_item(surface_only);
if (protect_features) {
p_new_item->set_sharp_edges_angle(sharp_edges_angle);
}
else if (protect_borders) {
p_new_item->set_detect_borders(true);
}
QString tooltip = QString("<div>From \"") + filename +
QString("\" with the following mesh parameters"
"<ul>"
"<li>Angle: %1</li>"
"<li>Edge size bound: %2</li>"
"<li>Edge min size bound :%3</li>"
"<li>Edge distance bound: %4</li>"
"<li>Facets size bound: %5</li>"
"<li>Approximation bound: %6</li>")
.arg(facet_angle)
.arg(edge_size)
.arg(edge_min_size)
.arg(edge_distance)
.arg(facet_sizing)
.arg(facet_approx);
if (!surface_only)
tooltip += QString("<li>Tetrahedra size bound: %1</li>")
.arg(tet_sizing);
tooltip += "</ul></div>";
p_new_item->setProperty("toolTip", tooltip);
Mesh_parameters param;
param.facet_angle = facet_angle;
param.facet_sizing = facet_sizing;
param.facet_approx = facet_approx;
param.tet_sizing = tet_sizing;
param.facet_min_sizing = facet_min_sizing;
param.tet_min_sizing = tet_min_sizing;
param.tet_shape = tet_shape;
param.edge_sizing = edge_size;
param.edge_min_sizing = edge_min_size;
param.edge_distance = edge_distance;
param.manifold = manifold;
param.protect_features = protect_features || protect_borders;
param.use_sizing_field_with_aabb_tree = protect_features;
param.image_3_ptr = nullptr;
param.weights_ptr = nullptr;
typedef ::Mesh_function<Polyhedral_complex_mesh_domain,
Mesh_fnt::Polyhedral_domain_tag> Mesh_function;
Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(),
p_domain,
param);
return new Meshing_thread(p_mesh_function, p_new_item);
}
#ifdef CGAL_MESH_3_DEMO_ACTIVATE_IMPLICIT_FUNCTIONS
Meshing_thread* cgal_code_mesh_3(const Implicit_function_interface* pfunction,
const double facet_angle,
const double facet_sizing,
const double facet_min_sizing,
const double facet_approx,
const double tet_sizing,
const double tet_min_sizing,
const double edge_size,
const double edge_min_size,
const double edge_distance,
const double tet_shape,
const int manifold,
const bool surface_only)
{
if (pfunction == nullptr) { return nullptr; }
CGAL::Bbox_3 domain_bbox(pfunction->bbox().xmin(),
pfunction->bbox().ymin(),
pfunction->bbox().zmin(),
pfunction->bbox().xmax(),
pfunction->bbox().ymax(),
pfunction->bbox().zmax());
namespace p = CGAL::parameters;
Function_mesh_domain* p_domain =
new Function_mesh_domain(p::function = Function_wrapper(*pfunction), p::bounding_object = domain_bbox, p::relative_error_bound = 1e-7,
p::construct_surface_patch_index =
[](int i, int j) { return (i * 1000 + j); }
);
Scene_c3t3_item* p_new_item = new Scene_c3t3_item(surface_only);
Mesh_parameters param;
param.protect_features = false;
param.facet_angle = facet_angle;
param.facet_sizing = facet_sizing;
param.facet_min_sizing = facet_min_sizing;
param.facet_approx = facet_approx;
param.tet_sizing = tet_sizing;
param.tet_min_sizing = tet_min_sizing;
param.tet_shape = tet_shape;
param.edge_sizing = edge_size;
param.edge_min_sizing = edge_min_size;
param.edge_distance = edge_distance;
param.manifold = manifold;
param.detect_connected_components = false; // to avoid random values
// in the debug displays
param.image_3_ptr = nullptr;
param.weights_ptr = nullptr;
typedef ::Mesh_function<Function_mesh_domain,
Mesh_fnt::Implicit_domain_tag> Mesh_function;
Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(),
p_domain, param);
return new Meshing_thread(p_mesh_function, p_new_item);
}
#endif // CGAL_MESH_3_DEMO_ACTIVATE_IMPLICIT_FUNCTIONS
#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES
#include <CGAL/Labeled_mesh_domain_3.h>
typedef CGAL::Labeled_mesh_domain_3<Kernel, int, int> Gray_image_domain;
typedef CGAL::Mesh_domain_with_polyline_features_3<Gray_image_domain> Gray_Image_mesh_domain;
Meshing_thread* cgal_code_mesh_3(const Image* pImage,
const Polylines_container& polylines,
const double facet_angle,
const double facet_sizing,
const double facet_min_sizing,
const double facet_approx,
const double tet_sizing,
const double tet_min_sizing,
const double edge_size,
const double edge_min_size,
const double edge_distance,
const double tet_shape,
bool protect_features, //detect_polylines
const bool protect_borders,//polylines on bbox
const int manifold,
const bool surface_only,
bool detect_connected_components,
bool is_gray,
float iso_value,
float value_outside,
bool inside_is_less,
Image* pWeights)
{
if (nullptr == pImage) { return nullptr; }
Mesh_parameters param;
param.protect_features
= protect_features || protect_borders || !polylines.empty();
param.detect_connected_components = detect_connected_components;
param.iso_value = iso_value;
param.inside_is_less = inside_is_less;
param.facet_angle = facet_angle;
param.facet_sizing = facet_sizing;
param.facet_min_sizing = facet_min_sizing;
param.facet_approx = facet_approx;
param.tet_sizing = tet_sizing;
param.tet_min_sizing = tet_min_sizing;
param.facet_min_sizing = facet_min_sizing;
param.tet_min_sizing = tet_min_sizing;
param.edge_sizing = edge_size;
param.edge_min_sizing = edge_min_size;
param.edge_distance = edge_distance;
param.tet_shape = tet_shape;
param.manifold = manifold;
param.image_3_ptr = pImage;
param.weights_ptr = pWeights;
Scene_c3t3_item* p_new_item = new Scene_c3t3_item(surface_only);
QString tooltip = QString("\" With the following mesh parameters"
"<ul>"
"<li>Angle: %1</li>"
"<li>Edge size bound: %2</li>"
"<li>Edge min size bound: %3</li>"
"<li>Edge distance bound: %4</li>"
"<li>Facets size bound: %5</li>"
"<li>Approximation bound: %6</li>")
.arg(facet_angle)
.arg(edge_size)
.arg(edge_min_size)
.arg(edge_distance)
.arg(facet_sizing)
.arg(facet_approx);
if (!surface_only)
tooltip += QString("<li>Tetrahedra size bound: %1</li>")
.arg(tet_sizing);
tooltip += QString("<li>Use Weighted Image: %1</li>")
.arg(pWeights == nullptr ? "No" : "Yes");
tooltip += "</ul></div>";
p_new_item->setProperty("toolTip", tooltip);
if(!is_gray)
{
namespace p = CGAL::parameters;
Image_mesh_domain* p_domain = nullptr;
CGAL::Image_3 null_weights;
CGAL::Image_3& weights = (pWeights == nullptr) ? null_weights : *pWeights;
if (protect_features)
{
p_domain = new Image_mesh_domain
(Image_mesh_domain::create_labeled_image_mesh_domain
(p::image = *pImage,
p::weights = std::ref(weights), //used only if valid
p::relative_error_bound = 1e-6,
p::construct_surface_patch_index =
[](int i, int j) { return (i * 1000 + j); },
p::features_detector = CGAL::Mesh_3::Detect_features_in_image(),
p::input_features = std::cref(polylines)
)
);
}
else if (protect_borders)//protect polylines on image Bbox
{
p_domain = new Image_mesh_domain
(Image_mesh_domain::create_labeled_image_mesh_domain
(p::image = *pImage,
p::weights = std::ref(weights), //used only if valid
p::relative_error_bound = 1e-6,
p::construct_surface_patch_index =
[](int i, int j) { return (i * 1000 + j); },
p::features_detector = CGAL::Mesh_3::Detect_features_on_image_bbox(),
p::input_features = std::cref(polylines)
)
);
}
else if (!polylines.empty())
{
p_domain = new Image_mesh_domain
(Image_mesh_domain::create_labeled_image_mesh_domain
(p::image = *pImage,
p::relative_error_bound = 1e-6,
p::construct_surface_patch_index =
[](int i, int j) { return (i * 1000 + j); },
p::input_features = std::cref(polylines)
)
);
}
if (p_domain == nullptr)
{
p_domain = new Image_mesh_domain
(Image_mesh_domain::create_labeled_image_mesh_domain
(p::image = *pImage,
p::weights = std::ref(weights), //used only if valid
p::relative_error_bound = 1e-6,
p::construct_surface_patch_index =
[](int i, int j) { return (i * 1000 + j); }
)
);
}
typedef ::Mesh_function<Image_mesh_domain,
Mesh_fnt::Labeled_image_domain_tag> Mesh_function;
Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(),
p_domain, param);
return new Meshing_thread(p_mesh_function, p_new_item);
}
else
{
if(Compare_to_isovalue(iso_value, inside_is_less)(value_outside) !=0)
{
std::cerr << "Warning : \"Value inside is less than iso value\"'s value has been inverted to avoid crash. "
<< " " << std::endl;
inside_is_less = !inside_is_less;
}
Compare_to_isovalue domain_functor(iso_value, inside_is_less);
namespace p = CGAL::parameters;
Gray_Image_mesh_domain* p_domain = new Gray_Image_mesh_domain
(Gray_Image_mesh_domain::create_gray_image_mesh_domain
(p::image = *pImage,
p::relative_error_bound = 1e-6,
p::image_values_to_subdomain_indices = domain_functor,
p::value_outside = value_outside,
p::construct_surface_patch_index =
[](int i, int j) { return (i * 1000 + j); }
)
);
if(protect_features && polylines.empty())
{
using CGAL::Mesh_3::internal::Linear_interpolator;
std::vector<std::vector<Bare_point> > polylines_on_bbox;
CGAL_IMAGE_IO_CASE(pImage->image(),
typedef Word Image_word_type;
(CGAL::polylines_to_protect<Bare_point, Image_word_type>
( *pImage,
pImage->vx(),
pImage->vy(),
pImage->vz(),
polylines_on_bbox,
(Image_word_type*)0,
CGAL::Null_subdomain_index(),
domain_functor,
Linear_interpolator<Kernel, Image_word_type>(),
0,
0,
Image_word_type(iso_value),
(std::max)(10, int(10 * (std::min)((std::min)(pImage->vx(),
pImage->vy()),
pImage->vz())
/ edge_size))));
);
p_domain->add_features(polylines_on_bbox.begin(), polylines_on_bbox.end());
}
if(! polylines.empty()){
// Insert edge in domain
p_domain->add_features(polylines.begin(), polylines.end());
}
typedef ::Mesh_function<Gray_Image_mesh_domain,
Mesh_fnt::Gray_image_domain_tag> Mesh_function;
Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(),
p_domain, param);
return new Meshing_thread(p_mesh_function, p_new_item);
}
}
#endif //CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES
//#include "CGAL_Lab_mesh_3_plugin_cgal_code.moc"
//#include "Scene_c3t3_item.moc" //Check this one, it's strange moc include.
|