int manipulateVoxel::getNearestNeighborBox(int voxelIdx) { arrayInt vShareFace = s_voxelObj->m_boxShareFaceWithBox[voxelIdx]; int boxIdxNeareast = -1; float nearest = MAX; std::vector<voxelBox> *boxes = &s_voxelObj->m_boxes; for (auto nbIdx : vShareFace) { arrayInt listMeshIdxs = m_voxelState[nbIdx]; if (m_hashBoxIdx[nbIdx] != -1) { listMeshIdxs.push_back(m_hashBoxIdx[nbIdx]); } for (auto mIdx : listMeshIdxs) { // Compute distance Vec3f center = meshBox[mIdx]->centerPoint(); Vec3f size3F = meshBox[mIdx]->m_BoxSize3F*curScaleF; Vec3f ld3F = center - size3F / 2; Vec3f ru3F = center + size3F / 2; GeometricFunc geoFunc; float dis = geoFunc.disBtwPointAndBox(Box(ld3F, ru3F), boxes->at(voxelIdx).center); if (dis < nearest) { nearest = dis; boxIdxNeareast = mIdx; } } } return boxIdxNeareast; }
int manipulateVoxel::getNearestBox(int voxelIdx) { std::vector<voxelBox> *boxes = &s_voxelObj->m_boxes; float smallest = MAX; int idxSmallest; for (int i = 0; i < meshBox.size(); i++) { Vec3f center = meshBox[i]->centerPoint(); Vec3f size3F = meshBox[i]->m_BoxSize3F*curScaleF; Vec3f ld3F = center - size3F / 2; Vec3f ru3F = center + size3F / 2; GeometricFunc geoFunc; float dis = geoFunc.disBtwPointAndBox(Box(ld3F, ru3F), boxes->at(voxelIdx).center); if (dis < smallest) { smallest = dis; idxSmallest = i; } } return idxSmallest; }