opensourceBIM / voxelization_toolkit

Voxelization Toolkit for (IFC) Building Models
MIT License
73 stars 14 forks source link

Is it possible to preserve the info to which ifc element a voxel belongs? #15

Closed dfkki123508 closed 1 year ago

dfkki123508 commented 1 year ago

My code in essence:

threaded_processor voxelization_processor(...);
voxelization_processor.process(geometries->begin(), geometries->end(), *method, output(MERGED()));
chunked_voxel_storage<voxel_uint32_t>* voxels = voxelization_processor.voxels();

// each voxel should be assigned to its original ifc-element

Thanks!

BR David

aothms commented 1 year ago

You can use VOLUME_PRODUCT_ID as *method to get volumetric element fills with the instance id in the model.

Alternatively, the approach I typically use is to revoxelize elements individually and check for overlap. That's essentially what we do here. https://github.com/opensourceBIM/voxelization_toolkit/blob/master/voxec.h#L1119

Performance for the 2nd option is obviously worse, but it's more flexible and deals with overlaps.

dfkki123508 commented 1 year ago

Thanks for the quick response! Finally I got it running. I had to switch from threaded_processor to the single threaded one and init a chunked_voxel_storage of type voxel_uint32_t before the calculation.

    // ...

    std::unique_ptr<fill_volume_t> method = std::make_unique<VOLUME_PRODUCT_ID>();
    chunked_voxel_storage<voxel_uint32_t> local_storage(x1, y1, z1, voxelsize, voxelCount_x, voxelCount_y, voxelCount_z,
                                                        chunksize);
    processor *voxelization_processor = new processor(&local_storage, [](int p) {});
    voxelization_processor->process(geometries->begin(), geometries->end(), *method, output(MERGED()));

    // Iterate a retrieve IfcElement Ids
   for (set_voxel_iterator it = local_storage.begin(); it != local_storage.end(); ++it) {
        // Value contains IfcElement Id
        uint32_t value;
        it.value(&value);
   }