void ConvexPolyhedron3<Real>::Create (const V3Array& rakPoint, const IArray& raiConnect) { assert( rakPoint.size() >= 4 && raiConnect.size() >= 4 ); int iVQuantity = (int)rakPoint.size(); int iTQuantity = (int)raiConnect.size()/3; int iEQuantity = iVQuantity + iTQuantity - 2; Reset(iVQuantity,iEQuantity,iTQuantity); m_akPoint = rakPoint; // Copy polyhedron points into vertex array. Compute centroid for use in // making sure the triangles are counterclockwise oriented when viewed // from the outside. ComputeCentroid(); // get polyhedron edge and triangle information for (int iT = 0, iIndex = 0; iT < iTQuantity; iT++) { // get vertex indices for triangle int iV0 = raiConnect[iIndex++]; int iV1 = raiConnect[iIndex++]; int iV2 = raiConnect[iIndex++]; // make sure triangle is counterclockwise Vector3<Real>& rkV0 = m_akPoint[iV0]; Vector3<Real>& rkV1 = m_akPoint[iV1]; Vector3<Real>& rkV2 = m_akPoint[iV2]; Vector3<Real> kDiff = m_kCentroid - rkV0; Vector3<Real> kE1 = rkV1 - rkV0; Vector3<Real> kE2 = rkV2 - rkV0; Vector3<Real> kNormal = kE1.Cross(kE2); Real fLength = kNormal.Length(); if ( fLength > Math<Real>::EPSILON ) { kNormal /= fLength; } else { kNormal = kDiff; kNormal.Normalize(); } Real fDistance = kNormal.Dot(kDiff); if ( fDistance < (Real)0.0 ) { // triangle is counterclockwise Insert(iV0,iV1,iV2); } else { // triangle is clockwise Insert(iV0,iV2,iV1); } } UpdatePlanes(); }
inline void DynSetArray(ok_msg::DynamicProto &dyn, const IArray<std::string> &arr) { dyn.mutable_vsstr()->Reserve(arr.Size()); for (const auto &s : arr) { *dyn.mutable_vsstr()->Add() = s; } }
void ConvexPolyhedron3<Real>::Create (const V3Array& rakPoint, const IArray& raiConnect, const PArray& rakPlane) { assert( rakPoint.size() >= 4 && raiConnect.size() >= 4 ); int iVQuantity = (int)rakPoint.size(); int iTQuantity = (int)raiConnect.size()/3; int iEQuantity = iVQuantity + iTQuantity - 2; Reset(iVQuantity,iEQuantity,iTQuantity); m_akPoint = rakPoint; m_akPlane = rakPlane; // Copy polyhedron points into vertex array. Compute centroid for use in // making sure the triangles are counterclockwise oriented when viewed // from the outside. ComputeCentroid(); // get polyhedron edge and triangle information for (int iT = 0, iIndex = 0; iT < iTQuantity; iT++) { // get vertex indices for triangle int iV0 = raiConnect[iIndex++]; int iV1 = raiConnect[iIndex++]; int iV2 = raiConnect[iIndex++]; Real fDistance = m_akPlane[iT].DistanceTo(m_kCentroid); if ( fDistance > (Real)0.0 ) { // triangle is counterclockwise Insert(iV0,iV1,iV2); } else { // triangle is clockwise Insert(iV0,iV2,iV1); } } }
inline char FindChar(const IArray &v) const { char c = 0, max; int vs = v.size(), tr = vs / 2 + 2; for(int i = 0; i < vs; ++i) { if(abs(max = v[i]) >= tr) { c = i; if(max < 0) { c |= 8; } break; } } return c; }
inline short FillChar(const IArray &v) const { short o = 0, p = 1; int vs = v.size(); for(int i = 0; i < vs; ++i) { if(v[i] > 0) { o |= p; } p *= 2; } #ifdef DEBUG cout << "Coded array: "; Print(o, 8); #endif return o; }
void dumpArray(IArray<MyNode>& a) { if (!a.isEmpty()) { // Dump some details about the array cout << "Contents of array (" << a.numberOfItems() << " elements," << a.size() << " size, " << a.delta() << " delta):"; cout << endl << " "; for (int i = 0; i < a.numberOfItems(); i++) cout << *a[i] << " "; if (a.isFull()) cout << "Array is full!" << endl; } else cout << "Empty array (" << a.numberOfItems() << ")"; cout << endl << endl; }
TEST(ArrayTest, testAlgorithm) { // create and initialize array const int SIZE = 10; typedef Poco::Array<int,SIZE> IArray; IArray a = { { 1, 2, 3, 4, 5 } }; IArray b(a); // modify elements directly for (unsigned i=0; i<b.size(); ++i) { ++b[i]; } // try iterators for (IArray::iterator pos =b.begin(); pos<b.end(); ++pos) { --(*pos); } for (unsigned i=0; i<a.size(); ++i) { EXPECT_TRUE(a[i] == b[i]); } // change order using an STL algorithm std::reverse(a.begin(),a.end()); for (unsigned i=0; i<a.size(); ++i) { EXPECT_TRUE(a[SIZE-i-1] == b[i]); } std::reverse(a.begin(),a.end()); // negate elements using STL framework std::transform( a.begin(),a.end(), // source a.begin(), // destination std::negate<int>()); // operation for (unsigned i=0; i<a.size(); ++i) { EXPECT_TRUE(a[i] == -b[i]); } }
inline void PrintArray(const IArray &arr) { for(int i = 0; i < arr.size(); ++i) { cout << '\t' << arr[i]; } cout << endl; }