Skip to content

Commit b529812

Browse files
committed
More Module.h, Algorithm.hs
1 parent b9a328f commit b529812

22 files changed

+192
-226
lines changed

src/Core/Algorithms/Base/AlgorithmBase.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ Name::Name(const std::string& name) : name_(name)
6060
}
6161
}
6262

63-
AlgorithmBase::~AlgorithmBase() {}
64-
6563
namespace
6664
{
6765
// Note: boost::serialization has trouble with NaN values, in addition to the platform differences.
@@ -381,10 +379,10 @@ bool AlgorithmParameterList::checkOption(const AlgorithmParameterName& key, cons
381379
return boost::iequals(value, currentValue);
382380
}
383381

384-
void AlgorithmBase::dumpAlgoState() const
382+
void AlgorithmParameterList::dumpAlgoState() const
385383
{
386384
std::ostringstream ostr;
387-
ostr << "Algorithm state for " << typeid(*this).name() << " id#" << id() << std::endl;
385+
ostr << "Algorithm state for " << typeid(*this).name() << std::endl;
388386

389387
auto range = std::make_pair(paramsBegin(), paramsEnd());
390388
BOOST_FOREACH(const ParameterMap::value_type& pair, range)
@@ -466,4 +464,4 @@ std::vector<std::string> Core::Algorithms::toNameVector(const Variable::List& li
466464
std::vector<double> Core::Algorithms::toDoubleVector(const Variable::List& list)
467465
{
468466
return toTypedVector<double>(list, [](const Variable& v) { return v.toDouble(); });
469-
}
467+
}

src/Core/Algorithms/Base/AlgorithmBase.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
namespace SCIRun {
4040
namespace Core {
4141
namespace Algorithms {
42-
43-
class SCISHARE AlgorithmBase : public AlgorithmInterface, public AlgorithmParameterList, public AlgorithmLogger, public AlgorithmStatusReporter
42+
43+
class SCISHARE AlgorithmBase :
44+
public AlgorithmInterface,
45+
public AlgorithmParameterList,
46+
public AlgorithmLogger,
47+
public AlgorithmStatusReporter
4448
{
45-
public:
46-
virtual ~AlgorithmBase();
47-
protected:
48-
void dumpAlgoState() const;
4949
};
50-
50+
5151
}}}
5252

5353
#endif

src/Core/Algorithms/Base/AlgorithmData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace Algorithms {
5555
{
5656
auto it = data_.find(name);
5757
/// @todo: log incorrect type if present but wrong type
58-
return it == data_.end() ? boost::shared_ptr<T>() : boost::dynamic_pointer_cast<T>(it->second[0]);
58+
return it == data_.end() ? nullptr : boost::dynamic_pointer_cast<T>(it->second[0]);
5959
}
6060

6161
template <typename T>
@@ -85,7 +85,7 @@ namespace Algorithms {
8585
{
8686
public:
8787
AlgorithmInput() {}
88-
AlgorithmInput(const Map& m) : AlgorithmData(m) {}
88+
explicit AlgorithmInput(const Map& m) : AlgorithmData(m) {}
8989
};
9090

9191
class SCISHARE AlgorithmOutput : public AlgorithmData

src/Core/Algorithms/Base/AlgorithmInterfaces.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,11 @@
3636
namespace SCIRun {
3737
namespace Core {
3838
namespace Algorithms {
39-
39+
4040
class SCISHARE AlgorithmInterface : public HasIntegerId
4141
{
4242
public:
4343
virtual ~AlgorithmInterface() {}
44-
45-
/*
46-
@todo idea: make it mockable
47-
48-
virtual OutputDatatypeHandleOptions run(InputDatatypeHandleOptions, ModuleParameterState) = 0;
49-
50-
ModuleParameterState: essentially a map of GuiVars. but need hooks for undo/redo and serialization
51-
Input: tuple/heterogeneous vector of Datatypes
52-
Output: tuple of Datatypes, possibly delay-executed
53-
*/
54-
5544
virtual AlgorithmOutput run(const AlgorithmInput& input) const = 0;
5645
};
5746

src/Core/Algorithms/Base/AlgorithmParameterList.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ namespace Algorithms {
7373
typedef std::map<AlgorithmParameterName, AlgorithmParameter> ParameterMap;
7474
ParameterMap::const_iterator paramsBegin() const { return parameters_.begin(); }
7575
ParameterMap::const_iterator paramsEnd() const { return parameters_.end(); }
76+
void dumpAlgoState() const;
7677
private:
7778
ParameterMap parameters_;
7879
};
79-
80+
8081
}}}
8182

8283
#endif

src/Core/Algorithms/Base/AlgorithmStatusReporter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace Algorithms {
5252
virtual void update_progress(double percent) const
5353
{
5454
if (updaterFunc_)
55-
updaterFunc_(percent);
55+
updaterFunc_(percent);
5656
}
5757

5858
typedef boost::function<void(double)> UpdaterFunc;
@@ -72,6 +72,8 @@ namespace Algorithms {
7272
const AlgorithmStatusReporter* asr_;
7373
};
7474

75+
#define REPORT_STATUS(className) ScopedAlgorithmStatusReporter __asr(this, #className);
76+
7577
}}}
7678

7779
#endif

src/Core/Algorithms/Base/Variable.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,15 @@ namespace Algorithms {
5050
class SCISHARE Variable
5151
{
5252
public:
53-
typedef std::vector<Variable> List;
54-
55-
typedef boost::variant<
53+
using List = std::vector<Variable>;
54+
using Value = boost::variant<
5655
int,
5756
double,
5857
std::string,
5958
bool,
6059
AlgoOption,
6160
List
62-
> Value;
61+
>;
6362

6463
Variable() {}
6564
Variable(const Name& name, const Value& value);

src/Core/Algorithms/DataIO/Tests/ReadMatrixTests.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ TEST(ReadMatrixAlgorithmTest, TestDenseFromRealASCIIMatFile)
128128
ASSERT_TRUE(matrixIs::dense(matrix));
129129

130130
auto dense = castMatrix::toDense(matrix);
131-
double* ptr = dense->data();
132-
size_t size = dense->get_dense_size();
133131

134132
EXPECT_EQ(4, dense->cols());
135133
EXPECT_EQ(3, dense->rows());

src/Core/Algorithms/Field/Tests/RefineTetMeshLocallyAlgoTests.cc

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ FieldList LoadAllCasesInputField()
5353
if (!(i==31 || i==47 || i==55 || i==59 || i==61 || i==62))
5454
{
5555
auto file = (TestResources::rootDir() / "Fields/refinetetmeshlocally/all57outof64case_input/").string() + std::to_string(i) + ".mat";
56-
FieldHandle field = MatlabField_reader(0, file.c_str());
56+
FieldHandle field = MatlabField_reader(0, file.c_str());
5757
result.push_back(field);
5858
}
5959
}
@@ -79,8 +79,8 @@ FieldList LoadAllCasesResultField()
7979

8080
SparseRowMatrixHandle GetTheoreticalTetCases(int cases, int nr_nodes)
8181
{
82-
SparseRowMatrixFromMap::Values result;
83-
82+
SparseRowMatrixFromMap::Values result;
83+
8484
if (cases==31)
8585
{
8686
result[1][2]=1;
@@ -141,8 +141,8 @@ TEST(RefineTetMeshLocallyAlgoTests, Test59basicCutCases)
141141
FieldList result_files = LoadAllCasesResultField();
142142

143143
double epsilon=1e-8;
144-
145-
RefineTetMeshLocallyAlgorithm algo;
144+
145+
RefineTetMeshLocallyAlgorithm algo;
146146
algo.set(Parameters::RefineTetMeshLocallyIsoValue, 1.0);
147147
algo.set(Parameters::RefineTetMeshLocallyEdgeLength, 0.0);
148148
algo.set(Parameters::RefineTetMeshLocallyVolume, 0.0);
@@ -155,31 +155,31 @@ TEST(RefineTetMeshLocallyAlgoTests, Test59basicCutCases)
155155
algo.set(Parameters::RefineTetMeshLocallyMaxNumberRefinementIterations, 1);
156156
GetMeshNodesAlgo getfieldnodes_algo;
157157
DenseMatrixHandle output_nodes,exp_result_nodes;
158-
VMesh::Node::array_type onodes1(4),onodes2(4);
158+
VMesh::Node::array_type onodes1(4),onodes2(4);
159159
VMesh *output_vmesh, *exp_result_vmesh;
160160
FieldHandle input,output, exp_result;
161161

162162
int count=0;
163163
for(int i=0; i<63; i++)
164-
{
164+
{
165165
if (!(i==31-1 || i==47-1 || i==55-1 || i==59-1 || i==61-1 || i==62-1))
166-
{
166+
{
167167
if(!input_files[count] || !result_files[i])
168168
{
169169
FAIL() << " ERROR: could not load data files. Please check path set in SCIRUN_TEST_RESOURCE_DIR variable (cmake). " << std::endl;
170170
}
171171
input=input_files[count++];
172172
exp_result=result_files[i];
173-
173+
174174
try
175175
{
176176
algo.runImpl(input, output);
177-
} catch (...)
177+
} catch (...)
178178
{
179179
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 1 does not work. " << std::endl;
180180
}
181181
exp_result_vmesh=exp_result->vmesh();
182-
output_vmesh=output->vmesh();
182+
output_vmesh=output->vmesh();
183183
try
184184
{
185185
getfieldnodes_algo.run(output,output_nodes);
@@ -188,60 +188,59 @@ TEST(RefineTetMeshLocallyAlgoTests, Test59basicCutCases)
188188
{
189189
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 1 does not work (could not get field nodes from input files). " << std::endl;
190190
}
191-
191+
192192
if( output_nodes->ncols()!=exp_result_nodes->ncols() || output_nodes->nrows()!=exp_result_nodes->nrows() )
193193
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 1 does not work (number of nodes is different than expected). " << std::endl;
194-
194+
195195
for (long idx=0;idx<exp_result_nodes->nrows();idx++)
196196
{
197197
EXPECT_NEAR( (*exp_result_nodes)(idx,0),(*output_nodes)(idx,0), epsilon);
198198
EXPECT_NEAR( (*exp_result_nodes)(idx,1),(*output_nodes)(idx,1), epsilon);
199199
EXPECT_NEAR( (*exp_result_nodes)(idx,2),(*output_nodes)(idx,2), epsilon);
200200
}
201-
201+
202202
output_vmesh->synchronize(Mesh::NODES_E);
203203
exp_result_vmesh->synchronize(Mesh::NODES_E);
204-
204+
205205
if( output_vmesh->num_elems()!=exp_result_vmesh->num_elems() || output_vmesh->num_elems()!=exp_result_vmesh->num_elems() )
206206
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 1 does not work (number of elements is different than expected). " << std::endl;
207-
207+
208208
for(VMesh::Elem::index_type idx=0; idx<output_vmesh->num_elems(); idx++)
209209
{
210210
output_vmesh->get_nodes(onodes1, idx);
211211
exp_result_vmesh->get_nodes(onodes2, idx);
212212
for (int j=0;j<4;j++)
213213
if (onodes1[j]!=onodes2[j])
214-
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 1 does not work (definition of resulting and expected tet definition differs). " << std::endl;
214+
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 1 does not work (definition of resulting and expected tet definition differs). " << std::endl;
215215
}
216-
216+
217217
}
218-
218+
219219
}
220-
220+
221221
}
222222

223223
TEST(RefineTetMeshLocallyAlgoTests, Test5MoreTheoreticalCutCases)
224224
{
225225
double epsilon=1e-8;
226-
RefineTetMeshLocallyAlgorithm algo;
226+
RefineTetMeshLocallyAlgorithm algo;
227227
VMesh::Node::array_type onodes1(4),onodes2(4);
228228
DenseMatrixHandle output_nodes,exp_result_nodes;
229229
FieldList input_list=LoadAllCasesInputField();
230230
FieldList result_list=LoadAllCasesResultField();
231231
FieldHandle input=input_list[56];
232-
int nr_nodes = input->vmesh()->num_nodes();
232+
int nr_nodes = input->vmesh()->num_nodes();
233233
SparseRowMatrixHandle case_;
234234
GetMeshNodesAlgo getfieldnodes_algo;
235-
VMesh *case_vmesh, *case_exp_vmesh;
236235
int cases[] = {31, 47, 55, 59, 61, 62};
237236
for(int i=0; i<sizeof(cases)/4; i++)
238237
{
239238
SparseRowMatrixHandle case_=GetTheoreticalTetCases(cases[i], nr_nodes);
240-
FieldHandle Casefld=algo.RefineMesh(input, case_);
239+
FieldHandle Casefld=algo.RefineMesh(input, case_);
241240
FieldHandle case_exp_result=result_list[cases[i]-1];
242-
VMesh *case_vmesh=Casefld->vmesh();
241+
VMesh *case_vmesh=Casefld->vmesh();
243242
VMesh *case_exp_vmesh=case_exp_result->vmesh();
244-
243+
245244
try
246245
{
247246
getfieldnodes_algo.run(Casefld,output_nodes);
@@ -250,32 +249,32 @@ TEST(RefineTetMeshLocallyAlgoTests, Test5MoreTheoreticalCutCases)
250249
{
251250
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 31 does not work (could not get field nodes from input files). " << std::endl;
252251
}
253-
252+
254253
if(output_nodes->ncols()!=exp_result_nodes->ncols() || output_nodes->nrows()!=exp_result_nodes->nrows() )
255254
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 63 does not work (number of nodes is different than expected). " << std::endl;
256-
255+
257256
for (long idx=0;idx<exp_result_nodes->nrows();idx++)
258257
{
259258
EXPECT_NEAR( (*exp_result_nodes)(idx,0),(*output_nodes)(idx,0), epsilon);
260259
EXPECT_NEAR( (*exp_result_nodes)(idx,1),(*output_nodes)(idx,1), epsilon);
261260
EXPECT_NEAR( (*exp_result_nodes)(idx,2),(*output_nodes)(idx,2), epsilon);
262261
}
263-
262+
264263
case_vmesh->synchronize(Mesh::NODES_E);
265264
case_exp_vmesh->synchronize(Mesh::NODES_E);
266-
265+
267266
if( case_vmesh->num_elems()!=case_exp_vmesh->num_elems() || case_vmesh->num_elems()!=case_exp_vmesh->num_elems() )
268267
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 63 does not work (number of elements is different than expected). " << std::endl;
269-
268+
270269
for(VMesh::Elem::index_type idx=0; idx<case_vmesh->num_elems(); idx++)
271270
{
272271
case_vmesh->get_nodes(onodes1, idx);
273272
case_exp_vmesh->get_nodes(onodes2, idx);
274273
for (int j=0;j<4;j++)
275274
if (onodes1[j]!=onodes2[j])
276-
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 63 does not work (definition of resulting and expected tet definition differs). " << std::endl;
277-
}
278-
275+
FAIL() << " ERROR: RefineTetMeshLocallyAlgorithm: Case 63 does not work (definition of resulting and expected tet definition differs). " << std::endl;
276+
}
277+
279278
}
280279

281280
}

src/Core/Algorithms/Legacy/Fields/ClipMesh/ClipMeshByIsovalue.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,8 @@ bool ClipMeshByIsovalueAlgoHex::run(const AlgorithmBase* algo, FieldHandle input
12131213
ofield->resize_values();
12141214
CopyProperties(*input, *output);
12151215

1216-
const size_type nrows = nodemap.size() + node_list.size();
1217-
12181216
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
1217+
const size_type nrows = nodemap.size() + node_list.size();
12191218
// Create the interpolation matrix for downstream use.
12201219
hash_type::iterator hitr = nodemap.begin();
12211220
const size_type ncols = field->num_values();

0 commit comments

Comments
 (0)