2013-11-25 15:50:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
|
|
|
|
* Applied Mathematics, Norway.
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
2015-03-09 12:41:34 +00:00
|
|
|
* Contact information: E-mail: tor.dokken@sintef.no
|
|
|
|
* SINTEF ICT, Department of Applied Mathematics,
|
|
|
|
* P.O. Box 124 Blindern,
|
|
|
|
* 0314 Oslo, Norway.
|
2013-11-25 15:50:03 +00:00
|
|
|
*
|
|
|
|
* This file is part of TTL.
|
|
|
|
*
|
|
|
|
* TTL is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
2015-03-09 12:41:34 +00:00
|
|
|
* License, or (at your option) any later version.
|
2013-11-25 15:50:03 +00:00
|
|
|
*
|
2015-03-09 12:41:34 +00:00
|
|
|
* TTL is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2013-11-25 15:50:03 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with TTL. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public
|
|
|
|
* License, a covered work must retain the producer line in every data
|
|
|
|
* file that is created or manipulated using TTL.
|
|
|
|
*
|
|
|
|
* Other Usage
|
|
|
|
* You can be released from the requirements of the license by purchasing
|
|
|
|
* a commercial license. Buying such a license is mandatory as soon as you
|
|
|
|
* develop commercial activities involving the TTL library without
|
|
|
|
* disclosing the source code of your own applications.
|
|
|
|
*
|
|
|
|
* This file may be used in accordance with the terms contained in a
|
2015-03-09 12:41:34 +00:00
|
|
|
* written agreement between you and SINTEF ICT.
|
2013-11-25 15:50:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _HE_TRIANG_H_
|
|
|
|
#define _HE_TRIANG_H_
|
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
//#define TTL_USE_NODE_ID // Each node gets it's own unique id
|
2016-09-13 08:06:25 +00:00
|
|
|
//#define TTL_USE_NODE_FLAG // Each node gets a flag (can be set to true or false)
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
#include <list>
|
2016-08-18 15:17:52 +00:00
|
|
|
#include <unordered_set>
|
2013-11-25 15:50:03 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <ttl/ttl_util.h>
|
2016-06-29 15:09:55 +00:00
|
|
|
#include <memory>
|
2015-06-04 12:54:08 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
|
|
|
|
class BOARD_CONNECTED_ITEM;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
namespace ttl
|
|
|
|
{
|
|
|
|
class TRIANGULATION_HELPER;
|
2014-01-27 10:42:47 +00:00
|
|
|
};
|
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
/**
|
|
|
|
* The half-edge data structure
|
|
|
|
*/
|
|
|
|
namespace hed
|
|
|
|
{
|
|
|
|
// Helper typedefs
|
|
|
|
class NODE;
|
|
|
|
class EDGE;
|
2016-06-29 15:09:55 +00:00
|
|
|
typedef std::shared_ptr<NODE> NODE_PTR;
|
|
|
|
typedef std::shared_ptr<EDGE> EDGE_PTR;
|
|
|
|
typedef std::weak_ptr<EDGE> EDGE_WEAK_PTR;
|
2014-04-07 11:32:09 +00:00
|
|
|
typedef std::vector<NODE_PTR> NODES_CONTAINER;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \class NODE
|
|
|
|
* \brief \b Node class for data structures (Inherits from HandleId)
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* - To enable node IDs, TTL_USE_NODE_ID must be defined.
|
|
|
|
* - To enable node flags, TTL_USE_NODE_FLAG must be defined.
|
|
|
|
* - TTL_USE_NODE_ID and TTL_USE_NODE_FLAG should only be enabled if this functionality is
|
|
|
|
* required by the application, because they increase the memory usage for each Node object.
|
|
|
|
*/
|
|
|
|
class NODE
|
|
|
|
{
|
2013-11-25 15:50:03 +00:00
|
|
|
protected:
|
|
|
|
#ifdef TTL_USE_NODE_FLAG
|
|
|
|
/// TTL_USE_NODE_FLAG must be defined
|
2014-04-07 11:32:09 +00:00
|
|
|
bool m_flag;
|
2013-11-25 15:50:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TTL_USE_NODE_ID
|
|
|
|
/// TTL_USE_NODE_ID must be defined
|
|
|
|
static int id_count;
|
|
|
|
|
|
|
|
/// A unique id for each node (TTL_USE_NODE_ID must be defined)
|
2014-04-07 11:32:09 +00:00
|
|
|
int m_id;
|
2013-11-25 15:50:03 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
/// Node coordinates
|
2016-09-13 15:13:16 +00:00
|
|
|
const int m_x, m_y;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
/// Tag for quick connection resolution
|
|
|
|
int m_tag;
|
|
|
|
|
2016-09-13 08:06:25 +00:00
|
|
|
/// Whether it the node can be a target for ratsnest lines
|
|
|
|
bool m_noline;
|
|
|
|
|
2015-06-04 12:54:08 +00:00
|
|
|
/// List of board items that share this node
|
2016-08-18 15:17:52 +00:00
|
|
|
std::unordered_set<const BOARD_CONNECTED_ITEM*> m_parents;
|
2015-06-04 12:54:08 +00:00
|
|
|
|
|
|
|
/// Layers that are occupied by this node
|
|
|
|
LSET m_layers;
|
|
|
|
|
|
|
|
/// Recomputes the layers used by this node
|
|
|
|
void updateLayers();
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
public:
|
|
|
|
/// Constructor
|
2014-04-07 11:32:09 +00:00
|
|
|
NODE( int aX = 0, int aY = 0 ) :
|
2013-11-25 15:50:03 +00:00
|
|
|
#ifdef TTL_USE_NODE_FLAG
|
2014-04-07 11:32:09 +00:00
|
|
|
m_flag( false ),
|
2013-11-25 15:50:03 +00:00
|
|
|
#endif
|
|
|
|
#ifdef TTL_USE_NODE_ID
|
2014-04-07 11:32:09 +00:00
|
|
|
m_id( id_count++ ),
|
2013-11-25 15:50:03 +00:00
|
|
|
#endif
|
2016-09-13 08:06:25 +00:00
|
|
|
m_x( aX ), m_y( aY ), m_tag( -1 ), m_noline( false )
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
m_layers.reset();
|
2014-04-07 11:32:09 +00:00
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Destructor
|
2014-04-07 11:32:09 +00:00
|
|
|
~NODE() {}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns the x-coordinate
|
2015-03-09 12:41:34 +00:00
|
|
|
inline int GetX() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_x;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns the y-coordinate
|
2015-03-09 12:41:34 +00:00
|
|
|
inline int GetY() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_y;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
/// Returns tag, common identifier for connected nodes
|
|
|
|
inline int GetTag() const
|
|
|
|
{
|
|
|
|
return m_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets tag, common identifier for connected nodes
|
|
|
|
inline void SetTag( int aTag )
|
|
|
|
{
|
|
|
|
m_tag = aTag;
|
|
|
|
}
|
2016-09-13 08:06:25 +00:00
|
|
|
|
|
|
|
/// Decides whether this node can be a ratsnest line target
|
|
|
|
inline void SetNoLine( bool aEnable )
|
|
|
|
{
|
|
|
|
m_noline = aEnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this node can be a target for ratsnest lines
|
|
|
|
inline const bool& GetNoLine() const
|
|
|
|
{
|
|
|
|
return m_noline;
|
|
|
|
}
|
2015-03-09 12:41:34 +00:00
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
#ifdef TTL_USE_NODE_ID
|
|
|
|
/// Returns the id (TTL_USE_NODE_ID must be defined)
|
2015-03-09 12:41:34 +00:00
|
|
|
inline int Id() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TTL_USE_NODE_FLAG
|
|
|
|
/// Sets the flag (TTL_USE_NODE_FLAG must be defined)
|
2015-03-09 12:41:34 +00:00
|
|
|
inline void SetFlag( bool aFlag )
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
m_flag = aFlag;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns the flag (TTL_USE_NODE_FLAG must be defined)
|
2015-03-09 12:41:34 +00:00
|
|
|
inline const bool& GetFlag() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_flag;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
inline unsigned int GetRefCount() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
2015-06-05 15:49:01 +00:00
|
|
|
return m_parents.size();
|
2014-04-07 11:32:09 +00:00
|
|
|
}
|
2015-06-04 12:54:08 +00:00
|
|
|
|
|
|
|
inline void AddParent( const BOARD_CONNECTED_ITEM* aParent )
|
|
|
|
{
|
2016-08-18 15:17:52 +00:00
|
|
|
m_parents.insert( aParent );
|
2015-06-04 12:54:08 +00:00
|
|
|
m_layers.reset(); // mark as needs updating
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RemoveParent( const BOARD_CONNECTED_ITEM* aParent )
|
|
|
|
{
|
2016-08-18 15:17:52 +00:00
|
|
|
auto it = m_parents.find( aParent );
|
|
|
|
|
|
|
|
if( it != m_parents.end() )
|
|
|
|
{
|
|
|
|
m_parents.erase( it );
|
|
|
|
m_layers.reset(); // mark as needs updating
|
|
|
|
}
|
2015-06-04 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const LSET& GetLayers()
|
|
|
|
{
|
|
|
|
if( m_layers.none() )
|
|
|
|
updateLayers();
|
|
|
|
|
|
|
|
return m_layers;
|
|
|
|
}
|
2015-06-05 15:49:00 +00:00
|
|
|
|
|
|
|
// Tag used for unconnected items.
|
|
|
|
static const int TAG_UNCONNECTED = -1;
|
2014-04-07 11:32:09 +00:00
|
|
|
};
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
/**
|
|
|
|
* \class EDGE
|
|
|
|
* \brief \b %Edge class in the in the half-edge data structure.
|
|
|
|
*/
|
|
|
|
class EDGE
|
|
|
|
{
|
|
|
|
public:
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Constructor
|
2014-04-07 11:32:09 +00:00
|
|
|
EDGE() : m_weight( 0 ), m_isLeadingEdge( false )
|
|
|
|
{
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Destructor
|
2014-04-07 11:32:09 +00:00
|
|
|
virtual ~EDGE()
|
|
|
|
{
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
/// Returns tag, common identifier for connected nodes
|
|
|
|
inline int GetTag() const
|
|
|
|
{
|
|
|
|
int tag = GetSourceNode()->GetTag();
|
|
|
|
if( tag >= 0 )
|
|
|
|
return tag;
|
|
|
|
|
|
|
|
return GetTargetNode()->GetTag();
|
|
|
|
}
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Sets the source node
|
2015-03-09 12:41:34 +00:00
|
|
|
inline void SetSourceNode( const NODE_PTR& aNode )
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
m_sourceNode = aNode;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Sets the next edge in face
|
2015-03-09 12:41:34 +00:00
|
|
|
inline void SetNextEdgeInFace( const EDGE_PTR& aEdge )
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
m_nextEdgeInFace = aEdge;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Sets the twin edge
|
2015-03-09 12:41:34 +00:00
|
|
|
inline void SetTwinEdge( const EDGE_PTR& aEdge )
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
m_twinEdge = aEdge;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Sets the edge as a leading edge
|
2015-03-09 12:41:34 +00:00
|
|
|
inline void SetAsLeadingEdge( bool aLeading = true )
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
m_isLeadingEdge = aLeading;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Checks if an edge is a leading edge
|
2015-03-09 12:41:34 +00:00
|
|
|
inline bool IsLeadingEdge() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_isLeadingEdge;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns the twin edge
|
2015-03-09 12:41:34 +00:00
|
|
|
inline EDGE_PTR GetTwinEdge() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_twinEdge.lock();
|
|
|
|
}
|
2014-03-05 13:57:14 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
inline void ClearTwinEdge()
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
m_twinEdge.reset();
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns the next edge in face
|
2015-03-09 12:41:34 +00:00
|
|
|
inline const EDGE_PTR& GetNextEdgeInFace() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_nextEdgeInFace;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Retuns the source node
|
2015-03-09 12:41:34 +00:00
|
|
|
inline const NODE_PTR& GetSourceNode() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_sourceNode;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns the target node
|
2014-04-07 11:32:09 +00:00
|
|
|
virtual const NODE_PTR& GetTargetNode() const
|
|
|
|
{
|
|
|
|
return m_nextEdgeInFace->GetSourceNode();
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
inline void SetWeight( unsigned int weight )
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
m_weight = weight;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
inline unsigned int GetWeight() const
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_weight;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
void Clear()
|
2014-03-05 13:57:14 +00:00
|
|
|
{
|
2014-04-07 11:32:09 +00:00
|
|
|
m_sourceNode.reset();
|
|
|
|
m_nextEdgeInFace.reset();
|
2014-03-05 13:57:14 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
if( !m_twinEdge.expired() )
|
2014-03-05 13:57:14 +00:00
|
|
|
{
|
2014-04-07 11:32:09 +00:00
|
|
|
m_twinEdge.lock()->ClearTwinEdge();
|
|
|
|
m_twinEdge.reset();
|
2014-03-05 13:57:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
protected:
|
|
|
|
NODE_PTR m_sourceNode;
|
|
|
|
EDGE_WEAK_PTR m_twinEdge;
|
|
|
|
EDGE_PTR m_nextEdgeInFace;
|
|
|
|
unsigned int m_weight;
|
|
|
|
bool m_isLeadingEdge;
|
|
|
|
};
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
/**
|
|
|
|
* \class EDGE_MST
|
|
|
|
* \brief \b Specialization of %EDGE class to be used for Minimum Spanning Tree algorithm.
|
2013-11-25 15:50:03 +00:00
|
|
|
*/
|
2014-04-07 11:32:09 +00:00
|
|
|
class EDGE_MST : public EDGE
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
NODE_PTR m_target;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
public:
|
|
|
|
EDGE_MST( const NODE_PTR& aSource, const NODE_PTR& aTarget, unsigned int aWeight = 0 ) :
|
|
|
|
m_target( aTarget )
|
|
|
|
{
|
|
|
|
m_sourceNode = aSource;
|
|
|
|
m_weight = aWeight;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// @copydoc Edge::setSourceNode()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual const NODE_PTR& GetTargetNode() const override
|
2014-04-07 11:32:09 +00:00
|
|
|
{
|
|
|
|
return m_target;
|
|
|
|
}
|
2015-03-09 12:41:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
EDGE_MST( const EDGE& aEdge )
|
|
|
|
{
|
|
|
|
assert( false );
|
|
|
|
}
|
2014-04-07 11:32:09 +00:00
|
|
|
};
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
class DART; // Forward declaration (class in this namespace)
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
/**
|
|
|
|
* \class TRIANGULATION
|
|
|
|
* \brief \b %Triangulation class for the half-edge data structure with adaption to TTL.
|
|
|
|
*/
|
|
|
|
class TRIANGULATION
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
/// One half-edge for each arc
|
|
|
|
std::list<EDGE_PTR> m_leadingEdges;
|
2014-01-27 10:42:47 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
ttl::TRIANGULATION_HELPER* m_helper;
|
2014-01-27 10:42:47 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
void addLeadingEdge( EDGE_PTR& aEdge )
|
|
|
|
{
|
|
|
|
aEdge->SetAsLeadingEdge();
|
|
|
|
m_leadingEdges.push_front( aEdge );
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
2014-01-27 10:42:47 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
bool removeLeadingEdgeFromList( EDGE_PTR& aLeadingEdge );
|
2014-01-27 10:42:47 +00:00
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
void cleanAll();
|
2014-04-07 11:32:09 +00:00
|
|
|
|
2014-01-27 10:42:47 +00:00
|
|
|
/** Swaps the edge associated with \e dart in the actual data structure.
|
2014-04-07 11:32:09 +00:00
|
|
|
*
|
|
|
|
* <center>
|
|
|
|
* \image html swapEdge.gif
|
|
|
|
* </center>
|
|
|
|
*
|
|
|
|
* \param aDart
|
|
|
|
* Some of the functions require a dart as output.
|
|
|
|
* If this is required by the actual function, the dart should be delivered
|
|
|
|
* back in a position as seen if it was glued to the edge when swapping (rotating)
|
|
|
|
* the edge CCW; see the figure.
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* - If the edge is \e constrained, or if it should not be swapped for
|
|
|
|
* some other reason, this function need not do the actual swap of the edge.
|
|
|
|
* - Some functions in TTL require that \c swapEdge is implemented such that
|
|
|
|
* darts outside the quadrilateral are not affected by the swap.
|
|
|
|
*/
|
|
|
|
void swapEdge( DART& aDart );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Splits the triangle associated with \e dart in the actual data structure into
|
|
|
|
* three new triangles joining at \e point.
|
|
|
|
*
|
|
|
|
* <center>
|
|
|
|
* \image html splitTriangle.gif
|
|
|
|
* </center>
|
|
|
|
*
|
|
|
|
* \param aDart
|
|
|
|
* Output: A CCW dart incident with the new node; see the figure.
|
|
|
|
*/
|
|
|
|
void splitTriangle( DART& aDart, const NODE_PTR& aPoint );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The reverse operation of TTLtraits::splitTriangle.
|
|
|
|
* This function is only required for functions that involve
|
|
|
|
* removal of interior nodes; see for example TrinagulationHelper::RemoveInteriorNode.
|
|
|
|
*
|
|
|
|
* <center>
|
|
|
|
* \image html reverse_splitTriangle.gif
|
|
|
|
* </center>
|
|
|
|
*/
|
|
|
|
void reverseSplitTriangle( DART& aDart );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a triangle with an edge at the boundary of the triangulation
|
|
|
|
* in the actual data structure
|
|
|
|
*/
|
|
|
|
void removeBoundaryTriangle( DART& aDart );
|
|
|
|
|
|
|
|
public:
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Default constructor
|
2014-04-07 11:32:09 +00:00
|
|
|
TRIANGULATION();
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Copy constructor
|
2014-04-07 11:32:09 +00:00
|
|
|
TRIANGULATION( const TRIANGULATION& aTriangulation );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Destructor
|
2014-04-07 11:32:09 +00:00
|
|
|
~TRIANGULATION();
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Creates a Delaunay triangulation from a set of points
|
2014-04-07 11:32:09 +00:00
|
|
|
void CreateDelaunay( NODES_CONTAINER::iterator aFirst, NODES_CONTAINER::iterator aLast );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Creates an initial Delaunay triangulation from two enclosing triangles
|
|
|
|
// When using rectangular boundary - loop through all points and expand.
|
|
|
|
// (Called from createDelaunay(...) when starting)
|
2014-04-07 11:32:09 +00:00
|
|
|
EDGE_PTR InitTwoEnclosingTriangles( NODES_CONTAINER::iterator aFirst,
|
|
|
|
NODES_CONTAINER::iterator aLast );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// These two functions are required by TTL for Delaunay triangulation
|
2014-04-07 11:32:09 +00:00
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Swaps the edge associated with diagonal
|
2014-04-07 11:32:09 +00:00
|
|
|
void SwapEdge( EDGE_PTR& aDiagonal );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
/// Splits the triangle associated with edge into three new triangles joining at point
|
2014-04-07 11:32:09 +00:00
|
|
|
EDGE_PTR SplitTriangle( EDGE_PTR& aEdge, const NODE_PTR& aPoint );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Functions required by TTL for removing nodes in a Delaunay triangulation
|
2014-04-07 11:32:09 +00:00
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Removes the boundary triangle associated with edge
|
2014-04-07 11:32:09 +00:00
|
|
|
void RemoveTriangle( EDGE_PTR& aEdge ); // boundary triangle required
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// The reverse operation of removeTriangle
|
2014-04-07 11:32:09 +00:00
|
|
|
void ReverseSplitTriangle( EDGE_PTR& aEdge );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Creates an arbitrary CCW dart
|
2014-04-07 11:32:09 +00:00
|
|
|
DART CreateDart();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns a list of "triangles" (one leading half-edge for each triangle)
|
2014-04-07 11:32:09 +00:00
|
|
|
const std::list<EDGE_PTR>& GetLeadingEdges() const
|
|
|
|
{
|
|
|
|
return m_leadingEdges;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns the number of triangles
|
2014-04-07 11:32:09 +00:00
|
|
|
int NoTriangles() const
|
|
|
|
{
|
|
|
|
return (int) m_leadingEdges.size();
|
|
|
|
}
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Returns a list of half-edges (one half-edge for each arc)
|
2014-04-07 11:32:09 +00:00
|
|
|
std::list<EDGE_PTR>* GetEdges( bool aSkipBoundaryEdges = false ) const;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
#ifdef TTL_USE_NODE_FLAG
|
2015-03-09 12:41:34 +00:00
|
|
|
/// Sets flag in all the nodes
|
2014-04-07 11:32:09 +00:00
|
|
|
void FlagNodes( bool aFlag ) const;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns a list of nodes. This function requires TTL_USE_NODE_FLAG to be defined. \see Node.
|
2014-04-07 11:32:09 +00:00
|
|
|
std::list<NODE_PTR>* GetNodes() const;
|
2013-11-25 15:50:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/// Swaps edges until the triangulation is Delaunay (constrained edges are not swapped)
|
2014-04-07 11:32:09 +00:00
|
|
|
void OptimizeDelaunay();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Checks if the triangulation is Delaunay
|
2014-04-07 11:32:09 +00:00
|
|
|
bool CheckDelaunay() const;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Returns an arbitrary interior node (as the source node of the returned edge)
|
2014-04-07 11:32:09 +00:00
|
|
|
EDGE_PTR GetInteriorNode() const;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
EDGE_PTR GetBoundaryEdgeInTriangle( const EDGE_PTR& aEdge ) const;
|
2014-01-27 10:42:47 +00:00
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
/// Returns an arbitrary boundary edge
|
2014-04-07 11:32:09 +00:00
|
|
|
EDGE_PTR GetBoundaryEdge() const;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/// Print edges for plotting with, e.g., gnuplot
|
2014-04-07 11:32:09 +00:00
|
|
|
void PrintEdges( std::ofstream& aOutput ) const;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
friend class ttl::TRIANGULATION_HELPER;
|
|
|
|
};
|
2013-11-25 15:50:03 +00:00
|
|
|
}; // End of hed namespace
|
|
|
|
|
|
|
|
#endif
|