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
|
////////////////////////////////////////////////////////////////////////////////
//
// PartialTriang.hh
//
// produced: 30/04/98 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef PARTIALTRIANG_HH
#define PARTIALTRIANG_HH
#include "Message.hh"
#include "SimplicialComplex.hh"
#include "SparseSimplicialComplex.hh"
#include "FastSimplicialComplex.hh"
#include "CommandlineOptions.hh"
#include "Field.hh"
#include "Permutation.hh"
#include "PointConfiguration.hh"
#include "Chirotope.hh"
#include "Circuits.hh"
#include "Facets.hh"
#include "Admissibles.hh"
#include "Incidences.hh"
#include "Volumes.hh"
namespace topcom {
typedef SimplicialComplex pt_complex_type;
// the following is an auxiliary class to make possible
// to read the object-specific data for a PartialTriang;
// PartialTriang then has a constructor from
// the global context data and PartialTriangReader:
class PartialTriangReader {
public:
pt_complex_type partial_triang; // the SimplicialComplex part of a PartialTriang
SimplicialComplex admissibles;
SimplicialComplex freeintfacets;
#ifdef USE_CONFFACETS
facets_data freeconffacets;
#endif
Field covered_volume;
public:
// the only functionality is to read data into the member fields:
inline std::istream& read(std::istream& ist) {
char c;
// the expected syntax should be idential to the write syntax of PartialTriang:
if (!(ist >> std::ws >> c >> std::ws) || (c != ContainerChars::list_start_char)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading - expected "
<< ContainerChars::list_start_char
<< " - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> partial_triang)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading partial_triang - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> std::ws >> c >> std::ws) || (c != ContainerChars::delim_char)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading - expected "
<< ContainerChars::delim_char
<< "after partial_triang - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> admissibles)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading admissibles - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> std::ws >> c >> std::ws) || (c != ContainerChars::delim_char)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading - expected "
<< ContainerChars::delim_char
<< "after _admissibles - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> freeintfacets)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading freeintfacets - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> std::ws >> c >> std::ws) || (c != ContainerChars::delim_char)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading - expected "
<< ContainerChars::delim_char
<< "after _freeintfacets - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
#ifdef USE_CONFFACETS
if (!(ist >> freeconffacets)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading freeconffacets - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> std::ws >> c >> std::ws) || (c != ContainerChars::delim_char)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading - expected "
<< ContainerChars::delim_char
<< "after _freeconffacets - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
#endif
if (!(ist >> covered_volume)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading covered_volume - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
if (!(ist >> std::ws >> c >> std::ws) || (c != ContainerChars::list_end_char)) {
MessageStreams::forced() << message::lock
<< "PartialTriangReader::read(std::istream& ist): error while reading - expected "
<< ContainerChars::list_end_char
<< "at end of data record - exiting"
<< std::endl
<< message::unlock;
exit(1);
}
return ist;
}
inline friend std::istream& operator>>(std::istream& ist, PartialTriangReader& ptr) {
return ptr.read(ist);
}
};
class PartialTriang : public pt_complex_type {
private:
parameter_type _no;
parameter_type _rank;
const Admissibles* _admtableptr;
const Incidences* _inctableptr;
const Volumes* _voltableptr;
SimplicialComplex _admissibles;
SimplicialComplex _freeintfacets;
#ifdef USE_CONFFACETS
facets_data _freeconffacets;
#endif
Field _covered_volume;
private:
PartialTriang();
public:
// constructors:
inline PartialTriang(const parameter_type no,
const parameter_type rank,
const Facets* facetsptr,
const Admissibles* admtableptr,
const Incidences* inctableptr,
const Volumes* voltableptr);
inline PartialTriang(const parameter_type no,
const parameter_type rank,
const Admissibles* admtableptr,
const Incidences* inctableptr,
const Volumes* voltableptr,
PartialTriangReader&& ptr);
inline PartialTriang(const PartialTriang& pt);
inline PartialTriang(PartialTriang&& pt);
inline PartialTriang(const PartialTriang& pt, const Simplex& new_simp);
inline PartialTriang(const PartialTriang& pt,
const Simplex& new_simp,
const SimplicialComplex& forbidden);
// destructor:
inline ~PartialTriang();
// assignments:
inline PartialTriang& operator=(const PartialTriang& pt);
inline PartialTriang& operator=(PartialTriang&& pt);
// accessors:
inline const SimplicialComplex& simplicial_complex() const { return *this; }
inline const parameter_type no() const { return _no; }
inline const parameter_type rank() const { return _rank; }
inline const Admissibles* admtableptr() const { return _admtableptr; }
inline const Incidences* inctableptr() const { return _inctableptr; }
inline const Volumes* voltableptr() const { return _voltableptr; }
inline const SimplicialComplex& admissibles() const { return _admissibles; }
inline const SimplicialComplex& freeintfacets() const { return _freeintfacets; }
#ifdef USE_CONFFACETS
inline const facets_data& freeconffacets() const { return _freeconffacets; }
#endif
inline const Field& covered_volume() const { return _covered_volume; }
// functions:
inline PartialTriang& add_simplices(const SimplicialComplex& sc);
inline void forbid(const Simplex&);
inline void forbid(const SimplicialComplex&);
inline bool complete();
private:
// internal algorithms:
void _add_simplex(const Simplex& simp);
void _add_simplex(const Simplex& simp, const SimplicialComplex& forbidden);
void _update_admissibles(const Simplex& simp);
void _update_admissibles(const Simplex& simp, const SimplicialComplex& forbidden);
void _update_freefacets(const Simplex& simp);
void _update_volume(const Simplex& simp);
// stream intput/output:
inline std::istream& read(std::istream&);
inline friend std::istream& operator>>(std::istream&, PartialTriang&);
inline std::ostream& write(std::ostream&) const;
inline friend std::ostream& operator<<(std::ostream&, const PartialTriang&);
};
// constructors:
inline PartialTriang::PartialTriang(const parameter_type no,
const parameter_type rank,
const Facets* facetsptr,
const Admissibles* admtableptr,
const Incidences* inctableptr,
const Volumes* voltableptr) :
pt_complex_type(),
_no(no),
_rank(rank),
_admtableptr(admtableptr),
_inctableptr(inctableptr),
_voltableptr(voltableptr),
_admissibles(admtableptr->simplices()),
_freeintfacets(),
#ifdef USE_CONFFACETS
_freeconffacets(*facetsptr),
#endif
_covered_volume(FieldConstants::ZERO) {}
// the following constructor initializes a partial triangulation
// from pointers to the global data and a PartialTriangReader object
// containing the object data read from an input stream;
// after this call, the reader maybe undefined because its data is moved:
inline PartialTriang::PartialTriang(const parameter_type no,
const parameter_type rank,
const Admissibles* admtableptr,
const Incidences* inctableptr,
const Volumes* voltableptr,
PartialTriangReader&& ptr) :
pt_complex_type(std::move(ptr.partial_triang)),
_no(no),
_rank(rank),
_admtableptr(admtableptr),
_inctableptr(inctableptr),
_voltableptr(voltableptr),
_admissibles(std::move(ptr.admissibles)),
_freeintfacets(std::move(ptr.freeintfacets)),
#ifdef USE_CONFFACETS
_freeconffacets(std::move(ptr.freeconffacets)),
#endif
_covered_volume(std::move(ptr.covered_volume)) {
}
inline PartialTriang::PartialTriang(const PartialTriang& pt) :
pt_complex_type(pt),
_no(pt._no),
_rank(pt._rank),
_admtableptr(pt._admtableptr),
_inctableptr(pt._inctableptr),
_voltableptr(pt._voltableptr),
_admissibles(pt._admissibles),
_freeintfacets(pt._freeintfacets),
#ifdef USE_CONFFACETS
_freeconffacets(pt._freeconffacets),
#endif
_covered_volume(pt._covered_volume) {
#ifdef CONSTRUCTOR_DEBUG
MessageStreams::debug() << message::lock
<< "PartialTriang::PartialTriang(const PartialTriang& pt): copy constructur called" << std::endl
<< message::unlock;
#endif
}
inline PartialTriang::PartialTriang(PartialTriang&& pt) :
pt_complex_type(std::move(pt)),
_no(pt._no),
_rank(pt._rank),
_admtableptr(pt._admtableptr),
_inctableptr(pt._inctableptr),
_voltableptr(pt._voltableptr),
_admissibles(std::move(pt._admissibles)),
_freeintfacets(std::move(pt._freeintfacets)),
#ifdef USE_CONFFACETS
_freeconffacets(std::move(pt._freeconffacets)),
#endif
_covered_volume(std::move(pt._covered_volume)) {
#ifdef CONSTRUCTOR_DEBUG
MessageStreams::debug() << message::lock
<< "PartialTriang::PartialTriang(PartialTriang&& pt): move constructur called" << std::endl
<< message::unlock;
#endif
}
inline PartialTriang::PartialTriang(const PartialTriang& pt, const Simplex& new_simp) :
pt_complex_type(pt),
_no(pt._no),
_rank(pt._rank),
_admtableptr(pt._admtableptr),
_inctableptr(pt._inctableptr),
_voltableptr(pt._voltableptr),
_admissibles(pt._admissibles),
_freeintfacets(pt._freeintfacets),
#ifdef USE_CONFFACETS
_freeconffacets(pt._freeconffacets),
#endif
_covered_volume(pt._covered_volume) {
_add_simplex(new_simp);
}
inline PartialTriang::PartialTriang(const PartialTriang& pt,
const Simplex& new_simp,
const SimplicialComplex& forbidden) :
pt_complex_type(pt),
_no(pt._no),
_rank(pt._rank),
_inctableptr(pt._inctableptr),
_admtableptr(pt._admtableptr),
_voltableptr(pt._voltableptr),
_admissibles(pt._admissibles),
_freeintfacets(pt._freeintfacets),
#ifdef USE_CONFFACETS
_freeconffacets(pt._freeconffacets),
#endif
_covered_volume(pt._covered_volume) {
_add_simplex(new_simp, forbidden);
}
// destructor:
inline PartialTriang::~PartialTriang() {}
// assignment:
inline PartialTriang& PartialTriang::operator=(const PartialTriang& pt) {
#ifdef CONSTRUCTOR_DEBUG
MessageStreams::debug() << message::lock
<< "PartialTriang& PartialTriang::operator=(const PartialTriang& pt): copy assignment operator called" << std::endl
<< message::unlock;
#endif
if (this == &pt) {
return *this;
}
pt_complex_type::operator=(pt);
_no = pt._no;
_rank = pt._rank;
_inctableptr = pt._inctableptr;
_admtableptr = pt._admtableptr;
_voltableptr = pt._voltableptr;
_admissibles = pt._admissibles;
_freeintfacets = pt._freeintfacets;
#ifdef USE_CONFFACETS
_freeconffacets = pt._freeconffacets;
#endif
_covered_volume = pt._covered_volume;
return *this;
}
inline PartialTriang& PartialTriang::operator=(PartialTriang&& pt) {
#ifdef CONSTRUCTOR_DEBUG
MessageStreams::debug() << message::lock
<< "PartialTriang& PartialTriang::operator=(PartialTriang&& pt): move assignment operator called" << std::endl
<< message::unlock;
#endif
if (this == &pt) {
return *this;
}
pt_complex_type::operator=(std::move(pt));
_no = pt._no;
_rank = pt._rank;
_inctableptr = pt._inctableptr;
_admtableptr = pt._admtableptr;
_voltableptr = pt._voltableptr;
_admissibles = std::move(pt._admissibles);
_freeintfacets = std::move(pt._freeintfacets);
#ifdef USE_CONFFACETS
_freeconffacets = std::move(pt._freeconffacets);
#endif
_covered_volume = std::move(pt._covered_volume);
return *this;
}
// functions:
// the following is useful if we want to update an already initialized
// PartialTriang with the simplices of a SimplicialComplex
// (like in the case when we read into an empty PartialTriang):
inline PartialTriang& PartialTriang::add_simplices(const SimplicialComplex& sc) {
for (SimplicialComplex::const_iterator iter = sc.begin();
iter != sc.end();
++iter) {
_add_simplex(*iter);
}
return *this;
}
inline void PartialTriang::forbid(const Simplex& simp) {
_admissibles -= simp;
}
inline void PartialTriang::forbid(const SimplicialComplex& sc) {
_admissibles -= sc;
}
inline bool PartialTriang::complete() {
if (_freeintfacets.empty()) {
return true;
}
for (SimplicialComplex::iterator iter = _admissibles.begin();
iter != _admissibles.end();
++iter) {
PartialTriang new_partialtriang(*this, *iter);
if (new_partialtriang.complete()) {
*this = std::move(new_partialtriang);
return true;
}
}
return false;
}
// internal algorithms:
inline void PartialTriang::_add_simplex(const Simplex& simp) {
// *this += simp;
this->insert(simp);
_update_admissibles(simp);
_update_freefacets(simp);
_update_volume(simp);
}
inline void PartialTriang::_add_simplex(const Simplex& simp, const SimplicialComplex& forbidden) {
// *this += simp;
this->insert(simp);
_update_admissibles(simp, forbidden);
_update_freefacets(simp);
_update_volume(simp);
}
inline void PartialTriang::_update_admissibles(const Simplex& simp) {
#ifdef TOPCOM_CONTAINERS
_admissibles *= _admtableptr->find(simp)->data();
#else
_admissibles *= _admtableptr->find(simp)->second;
#endif
}
inline void PartialTriang::_update_admissibles(const Simplex& simp,
const SimplicialComplex& forbidden) {
#ifdef DEBUG
MessageStreams::debug() << message::lock
<< "adm before: " << _admissibles << '\n';
MessageStreams::debug() << message::lock
<< "adm of new simp: " << _admtableptr->find(simp)->second << '\n';
MessageStreams::debug() << message::lock
<< "forbidden: " << forbidden << std::endl
<< message::unlock;
#endif
#ifdef TOPCOM_CONTAINERS
_admissibles *= _admtableptr->find(simp)->data();
#else
_admissibles *= _admtableptr->find(simp)->second;
#endif
_admissibles -= forbidden;
#ifdef DEBUG
MessageStreams::debug() << message::lock
<< "adm after: " << _admissibles << '\n';
#endif
}
inline void PartialTriang::_update_freefacets(const Simplex& simp) {
#ifdef TOPCOM_CONTAINERS
_freeintfacets ^= _inctableptr->intfacets().find(simp)->data();
#ifdef USE_CONFFACETS
const facets_data& covered_conffacets(_inctableptr->conffacets().find(simp)->data());
#endif
#else
_freeintfacets ^= _inctableptr->intfacets().find(simp)->second;
#ifdef USE_CONFFACETS
const facets_data& covered_conffacets(_inctableptr->conffacets().find(simp)->second);
#endif
#endif
#ifdef USE_CONFFACETS
for (facets_data::const_iterator conffacets_iter = covered_conffacets.begin();
conffacets_iter != covered_conffacets.end();
++conffacets_iter) {
_freeconffacets.erase(*conffacets_iter);
}
#endif
}
inline void PartialTriang::_update_volume(const Simplex& simp) {
if (_voltableptr && !_voltableptr->empty()) {
_covered_volume += _voltableptr->find(simp)->second;
}
}
// stream intput/output:
inline std::istream& PartialTriang::read(std::istream& ist) {
MessageStreams::debug() << message::lock
<< "std::istream& read(std::istream& ist): "
<< "reading not supported because of pointers to global data - exiting"
<< std::endl
<< message::unlock;
exit(1);
return ist;
}
inline std::istream& operator>>(std::istream& ist, PartialTriang& pt) {
return pt.read(ist);
}
inline std::ostream& PartialTriang::write(std::ostream& ost) const {
ost << ContainerChars::list_start_char
<< simplicial_complex()
<< ContainerChars::delim_char
<< _admissibles
<< ContainerChars::delim_char
<< _freeintfacets
#ifdef USE_CONFFACETS
<< ContainerChars::delim_char
<< _freeconffacets
#endif
<< ContainerChars::delim_char
<< _covered_volume
<< ContainerChars::list_end_char;
return ost;
}
inline std::ostream& operator<<(std::ostream& ost, const PartialTriang& pt) {
return pt.write(ost);
}
}; // namespace topcom
#endif
// eof PartialTriang.hh
|