# Point Cloud Library in UE4

**URL:** <https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [November 5, 2015, 3:12pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713 "2015-11-05T15:12:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_89e0d94a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_89e0d94a](https://forums.unrealengine.com/u/anonymous_user_89e0d94a)\
**Post date:** [November 5, 2015, 3:12pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/1 "2015-11-05T15:12:31Z")

</div>

I tried to include PCL into my project. I need some methods to process my point cloud like filtering, smoothing, downsampling and triangulation.  
Unfortunately I always get the same error when using some function of PCL. For example at the following filter method:

```auto

#include <pcl/filters/radius_outlier_removal.h>
#include <pcl/filters/conditional_removal.h>

void AVoxelGenerator::GeneratePointCloud(TArray<FVector4> Voxels)
{
	 pcl::PointCloud<pcl::PointXYZI>::Ptr Cloud(new pcl::PointCloud<pcl::PointXYZI>());
 	 pcl::PointCloud<pcl::PointXYZI>::Ptr Cloud_filtered(new pcl::PointCloud<pcl::PointXYZI>());

	 Cloud->width = Width;
	 Cloud->height = Height;
 	 Cloud->is_dense = true;		
	 Cloud->points.resize(Voxels.Num());

	  for (int i = 0; i < Voxels.Num(); i++)
	  {
		 Cloud->points*.x = Voxels*.X;
		 Cloud->points*.y = Voxels*.Y;
		 Cloud->points*.z = Voxels*.Z;
 		 Cloud->points*.intensity = Voxels*.W;
	 }

	pcl::RadiusOutlierRemoval<pcl::PointXYZI> Ror;
	Ror.setInputCloud(Cloud);
	Ror.setRadiusSearch(20.0);
	Ror.setMinNeighborsInRadius(5);
	Ror.filter(*Cloud_filtered);

	pcl::PCDWriter Writer;
	Writer.write<pcl::PointXYZI>("Table_inliers.pcd", *Cloud_filtered, false);
}

```

When I debug the method everything works fine (The Writer writes the file and saves the estimated points). But at the end of the method before jumping to the next method I always get an error at MallocTB::Free().  
First-chance exception at 0x00007FFB2AB60080 (UE4Editor-Core.dll) in UE4Editor.exe: 0xC0000005: Access violation writing location 0x000000293E868050  
Unhandled exception at 0x00007FFB2AB60080 (UE4Editor-Core.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x000000293E868050

I really tried a lot but I don’t know why this error occurs… . It seems that there are some problems between memory handling in UE4 and memory handling in the PCL framework? I would be grateful if someone can help me.

Is it possible that there is a problem with using boost::shared\_ptr in UE4? “Ptr” is of this type.

---

<div class="post-metadata">

**Author:** ![Cyxx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cyxx](https://forums.unrealengine.com/u/Cyxx)\
**Post date:** [November 7, 2015, 7:16pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/2 "2015-11-07T19:16:13Z")

</div>

Hi Mell\_D  
I setup a small PCL plugin project and tried your code.  
Except the Ror filter everything works fine here without exception and the pcd file is written.  
From the name “AVoxelGenerator” I guess that you derive from AActor, or?  
Is this actor always available? Because all UObjects can be garbage collected:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Which version of PCL, Boost and VStudio do you use?  
I used UE4.9, VS2013, Boost 1.59 and the actual PCL code from the repository.

Attached the code from my test class:

```auto

PCLFilter.h:

#pragma once
#include "Engine.h"
#include "GameFramework/Actor.h"
#include "PCLFilter.generated.h"

UCLASS()
class AVoxelGenerator : public AActor
{
 	GENERATED_BODY()
	
  public:	
 	AVoxelGenerator();

 	void GeneratePointCloud(TArray<FVector4> Voxels);
};

---
PCLFilter.cpp:

#include "PCLPrivatePCH.h"
#include "PCLFilter.h"
#include "AllowWindowsPlatformTypes.h"
#include "pcl/point_types.h"
#include "pcl/filters/radius_outlier_removal.h"
#include "pcl/filters/conditional_removal.h"
#include "pcl/io/pcd_io.h"
#include "HideWindowsPlatformTypes.h"

AVoxelGenerator::AVoxelGenerator()
{
	
}

void AVoxelGenerator::GeneratePointCloud(TArray<FVector4> Voxels)
{
  pcl::PointCloud<pcl::PointXYZI>::Ptr Cloud(new pcl::PointCloud<pcl::PointXYZI>());
  pcl::PointCloud<pcl::PointXYZI>::Ptr Cloud_filtered(new pcl::PointCloud<pcl::PointXYZI>());

  Cloud->width = Voxels.Num();
  Cloud->height = 1;
  Cloud->is_dense = false;		
  Cloud->points.resize(Voxels.Num());

  for (int i = 0; i < Voxels.Num(); i++)
  {
    Cloud->points*.x = Voxels*.X;
    Cloud->points*.y = Voxels*.Y;
    Cloud->points*.z = Voxels*.Z;
    Cloud->points*.intensity = Voxels*.W;
  }

  // ...

  pcl::PCDWriter Writer;
  Writer.write<pcl::PointXYZI>("d:/Table_inliers.pcd", *Cloud, false);
  //Writer.write<pcl::PointXYZI>("d:/Table_inliers.pcd", *Cloud_filtered, false);	
}

```

Regarding your boost::shared\_ptr:  
Did you try using a reference instead? Like:  
pcl::PointCloud\<pcl::PointXYZI\> Cloud;

Best regards  
Heiko

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_89e0d94a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_89e0d94a](https://forums.unrealengine.com/u/anonymous_user_89e0d94a)\
**Post date:** [November 9, 2015, 9:39am UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/3 "2015-11-09T09:39:44Z")

</div>

Hi Heiko,

thank you very much for your answer and sorry for my late reply.

Yes, my class derives from AActor and yes, this class is always available. I use UE4.9, VS2013, Boost 1.57 and PCL 1.7.2 (I used the all-in-one-installer from [http://unanancyowen.com/?p=1255&lang=en](http://unanancyowen.com/?p=1255&lang=en) for VS2013, Win64).  
And yes I tried to use a reference instead of boost::shared\_ptr but that didn’t work. Which problems did appear with your RoR filter? Is it too slow?

If I comment the filter method out my code works well too. Otherwise the filter method works well but at the end of my function I suddenly get that error. I tried other filters too (e.g Voxelgrid) but it’s always the same error.

Best regards

---

<div class="post-metadata">

**Author:** ![Cyxx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cyxx](https://forums.unrealengine.com/u/Cyxx)\
**Post date:** [November 9, 2015, 1:38pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/4 "2015-11-09T13:38:29Z")

</div>

Hi  
thanks for your additional infos. I just wanted to let you know that I switched to your Boost and PCL version,  
activated the ROR filter again and now I get a similiar exception as you:  
_Unhandled exception at 0x000007FEE757D983 (UE4Editor-Core.dll) in UE4Editor.exe: 0xC0000005: Access violation writing location 0x0000000000000010._  
Debugger stops at the end of FMallocTBB::Free method.  
In the stack frame I see that the destructor of class Filter and then the dispose method of Boost class sp\_counted\_impl\_p is called before.  
I will now try to debug deeper.

As a quick dirty workaround you can declare Ror as global.  
Just move the line outside the function:  
pcl::RadiusOutlierRemoval\<pcl::PointXYZI\> Ror;

Best regards  
Heiko

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_89e0d94a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_89e0d94a](https://forums.unrealengine.com/u/anonymous_user_89e0d94a)\
**Post date:** [November 9, 2015, 3:00pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/5 "2015-11-09T15:00:19Z")

</div>

Hi Heiko,

yes the error arises after the sp\_counted\_impl.hpp. I just tried to uncomment the “delete x” in the file boost/core/checked\_delete.hpp (… dangerous(!) haha…).  
So that works but what does it mean for the problem? Unreal wants to delete the pointer again after Boost does it and that’s why we get the access violation error? I can prevent Unreal from doing this only if I declare Ror as a global?  
Not so pretty but it works! Thank you very very much! 🙂 I really spend a lot of time to understand what’s going on here…

Best regards

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_844f5cc3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_844f5cc3](https://forums.unrealengine.com/u/anonymous_user_844f5cc3)\
**Post date:** [February 16, 2016, 12:17pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/6 "2016-02-16T12:17:11Z")

</div>

Hi,

I’m new to unreal and trying to use PCL. How did you get it to work? What has to be done before you can write “#include \<pcl/…”?

I hope it’s ok that I borrowed the thread!

Best regards

---

<div class="post-metadata">

**Author:** ![as3ef2th1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@as3ef2th1](https://forums.unrealengine.com/u/as3ef2th1)\
**Post date:** [February 21, 2016, 10:13pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/7 "2016-02-21T22:13:45Z")

</div>

Hello,

Hi,

I also would like to import points cloud in the engine.  
Are you still working on your plugin, to be honest my C++ knowledge is not that good ?

I guess everyone want at least two things : get point cloud in the engine and get the dynamic LOD to work inside the engine (you know, the real time decimation from octrees and camera position).

Best regards,

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_47d2417c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_47d2417c](https://forums.unrealengine.com/u/anonymous_user_47d2417c)\
**Post date:** [February 24, 2016, 4:06am UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/8 "2016-02-24T04:06:16Z")

</div>

> [@as3ef2th1;478573](#):
>
> Hello,
> 
> Hi,
> 
> I also would like to import points cloud in the engine.  
> Are you still working on your plugin, to be honest my C++ knowledge is not that good ?
> 
> I guess everyone want at least two things : get point cloud in the engine and get the dynamic LOD to work inside the engine (you know, the real time decimation from octrees and camera position).
> 
> Best regards,

Hi Did you find solution ? I am also working on the same issue.

---

<div class="post-metadata">

**Author:** ![as3ef2th1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@as3ef2th1](https://forums.unrealengine.com/u/as3ef2th1)\
**Post date:** [April 21, 2016, 12:06pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/9 "2016-04-21T12:06:16Z")

</div>

> [@qbhust;480129](#):
>
> Hi Did you find solution ? I am also working on the same issue.

Not yet unfortunately. Maybe when I have more time I will look into this seriously…

---

<div class="post-metadata">

**Author:** ![plangton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@plangton](https://forums.unrealengine.com/u/plangton)\
**Post date:** [June 1, 2017, 1:49pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/10 "2017-06-01T13:49:24Z")

</div>

Is anyone still interested in cpu based pointcloud ? I can make a basic plugin for you guys.  
I was testing the possibilities after reading this thread and it is not too hard to create, draw and update points in ue4

---

<div class="post-metadata">

**Author:** ![Neoplanetz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neoplanetz](https://forums.unrealengine.com/u/Neoplanetz)\
**Post date:** [June 7, 2017, 7:34am UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/11 "2017-06-07T07:34:17Z")

</div>

Hi plangton. I’m also interesting using PCL library in UE4. Is it possible to get point cloud data from depth sensor like Kinect v2 and draw and display in UE4 realtime?  
If It can be, Can you share your idea or plugin code? thanks you~

---

<div class="post-metadata">

**Author:** ![plangton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@plangton](https://forums.unrealengine.com/u/plangton)\
**Post date:** [July 19, 2017, 9:49am UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/12 "2017-07-19T09:49:47Z")

</div>

> [@Neoplanetz;720612](#):
>
> Hi plangton. I’m also interesting using PCL library in UE4. Is it possible to get point cloud data from depth sensor like Kinect v2 and draw and display in UE4 realtime?  
> If It can be, Can you share your idea or plugin code? thanks you~

I have done that with Kinect but for that it’s the best if you do it with GPU particles or in materials with worldpositionoffset. the reason I am telling this is that Kinect v2 will send you 30 fps and each frame consists of 512_424 pixel data this is a massive amount of information to be process all in cpu and better to be shared between cpu and gpu.  
So, here are my suggestions  
1 - have a plane with 512_424 vertices, get each frame as a depth texture, send it to a material that apply the depth value to worldpositionoffset z position and apply that material as a dynamic material to your plane. ( this will set the Z but not the exact x&y for that you need more calculation to get world (x,y,z) from depth texture which is in (u,v,z) basically you will need to calculate x,y using u,v and camera intrinsics

2 - it is mostly like solution one except that you will set everything to a gpu particle. you can adjust it to have exactly 512\*424 number of particle and set the position of each separately using the texture. I once saw another thread explaining this solution extensively

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_88d57b37](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_88d57b37](https://forums.unrealengine.com/u/anonymous_user_88d57b37)\
**Post date:** [August 16, 2017, 2:27pm UTC](https://forums.unrealengine.com/t/point-cloud-library-in-ue4/46713/13 "2017-08-16T14:27:19Z")

</div>

hey guys,

this might be helpful: [How to include Third Party library (like boost / PCL) in a custom plugin? [SOLVED] - Plugins - Epic Developer Community Forums](https://answers.unrealengine.com/questions/679340/how-to-include-third-party-library-like-boost-pcl.html#answer-679343)
