RCSpatialFilter performance issue and wrong behaviour

RCSpatialFilter performance issue and wrong behaviour

daniel_klawitter
Participant Participant
2,048 Views
10 Replies
Message 1 of 11

RCSpatialFilter performance issue and wrong behaviour

daniel_klawitter
Participant
Participant

Dear ReCap SDK team,

 

I used the documentation and worked myself throug the topic:

Using Temporary Spatial Filters

 

The filter that I used is RCBoxSpatialFilter. First I compared the performance of the Sdk with that of ObjectArx.

The iteration over the points with the filter took longer than without them.

performanceReCapSDK.png

Therefore, I tested the same example with ObjectARX:

performanceObjectArx.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I made two observations:

  •  with ObjectArx it is much faster than with the SDK.  This leads to the question: Does the ReCap SDK use an octree structure, does it just iterate over all points or am I messing something?
  • the number of points contained by the box differs.

I created a new rcp file containing all points that were filtered with the ReCap SDK. Here you can see the filtered part of the point cloud together with the box that I used to filter the points.

boxFilterReCap.png

It seems that the RCBoxSpatialFilter does not work properly. I can provide all data and the code I used if necessary.

 

I am very excited to receive an answer.

2,049 Views
10 Replies
Replies (10)
Message 2 of 11

yan.fu
Alumni
Alumni

Hi @daniel_klawitter ,

 

Thank you for reporting this issue. The spatial filter makes use of the octree structure for filtering. 

Please share with us your code and data with us for further investigation. 

 

Thanks,

Yan

Message 3 of 11

daniel_klawitter
Participant
Participant

Hi @yan.fu ,

 

here is the code:

#include "stdafx.h"

#include <data/RCPointBuffer.h>
#include <data/RCProjectImportSession.h>
#include <dbobjptr.h>
#include <AcDbPointCloudEx.h>
#include <data/RCProject.h>
#include <data/RCPointIteratorSettings.h>
#include <data/IRCPointIterator.h>

#include <data/RCSpatialFilter.h>

namespace Testing
{
	using namespace Autodesk::RealityComputing::Foundation;
	using namespace Autodesk::RealityComputing::Data;

	TEST(TestRecapSDK, DISABLED_TestSpatialFilterPlanar)
	{
		dev\\test.rcp")); // Full path of the .rcp file to be loaded
		RCCode errorCode;
		auto projectPointer = RCProject::loadFromFile(projectFilePath,
			RCFileAccess::ReadOnly,
			RCProjectUserEdits::None,
			errorCode);

		RCBoxSpatialFilter boxFilter(RCVector3d(0, 0, 0), RCVector3d(2000, 2000, 2000));
		projectPointer->addTemporarySpatialFilter(boxFilter.clone());

		RCPointIteratorSettings settings;

		// Create a point-by-point iterator that has access to all points in the given project
		RCSharedPtr<IRCPointIterator> pointIterator = projectPointer->createPointIterator(settings);

		// iterate through points without spatial filter
		clock_t tic = clock();
		uint64_t count(0);
		while (pointIterator->moveToNextPoint())
			count++;
		
		clock_t toc = clock();
		double time = (double)(toc - tic);
		std::wstringstream wstr;
		wstr << "Time taken without filter: " << 1000 * (time / CLOCKS_PER_SEC) << " milli seconds, "<< count <<" points." << std::endl;
		acutPrintf(wstr.str().c_str());

		settings.setIsVisiblePointsOnly(true);
		pointIterator = projectPointer->createPointIterator(settings);
	
		count = 0;
		wstr.clear();
		tic = clock();
		while (pointIterator->moveToNextPoint())
			count++;
		
		toc = clock();
		time = (double)(toc - tic);
		wstr << "Time taken with box filter: " << 1000 * (time / CLOCKS_PER_SEC) << " milli seconds, " << count << " points." << std::endl;
		acutPrintf(wstr.str().c_str());
	}
}

Atached you find a zip file containing the rcp and rcs files. I am excited to hearing from you.

 

Best regards,

Daniel

Message 4 of 11

yan.fu
Alumni
Alumni

Thank you @daniel_klawitter .

 

