DGtal  0.9.3
Functions
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 "DGtal/topology/CubicalComplexFunctions.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 116 of file cubical-complex-collapse.cpp.

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::PointVector< dim, TEuclideanRing, TContainer >::norm(), DGtal::Display3D< Space, KSpace >::setFillColor(), DGtal::Viewer3D< Space, KSpace >::show(), DGtal::trace, DGtal::KhalimskySpaceND< dim, TInteger >::uCell(), and DGtal::Display3D< Space, KSpace >::updateDisplay.

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