Skip to content

Commit 8bc0be2

Browse files
authored
Merge pull request #1701 from SCIInstitute/complex-calculations
Complex calculations et al
2 parents 08040da + 1fdc648 commit 8bc0be2

File tree

81 files changed

+2350
-7314
lines changed

Some content is hidden

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

81 files changed

+2350
-7314
lines changed

src/Core/Algorithms/Describe/DescribeDatatype.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ std::string DescribeDatatype::describe(const DatatypeHandle& data) const
7272
return "[Complex Matrix Data] Info:\n" + ReportComplexMatrixInfoAlgo::summarize(info);
7373
}
7474

75+
auto cmatsp = boost::dynamic_pointer_cast<ComplexSparseRowMatrix>(data);
76+
if (cmatsp)
77+
{
78+
ReportComplexMatrixInfoAlgo algo;
79+
auto info = algo.runImpl(cmatsp);
80+
81+
return "[Complex Matrix Data] Info:\n" + ReportComplexMatrixInfoAlgo::summarize(info);
82+
}
83+
7584
auto field = boost::dynamic_pointer_cast<Field>(data);
7685
if (field)
7786
{

src/Core/Algorithms/Describe/Tests/DescribeDatatypeTests.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <Testing/Utils/MatrixTestUtilities.h>
3333
#include <Testing/Utils/SCIRunUnitTests.h>
3434
#include <Testing/ModuleTestBase/ModuleTestBase.h>
35+
#include <Core/Datatypes/MatrixTypeConversions.h>
3536

3637

3738
using namespace SCIRun;
@@ -70,3 +71,28 @@ TEST(DescribeDatatypeAlgorithmTests, CanDescribeField)
7071

7172
EXPECT_EQ("[Field Data] Info:\nType: GenericField<LatVolMesh<HexTrilinearLgn<Point> > ,HexTrilinearLgn<double> ,FData3d<double,LatVolMesh<HexTrilinearLgn<Point> > > > \nCenter: [0 0 0]\nSize: [2 2 2]\nData min,max: 0 , 0\n# nodes: 60\n# elements: 24\n# data: 60\nData location: Nodes (linear basis)\nDims (x,y,z): [3 4 5]\nGeometric size: 8\n", desc);
7273
}
74+
75+
TEST(DescribeDatatypeAlgorithmTests, CanDescribeComplexDenseMatrix)
76+
{
77+
DescribeDatatype algo;
78+
79+
auto m = boost::make_shared<ComplexDenseMatrix>(2, 2);
80+
*m << complex{ 1, 2 }, complex{ 3, -1 }, complex{ 0, 1 }, complex{ -2, -1 };
81+
82+
auto desc = algo.describe(m);
83+
84+
EXPECT_EQ("[Complex Matrix Data] Info:\nType:\t\tComplexDenseMatrix\n# Rows:\t\t2\n# Columns:\t\t2\n# Elements:\t\t4\nMinimum (by norm):\t(0,1)\nMaximum (by norm):\t(3,-1)\n", desc);
85+
}
86+
87+
TEST(DescribeDatatypeAlgorithmTests, CanDescribeComplexSparseMatrix)
88+
{
89+
DescribeDatatype algo;
90+
91+
ComplexDenseMatrix m(2, 2);
92+
m << complex{ 1, 2 }, complex{ 3, -1 }, complex{ 0, 1 }, complex{ -2, -1 };
93+
auto s = convertMatrix::fromDenseToSparse(m);
94+
95+
auto desc = algo.describe(s);
96+
97+
EXPECT_EQ("[Complex Matrix Data] Info:\nType:\t\tComplexSparseRowMatrix\n# Rows:\t\t2\n# Columns:\t\t2\n# Elements:\t\t4\nMinimum (by norm):\t(0,1)\nMaximum (by norm):\t(3,-1)\n", desc);
98+
}

src/Core/Algorithms/Legacy/Fields/FieldData/BuildMatrixOfSurfaceNormalsAlgo.cc

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,21 @@
2626
DEALINGS IN THE SOFTWARE.
2727
*/
2828

