本文整理汇总了C++中ObjectType::computeConnectedness方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectType::computeConnectedness方法的具体用法?C++ ObjectType::computeConnectedness怎么用?C++ ObjectType::computeConnectedness使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectType
的用法示例。
在下文中一共展示了ObjectType::computeConnectedness方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testBoard2D
/**
* Simple test of Board2D. Illustrates the border extraction of a
* simple 2D object considering different topologies.
*
*/
bool testBoard2D()
{
trace.beginBlock ( "Testing Board2D with Object Borders in 2D ..." );
typedef int Integer; // choose your digital line here.
typedef SpaceND<2> Z2; // Z^2
typedef Z2::Point Point;
typedef MetricAdjacency<Z2, 1> Adj4; // 4-adjacency type
typedef MetricAdjacency<Z2, 2> Adj8; // 8-adjacency type
typedef DigitalTopology< Adj8, Adj4 > DT8_4; //8,4 topology type
typedef HyperRectDomain< Z2 > Domain;
typedef Domain::ConstIterator DomainConstIterator;
typedef DigitalSetSelector < Domain, BIG_DS + HIGH_BEL_DS >::Type DigitalSet;
typedef Object<DT8_4, DigitalSet> ObjectType;
Point p1( -20, -10 );
Point p2( 20, 10 );
Domain domain( p1, p2 );
Adj4 adj4; // instance of 4-adjacency
Adj8 adj8; // instance of 8-adjacency
DT8_4 dt8_4(adj8, adj4, JORDAN_DT );
Point c( 0, 0 );
//We construct a simple 3-bubbles set
DigitalSet bubble_set( domain );
for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
{
int x = (*it)[0];
int y = (*it)[1];
if (( x*x + y*y < 82) ||
( (x - 14)*(x - 14) + (y + 1)*(y + 1) < 17) ||
( (x + 14)*(x + 14) + (y - 1)*(y - 1) < 17) )
bubble_set.insertNew( *it);
}
ObjectType bubble( dt8_4, bubble_set );
//Connectedness Check
if (bubble.computeConnectedness() == ObjectType::CONNECTED)
trace.info() << "The object is (8,4)connected." << endl;
else
trace.info() << "The object is not (8,4)connected." << endl;
//Border Computation
ObjectType bubbleBorder = bubble.border();
if (bubbleBorder.computeConnectedness() == ObjectType::CONNECTED)
trace.info() << "The object (8,4) border is connected." << endl;
else
trace.info() << "The object (8,4) border is not connected." << endl;
//Board Export
Board2D board;
board.setUnit(Board::UCentimeter);
board << DrawDomainGrid()
<< CustomStyle( domain.styleName(), new MyDrawStyleCustomGreen )
<< domain
<< CustomStyle( bubble_set.styleName(), new MyDrawStyleCustomRed )
<< bubble_set;
board.saveSVG("bubble-set-dgtalboard.svg");
board << DrawObjectAdjacencies( true )
<< CustomStyle( bubbleBorder.styleName(), new MyDrawStyleCustomBlue )
<< bubbleBorder;
board.saveSVG("bubble-object-border-dgtalboard.svg");
board.clear();
trace.endBlock();
return true;
}
示例2: testObjectBorder
/**
* Simple test to illustrate the border extraction of a simple 2D
* object considering different topologies.
*
*/
bool testObjectBorder()
{
trace.beginBlock ( "Testing Object Borders in 2D ..." );
typedef int Integer; // choose your digital line here.
typedef SpaceND<2> Z2; // Z^2
typedef Z2::Point Point;
typedef MetricAdjacency<Z2, 1> Adj4; // 4-adjacency type
typedef MetricAdjacency<Z2, 2> Adj8; // 8-adjacency type
typedef DigitalTopology< Adj8, Adj4 > DT8_4; //8,4 topology type
typedef HyperRectDomain< Z2 > Domain;
typedef Domain::ConstIterator DomainConstIterator;
typedef DigitalSetSelector < Domain, BIG_DS + HIGH_BEL_DS >::Type DigitalSet;
typedef Object<DT8_4, DigitalSet> ObjectType;
Point p1( -20, -10 );
Point p2( 20, 10 );
Domain domain( p1, p2 );
Adj4 adj4; // instance of 4-adjacency
Adj8 adj8; // instance of 8-adjacency
DT8_4 dt8_4(adj8, adj4, JORDAN_DT );
Point c( 0, 0 );
//We construct a simple 3-bubbles set
DigitalSet bubble_set( domain );
for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
{
int x = (*it)[0];
int y = (*it)[1];
if (( x*x + y*y < 82) ||
( (x - 14)*(x - 14) + (y + 1)*(y + 1) < 17) ||
( (x + 14)*(x + 14) + (y - 1)*(y - 1) < 17) )
bubble_set.insertNew( *it);
}
ObjectType bubble( dt8_4, bubble_set );
//Connectedness Check
if (bubble.computeConnectedness() == ObjectType::CONNECTED)
trace.info() << "The object is (8,4)connected." << endl;
else
trace.info() << "The object is not (8,4)connected." << endl;
//Border Computation
ObjectType bubbleBorder = bubble.border();
if (bubbleBorder.computeConnectedness() == ObjectType::CONNECTED)
trace.info() << "The object (8,4) border is connected." << endl;
else
trace.info() << "The object (8,4) border is not connected." << endl;
//Board Export
Board2D board;
board.setUnit(Board::UCentimeter);
board << DrawDomainGrid() << domain << bubble_set;
board.saveSVG("bubble-set.svg");
board << DrawObjectAdjacencies()
// << DrawWithCustomStyle<SelfDrawStyleCustom>()
<< CustomStyle( "Object", new MyObjectStyleCustom )
<< bubbleBorder;
board.saveSVG("bubble-object-border.svg");
board.clear();
//////////////////////:
//the same with the reverse topology
typedef Object<DT8_4::ReverseTopology, DigitalSet> ObjectType48;
DT8_4::ReverseTopology dt4_8 = dt8_4.reverseTopology();
ObjectType48 bubble2( dt4_8, bubble_set );
//Border Computation
ObjectType48 bubbleBorder2 = bubble2.border();
if (bubbleBorder2.computeConnectedness() == ObjectType48::CONNECTED)
trace.info() << "The object (4,8) border is connected." << endl;
else
trace.info() << "The object (4,8) border is not connected." << endl;
domain.selfDrawAsGrid(board);
bubble_set.selfDraw(board);
board << DrawObjectAdjacencies()
<< CustomStyle( "Object", new MyObjectStyleCustom )
<< bubbleBorder2;
board.saveSVG("bubble-object-border-48.svg");
//We split the border according to its components
vector<ObjectType48> borders(30);
unsigned int nbComponents;
vector<ObjectType48>::iterator it = borders.begin();
//.........这里部分代码省略.........