File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
cubical-complex-collapse.cpp File Reference
#include <iostream>
#include <map>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/PolyscopeViewer.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.

Data Structures

struct  DiagonalPriority< CubicalComplex >

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 114 of file cubical-complex-collapse.cpp.

115{
116 // JOL: unordered_map is approximately twice faster than map for
117 // collapsing.
118 typedef std::map<Cell, CubicalCellData> Map;
119 // typedef boost::unordered_map<Cell, CubicalCellData> Map;
121
122 trace.beginBlock( "Creating Cubical Complex" );
123 KSpace K;
124 K.init( Point( 0,0,0 ), Point( 512,512,512 ), true );
125 CC complex( K );
126 Integer m = 40;
127 std::vector<Cell> S;
128 for ( Integer x = 0; x <= m; ++x )
129 for ( Integer y = 0; y <= m; ++y )
130 for ( Integer z = 0; z <= m; ++z )
131 {
132 Point k1 = Point( x, y, z );
133 S.push_back( K.uCell( k1 ) );
134 double d1 = Point::diagonal( 1 ).dot( k1 ) / (double) KSpace::dimension; // sqrt( (double) KSpace::dimension );
135 RealPoint v1( k1[ 0 ], k1[ 1 ], k1[ 2 ] );
136 v1 -= d1 * RealPoint::diagonal( 1.0 );
137 //RealPoint v1( k1[ 0 ] - d1 * k1[ 0 ], k1[ 1 ] - d1 * k1[ 1 ], k1[ 2 ] - d1 * k1[ 2 ] );
138 double n1 = v1.norm();
139 bool fixed = ( ( x == 0 ) && ( y == 0 ) && ( z == 0 ) )
140 || ( ( x == 0 ) && ( y == m ) && ( z == 0 ) )
141 || ( ( x == m ) && ( y == 0 ) && ( z == 0 ) )
142 || ( ( x == m ) && ( y == m ) && ( z == 0 ) )
143 || ( ( x == m/3 ) && ( y == 2*m/3 ) && ( z == 2*m/3 ) )
144 || ( ( x == 0 ) && ( y == 0 ) && ( z == m ) )
145 || ( ( x == 0 ) && ( y == m ) && ( z == m ) )
146 || ( ( x == m ) && ( y == 0 ) && ( z == m ) )
147 || ( ( x == m ) && ( y == m ) && ( z == m ) )
148 || ( ( x == 0 ) && ( y == m ) )
149 || ( ( x == m ) && ( y == m ) )
150 || ( ( z == 0 ) && ( y == m ) )
151 || ( ( z == m ) && ( y == m ) );
152 complex.insertCell( S.back(),
153 fixed ? CC::FIXED
154 : (DGtal::uint32_t) floor(64.0 * n1 ) // This is the priority for collapse
155 );
156 }
157 //complex.close();
158 trace.info() << "After close: " << complex << std::endl;
159 trace.endBlock();
160
161 // for 3D display with PolyscopeViewer
163
164 {
165 MyViewer viewer(K);
167 for ( Dimension d = 0; d <= 3; ++d )
168 for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
169 it != itE; ++it )
170 {
171 bool fixed = (it->second.data == CC::FIXED);
172 if ( fixed ) viewer.drawColor( Color::Red );
173 else viewer.drawColor( Color::White );
174 viewer << it->first;
175 }
176 viewer.show();
177 }
178
179 trace.beginBlock( "Collapsing complex" );
180 CC::DefaultCellMapIteratorPriority P;
181 DGtal::uint64_t removed
182 = functions::collapse( complex, S.begin(), S.end(), P, true, true, true );
183 trace.info() << "Collapse removed " << removed << " cells." << std::endl;
184 trace.info() << "After collapse: " << complex << std::endl;
185 trace.endBlock();
186
187 {
188 MyViewer viewer(K);
190 for ( Dimension d = 0; d <= 3; ++d )
191 for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
192 it != itE; ++it )
193 {
194 bool fixed = (it->second.data == CC::FIXED);
195 if ( fixed ) viewer.drawColor( Color::Red );
196 else viewer.drawColor( Color::White );
197 viewer << it->first;
198 }
199 viewer.show();
200 return 0;
201 }
202}
static const Color Red
Definition Color.h:425
static const Color White
Definition Color.h:424
CellMap::const_iterator CellMapConstIterator
static const constexpr Dimension dimension
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
static Self diagonal(Component val=1)
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Space::RealPoint RealPoint
Definition StdDefs.h:170
Space::Point Point
Definition StdDefs.h:168
DGtal::int32_t Integer
Definition StdDefs.h:143
uint64_t collapse(CubicalComplex< TKSpace, TCellContainer > &K, CellConstIterator S_itB, CellConstIterator S_itE, const CellMapIteratorPriority &priority, bool hintIsSClosed=false, bool hintIsKClosed=false, bool verbose=false)
std::uint64_t uint64_t
unsigned 64-bit integer.
Definition BasicTypes.h:64
std::uint32_t uint32_t
unsigned 32-bit integer.
Definition BasicTypes.h:62
DGtal::uint32_t Dimension
Definition Common.h:119
Trace trace
KSpace K
std::unordered_map< Cell, CubicalCellData > Map
CubicalComplex< KSpace, Map > CC
CC::CellMapConstIterator CellMapConstIterator
PolyscopeViewer< Space, KSpace > MyViewer

References DGtal::functions::collapse(), DGtal::PointVector< dim, double >::diagonal(), DGtal::PointVector< dim, Integer >::diagonal(), DGtal::KhalimskySpaceND< 3, Integer >::dimension, DGtal::PointVector< dim, TEuclideanRing, TContainer >::dot(), DGtal::Display3D< Space, KSpace >::drawColor(), K, DGtal::PointVector< dim, TEuclideanRing, TContainer >::norm(), DGtal::Color::Red, DGtal::PolyscopeViewer< Space, KSpace >::show(), DGtal::trace, and DGtal::Color::White.