Skip to content

Commit 7a3d367

Browse files
committed
merging master
2 parents 871a430 + cacc359 commit 7a3d367

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1877
-996
lines changed

src/Core/Algorithms/Base/AlgorithmLogger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace Algorithms {
4242
AlgorithmLogger();
4343
~AlgorithmLogger();
4444
void setLogger(Core::Logging::LoggerHandle logger);
45+
Core::Logging::LoggerHandle getLogger() const { return logger_; }
4546

4647
/// functions for the algorithm, so it can forward errors if needed
4748
virtual void error(const std::string& error) const;

src/Core/Algorithms/BrainStimulator/ElectrodeCoilSetupAlgorithm.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ boost::tuple<DenseMatrixHandle, FieldHandle, FieldHandle, VariableHandle> Electr
822822
/// but first splitbydomain to get the surface with tha value 1.0
823823
SplitFieldByDomainAlgo algo_splitfieldbydomain;
824824
algo_splitfieldbydomain.setUpdaterFunc(getUpdaterFunc());
825+
algo_splitfieldbydomain.setLogger(getLogger());
825826
FieldList final_electrode_sponge_surf_domainsplit;
826827
algo_splitfieldbydomain.set(SplitFieldByDomainAlgo::SortBySize, true);
827828
algo_splitfieldbydomain.set(SplitFieldByDomainAlgo::SortAscending, false);

src/Core/Algorithms/BrainStimulator/SetupRHSforTDCSandTMSAlgorithm.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ boost::tuple<DenseMatrixHandle, DenseMatrixHandle, DenseMatrixHandle, DenseMatri
489489
/// use SplitFieldByDomainAlgo to find only labeled (based on elc. normal criteria) surfaces
490490
VMesh::Elem::index_type c_ind=0;
491491
SplitFieldByDomainAlgo algo2;
492+
algo2.setUpdaterFunc(getUpdaterFunc());
493+
algo2.setLogger(getLogger());
492494
FieldList output;
493495
algo2.set(SplitFieldByDomainAlgo::SortBySize, true);
494496
algo2.set(SplitFieldByDomainAlgo::SortAscending, false);

src/Core/Algorithms/Factory/HardCodedAlgorithmFactory.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <Core/Algorithms/Legacy/Fields/TransformMesh/ScaleFieldMeshAndData.h>
5757
#include <Core/Algorithms/Legacy/Fields/TransformMesh/ProjectPointsOntoMesh.h>
5858
#include <Core/Algorithms/Legacy/Fields/FieldData/SwapFieldDataWithMatrixEntriesAlgo.h>
59+
#include <Core/Algorithms/Legacy/Fields/FieldData/ConvertIndicesToFieldDataAlgo.h>
5960
#include <Core/Algorithms/Legacy/Fields/Mapping/BuildMappingMatrixAlgo.h>
6061
#include <Core/Algorithms/Math/AddKnownsToLinearSystem.h>
6162
#include <Core/Algorithms/Math/LinearSystem/SolveLinearSystemAlgo.h>
@@ -165,6 +166,7 @@ void HardCodedAlgorithmFactory::addToMakerMap()
165166
ADD_MODULE_ALGORITHM(FlipSurfaceNormals,FlipSurfaceNormalsAlgo)
166167
ADD_MODULE_ALGORITHM(BuildNoiseColumnMatrix,BuildNoiseColumnMatrixAlgorithm)
167168
ADD_MODULE_ALGORITHM(BuildMappingMatrix, BuildMappingMatrixAlgo)
169+
ADD_MODULE_ALGORITHM(ConvertIndicesToFieldData, ConvertIndicesToFieldDataAlgo)
168170
;
169171
}
170172
}

