Impossible to Generate Triangulation from PointCloud - C code
Hi, I can't run the exemple of triangulation of a point cloud in C. There is directly a Memory violation raised. Thanks for you're help.
#include <MRMeshC/MRBitSet.h>
#include <MRMeshC/MRMesh.h>
#include <MRMeshC/MROffset.h>
#include <MRMeshC/MRPointCloud.h>
#include <MRMeshC/MRPointCloudTriangulation.h>
#include <MRMeshC/MRUniformSampling.h>
#define M_PI 3.1415926535897932384626433832795
#define M_PI_2 1.5707963267948966192313216916398
#include <math.h>
int main(int argc, char* argv[])
{
// Generate point cloud
MRVector3f points[10000];
for (int i = 0; i < 100; ++i)
{
float u = M_PI_2 * (float)i / (100.f - 1.f);
for (int j = 0; j < 100; ++j)
{
float v = M_PI * (float)j / (100.f - 1.f);
points[i * 100 + j] = (MRVector3f){
cos(u) * sin(v),
sin(u) * sin(v),
cos(v)
};
}
}
MRPointCloud* pc = mrPointCloudFromPoints(points, 10000);
// Remove duplicate points
MRUniformSamplingSettings samplingSettings = mrUniformSamplingSettingsNew();
samplingSettings.distance = 1e-3f;
MRVertBitSet* vs = mrPointUniformSampling(pc, &samplingSettings);
mrPointCloudSetValidPoints(pc, vs);
mrPointCloudInvalidateCaches(pc);
// Triangulate it
MRMesh* triangulated = mrTriangulatePointCloud(pc, NULL);
// Fix possible issues
MROffsetParameters offsetParams = mrOffsetParametersNew();
offsetParams.voxelSize = mrSuggestVoxelSize((MRMeshPart) { triangulated, NULL }, 5e+6f);
MRMesh* mesh = mrOffsetMesh((MRMeshPart) { triangulated, NULL }, 0.f, & offsetParams, NULL);
mrMeshFree(mesh);
mrMeshFree(triangulated);
mrVertBitSetFree(vs);
mrPointCloudFree(pc);
}
This code end with :
TestMesh.exe (process 4868) exited with code -1073741819 (0xC0000005).
whereas the example code is.
Can you help me please ?
Hello, there's a bug in the point cloud construction, it will be fixed in the nearest future. Right now you can bypass it by setting the valid points for the point cloud manually:
MRVertBitSet* validPoints = mrVertBitSetNew( 10000, true );
mrPointCloudSetValidPoints( pc, validPoints );
mrVertBitSetFree( validPoints );
Thanks for your answer — that solved the issue.
I have another question: why is triangulation significantly slower when using the C API compared to the C++ API?
I have another question: why is triangulation significantly slower when using the C API compared to the C++ API?
Since C API is implemented on top of C++ API, it is always somewhat slower, but it shall not be significantly slower in most importance scenarios.
Could you please attach input point cloud on which you measured the performance, and your code for both API? Then we will investigate.