/* see https://github.com/kduske/TrenchBroom/issues/1033 commented out because it breaks the release build process */ TEST(PlaneTest, planePointFinder) { Plane3 plane; const Vec3 points[3] = {Vec3(48, 16, 28), Vec3(16.0, 16.0, 27.9980487823486328125), Vec3(48, 18, 22)}; ASSERT_FALSE(points[1].isInteger()); ASSERT_TRUE(setPlanePoints(plane, points[0], points[1], points[2])); // Some verts that should lie (very close to) on the plane std::vector<Vec3> verts; verts.push_back(Vec3(48, 18, 22)); verts.push_back(Vec3(48, 16, 28)); verts.push_back(Vec3(16, 16, 28)); verts.push_back(Vec3(16, 18, 22)); for (size_t i=0; i<verts.size(); i++) { FloatType dist = Math::abs(plane.pointDistance(verts[i])); ASSERT_LT(dist, 0.01); } // Now find a similar plane with integer points Vec3 intpoints[3]; for (size_t i=0; i<3; i++) intpoints[i] = points[i]; TrenchBroom::Model::PlanePointFinder::findPoints(plane, intpoints, 3); ASSERT_TRUE(intpoints[0].isInteger()); ASSERT_TRUE(intpoints[1].isInteger()); ASSERT_TRUE(intpoints[2].isInteger()); Plane3 intplane; ASSERT_TRUE(setPlanePoints(intplane, intpoints[0], intpoints[1], intpoints[2])); // ASSERT_FALSE(intplane.equals(plane)); no longer fails // Check that the verts are still close to the new integer plane for (size_t i=0; i<verts.size(); i++) { FloatType dist = Math::abs(intplane.pointDistance(verts[i])); ASSERT_LT(dist, 0.01); } }
/****************************************************************************** * Performs the actual rejection of particles. ******************************************************************************/ size_t SliceModifier::filterParticles(boost::dynamic_bitset<>& mask, TimePoint time, TimeInterval& validityInterval) { // Get the required input properties. ParticlePropertyObject* const posProperty = expectStandardProperty(ParticleProperty::PositionProperty); ParticlePropertyObject* const selProperty = applyToSelection() ? inputStandardProperty(ParticleProperty::SelectionProperty) : nullptr; OVITO_ASSERT(posProperty->size() == mask.size()); OVITO_ASSERT(!selProperty || selProperty->size() == mask.size()); FloatType sliceWidth = 0; if(_widthCtrl) sliceWidth = _widthCtrl->getFloatValue(time, validityInterval); sliceWidth *= 0.5; Plane3 plane = slicingPlane(time, validityInterval); size_t na = 0; boost::dynamic_bitset<>::size_type i = 0; const Point3* p = posProperty->constDataPoint3(); const Point3* p_end = p + posProperty->size(); if(sliceWidth <= 0) { if(selProperty) { const int* s = selProperty->constDataInt(); for(; p != p_end; ++p, ++s, ++i) { if(*s && plane.pointDistance(*p) > 0) { mask.set(i); na++; } else mask.reset(i); } } else { for(; p != p_end; ++p, ++i) { if(plane.pointDistance(*p) > 0) { mask.set(i); na++; } else mask.reset(i); } } } else { bool invert = inverse(); if(selProperty) { const int* s = selProperty->constDataInt(); for(; p != p_end; ++p, ++s, ++i) { if(*s && invert == (plane.classifyPoint(*p, sliceWidth) == 0)) { mask.set(i); na++; } else mask.reset(i); } } else { for(; p != p_end; ++p, ++i) { if(invert == (plane.classifyPoint(*p, sliceWidth) == 0)) { mask.set(i); na++; } else mask.reset(i); } } } return na; }