Skip to content

Commit e21becd

Browse files
committed
Added algorithm files
1 parent 19d930d commit e21becd

File tree

7 files changed

+318
-12
lines changed

7 files changed

+318
-12
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ SET(Core_Algorithms_Legacy_Fields_HEADERS
9898
RegisterWithCorrespondences.h
9999
SampleField/GeneratePointSamplesFromField.h
100100
DistanceField/CalculateIsInsideField.h
101+
CreateMesh/ConvertMatricesToMeshAlgo.h
101102
)
102103

103104
SET(Core_Algorithms_Legacy_Fields_SRCS
@@ -119,6 +120,7 @@ SET(Core_Algorithms_Legacy_Fields_SRCS
119120
#CompareFields/CompareFields.cc
120121
#CompareFields/SimilarMeshes.cc
121122
#CreateMesh/CreateMeshFromNrrd.cc
123+
CreateMesh/ConvertMatricesToMeshAlgo.h
122124

123125
DistanceField/CalculateDistanceField.cc
124126
DistanceField/CalculateIsInsideField.cc
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2015 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/ConvertMatricesToMeshAlgo.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, InputFieldTypeName)
50+
ALGORITHM_PARAMETER_DEF(Fields, InputFieldTypeTypeName)
51+
ALGORITHM_PARAMETER_DEF(Fields, OutputMeshDataType)
52+
ALGORITHM_PARAMETER_DEF(Fields, OutputFieldDatatype)
53+
54+
ConvertMatricesToMeshAlgo::ConvertMatricesToMeshAlgo()
55+
{
56+
add_option(Parameters::OutputMeshDataType, "TetVol", "Curve|HexVol|PointCloud|PrismVol|QuadSurf|TetVol|TriSurf");
57+
add_option(Parameters::OutputFieldDataType, "double", "unsigned char|unsigned short|unsigned int|char|short|int|float|double|Vector|Tensor");
58+
}
59+
60+
bool
61+
ConvertMatricesToMeshAlgo::runImpl(FieldHandle input_field, DenseMatrixHandle input_matrix, FieldHandle& output_field) const
62+
{/*
63+
ScopedAlgorithmStatusReporter r(this, "ConvertIndicesToFieldData");
64+
65+
if (!input_field)
66+
{
67+
error("No input field");
68+
return (false);
69+
}
70+
71+
FieldInformation fi(input_field);
72+
output_field = CreateField(fi);
73+
FieldInformation fo(output_field);
74+
75+
if (fi.is_nonlinear())
76+
{
77+
error("This function has not yet been defined for non-linear elements");
78+
return (false);
79+
}
80+
81+
if (fi.is_nodata())
82+
{
83+
error("This function has not yet been defined for fields with no data");
84+
return (false);
85+
}
86+
87+
if (fi.is_vector() || fi.is_tensor())
88+
{
89+
error("This function has not yet been defined for fields with vectors or tensors as indices");
90+
return (false);
91+
}
92+
93+
size_type nrows = input_matrix->nrows();
94+
size_type ncols = input_matrix->ncols();
95+
96+
std::string algotype;
97+
98+
if (ncols == 1)
99+
{
100+
algotype = "Scalar";
101+
}
102+
else if (ncols == 3)
103+
{
104+
algotype = "Vector";
105+
}
106+
else if (ncols == 6 || ncols == 9)
107+
{
108+
algotype = "Tensor";
109+
}
110+
else
111+
{
112+
if (nrows == 1)
113+
{
114+
algotype = "Scalar";
115+
}
116+
else if (nrows == 3)
117+
{
118+
algotype = "Vector";
119+
}
120+
else if (nrows == 6 || nrows == 9)
121+
{
122+
algotype = "Tensor";
123+
}
124+
else
125+
{
126+
error("Data does not have dimension of 1, 3, 6, or 9");
127+
return (false);
128+
}
129+
}
130+
131+
if (algotype == "Scalar")
132+
{
133+
std::string datatype;
134+
get_option(Parameters::OutputFieldDataType);
135+
fo.set_data_type(get_option(Parameters::OutputFieldDataType));
136+
}
137+
if (algotype == "Vector") fo.make_vector();
138+
if (algotype == "Tensor") fo.make_tensor();
139+
140+
//--------------------------------
141+
// VIRTUAL INTERFACE
142+
143+
output_field = CreateField(fo, input_field->mesh());
144+
VField* vinput = input_field->vfield();
145+
VField* voutput = output_field->vfield();
146+
voutput->resize_fdata();
147+
148+
if (algotype == "Scalar")
149+
{
150+
int max_index = input_matrix->nrows() * input_matrix->ncols();
151+
const double *dataptr = input_matrix->data();
152+
VMesh::size_type sz = vinput->num_values();
153+
for (VMesh::index_type r = 0; r<sz; r++)
154+
{
155+
int idx;
156+
vinput->get_value(idx, r);
157+
if ((idx < 0) || (idx >= max_index))
158+
{
159+
error("Index exceeds matrix dimensions");
160+
return (false);
161+
}
162+
voutput->set_value(dataptr[idx], r);
163+
}
164+
return (true);
165+
}
166+
else if (algotype == "Vector")
167+
{
168+
if (input_matrix->ncols() != 3)
169+
{
170+
input_matrix.reset(new DenseMatrix(input_matrix->transpose()));
171+
}
172+
173+
const double *dataptr = input_matrix->data();
174+
int max_index = input_matrix->nrows();
175+
176+
VMesh::size_type sz = vinput->num_values();
177+
for (VMesh::index_type r = 0; r<sz; r++)
178+
{
179+
int idx;
180+
vinput->get_value(idx, r);
181+
if ((idx < 0) || (idx >= max_index))
182+
{
183+
error("Index exceeds matrix dimensions");
184+
return (false);
185+
}
186+
voutput->set_value(Vector(dataptr[3 * idx], dataptr[3 * idx + 1], dataptr[3 * idx + 2]), r);
187+
}
188+
return (true);
189+
}
190+
else if (algotype == "Tensor")
191+
{
192+
if ((input_matrix->ncols() != 6) && (input_matrix->ncols() != 9))
193+
{
194+
input_matrix.reset(new DenseMatrix(input_matrix->transpose()));
195+
}
196+
197+
int max_index = input_matrix->nrows();
198+
const double *dataptr = input_matrix->data();
199+
int ncols = input_matrix->ncols();
200+
201+
VMesh::size_type sz = vinput->num_values();
202+
for (VMesh::index_type r = 0; r<sz; r++)
203+
{
204+
int idx;
205+
vinput->get_value(idx, r);
206+
if ((idx < 0) || (idx >= max_index))
207+
{
208+
error("Index exceeds matrix dimensions");
209+
return (false);
210+
}
211+
if (ncols == 6)
212+
{
213+
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);
214+
}
215+
else
216+
{
217+
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);
218+
}
219+
}
220+
AlgorithmOutput output;
221+
output[Variables::OutputField] = output_field;
222+
return (true);
223+
}
224+
225+
// keep the compiler happy:
226+
// it seems reasonable to return false if none of the cases apply (AK)
227+
return (false);
228+
*/
229+
}
230+
231+
AlgorithmOutput ConvertMatricesToMeshAlgo::run_generic(const AlgorithmInput& input) const
232+
{/*
233+
auto field = input.get<Field>(Variables::InputField);
234+
auto inputmatrix = input.get<DenseMatrix>(Variables::InputMatrix);
235+
236+
FieldHandle output_field;
237+
if (!runImpl(field, inputmatrix, output_field))
238+
THROW_ALGORITHM_PROCESSING_ERROR("False returned on legacy run call.");
239+
240+
AlgorithmOutput output;
241+
output[Variables::OutputField] = output_field;
242+
return output; */
243+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2015 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_CONVERTMATRICESTOMESHALGO_H
31+
#define CORE_ALGORITHMS_FIELDS_FIELDDATA_CONVERTMATRICESTOMESHALGO_H
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_DEF(Fields, InputFieldTypeName);
42+
ALGORITHM_PARAMETER_DEF(Fields, InputFieldTypeTypeName);
43+
ALGORITHM_PARAMETER_DEF(Fields, OutputMeshDataType);
44+
ALGORITHM_PARAMETER_DEF(Fields, OutputFieldDatatype);
45+
46+
class SCISHARE ConvertMatricesToMeshAlgo : public AlgorithmBase
47+
{
48+
public:
49+
ConvertMatricesToMeshAlgo();
50+
51+
bool runImpl(FieldHandle input_field, Datatypes::DenseMatrixHandle input_matrix, FieldHandle& output_field)const;
52+
53+
// bool runImpl(FieldHandle input, Datatypes::MatrixHandle input_matrix, FieldHandle& output) const;
54+
55+
virtual AlgorithmOutput run_generic(const AlgorithmInput& input) const override;
56+
};
57+
}
58+
}
59+
}
60+
}
61+
62+
#endif
63+

