Skip to content

Commit 656141f

Browse files
committed
first pass
1 parent e5c6b0d commit 656141f

File tree

5 files changed

+93
-74
lines changed

5 files changed

+93
-74
lines changed

source/pdal/pdalc_config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* POSSIBILITY OF SUCH DAMAGE.
2828
*****************************************************************************/
2929

30+
#define _CRT_SECURE_NO_WARNINGS
3031
#include "pdalc_config.h"
3132

3233
#include <cstdlib>
@@ -36,6 +37,8 @@
3637
#include <pdal/pdal_config.hpp>
3738
#include <pdal/util/Utils.hpp>
3839

40+
41+
3942
namespace pdal
4043
{
4144
namespace capi

source/pdal/pdalc_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "pdalc_forward.h"
3434

35+
3536
/**
3637
* @file pdalc_config.h
3738
* Functions to retrieve PDAL version and configuration information.

source/pdal/pdalc_forward.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
namespace pdal
5454
{
5555
struct DimType;
56-
class PipelineExecutor;
56+
class PipelineManager;
5757
class PointView;
5858
class TriangularMesh;
5959

@@ -64,10 +64,19 @@ using MeshPtr = std::shared_ptr<TriangularMesh>;
6464
namespace capi
6565
{
6666
class PointViewIterator;
67-
using Pipeline = std::unique_ptr<pdal::PipelineExecutor>;
6867
using PointView = pdal::PointViewPtr;
6968
using TriangularMesh = pdal::MeshPtr;
7069
using DimTypeList = std::unique_ptr<pdal::DimTypeList>;
70+
71+
struct Pipeline {
72+
public:
73+
74+
std::unique_ptr<pdal::PipelineManager> manager = std::make_unique<pdal::PipelineManager>();
75+
76+
bool m_executed = false;
77+
std::stringstream logStream;
78+
pdal::LogLevel logLevel;
79+
};
7180
}
7281
}
7382

source/pdal/pdalc_pipeline.cpp

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/******************************************************************************
2-
* Copyright (c) 2019, Simverge Software LLC. All rights reserved.
2+
* Copyright (c) 2019, Simverge Software LLC & Runette Software Ltd. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following
@@ -26,15 +26,17 @@
2626
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2727
* POSSIBILITY OF SUCH DAMAGE.
2828
*****************************************************************************/
29-
29+
#define _CRT_SECURE_NO_WARNINGS
3030
#include "pdalc_pipeline.h"
3131

3232
#include <string>
3333

34-
#include <pdal/PipelineExecutor.hpp>
35-
3634
#include "pdalc_pointviewiterator.h"
3735

36+
#include <pdal/util/Utils.hpp>
37+
#include <pdal/PipelineWriter.hpp>
38+
#include <pdal/Stage.hpp>
39+
3840
// TODO Address cause of std::min problems. See https://github.com/PDAL/CAPI/issues/4
3941
#undef min
4042

@@ -46,46 +48,35 @@ extern "C"
4648
{
4749
PDALPipelinePtr PDALCreatePipeline(const char* json)
4850
{
49-
PDALPipelinePtr pipeline = nullptr;
50-
51+
PDALPipelinePtr pipeline = new Pipeline();
52+
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
53+
PipelineManager *manager = ptr->manager.get();
5154
if (json && std::strlen(json) > 0)
5255
{
53-
pdal::PipelineExecutor *executor = nullptr;
54-
5556
try
5657
{
57-
pdal::PipelineExecutor stackpipe(json);
58-
executor = new pdal::PipelineExecutor(json);
58+
LogPtr log(Log::makeLog("capi pipeline", &ptr->logStream));
59+
manager->setLog(log);
60+
61+
std::stringstream strm;
62+
strm << json;
63+
manager->readPipeline(strm);
5964
}
6065
catch (const std::exception &e)
6166
{
6267
printf("Could not create pipeline: %s\n%s\n", e.what(), json);
63-
executor = nullptr;
6468
}
6569

66-
if (executor)
70+
if (manager)
6771
{
68-
bool valid = false;
69-
7072
try
7173
{
72-
valid = executor->validate();
74+
manager->prepare();
7375
}
7476
catch (const std::exception &e)
7577
{
7678
printf("Error while validating pipeline: %s\n%s\n", e.what(), json);
7779
}
78-
79-
if (valid)
80-
{
81-
pipeline = new Pipeline(executor);
82-
}
83-
else
84-
{
85-
delete executor;
86-
executor = NULL;
87-
printf("The pipeline is invalid:\n%s\n", json);
88-
}
8980
}
9081
}
9182

@@ -97,6 +88,7 @@ extern "C"
9788
if (pipeline)
9889
{
9990
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
91+
ptr->manager.reset();
10092
delete ptr;
10193
}
10294
}
@@ -108,17 +100,18 @@ extern "C"
108100
if (pipeline && buffer && size > 0)
109101
{
110102
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
111-
pdal::PipelineExecutor *executor = ptr->get();
103+
PipelineManager *manager = ptr->manager.get();
112104
buffer[0] = '\0';
113105
buffer[size - 1] = '\0';
114106

115-
if (executor)
107+
if (manager)
116108
{
117109
try
118110
{
119-
std::string s = executor->getPipeline();
120-
std::strncpy(buffer, s.c_str(), size - 1);
121-
result = std::min(s.length(), size);
111+
std::stringstream strm;
112+
pdal::PipelineWriter::writePipeline(manager->getStage(), strm);
113+
std::strncpy(buffer, strm.str().c_str(), size - 1);
114+
result = std::min(strm.str().length(), size);
122115
}
123116
catch (const std::exception &e)
124117
{
@@ -138,17 +131,19 @@ extern "C"
138131
if (pipeline && metadata && size > 0)
139132
{
140133
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
141-
pdal::PipelineExecutor *executor = ptr->get();
134+
PipelineManager *manager = ptr->manager.get();
142135
metadata[0] = '\0';
143136
metadata[size - 1] = '\0';
144137

145-
if (executor)
138+
if (manager)
146139
{
147140
try
148141
{
149-
std::string s = executor->getMetadata();
150-
std::strncpy(metadata, s.c_str(), size);
151-
result = std::min(s.length(), size);
142+
std::stringstream strm;
143+
MetadataNode root = manager->getMetadata().clone("metadata");
144+
pdal::Utils::toJSON(root, strm);
145+
std::strncpy(metadata, strm.str().c_str(), size);
146+
result = std::min(strm.str().length(), size);
152147
}
153148
catch (const std::exception &e)
154149
{
@@ -167,17 +162,19 @@ extern "C"
167162
if (pipeline && schema && size > 0)
168163
{
169164
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
170-
pdal::PipelineExecutor *executor = ptr->get();
165+
PipelineManager *manager = ptr->manager.get();
171166
schema[0] = '\0';
172167
schema[size - 1] = '\0';
173168

174-
if (executor)
169+
if (manager)
175170
{
176171
try
177172
{
178-
std::string s = executor->getSchema();
179-
std::strncpy(schema, s.c_str(), size);
180-
result = std::min(s.length(), size);
173+
std::stringstream strm;
174+
MetadataNode root = manager->pointTable().layout()->toMetadata().clone("schema");
175+
pdal::Utils::toJSON(root, strm);
176+
std::strncpy(schema, strm.str().c_str(), size);
177+
result = std::min(strm.str().length(), size);
181178
}
182179
catch (const std::exception &e)
183180
{
@@ -196,15 +193,15 @@ extern "C"
196193
if (pipeline && log && size > 0)
197194
{
198195
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
199-
pdal::PipelineExecutor *executor = ptr->get();
196+
PipelineManager *manager = ptr->manager.get();
200197
log[0] = '\0';
201198
log[size - 1] = '\0';
202199

203-
if (executor)
200+
if (manager)
204201
{
205202
try
206203
{
207-
std::string s = executor->getLog();
204+
std::string s = ptr->logStream.str();
208205
std::strncpy(log, s.c_str(), size);
209206
result = std::min(s.length(), size);
210207
}
@@ -221,36 +218,43 @@ extern "C"
221218
void PDALSetPipelineLogLevel(PDALPipelinePtr pipeline, int level)
222219
{
223220
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
221+
PipelineManager *manager = ptr->manager.get();
224222

225-
if (ptr && ptr->get())
223+
try
224+
{
225+
if (level < 0 || level > 8)
226+
throw pdal_error("log level must be between 0 and 8!");
227+
228+
ptr->logLevel = static_cast<pdal::LogLevel>(level);
229+
pdal::LogPtr lptr = manager->log();
230+
lptr->setLevel(ptr->logLevel);
231+
}
232+
catch (const std::exception &e)
226233
{
227-
try
228-
{
229-
ptr->get()->setLogLevel(level);
230-
}
231-
catch (const std::exception &e)
232-
{
233-
printf("Found error while setting log level: %s\n", e.what());
234-
}
234+
printf("Found error while setting log level: %s\n", e.what());
235235
}
236+
236237
}
237238

238239
int PDALGetPipelineLogLevel(PDALPipelinePtr pipeline)
239240
{
240241
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
241-
return (ptr && ptr->get()) ? ptr->get()->getLogLevel() : 0;
242+
return (ptr && ptr->manager.get())
243+
? static_cast<int>(
244+
ptr->manager.get()->log()->getLevel()
245+
) : 0;
242246
}
243247

244248
int64_t PDALExecutePipeline(PDALPipelinePtr pipeline)
245249
{
246250
int64_t result = 0;
247251
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
248252

249-
if (ptr && ptr->get())
253+
if (ptr)
250254
{
251255
try
252256
{
253-
result = ptr->get()->execute();
257+
result = ptr->manager.get()->execute();
254258
}
255259
catch (const std::exception &e)
256260
{
@@ -266,11 +270,11 @@ extern "C"
266270
int64_t result = 0;
267271
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
268272

269-
if (ptr && ptr->get())
273+
if (ptr)
270274
{
271275
try
272276
{
273-
result = ptr->get()->validate();
277+
ptr->manager.get()->prepare();
274278
}
275279
catch (const std::exception &e)
276280
{
@@ -284,18 +288,14 @@ extern "C"
284288
PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline)
285289
{
286290
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
291+
PipelineManager *manager = ptr->manager.get();
287292
pdal::capi::PointViewIterator *views = nullptr;
288293

289-
if (ptr && ptr->get())
294+
if (ptr)
290295
{
291296
try
292297
{
293-
auto &v = ptr->get()->getManagerConst().views();
294-
295-
if (!v.empty())
296-
{
297-
views = new pdal::capi::PointViewIterator(v);
298-
}
298+
views = new pdal::capi::PointViewIterator(manager->views());
299299
}
300300
catch (const std::exception &e)
301301
{
@@ -305,6 +305,9 @@ extern "C"
305305

306306
return views;
307307
}
308-
}
309-
}
310-
}
308+
} /* extern c */
309+
310+
311+
312+
} /* capi */
313+
} /* pdal */

source/pdal/pdalc_pipeline.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/******************************************************************************
2-
* Copyright (c) 2019, Simverge Software LLC. All rights reserved.
2+
* Copyright (c) 2019, Simverge Software LLC & Runette Software. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following
@@ -156,8 +156,11 @@ PDALC_API PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline);
156156

157157
#ifdef __cplusplus
158158

159-
}
160-
}
161-
}
159+
} /* extern C */
160+
161+
162+
163+
} /* capi*/
164+
} /* pdal*/
162165
#endif /* _cplusplus */
163166
#endif /* PDALC_PIPELINE_H */

0 commit comments

Comments
 (0)