Skip to content

Commit ba0d55b

Browse files
committed
Reformat
1 parent 21ce337 commit ba0d55b

File tree

1 file changed

+103
-100
lines changed

1 file changed

+103
-100
lines changed

src/Core/Algorithms/Field/InterfaceWithCleaverAlgorithm.cc

Lines changed: 103 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ InterfaceWithCleaverAlgorithm::InterfaceWithCleaverAlgorithm()
8282
FieldHandle InterfaceWithCleaverAlgorithm::run(const std::vector<FieldHandle>& input) const
8383
{
8484
FieldHandle output;
85-
85+
8686
std::vector<FieldHandle> inputs;
8787
std::copy_if(input.begin(), input.end(), std::back_inserter(inputs), [](FieldHandle f) { return f; });
8888

@@ -93,139 +93,142 @@ FieldHandle InterfaceWithCleaverAlgorithm::run(const std::vector<FieldHandle>& i
9393
}
9494
if (inputs.size()<2)
9595
{
96-
THROW_ALGORITHM_INPUT_ERROR(" At least 2 indicator functions stored as float values are needed to run cleaver! " );
97-
return FieldHandle();
96+
THROW_ALGORITHM_INPUT_ERROR(" At least 2 indicator functions stored as float values are needed to run cleaver! " );
97+
return FieldHandle();
9898
}
99-
99+
100100
std::vector<boost::shared_ptr<Cleaver::ScalarField>> fields;
101101
VMesh::dimension_type dims; int x=0,y=0,z=0;
102102
for (size_t p=1; p<inputs.size(); p++)
103103
{
104104
VMesh* imesh1 = inputs[p]->vmesh();
105-
105+
106106
if( !imesh1->is_structuredmesh() )
107107
{
108-
THROW_ALGORITHM_INPUT_ERROR("needs to be structured mesh!");
109-
} else
108+
THROW_ALGORITHM_INPUT_ERROR("needs to be structured mesh!");
109+
}
110+
else
110111
{
111-
VField* vfield1 = inputs[p]->vfield();
112-
if (!vfield1->is_scalar())
113-
{
114-
THROW_ALGORITHM_INPUT_ERROR("values at the node needs to be scalar!");
115-
return FieldHandle();
116-
}
117-
118-
imesh1->get_dimensions( dims );
119-
if (p==1)
120-
{
121-
x=dims[0]; y=dims[1]; z=dims[2];
122-
if (x<1 || y<1 || z<1)
123-
{
124-
THROW_ALGORITHM_INPUT_ERROR(" Size of input fields should be non-zero !");
125-
}
126-
} else
127-
{
128-
if ( dims[0]!=x || dims[1]!=y || dims[2]!=z)
129-
{
130-
THROW_ALGORITHM_INPUT_ERROR(" Size of input fields is inconsistent !");
131-
}
132-
}
133-
134-
if (dims.size()!=3)
135-
{
136-
THROW_ALGORITHM_INPUT_ERROR("need a three dimensional indicator function");
137-
return FieldHandle();
138-
}
139-
140-
if (vfield1->is_float())
141-
{
142-
float* ptr = static_cast<float*>(vfield1->fdata_pointer());
143-
if (ptr)
112+
VField* vfield1 = inputs[p]->vfield();
113+
if (!vfield1->is_scalar())
114+
{
115+
THROW_ALGORITHM_INPUT_ERROR("values at the node needs to be scalar!");
116+
return FieldHandle();
117+
}
118+
119+
imesh1->get_dimensions( dims );
120+
if (p==1)
144121
{
145-
fields.push_back(boost::make_shared<Cleaver::FloatField>(dims[0], dims[1], dims[2], ptr));
146-
} else
122+
x=dims[0]; y=dims[1]; z=dims[2];
123+
if (x<1 || y<1 || z<1)
124+
{
125+
THROW_ALGORITHM_INPUT_ERROR(" Size of input fields should be non-zero !");
126+
}
127+
}
128+
else
129+
{
130+
if ( dims[0]!=x || dims[1]!=y || dims[2]!=z)
131+
{
132+
THROW_ALGORITHM_INPUT_ERROR(" Size of input fields is inconsistent !");
133+
}
134+
}
135+
136+
if (dims.size()!=3)
147137
{
148-
THROW_ALGORITHM_INPUT_ERROR(" float field is NULL pointer");
138+
THROW_ALGORITHM_INPUT_ERROR("need a three dimensional indicator function");
149139
return FieldHandle();
140+
}
141+
142+
if (vfield1->is_float())
143+
{
144+
float* ptr = static_cast<float*>(vfield1->fdata_pointer());
145+
if (ptr)
146+
{
147+
fields.push_back(boost::make_shared<Cleaver::FloatField>(dims[0], dims[1], dims[2], ptr));
148+
}
149+
else
150+
{
151+
THROW_ALGORITHM_INPUT_ERROR(" float field is NULL pointer");
152+
return FieldHandle();
153+
}
150154
}
151-
}
152155

153156
}
154-
157+
155158
}
156-
159+
157160
boost::shared_ptr<Cleaver::Volume> volume(new Cleaver::Volume(toVectorOfRawPointers(fields)));
158161