The dev team will take a look and update when there is further finding.

 

Thanks,

Yan

Message 5 of 11

daniel_klawitter
Participant
Participant

@yan.fu 

 

I found another issue with RCSpatialFilter. When the dev team takes a closer look, they can also check the following behaviour.

I tested the entry into ReCap SDK from ObjectARX is via the AcDbPointCloudEx::getReCapProject(). The following code snippet was used:

 

// open the point cloud object
AcDbObjectPointer<AcDbPointCloudEx> pPcEx(pointCloudId, AcDb::kForRead);
if (Acad::eOk != pPcEx.openStatus())
{
	return;
}

//RCProject* projectPointer = pPcEx->getReCapProject();
RCBoxSpatialFilter boxFilter(RCVector3d(0, 0, 0), RCVector3d(2000, 2000, 2000));
RCProject* projectPointer = pPcEx->getReCapProject();
projectPointer->addTemporarySpatialFilter(boxFilter.clone());

RCPointIteratorSettings settings;
settings.setIsVisiblePointsOnly(true);

// Create a point-by-point iterator that has access to all points in the given project
RCSharedPtr<IRCPointIterator> pointIterator = projectPointer->createPointIterator(settings);
int count = 0;
	
auto tic = clock();
while (pointIterator->moveToNextPoint())
	count++;

auto toc = clock();
double time = (double)(toc - tic);
std::wstringstream wstr;
wstr << "Time taken with box filter ReCap SDK: " << 1000 * (time / CLOCKS_PER_SEC) << " milli seconds, " << count << " points." << std::endl;
acutPrintf(wstr.str().c_str());

 

I compared the time that was needed with an objectArx implementation. It was slower as written in my other post. Additionally, I have observed that each call of my test command needs more time:

slowerAndSlower.png

 

If I create the RCProject pointer via:

 

RCString projectFilePath(("C:\\dev\\test.rcp")); // Full path of the .rcp file to be loaded
		RCCode errorCode;
		auto projectPointer = RCProject::loadFromFile(projectFilePath,
			RCFileAccess::ReadOnly,
			RCProjectUserEdits::None,
			errorCode);

 

the time needed for each iteration through all points of the section is constant. 

Message 6 of 11

yan.fu
Alumni
Alumni

Hi @daniel_klawitter ,

 

For the result of RCBoxSpatialFilter, please note that the unit of the input coordinates is in meter instead of millimetre. So the result is correct. 

 

boxfilter.PNG

 

For the increasing time cost, have you removed the temporary spatial filter after each use? Is the temporary spatial filter remaining in the project?

 

Yan

Message 7 of 11

yan.fu
Alumni
Alumni

BTW, you can use PointBtachIterator, it is faster than single point iterator. 

 

auto pointBatchIterator = mProjectInfo->createPointBatchIterator(settings);

while (pointBatchIterator->moveToNextBatch(batchSize))

{

    ...

}

 

We will continue looking into the performance of RCSpatialFilter.

 

Yan

Message 8 of 11

daniel_klawitter
Participant
Participant

Hey @yan.fu,

 

Thank you for the clarification. You are right, I used the wrong unit. Good to know, that the project unit is needed.

 

For the increasing time cost: I left the scope of RCProject pointer and fetched it again when calling the test command again. I will try to remove it.

 

Message 9 of 11

daniel_klawitter
Participant
Participant

Removing the sptaial temporaly filters helped. I have to say, that this behaviour is not very intuitive. I would assume that a newly loaded project has no temporally spatial filters, ok.

 

One more question: How do I create a project thats unit is millimeter. The bumped_sphere point cloud was generated with RCProjectImportSession. How do I set the unit of the resulting rcp project?

 

Best regards,

Daniel

Message 10 of 11

daniel_klawitter
Participant
Participant

We will continue looking into the performance of RCSpatialFilter.

 

Did you solve this issue or the SDK still not usable for spatial filter based point cloud interaction?

Message 11 of 11

yan.fu
Alumni
Alumni

Hi @daniel_klawitter ,

 

Sorry that we don't have update on the RCSpatialFilter performance yet. 

 

Best,

Yan