Skip to content

Commit 5783116

Browse files
committed
Clean up and improve error message. Closes #1188
1 parent 1a0686a commit 5783116

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/Modules/Legacy/Fields/InterfaceWithTetGen.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
#include <Modules/Legacy/Fields/InterfaceWithTetGen.h>
3030
#include <Modules/Legacy/Fields/InterfaceWithTetGenImpl.h>
31+
// ReSharper disable once CppUnusedIncludeDirective
3132
#include <Core/Datatypes/Legacy/Field/Field.h>
3233
#include <Dataflow/Network/ModuleStateInterface.h>
3334

3435
using namespace SCIRun::Modules::Fields;
3536
using namespace SCIRun::Core::Algorithms;
36-
using namespace SCIRun::Core::Algorithms::Fields;
37+
using namespace Fields;
3738
using namespace SCIRun::Dataflow::Networks;
3839
using namespace SCIRun::Core::Datatypes;
3940
using namespace SCIRun;

src/Modules/Legacy/Fields/InterfaceWithTetGenImpl.cc

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@
4545
#define TETLIBRARY // Required definition for use of tetgen library
4646
#include <tetgen/tetgen.h>
4747

48-
#include <algorithm>
4948
#include <sstream>
5049

5150
#include <sci_debug.h>
5251

5352
using namespace SCIRun;
54-
using namespace SCIRun::Dataflow::Networks;
55-
using namespace SCIRun::Modules::Fields;
56-
using namespace SCIRun::Core::Thread;
57-
using namespace SCIRun::Core::Geometry;
53+
using namespace Dataflow::Networks;
54+
using namespace Modules::Fields;
55+
using namespace Core::Thread;
56+
using namespace Core::Geometry;
5857

5958
namespace SCIRun {
6059
namespace Modules {
@@ -79,7 +78,7 @@ class InterfaceWithTetGenImplImpl //: public AlgorithmBase
7978
static Mutex TetGenMutex;
8079
};
8180

82-
Mutex detail::InterfaceWithTetGenImplImpl::TetGenMutex("Protect TetGen from running in parallel");
81+
Mutex InterfaceWithTetGenImplImpl::TetGenMutex("Protect TetGen from running in parallel");
8382
}}}}
8483

8584
detail::InterfaceWithTetGenImplImpl::InterfaceWithTetGenImplImpl(Module* module) : module_(module)
@@ -180,7 +179,7 @@ FieldHandle detail::InterfaceWithTetGenImplImpl::runImpl(const std::deque<FieldH
180179

181180
addin.numberofpoints = num_nodes;
182181
addin.pointlist = new REAL[num_nodes*3];
183-
for(VMesh::Node::index_type idx=0; idx<num_nodes; idx++)
182+
for(VMesh::Node::index_type idx=0; idx<num_nodes; ++idx)
184183
{
185184
Point p;
186185
mesh->get_center(p, idx);
@@ -200,7 +199,7 @@ FieldHandle detail::InterfaceWithTetGenImplImpl::runImpl(const std::deque<FieldH
200199

201200
in.regionlist = new REAL[num_nodes*5];
202201
in.numberofregions = num_nodes;
203-
for(VMesh::Node::index_type idx=0; idx<num_nodes; idx++)
202+
for(VMesh::Node::index_type idx=0; idx<num_nodes; ++idx)
204203
{
205204
Point p; double val;
206205
mesh->get_center(p, idx);
@@ -242,7 +241,7 @@ FieldHandle detail::InterfaceWithTetGenImplImpl::runImpl(const std::deque<FieldH
242241

243242
VMesh::index_type idx = 0;
244243
VMesh::index_type fidx = 0;
245-
VMesh::index_type off = 0;
244+
VMesh::index_type off;
246245

247246
for (size_t j=0; j< surfaces.size(); j++)
248247
{
@@ -251,7 +250,7 @@ FieldHandle detail::InterfaceWithTetGenImplImpl::runImpl(const std::deque<FieldH
251250
VMesh::Elem::size_type num_elems = mesh->num_elems();
252251

253252
off = idx;
254-
for(VMesh::Node::index_type nidx=0; nidx<num_nodes; nidx++)
253+
for(VMesh::Node::index_type nidx=0; nidx<num_nodes; ++nidx)
255254
{
256255
Point p;
257256
mesh->get_center(p, nidx);
@@ -266,21 +265,21 @@ FieldHandle detail::InterfaceWithTetGenImplImpl::runImpl(const std::deque<FieldH
266265
// iterate over faces.
267266
VMesh::Node::array_type nodes;
268267

269-
for(VMesh::Elem::index_type eidx=0; eidx<num_elems; eidx++)
268+
for(VMesh::Elem::index_type eidx=0; eidx<num_elems; ++eidx)
270269
{
271270
tetgenio::facet *f = &in.facetlist[fidx];
272271
f->numberofpolygons = 1;
273272
f->polygonlist = new tetgenio::polygon[1];
274273
f->numberofholes = 0;
275-
f->holelist = 0;
274+
f->holelist = nullptr;
276275
tetgenio::polygon *p = &f->polygonlist[0];
277276
p->numberofvertices = vert_per_face;
278277
p->vertexlist = new int[p->numberofvertices];
279278

280279
mesh->get_nodes(nodes, eidx);
281-
for (size_t j=0; j<nodes.size(); j++)
280+
for (size_t i=0; i<nodes.size(); i++)
282281
{
283-
p->vertexlist[j] = VMesh::index_type(nodes[j]) + off;
282+
p->vertexlist[i] = VMesh::index_type(nodes[i]) + off;
284283
}
285284

286285
in.facetmarkerlist[fidx] = marker;
@@ -300,7 +299,7 @@ FieldHandle detail::InterfaceWithTetGenImplImpl::runImpl(const std::deque<FieldH
300299
#if DEBUG
301300
std::cerr << "\nTetgen command line: " << cmmd_ln << std::endl;
302301
#endif
303-
tetgenio *addtgio = 0;
302+
tetgenio *addtgio = nullptr;
304303
if (add_points)
305304
{
306305
addtgio = &addin;
@@ -313,9 +312,14 @@ FieldHandle detail::InterfaceWithTetGenImplImpl::runImpl(const std::deque<FieldH
313312
Guard g(TetGenMutex.get());
314313
try
315314
{
316-
tetrahedralize((char*)cmmd_ln.c_str(), &in, &out, addtgio);
315+
tetrahedralize(const_cast<char*>(cmmd_ln.c_str()), &in, &out, addtgio);
317316
}
318-
catch(...)
317+
catch(std::exception& e)
318+
{
319+
module_->error(std::string("TetGen failed to generate a mesh: ") + e.what());
320+
return nullptr;
321+
}
322+
catch (...)
319323
{
320324
module_->error("TetGen failed to generate a mesh");
321325
return nullptr;
@@ -388,7 +392,7 @@ moreSwitches_("")
388392
{
389393
}
390394

391-
InterfaceWithTetGenImpl::InterfaceWithTetGenImpl(Dataflow::Networks::Module* module, const InterfaceWithTetGenInput& input) :
395+
InterfaceWithTetGenImpl::InterfaceWithTetGenImpl(Module* module, const InterfaceWithTetGenInput& input) :
392396
impl_(new detail::InterfaceWithTetGenImplImpl(module)),
393397
inputFlags_(input)
394398
{}

0 commit comments

Comments
 (0)