tools::PointsToVolume

189 views
Skip to first unread message

uhlong

unread,
Dec 7, 2020, 2:35:34 AM12/7/20
to OpenVDB Forum
Hi guys,

    I am looking for a tool, which is shown in "TopologyToLevelSet.h", to convert points to volume, but I haven't found it. Does anyone know where the API is or any suggestion to realize such function. Thank you in advance.
    Regards.


Pavel Geraskin

unread,
Dec 7, 2020, 4:20:40 AM12/7/20
to OpenVDB Forum
I searched this example on the internet  too   but I failed.  OpenVDB is too hardcore for newbies like me.   May I suggest  openvdb::tools::ParticlesToLevelSet ? 
I found these 2 examples :


All you need is just points positions. My simple code was like this:

[code]

struct MyParticle
{
    openvdb::Vec3R p, v;
    openvdb::Real  r;
};


class MyParticleList {

public:
    openvdb::Real           mRadiusScale;
    openvdb::Real           mVelocityScale;
    std::vector<MyParticle> mParticleList;

  typedef openvdb::Vec3R  PosType;

    MyParticleList(openvdb::Real rScale=1, openvdb::Real vScale=1)
            : mRadiusScale(rScale), mVelocityScale(vScale) {}

    void add(const openvdb::Vec3R &p, const openvdb::Real &r,
             const openvdb::Vec3R &v=openvdb::Vec3R(0,0,0))
    {
        MyParticle pa;
        pa.p = p;
        pa.r = r;
        pa.v = v;
        mParticleList.push_back(pa);
    }

  // Return the total number of particles in list.
  // Always required!
  size_t size() const { return mParticleList.size(); };
  // Get the world space position of the nth particle.
  // Required by ParticledToLevelSet::rasterizeSphere(*this,radius).
  void getPos(size_t n, openvdb::Vec3R& pos) const { pos = mParticleList[n].p; };
  // Get the world space position and radius of the nth particle.
  // Required by ParticledToLevelSet::rasterizeSphere(*this).
  void getPosRad(size_t n,  openvdb::Vec3R& pos, openvdb::Real& rad) const {
      pos = mParticleList[n].p;
      rad = mRadiusScale*mParticleList[n].r;
  };
  // Get the world space position, radius and velocity of the nth particle.
  // Required by ParticledToLevelSet::rasterizeSphere(*this,radius).
  void getPosRadVel(size_t n, openvdb::Vec3R& pos, openvdb::Real& rad, openvdb::Vec3R& vel) const {
      pos = mParticleList[n].p;
      rad = mRadiusScale*mParticleList[n].r;
      vel = mVelocityScale*mParticleList[n].v;
  };
  // Get the attribute of the nth particle. AttributeType is user-defined!
  // Only required if attribute transfer is enabled in ParticlesToLevelSet.
  void getAtt(size_t n, openvdb::Index32& att) const { att = openvdb::Index32(n); };
};



int main(int argc, char *argv[])
{

    openvdb::initialize();

....... SOME CODE ......


// VDB transform openvdb::math::Transform::Ptr xform = openvdb::math::Transform::createLinearTransform(0.01);

    MyParticleList pa(1,1);
    for (openvdb::Vec3s pos : vertices) {
        pa.add(openvdb::Vec3R( pos[0],  pos[1],  pos[2]), 0.1, openvdb::Vec3R( 0, 0, 0));
    }

    openvdb::FloatGrid::Ptr densityGrid = openvdb::createLevelSet<openvdb::FloatGrid>(vdb_voxel_size, 3);
    std::cout << "set density grid";
    densityGrid->setGridClass(openvdb::GRID_LEVEL_SET);
    densityGrid->setTransform(xform);
    densityGrid->setName("density");

    openvdb::tools::ParticlesToLevelSet<openvdb::FloatGrid> raster(*densityGrid);

    raster.rasterizeSpheres(pa);
    raster.finalize(true);

    //openvdb::FloatGrid::Ptr grid = densityGrid;  // TEST!!!!!!


}

[/code]  


понедельник, 7 декабря 2020 г. в 10:35:34 UTC+3, uhlong:

uhlong

unread,
Dec 9, 2020, 7:21:39 AM12/9/20
to OpenVDB Forum
Hi Pavel, thanks for sharing. 
Reply all
Reply to author
Forward
0 new messages