void sliceTriangle(const point_type& A, const point_type& B, const point_type& C, const vec_type& N, SegmentStack& _segmentStack) const { using geometry::prim::Segment; typedef geometry::comp::Compound<Segment> SegmentPlane; SegmentStack::iterator _Ait = _segmentStack.get(A.z()), _Bit = _segmentStack.get(B.z()), _Cit = _segmentStack.get(C.z()), it; Point2f _Aproj = A.project(geometry::base::Z); vec_type b = B - A; scalar_type _invBz = 1.0 / b.z(); vec_type c = C - A; scalar_type _invCz = 1.0 / c.z(); vec_type d = C - B; scalar_type _invDz = 1.0 / d.z(); scalar_type _ratioR, _ratioS, _pos; Vec2f r,s; bool _passedB = false; for (it = _Ait ; it != _Cit && it != _segmentStack.end(); ++it) { SegmentPlane* _segmentPlane = &(it->second); if (it == _Bit) _passedB = true; if (!_passedB) { _pos = it->first - A.z(); _ratioR = _pos * _invCz; _ratioS = _pos * _invBz; s(b.x()*_ratioS,b.y()*_ratioS); } else { _pos = it->first; _ratioR = (_pos - A.z()) * _invCz; _ratioS = (_pos - B.z()) * _invDz; s(b.x() + d.x()*_ratioS,b.y() + d.y()*_ratioS); } r(c.x()*_ratioR,c.y()*_ratioR); Point2f _p0 = _Aproj+r, _p1 = _Aproj+s; Vec2f _normal = _p1 - _p0; // Normal of segment points if (_normal.sqrLength() == 0.0) continue; _normal(-_normal[1],_normal[0]); /// Swap point to assure that points are in proper order to be able to make lineSegments if (dot(Vec2f(N.x(),N.y()),_normal) > 0.0) std::swap(_p0,_p1); _segmentPlane->add(Segment(_p0,_p1)); } }
bool insert( Entry& e , vec_type& v ) { if ( entries.find( e.ID() ) != entries.end() ) { return false; } for ( typename vec_type::size_type ii=0; ii<v.size(); ++ii ) { table[ii].insert( EDE( e , v[ii]) ); } entries.insert( e.ID() ); return true; }
UnitTestSetup() { rtol = 1e-4; atol = 1e-5; crtol = 1e-12; catol = 1e-12; a = 3.1; sz = 8; // Create vector x.reset(sz); y.reset(sz); cx.reset(1); cx = a; for (int i=0; i<sz; i++) { x.fastAccessCoeff(i) = 0.1*i; y.fastAccessCoeff(i) = 0.25*i; } }
// ACCESSORS bool closeToEntries( const vec_type& v , precision cutoff ) { // Go through each dimension and look for the one that // satisfies the cutoff for ( typename vec_type::size_type ii=0; ii<v.size(); ++ii ) { DimensionEntries& dentries = table[ii]; typename DimensionEntries::iterator theend = dentries.end(); EDE lower; lower.value = v[ii] - cutoff; typename DimensionEntries::iterator begin = dentries.lower_bound( lower ); EDE upper; upper.value = v[ii] + cutoff; typename DimensionEntries::iterator end = dentries.upper_bound( upper ); if ( begin != theend && end != theend ) { for(; begin!=end; ++begin) { precision d = euclideanDistance( begin->entry.location().begin() , begin->entry.location().end() , v.begin() ); if ( d < cutoff + begin->entry.radius() ) { return true; } } } } return false; }
/** * \brief Computes XtX += other.XtX and Xy += other.Xy updating this * tuples value */ gather_type& operator+=(const gather_type& other) { if(other.Xy.size() == 0) { ASSERT_EQ(other.XtX.rows(), 0); ASSERT_EQ(other.XtX.cols(), 0); } else { if(Xy.size() == 0) { ASSERT_EQ(XtX.rows(), 0); ASSERT_EQ(XtX.cols(), 0); XtX = other.XtX; Xy = other.Xy; } else { XtX.triangularView<Eigen::Upper>() += other.XtX; Xy += other.Xy; } } return *this; } // end of operator+=
bool collisionCheck( const Particle_& vp ) const { return ( x.distance(vp.x) <= (radius()+vp.radius()) ); }
prec_ separation( const Particle_& p ) const { return x.distance(p.x); }
prec_ separation2( const Particle_& p ) const { return x.distanceSquared(p.x); }
void X( InputIterator begin , InputIterator end ) { std::copy( begin , end , x.begin()); }
libgm::real_pair<> value_slope(const vec_type& x, const vec_type& dir) override { vec_type diff = x - ctr; double value = 0.5 * diff.dot(cov * diff); double slope = dir.dot(cov * diff); return { value, slope }; }
~writeback_array() { for(std::size_t i = 0; i < vector->size(); i++) { (*vector)[i] = base_type::operator[](i); } }
/** \brief Randomizes the latent factor */ void randomize() { factor.resize(NLATENT); factor.setRandom(); }
/** * \brief This constructor computes XtX and Xy and stores the result * in XtX and Xy */ gather_type(const vec_type& X, const double y) : XtX(X.size(), X.size()), Xy(X.size()) { XtX.triangularView<Eigen::Upper>() = X * X.transpose(); Xy = X * y; } // end of constructor for gather type
foreach(vec_type& factor, movie_factors) { factor.resize(D); // Randomize the factor for(size_t d = 0; d < D; ++d) factor(d) = gen.gaussian(0, stdev); }