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
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkQuadEdgeMesh_h
#define itkQuadEdgeMesh_h
#include <cstdarg>
#include <queue>
#include <vector>
#include <list>
#include "itkMesh.h"
#include "itkQuadEdgeMeshTraits.h"
#include "itkQuadEdgeMeshLineCell.h"
#include "itkQuadEdgeMeshPolygonCell.h"
#include "itkQuadEdgeMeshFrontIterator.h"
#include "itkConceptChecking.h"
namespace itk
{
/**
* \class QuadEdgeMesh
*
* \brief Mesh class for 2D manifolds embedded in ND space.
*
* \author Alexandre Gouaillard, Leonardo Florez-Valencia, Eric Boix
*
* This implementation was contributed as a paper to the Insight Journal
* https://www.insight-journal.org/browse/publication/122
*
* \ingroup ITKQuadEdgeMesh
*/
template <typename TPixel,
unsigned int VDimension,
typename TTraits = QuadEdgeMeshTraits<TPixel, VDimension, bool, bool>>
class ITK_TEMPLATE_EXPORT QuadEdgeMesh : public Mesh<TPixel, VDimension, TTraits>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(QuadEdgeMesh);
/** Input template parameters. */
using Traits = TTraits;
using PixelType = TPixel;
/** Standard type alias. */
using Self = QuadEdgeMesh;
using Superclass = Mesh<TPixel, VDimension, Traits>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** Convenient constants obtained from MeshTraits. */
static constexpr unsigned int PointDimension = Traits::PointDimension;
static constexpr unsigned int MaxTopologicalDimension = Traits::MaxTopologicalDimension;
/** Types defined in superclass. */
using typename Superclass::CellPixelType;
using typename Superclass::CoordRepType;
using typename Superclass::PointIdentifier;
using typename Superclass::PointHashType;
using typename Superclass::PointType;
using typename Superclass::CellTraits;
using PointIdInternalIterator = typename CellTraits::PointIdInternalIterator;
using PointIdIterator = typename CellTraits::PointIdIterator;
// Point section:
using typename Superclass::PointsContainer;
using typename Superclass::PointsContainerPointer;
using CoordRepArrayType = CoordRepType[Self::PointDimension];
// Point data section:
using typename Superclass::PointDataContainer;
using typename Superclass::PointDataContainerPointer;
using typename Superclass::PointDataContainerIterator;
using typename Superclass::PointsContainerConstIterator;
using typename Superclass::PointsContainerIterator;
// Cell section:
using typename Superclass::CellIdentifier;
using typename Superclass::CellType;
using typename Superclass::CellAutoPointer;
using typename Superclass::CellFeatureIdentifier;
using typename Superclass::CellFeatureCount;
using typename Superclass::CellMultiVisitorType;
using typename Superclass::CellsContainer;
using typename Superclass::CellsContainerPointer;
using typename Superclass::CellsContainerConstIterator;
using typename Superclass::CellsContainerIterator;
using typename Superclass::CellLinksContainer;
using typename Superclass::CellLinksContainerPointer;
using typename Superclass::CellLinksContainerIterator;
// Cell data section:
using typename Superclass::CellDataContainer;
using typename Superclass::CellDataContainerPointer;
using typename Superclass::CellDataContainerIterator;
// Point / Cell correspondence section:
using typename Superclass::PointCellLinksContainer;
using typename Superclass::PointCellLinksContainerIterator;
// BoundaryAssignments section:
using typename Superclass::BoundaryAssignmentsContainer;
using typename Superclass::BoundaryAssignmentsContainerPointer;
using typename Superclass::BoundaryAssignmentsContainerVector;
// Miscellaneous section:
using typename Superclass::BoundingBoxPointer;
using typename Superclass::BoundingBoxType;
using typename Superclass::RegionType;
using typename Superclass::InterpolationWeightType;
/** Specific types for a quad-edge structure. */
using PrimalDataType = typename Traits::PrimalDataType;
using DualDataType = typename Traits::DualDataType;
using QEPrimal = typename Traits::QEPrimal;
using QEDual = typename Traits::QEDual;
using QEType = typename Traits::QEPrimal;
// See the TODO entry dated from 2005-05-28
// struct QEType : public QEPrimal, public QEDual {}
using VertexRefType = typename Traits::VertexRefType;
using FaceRefType = typename Traits::FaceRefType;
using VectorType = typename Traits::VectorType;
/** Possible specialized cell types. */
using EdgeCellType = QuadEdgeMeshLineCell<CellType>;
using PolygonCellType = QuadEdgeMeshPolygonCell<CellType>;
/** Free insertion indexes. */
using FreePointIndexesType = std::queue<PointIdentifier>;
using FreeCellIndexesType = std::queue<CellIdentifier>;
/** Auxiliary types. */
using PointIdList = std::vector<PointIdentifier>;
using EdgeListType = std::list<QEPrimal *>;
using EdgeListPointerType = EdgeListType *;
using MeshClassCellsAllocationMethodEnum = itk::MeshEnums::MeshClassCellsAllocationMethod;
/** Reserved PointIdentifier designated to represent the absence of Point */
static const PointIdentifier m_NoPoint;
/** Reserved CellIdentifier designated to represent the absence of Face */
static const CellIdentifier m_NoFace;
public:
/** Basic Object interface. */
itkNewMacro(Self);
itkOverrideGetNameOfClassMacro(QuadEdgeMesh);
#if !defined(ITK_WRAPPING_PARSER)
/** FrontIterator definitions */
itkQEDefineFrontIteratorMethodsMacro(Self);
#endif
public:
// Multithreading framework: not tested yet.
bool
RequestedRegionIsOutsideOfTheBufferedRegion() override
{
return (false);
}
void
Initialize() override;
/** another way of deleting all the cells */
virtual void
Clear();
CellsContainer *
GetEdgeCells()
{
return m_EdgeCellsContainer;
}
const CellsContainer *
GetEdgeCells() const
{
return m_EdgeCellsContainer;
}
void
SetEdgeCells(CellsContainer * edgeCells)
{
m_EdgeCellsContainer = edgeCells;
}
void
SetEdgeCell(CellIdentifier cellId, CellAutoPointer & cellPointer)
{
m_EdgeCellsContainer->InsertElement(cellId, cellPointer.ReleaseOwnership());
}
/** Overloaded to avoid a bug in Mesh that prevents proper inheritance
* Refer to
* https://public.kitware.com/pipermail/insight-users/2005-March/012459.html
* and
* https://public.kitware.com/pipermail/insight-users/2005-April/012613.html
*/
void
CopyInformation(const DataObject * data) override
{
(void)data;
}
void
Graft(const DataObject * data) override;
/** squeeze the point container to be able to write the file properly */
void
SqueezePointsIds();
/** overloaded method for backward compatibility */
void
BuildCellLinks() const
{}
#if !defined(ITK_WRAPPING_PARSER)
/** overloaded method for backward compatibility */
void
SetBoundaryAssignments(int dimension, BoundaryAssignmentsContainer * container)
{
(void)dimension;
(void)container;
}
/** overloaded method for backward compatibility */
BoundaryAssignmentsContainerPointer
GetBoundaryAssignments(int dimension)
{
(void)dimension;
return (nullptr);
}
/** overloaded method for backward compatibility */
const BoundaryAssignmentsContainerPointer
GetBoundaryAssignments(int dimension) const
{
(void)dimension;
return (nullptr);
}
#endif
/** overloaded method for backward compatibility */
void
SetBoundaryAssignment(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellIdentifier boundaryId)
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)boundaryId;
}
/** overloaded method for backward compatibility */
bool
GetBoundaryAssignment(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellIdentifier * boundaryId) const
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)boundaryId;
return (false); // ALEX: is it the good way?
}
/** overloaded method for backward compatibility */
bool
RemoveBoundaryAssignment(int dimension, CellIdentifier cellId, CellFeatureIdentifier featureId)
{
(void)dimension;
(void)cellId;
(void)featureId;
return (false); // ALEX: is it the good way?
}
/** overloaded method for backward compatibility */
bool
GetCellBoundaryFeature(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellAutoPointer & cellAP) const
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)cellAP;
return (false);
}
/** overloaded method for backward compatibility */
CellIdentifier
GetCellBoundaryFeatureNeighbors(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
std::set<CellIdentifier> * cellSet)
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)cellSet;
return CellIdentifier{};
}
/** NOTE ALEX: this method do not use CellFeature and thus could be recoded */
CellIdentifier
GetCellNeighbors(CellIdentifier itkNotUsed(cellId), std::set<CellIdentifier> * itkNotUsed(cellSet))
{
return CellIdentifier{};
}
/** overloaded method for backward compatibility */
bool
GetAssignedCellBoundaryIfOneExists(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellAutoPointer & cellAP) const
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)cellAP;
return (false); // ALEX: is it the good way?
}
/** overloaded method for backward compatibility */
void
SetCell(CellIdentifier cId, CellAutoPointer & cell);
/** Methods to simplify point/edge insertion/search. */
virtual PointIdentifier
FindFirstUnusedPointIndex();
virtual CellIdentifier
FindFirstUnusedCellIndex();
virtual void
PushOnContainer(EdgeCellType * newEdge);
// Adding Point/Edge/Face methods
virtual PointIdentifier
AddPoint(const PointType & p);
/** */
virtual QEPrimal *
AddEdge(const PointIdentifier & orgPid, const PointIdentifier & destPid);
virtual QEPrimal *
AddEdgeWithSecurePointList(const PointIdentifier & orgPid, const PointIdentifier & destPid);
/** Add a polygonal face to the Mesh, suppose QE layer ready */
virtual void
AddFace(QEPrimal * entry);
/** Add a polygonal face to the Mesh. The list of points
* is expected to be ordered counter-clock wise. The inside
* of the new face will be on the left side of the edges
* formed by consecutive points in this list. */
virtual QEPrimal *
AddFace(const PointIdList & points);
virtual QEPrimal *
AddFaceWithSecurePointList(const PointIdList & points);
virtual QEPrimal *
AddFaceWithSecurePointList(const PointIdList & points, bool CheckEdges);
/** Adds a triangular face to the Mesh */
virtual QEPrimal *
AddFaceTriangle(const PointIdentifier & aPid, const PointIdentifier & bPid, const PointIdentifier & cPid);
/** Deletion methods */
virtual void
DeletePoint(const PointIdentifier & pid);
virtual void
DeleteEdge(const PointIdentifier & orgPid, const PointIdentifier & destPid);
virtual void
DeleteEdge(QEPrimal * e);
virtual void
LightWeightDeleteEdge(EdgeCellType * edgeCell);
virtual void
LightWeightDeleteEdge(QEPrimal * e);
virtual void
DeleteFace(FaceRefType faceToDelete);
//
bool
GetPoint(PointIdentifier pid, PointType * pt) const
{
return (Superclass::GetPoint(pid, pt));
}
virtual PointType
GetPoint(const PointIdentifier & pid) const;
virtual VectorType
GetVector(const PointIdentifier & pid) const;
virtual QEPrimal *
GetEdge() const;
virtual QEPrimal *
GetEdge(const CellIdentifier & eid) const;
virtual QEPrimal *
FindEdge(const PointIdentifier & pid0) const;
virtual QEPrimal *
FindEdge(const PointIdentifier & pid0, const PointIdentifier & pid1) const;
virtual EdgeCellType *
FindEdgeCell(const PointIdentifier & pid0, const PointIdentifier & pid1) const;
/// Compute the euclidean length of argument edge
CoordRepType
ComputeEdgeLength(QEPrimal * e);
PointIdentifier
ComputeNumberOfPoints() const;
CellIdentifier
ComputeNumberOfFaces() const;
CellIdentifier
ComputeNumberOfEdges() const;
PointIdentifier
Splice(QEPrimal * a, QEPrimal * b);
#ifdef ITK_USE_CONCEPT_CHECKING
// Begin concept checking
// End concept checking
#endif
// for reusability of a mesh in the MeshToMesh filter
void
ClearFreePointAndCellIndexesLists()
{
while (!this->m_FreePointIndexes.empty())
{
this->m_FreePointIndexes.pop();
}
while (!this->m_FreeCellIndexes.empty())
{
this->m_FreeCellIndexes.pop();
}
}
CellIdentifier
GetNumberOfFaces() const
{
return (m_NumberOfFaces);
}
CellIdentifier
GetNumberOfEdges() const
{
return (m_NumberOfEdges);
}
protected:
/** Constructor and Destructor. */
QuadEdgeMesh();
~QuadEdgeMesh() override;
/** Release the memory of each one of the cells independently. */
virtual void
ClearCellsContainer();
CellsContainerPointer m_EdgeCellsContainer{};
private:
CellIdentifier m_NumberOfFaces{};
CellIdentifier m_NumberOfEdges{};
protected:
FreePointIndexesType m_FreePointIndexes{};
FreeCellIndexesType m_FreeCellIndexes{};
};
} // namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkQuadEdgeMesh.hxx"
#endif
#endif
|