std::vector<AlprResult> AlprImpl::recognize(cv::Mat img) { timespec startTime; getTime(&startTime); // Find all the candidate regions vector<PlateRegion> plateRegions = plateDetector->detect(img); // Get the number of threads specified and make sure the value is sane (cannot be greater than CPU cores or less than 1) int numThreads = config->multithreading_cores; if (numThreads > tthread::thread::hardware_concurrency()) numThreads = tthread::thread::hardware_concurrency(); if (numThreads <= 0) numThreads = 1; PlateDispatcher dispatcher(plateRegions, &img, config, stateIdentifier, ocr, topN, detectRegion, defaultRegion); // Spawn n threads to process all of the candidate regions and recognize list<tthread::thread*> threads; for (int i = 0; i < numThreads; i++) { tthread::thread * t = new tthread::thread(plateAnalysisThread, (void *) &dispatcher); threads.push_back(t); } // Wait for all threads to finish for(list<tthread::thread *>::iterator i = threads.begin(); i != threads.end(); ++ i) { tthread::thread* t = *i; t->join(); delete t; } if (config->debugTiming) { timespec endTime; getTime(&endTime); cout << "Total Time to process image: " << diffclock(startTime, endTime) << "ms." << endl; } if (config->debugGeneral && config->debugShowImages) { for (int i = 0; i < plateRegions.size(); i++) { rectangle(img, plateRegions[i].rect, Scalar(0, 0, 255), 2); } for (int i = 0; i < dispatcher.getRecognitionResults().size(); i++) { for (int z = 0; z < 4; z++) { AlprCoordinate* coords = dispatcher.getRecognitionResults()[i].plate_points; Point p1(coords[z].x, coords[z].y); Point p2(coords[(z + 1) % 4].x, coords[(z + 1) % 4].y); line(img, p1, p2, Scalar(255,0,255), 2); } } displayImage(config, "Main Image", img); cv::waitKey(1); } if (config->debugPauseOnFrame) { // Pause indefinitely until they press a key while ((char) cv::waitKey(50) == -1) {} } return dispatcher.getRecognitionResults(); }
/** * This test checks various generic API methods in DecimalFormat to achieve 100% * API coverage. */ void IntlTestDecimalFormatAPI::testAPI(/*char *par*/) { UErrorCode status = U_ZERO_ERROR; // ======= Test constructors logln((UnicodeString)"Testing DecimalFormat constructors"); DecimalFormat def(status); if(U_FAILURE(status)) { errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status)); return; } status = U_ZERO_ERROR; const UnicodeString pattern("#,##0.# FF"); DecimalFormat pat(pattern, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern)"); return; } status = U_ZERO_ERROR; DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::getFrench(), status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (French)"); return; } status = U_ZERO_ERROR; DecimalFormat cust1(pattern, symbols, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern, symbols*)"); } status = U_ZERO_ERROR; DecimalFormat cust2(pattern, *symbols, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern, symbols)"); } DecimalFormat copy(pat); // ======= Test clone(), assignment, and equality logln((UnicodeString)"Testing clone(), assignment and equality operators"); if( ! (copy == pat) || copy != pat) { errln((UnicodeString)"ERROR: Copy constructor or == failed"); } copy = cust1; if(copy != cust1) { errln((UnicodeString)"ERROR: Assignment (or !=) failed"); } Format *clone = def.clone(); if( ! (*clone == def) ) { errln((UnicodeString)"ERROR: Clone() failed"); } delete clone; // ======= Test various format() methods logln((UnicodeString)"Testing various format() methods"); double d = -10456.0037; int32_t l = 100000000; Formattable fD(d); Formattable fL(l); UnicodeString res1, res2, res3, res4; FieldPosition pos1(0), pos2(0), pos3(0), pos4(0); res1 = def.format(d, res1, pos1); logln( (UnicodeString) "" + (int32_t) d + " formatted to " + res1); res2 = pat.format(l, res2, pos2); logln((UnicodeString) "" + (int32_t) l + " formatted to " + res2); status = U_ZERO_ERROR; res3 = cust1.format(fD, res3, pos3, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: format(Formattable [double]) failed"); } logln((UnicodeString) "" + (int32_t) fD.getDouble() + " formatted to " + res3); status = U_ZERO_ERROR; res4 = cust2.format(fL, res4, pos4, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: format(Formattable [long]) failed"); } logln((UnicodeString) "" + fL.getLong() + " formatted to " + res4); // ======= Test parse() logln((UnicodeString)"Testing parse()"); UnicodeString text("-10,456.0037"); Formattable result1, result2; ParsePosition pos(0); UnicodeString patt("#,##0.#"); status = U_ZERO_ERROR; pat.applyPattern(patt, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: applyPattern() failed"); } pat.parse(text, result1, pos); if(result1.getType() != Formattable::kDouble && result1.getDouble() != d) { errln((UnicodeString)"ERROR: Roundtrip failed (via parse()) for " + text); } logln(text + " parsed into " + (int32_t) result1.getDouble()); status = U_ZERO_ERROR; pat.parse(text, result2, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: parse() failed"); } if(result2.getType() != Formattable::kDouble && result2.getDouble() != d) { errln((UnicodeString)"ERROR: Roundtrip failed (via parse()) for " + text); } logln(text + " parsed into " + (int32_t) result2.getDouble()); // ======= Test getters and setters logln((UnicodeString)"Testing getters and setters"); const DecimalFormatSymbols *syms = pat.getDecimalFormatSymbols(); DecimalFormatSymbols *newSyms = new DecimalFormatSymbols(*syms); def.setDecimalFormatSymbols(*newSyms); def.adoptDecimalFormatSymbols(newSyms); // don't use newSyms after this if( *(pat.getDecimalFormatSymbols()) != *(def.getDecimalFormatSymbols())) { errln((UnicodeString)"ERROR: adopt or set DecimalFormatSymbols() failed"); } UnicodeString posPrefix; pat.setPositivePrefix("+"); posPrefix = pat.getPositivePrefix(posPrefix); logln((UnicodeString)"Positive prefix (should be +): " + posPrefix); if(posPrefix != "+") { errln((UnicodeString)"ERROR: setPositivePrefix() failed"); } UnicodeString negPrefix; pat.setNegativePrefix("-"); negPrefix = pat.getNegativePrefix(negPrefix); logln((UnicodeString)"Negative prefix (should be -): " + negPrefix); if(negPrefix != "-") { errln((UnicodeString)"ERROR: setNegativePrefix() failed"); } UnicodeString posSuffix; pat.setPositiveSuffix("_"); posSuffix = pat.getPositiveSuffix(posSuffix); logln((UnicodeString)"Positive suffix (should be _): " + posSuffix); if(posSuffix != "_") { errln((UnicodeString)"ERROR: setPositiveSuffix() failed"); } UnicodeString negSuffix; pat.setNegativeSuffix("~"); negSuffix = pat.getNegativeSuffix(negSuffix); logln((UnicodeString)"Negative suffix (should be ~): " + negSuffix); if(negSuffix != "~") { errln((UnicodeString)"ERROR: setNegativeSuffix() failed"); } int32_t multiplier = 0; pat.setMultiplier(8); multiplier = pat.getMultiplier(); logln((UnicodeString)"Multiplier (should be 8): " + multiplier); if(multiplier != 8) { errln((UnicodeString)"ERROR: setMultiplier() failed"); } int32_t groupingSize = 0; pat.setGroupingSize(2); groupingSize = pat.getGroupingSize(); logln((UnicodeString)"Grouping size (should be 2): " + (int32_t) groupingSize); if(groupingSize != 2) { errln((UnicodeString)"ERROR: setGroupingSize() failed"); } pat.setDecimalSeparatorAlwaysShown(TRUE); UBool tf = pat.isDecimalSeparatorAlwaysShown(); logln((UnicodeString)"DecimalSeparatorIsAlwaysShown (should be TRUE) is " + (UnicodeString) (tf ? "TRUE" : "FALSE")); if(tf != TRUE) { errln((UnicodeString)"ERROR: setDecimalSeparatorAlwaysShown() failed"); } // Added by Ken Liu testing set/isExponentSignAlwaysShown pat.setExponentSignAlwaysShown(TRUE); UBool esas = pat.isExponentSignAlwaysShown(); logln((UnicodeString)"ExponentSignAlwaysShown (should be TRUE) is " + (UnicodeString) (esas ? "TRUE" : "FALSE")); if(esas != TRUE) { errln((UnicodeString)"ERROR: ExponentSignAlwaysShown() failed"); } // Added by Ken Liu testing set/isScientificNotation pat.setScientificNotation(TRUE); UBool sn = pat.isScientificNotation(); logln((UnicodeString)"isScientificNotation (should be TRUE) is " + (UnicodeString) (sn ? "TRUE" : "FALSE")); if(sn != TRUE) { errln((UnicodeString)"ERROR: setScientificNotation() failed"); } // Added by Ken Liu testing set/getMinimumExponentDigits int8_t MinimumExponentDigits = 0; pat.setMinimumExponentDigits(2); MinimumExponentDigits = pat.getMinimumExponentDigits(); logln((UnicodeString)"MinimumExponentDigits (should be 2) is " + (int8_t) MinimumExponentDigits); if(MinimumExponentDigits != 2) { errln((UnicodeString)"ERROR: setMinimumExponentDigits() failed"); } // Added by Ken Liu testing set/getRoundingIncrement double RoundingIncrement = 0.0; pat.setRoundingIncrement(2.0); RoundingIncrement = pat.getRoundingIncrement(); logln((UnicodeString)"RoundingIncrement (should be 2.0) is " + (double) RoundingIncrement); if(RoundingIncrement != 2.0) { errln((UnicodeString)"ERROR: setRoundingIncrement() failed"); } //end of Ken's Adding UnicodeString funkyPat; funkyPat = pat.toPattern(funkyPat); logln((UnicodeString)"Pattern is " + funkyPat); UnicodeString locPat; locPat = pat.toLocalizedPattern(locPat); logln((UnicodeString)"Localized pattern is " + locPat); // ======= Test applyPattern() logln((UnicodeString)"Testing applyPattern()"); UnicodeString p1("#,##0.0#;(#,##0.0#)"); logln((UnicodeString)"Applying pattern " + p1); status = U_ZERO_ERROR; pat.applyPattern(p1, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: applyPattern() failed with " + (int32_t) status); } UnicodeString s2; s2 = pat.toPattern(s2); logln((UnicodeString)"Extracted pattern is " + s2); if(s2 != p1) { errln((UnicodeString)"ERROR: toPattern() result did not match pattern applied"); } if(pat.getSecondaryGroupingSize() != 0) { errln("FAIL: Secondary Grouping Size should be 0, not %d\n", pat.getSecondaryGroupingSize()); } if(pat.getGroupingSize() != 3) { errln("FAIL: Primary Grouping Size should be 3, not %d\n", pat.getGroupingSize()); } UnicodeString p2("#,##,##0.0# FF;(#,##,##0.0# FF)"); logln((UnicodeString)"Applying pattern " + p2); status = U_ZERO_ERROR; pat.applyLocalizedPattern(p2, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: applyPattern() failed with " + (int32_t) status); } UnicodeString s3; s3 = pat.toLocalizedPattern(s3); logln((UnicodeString)"Extracted pattern is " + s3); if(s3 != p2) { errln((UnicodeString)"ERROR: toLocalizedPattern() result did not match pattern applied"); } status = U_ZERO_ERROR; UParseError pe; pat.applyLocalizedPattern(p2, pe, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: applyPattern((with ParseError)) failed with " + (int32_t) status); } UnicodeString s4; s4 = pat.toLocalizedPattern(s3); logln((UnicodeString)"Extracted pattern is " + s4); if(s4 != p2) { errln((UnicodeString)"ERROR: toLocalizedPattern(with ParseErr) result did not match pattern applied"); } if(pat.getSecondaryGroupingSize() != 2) { errln("FAIL: Secondary Grouping Size should be 2, not %d\n", pat.getSecondaryGroupingSize()); } if(pat.getGroupingSize() != 3) { errln("FAIL: Primary Grouping Size should be 3, not %d\n", pat.getGroupingSize()); } // ======= Test getStaticClassID() logln((UnicodeString)"Testing getStaticClassID()"); status = U_ZERO_ERROR; NumberFormat *test = new DecimalFormat(status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Couldn't create a DecimalFormat"); } if(test->getDynamicClassID() != DecimalFormat::getStaticClassID()) { errln((UnicodeString)"ERROR: getDynamicClassID() didn't return the expected value"); } delete test; }
//------------------------------------------------------------------------------ bool Rect::lineIntersect (const Point& _p1, const Point& _p2) const { Point p1 (_p1); Point p2 (_p2); return boundLine (p1,p2); }
TEST(VectorTest, Subtraction) { Vector_i p1(1, 2); Vector_i p2(4, 4); EXPECT_EQ(Vector_i(-3, -2), p1 - p2); }
void Sphere::paint(void) { float thetaRange = 2*PI; float phiRange = PI; float thetaStart = 0.0; float phiStart = -PI/2.0; float thetaDelta = thetaRange / mThetaSteps; float phiDelta = phiRange / mPhiSteps; mMaterial->glSetMaterial(); int i; int j; glBegin(GL_QUADS); for (i = 0; i < mPhiSteps; i++) for (j = 0; j < mThetaSteps; j++) { // compute appropriate coordinates & normals float curPhi = i * phiDelta; float curTheta = j * thetaDelta; float nextPhi = (i + 1) * phiDelta; float nextTheta = (j + 1) * thetaDelta; Vec3f p0(mRadius * sin(curTheta) * cos(curPhi), mRadius * sin(curTheta) * sin(curPhi), mRadius * cos(curTheta)); p0 += mCenterPoint; Vec3f n0 = p0 - mCenterPoint; n0.Normalize(); Vec3f p1(mRadius * sin(curTheta) * cos(nextPhi), mRadius * sin(curTheta) * sin(nextPhi), mRadius * cos(curTheta)); p1 += mCenterPoint; Vec3f n1 = p1 - mCenterPoint; n1.Normalize(); Vec3f p2(mRadius * sin(nextTheta) * cos(curPhi), mRadius * sin(nextTheta) * sin(curPhi), mRadius * cos(nextTheta)); p2 += mCenterPoint; Vec3f n2 = p2 - mCenterPoint; n2.Normalize(); Vec3f p3(mRadius * sin(nextTheta) * cos(nextPhi), mRadius * sin(nextTheta) * sin(nextPhi), mRadius * cos(nextTheta)); p3 += mCenterPoint; Vec3f n3 = p3 - mCenterPoint; n3.Normalize(); //Actually, what I have done is just the Gourand shading, four normals for //the polygon glNormal3f(n0.x(), n0.y(), n0.z()); glVertex3f(p0.x(), p0.y(), p0.z()); glNormal3f(n1.x(), n1.y(), n1.z()); glVertex3f(p1.x(), p1.y(), p1.z()); glNormal3f(n3.x(), n3.y(), n3.z()); glVertex3f(p3.x(), p3.y(), p3.z()); glNormal3f(n2.x(), n2.y(), n2.z()); glVertex3f(p2.x(), p2.y(), p2.z()); } glEnd(); }
void Import::SetSmoothingGroups (Mesh& maxMesh) { struct FaceAdjecency { int m_count; int m_adjacentFace[9]; }; int edgeCount; int faceIndexPool[1024 * 8]; int triangleCount = maxMesh.getNumFaces(); maxMesh.InvalidateTopologyCache(); maxMesh.InvalidateGeomCache(); Edge* const edgeList = maxMesh.MakeEdgeList(&edgeCount); FaceAdjecency* const adjacency = new FaceAdjecency [triangleCount]; dVector* const faceNormals = new dVector[triangleCount]; memset (adjacency, 0, triangleCount * sizeof (FaceAdjecency)); for (int i = 0; i < edgeCount; i ++) { int face0 = edgeList[i].f[0]; int face1 = edgeList[i].f[1]; if ((face0 != -1) && (face1 != -1)) { _ASSERTE (face0 < triangleCount); _ASSERTE (face1 < triangleCount); adjacency[face0].m_adjacentFace[adjacency[face0].m_count] = face1; adjacency[face1].m_adjacentFace[adjacency[face1].m_count] = face0; adjacency[face0].m_count += 1; adjacency[face1].m_count += 1; _ASSERTE (adjacency[face0].m_count <= sizeof (adjacency[0].m_adjacentFace) / sizeof (adjacency[0].m_adjacentFace[0])); _ASSERTE (adjacency[face1].m_count <= sizeof (adjacency[0].m_adjacentFace) / sizeof (adjacency[0].m_adjacentFace[0])); } } for (int i = 0; i < triangleCount; i ++) { Face* face; face = &maxMesh.faces[i]; dVector p0 (maxMesh.verts[face->v[0]].x, maxMesh.verts[face->v[0]].y, maxMesh.verts[face->v[0]].z, 0.0f); dVector p1 (maxMesh.verts[face->v[1]].x, maxMesh.verts[face->v[1]].y, maxMesh.verts[face->v[1]].z, 0.0f); dVector p2 (maxMesh.verts[face->v[2]].x, maxMesh.verts[face->v[2]].y, maxMesh.verts[face->v[2]].z, 0.0f); dVector normal ((p1 - p0) * (p2 - p0)); faceNormals[i] = normal.Scale (1.0f / dSqrt (normal % normal)); } unsigned group = 1; for (int i = 0; i < triangleCount; i ++) { Face* const face = &maxMesh.faces[i]; if (!face->smGroup) { face->setSmGroup(group); faceIndexPool[0] = i; int stack = 1; while (stack) { stack --; int index = faceIndexPool[stack]; dVector& n0 = faceNormals[index]; for (int j = 0; j < adjacency[index].m_count; j ++) { int adjacentFaceIndex = adjacency[index].m_adjacentFace[j]; Face* const adjacentFace = &maxMesh.faces[adjacentFaceIndex]; if (!adjacentFace->smGroup) { dVector& n1 = faceNormals[adjacentFaceIndex]; float dot = n0 % n1; if (dot > 0.86f) { if (stack < sizeof (faceIndexPool) / sizeof (faceIndexPool[0])) { adjacentFace->setSmGroup(group); faceIndexPool[stack] = adjacentFaceIndex; stack ++; } } } } } group = group * 2; if (!group) { group = 1; } } } delete[] faceNormals; delete[] adjacency; maxMesh.buildNormals(); }
void run () { beast::Journal const j; beast::manual_clock <std::chrono::seconds> clock; clock.set (0); typedef int Key; typedef std::string Value; typedef TaggedCache <Key, Value> Cache; Cache c ("test", 1, 1, clock, j); // Insert an item, retrieve it, and age it so it gets purged. { expect (c.getCacheSize() == 0); expect (c.getTrackSize() == 0); expect (! c.insert (1, "one")); expect (c.getCacheSize() == 1); expect (c.getTrackSize() == 1); { std::string s; expect (c.retrieve (1, s)); expect (s == "one"); } ++clock; c.sweep (); expect (c.getCacheSize () == 0); expect (c.getTrackSize () == 0); } // Insert an item, maintain a strong pointer, age it, and // verify that the entry still exists. { expect (! c.insert (2, "two")); expect (c.getCacheSize() == 1); expect (c.getTrackSize() == 1); { Cache::mapped_ptr p (c.fetch (2)); expect (p != nullptr); ++clock; c.sweep (); expect (c.getCacheSize() == 0); expect (c.getTrackSize() == 1); } // Make sure its gone now that our reference is gone ++clock; c.sweep (); expect (c.getCacheSize() == 0); expect (c.getTrackSize() == 0); } // Insert the same key/value pair and make sure we get the same result { expect (! c.insert (3, "three")); { Cache::mapped_ptr const p1 (c.fetch (3)); Cache::mapped_ptr p2 (std::make_shared <Value> ("three")); c.canonicalize (3, p2); expect (p1.get() == p2.get()); } ++clock; c.sweep (); expect (c.getCacheSize() == 0); expect (c.getTrackSize() == 0); } // Put an object in but keep a strong pointer to it, advance the clock a lot, // then canonicalize a new object with the same key, make sure you get the // original object. { // Put an object in expect (! c.insert (4, "four")); expect (c.getCacheSize() == 1); expect (c.getTrackSize() == 1); { // Keep a strong pointer to it Cache::mapped_ptr p1 (c.fetch (4)); expect (p1 != nullptr); expect (c.getCacheSize() == 1); expect (c.getTrackSize() == 1); // Advance the clock a lot ++clock; c.sweep (); expect (c.getCacheSize() == 0); expect (c.getTrackSize() == 1); // Canonicalize a new object with the same key Cache::mapped_ptr p2 (std::make_shared <std::string> ("four")); expect (c.canonicalize (4, p2, false)); expect (c.getCacheSize() == 1); expect (c.getTrackSize() == 1); // Make sure we get the original object expect (p1.get() == p2.get()); } ++clock; c.sweep (); expect (c.getCacheSize() == 0); expect (c.getTrackSize() == 0); } }
bool EntityWithMetadataFS::hasMetadata() const { bfs::path p1(location()), p2("metadata"); return bfs::exists(p1/p2); }
int main() { { printf("Should create one |TestObject|:\n"); nsAutoPtr<TestObject> pobj( new TestObject() ); printf("Should destroy one |TestObject|:\n"); } { printf("Should create one |TestObject|:\n"); nsAutoPtr<TestObject> pobj( new TestObject() ); printf("Should create one |TestObject| and then destroy one:\n"); pobj = new TestObject(); printf("Should destroy one |TestObject|:\n"); } { printf("Should create 3 |TestObject|s:\n"); nsAutoArrayPtr<TestObject> pobj( new TestObject[3] ); printf("Should create 5 |TestObject|s and then destroy 3:\n"); pobj = new TestObject[5]; printf("Should destroy 5 |TestObject|s:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); nsRefPtr<TestRefObject> pobj( new TestRefObject() ); printf("Should Release and destroy one |TestRefObject|:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); nsRefPtr<TestRefObject> pobj( new TestRefObject() ); printf("Should create and AddRef one |TestRefObject| and then Release and destroy one:\n"); pobj = new TestRefObject(); printf("Should Release and destroy one |TestRefObject|:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); nsRefPtr<TestRefObject> p1( new TestRefObject() ); printf("Should AddRef one |TestRefObject|:\n"); nsRefPtr<TestRefObject> p2( p1 ); printf("Should Release twice and destroy one |TestRefObject|:\n"); } printf("\nTesting equality (with all const-ness combinations):\n"); { nsRefPtr<TestRefObject> p1( new TestRefObject() ); nsRefPtr<TestRefObject> p2( p1 ); printf("equality %s.\n", ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken"); } { const nsRefPtr<TestRefObject> p1( new TestRefObject() ); nsRefPtr<TestRefObject> p2( p1 ); printf("equality %s.\n", ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken"); } { nsRefPtr<TestRefObject> p1( new TestRefObject() ); const nsRefPtr<TestRefObject> p2( p1 ); printf("equality %s.\n", ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken"); } { const nsRefPtr<TestRefObject> p1( new TestRefObject() ); const nsRefPtr<TestRefObject> p2( p1 ); printf("equality %s.\n", ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken"); } { nsRefPtr<TestRefObject> p1( new TestRefObject() ); TestRefObject * p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { const nsRefPtr<TestRefObject> p1( new TestRefObject() ); TestRefObject * p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } #if 0 /* MSVC++ 6.0 can't be coaxed to accept this */ { nsRefPtr<TestRefObject> p1( new TestRefObject() ); TestRefObject * const p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { const nsRefPtr<TestRefObject> p1( new TestRefObject() ); TestRefObject * const p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } #endif /* Things that MSVC++ 6.0 can't be coaxed to accept */ { nsRefPtr<TestRefObject> p1( new TestRefObject() ); const TestRefObject * p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { const nsRefPtr<TestRefObject> p1( new TestRefObject() ); const TestRefObject * p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { nsRefPtr<TestRefObject> p1( new TestRefObject() ); const TestRefObject * const p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { const nsRefPtr<TestRefObject> p1( new TestRefObject() ); const TestRefObject * const p2 = p1; printf("equality %s.\n", ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } printf("\nTesting getter_Transfers and getter_AddRefs.\n"); { nsAutoPtr<TestObject> ptr; printf("Should create one |TestObject|:\n"); CreateTestObject(getter_Transfers(ptr)); printf("Should destroy one |TestObject|:\n"); } { nsRefPtr<TestRefObject> ptr; printf("Should create and AddRef one |TestRefObject|:\n"); CreateTestRefObject(getter_AddRefs(ptr)); printf("Should Release and destroy one |TestRefObject|:\n"); } printf("\nTesting casts and equality tests.\n"); if ((void*)(TestObject*)0x1000 == (void*)(TestObjectBaseB*)(TestObject*)0x1000) printf("\n\nAll these tests are meaningless!\n\n\n"); { nsAutoPtr<TestObject> p1(new TestObject()); TestObjectBaseB *p2 = p1; printf("equality %s.\n", ((static_cast<void*>(p1) != static_cast<void*>(p2)) && (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { TestObject *p1 = new TestObject(); nsAutoPtr<TestObjectBaseB> p2(p1); printf("equality %s.\n", ((static_cast<void*>(p1) != static_cast<void*>(p2)) && (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { nsRefPtr<TestRefObject> p1 = new TestRefObject(); // nsCOMPtr requires a |get| for something like this as well nsRefPtr<TestRefObjectBaseB> p2 = p1.get(); printf("equality %s.\n", ((static_cast<void*>(p1) != static_cast<void*>(p2)) && (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { nsRefPtr<TestRefObject> p1 = new TestRefObject(); TestRefObjectBaseB *p2 = p1; printf("equality %s.\n", ((static_cast<void*>(p1) != static_cast<void*>(p2)) && (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } { TestRefObject *p1 = new TestRefObject(); nsRefPtr<TestRefObjectBaseB> p2 = p1; printf("equality %s.\n", ((static_cast<void*>(p1) != static_cast<void*>(p2)) && (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken"); } printf("\nTesting |forget()|.\n"); { printf("Should create one |TestObject|:\n"); nsAutoPtr<TestObject> pobj( new TestObject() ); printf("Should do nothing:\n"); nsAutoPtr<TestObject> pobj2( pobj.forget() ); printf("Should destroy one |TestObject|:\n"); } { printf("Should create 3 |TestObject|s:\n"); nsAutoArrayPtr<TestObject> pobj( new TestObject[3] ); printf("Should do nothing:\n"); nsAutoArrayPtr<TestObject> pobj2( pobj.forget() ); printf("Should destroy 3 |TestObject|s:\n"); } { printf("Should create one |TestRefObject|:\n"); nsRefPtr<TestRefObject> pobj( new TestRefObject() ); printf("Should do nothing:\n"); nsRefPtr<TestRefObject> pobj2( pobj.forget() ); printf("Should destroy one |TestRefObject|:\n"); } printf("\nTesting construction.\n"); { printf("Should create one |TestObject|:\n"); nsAutoPtr<TestObject> pobj(new TestObject()); printf("Should destroy one |TestObject|:\n"); } { printf("Should create 3 |TestObject|s:\n"); nsAutoArrayPtr<TestObject> pobj(new TestObject[3]); printf("Should destroy 3 |TestObject|s:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); nsRefPtr<TestRefObject> pobj = new TestRefObject(); printf("Should Release and destroy one |TestRefObject|:\n"); } printf("\nTesting calling of functions (including array access and casts).\n"); { printf("Should create one |TestObject|:\n"); nsAutoPtr<TestObject> pobj(new TestObject()); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObject(pobj); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObject(pobj); printf("Should destroy one |TestObject|:\n"); } { printf("Should create 3 |TestObject|s:\n"); nsAutoArrayPtr<TestObject> pobj(new TestObject[3]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObject(&pobj[2]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObject(&pobj[1]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObject(pobj + 2); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObject(pobj + 1); printf("Should destroy 3 |TestObject|s:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); nsRefPtr<TestRefObject> pobj = new TestRefObject(); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithTestRefObject(pobj); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithConstTestRefObject(pobj); printf("Should Release and destroy one |TestRefObject|:\n"); } { printf("Should create one |TestObject|:\n"); nsAutoPtr<TestObject> pobj(new TestObject()); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObjectBaseB(pobj); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObjectBaseB(pobj); printf("Should destroy one |TestObject|:\n"); } { printf("Should create 3 |TestObject|s:\n"); nsAutoArrayPtr<TestObject> pobj(new TestObject[3]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObjectBaseB(&pobj[2]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObjectBaseB(&pobj[1]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObjectBaseB(pobj + 2); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObjectBaseB(pobj + 1); printf("Should destroy 3 |TestObject|s:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); nsRefPtr<TestRefObject> pobj = new TestRefObject(); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithTestRefObjectBaseB(pobj); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithConstTestRefObjectBaseB(pobj); printf("Should Release and destroy one |TestRefObject|:\n"); } { printf("Should create one |TestObject|:\n"); const nsAutoPtr<TestObject> pobj(new TestObject()); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObject(pobj); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObject(pobj); printf("Should destroy one |TestObject|:\n"); } { printf("Should create 3 |TestObject|s:\n"); const nsAutoArrayPtr<TestObject> pobj(new TestObject[3]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObject(&pobj[2]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObject(&pobj[1]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObject(pobj + 2); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObject(pobj + 1); printf("Should destroy 3 |TestObject|s:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); const nsRefPtr<TestRefObject> pobj = new TestRefObject(); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithTestRefObject(pobj); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithConstTestRefObject(pobj); printf("Should Release and destroy one |TestRefObject|:\n"); } { printf("Should create one |TestObject|:\n"); const nsAutoPtr<TestObject> pobj(new TestObject()); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObjectBaseB(pobj); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObjectBaseB(pobj); printf("Should destroy one |TestObject|:\n"); } { printf("Should create 3 |TestObject|s:\n"); const nsAutoArrayPtr<TestObject> pobj(new TestObject[3]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObjectBaseB(&pobj[2]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObjectBaseB(&pobj[1]); printf("Should do something with one |TestObject|:\n"); DoSomethingWithTestObjectBaseB(pobj + 2); printf("Should do something with one |TestObject|:\n"); DoSomethingWithConstTestObjectBaseB(pobj + 1); printf("Should destroy 3 |TestObject|s:\n"); } { printf("Should create and AddRef one |TestRefObject|:\n"); const nsRefPtr<TestRefObject> pobj = new TestRefObject(); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithTestRefObjectBaseB(pobj); printf("Should do something with one |TestRefObject|:\n"); DoSomethingWithConstTestRefObjectBaseB(pobj); printf("Should Release and destroy one |TestRefObject|:\n"); } return 0; }
static void split_convex(const std::vector<DPoint>& in, std::vector<DPoint>& out, std::vector<size_t>& cvx) { // initialization std::vector<DPoint>::const_iterator p=in.begin(), pmax = in.end(); bool is_closed = (in.front()==in.back()); if(in.size()<4) { while(p!=pmax) out.push_back(*p++); cvx.push_back( out.size() ); return; } int ni = 0; DPoint p1(*p++),p2(*p++),p3(*p++); out.push_back(p1); int d2 = dir(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); // MAIN LOOP : d1=angle(P1-P2-P3) and d2=angle(P2-P3-P4) bool ok = true; std::vector<DPoint>::const_iterator first=in.begin(); while (ok) { int d1 = d2; DPoint p4=*p++; d2 = dir(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y); if(d1*d2>0) { // convex part: store point and increment p out.push_back(p1=p2); p2 = p3; p3 = p4; } else if(d1*d2<0) { // split curve out.push_back(p2); DPoint m = .5*(p2+p3); out.push_back(m); cvx.push_back( out.size() ); if(p==first) ok=false; if(first==in.begin()) first=p; if(ok) { if(is_closed && !ni) { out.clear(); cvx.clear(); cvx.push_back(0); } out.push_back(m); ni++; p1 = p2; p2 = p3; p3 = p4; } } else { // undefined sign: remove one point if(d1==0 || d2==0) { if(d1==0) p2 = p3; p3 = p4; d2 = dir(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); } else assert(false); // NaN in curve? } // test end of loop if(ok && p==pmax) { if (is_closed) p = in.begin()+1; else ok=false; } // stop for convex closed curves if(p==in.begin()+3 && ni==0) ok=false; } // END OF MAIN LOOP if (!is_closed) { out.push_back(p2); out.push_back(p3); cvx.push_back( out.size() ); } else if(ni==0) { // convex closed curve */ if (out.end() == out.begin()+1) out.push_back( out.front() ); else out[0] = out.back(); cvx.push_back( out.size() ); } }
CubitStatus SimplifyTool::weighted_average_normal(RefFace* ref_face, CubitVector &normal, double &weight ) { GMem g_mem; unsigned short norm_tol = 30; double dist_tol = -1.0; ref_face->get_geometry_query_engine()-> get_graphics(ref_face->get_surface_ptr(), &g_mem, norm_tol, dist_tol ); if(g_mem.fListCount < 1) { // Decrease tolerance and try again (we can get this for small features) norm_tol /= 2; ref_face->get_geometry_query_engine()-> get_graphics(ref_face->get_surface_ptr(), &g_mem, norm_tol, dist_tol ); } if(g_mem.fListCount < 1) { // Lets give up PRINT_ERROR( "Unable to find average normal of a surface\n" ); return CUBIT_FAILURE; } // Initialize weight = 0.0; normal.set( 0.0, 0.0, 0.0 ); // Loop through the triangles double tri_weight, A, B, C; GPoint p[3]; GPoint* plist = g_mem.point_list(); int* facet_list = g_mem.facet_list(); int c = 0; for( ;c<g_mem.fListCount; ) { p[0] = plist[facet_list[++c]]; p[2] = plist[facet_list[++c]]; p[1] = plist[facet_list[++c]]; c++; // Get centroid CubitVector p1( p[0].x, p[0].y, p[0].z ); CubitVector p2( p[2].x, p[2].y, p[2].z ); CubitVector p3( p[1].x, p[1].y, p[1].z ); CubitVector center = (p1 + p2 + p3)/3.0; CubitVector norm(ref_face->normal_at(center)); // Get triangle area A = p1.y() * p2.z() + p1.z() * p3.y() + p2.y() * p3.z() - p2.z() * p3.y() - p1.y() * p3.z() - p1.z() * p2.y(); B = p1.z() * p2.x() + p1.x() * p3.z() + p2.z() * p3.x() - p2.x() * p3.z() - p1.z() * p3.x() - p1.x() * p2.z(); C = p1.x() * p2.y() + p1.y() * p3.x() + p2.x() * p3.y() - p2.y() * p3.x() - p1.x() * p3.y() - p1.y() * p2.x(); //Note: triangle area = 0.5*(sqrt(A*A+B*B+C*C)); tri_weight = 0.5*(A*A+B*B+C*C); normal += tri_weight * norm; weight += tri_weight; } normal.normalize(); return CUBIT_SUCCESS; }
int main(int argc, char* argv[]) { CS325Graphics window(argc, argv); float delta = 0.1; Point2D p1(CS325Graphics::X_MIN, CS325Graphics::Y_MAX / 4.5); Point2D p2(CS325Graphics::X_MAX, CS325Graphics::Y_MAX / 4.5); Point2D p3(CS325Graphics::X_MIN, CS325Graphics::Y_MIN); Point2D p4(CS325Graphics::X_MAX, CS325Graphics::Y_MAX); //Points 41, 42, 45, 46 control the sandbox. DON"T MESS WITH THEM! Point3D p30(0.5, 0.5,-3.5); Point3D p31(0.5, -0.5,-3.5); Point3D p32(-0.5,-0.5,-3.5); Point3D p33(-0.5, 0.5,-3.5); Point3D p34(0.5, 0.5,-1.5); Point3D p35(0.5, -0.5,-1.5); Point3D p36(-0.5,-0.5,-1.5); Point3D p37(-0.5, 0.5,-1.5); Point3D p40( -70.8, 28.8, -50.8); Point3D p41( 50.8,-2.8, 50.8); Point3D p42(-50.8,-2.8, 50.8); Point3D p43(-58.8, 25.8, 50.8); Point3D p44( 50.8, 50.8, -50.8); Point3D p45( 50.8,-2.8, -50.8); Point3D p46(-50.8,-2.8, -50.8); Point3D p47(-84.8,-2.8, -50.8); Point3D p49(-8.5,22.0, 50.8); Point3D p48(70,20,50.8); Point3D p50(3.5, 0.5,-3.5); Point3D p51(3.5, -0.5,-3.5); Point3D p52(2.5,-0.5,-3.5); Point3D p53(2.5, 0.5,-3.5); Point3D p54(3.5, 0.5,-1.5); Point3D p55(3.5, -0.5,-1.5); Point3D p56(2.5,-0.5,-1.5); Point3D p57(2.5, 0.5,-1.5); Point3D p60(3.5, 0.5, 13.5); Point3D p61(3.5, -0.5, 13.5); Point3D p62(2.5,-0.5, 13.5); Point3D p63(2.5, 0.5, 13.5); Point3D p64(3.5, 0.5, 16.5); Point3D p65(3.5, -0.5, 16.5); Point3D p66(2.5,-0.5, 16.5); Point3D p67(2.5, 0.5, 16.5); Point2D viewPos; Vector2D viewDir; Vector3D deltaV; viewDir.setAngle(0); // move view position for(int i = 0; i < MOVE_TEST; i){ /*window.DrawLineOnScreen(p1, p2);*/ //window.DrawLineOnScreen(p4, p3); window.DrawLineInSpace(p30, p31); window.DrawLineInSpace(p31, p32); window.DrawLineInSpace(p32, p33); window.DrawLineInSpace(p33, p30); window.DrawLineInSpace(p34, p35); window.DrawLineInSpace(p35, p36); window.DrawLineInSpace(p36, p37); window.DrawLineInSpace(p37, p34); window.DrawLineInSpace(p30, p34); window.DrawLineInSpace(p31, p35); window.DrawLineInSpace(p32, p36); window.DrawLineInSpace(p33, p37); window.DrawLineInSpace(p50, p51); window.DrawLineInSpace(p51, p52); window.DrawLineInSpace(p52, p53); window.DrawLineInSpace(p53, p50); window.DrawLineInSpace(p54, p55); window.DrawLineInSpace(p55, p56); window.DrawLineInSpace(p56, p57); window.DrawLineInSpace(p57, p54); window.DrawLineInSpace(p50, p54); window.DrawLineInSpace(p51, p55); window.DrawLineInSpace(p52, p56); window.DrawLineInSpace(p53, p57); window.DrawLineInSpace(p60, p61); window.DrawLineInSpace(p61, p62); window.DrawLineInSpace(p62, p63); window.DrawLineInSpace(p63, p60); window.DrawLineInSpace(p64, p65); window.DrawLineInSpace(p65, p66); window.DrawLineInSpace(p66, p67); window.DrawLineInSpace(p67, p64); window.DrawLineInSpace(p60, p64); window.DrawLineInSpace(p61, p65); window.DrawLineInSpace(p62, p66); window.DrawLineInSpace(p63, p67); //window.DrawLineInSpace(p40, p41); window.DrawLineInSpace(p41, p42); window.DrawLineInSpace(p42, p43); //window.DrawLineInSpace(p43, p40); //window.DrawLineInSpace(p44, p45); window.DrawLineInSpace(p45, p46); //window.DrawLineInSpace(p46, p47); //window.DrawLineInSpace(p47, p44); window.DrawLineInSpace(p40, p45); window.DrawLineInSpace(p41, p45); window.DrawLineInSpace(p42, p46); window.DrawLineInSpace(p43, p47); window.DrawLineInSpace(p40, p47); window.DrawLineInSpace(p41, p49); window.DrawLineInSpace(p42, p49); window.DrawLineInSpace(p41, p48); window.DrawLineInSpace(p45, p48); if(GetAsyncKeyState(VK_DOWN)) // the DOWN arrow was pressed, let's do something { delta = -.1; viewPos.setY(viewPos.getY() + cos(-viewDir.getAngle())*delta); viewPos.setX(viewPos.getX() + sin(-viewDir.getAngle())*delta); window.SetViewPosition(viewPos); cout << "view pos: " << viewPos.toString() << endl; window.DisplayNow(); Sleep(50); } if(GetAsyncKeyState(VK_UP)) // the UP arrow was pressed, let's do something { delta = .1; viewPos.setY(viewPos.getY() + cos(-viewDir.getAngle())*delta); viewPos.setX(viewPos.getX() + sin(-viewDir.getAngle())*delta); window.SetViewPosition(viewPos); cout << "view pos: " << viewPos.toString() << endl; window.DisplayNow(); Sleep(50); } if(GetAsyncKeyState(VK_RIGHT)) // the RIGHT arrow was pressed, let's do something { delta = .1; viewDir.setAngle(viewDir.getAngle()+delta); window.SetViewDirection(viewDir); cout << "view dir: " << viewDir.getAngle() << endl; window.DisplayNow(); Sleep(50); } if(GetAsyncKeyState(VK_LEFT)) // the LEFT arrow was pressed, let's do something { delta = -.1; viewDir.setAngle(viewDir.getAngle()+delta); window.SetViewDirection(viewDir); cout << "view dir: " << viewDir.getAngle() << endl; window.DisplayNow(); Sleep(50); } if(GetAsyncKeyState(VK_ESCAPE)) { return 1; } } }
void testController(){ MemRepository* repo=new MemRepository(); Controller c(repo); string errors=""; Expense p(1, 21, 92, "clothing"); c.add(p); assert(c.size()==1); Expense p1(2, 23, 440, "telephone"); c.add(p1); assert(c.size()==2); Expense p2(3, 2, 9, "pizza"); try{ c.add(p2); } catch(RepositoryException& s) { errors+=s.getMsg(); } assert(c.size()==2); assert(errors!=""); errors=""; Expense p3(3, 34, 29, "others"); try{ c.add(p2); } catch(RepositoryException& s) { errors+=s.getMsg(); } assert(c.size()==2); assert(errors!=""); Expense p4(1, 23, 440, "others"); c.update(1,p4); vector<Expense*> all=c.getAll(); assert(all.at(0)->getDay()==23); assert(c.size()==2); errors=""; try{ c.update(1,p3); } catch (RepositoryException& s1) { errors+=s1.getMsg(); } assert(errors!=""); c.remove(1); assert (c.size()==1); errors=""; try{ c.remove(7); } catch (RepositoryException& s1) { errors+=s1.getMsg(); } assert(errors!=""); assert (c.size()==1); c.add(p); all=c.filterByDay(23); assert(all.size()==1); all=c.filterByAmount(440); assert(all.size()==1); all=c.sortByAmountA(); assert(all.at(0)->getId()==1); all=c.sortByAmountD(); assert(all.at(0)->getId()==2); all=c.sortByTypeA(); assert(all.at(0)->getId()==1); all=c.sortByTypeD(); assert(all.at(0)->getId()==2); }
static void Statistics ( dgSphere &sphere, dgVector &eigenValues, dgVector &scaleVector, const dgFloat32 vertex[], const dgInt32 faceIndex[], dgInt32 indexCount, dgInt32 stride) { /* dgInt32 i; dgInt32 j; dgFloat32 *ptr; dgFloat32 x; dgFloat32 z; dgFloat32 y; dgFloat64 k; dgFloat64 Ixx; dgFloat64 Iyy; dgFloat64 Izz; dgFloat64 Ixy; dgFloat64 Ixz; dgFloat64 Iyz; dgBigVector massCenter (0, 0, 0, 0); dgBigVector var (0, 0, 0, 0); dgBigVector cov (0, 0, 0, 0); ptr = (dgFloat32*)vertex; for (i = 0; i < indexCount; i ++) { j = index[i] * stride; x = ptr[j + 0] * scaleVector.m_x; y = ptr[j + 1] * scaleVector.m_y; z = ptr[j + 2] * scaleVector.m_z; massCenter += dgBigVector (x, y, z, 0); var += dgBigVector (x * x, y * y, z * z, 0); cov += dgBigVector (x * y, x * z, y * z, 0); } k = 1.0 / indexCount; var = var.Scale (k); cov = cov.Scale (k); massCenter = massCenter.Scale (k); Ixx = var.m_x - massCenter.m_x * massCenter.m_x; Iyy = var.m_y - massCenter.m_y * massCenter.m_y; Izz = var.m_z - massCenter.m_z * massCenter.m_z; Ixy = cov.m_x - massCenter.m_x * massCenter.m_y; Ixz = cov.m_y - massCenter.m_x * massCenter.m_z; Iyz = cov.m_z - massCenter.m_y * massCenter.m_z; sphere.m_front = dgVector (dgFloat32(Ixx), dgFloat32(Ixy), dgFloat32(Ixz), dgFloat32 (0.0f)); sphere.m_up = dgVector (dgFloat32(Ixy), dgFloat32(Iyy), dgFloat32(Iyz), dgFloat32 (0.0f)); sphere.m_right = dgVector (dgFloat32(Ixz), dgFloat32(Iyz), dgFloat32(Izz), dgFloat32 (0.0f)); sphere.EigenVectors (eigenValues); */ const dgFloat32 *ptr; dgFloat64 K; dgFloat64 Ixx; dgFloat64 Iyy; dgFloat64 Izz; dgFloat64 Ixy; dgFloat64 Ixz; dgFloat64 Iyz; dgFloat64 area; dgFloat64 totalArea; // const dgFace *Face; dgVector var (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f)); dgVector cov (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f)); dgVector centre (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f)); dgVector massCenter (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f)); totalArea = dgFloat32 (0.0f); ptr = vertex; for (dgInt32 i = 0; i < indexCount; i += 3) { // Face = &face[i]; dgInt32 index; index = faceIndex[i] * stride; dgVector p0 (&ptr[index]); p0 = p0.CompProduct (scaleVector); index = faceIndex[i + 1] * stride;; dgVector p1 (&ptr[index]); p1 = p1.CompProduct (scaleVector); index = faceIndex[i + 2] * stride;; dgVector p2 (&ptr[index]); p2 = p2.CompProduct (scaleVector); dgVector normal ((p1 - p0) * (p2 - p0)); area = dgFloat32 (0.5f) * sqrt (normal % normal); centre = p0 + p1 + p2; centre = centre.Scale (dgFloat32 (1.0f / 3.0f)); // Inertia of each point in the triangle Ixx = p0.m_x * p0.m_x + p1.m_x * p1.m_x + p2.m_x * p2.m_x; Iyy = p0.m_y * p0.m_y + p1.m_y * p1.m_y + p2.m_y * p2.m_y; Izz = p0.m_z * p0.m_z + p1.m_z * p1.m_z + p2.m_z * p2.m_z; Ixy = p0.m_x * p0.m_y + p1.m_x * p1.m_y + p2.m_x * p2.m_y; Iyz = p0.m_y * p0.m_z + p1.m_y * p1.m_z + p2.m_y * p2.m_z; Ixz = p0.m_x * p0.m_z + p1.m_x * p1.m_z + p2.m_x * p2.m_z; if (area > dgEPSILON * 10.0) { K = area / 12.0; //Coriollis teorem for Inercia of a triangle in an arbitrary orientation Ixx = K * (Ixx + 9.0 * centre.m_x * centre.m_x); Iyy = K * (Iyy + 9.0 * centre.m_y * centre.m_y); Izz = K * (Izz + 9.0 * centre.m_z * centre.m_z); Ixy = K * (Ixy + 9.0 * centre.m_x * centre.m_y); Ixz = K * (Ixz + 9.0 * centre.m_x * centre.m_z); Iyz = K * (Iyz + 9.0 * centre.m_y * centre.m_z); centre = centre.Scale ((dgFloat32)area); } totalArea += area; massCenter += centre; var += dgVector ((dgFloat32)Ixx, (dgFloat32)Iyy, (dgFloat32)Izz, dgFloat32 (0.0f)); cov += dgVector ((dgFloat32)Ixy, (dgFloat32)Ixz, (dgFloat32)Iyz, dgFloat32 (0.0f)); } if (totalArea > dgEPSILON * 10.0) { K = 1.0 / totalArea; var = var.Scale ((dgFloat32)K); cov = cov.Scale ((dgFloat32)K); massCenter = massCenter.Scale ((dgFloat32)K); } Ixx = var.m_x - massCenter.m_x * massCenter.m_x; Iyy = var.m_y - massCenter.m_y * massCenter.m_y; Izz = var.m_z - massCenter.m_z * massCenter.m_z; Ixy = cov.m_x - massCenter.m_x * massCenter.m_y; Ixz = cov.m_y - massCenter.m_x * massCenter.m_z; Iyz = cov.m_z - massCenter.m_y * massCenter.m_z; sphere.m_front = dgVector ((dgFloat32)Ixx, (dgFloat32)Ixy, (dgFloat32)Ixz, dgFloat32 (0.0f)); sphere.m_up = dgVector ((dgFloat32)Ixy, (dgFloat32)Iyy, (dgFloat32)Iyz, dgFloat32 (0.0f)); sphere.m_right = dgVector ((dgFloat32)Ixz, (dgFloat32)Iyz, (dgFloat32)Izz, dgFloat32 (0.0f)); sphere.EigenVectors(eigenValues); }
void qPoissonRecon::doAction() { assert(m_app); if (!m_app) { return; } const ccHObject::Container& selectedEntities = m_app->getSelectedEntities(); //we need one point cloud size_t selNum = selectedEntities.size(); if (selNum != 1) { m_app->dispToConsole("Select only one cloud!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } //a real point cloud ccHObject* ent = selectedEntities[0]; if (!ent->isA(CC_TYPES::POINT_CLOUD)) { m_app->dispToConsole("Select a cloud!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } //with normals! ccPointCloud* pc = static_cast<ccPointCloud*>(ent); if (!pc->hasNormals()) { m_app->dispToConsole("Cloud must have normals!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } bool cloudHasColors = pc->hasColors(); PoissonReconParamDlg prpDlg(m_app->getMainWindow()); prpDlg.importColorsCheckBox->setVisible(cloudHasColors); //init dialog with semi-persistent settings prpDlg.octreeLevelSpinBox->setValue(s_params.depth); prpDlg.weightDoubleSpinBox->setValue(s_params.pointWeight); prpDlg.fullDepthSpinBox->setValue(s_params.fullDepth); prpDlg.samplesPerNodeSpinBox->setValue(s_params.samplesPerNode); prpDlg.densityCheckBox->setChecked(s_params.density); prpDlg.importColorsCheckBox->setChecked(true); if (!prpDlg.exec()) return; //set parameters with dialog settings s_params.depth = prpDlg.octreeLevelSpinBox->value(); s_params.pointWeight = static_cast<float>(prpDlg.weightDoubleSpinBox->value()); s_params.fullDepth = prpDlg.fullDepthSpinBox->value(); s_params.samplesPerNode = static_cast<float>(prpDlg.samplesPerNodeSpinBox->value()); s_params.density = prpDlg.densityCheckBox->isChecked(); bool withColors = pc->hasColors() && prpDlg.importColorsCheckBox->isChecked(); /*** RECONSTRUCTION PROCESS ***/ PoissonMesh mesh; ColoredPoissonMesh coloredMesh; s_cloud = 0; s_mesh = 0; s_coloredMesh = 0; //run in a separate thread bool result = false; { //start message m_app->dispToConsole(QString("[PoissonRecon] Job started (level %1)").arg(s_params.depth),ccMainAppInterface::STD_CONSOLE_MESSAGE); //progress dialog (Qtconcurrent::run can't be canceled!) QProgressDialog pDlg("Initialization", QString(), 0, 0, m_app->getMainWindow()); pDlg.setWindowTitle("Poisson Reconstruction"); pDlg.show(); //QApplication::processEvents(); pDlg.setLabelText(QString("Reconstruction in progress\nlevel: %1 [%2 thread(s)]").arg(s_params.depth).arg(s_params.threads)); QApplication::processEvents(); QFuture<bool> future; //run in a separate thread s_cloud = pc; if (withColors) { s_coloredMesh = &coloredMesh; future = QtConcurrent::run(doReconstructWithColors); } else { s_mesh = &mesh; future = QtConcurrent::run(doReconstruct); } //wait until process is finished! while (!future.isFinished()) { #if defined(CC_WINDOWS) ::Sleep(500); #else usleep(500 * 1000); #endif pDlg.setValue(pDlg.value()+1); QApplication::processEvents(); } result = future.result(); pDlg.hide(); QApplication::processEvents(); } if (result && (!s_mesh || s_mesh->polygonCount() > 0) && (!s_coloredMesh || s_coloredMesh->polygonCount() > 0)) { unsigned nic = 0, noc = 0, nr_faces = 0; if (s_coloredMesh) { s_coloredMesh->resetIterator(); nic = static_cast<unsigned>(s_coloredMesh->inCorePoints.size()); noc = static_cast<unsigned>(s_coloredMesh->outOfCorePointCount()); nr_faces = static_cast<unsigned>(s_coloredMesh->polygonCount()); } else //if (s_mesh) { s_mesh->resetIterator(); nic = static_cast<unsigned>(s_mesh->inCorePoints.size()); noc = static_cast<unsigned>(s_mesh->outOfCorePointCount()); nr_faces = static_cast<unsigned>(s_mesh->polygonCount()); } unsigned nr_vertices = nic+noc; //end message m_app->dispToConsole(QString("[PoissonRecon] Job finished (%1 triangles, %2 vertices)").arg(nr_faces).arg(nr_vertices),ccMainAppInterface::STD_CONSOLE_MESSAGE); ccPointCloud* newPC = new ccPointCloud("vertices"); ccMesh* newMesh = new ccMesh(newPC); newMesh->addChild(newPC); if (newPC->reserve(nr_vertices) && newMesh->reserve(nr_faces)) { ccScalarField* densitySF = 0; if (s_params.density) { densitySF = new ccScalarField("Density"); if (!densitySF->reserve(nr_vertices)) { m_app->dispToConsole(QString("[PoissonRecon] Failed to allocate memory for storing density!"),ccMainAppInterface::WRN_CONSOLE_MESSAGE); densitySF->release(); densitySF = 0; } } if (s_coloredMesh) { bool importColors = newPC->reserveTheRGBTable(); if (!importColors) { if (m_app) m_app->dispToConsole("Not enough memory to import colors!", ccMainAppInterface::ERR_CONSOLE_MESSAGE); } //add 'in core' points { for (unsigned i=0; i<nic; i++) { ColoredVertex& p = s_coloredMesh->inCorePoints[i]; CCVector3 p2( static_cast<PointCoordinateType>(p.point.coords[0]), static_cast<PointCoordinateType>(p.point.coords[1]), static_cast<PointCoordinateType>(p.point.coords[2]) ); newPC->addPoint(p2); if (importColors) { newPC->addRGBColor(p.color); } if (densitySF) { ScalarType sf = static_cast<ScalarType>(p.value); densitySF->addElement(sf); } } } //add 'out of core' points { for (unsigned i=0; i<noc; i++) { ColoredVertex p; s_coloredMesh->nextOutOfCorePoint(p); CCVector3 p2( static_cast<PointCoordinateType>(p.point.coords[0]), static_cast<PointCoordinateType>(p.point.coords[1]), static_cast<PointCoordinateType>(p.point.coords[2]) ); newPC->addPoint(p2); if (importColors) { newPC->addRGBColor(p.color); } if (densitySF) { ScalarType sf = static_cast<ScalarType>(p.value); densitySF->addElement(sf); } } } newPC->showColors(importColors); } else { //add 'in core' points { for (unsigned i=0; i<nic; i++) { Vertex& p = s_mesh->inCorePoints[i]; CCVector3 p2( static_cast<PointCoordinateType>(p.point.coords[0]), static_cast<PointCoordinateType>(p.point.coords[1]), static_cast<PointCoordinateType>(p.point.coords[2]) ); newPC->addPoint(p2); if (densitySF) { ScalarType sf = static_cast<ScalarType>(p.value); densitySF->addElement(sf); } } } //add 'out of core' points { for (unsigned i=0; i<noc; i++) { Vertex p; s_mesh->nextOutOfCorePoint(p); CCVector3 p2( static_cast<PointCoordinateType>(p.point.coords[0]), static_cast<PointCoordinateType>(p.point.coords[1]), static_cast<PointCoordinateType>(p.point.coords[2]) ); newPC->addPoint(p2); if (densitySF) { ScalarType sf = static_cast<ScalarType>(p.value); densitySF->addElement(sf); } } } newPC->showColors(false); } // density SF if (densitySF) { densitySF->computeMinAndMax(); densitySF->showNaNValuesInGrey(false); int sfIdx = newPC->addScalarField(densitySF); newPC->setCurrentDisplayedScalarField(sfIdx); newPC->showSF(true); newMesh->showColors(newPC->colorsShown()); newMesh->showSF(true); } //add faces { for (unsigned i=0; i<nr_faces; i++) { std::vector<CoredVertexIndex> triangleIndexes; if (s_mesh) s_mesh->nextPolygon(triangleIndexes); else s_coloredMesh->nextPolygon(triangleIndexes); if (triangleIndexes.size() == 3) { for (std::vector<CoredVertexIndex>::iterator it = triangleIndexes.begin(); it != triangleIndexes.end(); ++it) if (!it->inCore) it->idx += nic; newMesh->addTriangle( triangleIndexes[0].idx, triangleIndexes[1].idx, triangleIndexes[2].idx ); } else { //Can't handle anything else than triangles yet! assert(false); } } } newMesh->setName(QString("Mesh[%1] (level %2)").arg(pc->getName()).arg(s_params.depth)); newPC->setEnabled(false); newMesh->setVisible(true); newMesh->computeNormals(true); newMesh->showColors(newMesh->hasColors()); //output mesh m_app->addToDB(newMesh); } else { delete newMesh; newMesh = 0; m_app->dispToConsole("Not enough memory!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); } //currently selected entities parameters may have changed! m_app->updateUI(); //currently selected entities appearance may have changed! m_app->refreshAll(); } else { m_app->dispToConsole("Reconstruction failed!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); } s_cloud = 0; s_mesh = 0; s_coloredMesh = 0; }
TEST(GrayPixel, OperatorGT) { GrayPixel p1(3); GrayPixel p2(234); ASSERT_TRUE(p2 > p1); ASSERT_FALSE(p1 > p2); }
void templateAppDraw( void ) { if( game_state == 2 ) { free_level(); load_level(); } glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); GFX_set_matrix_mode( PROJECTION_MATRIX ); GFX_load_identity(); GFX_set_perspective( 80.0f, ( float )viewport_matrix[ 2 ] / ( float )viewport_matrix[ 3 ], 0.1f, 50.0f, 0.0f ); GFX_set_matrix_mode( MODELVIEW_MATRIX ); GFX_load_identity(); if(turn_left()) { next_rotz+=1.2; } if(turn_right()) { next_rotz-=1.2; } vec3 forward = { 0.0f, 1.0f, 0.0f },direction; if( !game_state ) { //Pre-calculate a few variables before rotating the forward vector by the camera's Z rotation. float r = rotz * DEG_TO_RAD, c = cosf( r ), s = sinf( r ); //Rotate the forward vector and store the result into the direction variable. Because //both vectors are already normalized, there's no need to re-normalize them one more time. direction.x = c * forward.y - s * forward.x; direction.y = s * forward.y + c * forward.x; //Calculate the current angular velocity that is relevant to the //accelerometer value that we are using as the force factor. //Then clamp the result to make sure that the speed is between the minimum and //maximum ball speed thresholds. float speed = CLAMP( -maximum_speed, -maximum_speed, maximum_speed ); player->btrigidbody->setAngularVelocity( btVector3( direction.x * speed,direction.y * speed,0.0f ) ); //Activate the rigid body to make sure that the angular velocity will be applied. player->btrigidbody->setActivationState( ACTIVE_TAG ); } /* if( view_delta.x || view_delta.y ) { if( view_delta.x ) next_rotz -= view_delta.x; if( view_delta.y ) { next_roty += view_delta.y; next_roty = CLAMP( next_roty, -180.0f, -90.0f ); } view_delta.x = view_delta.y = 0.0f; } if( move_delta.z ) { vec3 direction; float r = rotz * DEG_TO_RAD, c = cosf( r ), s = sinf( r ); direction.x = s * move_delta.y + c * move_delta.x; direction.y = c * move_delta.y - s * move_delta.x; player->btrigidbody->setAngularVelocity( 2*btVector3( -direction.y * ( move_delta.z * 6.7f ), -direction.x * ( move_delta.z * 6.7f ), 0.0f ) ); player->btrigidbody->setActivationState( ACTIVE_TAG ); }*/ //console_print("player_x: %3.f player_y: %3.f\n",player->location.x,player->location.y); next_eye.x = player->location.x + distance * cosf( roty * DEG_TO_RAD ) * sinf( rotz * DEG_TO_RAD ); next_eye.y = player->location.y - distance * cosf( roty * DEG_TO_RAD ) * cosf( rotz * DEG_TO_RAD ); next_eye.z = player->location.z + distance * sinf( roty * DEG_TO_RAD ); btVector3 p1( player->location.x, player->location.y, player->location.z ), p2( next_eye.x, next_eye.y, next_eye.z ); ClosestNotMeRayResultCallback back_ray( player->btrigidbody, p1, p2 ); dynamicsworld->rayTest( p1, p2, back_ray ); if( back_ray.hasHit() ) { back_ray.m_hitNormalWorld.normalize(); next_eye.x = back_ray.m_hitPointWorld.x() + ( back_ray.m_hitNormalWorld.x() * 0.1f ); next_eye.y = back_ray.m_hitPointWorld.y() + ( back_ray.m_hitNormalWorld.y()* 0.1f ); next_eye.z = back_ray.m_hitPointWorld.z() + ( back_ray.m_hitNormalWorld.z()* 0.1f ); } roty = roty * 0.9f + next_roty * 0.1f; rotz = rotz * 0.9f + next_rotz * 0.1f; eye.x = eye.x * 0.95f + next_eye.x * 0.05f; eye.y = eye.y * 0.95f + next_eye.y * 0.05f; eye.z = eye.z * 0.95f + next_eye.z * 0.05f; player->location.z += player->dimension.z * 0.5f; /* * needed for directional audio */ vec3 player_location={player->location.x,player->location.y,player->location.z}; AUDIO_set_listener( &eye, &player_location, &up ); GFX_look_at( &eye, &player->location, &up ); build_frustum( frustum, GFX_get_modelview_matrix(), GFX_get_projection_matrix() ); unsigned int i = 0; while( i != obj->n_objmesh ) { OBJMESH *objmesh = &obj->objmesh[ i ]; objmesh->distance = sphere_distance_in_frustum( frustum, &objmesh->location, objmesh->radius ); if( objmesh->distance && objmesh->visible ) { GFX_push_matrix(); if( strstr( objmesh->name, "gem" ) ) { GFX_translate( objmesh->location.x, objmesh->location.y, objmesh->location.z ); objmesh->rotation.z += 1.0f; GFX_rotate( objmesh->rotation.z, 0.0f, 0.0f, 1.0f ); } else if( objmesh->btrigidbody ) { mat4 mat; objmesh->btrigidbody->getWorldTransform().getOpenGLMatrix( ( float * )&mat ); memcpy( &objmesh->location, ( vec3 * )&mat.m[ 3 ], sizeof( vec3 ) ); GFX_multiply_matrix( &mat ); } else { GFX_translate( objmesh->location.x, objmesh->location.y, objmesh->location.z ); } OBJ_draw_mesh( obj, i ); GFX_pop_matrix(); } ++i; } if(!game_state ) { dynamicsworld->stepSimulation( 1.0f / 60.0f ); } GFX_set_matrix_mode( PROJECTION_MATRIX ); GFX_load_identity(); float half_width = ( float )viewport_matrix[ 2 ] * 0.5f, half_height = ( float )viewport_matrix[ 3 ] * 0.5f; GFX_set_orthographic_2d( -half_width, half_width, -half_height, half_height ); GFX_rotate( 0.0f, 0.0f, 0.0f, 1.0f ); GFX_translate( -half_width, -half_height, 0.0f ); GFX_set_matrix_mode( MODELVIEW_MATRIX ); GFX_load_identity(); vec4 font_color = { 0.0f, 0.0f, 0.0f, 1.0f }; char gem_str [ MAX_CHAR ] = {""}, time_str [ MAX_CHAR ] = {""}, level_str[ MAX_CHAR ] = {""}, pause_str [ MAX_CHAR ] = {""}; if( game_state == 3 ) { sprintf( pause_str, "Touch to Resume" ); FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, pause_str ) * 0.5f + 4.0f, viewport_matrix[ 3 ] * 0.7f - font_big->font_size * 1.5f - 4.0f, pause_str, &font_color ); /* Yellow. */ font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, pause_str ) * 0.5f, viewport_matrix[ 3 ] * 0.7f - font_big->font_size * 1.5f, pause_str, &font_color ); } if( game_state == 1 ) { sprintf( level_str, "Level Clear!" ); FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, level_str ) * 0.5f + 4.0f, viewport_matrix[ 3 ] - font_big->font_size * 1.5f - 4.0f, level_str, &font_color ); /* Yellow. */ font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, level_str ) * 0.5f, viewport_matrix[ 3 ] - font_big->font_size * 1.5f, level_str, &font_color ); } font_color.x = 0.0f; font_color.y = 0.0f; font_color.z = 0.0f; sprintf( gem_str, "Gem Points:%02d", gem_points ); sprintf( time_str, "Game Time:%02.2f", game_time * 0.1f ); FONT_print( font_small, viewport_matrix[ 2 ] - FONT_length( font_small, gem_str ) - 6.0f, ( font_small->font_size * 0.5f ), gem_str, &font_color ); FONT_print( font_small, 8.0f, ( font_small->font_size * 0.5f ), time_str, &font_color ); font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_small, viewport_matrix[ 2 ] - FONT_length( font_small, gem_str ) - 8.0f, ( font_small->font_size * 0.5f ), gem_str, &font_color ); FONT_print( font_small, 6.0f, ( font_small->font_size * 0.5f ), time_str, &font_color ); if( !game_state ) game_time += SOUND_get_time( background_sound ); }
TEST(GrayPixel, OperatorSum) { GrayPixel p1(3); GrayPixel p2(234); GrayPixel result = p1 + p2; ASSERT_TRUE(result.getV() == 237); }
MenuExample::MenuExample( QWidget *parent, const char *name ) : QWidget( parent, name ) { QPixmap p1( p1_xpm ); QPixmap p2( p2_xpm ); QPixmap p3( p3_xpm ); QPopupMenu *print = new QPopupMenu( this ); CHECK_PTR( print ); print->insertTearOffHandle(); print->insertItem( "&Print to printer", this, SLOT(printer()) ); print->insertItem( "Print to &file", this, SLOT(file()) ); print->insertItem( "Print to fa&x", this, SLOT(fax()) ); print->insertSeparator(); print->insertItem( "Printer &Setup", this, SLOT(printerSetup()) ); QPopupMenu *file = new QPopupMenu( this ); CHECK_PTR( file ); file->insertItem( p1, "&Open", this, SLOT(open()), CTRL+Key_O ); file->insertItem( p2, "&New", this, SLOT(news()), CTRL+Key_N ); file->insertItem( p3, "&Save", this, SLOT(save()), CTRL+Key_S ); file->insertItem( "&Close", this, SLOT(closeDoc()), CTRL+Key_W ); file->insertSeparator(); file->insertItem( "&Print", print, CTRL+Key_P ); file->insertSeparator(); file->insertItem( "E&xit", qApp, SLOT(quit()), CTRL+Key_Q ); QPopupMenu *edit = new QPopupMenu( this ); CHECK_PTR( edit ); int undoID = edit->insertItem( "&Undo", this, SLOT(undo()) ); int redoID = edit->insertItem( "&Redo", this, SLOT(redo()) ); edit->setItemEnabled( undoID, FALSE ); edit->setItemEnabled( redoID, FALSE ); QPopupMenu* options = new QPopupMenu( this ); CHECK_PTR( options ); options->insertTearOffHandle(); options->setCaption("Options"); options->insertItem( "&Normal Font", this, SLOT(normal()) ); options->insertSeparator(); options->polish(); // adjust system settings QFont f = options->font(); f.setBold( TRUE ); boldID = options->insertItem( new MyMenuItem( "&Bold", f ) ); options->setAccel( CTRL+Key_B, boldID ); options->connectItem( boldID, this, SLOT(bold()) ); f = font(); f.setUnderline( TRUE ); underlineID = options->insertItem( new MyMenuItem( "&Underline", f ) ); options->setAccel( CTRL+Key_U, underlineID ); options->connectItem( underlineID, this, SLOT(underline()) ); isBold = FALSE; isUnderline = FALSE; options->setCheckable( TRUE ); QPopupMenu *help = new QPopupMenu( this ); CHECK_PTR( help ); help->insertItem( "&About", this, SLOT(about()), CTRL+Key_H ); help->insertItem( "About &Qt", this, SLOT(aboutQt()) ); menu = new QMenuBar( this ); CHECK_PTR( menu ); menu->insertItem( "&File", file ); menu->insertItem( "&Edit", edit ); menu->insertItem( "&Options", options ); menu->insertSeparator(); menu->insertItem( "&Help", help ); menu->setSeparator( QMenuBar::InWindowsStyle ); label = new QLabel( this ); CHECK_PTR( label ); label->setGeometry( 20, rect().center().y()-20, width()-40, 40 ); label->setFrameStyle( QFrame::Box | QFrame::Raised ); label->setLineWidth( 1 ); label->setAlignment( AlignCenter ); connect( this, SIGNAL(explain(const QString&)), label, SLOT(setText(const QString&)) ); setMinimumSize( 100, 80 ); }
bool CCurve::CheckForArc(const CVertex& prev_vt, std::list<const CVertex*>& might_be_an_arc, CArc &arc_returned) { // this examines the vertices in might_be_an_arc // if they do fit an arc, set arc to be the arc that they fit and return true // returns true, if arc added if(might_be_an_arc.size() < 2)return false; // find middle point int num = static_cast<int>(might_be_an_arc.size()); int i = 0; const CVertex* mid_vt = NULL; int mid_i = (num-1)/2; for(std::list<const CVertex*>::iterator It = might_be_an_arc.begin(); It != might_be_an_arc.end(); It++, i++) { if(i == mid_i) { mid_vt = *It; break; } } // create a circle to test Point p0(prev_vt.m_p); Point p1(mid_vt->m_p); Point p2(might_be_an_arc.back()->m_p); Circle c(p0, p1, p2); const CVertex* current_vt = &prev_vt; double accuracy = CArea::m_accuracy * 1.4 / CArea::m_units; for(std::list<const CVertex*>::iterator It = might_be_an_arc.begin(); It != might_be_an_arc.end(); It++) { const CVertex* vt = *It; if(!c.LineIsOn(current_vt->m_p, vt->m_p, accuracy)) return false; current_vt = vt; } CArc arc; arc.m_c = c.m_c; arc.m_s = prev_vt.m_p; arc.m_e = might_be_an_arc.back()->m_p; arc.SetDirWithPoint(might_be_an_arc.front()->m_p); arc.m_user_data = might_be_an_arc.back()->m_user_data; double angs = atan2(arc.m_s.y - arc.m_c.y, arc.m_s.x - arc.m_c.x); double ange = atan2(arc.m_e.y - arc.m_c.y, arc.m_e.x - arc.m_c.x); if(arc.m_dir) { // make sure ange > angs if(ange < angs)ange += 6.2831853071795864; } else { // make sure angs > ange if(angs < ange)angs += 6.2831853071795864; } if(arc.IncludedAngle() >= 3.15)return false; // We don't want full arcs, so limit to about 180 degrees for(std::list<const CVertex*>::iterator It = might_be_an_arc.begin(); It != might_be_an_arc.end(); It++) { const CVertex* vt = *It; double angp = atan2(vt->m_p.y - arc.m_c.y, vt->m_p.x - arc.m_c.x); if(arc.m_dir) { // make sure angp > angs if(angp < angs)angp += 6.2831853071795864; if(angp > ange)return false; } else { // make sure angp > ange if(angp < ange)angp += 6.2831853071795864; if(angp > angs)return false; } } arc_returned = arc; return true; }
TEST(VectorTest, Addition) { Vector_i p1(1, 2); Vector_i p2(4, 4); EXPECT_EQ(Vector_i(5, 6), p1 + p2); }
void AngleBendContrib::getGrad(double *pos,double *grad) const { PRECONDITION(dp_forceField,"no owner"); PRECONDITION(pos,"bad vector"); PRECONDITION(grad,"bad vector"); double dist1=this->dp_forceField->distance(this->d_at1Idx,this->d_at2Idx,pos); double dist2=this->dp_forceField->distance(this->d_at2Idx,this->d_at3Idx,pos); //std::cout << "\tAngle("<<this->d_at1Idx<<","<<this->d_at2Idx<<","<<this->d_at3Idx<<") " << dist1 << " " << dist2 << std::endl; RDGeom::Point3D p1(pos[3*this->d_at1Idx], pos[3*this->d_at1Idx+1], pos[3*this->d_at1Idx+2]); RDGeom::Point3D p2(pos[3*this->d_at2Idx], pos[3*this->d_at2Idx+1], pos[3*this->d_at2Idx+2]); RDGeom::Point3D p3(pos[3*this->d_at3Idx], pos[3*this->d_at3Idx+1], pos[3*this->d_at3Idx+2]); double *g1=&(grad[3*this->d_at1Idx]); double *g2=&(grad[3*this->d_at2Idx]); double *g3=&(grad[3*this->d_at3Idx]); RDGeom::Point3D p12=p1-p2; RDGeom::Point3D p32=p3-p2; double cosTheta = p12.dotProduct(p32)/(dist1*dist2); double sinTheta = std::max(sqrt(1.0-cosTheta*cosTheta),1e-8); //std::cerr << "GRAD: " << cosTheta << " (" << acos(cosTheta)<< "), "; //std::cerr << sinTheta << " (" << asin(sinTheta)<< ")" << std::endl; // use the chain rule: // dE/dx = dE/dTheta * dTheta/dx // dE/dTheta is independent of cartesians: double dE_dTheta=getThetaDeriv(cosTheta,sinTheta); // ------- // dTheta/dx is trickier: double dCos_dS1=1./dist1 * (p32.x/dist2 - cosTheta*p12.x/dist1); double dCos_dS2=1./dist1 * (p32.y/dist2 - cosTheta*p12.y/dist1); double dCos_dS3=1./dist1 * (p32.z/dist2 - cosTheta*p12.z/dist1); double dCos_dS4=1./dist2 * (p12.x/dist1 - cosTheta*p32.x/dist2); double dCos_dS5=1./dist2 * (p12.y/dist1 - cosTheta*p32.y/dist2); double dCos_dS6=1./dist2 * (p12.z/dist1 - cosTheta*p32.z/dist2); g1[0] += dE_dTheta*dCos_dS1/(-sinTheta); g1[1] += dE_dTheta*dCos_dS2/(-sinTheta); g1[2] += dE_dTheta*dCos_dS3/(-sinTheta); g2[0] += dE_dTheta*(-dCos_dS1 - dCos_dS4)/(-sinTheta); g2[1] += dE_dTheta*(-dCos_dS2 - dCos_dS5)/(-sinTheta); g2[2] += dE_dTheta*(-dCos_dS3 - dCos_dS6)/(-sinTheta); g3[0] += dE_dTheta*dCos_dS4/(-sinTheta); g3[1] += dE_dTheta*dCos_dS5/(-sinTheta); g3[2] += dE_dTheta*dCos_dS6/(-sinTheta); }
TEST(VectorTest, Cast) { Vector_i p1(4, 4); Vector_f p2(4.122332, 4.423232); EXPECT_EQ(p1, static_cast<Vector<int>>(p2)); }
/* * Dump TCP statistics structure. */ void tcp_stats(u_long off __unused, const char *name, int af1 __unused) { struct tcp_stats tcpstat, *stattmp; struct tcp_stats zerostat[SMP_MAXCPU]; size_t len = sizeof(struct tcp_stats) * SMP_MAXCPU; int cpucnt; if (zflag) memset(zerostat, 0, len); if ((stattmp = malloc(len)) == NULL) { return; } else { if (sysctlbyname("net.inet.tcp.stats", stattmp, &len, zflag ? zerostat : NULL, zflag ? len : 0) < 0) { warn("sysctl: net.inet.tcp.stats"); free(stattmp); return; } else { if ((stattmp = realloc(stattmp, len)) == NULL) { warn("tcp_stats"); return; } } } cpucnt = len / sizeof(struct tcp_stats); tcp_stats_agg(stattmp, &tcpstat, cpucnt); #ifdef INET6 if (tcp_done != 0) return; else tcp_done = 1; #endif printf ("%s:\n", name); #define p(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, tcpstat.f, plural(tcpstat.f)) #define p1a(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, tcpstat.f) #define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2)) #define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2) #define p3(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, tcpstat.f, plurales(tcpstat.f)) p(tcps_sndtotal, "\t%lu packet%s sent\n"); p2(tcps_sndpack,tcps_sndbyte, "\t\t%lu data packet%s (%lu byte%s)\n"); p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t%lu data packet%s (%lu byte%s) retransmitted\n"); p2(tcps_sndsackpack, tcps_sndsackbyte, "\t\t%lu data packet%s (%lu byte%s) sent by SACK recovery\n"); p2(tcps_sndsackrtopack, tcps_sndsackrtobyte, "\t\t%lu data packet%s (%lu byte%s) retransmitted by SACK\n"); p2a(tcps_sndfastrexmit, tcps_sndearlyrexmit, "\t\t%lu Fast Retransmit%s (%lu early)\n"); p(tcps_sndlimited, "\t\t%lu packet%s sent by Limited Transmit\n"); p(tcps_sndrtobad, "\t\t%lu spurious RTO retransmit%s\n"); p2a(tcps_sndfastrexmitbad, tcps_sndearlyrexmitbad, "\t\t%lu spurious Fast Retransmit%s (%lu early)\n"); p2a(tcps_eifeldetected, tcps_rttcantdetect, "\t\t%lu Eifel-detected spurious retransmit%s (%lu non-RTT)\n"); p(tcps_rttdetected, "\t\t%lu RTT-detected spurious retransmit%s\n"); p(tcps_mturesent, "\t\t%lu resend%s initiated by MTU discovery\n"); p(tcps_sndsackopt, "\t\t%lu SACK option%s sent\n"); p(tcps_snddsackopt, "\t\t%lu D-SACK option%s sent\n"); p2a(tcps_sndacks, tcps_delack, "\t\t%lu ack-only packet%s (%lu delayed)\n"); p(tcps_sndurg, "\t\t%lu URG only packet%s\n"); p(tcps_sndprobe, "\t\t%lu window probe packet%s\n"); p(tcps_sndwinup, "\t\t%lu window update packet%s\n"); p(tcps_sndctrl, "\t\t%lu control packet%s\n"); p(tcps_rcvtotal, "\t%lu packet%s received\n"); p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t%lu ack%s (for %lu byte%s)\n"); p(tcps_rcvdupack, "\t\t%lu duplicate ack%s\n"); p(tcps_rcvacktoomuch, "\t\t%lu ack%s for unsent data\n"); p2(tcps_rcvpack, tcps_rcvbyte, "\t\t%lu packet%s (%lu byte%s) received in-sequence\n"); p2(tcps_rcvduppack, tcps_rcvdupbyte, "\t\t%lu completely duplicate packet%s (%lu byte%s)\n"); p(tcps_pawsdrop, "\t\t%lu old duplicate packet%s\n"); p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, "\t\t%lu packet%s with some dup. data (%lu byte%s duped)\n"); p2(tcps_rcvoopack, tcps_rcvoobyte, "\t\t%lu out-of-order packet%s (%lu byte%s)\n"); p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, "\t\t%lu packet%s (%lu byte%s) of data after window\n"); p(tcps_rcvwinprobe, "\t\t%lu window probe%s\n"); p(tcps_rcvwinupd, "\t\t%lu window update packet%s\n"); p(tcps_rcvafterclose, "\t\t%lu packet%s received after close\n"); p(tcps_rcvbadsum, "\t\t%lu discarded for bad checksum%s\n"); p(tcps_rcvbadoff, "\t\t%lu discarded for bad header offset field%s\n"); p1a(tcps_rcvshort, "\t\t%lu discarded because packet too short\n"); p(tcps_rcvbadsackopt, "\t\t%lu bad SACK option%s\n"); p(tcps_connattempt, "\t%lu connection request%s\n"); p(tcps_accepts, "\t%lu connection accept%s\n"); p(tcps_badsyn, "\t%lu bad connection attempt%s\n"); p(tcps_listendrop, "\t%lu listen queue overflow%s\n"); p(tcps_connects, "\t%lu connection%s established (including accepts)\n"); p2(tcps_closed, tcps_drops, "\t%lu connection%s closed (including %lu drop%s)\n"); p(tcps_cachedrtt, "\t\t%lu connection%s updated cached RTT on close\n"); p(tcps_cachedrttvar, "\t\t%lu connection%s updated cached RTT variance on close\n"); p(tcps_cachedssthresh, "\t\t%lu connection%s updated cached ssthresh on close\n"); p(tcps_conndrops, "\t%lu embryonic connection%s dropped\n"); p2(tcps_rttupdated, tcps_segstimed, "\t%lu segment%s updated rtt (of %lu attempt%s)\n"); p(tcps_rexmttimeo, "\t%lu retransmit timeout%s\n"); p(tcps_timeoutdrop, "\t\t%lu connection%s dropped by rexmit timeout\n"); p(tcps_persisttimeo, "\t%lu persist timeout%s\n"); p(tcps_persistdrop, "\t\t%lu connection%s dropped by persist timeout\n"); p(tcps_keeptimeo, "\t%lu keepalive timeout%s\n"); p(tcps_keepprobe, "\t\t%lu keepalive probe%s sent\n"); p(tcps_keepdrops, "\t\t%lu connection%s dropped by keepalive\n"); p(tcps_predack, "\t%lu correct ACK header prediction%s\n"); p(tcps_preddat, "\t%lu correct data packet header prediction%s\n"); p1a(tcps_sc_added, "\t%lu syncache entries added\n"); p1a(tcps_sc_retransmitted, "\t\t%lu retransmitted\n"); p1a(tcps_sc_dupsyn, "\t\t%lu dupsyn\n"); p1a(tcps_sc_dropped, "\t\t%lu dropped\n"); p1a(tcps_sc_completed, "\t\t%lu completed\n"); p1a(tcps_sc_bucketoverflow, "\t\t%lu bucket overflow\n"); p1a(tcps_sc_cacheoverflow, "\t\t%lu cache overflow\n"); p1a(tcps_sc_reset, "\t\t%lu reset\n"); p1a(tcps_sc_stale, "\t\t%lu stale\n"); p1a(tcps_sc_aborted, "\t\t%lu aborted\n"); p1a(tcps_sc_badack, "\t\t%lu badack\n"); p1a(tcps_sc_unreach, "\t\t%lu unreach\n"); p1a(tcps_sc_zonefail, "\t\t%lu zone failures\n"); p1a(tcps_sc_sendcookie, "\t\t%lu cookies sent\n"); p1a(tcps_sc_recvcookie, "\t\t%lu cookies received\n"); p(tcps_sacksbupdate, "\t%lu SACK scoreboard update%s\n"); p(tcps_sacksboverflow, "\t\t%lu overflow%s\n"); p(tcps_sacksbfailed, "\t\t%lu failure%s\n"); p(tcps_sacksbreused, "\t\t%lu record%s reused\n"); free(stattmp); #undef p #undef p1a #undef p2 #undef p2a #undef p3 }
/** * メッシュ情報を読み込む * * @param mesh メッシュ情報 */ void FbxFileLoader::load_mesh( FbxMesh* mesh ) { if ( ! mesh ) { return; } if ( ! get_model()->get_mesh() ) { get_model()->set_mesh( create_mesh() ); } VertexIndexMap vertex_index_map; VertexList vertex_list; Mesh::PositionList position_list; Mesh::VertexWeightList vertex_weight_list; // load_mesh_vertex() for ( int n = 0; n < mesh->GetControlPointsCount(); n++ ) { FbxVector4 v = mesh->GetControlPointAt( n ); position_list.push_back( Mesh::Position( static_cast< float >( v[ 0 ] ), static_cast< float >( v[ 1 ] ), static_cast< float >( v[ 2 ] ) ) ); } // load_mesh_vertex_weight() { int skin_count = mesh->GetDeformerCount( FbxDeformer::eSkin ); if ( skin_count > 0 ) { assert( skin_count == 1 ); vertex_weight_list.resize( position_list.size() ); FbxSkin* skin = FbxCast< FbxSkin >( mesh->GetDeformer( 0, FbxDeformer::eSkin ) ); load_mesh_vertex_weight( skin, vertex_weight_list ); } } FbxLayerElementSmoothing* smoothing = 0; // load_mesh_smoothing_info() { FbxLayer* layer = mesh->GetLayer( 0 ); smoothing = layer->GetSmoothing(); } if ( ! smoothing ) { COMMON_THROW_EXCEPTION_MESSAGE( "this FBX format is not supported. ( no smoothing info )" ); } // load_mesh_plygon() FbxLayerElementArrayTemplate< int >* material_indices; mesh->GetMaterialIndices( & material_indices ); for ( int n = 0; n < mesh->GetPolygonCount(); n++ ) { Mesh::VertexGroup* vertex_group = get_model()->get_mesh()->get_vertex_group_at( material_indices->GetAt( n ) ); bool is_smooth = smoothing->GetDirectArray().GetAt( n ) != 0; FbxVector4 polygon_normal( 0.f, 0.f, 0.f ); if ( ! is_smooth ) { // ポリゴンの法線を計算する Mesh::Position p1( position_list.at( mesh->GetPolygonVertex( n, 0 ) ) ); Mesh::Position p2( position_list.at( mesh->GetPolygonVertex( n, 1 ) ) ); Mesh::Position p3( position_list.at( mesh->GetPolygonVertex( n, 2 ) ) ); FbxVector4 a = FbxVector4( p1.x(), p1.y(), p1.z() ); FbxVector4 b = FbxVector4( p2.x(), p2.y(), p2.z() ); FbxVector4 c = FbxVector4( p3.x(), p3.y(), p3.z() ); FbxVector4 ab( b - a ); FbxVector4 bc( c - b ); polygon_normal = ab.CrossProduct( bc ); polygon_normal.Normalize(); } for ( int m = 0; m < mesh->GetPolygonSize( n ); m++ ) { int position_index = mesh->GetPolygonVertex( n, m ); Mesh::Vertex v; v.Position = Mesh::Position( position_list.at( position_index ) ); FbxVector2 uv_vector; bool unmapped; if ( mesh->GetPolygonVertexUV( n, m, "UVMap", uv_vector, unmapped) ) { v.TexCoord = Mesh::TexCoord( static_cast< float >( uv_vector[ 0 ] ), 1.f - static_cast< float >( uv_vector[ 1 ] ) ); } if ( is_smooth ) { FbxVector4 normal_vector; // 頂点の法線 if ( mesh->GetPolygonVertexNormal( n, m, normal_vector ) ) { v.Normal = Mesh::Normal( static_cast< float >( normal_vector[ 0 ] ), static_cast< float >( normal_vector[ 1 ] ), static_cast< float >( normal_vector[ 2 ] ) ); } } else { // ポリゴンの法線 v.Normal = Mesh::Normal( static_cast< float >( polygon_normal[ 0 ] ), static_cast< float >( polygon_normal[ 1 ] ), static_cast< float >( polygon_normal[ 2 ] ) ); } // 頂点の一覧に追加 { VertexIndexMap::iterator i = vertex_index_map.find( v ); if ( i != vertex_index_map.end() ) { vertex_group->add_index( i->second ); } else { Mesh::Index vertex_index = static_cast< Mesh::Index >( get_model()->get_mesh()->get_vertex_count() ); get_model()->get_mesh()->add_vertex( v ); if ( ! vertex_weight_list.empty() ) { get_model()->get_mesh()->add_vertex_weight( vertex_weight_list.at( position_index ) ); } vertex_group->add_index( vertex_index ); vertex_index_map[ v ] = vertex_index; } } } } }
/* * Dump ICMP statistics. */ void icmp_stats(u_long off __unused, const char *name, int af1 __unused) { struct icmpstat icmpstat, zerostat; int i, first; int mib[4]; /* CTL_NET + PF_INET + IPPROTO_ICMP + req */ size_t len; mib[0] = CTL_NET; mib[1] = PF_INET; mib[2] = IPPROTO_ICMP; mib[3] = ICMPCTL_STATS; len = sizeof icmpstat; if (zflag) memset(&zerostat, 0, len); if (sysctl(mib, 4, &icmpstat, &len, zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { warn("sysctl: net.inet.icmp.stats"); return; } printf("%s:\n", name); #define p(f, m) if (icmpstat.f || sflag <= 1) \ printf(m, icmpstat.f, plural(icmpstat.f)) #define p1a(f, m) if (icmpstat.f || sflag <= 1) \ printf(m, icmpstat.f) #define p2(f, m) if (icmpstat.f || sflag <= 1) \ printf(m, icmpstat.f, plurales(icmpstat.f)) p(icps_error, "\t%lu call%s to icmp_error\n"); p(icps_oldicmp, "\t%lu error%s not generated 'cuz old message was icmp\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) if (icmpstat.icps_outhist[i] != 0) { if (first) { printf("\tOutput histogram:\n"); first = 0; } printf("\t\t%s: %lu\n", icmpnames[i], icmpstat.icps_outhist[i]); } p(icps_badcode, "\t%lu message%s with bad code fields\n"); p(icps_tooshort, "\t%lu message%s < minimum length\n"); p(icps_checksum, "\t%lu bad checksum%s\n"); p(icps_badlen, "\t%lu message%s with bad length\n"); p1a(icps_bmcastecho, "\t%lu multicast echo requests ignored\n"); p1a(icps_bmcasttstamp, "\t%lu multicast timestamp requests ignored\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) if (icmpstat.icps_inhist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } printf("\t\t%s: %lu\n", icmpnames[i], icmpstat.icps_inhist[i]); } p(icps_reflect, "\t%lu message response%s generated\n"); p2(icps_badaddr, "\t%lu invalid return address%s\n"); p(icps_noroute, "\t%lu no return route%s\n"); #undef p #undef p1a #undef p2 mib[3] = ICMPCTL_MASKREPL; len = sizeof i; if (sysctl(mib, 4, &i, &len, NULL, 0) < 0) return; printf("\tICMP address mask responses are %sabled\n", i ? "en" : "dis"); }
void MonthWidget::paintEvent(QPaintEvent*) { QRect cr(contentsRect()); QPixmap pix(cr.width(), cr.height()); QFont fnBold(font()); QFont fnOrig(font()); fnBold.setBold(true); fnOrig.setBold(false); QPainter p(&pix); p.fillRect(0, 0, cr.width(), cr.height(), palette().color(QPalette::Background)); QRect r(0, 0, d->currw, d->currh); QRect rsmall; int sx, sy; int index = 0; bool weekvisible; for (int j=3; j<9; ++j) { sy = d->currh * j; weekvisible = false; for (int i=1; i<8; ++i) { sx = d->currw * i; r.moveTopLeft(QPoint(sx,sy)); rsmall = QRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2); if (d->days[index].day != -1) { if (d->days[index].selected) { p.fillRect(r, palette().color(QPalette::Highlight)); p.setPen(palette().color(QPalette::HighlightedText)); if (d->days[index].active) { p.setFont(fnBold); } else { p.setFont(fnOrig); } } else { if (d->days[index].active) { p.setPen(palette().color(QPalette::Text)); p.setFont(fnBold); } else { p.setPen(palette().color(QPalette::Mid)); p.setFont(fnOrig); } } p.drawText(rsmall, Qt::AlignVCenter|Qt::AlignHCenter, QString::number(d->days[index].day)); if (!weekvisible) { int weeknr = KGlobal::locale()->calendar()->weekNumber(QDate(d->year, d->month, d->days[index].day)); p.setPen(d->active ? Qt::black : Qt::gray); p.setFont(fnBold); p.fillRect(1, sy, d->currw-1, d->currh-1, QColor(210,210,210)); p.drawText(1, sy, d->currw-1, d->currh-1, Qt::AlignVCenter|Qt::AlignHCenter, QString::number(weeknr)); weekvisible = true; } } ++index; } } p.setPen(d->active ? Qt::black : Qt::gray); p.setFont(fnBold); sy = 2*d->currh; for (int i=1; i<8; ++i) { sx = d->currw * i; r.moveTopLeft(QPoint(sx+1,sy+1)); rsmall = r; rsmall.setWidth(r.width() - 2); rsmall.setHeight(r.height() - 2); p.drawText(rsmall, Qt::AlignVCenter|Qt::AlignHCenter, KGlobal::locale()->calendar()->weekDayName(i, KCalendarSystem::ShortDayName) .remove(2,1)); ++index; } r = QRect(0, 0, cr.width(), 2*d->currh); fnBold.setPointSize(fnBold.pointSize()+2); p.setFont(fnBold); p.drawText(r, Qt::AlignCenter, QString("%1 %2") .arg(KGlobal::locale()->calendar()->monthName(d->month, KCalendarSystem::LongDayName)) .arg(KGlobal::locale()->calendar()->year(QDate(d->year,d->month,1)))); p.end(); QPainter p2(this); p2.drawPixmap(cr.x(), cr.y(), pix); p2.end(); }
void main() { LinkedList list; Point p1(17.0f,12.5f); Point p2(1.0f,99.0f); Point p3(38.0f,1.2f); list.GetItem(); /*list.Add(p1); list.Add(p2); list.Add(p3); list.Head(); std::cout << list.GetItem().X() << std::endl; std::cout << list.GetItem().Y() << std::endl << std::endl; list.Next(); std::cout << list.GetItem().X() << std::endl; std::cout << list.GetItem().Y() << std::endl << std::endl; list.Prev(); std::cout << list.GetItem().X() << std::endl; std::cout << list.GetItem().Y() << std::endl << std::endl; list.Tail(); std::cout << list.GetItem().X() << std::endl; std::cout << list.GetItem().Y() << std::endl << std::endl; LinkedList list2; list2.Add(Point(99,55)); list2.Add(Point(88,55)); list2.Add(Point(77,55)); list2.Add(Point(66,55)); list2.Head(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; list2.Next(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; list2.Tail(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; list2.Prev(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; list2.Remove(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; list2.Remove(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; list2.Head(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; list2.Remove(); std::cout << list2.GetItem().X() << std::endl; std::cout << list2.GetItem().Y() << std::endl << std::endl; StackFIFO StackF; StackF.Add(Point(99,11)); StackF.Add(Point(88,11)); StackF.Add(Point(77,11)); StackF.Add(Point(66,11)); StackF.Add(Point(55,11)); Point p1 = StackF.Get(); Point p2 = StackF.Get(); StackLIFO StackL; StackL.Add(Point(99,11)); StackL.Add(Point(88,11)); StackL.Add(Point(77,11)); StackL.Add(Point(66,11)); StackL.Add(Point(55,11)); Point p1 = StackL.Pop(); Point p2 = StackL.Pick();*/ }
void OpenPSTD::GUI::DGResults::UpdateScene(const std::shared_ptr<OpenPSTD::GUI::Model> &m, std::unique_ptr<QOpenGLFunctions, void (*)(void *)> const &f) { program->bind(); if(m->view->IsChanged()) { program->setUniformValue("u_view", m->view->viewMatrix); } auto doc = m->documentAccess->GetDocument(); if(m->interactive->visibleFrame >= 0 && m->interactive->visibleFrame < doc->GetResultsDGFrameCount()) { if (m->documentAccess->IsChanged()) { auto conf = doc->GetResultsSceneConf(); std::vector<QVector2D> positions; positions.reserve(conf->DGIndices.size() * 3); MinMaxValue minMaxPos; for (int i = 0; i < conf->DGIndices.size(); ++i) { //create the 3 points QVector2D p1(conf->DGVertices[conf->DGIndices[i][0]](0), conf->DGVertices[conf->DGIndices[i][0]](1)); QVector2D p2(conf->DGVertices[conf->DGIndices[i][1]](0), conf->DGVertices[conf->DGIndices[i][1]](1)); QVector2D p3(conf->DGVertices[conf->DGIndices[i][2]](0), conf->DGVertices[conf->DGIndices[i][2]](1)); //update min max values minMaxPos = MinMaxValue::Combine(minMaxPos, MinMaxValue(p1, p2)); //add to vector positions.push_back(p1); positions.push_back(p2); positions.push_back(p3); } triangles = conf->DGIndices.size(); this->minMaxPos = minMaxPos; f->glBindBuffer(GL_ARRAY_BUFFER, this->positionsBuffer); f->glBufferData(GL_ARRAY_BUFFER, positions.size() * sizeof(QVector2D), positions.data(), GL_STATIC_DRAW); } if (m->interactive->IsChanged()) { Kernel::DG_FRAME_PTR frame = doc->GetResultsDGFrameCorner(m->interactive->visibleFrame); std::vector<float> values(frame->rows() * frame->cols()); Eigen::Map<Kernel::DG_FRAME> map(values.data(), frame->rows(), frame->cols()); map = *frame; f->glBindBuffer(GL_ARRAY_BUFFER, this->valuesBuffer); f->glBufferData(GL_ARRAY_BUFFER, values.size() * sizeof(float), values.data(), GL_DYNAMIC_DRAW); valuesInitialized = true; } } }
void cveRectangle(cv::_InputOutputArray* img, CvRect* rect, CvScalar* color, int thickness, int lineType, int shift) { cv::Point p1(rect->x, rect->y); cv::Point p2(rect->x + rect->width, rect->y + rect->height); cv::rectangle(*img, p1, p2, *color, thickness, lineType, shift); }