/** * Count the amount of camera's each voxel in the space appears on, * if that amount equals the amount of cameras, add that voxel to the * visible_voxels vector */ void Reconstructor::update() { m_visible_voxels.clear(); std::vector<Voxel*> visible_voxels; int v; #pragma omp parallel for private(v) shared(visible_voxels) for (v = 0; v < (int) m_voxels_amount; ++v) { int camera_counter = 0; Voxel* voxel = m_voxels[v]; for (size_t c = 0; c < m_cameras.size(); ++c) { if (voxel->valid_camera_projection[c]) { const Point point = voxel->camera_projection[c]; //If there's a white pixel on the foreground image at the projection point, add the camera if (m_cameras[c]->getForegroundImage().at<uchar>(point) == 255) ++camera_counter; } } // If the voxel is present on all cameras if (camera_counter == m_cameras.size()) { int minLabel = 0; float minDist = norm(m_clusterCenters[0] - Point2f(voxel->x, voxel->y)); for (int i = 1; i < 4; ++i) { float dist = norm(m_clusterCenters[i] - Point2f(voxel->x, voxel->y)); if (dist < minDist) { minLabel = i; minDist = dist; } } voxel->label = minLabel; #pragma omp critical //push_back is critical if (minDist < 600 || !m_clustered) visible_voxels.push_back(voxel); } } m_visible_voxels.insert(m_visible_voxels.end(), visible_voxels.begin(), visible_voxels.end()); //Build surface int sizeh = m_height / m_step; int sizew = m_edge / m_step; PolyVox::SimpleVolume<uint8_t> volData(PolyVox::Region(PolyVox::Vector3DInt32(0, 0, 0), PolyVox::Vector3DInt32(sizew, sizew, sizeh))); for (size_t v = 0; v < visible_voxels.size(); v++) { volData.setVoxelAt(visible_voxels[v]->x / m_step + sizew / 2, visible_voxels[v]->y / m_step + sizew / 2, visible_voxels[v]->z / m_step + 1, 255); } PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor(&volData, volData.getEnclosingRegion(), &m_mesh); surfaceExtractor.execute(); }
void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh) { MarchingCubesSurfaceExtractor< SimpleVolume<MaterialDensityPair88> > surfaceExtractor(&volume, region, &resultMesh); surfaceExtractor.execute(); }
void extractCubicMesh(Volume& volume, const Region& region, Mesh& resultMesh) { CubicSurfaceExtractorWithNormals< SimpleVolume<MaterialDensityPair88> > surfaceExtractor(&volume, region, &resultMesh); surfaceExtractor.execute(); }