Converting real Pointcloud data to a shape using simSurfRec.reconstruct_scale_space

Typically: "How do I... ", "How can I... " questions
Post Reply
dkchaisumdet
Posts: 12
Joined: 19 Mar 2023, 06:27

Converting real Pointcloud data to a shape using simSurfRec.reconstruct_scale_space

Post by dkchaisumdet »

Hello,

When i attempt to convert my real sensor point cloud data into a shape using the function simSurfRec.reconstruct_scale_space, my simulation freezes the moment i call the function and I'm not quite sure why.

Here is the code

Code: Select all

function click_callback()
   createdShape=simSurfRec.reconstruct_scale_space(pointCloudHandle,4,12,300,0.001)
a=2
end

function createDlg()
    if not ui then
        local xml =[[<ui title="point cloud" closeable="false" placement="relative">
                <button text="Take a point cloud picture to interact with" on-click="click_callback"/>
                <label text="(The robot can operate within a point cloud, or within a shape (i.e. a mesh))"/>
        </ui>]]
        ui=simUI.create(xml)
        if uiPos then
            simUI.setPosition(ui,uiPos[1],uiPos[2])
        else
            uiPos={}
            uiPos[1],uiPos[2]=simUI.getPosition(ui)
        end
    end
end

Code: Select all

function sysCall_init()
    showDlg()
    size=1
pointCloudHandle=sim.getObject('/PointCloud',{noError=true})
shapeHandle=sim.getObject('/Shape',{noError=true})
    floorhandle=sim.getObjectHandle('.')
        if(not sim.isHandle(pointCloudHandle)) then
    sim.createPointCloud(0.02,100,0,4)
    pointCloudHandle=sim.getObject('/PointCloud')
    end
    sub=simROS.subscribe('/camera/depth_registered/points', 'sensor_msgs/PointCloud2', 'pointcloudMessage_callback')
    simROS.subscriberTreatUInt8ArrayAsString(sub)
    a=0
end

function pointcloudMessage_callback(pts)
if a==0 then
    sim.removePointsFromPointCloud(pointCloudHandle,0,nil,0)
    local points={}
    local col={}
    local num=pts.width*pts.height
    tables=sim.unpackFloatTable(pts.data,0,0,0)
    tables1=sim.unpackUInt8Table(pts.data,0,0,0)
    for  i=0,num-1 do
        if(tables[8*i+1]==tables[8*i+1]) then
           table.insert(col,tables1[32*i+19])
           table.insert(col,tables1[32*i+18])
           table.insert(col,tables1[32*i+17])
           table.insert(points,-tables[8*i+1])
           table.insert(points,-tables[8*i+2])
           table.insert(points,tables[8*i+3])
         end
    end
    sim.insertPointsIntoPointCloud(pointCloudHandle,3,points,col,nil)

    sim.setObjectPosition(pointCloudHandle,floorhandle,{0,0,0.2})
    yawAngle=-90*(math.pi/180)
    pitchAngle=0*(math.pi/180)
    rollAngle=105*(math.pi/180)
    alphaAngle,betaAngle,gammaAngle=sim.yawPitchRollToAlphaBetaGamma(yawAngle,pitchAngle,rollAngle)
    sim.setObjectOrientation(pointCloudHandle,floorhandle,{alphaAngle,betaAngle,gammaAngle})
    a=1
    end
end
Thanks

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: Converting real Pointcloud data to a shape using simSurfRec.reconstruct_scale_space

Post by fferri »

Depending on the size of the point cloud and the parameters you pass to the simSurfRec.reconstruct_scale_space function, it can take a long(!) time to execute.

dkchaisumdet
Posts: 12
Joined: 19 Mar 2023, 06:27

Re: Converting real Pointcloud data to a shape using simSurfRec.reconstruct_scale_space

Post by dkchaisumdet »

fferri wrote: 28 Mar 2023, 09:19 Depending on the size of the point cloud and the parameters you pass to the simSurfRec.reconstruct_scale_space function, it can take a long(!) time to execute.
Are you able to explain the parameters of the function as I dont quite understand them?

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: Converting real Pointcloud data to a shape using simSurfRec.reconstruct_scale_space

Post by fferri »

A short description of the parameters is found in the documentation:
simSurfRec.reconstruct_scale_space

Lua parameters:
pointCloudHandle (int): handle of the point cloud
iterations (int, default: 4): number of iterations
neighbors (int, default: 12): number of neighbors a point's neighborhood should contain on average
samples (int, default: 300): number of points sampled to estimate the neighborhood radius
squared_radius (float, default: -1.0): neighborhood squared radius used for principal component analysis. if this is positive, neighbors and samples will be ignored
For more details, the SurfRec plugin uses CGAL's:

Post Reply