Skip to content

Commit a016a12

Browse files
committed
Extract function for converting LatVols to Cleaver FloatFields
1 parent 207206a commit a016a12

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/Core/Algorithms/Field/InterfaceWithCleaverAlgorithm.cc

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,34 @@ InterfaceWithCleaverAlgorithm::InterfaceWithCleaverAlgorithm()
7474
addParameter(VolumeScalingZ,1.0);
7575
}
7676

77+
boost::shared_ptr<Cleaver::ScalarField> InterfaceWithCleaverAlgorithm::makeCleaverFieldFromLatVol(FieldHandle field)
78+
{
79+
//TODO: this function assumes input is completely valid, may want to move various checks from run() function here.
80+
81+
VMesh* vmesh = field->vmesh();
82+
VField* vfield = field->vfield();
83+
VMesh::dimension_type dims;
84+
vmesh->get_dimensions( dims );
85+
float* ptr = static_cast<float*>(vfield->fdata_pointer());
86+
auto cleaverField = boost::make_shared<Cleaver::FloatField>(dims[0], dims[1], dims[2], ptr);
87+
88+
//0 = constant, 1 = linear
89+
if (0 == vfield->basis_order())
90+
cleaverField->setCenter(Cleaver::FloatField::CellCentered);
91+
else if (1 == vfield->basis_order())
92+
cleaverField->setCenter(Cleaver::FloatField::NodeCentered);
93+
//else: TODO? handle other bases, probably by throwing exception.
94+
95+
//TODO: Cleaver FloatField needs more setup (constructor is not sufficient)
96+
// 1.
97+
// setBounds(BoundingBox). Convert vmesh->get_bounding_box() to Cleaver BoundingBox.
98+
// 2.
99+
// setScale(vec3). Need to figure out which vmesh function to call, and convert to Cleaver::vec3.
100+
// 3. unit test heavily.
101+
102+
return cleaverField;
103+
}
104+
77105
FieldHandle InterfaceWithCleaverAlgorithm::run(const std::vector<FieldHandle>& input) const
78106
{
79107
FieldHandle output;
@@ -96,15 +124,16 @@ FieldHandle InterfaceWithCleaverAlgorithm::run(const std::vector<FieldHandle>& i
96124
VMesh::dimension_type dims; int x=0,y=0,z=0;
97125
for (size_t p=1; p<inputs.size(); p++)
98126
{
99-
VMesh* imesh1 = inputs[p]->vmesh();
127+
FieldHandle input = inputs[p];
128+
VMesh* imesh1 = input->vmesh();
100129

101130
if( !imesh1->is_structuredmesh() )
102131
{
103132
THROW_ALGORITHM_INPUT_ERROR("needs to be structured mesh!");
104133
}
105134
else
106135
{
107-
VField* vfield1 = inputs[p]->vfield();
136+
VField* vfield1 = input->vfield();
108137
if (!vfield1->is_scalar())
109138
{
110139
THROW_ALGORITHM_INPUT_ERROR("values at the node needs to be scalar!");
@@ -139,7 +168,7 @@ FieldHandle InterfaceWithCleaverAlgorithm::run(const std::vector<FieldHandle>& i
139168
float* ptr = static_cast<float*>(vfield1->fdata_pointer());
140169
if (ptr)
141170
{
142-
fields.push_back(boost::make_shared<Cleaver::FloatField>(dims[0], dims[1], dims[2], ptr));
171+
fields.push_back(makeCleaverFieldFromLatVol(input));
143172
}
144173
else
145174
{

src/Core/Algorithms/Field/InterfaceWithCleaverAlgorithm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
#include <Core/Datatypes/DatatypeFwd.h>
3434
#include <Core/Algorithms/Field/share.h>
3535

36+
namespace Cleaver
37+
{
38+
class ScalarField;
39+
}
40+
3641
namespace SCIRun {
3742
namespace Core {
3843
namespace Algorithms {
@@ -52,6 +57,8 @@ namespace Fields {
5257

5358
FieldHandle run(const FieldList& input) const;
5459
virtual AlgorithmOutput run_generic(const AlgorithmInput &) const override;
60+
61+
static boost::shared_ptr<Cleaver::ScalarField> makeCleaverFieldFromLatVol(FieldHandle field);
5562
};
5663

5764
}}}}

0 commit comments

Comments
 (0)