if quadric.getName() != 'aQuadric': raise RuntimeError if quadric.size() != 6962: raise RuntimeError tr8 = cc.ccGLMatrix() tr8.initFromParameters(0.5 * math.pi, (0., 1., 0.), (-0.0, -0.0, -4.0)) dish = cc.ccDish(2.0, 1.0, 3.0, tr8, "aDish", 72) if dish.getName() != 'aDish': raise RuntimeError if dish.size() != 2520: raise RuntimeError params = cc.Cloud2MeshDistancesComputationParams() params.maxThreadCount = 12 params.octreeLevel = 6 cc.DistanceComputationTools.computeCloud2MeshDistances(cloud, cylinder, params) cc.DistanceComputationTools.computeCloud2MeshDistances( cone.getAssociatedCloud(), sphere, params) params2 = cc.Cloud2CloudDistancesComputationParams() params2.maxThreadCount = 12 params2.octreeLevel = 6 cc.DistanceComputationTools.computeCloud2CloudDistances( dish.getAssociatedCloud(), box.getAssociatedCloud(), params2) cc.SaveEntities( [cloud, box, cone, cylinder, plane, sphere, torus, quadric, dish], os.path.join(dataDir, "entities2.bin"))
# # ########################################################################## import os import sys import math from gendata import getSampleCloud, getSampleCloud2, dataDir, isCoordEqual, createSymbolicLinks import cloudComPy as cc createSymbolicLinks() # required for tests on build, before cc.initCC cc.initCC() # to do once before using plugins or dealing with numpy cloud1 = cc.loadPointCloud(getSampleCloud2(3.0, 0, 0.1)) cloud1.setName("cloud1") tr1 = cc.ccGLMatrix() tr1.initFromParameters(0.2 * math.pi, (1., 1., 1.), (0.0, 0.0, 10.0)) cloud1.applyRigidTransformation(tr1) plane = cc.ccPlane.Fit(cloud1) equation = plane.getEquation() eqRef = [ 0.4032580554485321, -0.2757962644100189, 0.8725361824035645, 8.782577514648438 ] for i in range(4): if not math.isclose(equation[i], eqRef[i], rel_tol=1.e-3): raise RuntimeError cc.SaveEntities([cloud1, plane], os.path.join(dataDir, "cloudsFit.bin"))
cc.initCC() # to do once before using plugins or dealing with numpy cloud1 = cc.loadPointCloud(getSampleCloud2(3.0,0, 0.1)) cloud1.setName("cloud1") mesh1 = cc.ccMesh.triangulate(cloud1, cc.TRIANGULATION_TYPES.DELAUNAY_2D_AXIS_ALIGNED) mesh1.setName("mesh1") cloud2=mesh1.samplePoints(True, 50) cloud2.setName("cloud2") if not math.isclose(cloud2.size(), 6489, rel_tol=0.05): raise RuntimeError cloud3=mesh1.samplePoints(True, 500) cloud3.setName("cloud3") if not math.isclose(cloud3.size(), 64641, rel_tol=0.05): raise RuntimeError cloud4=mesh1.samplePoints(False, 1000) cloud4.setName("cloud4") if not math.isclose(cloud4.size(), 1000, rel_tol=0.05): raise RuntimeError cloud5=mesh1.samplePoints(False, 100000) cloud5.setName("cloud5") if not math.isclose(cloud5.size(), 100000, rel_tol=0.05): raise RuntimeError cc.SaveEntities([cloud1, mesh1, cloud2, cloud3, cloud4, cloud5], os.path.join(dataDir, "samplemesh.bin"))
import cloudComPy as cc createSymbolicLinks() # required for tests on build, before cc.initCC cc.initCC() # to do once before using plugins or dealing with numpy cloud1 = cc.loadPointCloud(getSampleCloud2(3.0, 0, 0.1)) cloud1.setName("cloud1") if cloud1.size() != 10000: raise RuntimeError mesh1 = cc.ccMesh.triangulate(cloud1, cc.TRIANGULATION_TYPES.DELAUNAY_2D_AXIS_ALIGNED) mesh1.setName("mesh1") if not math.isclose(mesh1.size(), 19602, rel_tol=5e-02): raise RuntimeError mesh2 = mesh1.cloneMesh() if mesh2.getName() != "mesh1.clone": raise RuntimeError mesh3 = mesh2.subdivide(0.001) if not math.isclose(mesh3.size(), 335696, rel_tol=5e-02): raise RuntimeError mesh3.laplacianSmooth() cc.SaveEntities([cloud1, mesh1, mesh2, mesh3], os.path.join(dataDir, "clouds1.bin"))
cc.initCC() # to do once before using plugins or dealing with numpy cloud1 = cc.loadPointCloud(getSampleCloud(5.0)) cloud1.setName("cloud1") cloud2ref = cc.loadPointCloud(getSampleCloud(5.0, 9.0)) cloud2ref.setName("cloud2_reference") cloud2 = cloud2ref.cloneThis() tr1 = cc.ccGLMatrix() # -------------------- z -- y -- x tr1.initFromParameters(0.0, 0.0, 0.1, (0.0, 0.0, 0.3)) cloud2.applyRigidTransformation(tr1) cloud2.setName("cloud2_transformed") cc.SaveEntities([cloud1, cloud2ref, cloud2], os.path.join(dataDir, "clouds2.bin")) res = cc.ICP(cloud2, cloud1, 1.e-5, 20, 50000, False, cc.CONVERGENCE_TYPE.MAX_ITER_CONVERGENCE, False, 0.1) tr2 = res.transMat cloud3 = res.aligned cloud3.applyRigidTransformation(tr2) cloud3.setName("cloud2_transformed_afterICP") params = cc.Cloud2CloudDistanceComputationParams() params.maxThreadCount = 12 params.octreeLevel = 6 cc.DistanceComputationTools.computeCloud2CloudDistance(cloud2ref, cloud3, params) sf = cloud2ref.getScalarField(cloud2ref.getNumberOfScalarFields() - 1)
if nb != 1000000: raise RuntimeError cloud.exportNormalToSF(True, True, True) sf = cloud.getScalarField(2) if sf.getName() != 'Nz': raise RuntimeError sfmin = sf.getMin() sfmax = sf.getMax() if not math.isclose(sfmin, 0.06670579, rel_tol=1e-06): raise RuntimeError if not math.isclose(sfmax, 0.9999990, rel_tol=1e-06): raise RuntimeError meanvar = sf.computeMeanAndVariance() if not math.isclose(meanvar[0], 0.74157232, rel_tol=1e-06): raise RuntimeError if not math.isclose(meanvar[1], 0.04167303, rel_tol=1e-06): raise RuntimeError cloud1 = cc.loadPointCloud(getSampleCloud2(3.0, 0, 0.1)) cloud1.setName("cloud1") plane = cc.ccPlane.Fit(cloud1) mesh1 = cc.ccMesh.triangulate(cloud1, cc.TRIANGULATION_TYPES.DELAUNAY_2D_AXIS_ALIGNED) mesh1.setName("mesh1") cc.computeNormals([mesh1]) res = cc.SaveEntities([cloud, cloud1, mesh1], os.path.join(dataDir, "cloudmesh.bin")) if res != cc.CC_FILE_ERROR.CC_FERR_NO_ERROR: raise RuntimeError