-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.cpp
More file actions
427 lines (355 loc) · 11.3 KB
/
wrapper.cpp
File metadata and controls
427 lines (355 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#include <tuple>
#include <map>
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
#include "PolyVoxCore/CubicSurfaceExtractor.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/SimpleVolume.h"
#include "PolyVoxCore/AmbientOcclusionCalculator.h"
#include "PolyVoxCore/AStarPathfinder.h"
#include "PolyVoxCore/Raycast.h"
extern "C"
{
#include "wrapper.h"
}
using namespace PolyVox;
std::map< PVoxVolume,VOLUMETYPE* > _Volume;
uint32_t _VolumeSeq;
std::map< PVoxRegion,Region* > _Region;
uint32_t _RegionSeq;
std::map< PVoxAStarPathfinder,std::tuple< AStarPathfinder< VOLUMETYPE >*,std::list< Vector3DInt32 >*,PVoxVectorNDUint32* > > _ASPathfinder;
uint32_t _ASPathfinderSeq;
std::map< PVoxSurfaceExtractor,EXTRACTORTYPE* > _SurfaceExtractor;
uint32_t _SurfaceExtractorSeq;
std::map< PVoxSurfaceMesh,SurfaceMesh< VERTEXTYPE >* > _SurfaceMesh;
uint32_t _SurfaceMeshSeq;
bool _funcIsTransparent(VOXELTYPE voxel)
{
return voxel != 0;
}
extern "C"
{
bool (*funcIsTransparent)(VOXELTYPE voxel) = _funcIsTransparent;
void pvoxAOCalculate
(
PVoxVolume volume,
uint8_t (*result)[3],
PVoxRegion region,
float fRayLength,
uint8_t uNoOfSamplesPerOutputElement,
bool (*__funcIsTransparent)(const VOXELTYPE voxel)
)
{
Array3DUint8 *arr = new Array3DUint8();
calculateAmbientOcclusion(
_Volume[volume], arr, *_Region[region], fRayLength,
uNoOfSamplesPerOutputElement,
[&] (const VOXELTYPE voxel) -> bool
{
return funcIsTransparent( voxel );
}
);
}
//PVoxAStarPathfinder pvoxASPathfinderAdd(
// PVoxVolume volData,
// PVoxVector3DUint32* v3dStart,
// PVoxVector3DUint32* v3dEnd,
// PVoxVectorNDUint32* listResult,
// float fHBias/*=1.0*/,
// uint32_t uMaxNoOfNodes/*=10000*/,
// //Connectivity connectivity=TwentySixConnected,
// bool funcIsVoxelValidForPath(const PVoxVolume, const PVoxVector3DInt32*)/*=NULL*/,
// void funcProgressCallback(float)/*=NULL*/
//)
//{
// std::list< Vector3DInt32 >* list = new std::list< Vector3DInt32 >();
// polyvox_function<bool (const VOLUMETYPE*, const Vector3DInt32&)> _isVoxelValidForPath =
// [&](const VOLUMETYPE* volume, const Vector3DInt32& vec_cpp) -> bool
// { //TODO: birectional map or something
// PVoxVector3DInt32 vec_c;
// vec_c.x = vec_cpp.getX();
// vec_c.y = vec_cpp.getY();
// vec_c.z = vec_cpp.getZ();
//
// for (std::map< PVoxVolume,VOLUMETYPE* >::iterator it = _Volume.begin(); it != _Volume.end(); it++)
// {
// if ( it->second == volume )
// return funcIsVoxelValidForPath(it->first, &vec_c);
// }
// assert(0);
// };
// _ASPathfinder[++_ASPathfinderSeq] = std::make_tuple< AStarPathfinder< VOLUMETYPE >*,std::list< Vector3DInt32 >*,PVoxVectorNDUint32* >(
// new AStarPathfinder< VOLUMETYPE >(
// AStarPathfinderParams< VOLUMETYPE >(
// _Volume[volData],
// Vector3DInt32(v3dStart->x, v3dStart->y, v3dStart->z),
// Vector3DInt32(v3dEnd->x, v3dEnd->y, v3dEnd->z),
// list, fHBias, uMaxNoOfNodes, TwentySixConnected,
// funcIsVoxelValidForPath == NULL ? NULL : _isVoxelValidForPath,
// funcProgressCallback
// )
// ),
// list,
// listResult
// );
// return _ASPathfinderSeq;
//}
//void pvoxASPathfinderRemove(PVoxAStarPathfinder handle)
//{
// std::tuple< AStarPathfinder< VOLUMETYPE >*,std::list< Vector3DInt32 >*,PVoxVectorNDUint32* > tuple = _ASPathfinder[handle];
// delete std::get<0>(tuple);
// delete std::get<1>(tuple);
// delete[] std::get<2>(tuple)->nodes;
//}
//void pvoxASPathfinderExecute(PVoxAStarPathfinder handle)
//{
// std::tuple< AStarPathfinder< VOLUMETYPE >*,std::list< Vector3DInt32 >*,PVoxVectorNDUint32* > tuple = _ASPathfinder[handle];
// std::get<0>(tuple)->execute();
// std::list< Vector3DInt32 > *list = std::get<1>(tuple);
// PVoxVectorNDUint32* path = std::get<2>(tuple);
// path->count = list->size();
// path->nodes = new PVoxVector3DUint32[path->count];
// int i = 0;
// for (std::list< Vector3DInt32 >::iterator it = list->begin(); it != list->end(); it++, i++)
// {
// PVoxVector3DUint32* node = path->nodes+i;
// node->x = it->getX();
// node->y = it->getY();
// node->z = it->getZ();
// }
//}
//
PVoxVolume pvoxVolumeAdd(PVoxRegion region)
{
_Volume[++_VolumeSeq] = new VOLUMETYPE(*_Region[region]);
return _VolumeSeq;
}
VOXELTYPE pvoxVolumeGetBorderValue(PVoxVolume volume)
{
return _Volume[volume]->getBorderValue();
}
int32_t pvoxVolumeGetWidth(PVoxVolume volume)
{
return _Volume[volume]->getWidth();
}
int32_t pvoxVolumeGetHeight(PVoxVolume volume)
{
return _Volume[volume]->getHeight();
}
int32_t pvoxVolumeGetLongestSideLength(PVoxVolume volume)
{
return _Volume[volume]->getLongestSideLength();
}
int32_t pvoxVolumeGetShortestSideLength(PVoxVolume volume)
{
return _Volume[volume]->getShortestSideLength();
}
float pvoxVolumeGetDiagonalLength(PVoxVolume volume)
{
return _Volume[volume]->getDiagonalLength();
}
VOXELTYPE pvoxVolumeGetVoxelAt(PVoxVolume volume, PVoxVector3DUint32 vec)
{
return _Volume[volume]->getVoxelAt(Vector3DInt32(vec.x, vec.y, vec.z));
}
void pvoxVolumeSetBorderValue(PVoxVolume volume, VOXELTYPE tBorder)
{
_Volume[volume]->setBorderValue(tBorder);
}
bool pvoxVolumeSetVoxelAt(PVoxVolume volume, PVoxVector3DUint32 vec, VOXELTYPE tValue)
{
return _Volume[volume]->setVoxelAt(Vector3DInt32(vec.x, vec.y, vec.z), tValue);
}
uint32_t pvoxVolumeCalculateSizeInBytes(PVoxVolume volume)
{
return _Volume[volume]->calculateSizeInBytes();
}
void pvoxVolumeRemove(PVoxVolume volume)
{
delete _Volume[volume];
}
//#if VOLUMETYPE == VOLUMETYPE_LARGE
// //
//#endif
//
PVoxSurfaceExtractor pvoxSurfaceExtractorAdd
(
PVoxVolume volData,
PVoxRegion region,
PVoxSurfaceMesh result,
bool bMergeQuads
//isQuadNeeded
)
{
#if EXTRACT_NORMALS
_SurfaceExtractor[++_SurfaceExtractorSeq] = new EXTRACTORTYPE(_Volume[volData], *_Region[region], _SurfaceMesh[result]);
#else
_SurfaceExtractor[++_SurfaceExtractorSeq] = new EXTRACTORTYPE(_Volume[volData], *_Region[region], _SurfaceMesh[result], bMergeQuads);
#endif
return _SurfaceExtractorSeq;
}
void pvoxSurfaceExtractorExecute(PVoxSurfaceExtractor handle)
{
_SurfaceExtractor[handle]->execute();
}
void pvoxSurfaceExtractorRemove(PVoxSurfaceExtractor handle)
{
delete _SurfaceExtractor[handle];
}
//
PVoxSurfaceMesh pvoxSurfaceMeshAdd()
{
_SurfaceMesh[++_SurfaceMeshSeq] = new SurfaceMesh< VERTEXTYPE >();
return _SurfaceMeshSeq;
}
void pvoxSurfaceMeshRemove(PVoxSurfaceMesh handle)
{
delete _SurfaceMesh[handle];
}
uint32_t pvoxSurfaceMeshGetNoOfIndices(PVoxSurfaceMesh handle)
{
return _SurfaceMesh[handle]->getNoOfIndices();
}
void pvoxSurfaceMeshGetIndices(PVoxSurfaceMesh handle, uint32_t result[])
{
std::vector< uint32_t > indices = _SurfaceMesh[handle]->getIndices();
size_t i = 0;
for( std::vector< uint32_t >::const_iterator it = indices.begin(); it != indices.end(); it++)
{
result[i++] = *it;
}
}
uint32_t pvoxSurfaceMeshGetNoOfVertices(PVoxSurfaceMesh handle)
{
return _SurfaceMesh[handle]->getNoOfVertices();
}
void pvoxSurfaceMeshGetVertices(PVoxSurfaceMesh handle, PVoxVertex result[])
{
std::vector< VERTEXTYPE > vertices = _SurfaceMesh[handle]->getVertices();
size_t i = 0;
for( std::vector< VERTEXTYPE >::const_iterator it = vertices.begin(); it != vertices.end(); it++, i++)
{
result[i].material = it->getMaterial();
Vector3DFloat pos = it->getPosition();
result[i].position.x = pos.getX();
result[i].position.y = pos.getY();
result[i].position.z = pos.getZ();
#if EXTRACT_NORMALS
Vector3DFloat normal = it->getNormal();
result[i].normal.x = normal.getX();
result[i].normal.y = normal.getY();
result[i].normal.z = normal.getZ();
#endif
}
}
uint32_t pvoxSurfaceMeshGetNoOfNonUniformTrianges(PVoxSurfaceMesh handle)
{
return _SurfaceMesh[handle]->getNoOfNonUniformTrianges();
}
uint32_t pvoxSurfaceMeshGetNoOfUniformTrianges(PVoxSurfaceMesh handle)
{
return _SurfaceMesh[handle]->getNoOfUniformTrianges();
}
PVoxVertex* pvoxSurfaceMeshGetRawVertexData(PVoxSurfaceMesh handle)
{
VERTEXTYPE* ret = _SurfaceMesh[handle]->getRawVertexData().data();
return (PVoxVertex*) ret;
}
//
bool pvoxRaycastWithDirection(PVoxVolume volume, PVoxVector3DFloat* start, PVoxVector3DFloat* direction, PVoxRaycastResult* result)
{
return RaycastResults::Interupted == raycastWithDirection(
_Volume[volume],
Vector3DFloat(start->x,start->y,start->z),
Vector3DFloat(direction->x,direction->y,direction->z),
[&] (VOLUMETYPE::Sampler sampler) -> bool
{
return funcIsTransparent(sampler.getVoxel());
}
);
}
//TODO: raycast with callback
PVoxRegion pvoxRegionAdd()
{
_Region[++_RegionSeq] = new Region;
return _RegionSeq;
}
PVoxVector3DInt32 pvoxRegionGetLowerCorner(PVoxRegion handle)
{
Vector3DInt32 corner = _Region[handle]->getLowerCorner();
PVoxVector3DInt32 ret;
ret.x = corner.getX();
ret.y = corner.getY();
ret.z = corner.getZ();
return ret;
}
PVoxVector3DInt32 pvoxRegionGetUpperCorner(PVoxRegion handle)
{
Vector3DInt32 corner = _Region[handle]->getUpperCorner();
PVoxVector3DInt32 ret;
ret.x = corner.getX();
ret.y = corner.getY();
ret.z = corner.getZ();
return ret;
}
void pvoxRegionSetUpperCorner(PVoxRegion handle, PVoxVector3DUint32* upperCorner)
{
_Region[handle]->setUpperCorner(Vector3DInt32(upperCorner->x,upperCorner->y,upperCorner->z));
}
void pvoxRegionSetLowerCorner(PVoxRegion handle, PVoxVector3DUint32* lowerCorner)
{
_Region[handle]->setLowerCorner(Vector3DInt32(lowerCorner->x,lowerCorner->y,lowerCorner->z));
}
bool pvoxRegionContainsPointF(PVoxRegion handle, PVoxVector3DFloat* pos, float boundary)
{
return _Region[handle]->containsPoint(Vector3DFloat(pos->x, pos->y, pos->z), boundary);
}
bool pvoxRegionContainsPointI(PVoxRegion handle, PVoxVector3DInt32* pos, uint8_t boundary)
{
return _Region[handle]->containsPoint(Vector3DInt32(pos->x, pos->y, pos->z), boundary);
}
bool pvoxRegionContainsPointInXF(PVoxRegion handle, float x, float boundary)
{
return _Region[handle]->containsPointInX(x, boundary);
}
bool pvoxRegionContainsPointInXI(PVoxRegion handle, uint32_t x, uint8_t boundary)
{
return _Region[handle]->containsPointInX(x, boundary);
}
bool pvoxRegionContainsPointInYF(PVoxRegion handle, float y, float boundary)
{
return _Region[handle]->containsPointInY(y, boundary);
}
bool pvoxRegionContainsPointInYI(PVoxRegion handle, uint32_t y, uint8_t boundary)
{
return _Region[handle]->containsPointInY(y, boundary);
}
bool pvoxRegionContainsPointInZF(PVoxRegion handle, float z, float boundary)
{
return _Region[handle]->containsPointInZ(z, boundary);
}
bool pvoxRegionContainsPointInZI(PVoxRegion handle, uint32_t z, uint8_t boundary)
{
return _Region[handle]->containsPointInZ(z, boundary);
}
void pvoxRegionCropTo(PVoxRegion handle, PVoxRegion other)
{
_Region[handle]->cropTo(*_Region[other]);
}
void pvoxRegionShift(PVoxRegion handle, PVoxVector3DInt32* vec)
{
_Region[handle]->shift(Vector3DInt32(vec->x, vec->y, vec->z));
}
void pvoxRegionShiftLowerCorner(PVoxRegion handle, PVoxVector3DInt32* vec)
{
_Region[handle]->shiftLowerCorner(Vector3DInt32(vec->x, vec->y, vec->z));
}
void pvoxRegionShiftUpperCorner(PVoxRegion handle, PVoxVector3DInt32* vec)
{
_Region[handle]->shiftUpperCorner(Vector3DInt32(vec->x, vec->y, vec->z));
}
void pvoxRegionRemove(PVoxRegion handle)
{
delete _Region[handle];
}
//
}