159162
if ( get(VolumeScalingSpinBox_X).toDouble()>0 && get(VolumeScalingSpinBox_Y).toDouble()>0 && get(VolumeScalingSpinBox_Z).toDouble()>0 )
160163
{
161164
if (get(AbsoluteVolumeScalingRadioButton).toBool())
162-
volume->setSize(get(VolumeScalingSpinBox_X).toDouble(),get(VolumeScalingSpinBox_Y).toDouble(),get(VolumeScalingSpinBox_Z).toDouble());
163-
else
164-
if (get(RelativeVolumeScalingRadioButton).toBool())
165-
volume->setSize(get(VolumeScalingSpinBox_X).toDouble()*volume->size().x, get(VolumeScalingSpinBox_Y).toDouble()*volume->size().y, get(VolumeScalingSpinBox_Z).toDouble()*volume->size().z);
166-
else
167-
volume->setSize(dims[0],dims[1],dims[2]);
168-
}
165+
volume->setSize(get(VolumeScalingSpinBox_X).toDouble(),get(VolumeScalingSpinBox_Y).toDouble(),get(VolumeScalingSpinBox_Z).toDouble());
169166
else
170-
{
171-
volume->setSize(dims[0],dims[1],dims[2]);
172-
THROW_ALGORITHM_INPUT_ERROR(" Invalid Scaling. Use Input sizes.");
173-
}
174-
175-
/// Padding is now optional!
176-
boost::scoped_ptr<Cleaver::TetMesh> mesh(Cleaver::createMeshFromVolume(get(PaddingCheckBox).toBool() ? ((boost::shared_ptr<Cleaver::AbstractVolume>) new Cleaver::PaddedVolume(volume.get())).get() : volume.get(), get(VerboseCheckBox).toBool()));
177-
178-
FieldInformation fi("TetVolMesh",0,"double"); ///create output field
167+
if (get(RelativeVolumeScalingRadioButton).toBool())
168+
volume->setSize(get(VolumeScalingSpinBox_X).toDouble()*volume->size().x, get(VolumeScalingSpinBox_Y).toDouble()*volume->size().y, get(VolumeScalingSpinBox_Z).toDouble()*volume->size().z);
169+
else
170+
volume->setSize(dims[0],dims[1],dims[2]);
171+
}
172+
else
173+
{
174+
volume->setSize(dims[0],dims[1],dims[2]);
175+
THROW_ALGORITHM_INPUT_ERROR(" Invalid Scaling. Use Input sizes.");
176+
}
179177

180-
output = CreateField(fi);
181-
auto omesh = output->vmesh();
182-
auto ofield = output->vfield();
178+
/// Padding is now optional!
179+
boost::scoped_ptr<Cleaver::TetMesh> mesh(Cleaver::createMeshFromVolume(get(PaddingCheckBox).toBool() ? ((boost::shared_ptr<Cleaver::AbstractVolume>) new Cleaver::PaddedVolume(volume.get())).get() : volume.get(), get(VerboseCheckBox).toBool()));
183180

184-
auto nr_of_tets = mesh->tets.size();
185-
auto nr_of_verts = mesh->verts.size();
181+
FieldInformation fi("TetVolMesh",0,"double"); ///create output field
186182

187-
omesh->node_reserve(nr_of_verts);
188-
omesh->elem_reserve(nr_of_tets);
183+
output = CreateField(fi);
184+
auto omesh = output->vmesh();
185+
auto ofield = output->vfield();
189186

