• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

icsm-au / DynAdjust / 13494567994

24 Feb 2025 09:15AM UTC coverage: 81.168% (+2.0%) from 79.161%
13494567994

push

github

web-flow
Merge pull request #234 from icsm-au/1.2.8

Version 1.2.8 (fixes, ehnacements, improved datum management)

6131 of 8137 new or added lines in 90 files covered. (75.35%)

162 existing lines in 33 files now uncovered.

32214 of 39688 relevant lines covered (81.17%)

11775.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.33
/dynadjust/dynadjust/dnasegmentwrapper/dnasegmentwrapper.hpp
1
//============================================================================
2
// Name         : dnasegmentwrapper.hpp
3
// Author       : Roger Fraser
4
// Contributors :
5
// Version      : 1.00
6
// Copyright    : Copyright 2017 Geoscience Australia
7
//
8
//                Licensed under the Apache License, Version 2.0 (the "License");
9
//                you may not use this file except in compliance with the License.
10
//                You may obtain a copy of the License at
11
//               
12
//                http ://www.apache.org/licenses/LICENSE-2.0
13
//               
14
//                Unless required by applicable law or agreed to in writing, software
15
//                distributed under the License is distributed on an "AS IS" BASIS,
16
//                WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
//                See the License for the specific language governing permissions and
18
//                limitations under the License.
19
//
20
// Description  : DynAdjust Network Segmentation Executable
21
//============================================================================
22

23
#ifndef DNASEGMENTWRAPPER_H_
24
#define DNASEGMENTWRAPPER_H_
25

26
#if defined(_MSC_VER)
27
        #if defined(LIST_INCLUDES_ON_BUILD) 
28
                #pragma message("  " __FILE__) 
29
        #endif
30
#endif
31

32
#include <iostream>
33
#include <vector>
34
#include <algorithm>
35
#include <iomanip>
36
#include <sstream>
37
#include <string>
38
#include <time.h>
39
#include <string.h>
40
#include <set>
41

42
#include <boost/timer/timer.hpp>
43
#include <boost/date_time/posix_time/posix_time.hpp>
44
#include <boost/thread.hpp>
45
#include <boost/thread/mutex.hpp>
46
#include <boost/shared_ptr.hpp>
47
#include <boost/program_options/options_description.hpp>
48
#include <boost/program_options/parsers.hpp>
49
#include <boost/program_options/variables_map.hpp>
50
#include <boost/filesystem.hpp>
51

52
#include <include/config/dnaversion.hpp>
53
#include <include/config/dnaconsts.hpp>
54
#include <include/config/dnaoptions-interface.hpp>
55
#include <include/config/dnaconsts-interface.hpp>
56
#include <include/config/dnaprojectfile.hpp>
57

58
#include <include/functions/dnastringfuncs.hpp>
59
#include <include/functions/dnafilepathfuncs.hpp>
60
#include <include/functions/dnastrmanipfuncs.hpp>
61

62
#include <dynadjust/dnasegment/dnasegment.hpp>
63

64
using namespace dynadjust::networksegment;
65
using namespace dynadjust::exception;
66

67
extern bool running;
68
extern boost::mutex cout_mutex;
69

