21 #if defined(MLAB_CMAKE_BUILDSYSTEM)
36 namespace PCLMLTools {
59 template <
typename PCL_POINT_TYPE>
75 thresholdMin(0.), thresholdMax(0.),
76 lowerValue(0.), upperValue(0.),
77 skipVoxelsBelowMin(false),
78 skipVoxelsAboveMax(false),
79 normalizeInClampedRange(false),
80 useVectorLengthAsIntensity(false),
81 transformToWorld(false){};
127 template <
typename POINT_CLOUD_TYPE>
129 const Matrix4 &voxelToWorldMatrix,
132 typedef typename POINT_CLOUD_TYPE::PointType PointType;
135 const size_t numPoints = pointCloud.points.size();
137 for (
size_t c=0; c < numPoints; ++c){
138 PointType &pclPoint = pointCloud.points[c];
139 pnt.
assign(pclPoint.x, pclPoint.y, pclPoint.z);
146 pclPoint.x =
static_cast<float>(pnt[0]);
147 pclPoint.y =
static_cast<float>(pnt[1]);
148 pclPoint.z =
static_cast<float>(pnt[2]);
162 template <
typename POINT_CLOUD_PTR_TYPE>
165 POINT_CLOUD_PTR_TYPE retPointCloudPtr)
167 bool allAddedRet =
true;
169 if (dataTypeInfos && subImg.
getData() && retPointCloudPtr){
183 typedef typename POINT_CLOUD_PTR_TYPE::element_type::PointType PointType;
184 typedef typename POINT_CLOUD_PTR_TYPE::element_type::VectorType PointVectorType;
185 PointVectorType tmpAddedPoints;
186 tmpAddedPoints.reserve(20000);
189 PointType valToAppend;
194 for (p.
z = subImgBox.
v1.
z; p.
z <= subImgBox.
v2.
z; ++p.
z){
195 for (p.
y = subImgBox.
v1.
y; p.
y <= subImgBox.
v2.
y; ++p.
y){
196 for (p.
x = subImgBox.
v1.
x; p.
x <= subImgBox.
v2.
x; ++p.
x){
234 valToAppend.x =
static_cast<float>(p.
x);
235 valToAppend.y =
static_cast<float>(p.
y);
236 valToAppend.z =
static_cast<float>(p.
z);
242 valToAppend.data[3] = 1.0f;
247 tmpAddedPoints.push_back(valToAppend);
255 if (tmpAddedPoints.size() > 0){
256 const MLuint64 newSize =
static_cast<MLuint64>(retPointCloudPtr->width) + tmpAddedPoints.size();
258 retPointCloudPtr->width = mlrange_cast<MLuint32>(newSize);
259 retPointCloudPtr->height = 1;
260 retPointCloudPtr->points.insert(retPointCloudPtr->points.end(), tmpAddedPoints.begin(), tmpAddedPoints.end());
263 ML_PRINT_ERROR(
"mlPCLMLTools.cpp: appendSubImageVoxelsToPointCloud",
265 "Could not add points to point cloud since this would exceed "
266 "the maximum number UINT32_MAX points in a point cloud.");
280 template <
typename POINT_CLOUD_PTR_TYPE>
283 POINT_CLOUD_PTR_TYPE &retPointCloudPtr)
285 typedef typename POINT_CLOUD_PTR_TYPE::element_type POINT_CLOUD_TYPE;
287 retPointCloudPtr = POINT_CLOUD_PTR_TYPE(
new POINT_CLOUD_TYPE);
290 bool isOrganized =
false;
292 retErr = inImg.
getTile(subImage);
297 if (isOrganized && retPointCloudPtr &&
299 retPointCloudPtr->width = mlrange_cast<MLuint32>(subImage.
getExtent().
x);
300 retPointCloudPtr->height = mlrange_cast<MLuint32>(subImage.
getExtent().
y * subImage.
getExtent().
z);
316 template <
typename POINT_TYPE>
319 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
320 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
321 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
322 point.data[3] = 1.0f;
334 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
335 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
336 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
337 point.data[3] = 1.0f;
338 point.data_n[0] =
static_cast<float>(xMarker.
vec[0]);
339 point.data_n[1] =
static_cast<float>(xMarker.
vec[1]);
340 point.data_n[2] =
static_cast<float>(xMarker.
vec[2]);
341 point.data_n[3] = 0.0f;
342 point.label =
static_cast<unsigned int>(xMarker.
type);
354 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
355 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
356 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
357 point.data[3] = 1.0f;
358 point.data_n[0] =
static_cast<float>(xMarker.
vec[0]);
359 point.data_n[1] =
static_cast<float>(xMarker.
vec[1]);
360 point.data_n[2] =
static_cast<float>(xMarker.
vec[2]);
361 point.data_n[3] = 0.0f;
362 point.rgba =
static_cast<unsigned int>(xMarker.
type);
374 point.data[0] =
static_cast<float>(xMarker.
pos[0]);
375 point.data[1] =
static_cast<float>(xMarker.
pos[1]);
376 point.data[2] =
static_cast<float>(xMarker.
pos[2]);
377 point.data[3] = 1.0f;
378 point.data_n[0] =
static_cast<float>(xMarker.
vec[0]);
379 point.data_n[1] =
static_cast<float>(xMarker.
vec[1]);
380 point.data_n[2] =
static_cast<float>(xMarker.
vec[2]);
381 point.data_n[3] = 0.0f;
382 point.intensity =
static_cast<float>(xMarker.
type);
395 template <
typename POINT_CLOUD_PTR_TYPE>
397 POINT_CLOUD_PTR_TYPE &retPointCloudPtr)
400 retPointCloudPtr.reset();
404 #if !defined(MLAB_CMAKE_BUILDSYSTEM)
405 const PointList *pl = mlbase_cast<const PointList*>(inBaseList);
406 const VectorList *vl = mlbase_cast<const VectorList*>(inBaseList);
408 const XMarkerList *xml = mlbase_cast<const XMarkerList*>(inBaseList);
412 #
if !defined(MLAB_CMAKE_BUILDSYSTEM)
417 typedef typename POINT_CLOUD_PTR_TYPE::element_type POINT_CLOUD_TYPE;
418 retPointCloudPtr = POINT_CLOUD_PTR_TYPE(
new POINT_CLOUD_TYPE);
421 #if !defined(MLAB_CMAKE_BUILDSYSTEM)
424 (xml ? mlrange_cast<MLssize_t>(xml->size()) :
425 (xmlc ? mlrange_cast<MLssize_t>(
const_cast<XMarkerListContainer*
>(xmlc)->getList()->size()) : 0))));
427 const MLssize_t numVals = (xml ? mlrange_cast<MLssize_t>(xml->size()) :
428 (xmlc ? mlrange_cast<MLssize_t>(
const_cast<XMarkerListContainer*
>(xmlc)->getList()->size()) : 0));
433 "Input point cloud has more than ML_UINT32_MAX entries; the "
434 "PointCloud.width parameter cannot be set to this value any more; "
435 "using ML_UINT32_MAX instead.");
439 retPointCloudPtr->width =
static_cast<MLuint32>(numVals);
441 retPointCloudPtr->height = 1;
442 retPointCloudPtr->is_dense =
true;
443 retPointCloudPtr->points.resize(mlrange_cast<size_t>(numVals));
447 for (
MLssize_t cs=0; cs < numVals; ++cs){
448 typename POINT_CLOUD_TYPE::PointType &point = retPointCloudPtr->points[
static_cast<size_t>(cs)];
450 #if !defined(MLAB_CMAKE_BUILDSYSTEM)
452 pl->
getValue(cs, point.data[0], point.data[1], point.data[2]);
456 vl->
getPoint(cs, vecType, point.data[0], point.data[1], point.data[2]);
479 template <
typename POINT_TYPE>
482 xMarker.
pos[0] = point.data[0];
483 xMarker.
pos[1] = point.data[1];
484 xMarker.
pos[2] = point.data[2];
495 xMarker.
pos[0] = point.data[0];
496 xMarker.
pos[1] = point.data[1];
497 xMarker.
pos[2] = point.data[2];
498 xMarker.
vec[0] = point.data_n[0];
499 xMarker.
vec[1] = point.data_n[1];
500 xMarker.
vec[2] = point.data_n[2];
501 xMarker.
type =
static_cast<int>(point.label);
512 xMarker.
pos[0] = point.data[0];
513 xMarker.
pos[1] = point.data[1];
514 xMarker.
pos[2] = point.data[2];
515 xMarker.
vec[0] = point.data_n[0];
516 xMarker.
vec[1] = point.data_n[1];
517 xMarker.
vec[2] = point.data_n[2];
518 xMarker.
type =
static_cast<int>(point.rgba);
529 xMarker.
pos[0] = point.data[0];
530 xMarker.
pos[1] = point.data[1];
531 xMarker.
pos[2] = point.data[2];
532 xMarker.
vec[0] = point.data_n[0];
533 xMarker.
vec[1] = point.data_n[1];
534 xMarker.
vec[2] = point.data_n[2];
535 xMarker.
type =
static_cast<int>(point.intensity);
545 template <
typename POINT_CLOUD_TYPE>
550 const size_t numInputPoints = inputPointCloud.points.size();
551 outputList.resize(numInputPoints);
552 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 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 which 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.
Class which represents an image, which manages properties of an image and image data which is located...
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 which 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)
Allocate data using the ML memory manager. For failure handing, see SubImage::allocate().
MLDataType getDataType() const
Return 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
Get MLTypeInfos for image data type.
MLint getNumVoxels() const
Returns number of voxels in (sub)image.
void * getImagePointer(const ImageVector &voxelPosition) const
Returns pointer to voxel data of image voxel at 6d position voxelPosition relative to the begin of th...
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 which is a signed 32 bit size_t on 32 bit platforms and 64 bit one on 64 bit ...
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.