src/Core/Algorithms/Legacy/Fields/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SET(Core_Algorithms_Legacy_Fields_HEADERS
3535
FieldData/BuildMatrixOfSurfaceNormalsAlgo.h
3636
#Mapping/ApplyMappingMatrix.h
3737
#FieldData/CalculateFieldDataMetric.h
38-
#FieldData/ConvertIndicesToFieldData.h
38+
FieldData/ConvertIndicesToFieldDataAlgo.h
3939
FieldData/CalculateGradientsAlgo.h
4040
FieldData/CalculateVectorMagnitudesAlgo.h
4141
#FieldData/ConvertMappingMatrixToFieldData.h
@@ -116,7 +116,7 @@ SET(Core_Algorithms_Legacy_Fields_SRCS
116116
#FieldData/ConvertFieldDataType.cc
117117
FieldData/ConvertFieldBasisType.cc
118118
FieldData/SwapFieldDataWithMatrixEntriesAlgo.cc
119-
#FieldData/ConvertIndicesToFieldData.cc
119+
FieldData/ConvertIndicesToFieldDataAlgo.cc
120120
#FieldData/GetFieldData.cc
121121
#FieldData/ConvertMappingMatrixToFieldData.cc
122122
FieldData/SetFieldData.cc
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2009 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
#include <Core/Algorithms/Legacy/Fields/FieldData/ConvertIndicesToFieldDataAlgo.h>
30+
#include <Core/Datatypes/Legacy/Field/Field.h>
31+
#include <Core/Datatypes/Legacy/Field/VField.h>
32+
#include <Core/Datatypes/Matrix.h>
33+
#include <Core/Datatypes/MatrixTypeConversions.h>
34+
#include <Core/Datatypes/SparseRowMatrix.h>
35+
#include <Core/Datatypes/DatatypeFwd.h>
36+
#include <Core/Datatypes/Legacy/Field/FieldInformation.h>
37+
#include <Core/Datatypes/DenseMatrix.h>
38+
39+
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
40+
#include <Core/Algorithms/Base/AlgorithmPreconditions.h>
41+
42+
using namespace SCIRun::Core::Algorithms;
43+
using namespace SCIRun::Core::Geometry;
44+
using namespace SCIRun::Core::Algorithms::Fields;
45+
using namespace SCIRun::Core::Algorithms::Fields::Parameters;
46+
using namespace SCIRun::Core::Datatypes;
47+
using namespace SCIRun;
48+
49+
ALGORITHM_PARAMETER_DEF(Fields, OutputFieldDataType);
50+
51+
ConvertIndicesToFieldDataAlgo::ConvertIndicesToFieldDataAlgo()
52+
{
53+
add_option(Parameters::OutputFieldDataType, "double","double|float|char|unsigned char|short|unsigned short|int|unsigned int");
54+
}
55+
56+
bool
57+
ConvertIndicesToFieldDataAlgo::runImpl(FieldHandle input_field, DenseMatrixHandle input_matrix, FieldHandle& output_field) const
58+
{
59+
ScopedAlgorithmStatusReporter r(this, "ConvertIndicesToFieldData");
60+
61+
if (!input_field)
62+
{
63+
error("No input field");
64+
return (false);
65+
}
66+
67+
FieldInformation fi(input_field);
68+
output_field = CreateField(fi);
69+
FieldInformation fo(output_field);
70+
71+
if (fi.is_nonlinear())
72+
{
73+
error("This function has not yet been defined for non-linear elements");
74+
return (false);
75+
}
76+
77+
if (fi.is_nodata())
78+
{
79+
error("This function has not yet been defined for fields with no data");
80+
return (false);
81+
}
82+
83+
if (fi.is_vector() || fi.is_tensor())
84+
{
85+
error("This function has not yet been defined for fields with vectors or tensors as indices");
86+
return (false);
87+
}
88+
89+
size_type nrows = input_matrix->nrows();
90+
size_type ncols = input_matrix->ncols();
91+
92+
std::string algotype;
93+
94+
if (ncols == 1)
95+
{
96+
algotype = "Scalar";
97+
}
98+
else if (ncols == 3)
99+
{
100+
algotype = "Vector";
101+
}
102+
else if (ncols == 6 || ncols == 9)
103+
{
104+
algotype = "Tensor";
105+
}
106+
else
107+
{
108+
if (nrows == 1)
109+
{
110+
algotype = "Scalar";
111+
}
112+
else if (nrows == 3)
113+
{
114+
algotype = "Vector";
115+
}
116+
else if (nrows == 6 || nrows == 9)
117+
{
118+
algotype = "Tensor";
119+
}
120+
else
121+
{
122+
error("Data does not have dimension of 1, 3, 6, or 9");
123+
return (false);
124+
}
125+
}
126+
127+
if (algotype == "Scalar")
128+
{
129+
std::string datatype;
130+
get_option(Parameters::OutputFieldDataType);
131+
fo.set_data_type(get_option(Parameters::OutputFieldDataType));
132+
}
133+
if (algotype == "Vector") fo.make_vector();
134+
if (algotype == "Tensor") fo.make_tensor();
135+
136+
//--------------------------------
137+
// VIRTUAL INTERFACE
138+
139+
output_field = CreateField(fo, input_field->mesh());
140+
VField* vinput = input_field->vfield();
141+
VField* voutput = output_field->vfield();
142+
voutput->resize_fdata();
143+
144+
if (algotype == "Scalar")
145+
{
146+
int max_index = input_matrix->nrows() * input_matrix->ncols();
147+
const double *dataptr = input_matrix->data();
148+
VMesh::size_type sz = vinput->num_values();
149+
for (VMesh::index_type r = 0; r<sz; r++)
150+
{
151+
int idx;
152+
vinput->get_value(idx, r);
153+
if ((idx < 0) || (idx >= max_index))
154+
{
155+
error("Index exceeds matrix dimensions");
156+
return (false);
157+
}
158+
voutput->set_value(dataptr[idx], r);
159+
}
160+
return (true);
161+
}
162+
else if (algotype == "Vector")
163+
{
164+
if (input_matrix->ncols() != 3)
165+
{
166+
input_matrix.reset(new DenseMatrix(input_matrix->transpose()));
167+
}
168+
169+
const double *dataptr = input_matrix->data();
170+
int max_index = input_matrix->nrows();
171+
172+
VMesh::size_type sz = vinput->num_values();
173+
for (VMesh::index_type r = 0; r<sz; r++)
174+
{
175+
int idx;
176+
vinput->get_value(idx, r);
177+
if ((idx < 0) || (idx >= max_index))
178+
{
179+
error("Index exceeds matrix dimensions");
180+
return (false);
181+
}
182+
voutput->set_value(Vector(dataptr[3 * idx], dataptr[3 * idx + 1], dataptr[3 * idx + 2]), r);
183+
}
184+
return (true);
185+
}
186+
else if (algotype == "Tensor")
187+
{
188+
if ((input_matrix->ncols() != 6) && (input_matrix->ncols() != 9))
189+
{
190+
input_matrix.reset(new DenseMatrix(input_matrix->transpose()));
191+
}
192+
193+
int max_index = input_matrix->nrows();
194+
const double *dataptr = input_matrix->data();
195+
int ncols = input_matrix->ncols();
196+
197+
VMesh::size_type sz = vinput->num_values();
198+
for (VMesh::index_type r = 0; r<sz; r++)
199+
{
200+
int idx;
201+
vinput->get_value(idx, r);
202+
if ((idx < 0) || (idx >= max_index))
203+
{
204+
error("Index exceeds matrix dimensions");
205+
return (false);
206+
}
207+
if (ncols == 6)
208+
{
209+
voutput->set_value(Tensor(dataptr[3 * idx], dataptr[3 * idx + 1], dataptr[3 * idx + 2], dataptr[3 * idx + 3], dataptr[3 * idx + 4], dataptr[3 * idx + 5]), r);
210+
}
211+
else
212+
{
213+
voutput->set_value(Tensor(dataptr[3 * idx], dataptr[3 * idx + 1], dataptr[3 * idx + 2], dataptr[3 * idx + 4], dataptr[3 * idx + 5], dataptr[3 * idx + 8]), r);
214+
}
215+
}
216+
AlgorithmOutput output;
217+
output[Variables::OutputField] = output_field;
218+
return (true);
219+
}
220+
221+
// keep the compiler happy:
222+
// it seems reasonable to return false if none of the cases apply (AK)
223+
return (false);
224+
}
225+
226+
AlgorithmOutput ConvertIndicesToFieldDataAlgo::run_generic(const AlgorithmInput& input) const
227+
{
228+
auto field = input.get<Field>(Variables::InputField);
229+
auto inputmatrix = input.get<DenseMatrix>(Variables::InputMatrix);
230+
231+
FieldHandle output_field;
232+
if (!runImpl(field, inputmatrix, output_field))
233+
THROW_ALGORITHM_PROCESSING_ERROR("False returned on legacy run call.");
234+
235+
AlgorithmOutput output;
236+
output[Variables::OutputField] = output_field;
237+
return output;
238+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2009 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
30+
#ifndef CORE_ALGORITHMS_FIELDS_FIELDDATA_CONVERTINDICESTOFIELDDATAALGO_H
31+
#define CORE_ALGORITHMS_FIELDS_FIELDDATA_CONVERTINDICESTOFIELDDATAALGO_H 1
32+
33+
#include <Core/Algorithms/Base/AlgorithmBase.h>
34+
#include <Core/Algorithms/Legacy/Fields/share.h>
35+
36+
namespace SCIRun {
37+
namespace Core {
38+
namespace Algorithms {
39+
namespace Fields {
40+
41+
ALGORITHM_PARAMETER_DECL(OutputFieldDataType);
42+
43+
class SCISHARE ConvertIndicesToFieldDataAlgo : public AlgorithmBase
44+
{
45+
public:
46+
ConvertIndicesToFieldDataAlgo();
47+
48+
bool runImpl(FieldHandle input_field, Datatypes::DenseMatrixHandle input_matrix, FieldHandle& output_field)const;
49+
50+
// bool runImpl(FieldHandle input, Datatypes::MatrixHandle input_matrix, FieldHandle& output) const;
51+
52+
virtual AlgorithmOutput run_generic(const AlgorithmInput& input) const override;
53+
};
54+
}
55+
}
56+
}
57+
}
58+
59+
#endif
60+

src/Core/Algorithms/Legacy/Forward/BuildBEMatrixAlgo.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,11 @@ BEMAlgoPtr BEMAlgoImplFactory::create(const bemfield_vector& fields)
10231023

10241024
static void printInfo(const DenseMatrix& m, const std::string& name)
10251025
{
1026+
#if 0
10261027
std::cout << name << ": " << m.rows() << " x " << m.cols() << std::endl;
10271028
std::cout << name << " min: " << m.minCoeff() << std::endl;
10281029
std::cout << name << " max: " << m.maxCoeff() << std::endl;
1030+
#endif
10291031
}
10301032

10311033
MatrixHandle SurfaceToSurface::compute(const bemfield_vector& fields) const
@@ -1128,14 +1130,14 @@ MatrixHandle SurfaceToSurface::compute(const bemfield_vector& fields) const
11281130
if (i == sourcefieldindices[j])
11291131
{
11301132
auto block = EJ.blockRef(i,j);
1131-
std::cout << "EJ block auto " << i << "," << j << " is size " << block.rows() << " x " << block.cols() /*<< " starting at " << blockStartsEE[i] << "," << blockStartsEJ[j]*/ << std::endl;
1133+
//std::cout << "EJ block auto " << i << "," << j << " is size " << block.rows() << " x " << block.cols() /*<< " starting at " << blockStartsEE[i] << "," << blockStartsEJ[j]*/ << std::endl;
11321134

11331135
make_auto_G_compute(fields[i].field_->vmesh(), block, fields[i].insideconductivity, fields[i].outsideconductivity, op_cond, triangleareas);
11341136
}
11351137
else
11361138
{
11371139
auto block = EJ.blockRef(i,j);
1138-
std::cout << "EJ block cross " << i << "," << j << " is size " << block.rows() << " x " << block.cols()/* << " starting at " << blockStartsEE[i] << "," << blockStartsEJ[j]*/ << std::endl;
1140+
//std::cout << "EJ block cross " << i << "," << j << " is size " << block.rows() << " x " << block.cols()/* << " starting at " << blockStartsEE[i] << "," << blockStartsEJ[j]*/ << std::endl;
11391141

11401142
make_cross_G_compute(fields[i].field_->vmesh(), fields[sourcefieldindices[j]].field_->vmesh(), block, fields[i].insideconductivity, fields[i].outsideconductivity, op_cond, triangleareas);
11411143
}

0 commit comments

Comments
 (0)