Skip to content

Commit 550f111

Browse files
committed
Closes #481
1 parent c1c4318 commit 550f111

File tree

5 files changed

+76
-86
lines changed

5 files changed

+76
-86
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SET(Core_Algorithms_Legacy_DataIO_SRCS
3333
ObjToFieldReader.cc
3434
VTKToTriSurfReader.cc
3535
TriSurfSTLBinaryConverter.cc
36-
#TriSurfSTLASCIIConverter.cc
36+
TriSurfSTLASCIIConverter.cc
3737
STLUtils.cc
3838
)
3939

src/Core/Algorithms/Legacy/DataIO/TriSurfSTLASCIIConverter.cc

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,47 @@
2626
DEALINGS IN THE SOFTWARE.
2727
*/
2828

29-
#include <Core/Algorithms/DataIO/Legacy/TriSurfSTLASCIIConverter.h>
30-
#include <Core/Algorithms/DataIO/Legacy/STLUtils.h>
29+
#include <Core/Algorithms/Legacy/DataIO/TriSurfSTLASCIIConverter.h>
30+
#include <Core/Algorithms/Legacy/DataIO/STLUtils.h>
3131

32-
#include <Core/Datatypes/VField.h>
33-
#include <Core/Datatypes/VMesh.h>
34-
#include <Core/Datatypes/FieldInformation.h>
35-
#include <Core/Util/StringUtil.h>
32+
#include <Core/Datatypes/Legacy/Field/VField.h>
33+
#include <Core/Datatypes/Legacy/Field/VMesh.h>
34+
#include <Core/Datatypes/Legacy/Field/FieldInformation.h>
3635

3736
#include <iomanip>
3837
#include <fstream>
3938
#include <sstream>
40-
#include <string>
41-
#include <vector>
4239

4340
#include <boost/filesystem.hpp>
4441
#include <boost/algorithm/string.hpp>
4542
#include <boost/shared_array.hpp>
4643

47-
#include <sci_debug.h>
44+
#include <Core/Utils/Legacy/StringUtil.h>
4845

49-
namespace SCIRunAlgo {
46+
using namespace SCIRun;
47+
using namespace SCIRun::Core::Algorithms;
48+
using namespace SCIRun::Core::Logging;
49+
using namespace SCIRun::Core::Geometry;
5050

51-
namespace ASCII {
51+
namespace SCIRun {
52+
namespace Core {
53+
namespace Algorithms {
5254

53-
class ConverterPrivate
55+
class AsciiConverterPrivate
5456
{
5557
public:
5658
// // point(vertex) lookup table
5759
// typedef boost::unordered_map< Point, unsigned int, PointHash > PointTable;
5860
// typedef std::list<Facet> FacetList;
5961

60-
ConverterPrivate(ProgressReporter* pr)
62+
explicit AsciiConverterPrivate(LoggerHandle pr)
6163
: pr_(pr),
6264
CELL_SIZE(3)
6365
{}
6466

6567
bool readFile(const std::string& filename, FieldHandle& field);
6668
bool writeFile(const std::string& filename, VMesh *vmesh);
67-
void formatLine(std::string& line)
69+
void formatLine(std::string& line) const
6870
{
6971
// replace comma's and tabs with white spaces
7072
for (size_t p = 0; p < line.size(); ++p)
@@ -74,20 +76,21 @@ class ConverterPrivate
7476
}
7577

7678
// assumes always length 3
77-
inline Point vectorToPoint(const std::vector<float>& v)
79+
inline Point vectorToPoint(const std::vector<float>& v) const
7880
{
7981
return Point( v[0], v[1], v[2] );
8082
}
8183

8284
private:
83-
ProgressReporter* pr_;
85+
LoggerHandle pr_;
8486
const unsigned short CELL_SIZE;
8587

8688
PointTable pointsLookupTable;
8789
};
90+
}}}
8891

8992
bool
90-
ConverterPrivate::readFile(const std::string& filename, FieldHandle& field)
93+
AsciiConverterPrivate::readFile(const std::string& filename, FieldHandle& field)
9194
{
9295
std::ifstream inputfile;
9396
inputfile.exceptions( std::ifstream::failbit | std::ifstream::badbit );
@@ -108,7 +111,7 @@ ConverterPrivate::readFile(const std::string& filename, FieldHandle& field)
108111
std::string line;
109112
unsigned int pointIndex = 0, vertexCounter = 0, lineCounter = 0;
110113

111-
boost::shared_array< std::vector<float> > vertexArray(new std::vector<float>[CELL_SIZE]);
114+
std::vector< std::vector<float> > vertexArray(CELL_SIZE);
112115
FacetList facetList;
113116

114117
// loop until header
@@ -240,7 +243,7 @@ ConverterPrivate::readFile(const std::string& filename, FieldHandle& field)
240243
}
241244

242245
bool
243-
ConverterPrivate::writeFile(const std::string& filename, VMesh *vmesh)
246+
AsciiConverterPrivate::writeFile(const std::string& filename, VMesh *vmesh)
244247
{
245248
std::ofstream outputfile;
246249
outputfile.exceptions( std::ofstream::failbit | std::ofstream::badbit );
@@ -297,7 +300,7 @@ ConverterPrivate::writeFile(const std::string& filename, VMesh *vmesh)
297300

298301
outputfile.close();
299302
}
300-
catch (std::ifstream::failure e)
303+
catch (std::ifstream::failure& e)
301304
{
302305
if (this->pr_) this->pr_->error("Could not open and write to file " + filename);
303306
return false;
@@ -311,13 +314,8 @@ ConverterPrivate::writeFile(const std::string& filename, VMesh *vmesh)
311314
return true;
312315
}
313316

314-
}
315-
316-
TriSurfSTLASCIIConverter::TriSurfSTLASCIIConverter(ProgressReporter* pr) :
317-
pr_(pr), converter_(new ASCII::ConverterPrivate(pr))
318-
{}
319-
320-
TriSurfSTLASCIIConverter::~TriSurfSTLASCIIConverter()
317+
TriSurfSTLASCIIConverter::TriSurfSTLASCIIConverter(LoggerHandle pr) :
318+
pr_(pr), converter_(new AsciiConverterPrivate(pr))
321319
{}
322320

323321
bool
@@ -327,8 +325,7 @@ TriSurfSTLASCIIConverter::read(const std::string& filename, FieldHandle& field)
327325
FieldInformation fieldInfo("TriSurfMesh", -1, "double");
328326
field = CreateField(fieldInfo);
329327

330-
bool result = converter_->readFile(filename, field);
331-
return result;
328+
return converter_->readFile(filename, field);
332329
}
333330

