MeshSelectionT.hh 18.7 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
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
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
*                                                                            *
\*===========================================================================*/

42

Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63




//=============================================================================
//
//
//=============================================================================


#ifndef MESHSELECTION_HH
#define MESHSELECTION_HH


/*! \file MeshSelectionT.hh
    \brief Functions for selection on a mesh

*/

//== INCLUDES =================================================================

64
#include <OpenMesh/Core/Mesh/Handles.hh>
Jan Möbius's avatar
Jan Möbius committed
65 66 67 68 69 70 71 72 73 74
#include <vector>

//== FORWARDDECLARATIONS ======================================================

//== NAMESPACES ===============================================================

namespace MeshSelection {

//== DEFINITIONS ==============================================================

75

Jan Möbius's avatar
Jan Möbius committed
76 77 78 79 80
//===========================================================================
/** @name Vertex Selection
* @{ */
//===========================================================================

81 82
/** \brief Select given vertices of a mesh
 *   @param _mesh      Mesh to work on
83
 *   @param _vertices  Vertex indices to select
84
 */
Jan Möbius's avatar
Jan Möbius committed
85 86 87 88
template< typename MeshT >
inline
void selectVertices(MeshT* _mesh, const std::vector< int >& _vertices);

89 90 91 92 93 94 95 96 97 98 99 100
/** \brief Select given vertices of a mesh
 *   Same as selectVertices
 *   @param _mesh      Mesh to work on
 *   @param _vertices  Vertex index to select
 */
template< typename MeshT >
inline
void selectElements(MeshT* _mesh, const std::vector< int >& _vertices, OpenMesh::VertexHandle /*_tag*/)
{
  selectVertices(_mesh, _vertices);
}

101 102 103 104 105

/** \brief Unselect given vertices of a mesh
 *   @param _mesh      Mesh to work on
 *   @param _vertices  Vertex index to unselect
 */
Jan Möbius's avatar
Jan Möbius committed
106 107 108 109
template< typename MeshT >
inline
void unselectVertices(MeshT* _mesh, const std::vector< int >& _vertices);

110 111 112
/** \brief Select all vertices of a mesh
 *   @param _mesh      Mesh to work on
 */
Jan Möbius's avatar
Jan Möbius committed
113 114 115 116
template< typename MeshT >
inline
void selectAllVertices(MeshT* _mesh);

117 118 119
/** \brief Set all vertices to unselected
 *   @param _mesh      Mesh to work on
 */
Jan Möbius's avatar
Jan Möbius committed
120 121 122 123
template< typename MeshT >
inline
void clearVertexSelection(MeshT* _mesh);

124 125 126
/** \brief invert vertex selection
 *   @param _mesh      Mesh to work on
 */
Jan Möbius's avatar
Jan Möbius committed
127 128 129 130
template< typename MeshT >
inline
void invertVertexSelection(MeshT* _mesh);

131 132 133
/** \brief Select all vertices of the mesh which are boundary vertices
 *
 *   @param _mesh      Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
134 135 136 137 138
 */
template< typename MeshT >
inline
void selectBoundaryVertices(MeshT* _mesh);

139 140
/** \brief Shrink  vertex selection
 *   @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
141 142 143 144 145
 */
template< typename MeshT >
inline
void shrinkVertexSelection(MeshT* _mesh) ;

146 147
/** \brief Grow vertex selection
 *   @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
148 149 150 151 152
 */
template< typename MeshT >
inline
void growVertexSelection(MeshT* _mesh);

153 154 155 156
/** \brief Get the current vertex selection
 *
 *   @param _mesh Mesh to work on
 *   @return vector of selected vertex indices
Jan Möbius's avatar
Jan Möbius committed
157 158 159 160 161 162
 */
template< typename MeshT >
inline
std::vector< int > getVertexSelection(MeshT* _mesh);

/** Get the current vertex selection
163 164
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
165 166 167 168 169 170
 * @param _invert if true : vector has been inverted to save mem
 */
template< typename MeshT >
inline
std::vector< int > getVertexSelection(MeshT* _mesh, bool& _invert);

171
/** \brief Select all vertices belonging to the same boundary as _vh
Jan Möbius's avatar
Jan Möbius committed
172 173 174 175 176
 *
 * This function gets one vertex that has to be on a boundary.
 * Than the function will follow the boundary and mark all vertices
 * at it as selected.
 *
177
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
178 179 180 181 182 183
 * @param _vh handle of a boundary vertex
 */
template< typename MeshT >
inline
void selectBoundaryVertices(MeshT* _mesh, const typename MeshT::VertexHandle& _vh);

184 185 186
/** \brief Select for each vertex in _vertices all incident edges
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
187 188 189 190 191 192
 * @param _vertices List of vertices to be converted
 */
template< typename MeshT >
inline
void convertVertexToEdgeSelection(MeshT* _mesh, const std::vector< int >& _vertices);

193 194 195
/** \brief For each selected vertex select all incident edges
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
196 197 198 199 200
 */
template< typename MeshT >
inline
void convertVertexToEdgeSelection(MeshT* _mesh);

201 202 203
/** \brief Select for each vertex in _vertices all incident halfedges
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
204 205 206 207 208 209
 * @param _vertices List of vertices to be converted
 */
template< typename MeshT >
inline
void convertVertexToHalfedgeSelection(MeshT* _mesh, const std::vector< int >& _vertices);

210 211 212
/** \brief For each selected vertex select all incident halfedges
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
213 214 215 216 217
 */
template< typename MeshT >
inline
void convertVertexToHalfedgeSelection(MeshT* _mesh);

218 219 220
/** \brief  Select for each vertex in _vertices all adjacent faces
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
221 222 223 224 225 226
 * @param _vertices List of vertices to be converted
 */
template< typename MeshT >
inline
void convertVertexToFaceSelection(MeshT* _mesh, const std::vector< int >& _vertices);

227 228 229
/** \brief For each selected vertex select all adjacent faces
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
230 231 232 233 234
 */
template< typename MeshT >
inline
void convertVertexToFaceSelection(MeshT* _mesh);

235 236 237
/** \brief Convert vertex selection to feature selection
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
238 239 240 241 242
 */
template< typename MeshT >
inline
void convertVertexSelectionToFeatureVertices(MeshT* _mesh);

243 244 245
/** \brief  Convert feature selection to vertex selection
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
246 247 248 249 250
 */
template< typename MeshT >
inline
void convertFeatureVerticesToVertexSelection(MeshT* _mesh);

251 252 253
/** \brief Clear all features
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
254 255 256 257 258 259 260 261 262 263 264 265
 */
template< typename MeshT >
inline
void clearFeatureVertices(MeshT* _mesh);

/** @} */

//===========================================================================
/** @name Modeling Regions
* @{ */
//===========================================================================

266 267 268
/** \brief Set the area bit for all defined vertices
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
269 270
 * @param _vertices The vertices belonging to the modeling area
 * @param _type Bit to be changed ( Normally Modeling area is OpenMesh::Attributes::UNUSED << 1 )
Jan Möbius's avatar
Jan Möbius committed
271
 * @param _state New state to be set
Jan Möbius's avatar
Jan Möbius committed
272 273 274 275 276
 * */
template< typename MeshT >
inline
void setArea(MeshT* _mesh, const std::vector< int >& _vertices , unsigned int _type, bool _state);

277
/** \brief Reset Modeling Status for vertices
Jan Möbius's avatar
Jan Möbius committed
278
 *
279 280 281
 * @param _mesh Mesh to work on
 * @param _type Bit to be changed ( Normally Modeling area is OpenMesh::Attributes::UNUSED << 1 )
 * @param _state New state to be set
Jan Möbius's avatar
Jan Möbius committed
282 283 284 285 286 287 288 289 290 291 292 293
 * */
template< typename MeshT >
inline
void setArea(MeshT* _mesh , unsigned int _type, bool _state);

/** Get the current vertex selection
 */
template< typename MeshT >
inline
std::vector< int > getArea(MeshT* _mesh, unsigned int _type);

/** Get the current vertex selection
Jan Möbius's avatar
Jan Möbius committed
294 295 296
 *
 * @param _mesh Mesh to work on
 * @param _type Bit to be changed ( Normally Modeling area is OpenMesh::Attributes::UNUSED << 1 )
Jan Möbius's avatar
Jan Möbius committed
297 298 299 300 301 302 303 304 305 306 307 308 309
 * @param _invert if true : vector has been inverted to save mem
 */
template< typename MeshT >
inline
std::vector< int > getArea(MeshT* _mesh, unsigned int _type , bool& _invert);

/** @} */

//===========================================================================
/** @name Edge Selection
* @{ */
//===========================================================================

310 311 312 313 314
/** \brief Select given edges of a mesh
 * @param _mesh Mesh to work on
 * @param _edges Edge indices to select
 * @param _dihedral_angle_threshold If mesh has normals, dihedral angle must be greator than or equal to this threshold in order to be selected
 */
Jan Möbius's avatar
Jan Möbius committed
315 316
template< typename MeshT >
inline
317
void selectEdges(MeshT* _mesh, const std::vector< int >& _edges, const double _dihedral_angle_threshold = 0.0);
Jan Möbius's avatar
Jan Möbius committed
318

319 320 321 322 323 324 325 326 327 328 329 330 331 332

/** \brief Select given edges of a mesh
 *   Same as selectEdges
 * @param _mesh Mesh to work on
 * @param _edges Edge indices to select
 * @param _dihedral_angle_threshold If mesh has normals, dihedral angle must be greator than or equal to this threshold in order to be selected
 */
template< typename MeshT >
inline
void selectElements(MeshT* _mesh, const std::vector< int >& _edges, OpenMesh::EdgeHandle /*_tag*/)
{
  selectEdges(_mesh, _edges);
}

Jan Möbius's avatar
Jan Möbius committed
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
/// Unselect given edges of a mesh
template< typename MeshT >
inline
void unselectEdges(MeshT* _mesh, const std::vector< int >& _edges);

/// Select all edges of a mesh
template< typename MeshT >
inline
void selectAllEdges(MeshT* _mesh);

///  Set all edges to unselected
template< typename MeshT >
inline
void clearEdgeSelection(MeshT* _mesh);

/// Invert Edge selection
template< typename MeshT >
inline
void invertEdgeSelection(MeshT* _mesh);

/// Invert Edge selection
template< typename MeshT >
inline
void growEdgeSelection(MeshT* _mesh);

/// Select all boundary edges of a mesh
template< typename MeshT >
void selectBoundaryEdges(MeshT* _mesh);

/** Get the current edge selection
 */
template< typename MeshT >
inline
std::vector< int > getEdgeSelection(MeshT* _mesh);

/** Get the current edge selection
Jan Möbius's avatar
Jan Möbius committed
369
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
370 371 372 373 374 375 376 377
 * @param _invert if true : vector has been inverted to save mem
 */
template< typename MeshT >
inline
std::vector< int > getEdgeSelection(MeshT* _mesh, bool& _invert);

/**
 * Select for each edge in _edges all incident vertices
Jan Möbius's avatar
Jan Möbius committed
378
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
 * @param _edges List of edges to be converted
 */
template< typename MeshT >
inline
void convertEdgeToVertexSelection(MeshT* _mesh, const std::vector< int >& _edges);

/**
 * For each selected edge select all incident vertices
 */
template< typename MeshT >
inline
void convertEdgeToVertexSelection(MeshT* _mesh);

/**
 * Select for each edge in _edges all adjacent faces
Jan Möbius's avatar
Jan Möbius committed
394
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
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
 * @param _edges List of edges to be converted
 */
template< typename MeshT >
inline
void convertEdgeToFaceSelection(MeshT* _mesh, const std::vector< int >& _edges);

/**
 * For each selected edge select all adjacent faces
 */
template< typename MeshT >
inline
void convertEdgeToFaceSelection(MeshT* _mesh);

/**
 * For each selected edge select all halfedges
 */
template< typename MeshT >
inline
void convertEdgeToHalfedgeSelection(MeshT* _mesh);

/**
 * Convert edge selection to feature selection
 */
template< typename MeshT >
inline
void convertEdgeSelectionToFeatureEdges(MeshT* _mesh);

/**
 * Convert feature selection to edge selection
 */
template< typename MeshT >
inline
void convertFeatureEdgesToEdgeSelection(MeshT* _mesh);

/**
 * Clear all features
 */
template< typename MeshT >
inline
void clearFeatureEdges(MeshT* _mesh);


/** @} */

//===========================================================================
/** @name Halfedge Selection
* @{ */
//===========================================================================

444 445 446 447
/** \brief Select given halfedges of a mesh
 * @param _mesh Mesh to work on
 * @param _halfedges face indices to select
 */
Jan Möbius's avatar
Jan Möbius committed
448 449 450 451
template< typename MeshT >
inline
void selectHalfedges(MeshT* _mesh, const std::vector< int >& _halfedges);

452 453 454 455 456 457 458 459 460 461 462 463
/** \brief Select given halfedges of a mesh
 *   Same as selectHalfedges
 * @param _mesh Mesh to work on
 * @param _halfedges halfedge indices to select
 */
template< typename MeshT >
inline
void selectElements(MeshT* _mesh, const std::vector< int >& _halfedges, OpenMesh::HalfedgeHandle /*_tag*/)
{
  selectHalfedges(_mesh, _halfedges);
}

Jan Möbius's avatar
Jan Möbius committed
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
/// Unselect given edges of a mesh
template< typename MeshT >
inline
void unselectHalfedges(MeshT* _mesh, const std::vector< int >& _halfedges);

/// Select all edges of a mesh
template< typename MeshT >
inline
void selectAllHalfedges(MeshT* _mesh);

///  Set all edges to unselected
template< typename MeshT >
inline
void clearHalfedgeSelection(MeshT* _mesh);

/// Invert Edge selection
template< typename MeshT >
inline
void invertHalfedgeSelection(MeshT* _mesh);

/// Select all boundary edges of a mesh
template< typename MeshT >
void selectBoundaryHalfedges(MeshT* _mesh);

/** Get the current edge selection
 */
template< typename MeshT >
inline
std::vector< int > getHalfedgeSelection(MeshT* _mesh);

/**
 * For each halfedge select all incident vertices
 */
template< typename MeshT >
inline
void convertHalfedgeToVertexSelection(MeshT* _mesh);

/**
 * For each halfedge select all edges
 */
template< typename MeshT >
inline
void convertHalfedgeToEdgeSelection(MeshT* _mesh);

/**
 * For each halfedge select all incident faces
 */
template< typename MeshT >
inline
void convertHalfedgeToFaceSelection(MeshT* _mesh);

//===========================================================================
/** @name Face Selection
* @{ */
//===========================================================================

520 521 522 523
/** \brief Select given faces of a mesh
 * @param _mesh Mesh to work on
 * @param _faces face indices to select
 */
Jan Möbius's avatar
Jan Möbius committed
524 525 526 527
template< typename MeshT >
inline
void selectFaces(MeshT* _mesh, const std::vector< int >& _faces );

528 529 530 531 532 533 534 535 536 537 538 539
/** \brief Select given faces of a mesh
 *   Same as selectFaces
 * @param _mesh Mesh to work on
 * @param _faces face indices to select
 */
template< typename MeshT >
inline
void selectElements(MeshT* _mesh, const std::vector< int >& _faces, OpenMesh::FaceHandle /*_tag*/)
{
  selectFaces(_mesh, _faces);
}

Jan Möbius's avatar
Jan Möbius committed
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
/// Unselect given faces of a mesh
template< typename MeshT >
inline
void unselectFaces(MeshT* _mesh, const std::vector< int >& _faces );

/// Select all faces of a mesh
template< typename MeshT >
inline
void selectAllFaces(MeshT* _mesh);

/// Set all faces to unselected
template< typename MeshT >
inline
void clearFaceSelection(MeshT* _mesh);

/// Invert face selection
template< typename MeshT >
inline
void invertFaceSelection(MeshT* _mesh);

/// Select all boundary faces of a mesh
template< typename MeshT >
void selectBoundaryFaces(MeshT* _mesh);

/** \brief Shrink Face selection
 *
 * Deselects all faces which are adjacent to a boundary vertex of the original selection
 */
template< typename MeshT >
inline
void shrinkFaceSelection(MeshT* _mesh);

/** \brief Grow Face selection
 *
 * Selects all faces which are adjacent to a vertex of a already selected face.
 */
template< typename MeshT >
inline
void growFaceSelection(MeshT* _mesh);

/** Get the current face selection
 */
template< typename MeshT >
inline
std::vector< int > getFaceSelection(MeshT* _mesh);

/** Get the current face selection
Jan Möbius's avatar
Jan Möbius committed
587 588
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
589 590 591 592 593 594 595 596
 * @param _invert if true : vector has been inverted to save mem
 */
template< typename MeshT >
inline
std::vector< int > getFaceSelection(MeshT* _mesh, bool& _invert);

/**
 * Select for each face in _faces all adjacent vertices
Jan Möbius's avatar
Jan Möbius committed
597 598
 *
 * @param _mesh Mesh to work on
Jan Möbius's avatar
Jan Möbius committed
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
 * @param _faces List of faces to be converted
 */
template< typename MeshT >
inline
void convertFaceToVertexSelection(MeshT* _mesh, const std::vector< int >& _faces);

/**
 * For each selected face select all adjacent vertices
 */
template< typename MeshT >
inline
void convertFaceToVertexSelection(MeshT* _mesh);

/**
 * For each selected face select all adjacent edges
 */
template< typename MeshT >
inline
void convertFaceToEdgeSelection(MeshT* _mesh);

/**
 * For each selected face select all incident halfedges
 */
template< typename MeshT >
inline
void convertFaceToHalfedgeSelection(MeshT* _mesh);

/**
 * Convert face selection to feature selection
 */
template< typename MeshT >
inline
void convertFaceSelectionToFeatureFaces(MeshT* _mesh);

/**
 * Convert feature selection to edge selection
 */
template< typename MeshT >
inline
void convertFeatureFacesToFaceSelection(MeshT* _mesh);

/**
 * Clear all features
 */
template< typename MeshT >
inline
void clearFeatureFaces(MeshT* _mesh);

/** @} */

//=============================================================================
} // MeshSelection Namespace
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(MESHSELECTION_C)
#define MESHSELECTION_TEMPLATES
654
#include "MeshSelectionT_impl.hh"
Jan Möbius's avatar
Jan Möbius committed
655 656 657 658 659
#endif
//=============================================================================
#endif // MESHSELECTION_HH defined
//=============================================================================