190-
for (auto i=0; i<nr_of_verts; i++)
191-
{
192-
omesh->add_point(Point(mesh->verts[i]->pos().x,mesh->verts[i]->pos().y,mesh->verts[i]->pos().z));
193-
}
187+
auto nr_of_tets = mesh->tets.size();
188+
auto nr_of_verts = mesh->verts.size();
194189

195-
VMesh::Node::array_type vdata;
196-
vdata.resize(4);
197-
std::vector<double> values(nr_of_tets);
198-
199-
for (auto i=0; i<nr_of_tets; i++)
200-
{
201-
vdata[0]=mesh->tets[i]->verts[0]->tm_v_index;
202-
vdata[1]=mesh->tets[i]->verts[1]->tm_v_index;
203-
vdata[2]=mesh->tets[i]->verts[2]->tm_v_index;
204-
vdata[3]=mesh->tets[i]->verts[3]->tm_v_index;
205-
omesh->add_elem(vdata);
206-
auto mat_label = mesh->tets[i]->mat_label+1;
207-
values[i]=mat_label;
208-
}
209-
ofield->resize_values();
210-
ofield->set_values(values);
211-
mesh->computeAngles();
212-
std::ostringstream ostr1;
213-
ostr1 << "Number of tetrahedral elements:" << ofield->vmesh()->num_elems() << std::endl;
214-
ostr1 << "Number of tetrahedral nodes:" << ofield->vmesh()->num_nodes() << std::endl;
215-
ostr1 << "Number of tetrahedral nodes:" << ofield->vmesh()->num_nodes() << std::endl;
216-
ostr1 << "Worst Angle (min):" << mesh->min_angle << std::endl;
217-
ostr1 << "Worst Angle (max):" << mesh->max_angle << std::endl;
218-
ostr1 << "Volume:" << volume->size().toString() << std::endl;
219-
220-
remark(ostr1.str());
190+
omesh->node_reserve(nr_of_verts);
191+
omesh->elem_reserve(nr_of_tets);
192+
193+
for (auto i=0; i<nr_of_verts; i++)
194+
{
195+
omesh->add_point(Point(mesh->verts[i]->pos().x,mesh->verts[i]->pos().y,mesh->verts[i]->pos().z));
196+
}
197+
198+
VMesh::Node::array_type vdata;
199+
vdata.resize(4);
200+
std::vector<double> values(nr_of_tets);
201+
202+
for (auto i=0; i<nr_of_tets; i++)
203+
{
204+
vdata[0]=mesh->tets[i]->verts[0]->tm_v_index;
205+
vdata[1]=mesh->tets[i]->verts[1]->tm_v_index;
206+
vdata[2]=mesh->tets[i]->verts[2]->tm_v_index;
207+
vdata[3]=mesh->tets[i]->verts[3]->tm_v_index;
208+
omesh->add_elem(vdata);
209+
auto mat_label = mesh->tets[i]->mat_label+1;
210+
values[i]=mat_label;
211+
}
212+
ofield->resize_values();
213+
ofield->set_values(values);
214+
mesh->computeAngles();
215+
std::ostringstream ostr1;
216+
ostr1 << "Number of tetrahedral elements:" << ofield->vmesh()->num_elems() << std::endl;
217+
ostr1 << "Number of tetrahedral nodes:" << ofield->vmesh()->num_nodes() << std::endl;
218+
ostr1 << "Number of tetrahedral nodes:" << ofield->vmesh()->num_nodes() << std::endl;
219+
ostr1 << "Worst Angle (min):" << mesh->min_angle << std::endl;
220+
ostr1 << "Worst Angle (max):" << mesh->max_angle << std::endl;
221+
ostr1 << "Volume:" << volume->size().toString() << std::endl;
222+
223+
remark(ostr1.str());
221224

222225
return output;
223226
}
224227

225228
AlgorithmOutput InterfaceWithCleaverAlgorithm::run_generic(const AlgorithmInput& input) const
226229
{
227230
auto inputfields = input.getList<Field>(InputFields);
228-
231+
229232
FieldHandle output_fld;
230233
output_fld=run(inputfields);
231234
if ( !output_fld ) THROW_ALGORITHM_PROCESSING_ERROR("False returned on legacy run call.");

0 commit comments

Comments
 (0)