29-
#include <Core/Algorithms/Legacy/Fields/FieldData/BuildMatrixOfSurfaceNormalsAlgo.h>
29+
#include <Core/Algorithms/Legacy/Fields/FieldData/BuildMatrixOfSurfaceNormalsAlgo.h>
3030
#include <Core/Algorithms/Base/AlgorithmPreconditions.h>
3131
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
32-
//#include <Core/GeometryPrimitives/Vector.h>
3332
#include <Core/Datatypes/Legacy/Field/Field.h>
3433
#include <Core/Datatypes/Legacy/Field/VField.h>
35-
#include <Core/Datatypes/DenseMatrix.h>
34+
#include <Core/Datatypes/DenseMatrix.h>
3635
#include <Core/GeometryPrimitives/Vector.h>
37-
#include <Core/Datatypes/Legacy/Matrix/Matrix.h>
3836
#include <Core/Datatypes/Legacy/Field/FieldInformation.h>
3937

40-
//#include <Core/Datatypes/DenseMatrix.h>
41-
//#include <Core/Datatypes/Legacy/Field/VMesh.h>
42-
43-
//#include <iostream>
44-
4538
using namespace SCIRun::Core::Algorithms;
4639
using namespace SCIRun::Core::Algorithms::Fields;
4740
using namespace SCIRun::Core::Datatypes;
4841
using namespace SCIRun::Core::Geometry;
49-
using namespace SCIRun::Core::Logging;
50-
using namespace SCIRun::Core::Utility;
42+
using namespace SCIRun::Core::Logging;
43+
using namespace SCIRun::Core::Utility;
5144
using namespace SCIRun;
5245

5346
BuildMatrixOfSurfaceNormalsAlgo::BuildMatrixOfSurfaceNormalsAlgo() {}
@@ -61,19 +54,19 @@ bool BuildMatrixOfSurfaceNormalsAlgo::runImpl(FieldHandle input, DenseMatrixHand
6154
error("No input source field");
6255
return (false);
6356
}
64-
65-
FieldInformation fi(input);
57+
58+
FieldInformation fi(input);
6659
if (!(fi.is_surface()))
6760
{
6861
error("This algorithm only works on a surface mesh");
6962
return (false);
7063
}
71-
64+
7265
VMesh* vmesh = input->vmesh();
7366
vmesh->synchronize(Mesh::NORMALS_E);
7467
VMesh::size_type num_nodes = vmesh->num_nodes();
7568

76-
output.reset(new DenseMatrix(num_nodes, 3));
69+
output.reset(new DenseMatrix(num_nodes, 3));
7770