src/Interface/Modules/Fields/ConvertMatricesToMeshDialog.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828

2929
#include <Interface/Modules/Fields/ConvertMatricesToMeshDialog.h>
30-
#include <Core/Algorithms/Legacy/Fields/FieldData/ConvertMatricesToMesh.h>
30+
#include <Modules/Legacy/Fields/ConvertMatricesToMesh.h>
3131
#include <Core/Algorithms/Legacy/Fields/FieldData/ConvertFieldBasisType.h>
3232

3333
using namespace SCIRun::Gui;

src/Modules/Factory/Config/ConvertMatricesToMesh.module

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"namespace": "Fields",
55
"status": "Ported module",
66
"description": "Store/retrieve values from an input matrix to/from the data of a field",
7-
"header": "Modules/Legacy/Forward/ConvertMatricesToMesh.h"
7+
"header": "Modules/Legacy/Fields/ConvertMatricesToMesh.h"
88
},
99
"algorithm": {
10-
"name": "N/A",
11-
"namespace": "N/A",
12-
"header": "N/A"
10+
"name": "ConvertMatricesToMeshAlgo",
11+
"namespace": "Fields",
12+
"header": "Core/Algorithms/Legacy/Fields/CreateMesh/ConvertMatricesToMeshAlgo.h"
1313
},
1414
"UI": {
1515
"name": "ConvertMatricesToMeshDialog",

src/Modules/Legacy/Fields/ConvertMatricesToMesh.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,17 @@
3535
///
3636

3737
#include <Modules/Legacy/Fields/ConvertMatricesToMesh.h>
38+
#include <Core/Datatypes/Matrix.h>
3839
#include <Core/Datatypes/Legacy/Field/Field.h>
3940
#include <Core/Datatypes/Legacy/Field/Mesh.h>
40-
#include <Core/Datatypes/Legacy/Matrix/Matrix.h>
4141
#include <Core/Datatypes/Legacy/Field/FieldInformation.h>
4242

4343
using namespace SCIRun::Modules::Fields;
4444
using namespace SCIRun::Dataflow::Networks;
4545

46-
ALGORITHM_PARAMETER_DEF(Fields, InputFieldTypeName)
47-
ALGORITHM_PARAMETER_DEF(Fields, InputFieldTypeTypeName)
48-
ALGORITHM_PARAMETER_DEF(Fields, OutputMeshDataType)
49-
ALGORITHM_PARAMETER_DEF(Fields, OutputFieldDatatype)
46+
const ModuleLookupInfo ConvertMatricesToMesh::staticInfo_("ConvertMatricesToMesh", "NewField", "SCIRun");
5047

51-
ConvertMatricesToMesh::ConvertMatricesToMesh()
52-
: Module(ModuleLookupInfo("ConvertMatricesToMesh", "ChangeMesh", "SCIRun"), false)
48+
ConvertMatricesToMesh::ConvertMatricesToMesh() : Module(staticInfo_)
5349
{
5450
INITIALIZE_PORT(MeshElements);
5551
INITIALIZE_PORT(MeshPositions);

src/Modules/Legacy/Fields/ConvertMatricesToMesh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ namespace SCIRun {
6565
INPUT_PORT(1, MeshPositions, Matrix);
6666
INPUT_PORT(2, MeshNormals, Matrix);
6767
OUTPUT_PORT(0, OutputField, LegacyField);
68+
69+
static const Dataflow::Networks::ModuleLookupInfo staticInfo_;
6870
};
6971
}
7072
}

0 commit comments

Comments
 (0)