// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2018 NVIDIA Corporation. All rights reserved. #include "RTdef.h" #if RT_COMPILE /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Contains code for box pruning. * \file IceBoxPruning.cpp * \author Pierre Terdiman * \date January, 29, 2000 */ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// You could use a complex sweep-and-prune as implemented in I-Collide. You could use a complex hashing scheme as implemented in V-Clip or recently in ODE it seems. You could use a "Recursive Dimensional Clustering" algorithm as implemented in GPG2. Or you could use this. Faster ? I don't know. Probably not. It would be a shame. But who knows ? Easier ? Definitely. Enjoy the sheer simplicity. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "IceBoxPruningBase.h" namespace nvidia { namespace fracture { namespace base { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Bipartite box pruning. Returns a list of overlapping pairs of boxes, each box of the pair belongs to a different set. * \param nb0 [in] number of boxes in the first set * \param bounds0 [in] list of boxes for the first set * \param nb1 [in] number of boxes in the second set * \param bounds1 [in] list of boxes for the second set * \param pairs [out] list of overlapping pairs * \param axes [in] projection order (0,2,1 is often best) * \return true if success. */ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool BoxPruning::bipartiteBoxPruning(const nvidia::Array &bounds0, const nvidia::Array &bounds1, nvidia::Array& pairs, const Axes& axes) { uint32_t nb0 = bounds0.size(); uint32_t nb1 = bounds1.size(); pairs.clear(); // Checkings if(nb0 == 0 || nb1 == 0) return false; // Catch axes uint32_t Axis0 = axes.Axis0; //uint32_t Axis1 = axes.Axis1; //uint32_t Axis2 = axes.Axis2; // Allocate some temporary data if (mMinPosBounds0.size() < nb0) mMinPosBounds0.resize(nb0); if (mMinPosBounds1.size() < nb1) mMinPosBounds1.resize(nb1); // 1) Build main lists using the primary axis for(uint32_t i=0;i &bounds, nvidia::Array &pairs, const Axes& axes) { uint32_t nb = bounds.size(); pairs.clear(); // Checkings if(!nb) return false; // Catch axes uint32_t Axis0 = axes.Axis0; //uint32_t Axis1 = axes.Axis1; //uint32_t Axis2 = axes.Axis2; // Allocate some temporary data if (mPosList.size() < nb) mPosList.resize(nb); // 1) Build main list using the primary axis for(uint32_t i=0;i &bounds0, const nvidia::Array &bounds1, nvidia::Array& pairs, const Axes& /*axes*/) { uint32_t nb0 = bounds0.size(); uint32_t nb1 = bounds1.size(); pairs.clear(); // Checkings if(!nb0 || !nb1) return false; // Brute-force nb0*nb1 overlap tests for(uint32_t i=0;i &bounds, nvidia::Array &pairs, const Axes& /*axes*/) { uint32_t nb = bounds.size(); pairs.clear(); // Checkings if(!nb) return false; // Brute-force n(n-1)/2 overlap tests for(uint32_t i=0;i