334331
bool
@@ -339,12 +336,10 @@ TriSurfSTLASCIIConverter::write(const std::string& filename, const FieldHandle&
339336
// validate
340337
if (! vmesh->is_trisurfmesh() )
341338
{
342-
if (this->pr_) this->pr_->error("STL ASCII converter only supports TriSurf mesh fields.");
339+
if (pr_)
340+
pr_->error("STL ASCII converter only supports TriSurf mesh fields.");
343341
return false;
344342
}
345343

346-
bool result = converter_->writeFile(filename, vmesh);
347-
return result;
348-
}
349-
344+
return converter_->writeFile(filename, vmesh);
350345
}
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/*
22
For more information, please see: http://software.sci.utah.edu
3-
3+
44
The MIT License
5-
5+
66
Copyright (c) 2014 Scientific Computing and Imaging Institute,
77
University of Utah.
8-
9-
8+
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
to deal in the Software without restriction, including without limitation
1313
the rights to use, copy, modify, merge, publish, distribute, sublicense,
1414
and/or sell copies of the Software, and to permit persons to whom the
1515
Software is furnished to do so, subject to the following conditions:
16-
16+
1717
The above copyright notice and this permission notice shall be included
1818
in all copies or substantial portions of the Software.
19-
19+
2020
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2121
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2222
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
@@ -30,46 +30,37 @@
3030
#ifndef CORE_ALGORITHMS_DATAIO_TRISURFSTLASCIICONVERTER_H
3131
#define CORE_ALGORITHMS_DATAIO_TRISURFSTLASCIICONVERTER_H 1
3232

33-
#include <string>
34-
35-
#include <boost/shared_ptr.hpp>
36-
37-
#include <Core/Algorithms/Util/AlgoLibrary.h>
38-
#include <Core/Datatypes/Field.h>
39-
40-
#include <Core/Algorithms/DataIO/share.h>
33+
#include <Core/Datatypes/Legacy/Field/FieldFwd.h>
34+
#include <Core/Algorithms/Base/AlgorithmBase.h>
35+
#include <Core/Algorithms/Legacy/DataIO/share.h>
4136

4237
///
4338
/// Convert SCIRun TriSurfMesh to STL format
4439
///
4540
/// ASCII STL format (http://en.wikipedia.org/wiki/STL_(file_format))
4641
///
47-
namespace SCIRunAlgo {
48-
49-
using namespace SCIRun;
50-
51-
namespace ASCII {
52-
53-
class ConverterPrivate;
54-
typedef boost::shared_ptr< ConverterPrivate > ConverterPrivateHandle;
42+
namespace SCIRun {
43+
namespace Core {
44+
namespace Algorithms {
5545

56-
}
46+
class AsciiConverterPrivate;
47+
typedef boost::shared_ptr< AsciiConverterPrivate > AsciiConverterPrivateHandle;
5748

58-
class SCISHARE TriSurfSTLASCIIConverter : public AlgoLibrary
49+
class SCISHARE TriSurfSTLASCIIConverter : public AlgorithmBase
5950
{
6051
public:
61-
TriSurfSTLASCIIConverter(ProgressReporter* pr = 0);
62-
~TriSurfSTLASCIIConverter();
63-
52+
explicit TriSurfSTLASCIIConverter(Core::Logging::LoggerHandle pr);
53+
virtual AlgorithmOutput run(const AlgorithmInput&) const override { throw "not implemented"; }
54+
6455
bool read(const std::string& filename, FieldHandle& field);
6556
bool write(const std::string& filename, const FieldHandle& field);
66-
57+
6758
private:
68-
ProgressReporter* pr_;
69-
70-
ASCII::ConverterPrivateHandle converter_;
59+
Core::Logging::LoggerHandle pr_;
60+
61+
AsciiConverterPrivateHandle converter_;
7162
};
7263

73-
}
64+
}}}
7465

7566
#endif

src/Core/Algorithms/Legacy/DataIO/TriSurfSTLBinaryConverter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class SCISHARE TriSurfSTLBinaryConverter : public AlgorithmBase
5050
{
5151
public:
5252
explicit TriSurfSTLBinaryConverter(Core::Logging::LoggerHandle pr);
53+
virtual AlgorithmOutput run(const AlgorithmInput&) const override { throw "not implemented"; }
5354

5455
bool read(const std::string& filename, FieldHandle& field);
5556
bool write(const std::string& filename, const FieldHandle& field);

src/Core/IEPlugin/TriSurfField_Plugin.cc

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,47 +1098,50 @@ bool SCIRun::TriSurfFieldToExotxtBaseIndexOne_writer(LoggerHandle pr, FieldHandl
10981098
return (true);
10991099
}
11001100

1101-
FieldHandle SCIRun::TriSurfFieldSTLASCII_reader(ProgressReporter *pr, const char *filename)
1101+
FieldHandle SCIRun::TriSurfFieldSTLASCII_reader(LoggerHandle pr, const char *filename)
11021102
{
1103-
FieldHandle outputField = 0;
1104-
SCIRunAlgo::TriSurfSTLASCIIConverter reader(pr);
1103+
FieldHandle outputField;
1104+
TriSurfSTLASCIIConverter reader(pr);
11051105

1106-
if (! reader.read(filename, outputField) )
1106+
if (!reader.read(filename, outputField))
11071107
{
1108-
if (pr) pr->error("Convert ASCII STL file to SCIRun TriSurf field failed.");
1109-
return FieldHandle(0);
1108+
if (pr)
1109+
pr->error("Convert ASCII STL file to SCIRun TriSurf field failed.");
1110+
return nullptr;
11101111
}
11111112
return outputField;
11121113
}
11131114

1114-
FieldHandle SCIRun::TriSurfFieldSTLBinary_reader(ProgressReporter *pr, const char *filename)
1115+
FieldHandle SCIRun::TriSurfFieldSTLBinary_reader(LoggerHandle pr, const char *filename)
11151116
{
1116-
FieldHandle outputField = 0;
1117-
SCIRunAlgo::TriSurfSTLBinaryConverter reader(pr);
1117+
FieldHandle outputField;
1118+
TriSurfSTLBinaryConverter reader(pr);
11181119

1119-
if (! reader.read(filename, outputField) )
1120+
if (!reader.read(filename, outputField))
11201121
{
1121-
if (pr) pr->error("Convert Binary STL file to SCIRun TriSurf field failed.");
1122-
return FieldHandle(0);
1122+
if (pr)
1123+
pr->error("Convert Binary STL file to SCIRun TriSurf field failed.");
1124+
return nullptr;
11231125
}
11241126
return outputField;
11251127
}
11261128

1127-
bool SCIRun::TriSurfFieldSTLASCII_writer(ProgressReporter *pr, FieldHandle fh, const char *filename)
1129+
bool SCIRun::TriSurfFieldSTLASCII_writer(LoggerHandle pr, FieldHandle fh, const char *filename)
11281130
{
1129-
SCIRunAlgo::TriSurfSTLASCIIConverter writer(pr);
1130-
if (! writer.write(filename, fh) )
1131+
TriSurfSTLASCIIConverter writer(pr);
1132+
if (!writer.write(filename, fh))
11311133
{
1132-
if (pr) pr->error("Convert SCIRun TriSurf field to ASCII STL file failed.");
1134+
if (pr)
1135+
pr->error("Convert SCIRun TriSurf field to ASCII STL file failed.");
11331136
return false;
11341137
}
11351138
return true;
11361139
}
11371140

1138-
bool SCIRun::TriSurfFieldSTLBinary_writer(ProgressReporter *pr, FieldHandle fh, const char *filename)
1141+
bool SCIRun::TriSurfFieldSTLBinary_writer(LoggerHandle pr, FieldHandle fh, const char *filename)
11391142
{
1140-
SCIRunAlgo::TriSurfSTLBinaryConverter writer(pr);
1141-
if (! writer.write(filename, fh) )
1143+
TriSurfSTLBinaryConverter writer(pr);
1144+
if (!writer.write(filename, fh))
11421145
{
11431146
if (pr) pr->error("Convert SCIRun TriSurf field to Binary STL file failed.");
11441147
return false;

0 commit comments

Comments
 (0)