70
class dna_segment_thread
71
{
72
public:
73
        dna_segment_thread(dna_segment* dnaSeg, project_settings* p, _SEGMENT_STATUS_* segmentStatus, boost::posix_time::milliseconds* s, std::string* status_msg)
17✔
74
                : _dnaSeg(dnaSeg)
17✔
75
                , _p(p)
17✔
76
                , _segmentStatus(segmentStatus)
17✔
77
                , _s(s)
17✔
78
                , _status_msg(status_msg) {};
17✔
79
        void operator()()
17✔
80
        {
81
                running = true;
17✔
82
                
83
                if (!_p->g.quiet)
17✔
84
                {
85
                        cout_mutex.lock();
17✔
86
                        std::cout << "+ Loading binary files...";
17✔
87
                        cout_mutex.unlock();
17✔
88
                }
89
                
90
                try {
17✔
91
                        // prepare the segmentation
92
                        _dnaSeg->PrepareSegmentation(_p);
17✔
93
                } 
94
                catch (const NetSegmentException& e) {
1✔
95
                        cout_mutex.lock();
1✔
96
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
1✔
97
                        cout_mutex.unlock();
1✔
98
                        running = false;
1✔
99
                        return;
1✔
100
                }
1✔
101

102
                if (!_p->g.quiet)
16✔
103
                {
104
                        cout_mutex.lock();
16✔
105
                        std::cout << " done." << std::endl;
16✔
106

107
                        if (_dnaSeg->StartingStations().empty())
16✔
108
                        {
109
                                std::string startStn(_dnaSeg->DefaultStartingStation());
11✔
110
                                if (startStn == "")
11✔
111
                                        startStn = "the first station";
×
112
                                std::cout << "+ Adopting " << _dnaSeg->DefaultStartingStation() << " as the initial station in the first block." << std::endl;
33✔
113
                        }
11✔
114
                        std::cout << "+ Creating block " << std::setw(PROGRESS_PAD_39) << " ";
16✔
115
                        cout_mutex.unlock();
16✔
116
                }
117
                boost::timer::cpu_timer time;
16✔
118
                try {
16✔
119
                        *_segmentStatus = SEGMENT_EXCEPTION_RAISED;
16✔
120
                        *_segmentStatus = _dnaSeg->SegmentNetwork(_p);
16✔
121
                } 
122
                catch (const NetSegmentException& e) {
×
123
                        running = false;
×
124
                        cout_mutex.lock();
×
NEW
125
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
126
                        cout_mutex.unlock();
×
127
                        return;
×
128
                }
×
NEW
129
                catch (const std::runtime_error& e) {
×
130
                        running = false;
×
NEW
131
                        boost::this_thread::sleep(boost::posix_time::milliseconds(250));
×
132
                        cout_mutex.lock();
×
NEW
133
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
134
                        cout_mutex.unlock();
×
135
                        return;
×
136
                }
×
137

138
                *_s = boost::posix_time::milliseconds(time.elapsed().wall/MILLI_TO_NANO);
16✔
139
                running = false;
16✔
140
                
141
                if (!_p->g.quiet)
16✔
142
                {
143
                        cout_mutex.lock();
16✔
144
                        std::cout << PROGRESS_BACKSPACE_39 << "\b" << std::setw(PROGRESS_PAD_39+3) << std::left << "s... done.   " << std::endl;
16✔
145
                        cout_mutex.unlock();
16✔
146
                }                
147
        }
148
private:
149
        dna_segment*                _dnaSeg;
150
        project_settings*        _p;
151
        _SEGMENT_STATUS_*        _segmentStatus;
152
        boost::posix_time::milliseconds*                _s;
153
        std::string*                                _status_msg;
154
};
155

156
class dna_segment_progress_thread
157
{
158
public:
159
        dna_segment_progress_thread(dna_segment* dnaSeg, project_settings* p)
17✔
160
                : _dnaSeg(dnaSeg), _p(p) {};
17✔
161
        void operator()()
17✔
162
        {
163
                UINT32 block, currentBlock(0);
17✔
164
                std::ostringstream ss;
17✔
165
                
166
                while (running)
34✔
167
                {
168
                        block = _dnaSeg->currentBlock();
17✔
169
                        if (!_p->g.quiet)
17✔
170
                        {
171
                                if (block != currentBlock)
17✔
172
                                {
173
                                        ss.str("");
×
NEW
174
                                        ss << "(" << std::fixed << std::setw(2) << std::right << std::setprecision(0) << _dnaSeg->GetProgress() << "% stations used)";
×
175
                                        cout_mutex.lock();
×
NEW
176
                                        std::cout << PROGRESS_BACKSPACE_39 << std::setw(PROGRESS_BLOCK) << std::left << block << std::setw(PROGRESS_PERCENT_29) << std::right << ss.str();
×
NEW
177
                                        std::cout.flush();
×
178
                                        cout_mutex.unlock();
×
179
                                        currentBlock = block;
×
180
                                }
181
                        }
182
                        boost::this_thread::sleep(boost::posix_time::milliseconds(75));
17✔
183
                }        
184
        }
17✔
185

186
private:
187
        dna_segment*                _dnaSeg;
188
        project_settings*        _p;
189
};
190

191
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc