DGtal  1.5.beta
cubical-complex-collapse.cpp File Reference
#include <iostream>
#include <map>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/topology/CubicalComplex.h"
Include dependency graph for cubical-complex-collapse.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program 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 GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2015/08/28

An example file named cubical-complex-collapse.cpp.

This file is part of the DGtal library.

Definition in file cubical-complex-collapse.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 115 of file cubical-complex-collapse.cpp.

116 {
117  // JOL: unordered_map is approximately twice faster than map for
118  // collapsing.
119  typedef std::map<Cell, CubicalCellData> Map;
120  // typedef boost::unordered_map<Cell, CubicalCellData> Map;
122 
123  trace.beginBlock( "Creating Cubical Complex" );
124  KSpace K;
125  K.init( Point( 0,0,0 ), Point( 512,512,512 ), true );
126  CC complex( K );
127  Integer m = 40;
128  std::vector<Cell> S;
129  for ( Integer x = 0; x <= m; ++x )
130  for ( Integer y = 0; y <= m; ++y )
131  for ( Integer z = 0; z <= m; ++z )
132  {
133  Point k1 = Point( x, y, z );
134  S.push_back( K.uCell( k1 ) );
135  double d1 = Point::diagonal( 1 ).dot( k1 ) / (double) KSpace::dimension; // sqrt( (double) KSpace::dimension );
136  RealPoint v1( k1[ 0 ], k1[ 1 ], k1[ 2 ] );
137  v1 -= d1 * RealPoint::diagonal( 1.0 );
138  //RealPoint v1( k1[ 0 ] - d1 * k1[ 0 ], k1[ 1 ] - d1 * k1[ 1 ], k1[ 2 ] - d1 * k1[ 2 ] );
139  double n1 = v1.norm();
140  bool fixed = ( ( x == 0 ) && ( y == 0 ) && ( z == 0 ) )
141  || ( ( x == 0 ) && ( y == m ) && ( z == 0 ) )
142  || ( ( x == m ) && ( y == 0 ) && ( z == 0 ) )
143  || ( ( x == m ) && ( y == m ) && ( z == 0 ) )
144  || ( ( x == m/3 ) && ( y == 2*m/3 ) && ( z == 2*m/3 ) )
145  || ( ( x == 0 ) && ( y == 0 ) && ( z == m ) )
146  || ( ( x == 0 ) && ( y == m ) && ( z == m ) )
147  || ( ( x == m ) && ( y == 0 ) && ( z == m ) )
148  || ( ( x == m ) && ( y == m ) && ( z == m ) )
149  || ( ( x == 0 ) && ( y == m ) )
150  || ( ( x == m ) && ( y == m ) )
151  || ( ( z == 0 ) && ( y == m ) )
152  || ( ( z == m ) && ( y == m ) );
153  complex.insertCell( S.back(),
154  fixed ? CC::FIXED
155  : (DGtal::uint32_t) floor(64.0 * n1 ) // This is the priority for collapse
156  );
157  }
158  //complex.close();
159  trace.info() << "After close: " << complex << std::endl;
160  trace.endBlock();
161 
162  // for 3D display with Viewer3D
163  QApplication application(argc,argv);
165 
166  {
167  MyViewer viewer(K);
168  viewer.show();
170  for ( Dimension d = 0; d <= 3; ++d )
171  for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
172  it != itE; ++it )
173  {
174  bool fixed = (it->second.data == CC::FIXED);
175  if ( fixed ) viewer.setFillColor( Color::Red );
176  else viewer.setFillColor( Color::White );
177  viewer << it->first;
178  }
179  viewer<< MyViewer::updateDisplay;
180  application.exec();
181  }
182 
183  trace.beginBlock( "Collapsing complex" );
185  DGtal::uint64_t removed
186  = functions::collapse( complex, S.begin(), S.end(), P, true, true, true );
187  trace.info() << "Collapse removed " << removed << " cells." << std::endl;
188  trace.info() << "After collapse: " << complex << std::endl;
189  trace.endBlock();
190 
191  {
192  MyViewer viewer(K);
193  viewer.show();
195  for ( Dimension d = 0; d <= 3; ++d )
196  for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
197  it != itE; ++it )
198  {
199  bool fixed = (it->second.data == CC::FIXED);
200  if ( fixed ) viewer.setFillColor( Color::Red );
201  else viewer.setFillColor( Color::White );
202  viewer << it->first;
203  }
204  viewer<< MyViewer::updateDisplay;
205  return application.exec();
206  }
207 }
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space....
CellMap::const_iterator CellMapConstIterator
Const iterator for visiting type CellMap.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Cell uCell(const PreCell &c) const
From an unsigned cell, returns an unsigned cell lying into this Khalismky space.
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
DGtal::int32_t Integer
Definition: StdDefs.h:143
boost::uint32_t uint32_t
unsigned 32-bit integer.
Definition: BasicTypes.h:63
DGtal::uint32_t Dimension
Definition: Common.h:136
Trace trace
Definition: Common.h:153
boost::uint64_t uint64_t
unsigned 64-bit integer.
Definition: BasicTypes.h:65
MyPointD Point
Definition: testClone2.cpp:383
KSpace K
std::unordered_map< Cell, CubicalCellData > Map
CubicalComplex< KSpace, Map > CC
CC::CellMapConstIterator CellMapConstIterator

References DGtal::CubicalComplex< TKSpace, TCellContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::CubicalComplex< TKSpace, TCellContainer >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::CubicalComplex< TKSpace, TCellContainer >::insertCell(), K, DGtal::Display3D< Space, KSpace >::setFillColor(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::uCell().