31 namespace PCLMLTools {
54 template <
typename PCL_POINT_TYPE>
70 thresholdMin(0.), thresholdMax(0.),
71 lowerValue(0.), upperValue(0.),
72 skipVoxelsBelowMin(false),
73 skipVoxelsAboveMax(false),
74 normalizeInClampedRange(false),
75 useVectorLengthAsIntensity(false),
76 transformToWorld(false){};
122 template <
typename POINT_CLOUD_TYPE>
124 const Matrix4 &voxelToWorldMatrix,
127 typedef typename POINT_CLOUD_TYPE::PointType PointType;
130 const size_t numPoints = pointCloud.points.size();
132 for (
size_t c=0; c < numPoints; ++c){
133 PointType &pclPoint = pointCloud.points[c];
134 pnt.
assign(pclPoint.x, pclPoint.y, pclPoint.z);
141 pclPoint.x =
static_cast<float>(pnt[0]);
142 pclPoint.y =
static_cast<float>(pnt[1]);
143 pclPoint.z =
static_cast<float>(pnt[2]);
157 template <
typename POINT_CLOUD_PTR_TYPE>
160 POINT_CLOUD_PTR_TYPE retPointCloudPtr)
162 bool allAddedRet =
true;
164 if (dataTypeInfos && subImg.
getData() && retPointCloudPtr){
178 typedef typename POINT_CLOUD_PTR_TYPE::element_type::PointType PointType;
179 typedef typename POINT_CLOUD_PTR_TYPE::element_type::VectorType PointVectorType;
180 PointVectorType tmpAddedPoints;
181 tmpAddedPoints.reserve(20000);
184 PointType valToAppend;
189 for (p.
z = subImgBox.
v1.
z; p.
z <= subImgBox.
v2.
z; ++p.
z){
190 for (p.
y = subImgBox.
v1.
y; p.
y <= subImgBox.
v2.
y; ++p.
y){
191 for (p.
x = subImgBox.
v1.
x; p.
x <= subImgBox.
v2.
x; ++p.
x){
229 valToAppend.x =
static_cast<float>(p.
x);
230 valToAppend.y =
static_cast<float>(p.
y);
231 valToAppend.z =
static_cast<float>(p.
z);
237 valToAppend.data[3] = 1.0f;
242 tmpAddedPoints.push_back(valToAppend);
250 if (tmpAddedPoints.size() > 0){
251 const MLuint64 newSize =
static_cast<MLuint64>(retPointCloudPtr->width) + tmpAddedPoints.size();
253 retPointCloudPtr->width = mlrange_cast<MLuint32>(newSize);
254 retPointCloudPtr->height = 1;
255 retPointCloudPtr->points.insert(retPointCloudPtr->points.end(), tmpAddedPoints.begin(), tmpAddedPoints.end());
258 ML_PRINT_ERROR(
"mlPCLMLTools.cpp: appendSubImageVoxelsToPointCloud",
260 "Could not add points to point cloud since this would exceed "
261 "the maximum number UINT32_MAX points in a point cloud.");
275 template <
typename POINT_CLOUD_PTR_TYPE>
278 POINT_CLOUD_PTR_TYPE &retPointCloudPtr)
280 typedef typename POINT_CLOUD_PTR_TYPE::element_type POINT_CLOUD_TYPE;
282 retPointCloudPtr = POINT_CLOUD_PTR_TYPE(
new POINT_CLOUD_TYPE);
285 bool isOrganized =
false;
287 retErr = inImg.
getTile(subImage);
292 if (isOrganized && retPointCloudPtr &&
294 retPointCloudPtr->width = mlrange_cast<MLuint32>(subImage.
getExtent().
x);
295 retPointCloudPtr->height = mlrange_cast<MLuint32>(subImage.
getExtent().
y * subImage.
getExtent().
z);
311 template <
typename POINT_TYPE>
314 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
315 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
316 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
317 point.data[3] = 1.0f;
329 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
330 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
331 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
332 point.data[3] = 1.0f;
333 point.data_n[0] =
static_cast<float>(xMarker.
vec[0]);
334 point.data_n[1] =
static_cast<float>(xMarker.
vec[1]);
335 point.data_n[2] =
static_cast<float>(xMarker.
vec[2]);
336 point.data_n[3] = 0.0f;
337 point.label =
static_cast<unsigned int>(xMarker.
type);
349 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
350 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
351 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
352 point.data[3] = 1.0f;
353 point.data_n[0] =
static_cast<float>(xMarker.
vec[0]);
354 point.data_n[1] =
static_cast<float>(xMarker.
vec[1]);
355 point.data_n[2] =
static_cast<float>(xMarker.
vec[2]);
356 point.data_n[3] = 0.0f;
357 point.rgba =
static_cast<unsigned int>(xMarker.
type);
369 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
370 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
371 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
372 point.data[3] = 1.0f;
373 point.data_n[0] =
static_cast<float>(xMarker.
vec[0]);
374 point.data_n[1] =
static_cast<float>(xMarker.
vec[1]);
375 point.data_n[2] =
static_cast<float>(xMarker.
vec[2]);
376 point.data_n[3] = 0.0f;
377 point.intensity =
static_cast<float>(xMarker.
type);
390 template <
typename POINT_CLOUD_PTR_TYPE>
392 POINT_CLOUD_PTR_TYPE &retPointCloudPtr)
395 retPointCloudPtr.reset();
399 const PointList *pl = mlbase_cast<const PointList*>(inBaseList);
400 const VectorList *vl = mlbase_cast<const VectorList*>(inBaseList);
401 const XMarkerList *xml = mlbase_cast<const XMarkerList*>(inBaseList);
404 if (pl || vl || xml || xmlc){
406 typedef typename POINT_CLOUD_PTR_TYPE::element_type POINT_CLOUD_TYPE;
407 retPointCloudPtr = POINT_CLOUD_PTR_TYPE(
new POINT_CLOUD_TYPE);
412 (xml ? mlrange_cast<MLssize_t>(xml->size()) :
413 (xmlc ? mlrange_cast<MLssize_t>(
const_cast<XMarkerListContainer*
>(xmlc)->getList()->size()) : 0))));
417 "Input point cloud has more than ML_UINT32_MAX entries; the "
418 "PointCloud.width parameter cannot be set to this value any more; "
419 "using ML_UINT32_MAX instead.");
423 retPointCloudPtr->width =
static_cast<MLuint32>(numVals);
425 retPointCloudPtr->height = 1;
426 retPointCloudPtr->is_dense =
true;
427 retPointCloudPtr->points.resize(mlrange_cast<size_t>(numVals));
431 for (
MLssize_t cs=0; cs < numVals; ++cs){
432 typename POINT_CLOUD_TYPE::PointType &point = retPointCloudPtr->points[
static_cast<size_t>(cs)];
435 pl->
getValue(cs, point.data[0], point.data[1], point.data[2]);
439 vl->
getPoint(cs, vecType, point.data[0], point.data[1], point.data[2]);
441 else if (xml || xmlc){
460 template <
typename POINT_TYPE>
463 xMarker.
pos[0] = point.data[0];
464 xMarker.
pos[1] = point.data[1];
465 xMarker.
pos[2] = point.data[2];
476 xMarker.
pos[0] = point.data[0];
477 xMarker.
pos[1] = point.data[1];
478 xMarker.
pos[2] = point.data[2];
479 xMarker.
vec[0] = point.data_n[0];
480 xMarker.
vec[1] = point.data_n[1];
481 xMarker.
vec[2] = point.data_n[2];
482 xMarker.
type =
static_cast<int>(point.label);
493 xMarker.
pos[0] = point.data[0];
494 xMarker.
pos[1] = point.data[1];
495 xMarker.
pos[2] = point.data[2];
496 xMarker.
vec[0] = point.data_n[0];
497 xMarker.
vec[1] = point.data_n[1];
498 xMarker.
vec[2] = point.data_n[2];
499 xMarker.
type =
static_cast<int>(point.rgba);
510 xMarker.
pos[0] = point.data[0];
511 xMarker.
pos[1] = point.data[1];
512 xMarker.
pos[2] = point.data[2];
513 xMarker.
vec[0] = point.data_n[0];
514 xMarker.
vec[1] = point.data_n[1];
515 xMarker.
vec[2] = point.data_n[2];
516 xMarker.
type =
static_cast<int>(point.intensity);
526 template <
typename POINT_CLOUD_TYPE>
531 const size_t numInputPoints = inputPointCloud.points.size();
532 outputList.resize(numInputPoints);
533 for (
size_t c=0; c < numInputPoints; ++c){
BaseItem * getItemAt(MLssize_t index) override
This virtual function is reimplemented from ListBase, where it returns 0 in any case (also in ListTem...
const BaseItem * getConstItemAt(MLssize_t index) const override
Same as getItemAt(MLssize_t index) for constant access.
Class representing general ML objects that support import/export via strings (setPersistentState() an...
T length() const
Returns the length of the vector, i.e., norm2().
MLDataType getDataType() const
Returns the data type of the image.
SubImageBox getBoxFromImageExtent() const
Returns the size of image as box with origin 0.
This class encapsulates basic medical image properties:
const Matrix4 & getVoxelToWorldMatrix() const
Returns the voxelToWorld matrix.
void setVoxelToWorldMatrix(const Matrix4 &matrix)
Sets the matrix that transforms voxel to world coordinates to matrix.
Vector3 mapWorldToVoxel(const Vector3 &worldPosition) const
Maps the worldPosition vector to voxel coordinates and returns it.
Vector3 mapVoxelToWorld(const Vector3 &voxelPosition) const
Maps the voxelPosition vector to world coordinates and returns it.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
MLEXPORT MLErrorCode getTile(SubImageBox location, MLDataType dataType, void **data, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
See Host::getTile( module, outputIndex, location, dataType, data, scaleShiftData).
Base object class PointList managing a list of points.
void getValue(MLssize_t index, Vector3 &vec) const
get point at given index
MLssize_t getNum() const
returns the number of contained points
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
void * getData() const
Returns the memory address of the memory managed by the subimage.
MLEXPORT void allocateAsMemoryBlockHandle(MLMemoryErrorHandling handleFailure=ML_RETURN_NULL)
Allocates data using the ML memory manager. For failure handing, see SubImage::allocate().
MLDataType getDataType() const
Returns the type of image data.
ImageVector getExtent() const
Returns the extent of the subimage, which is identical to getBox().getExtent().
const SubImageBox & getBox() const
Returns the box describing the origin/extent of the subimage.
const MLTypeInfos * getDataTypeInfos() const
Returns MLTypeInfos for image data type.
MLint getNumVoxels() const
Returns number of voxels in (sub)image.
void * getImagePointer(const ImageVector &voxelPosition) const
Returns a pointer to voxel data of image voxel at 6D position voxelPosition relative to the origin of...
VectorType v1
Corner v1 of the subimage region (included in region).
VectorType v2
Corner v2 of the subimage region (also included in region!).
ComponentType z
Z component of the vector.
ComponentType x
X component of the vector.
ComponentType y
Y component of the vector.
Forward declarations to resolve header file dependencies.
void assign(const DT px, const DT py, const DT pz)
Sets all components to the passed values.
Base object representing a list of vectors given as Vector4's.
void getPoint(MLssize_t index, int &type, float &x1, float &y1, float &z1) const
returns point of vectors at given point index (NOTE: (0,1 = first vector , 2,3 = second vector))
MLssize_t getNum() const
returns the number of contained points
Base object class XMarkerListContainer (derived from ListContainerTemplate) for XMarkerList objects.
Base object class XMarkerList (derived from BaseListTemplate) specialized for XMarker items.
Base object class XMarker (derived form baseItem) with 6D pos, 3D vec and type int.
Vector3 vec
Marker vector, relative to position.
Vector6 pos
Marker position.
MLint32 MLDataType
MLDataType.
MLEXPORT MLint32 MLIsScalarType(MLDataType dataType)
Alternative name for MLIsStandardType.
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm,...
MLint32 MLErrorCode
Type of an ML Error code.
#define ML_NO_MEMORY
The system does not have enough memory to perform the desired operation; try to reduce application da...
#define ML_RESULT_OK
No error. Everything seems to be okay.
#define ML_PRINT_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped.
Basic types used in the MeVislab binding of the Point Cloud Library(PCL).
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
@ ML_RETURN_NULL
On allocation failure, NULL is returned without error handling.
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
Structure containing all data type features and pointers to all functions needed to implement operati...
Function_CastToDouble castToDouble
Returns a type value cast to double.