/usr/include/CGAL/IO/File_medit.h is in libcgal-dev 4.11-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | // Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France).
// Copyright (c) 2009 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Laurent RINEAU, Stephane Tayeb
#ifndef CGAL_IO_FILE_MEDIT_H
#define CGAL_IO_FILE_MEDIT_H
#include <CGAL/license/Mesh_3.h>
#include <CGAL/Mesh_3/config.h>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <CGAL/utility.h>
#include <CGAL/basic.h>
#include <boost/unordered_map.hpp>
namespace CGAL {
namespace Mesh_3 {
//-------------------------------------------------------
// Needed in verbose mode
//-------------------------------------------------------
#ifdef CGAL_MESH_3_IO_VERBOSE
template<class T>
inline
std::ostream&
operator<<(std::ostream &os, const std::pair<T,T>& pair)
{
return os << "<" << pair.first << "," << pair.second << ">";
}
#endif
// -----------------------------------
// Rebind_cell_pmap
// -----------------------------------
template <typename C3T3>
class Rebind_cell_pmap
{
typedef typename C3T3::Subdomain_index Subdomain_index;
typedef std::map<Subdomain_index,int> Subdomain_map;
typedef typename C3T3::Cell_handle Cell_handle;
typedef unsigned int size_type;
public:
Rebind_cell_pmap(const C3T3& c3t3)
: r_c3t3_(c3t3)
{
typedef typename C3T3::Cells_in_complex_iterator Cell_iterator;
int first_index = 0;
int index_counter = first_index + 1;
for( Cell_iterator cell_it = r_c3t3_.cells_in_complex_begin();
cell_it != r_c3t3_.cells_in_complex_end();
++cell_it)
{
// Add subdomain index in internal map if needed
std::pair<typename Subdomain_map::iterator, bool> is_insert_successful =
subdomain_map_.insert(std::make_pair(r_c3t3_.subdomain_index(cell_it),
index_counter));
if(is_insert_successful.second)
++index_counter;
}
// Rebind indices in alphanumeric order
index_counter = first_index + 1;
for ( typename Subdomain_map::iterator mit = subdomain_map_.begin() ;
mit != subdomain_map_.end() ;
++mit )
{
mit->second = index_counter++;
}
#ifdef CGAL_MESH_3_IO_VERBOSE
std::cerr << "Nb of subdomains: " << subdomain_map_.size() << "\n";
std::cerr << "Subdomain mapping:\n\t" ;
typedef typename Subdomain_map::iterator Subdomain_map_iterator;
for ( Subdomain_map_iterator sub_it = subdomain_map_.begin() ;
sub_it != subdomain_map_.end() ;
++sub_it )
{
std::cerr << "[" << (*sub_it).first << ":" << (*sub_it).second << "] ";
}
std::cerr << "\n";
#endif
}
int subdomain_index(const Cell_handle& ch) const
{
return subdomain_index(r_c3t3_.subdomain_index(ch));
}
size_type subdomain_number() const
{
return subdomain_map_.size();
}
private:
int subdomain_index(const Subdomain_index& index) const
{
typedef typename Subdomain_map::const_iterator Smi;
Smi elt_it = subdomain_map_.find(index);
if ( elt_it != subdomain_map_.end() )
return elt_it->second;
else
return -1;
}
private:
const C3T3& r_c3t3_;
Subdomain_map subdomain_map_;
};
// Accessor
template <typename C3T3>
int
get(const Rebind_cell_pmap<C3T3>& cmap,
const typename C3T3::Cell_handle& ch)
{
return cmap.subdomain_index(ch);
}
template <typename C3T3>
unsigned int get_size(const Rebind_cell_pmap<C3T3>& cmap)
{
return cmap.subdomain_number();
}
// -----------------------------------
// No_rebind_cell_pmap
// -----------------------------------
template <typename C3T3>
class No_rebind_cell_pmap
{
typedef typename C3T3::Subdomain_index Subdomain_index;
typedef typename C3T3::Cell_handle Cell_handle;
typedef unsigned int size_type;
public:
No_rebind_cell_pmap(const C3T3& c3t3)
: r_c3t3_(c3t3) {}
int subdomain_index(const Cell_handle& ch) const
{
return static_cast<int>(r_c3t3_.subdomain_index(ch));
}
size_type subdomain_number() const
{
typedef typename C3T3::Cells_in_complex_iterator Cell_iterator;
std::set<Subdomain_index> subdomain_set;
for( Cell_iterator cell_it = r_c3t3_.cells_in_complex_begin();
cell_it != r_c3t3_.cells_in_complex_end();
++cell_it)
{
// Add subdomain index in set
subdomain_set.insert(subdomain_index(cell_it));
}
return subdomain_set.size();
}
private:
const C3T3& r_c3t3_;
};
// Accessor
template <typename C3T3>
int
get(const No_rebind_cell_pmap<C3T3>& cmap,
const typename C3T3::Cell_handle& ch)
{
return cmap.subdomain_index(ch);
}
// -----------------------------------
// Rebind_facet_pmap
// -----------------------------------
template <typename C3T3, typename Cell_pmap>
class Rebind_facet_pmap
{
typedef typename C3T3::Surface_patch_index Surface_patch_index;
typedef std::map<Surface_patch_index,int> Surface_map;
typedef typename C3T3::Facet Facet;
typedef unsigned int size_type;
public:
Rebind_facet_pmap(const C3T3& c3t3, const Cell_pmap& cell_pmap)
: r_c3t3_(c3t3)
, cell_pmap_(cell_pmap)
{
typedef typename C3T3::Facets_in_complex_iterator Facet_iterator;
int first_index = 1;
int index_counter = first_index;
for( Facet_iterator facet_it = r_c3t3_.facets_in_complex_begin();
facet_it != r_c3t3_.facets_in_complex_end();
++facet_it)
{
// Add surface index in internal map if needed
std::pair<typename Surface_map::iterator, bool> is_insert_successful =
surface_map_.insert(std::make_pair(r_c3t3_.surface_patch_index(*facet_it),
index_counter));
if(is_insert_successful.second)
++index_counter;
}
// Find cell_pmap_ unused indices
typedef typename C3T3::Cells_in_complex_iterator Cell_iterator;
std::set<int> cell_label_set;
for( Cell_iterator cell_it = r_c3t3_.cells_in_complex_begin();
cell_it != r_c3t3_.cells_in_complex_end();
++cell_it)
{
// Add subdomain index in set
cell_label_set.insert(get(cell_pmap_, cell_it));
}
// Rebind indices
index_counter = get_first_unused_label(cell_label_set,first_index);
for ( typename Surface_map::iterator mit = surface_map_.begin() ;
mit != surface_map_.end() ;
++mit )
{
mit->second = index_counter++;
index_counter = get_first_unused_label(cell_label_set,index_counter);
}
#ifdef CGAL_MESH_3_IO_VERBOSE
std::cerr << "Nb of surface patches: " << surface_map_.size() << "\n";
std::cerr << "Surface mapping:\n\t" ;
typedef typename Surface_map::iterator Surface_map_iterator;
for ( Surface_map_iterator surf_it = surface_map_.begin() ;
surf_it != surface_map_.end() ;
++surf_it )
{
std::cerr << "[" << (*surf_it).first
<< ":" << (*surf_it).second << "] ";
}
std::cerr << "\n";
#endif
}
int surface_index(const Facet& f) const
{
return surface_index(r_c3t3_.surface_patch_index(f));
}
size_type surface_number() const
{
return surface_map_.size();
}
private:
int surface_index(const Surface_patch_index& index) const
{
typedef typename Surface_map::const_iterator Smi;
Smi elt_it = surface_map_.find(index);
if ( elt_it != surface_map_.end() )
return elt_it->second;
else
return -1;
}
int get_first_unused_label(const std::set<int>& label_set,
int search_start) const
{
while ( label_set.end() != label_set.find(search_start) )
++search_start;
return search_start;
}
private:
const C3T3& r_c3t3_;
const Cell_pmap& cell_pmap_;
Surface_map surface_map_;
};
// Accessors
template <typename C3T3, typename Cell_pmap>
int
get(const Rebind_facet_pmap<C3T3,Cell_pmap>& fmap,
const typename C3T3::Facet& f)
{
return fmap.surface_index(f);
}
template <typename C3T3, typename Cell_pmap>
unsigned int
get_size(const Rebind_facet_pmap<C3T3,Cell_pmap>& fmap,
const typename C3T3::Facet& f)
{
return fmap.surface_number(f);
}
// -----------------------------------
// No_rebind_facet_pmap
// -----------------------------------
template <typename C3T3, typename Cell_pmap>
class No_rebind_facet_pmap
{
typedef typename C3T3::Surface_patch_index Surface_patch_index;
typedef typename C3T3::Facet Facet;
typedef unsigned int size_type;
public:
No_rebind_facet_pmap(const C3T3& c3t3, const Cell_pmap& /*cell_pmap*/)
: r_c3t3_(c3t3) {}
int surface_index(const Facet& f) const
{
return static_cast<int>(r_c3t3_.surface_patch_index(f));
}
private:
const C3T3& r_c3t3_;
};
// Accessors
template <typename C3T3, typename Cell_pmap>
int
get(const No_rebind_facet_pmap<C3T3,Cell_pmap>& fmap,
const typename C3T3::Facet& f)
{
return fmap.surface_index(f);
}
// -----------------------------------
// No_rebind_facet_pmap_first
// -----------------------------------
template <typename C3T3, typename Cell_pmap>
class No_rebind_facet_pmap_first
{
typedef typename C3T3::Surface_patch_index Surface_patch_index;
typedef typename C3T3::Facet Facet;
typedef unsigned int size_type;
public:
No_rebind_facet_pmap_first(const C3T3& c3t3, const Cell_pmap& /*cell_pmap*/)
: r_c3t3_(c3t3) {}
int surface_index(const Facet& f) const
{
return static_cast<int>(r_c3t3_.surface_patch_index(f).first);
}
private:
const C3T3& r_c3t3_;
};
// Accessors
template <typename C3T3, typename Cell_pmap>
int
get(const No_rebind_facet_pmap_first<C3T3,Cell_pmap>& fmap,
const typename C3T3::Facet& f)
{
return fmap.surface_index(f);
}
// -----------------------------------
// No_rebind_facet_pmap_second
// -----------------------------------
template <typename C3T3, typename Cell_pmap>
class No_rebind_facet_pmap_second
{
typedef typename C3T3::Surface_patch_index Surface_patch_index;
typedef typename C3T3::Facet Facet;
typedef unsigned int size_type;
public:
No_rebind_facet_pmap_second(const C3T3& c3t3, const Cell_pmap& /*cell_pmap*/)
: r_c3t3_(c3t3) {}
int surface_index(const Facet& f) const
{
return static_cast<int>(r_c3t3_.surface_patch_index(f).second);
}
private:
const C3T3& r_c3t3_;
};
// Accessors
template <typename C3T3, typename Cell_pmap>
int
get(const No_rebind_facet_pmap_second<C3T3,Cell_pmap>& fmap,
const typename C3T3::Facet& f)
{
return fmap.surface_index(f);
}
// -----------------------------------
// No_patch_facet_pmap_first
// -----------------------------------
template <typename C3T3, typename Cell_pmap>
class No_patch_facet_pmap_first
{
typedef typename C3T3::Surface_patch_index Surface_patch_index;
typedef typename C3T3::Facet Facet;
typedef typename C3T3::Cell_handle Cell_handle;
public:
No_patch_facet_pmap_first(const C3T3&, const Cell_pmap& cell_pmap)
: cell_pmap_(cell_pmap) { }
int surface_index(const Facet& f) const
{
Cell_handle c1 = f.first;
Cell_handle c2 = c1->neighbor(f.second);
int label1 = get(cell_pmap_,c1);
int label2 = get(cell_pmap_,c2);
if ( 0 == label1 || -1 == label1 )
label1 = label2;
if ( 0 == label2 || -1 == label2 )
label2 = label1;
return (std::min)(label1,label2);
}
private:
const Cell_pmap& cell_pmap_;
};
// Accessors
template <typename C3T3, typename Cell_pmap>
int
get(const No_patch_facet_pmap_first<C3T3,Cell_pmap>& fmap,
const typename C3T3::Facet& f)
{
return fmap.surface_index(f);
}
// -----------------------------------
// No_patch_facet_pmap_second
// -----------------------------------
template <typename C3T3, typename Cell_pmap>
class No_patch_facet_pmap_second
{
typedef typename C3T3::Surface_patch_index Surface_patch_index;
typedef typename C3T3::Facet Facet;
typedef typename C3T3::Cell_handle Cell_handle;
public:
No_patch_facet_pmap_second(const C3T3&, const Cell_pmap& cell_pmap)
: cell_pmap_(cell_pmap) { }
int surface_index(const Facet& f) const
{
Cell_handle c1 = f.first;
Cell_handle c2 = c1->neighbor(f.second);
int label1 = get(cell_pmap_,c1);
int label2 = get(cell_pmap_,c2);
if ( 0 == label1 || -1 == label1 )
label1 = label2;
if ( 0 == label2 || -1 == label2 )
label2 = label1;
return (std::max)(label1,label2);
}
private:
const Cell_pmap& cell_pmap_;
};
// Accessors
template <typename C3T3, typename Cell_pmap>
int
get(const No_patch_facet_pmap_second<C3T3,Cell_pmap>& fmap,
const typename C3T3::Facet& f)
{
return fmap.surface_index(f);
}
// -----------------------------------
// Default_vertex_index_pmap
// -----------------------------------
template <typename C3T3, typename Cell_pmap, typename Facet_pmap>
class Default_vertex_pmap
{
typedef typename C3T3::Surface_patch_index Surface_patch_index;
typedef typename C3T3::Subdomain_index Subdomain_index;
typedef typename C3T3::Index Index;
typedef typename C3T3::Vertex_handle Vertex_handle;
typedef typename C3T3::Cell_handle Cell_handle;
typedef typename C3T3::Facet Facet;
public:
Default_vertex_pmap(const C3T3& c3t3,
const Cell_pmap& c_pmap,
const Facet_pmap& f_pmap)
: c_pmap_(c_pmap)
, f_pmap_(f_pmap)
, r_c3t3_(c3t3)
, edge_index_(0) {}
int index(const Vertex_handle& vh) const
{
switch ( r_c3t3_.in_dimension(vh) )
{
case 2:
{
// Check if each incident surface facet of vh has the same surface index
typename std::vector<Facet> facets;
r_c3t3_.triangulation().finite_incident_facets(
vh, std::back_inserter(facets));
if ( facets.begin() == facets.end() )
return -1;
// Look for the first surface facet
typename std::vector<Facet>::iterator it_facet = facets.begin();
while ( ! r_c3t3_.is_in_complex(*it_facet) )
{
if ( ++it_facet == facets.end() )
return -1;
}
Surface_patch_index facet_index = r_c3t3_.surface_patch_index(*it_facet);
Facet facet = *it_facet;
++it_facet;
for( ; it_facet != facets.end() ; ++it_facet)
{
// If another index is found, return value for edge vertice
if ( r_c3t3_.is_in_complex(*it_facet)
&& !( facet_index == r_c3t3_.surface_patch_index(*it_facet) ) )
return edge_index_;
}
return get(f_pmap_,facet);
}
break;
case 3:
{
// Returns value of any incident cell
typename std::vector<Cell_handle> cells;
r_c3t3_.triangulation().finite_incident_cells(
vh,std::back_inserter(cells));
if ( cells.begin() != cells.end() )
return get(c_pmap_, *cells.begin());
else
return -1;
}
break;
default:
// should not happen
return -1;
break;
}
}
private:
const Cell_pmap& c_pmap_;
const Facet_pmap& f_pmap_;
const C3T3& r_c3t3_;
const unsigned int edge_index_;
};
template <typename C3T3, typename Cell_pmap, typename Facet_pmap>
int
get(const Default_vertex_pmap<C3T3,Cell_pmap,Facet_pmap>& vmap,
const typename C3T3::Vertex_handle& vh)
{
return vmap.index(vh);
}
// -----------------------------------
// Null pmap
// -----------------------------------
template <typename C3T3, typename Cell_pmap>
struct Null_facet_pmap
{
Null_facet_pmap(const C3T3&, const Cell_pmap&) {}
};
template <typename C3T3, typename Cell_pmap>
int get(const Null_facet_pmap<C3T3,Cell_pmap>&,
const typename C3T3::Facet&)
{
return 0;
}
template <typename C3T3, typename Cell_pmap, typename Facet_pmap>
struct Null_vertex_pmap
{
Null_vertex_pmap(const C3T3&, const Cell_pmap&, const Facet_pmap&) {}
};
template <typename C3T3, typename Cell_pmap, typename Facet_pmap>
int get(const Null_vertex_pmap<C3T3, Cell_pmap, Facet_pmap>&,
const typename C3T3::Vertex_handle&)
{
return 0;
}
// -----------------------------------
// Generator
// -----------------------------------
template <typename C3T3, bool rebind, bool no_patch>
struct Medit_pmap_generator{};
template <typename C3T3>
struct Medit_pmap_generator<C3T3, true, false>
{
typedef Rebind_cell_pmap<C3T3> Cell_pmap;
typedef Rebind_facet_pmap<C3T3, Cell_pmap> Facet_pmap;
typedef Null_facet_pmap<C3T3, Cell_pmap> Facet_pmap_twice;
typedef Default_vertex_pmap<C3T3, Cell_pmap, Facet_pmap> Vertex_pmap;
bool print_twice() { return false; }
};
template <typename C3T3>
struct Medit_pmap_generator<C3T3, true, true>
{
typedef Rebind_cell_pmap<C3T3> Cell_pmap;
typedef No_patch_facet_pmap_first<C3T3,Cell_pmap> Facet_pmap;
typedef No_patch_facet_pmap_second<C3T3,Cell_pmap> Facet_pmap_twice;
typedef Default_vertex_pmap<C3T3, Cell_pmap, Facet_pmap> Vertex_pmap;
bool print_twice() { return true; }
};
template <typename C3T3>
struct Medit_pmap_generator<C3T3, false, true>
{
typedef No_rebind_cell_pmap<C3T3> Cell_pmap;
typedef No_patch_facet_pmap_first<C3T3,Cell_pmap> Facet_pmap;
typedef No_patch_facet_pmap_second<C3T3,Cell_pmap> Facet_pmap_twice;
typedef Default_vertex_pmap<C3T3, Cell_pmap, Facet_pmap> Vertex_pmap;
bool print_twice() { return true; }
};
template <typename C3T3>
struct Medit_pmap_generator<C3T3, false, false>
{
typedef No_rebind_cell_pmap<C3T3> Cell_pmap;
typedef Rebind_facet_pmap<C3T3,Cell_pmap> Facet_pmap;
typedef Null_facet_pmap<C3T3, Cell_pmap> Facet_pmap_twice;
typedef Null_vertex_pmap<C3T3, Cell_pmap, Facet_pmap> Vertex_pmap;
bool print_twice() { return false; }
};
//-------------------------------------------------------
// IO functions
//-------------------------------------------------------
template <class C3T3, bool rebind, bool no_patch>
void
output_to_medit(std::ostream& os,
const C3T3& c3t3)
{
#ifdef CGAL_MESH_3_IO_VERBOSE
std::cerr << "Output to medit:\n";
#endif
typedef Medit_pmap_generator<C3T3,rebind,no_patch> Generator;
typedef typename Generator::Cell_pmap Cell_pmap;
typedef typename Generator::Facet_pmap Facet_pmap;
typedef typename Generator::Facet_pmap_twice Facet_pmap_twice;
typedef typename Generator::Vertex_pmap Vertex_pmap;
Cell_pmap cell_pmap(c3t3);
Facet_pmap facet_pmap(c3t3,cell_pmap);
Facet_pmap_twice facet_pmap_twice(c3t3,cell_pmap);
Vertex_pmap vertex_pmap(c3t3,cell_pmap,facet_pmap);
output_to_medit(os,
c3t3,
vertex_pmap,
facet_pmap,
cell_pmap,
facet_pmap_twice,
Generator().print_twice());
#ifdef CGAL_MESH_3_IO_VERBOSE
std::cerr << "done.\n";
#endif
}
template <class C3T3,
class Vertex_index_property_map,
class Facet_index_property_map,
class Facet_index_property_map_twice,
class Cell_index_property_map>
void
output_to_medit(std::ostream& os,
const C3T3& c3t3,
const Vertex_index_property_map& vertex_pmap,
const Facet_index_property_map& facet_pmap,
const Cell_index_property_map& cell_pmap,
const Facet_index_property_map_twice& facet_twice_pmap = Facet_index_property_map_twice(),
const bool print_each_facet_twice = false)
{
typedef typename C3T3::Triangulation Tr;
typedef typename C3T3::Facets_in_complex_iterator Facet_iterator;
typedef typename C3T3::Cells_in_complex_iterator Cell_iterator;
typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator;
typedef typename Tr::Vertex_handle Vertex_handle;
typedef typename Tr::Weighted_point Weighted_point;
const Tr& tr = c3t3.triangulation();
//-------------------------------------------------------
// File output
//-------------------------------------------------------
//-------------------------------------------------------
// Header
//-------------------------------------------------------
os << std::setprecision(17);
os << "MeshVersionFormatted 1\n"
<< "Dimension 3\n";
//-------------------------------------------------------
// Vertices
//-------------------------------------------------------
os << "Vertices\n" << tr.number_of_vertices() << '\n';
boost::unordered_map<Vertex_handle, int> V;
int inum = 1;
for( Finite_vertices_iterator vit = tr.finite_vertices_begin();
vit != tr.finite_vertices_end();
++vit)
{
V[vit] = inum++;
Weighted_point p = vit->point();
os << CGAL::to_double(p.x()) << ' '
<< CGAL::to_double(p.y()) << ' '
<< CGAL::to_double(p.z()) << ' '
<< get(vertex_pmap, vit)
<< '\n';
}
//-------------------------------------------------------
// Facets
//-------------------------------------------------------
typename C3T3::size_type number_of_triangles = c3t3.number_of_facets_in_complex();
if ( print_each_facet_twice )
number_of_triangles += number_of_triangles;
os << "Triangles\n"
<< number_of_triangles << '\n';
for( Facet_iterator fit = c3t3.facets_in_complex_begin();
fit != c3t3.facets_in_complex_end();
++fit)
{
for (int i=0; i<4; i++)
{
if (i != fit->second)
{
const Vertex_handle& vh = (*fit).first->vertex(i);
os << V[vh] << ' ';
}
}
os << get(facet_pmap, *fit) << '\n';
// Print triangle again if needed
if ( print_each_facet_twice )
{
for (int i=0; i<4; i++)
{
if (i != fit->second)
{
const Vertex_handle& vh = (*fit).first->vertex(i);
os << V[vh] << ' ';
}
}
os << get(facet_twice_pmap, *fit) << '\n';
}
}
//-------------------------------------------------------
// Tetrahedra
//-------------------------------------------------------
os << "Tetrahedra\n"
<< c3t3.number_of_cells_in_complex() << '\n';
for( Cell_iterator cit = c3t3.cells_in_complex_begin() ;
cit != c3t3.cells_in_complex_end() ;
++cit )
{
for (int i=0; i<4; i++)
os << V[cit->vertex(i)] << ' ';
os << get(cell_pmap, cit) << '\n';
}
//-------------------------------------------------------
// End
//-------------------------------------------------------
os << "End\n";
} // end output_to_medit(...)
} // end namespace Mesh_3
/**
* @brief outputs mesh to medit format
* @param os the stream
* @param c3t3 the mesh
* @param rebind if true, labels of cells are rebinded into [1..nb_of_labels]
* @param show_patches if true, patches are labeled with different labels than
* cells. If false, each surface facet is written twice, using label of
* each adjacent cell.
*/
template <class C3T3>
void
output_to_medit(std::ostream& os,
const C3T3& c3t3,
bool rebind = false,
bool show_patches = false)
{
if ( rebind )
{
if ( show_patches )
Mesh_3::output_to_medit<C3T3,true,false>(os,c3t3);
else
Mesh_3::output_to_medit<C3T3,true,true>(os,c3t3);
}
else
{
if ( show_patches )
Mesh_3::output_to_medit<C3T3,false,false>(os,c3t3);
else
Mesh_3::output_to_medit<C3T3,false,true>(os,c3t3);
}
}
} // end namespace CGAL
#endif // CGAL_IO_FILE_MEDIT_H
|