7871
if (!output)
7972
{
@@ -86,10 +79,10 @@ bool BuildMatrixOfSurfaceNormalsAlgo::runImpl(FieldHandle input, DenseMatrixHand
8679
Vector norm;
8780
for (VMesh::Node::index_type i=0; i<num_nodes; ++i)
8881
{
89-
vmesh->get_normal(norm,i);
82+
vmesh->get_normal(norm,i);
9083
(*output)(k) = norm.x();
9184
(*output)(k+1) = norm.y();
92-
(*output)(k+2) = norm.z();
85+
(*output)(k+2) = norm.z();
9386
k += 3;
9487
cnt++; if (cnt == 400) {cnt=0; update_progress_max(i,num_nodes); }
9588
}
@@ -99,12 +92,12 @@ bool BuildMatrixOfSurfaceNormalsAlgo::runImpl(FieldHandle input, DenseMatrixHand
9992
AlgorithmOutput BuildMatrixOfSurfaceNormalsAlgo::run(const AlgorithmInput& input) const
10093
{
10194
auto field = input.get<Field>(Variables::InputField);
102-
DenseMatrixHandle outputMatrix;
95+
DenseMatrixHandle outputMatrix;
10396

10497
if(!runImpl(field, outputMatrix))
105-
THROW_ALGORITHM_PROCESSING_ERROR("False returned on legacy call.");
98+
THROW_ALGORITHM_PROCESSING_ERROR("False returned on legacy call.");
10699

107100
AlgorithmOutput output;
108101
output[Variables::OutputMatrix] = outputMatrix;
109102
return output;
110-
}
103+
}

src/Core/Algorithms/Legacy/Fields/FieldData/SetFieldData.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ FieldHandle SetFieldDataAlgo::runImplRealComplex(FieldHandle input_field, DenseM
399399
found = verify_input_data(input_field, realData->nrows(), realData->ncols(), numvals, fi);
400400
else if (complexData)
401401
{
402-
found = verify_input_data(input_field, complexData->nrows(), complexData->ncols(), numvals, fi, "std::complex<double>");
402+
found = verify_input_data(input_field, complexData->nrows(), complexData->ncols(), numvals, fi, "complex");
403403
}
404404

405405
if (!found)

src/Core/Algorithms/Math/AppendMatrix.cc

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2525
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
DEALINGS IN THE SOFTWARE.
27-
27+
2828
Author : Moritz Dannhauer (reimplementation)
2929
Date: August 2017
3030
*/
@@ -33,7 +33,6 @@
3333
#include <Core/Datatypes/DenseMatrix.h>
3434
#include <Core/Datatypes/SparseRowMatrix.h>
3535
#include <Core/Datatypes/SparseRowMatrixFromMap.h>
36-
#include <Core/Datatypes/Legacy/Matrix/MatrixOperations.h>
3736
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
3837
#include <Core/Datatypes/MatrixTypeConversions.h>
3938
#include <Eigen/Sparse>
@@ -58,16 +57,16 @@ bool AppendMatrixAlgorithm::check_dimensions(const Matrix& mat1, const Matrix& m
5857
if(cols_m1!=cols_m2) return false;
5958
} else
6059
if(rows_m1!=rows_m2) return false;
61-
60+
6261
return true;
6362
}
6463

6564
AppendMatrixAlgorithm::Outputs AppendMatrixAlgorithm::ConcatenateMatrices(const MatrixHandle base_matrix, const std::vector<boost::shared_ptr<Matrix>> input_matrices, const AppendMatrixAlgorithm::Parameters& params) const
66-
{
65+
{
6766

6867
if (input_matrices.size()==0)
6968
return base_matrix;
70-
69+
7170
Outputs outputs = run(boost::make_tuple(base_matrix, input_matrices[0]), params);
7271
for(Eigen::Index c=1; c<input_matrices.size(); c++)
7372
{
@@ -79,49 +78,49 @@ AppendMatrixAlgorithm::Outputs AppendMatrixAlgorithm::ConcatenateMatrices(const
7978
}
8079

8180
AppendMatrixAlgorithm::Outputs AppendMatrixAlgorithm::run(const AppendMatrixAlgorithm::Inputs& input, const AppendMatrixAlgorithm::Parameters& params) const
82-
{
81+
{
8382
auto lhsPtr = input.get<0>();
8483
auto rhsPtr = input.get<1>();
8584
if (!lhsPtr || !rhsPtr)
8685
error(" At least two matrices are needed to run this module. ");
8786

88-
if (!((matrixIs::sparse(lhsPtr) && matrixIs::sparse(rhsPtr)) || (matrixIs::dense(lhsPtr) && matrixIs::dense(rhsPtr)) || (matrixIs::column(lhsPtr) && matrixIs::column(rhsPtr))))
87+
if (!((matrixIs::sparse(lhsPtr) && matrixIs::sparse(rhsPtr)) || (matrixIs::dense(lhsPtr) && matrixIs::dense(rhsPtr)) || (matrixIs::column(lhsPtr) && matrixIs::column(rhsPtr))))
8988
{
9089
error(" Mixing of different matrix types as inputs is not supported. ");
91-
return Outputs();
90+
return Outputs();
9291
}
93-
92+
9493
if (!check_dimensions(*lhsPtr, *rhsPtr, params))
9594
{
9695
error(" Input matrix dimensions do not match. ");
9796
return Outputs();
9897
}
99-
98+
10099
Eigen::MatrixXd result;
101100
if(matrixIs::dense(lhsPtr) || matrixIs::column(lhsPtr))
102101
{
103102
if(params == ROWS)
104103
result=Eigen::MatrixXd(lhsPtr->nrows()+rhsPtr->nrows(),lhsPtr->ncols());
105104
else
106-
result=Eigen::MatrixXd(lhsPtr->nrows(),lhsPtr->ncols()+rhsPtr->ncols());
107-
105+
result=Eigen::MatrixXd(lhsPtr->nrows(),lhsPtr->ncols()+rhsPtr->ncols());
106+
108107
if(matrixIs::dense(lhsPtr))
109108
result << *castMatrix::toDense(lhsPtr), *castMatrix::toDense(rhsPtr);
110109
else
111110
result << *castMatrix::toColumn(lhsPtr), *castMatrix::toColumn(rhsPtr);
112-
111+
113112
if (matrixIs::column(lhsPtr) && (result.rows()==1 || result.cols()==1))
114-
return boost::make_shared<DenseColumnMatrix>(result);
115-
113+
return boost::make_shared<DenseColumnMatrix>(result);
114+
116115
return boost::make_shared<DenseMatrix>(result);
117116
} else
118117
if (matrixIs::sparse(lhsPtr))
119118
return SparseRowMatrixFromMap::concatenateSparseMatrices(*castMatrix::toSparse(lhsPtr),*castMatrix::toSparse(rhsPtr),params==ROWS);
120119
else
121120
{
122121
error(" This matrix type is not supported");
123-
}
124-
122+
}
123+
125124
return Outputs();
126125
}
127126

@@ -130,14 +129,14 @@ AlgorithmOutput AppendMatrixAlgorithm::run(const AlgorithmInput& input) const
130129
auto lhs = input.get<Matrix>(Variables::FirstMatrix);
131130
auto rhs = input.get<Matrix>(Variables::SecondMatrix);
132131
auto input_matrices = input.getList<Matrix>(AppendMatrixAlgorithm::InputMatrices);
133-
134-
Outputs outputs;
132+
133+
Outputs outputs;
135134
Parameters params=Option(get(Variables::RowsOrColumns).toInt());
136135
outputs = run(boost::make_tuple(lhs, rhs), params);
137-
136+
138137
if (input_matrices.size()>0)
139138
outputs = ConcatenateMatrices(outputs, input_matrices, params);
140-
139+
141140
AlgorithmOutput output;
142141
output[Variables::ResultMatrix] = outputs;
143142
return output;

src/Core/Application/Preferences/Preferences.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <boost/filesystem.hpp>
3333
#include <boost/algorithm/string/predicate.hpp>
3434
#include <boost/algorithm/string/split.hpp>
35+
#include <boost/algorithm/string/replace.hpp>
3536
#include <boost/algorithm/string/classification.hpp>
3637
#ifdef BUILD_WITH_PYTHON
3738
#include <Core/Python/PythonInterpreter.h>
@@ -90,7 +91,8 @@ void Preferences::setDataDirectory(const boost::filesystem::path& path, bool run
9091
#ifdef BUILD_WITH_PYTHON
9192
if (runPython)
9293
{
93-
auto setDataDir = "import os; os.environ[\"SCIRUNDATADIR\"] = \"" + dataDir_.string() + "\"";
94+
auto forwardSlashPath = boost::replace_all_copy(dataDir_.string(), "\\", "/");
95+
auto setDataDir = "import os; os.environ[\"SCIRUNDATADIR\"] = \"" + forwardSlashPath + "\"";
9496
PythonInterpreter::Instance().run_string(setDataDir);
9597
}
9698
#endif

src/Core/Datatypes/Color.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ namespace Datatypes {
8585
std::tuple<int,int> windowSize;
8686
};
8787

88+
struct SCISHARE MeshComponentSelectionFeedback : ModuleFeedback
89+
{
90+
MeshComponentSelectionFeedback() {}
91+
MeshComponentSelectionFeedback(const std::string& mod, const std::string& comp, bool sel) :
92+
moduleId(mod), component(comp), selected(sel) {}
93+
std::string moduleId;
94+
std::string component;
95+
bool selected {false};
96+
};
97+
8898
}}}
8999

90100

src/Core/Datatypes/DenseColumnMatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace Datatypes {
4747
typedef DenseColumnMatrixGeneric<T> this_type;
4848
typedef Eigen::Matrix<T, Eigen::Dynamic, 1> EigenBase;
4949

50-
DenseColumnMatrixGeneric(size_t nrows = 0) : EigenBase(nrows) {}
50+
explicit DenseColumnMatrixGeneric(size_t nrows = 0) : EigenBase(nrows) {}
5151

5252
/// This constructor allows you to construct DenseColumnMatrixGeneric from Eigen expressions
5353
template<typename OtherDerived>

src/Core/Datatypes/Geometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace Datatypes
6161

6262
struct SCISHARE ModuleFeedback
6363
{
64-
// tag class
64+
virtual ~ModuleFeedback() {}
6565
};
6666

6767
}}}

src/Core/Datatypes/Legacy/Base/TypeName.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ template<> std::string find_type_name(double*)
7070

7171
template<> std::string find_type_name(std::complex<double>*)
7272
{
73-
static const std::string name = "std::complex<double>";
73+
static const std::string name = "complex";
7474
return name;
7575
}
7676

0 commit comments

Comments
 (0)