dgInt32 dgCollisionInstance::CalculatePlaneIntersection (const dgVector& normal, const dgVector& point, dgVector* const contactsOut) const { dgInt32 count = 0; dgAssert(normal.m_w == dgFloat32 (0.0f)); switch (m_scaleType) { case m_unit: { count = m_childShape->CalculatePlaneIntersection (normal, point, contactsOut); break; } case m_uniform: { dgVector point1 (m_invScale * point); count = m_childShape->CalculatePlaneIntersection (normal, point1, contactsOut); for (dgInt32 i = 0; i < count; i ++) { contactsOut[i] = m_scale * contactsOut[i]; } break; } case m_nonUniform: { // support((p * S), n) = S * support (p, n * transp(S)) dgVector point1 (m_invScale * point); dgVector normal1 (m_scale * normal); normal1 = normal1.Normalize(); count = m_childShape->CalculatePlaneIntersection (normal1, point1, contactsOut); for (dgInt32 i = 0; i < count; i ++) { contactsOut[i] = m_scale * contactsOut[i]; } break; } case m_global: default: { dgVector point1 (m_aligmentMatrix.UntransformVector (m_invScale * point)); dgVector normal1 (m_aligmentMatrix.UntransformVector (m_scale * normal)); normal1 = normal1.Normalize(); count = m_childShape->CalculatePlaneIntersection (normal1, point1, contactsOut); for (dgInt32 i = 0; i < count; i ++) { contactsOut[i] = m_scale * m_aligmentMatrix.TransformVector(contactsOut[i]); } } } return count; }
void Arrow2D(const Point<float>& tail, const Point<float>& head) { // u-v-w - Arrow coordinate system: Vector<float> u, v, w; Vector<float> arrowLine(tail, head); GetOrthonormalBasisFromNormal(arrowLine, u, v, w); // set size of wings and turn w into a Unit vector: float d = WINGS * arrowLine.norm(); // draw the shaft of the arrow: glBegin(GL_LINE_STRIP); glVertex3f(tail.x(), tail.y(), tail.z()); glVertex3f(head.x(), head.y(), head.z()); glEnd(); Vector<float> point1(head.x() + d * (u.x() - w.x()), head.y() + d * (u.y() - w.y()), head.z() + d * (u.z() - w.z())); glBegin(GL_LINE_STRIP); glVertex3f(head.x(), head.y(), head.z()); glVertex3f(point1.x(), point1.y(), point1.z()); glEnd(); Vector<float> point2(head.x() + d * (-u.x() - w.x()), head.y() + d * (-u.y() - w.y()), head.z() + d * (-u.z() - w.z())); glBegin(GL_LINE_STRIP); glVertex3f(head.x(), head.y(), head.z()); glVertex3f(point2.x(), point2.y(), point2.z()); glEnd(); }
/** * This method parses a Python tuple and builds a CylinderVectorGenerator. * The arguments accepted are two triples of numbers and two numbers. Args * is not a borrowed object so it needs to have its reference count * decremented after use. * * @param args Python tuple containing initialisation information. * * @return A pointer to the newly created vector generator if successful; * NULL, otherwise. */ CylinderVectorGenerator *CylinderVectorGenerator::parsePythonTuple( PyObject *args ) { BW_GUARD; float x1, y1, z1; float x2, y2, z2; float maxRadius, minRadius; if ( PyArg_ParseTuple( args, "(fff)(fff)ff", &x1, &y1, &z1, &x2, &y2, &z2, &maxRadius, &minRadius ) ) { Vector3 point1( x1, y1, z1 ); Vector3 point2( x2, y2, z2 ); Py_DECREF( args ); return new CylinderVectorGenerator( point1, point2, maxRadius, minRadius ); } else { PyErr_SetString( PyExc_TypeError, "CylinderVectorGenerator:" "Expected (x1,y1,z1), (x2,y2,z2), maxRadius, minRadius." ); Py_DECREF( args ); return NULL; } }
void MyPrimitive::GenerateTorus(float a_fOuterRadius, float a_fInnerRadius, int a_nSubdivisionsA, int a_nSubdivisionsB, vector3 a_v3Color) { if (a_fOuterRadius <= a_fInnerRadius + 0.1f) return; if (a_nSubdivisionsA < 3) a_nSubdivisionsA = 3; if (a_nSubdivisionsA > 25) a_nSubdivisionsA = 25; if (a_nSubdivisionsB < 3) a_nSubdivisionsB = 3; if (a_nSubdivisionsB > 25) a_nSubdivisionsB = 25; Release(); Init(); //Your code starts here float fValue = 0.5f; //3--2 //| | //0--1 vector3 point0(-fValue, -fValue, fValue); //0 vector3 point1(fValue, -fValue, fValue); //1 vector3 point2(fValue, fValue, fValue); //2 vector3 point3(-fValue, fValue, fValue); //3 AddQuad(point0, point1, point3, point2); //Your code ends here CompileObject(a_v3Color); }
bool SVGPathParser::parseCurveToQuadraticSmoothSegment() { FloatPoint targetPoint; if (!m_source.parseCurveToQuadraticSmoothSegment(targetPoint)) return false; if (m_lastCommand != PathSegCurveToQuadraticAbs && m_lastCommand != PathSegCurveToQuadraticRel && m_lastCommand != PathSegCurveToQuadraticSmoothAbs && m_lastCommand != PathSegCurveToQuadraticSmoothRel) m_controlPoint = m_currentPoint; if (m_pathParsingMode == NormalizedParsing) { FloatPoint cubicPoint = m_currentPoint; cubicPoint.scale(2); cubicPoint.move(-m_controlPoint.x(), -m_controlPoint.y()); FloatPoint point1(m_currentPoint.x() + 2 * cubicPoint.x(), m_currentPoint.y() + 2 * cubicPoint.y()); FloatPoint point2(targetPoint.x() + 2 * cubicPoint.x(), targetPoint.y() + 2 * cubicPoint.y()); if (m_mode == RelativeCoordinates) { point2 += m_currentPoint; targetPoint += m_currentPoint; } point1.scale(gOneOverThree); point2.scale(gOneOverThree); m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); m_controlPoint = cubicPoint; m_currentPoint = targetPoint; } else m_consumer.curveToQuadraticSmooth(targetPoint, m_mode); return true; }
void ShadowScene::drawMagicCircle(){ int interval = 360/64; //ここの値を変えてみよう int max_num = 360 / interval; for (int angle = 0; angle < 360; angle+=interval) { if (angle > 360) angle = 360; int cur_num = angle / interval; float radius = 0.0f; Vector3<float> center(0.0f,0.0f,0.0f); Vector2<double> texcoc(0.5,0.5); radius = DEGREE_TO_RADIAN(angle); Vector3<float> point1(cos(radius),0.0f,sin(radius)); Vector2<double> texco1((cos(radius) + 1)/2,(sin(radius) + 1)/2); radius = DEGREE_TO_RADIAN(angle + interval); Vector3<float> point2(cos(radius),0.0f,sin(radius)); Vector2<double> texco2((cos(radius) + 1)/2,(sin(radius) + 1)/2); Vector3<float> normal(0.0f,1.0f,0.0f); //座標変換等の開始 glPushMatrix(); glBegin(GL_TRIANGLES); //描画の開始 glNormal3fv(normal.v); //法線の定義 glTexCoord2d(texcoc.x, texcoc.y); glVertex3fv(center.v); //頂点3個目 glTexCoord2d(texco1.x, texco1.y); glVertex3fv(point1.v); //頂点2個目 glTexCoord2d(texco2.x, texco2.y); glVertex3fv(point2.v); //頂点1個目 //描画の終了 glEnd(); //座標変換の終了 glPopMatrix(); } }
void MyPrimitive::GenerateTube(float a_fOuterRadius, float a_fInnerRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color) { if (a_nSubdivisions < 3) a_nSubdivisions = 3; if (a_nSubdivisions > 360) a_nSubdivisions = 360; Release(); Init(); for (int i = 0; i < a_nSubdivisions; i++) { float ang = (2 * PI) / a_nSubdivisions; vector3 point0(a_fOuterRadius*cos((i + 1)*ang), a_fHeight, a_fOuterRadius*sin((i + 1)*ang)); //1 vector3 point1(a_fOuterRadius*cos(i*ang), 0, a_fOuterRadius*sin(i*ang)); //2 vector3 point2(a_fOuterRadius*cos(i*ang), a_fHeight, a_fOuterRadius*sin(i*ang)); //0 vector3 point3(a_fOuterRadius*cos((i + 1)*ang), 0, a_fOuterRadius*sin((i + 1)*ang)); //3 vector3 point4(a_fInnerRadius*cos((i + 1)*ang), a_fHeight, a_fInnerRadius*sin((i + 1)*ang)); //1 vector3 point5(a_fInnerRadius*cos(i*ang), 0, a_fInnerRadius*sin(i*ang)); //2 vector3 point6(a_fInnerRadius*cos(i*ang), a_fHeight, a_fInnerRadius*sin(i*ang)); //0 vector3 point7(a_fInnerRadius*cos((i + 1)*ang), 0, a_fInnerRadius*sin((i + 1)*ang)); //3 AddQuad(point4, point0, point6, point2); //Top AddQuad(point0, point3, point2, point1); //Outer AddQuad(point7, point5, point3, point1); //Bottom AddQuad(point5, point7, point6,point4 ); // Inner } //Your code ends here CompileObject(a_v3Color); }
BaseIF* makeChamber(const Real& radius, const Real& thick, const Real& offset, const Real& height) { RealVect zero(D_DECL(0.0,0.0,0.0)); RealVect xAxis(D_DECL(1.0,0.0,0.0)); bool inside = true; Vector<BaseIF*> pieces; // Create a chamber TiltedCylinderIF chamberOut(radius + thick/2.0,xAxis,zero, inside); TiltedCylinderIF chamberIn (radius - thick/2.0,xAxis,zero,!inside); IntersectionIF infiniteChamber(chamberIn,chamberOut); pieces.push_back(&infiniteChamber); RealVect normal1(D_DECL(1.0,0.0,0.0)); RealVect point1(D_DECL(offset,0.0,0.0)); PlaneIF plane1(normal1,point1,inside); pieces.push_back(&plane1); RealVect normal2(D_DECL(-1.0,0.0,0.0)); RealVect point2(D_DECL(offset+height,0.0,0.0)); PlaneIF plane2(normal2,point2,inside); pieces.push_back(&plane2); IntersectionIF* chamber = new IntersectionIF(pieces); return chamber; }
void NormalQuantifier::build (UInt32 numberSubdivisions) { UInt32 index = 0; UInt32 nN = ((1 << (2 * numberSubdivisions)) * 8); _numberSubdivisions = numberSubdivisions; _normalTable.resize(nN); if(_numberSubdivisions != 0) { for(UInt32 octant = 0; octant < 8; octant++) { Int32 xoctant = (octant & 4)>0?-1:1; Int32 yoctant = (octant & 2)>0?-1:1; Int32 zoctant = (octant & 1)>0?-1:1; Vec3f point1(0.f * xoctant, 0.f * yoctant, 1.f * zoctant); Vec3f point2(1.f * xoctant, 0.f * yoctant, 0.f * zoctant); Vec3f point3(0.f * xoctant, 1.f * yoctant, 0.f * zoctant); subdivide(point1, point2, point3, _numberSubdivisions+1, index); } if(index != nN) { FFATAL(("NormalQuantifier::build() index missmatch!\n")); } else { FLOG(("NormalQuantifier init: %d subdivision, %d normal\n", _numberSubdivisions, _normalTable.size())); } } }
BaseIF* makeVane(const Real& thick, const RealVect& normal, const Real& innerRadius, const Real& outerRadius, const Real& offset, const Real& height) { RealVect zero(D_DECL(0.0,0.0,0.0)); RealVect xAxis(D_DECL(1.0,0.0,0.0)); bool inside = true; Vector<BaseIF*> vaneParts; // Each side of the vane (infinite) RealVect normal1(normal); RealVect point1(D_DECL(offset+height/2.0,-thick/2.0,0.0)); PlaneIF plane1(normal1,point1,inside); vaneParts.push_back(&plane1); RealVect normal2(-normal); RealVect point2(D_DECL(offset+height/2.0,thick/2.0,0.0)); PlaneIF plane2(normal2,point2,inside); vaneParts.push_back(&plane2); // Make sure we only get something to the right of the origin RealVect normal3(D_DECL(0.0,0.0,1.0)); RealVect point3(D_DECL(0.0,0.0,0.0)); PlaneIF plane3(normal3,point3,inside); vaneParts.push_back(&plane3); // Cut off the top and bottom RealVect normal4(D_DECL(1.0,0.0,0.0)); RealVect point4(D_DECL(offset,0.0,0.0)); PlaneIF plane4(normal4,point4,inside); vaneParts.push_back(&plane4); RealVect normal5(D_DECL(-1.0,0.0,0.0)); RealVect point5(D_DECL(offset+height,0.0,0.0)); PlaneIF plane5(normal5,point5,inside); vaneParts.push_back(&plane5); // The outside of the inner cylinder TiltedCylinderIF inner(innerRadius,xAxis,zero,!inside); vaneParts.push_back(&inner); // The inside of the outer cylinder TiltedCylinderIF outer(outerRadius,xAxis,zero,inside); vaneParts.push_back(&outer); IntersectionIF* vane = new IntersectionIF(vaneParts); return vane; }
int main() { // Take the counts per second (frequency) at the start of the program /*float dt = 0; __int64 cntsPerSec = 0; QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec); float secsPerCnt = 1.0f / (float)cntsPerSec; __int64 prevTimeStamp = 0; QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp); __int64 currTimeStamp = 0; do { QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp); dt = (currTimeStamp - prevTimeStamp) * secsPerCnt; std::cout << "Time: " << dt << std::endl; }while(dt <= 10);*/ /*Clock myClock = Clock(); do { myClock.SetDeltaTime(); std::cout << "Time: " << myClock.GetDeltaTime() << std::endl; }while(myClock.GetDeltaTime() <= 10);*/ Point2D point1(3.0, 0.0); Point2D point2(1.5, 0.0); bool bCheck= CollisionCheck2D_AABB(point1, point2) ; std::cout << "The distance between Point1: (" << point1.x << "," << point1.y << ") and Point2: (" << point2.x << "," << point2.y << ")" << std::endl; std::cout << "Dist: " << distance2D(point1.x, point1.y, point2.x, point2.y) << std::endl; std::cout << "Collision check: " << bCheck << std::endl; return 0; }
void Rectangle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec3 position = getPosition(); glm::vec2 dimensions = getDimensions(); glm::vec2 halfDimensions = dimensions * 0.5f; glm::quat rotation = getRotation(); auto batch = args->_batch; if (batch) { Transform transform; transform.setTranslation(position); transform.setRotation(rotation); batch->setModelTransform(transform); auto geometryCache = DependencyManager::get<GeometryCache>(); if (getIsSolid()) { glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->bindSimpleProgram(*batch); geometryCache->renderQuad(*batch, topLeft, bottomRight, rectangleColor); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); if (getIsDashedLine()) { glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f); glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->renderDashedLine(*batch, point1, point2, rectangleColor); geometryCache->renderDashedLine(*batch, point2, point3, rectangleColor); geometryCache->renderDashedLine(*batch, point3, point4, rectangleColor); geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor); } else { if (halfDimensions != _previousHalfDimensions) { QVector<glm::vec3> border; border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); geometryCache->updateVertices(_geometryCacheID, border, rectangleColor); _previousHalfDimensions = halfDimensions; } geometryCache->renderVertices(*batch, gpu::LINE_STRIP, _geometryCacheID); } } } }
void AxisAlignedBoxTest::collisionPoint() { Shapes::AxisAlignedBox3D box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); Shapes::Point3D point1({-1.5f, -1.0f, 2.0f}); Shapes::Point3D point2({0.5f, 1.0f, -2.5f}); VERIFY_NOT_COLLIDES(box, point1); VERIFY_COLLIDES(box, point2); }
bool RTRBoundingBox::contain(const RTRVector3D& point) const { for (int i = 0; i < 3; i++) { if (point(i) < point1(i) || point(i) > point2(i)) return false; } return true; }
// out: optimized model-shape // in: GRAY img // in: evtl zusaetzlicher param um scale-level/iter auszuwaehlen // calculates shape updates (deltaShape) for one or more iter/scales and returns... // assume we get a col-vec. cv::Mat optimize(cv::Mat modelShape, cv::Mat image) { for (int cascadeStep = 0; cascadeStep < model.getNumCascadeSteps(); ++cascadeStep) { //feature_current = obtain_features(double(TestImg), New_Shape, 'HOG', hogScale); vector<cv::Point2f> points; for (int i = 0; i < model.getNumLandmarks(); ++i) { // in case of HOG, need integers? points.emplace_back(cv::Point2f(modelShape.at<float>(i), modelShape.at<float>(i + model.getNumLandmarks()))); } Mat currentFeatures; double dynamicFaceSizeDistance = 0.0; if (true) { // adaptive // dynamic face-size: cv::Vec2f point1(modelShape.at<float>(8), modelShape.at<float>(8 + model.getNumLandmarks())); // reye_ic cv::Vec2f point2(modelShape.at<float>(9), modelShape.at<float>(9 + model.getNumLandmarks())); // leye_ic cv::Vec2f anchor1 = (point1 + point2) / 2.0f; cv::Vec2f point3(modelShape.at<float>(11), modelShape.at<float>(11 + model.getNumLandmarks())); // rmouth_oc cv::Vec2f point4(modelShape.at<float>(12), modelShape.at<float>(12 + model.getNumLandmarks())); // lmouth_oc cv::Vec2f anchor2 = (point3 + point4) / 2.0f; // dynamic window-size: // From the paper: patch size $ S_p(d) $ of the d-th regressor is $ S_p(d) = S_f / ( K * (1 + e^(d-D)) ) $ // D = numCascades (e.g. D=5, d goes from 1 to 5 (Matlab convention)) // K = fixed value for shrinking // S_f = the size of the face estimated from the previous updated shape s^(d-1). // For S_f, can use the IED, EMD, or max(IED, EMD). We use the EMD. dynamicFaceSizeDistance = cv::norm(anchor1 - anchor2); double windowSize = dynamicFaceSizeDistance / 2.0; // shrink value double windowSizeHalf = windowSize / 2.0; windowSizeHalf = std::round(windowSizeHalf * (1 / (1 + exp((cascadeStep + 1) - model.getNumCascadeSteps())))); // this is (step - numStages), numStages is 5 and step goes from 1 to 5. Because our step goes from 0 to 4, we add 1. int NUM_CELL = 3; // think about if this should go in the descriptorExtractor or not. Is it Hog specific? int windowSizeHalfi = static_cast<int>(windowSizeHalf) + NUM_CELL - (static_cast<int>(windowSizeHalf) % NUM_CELL); // make sure it's divisible by 3. However, this is not needed and not a good way currentFeatures = model.getDescriptorExtractor(cascadeStep)->getDescriptors(image, points, windowSizeHalfi); } else { // non-adaptive, the descriptorExtractor has all necessary params currentFeatures = model.getDescriptorExtractor(cascadeStep)->getDescriptors(image, points); } currentFeatures = currentFeatures.reshape(0, currentFeatures.cols * model.getNumLandmarks()).t(); //delta_shape = AAM.RF(1).Regressor(hogScale).A(1:end - 1, : )' * feature_current + AAM.RF(1).Regressor(hogScale).A(end,:)'; Mat regressorData = model.getRegressorData(cascadeStep); //Mat deltaShape = regressorData.rowRange(0, regressorData.rows - 1).t() * currentFeatures + regressorData.row(regressorData.rows - 1).t(); Mat deltaShape = currentFeatures * regressorData.rowRange(0, regressorData.rows - 1) + regressorData.row(regressorData.rows - 1); if (true) { // adaptive modelShape = modelShape + deltaShape.t() * dynamicFaceSizeDistance; } else { modelShape = modelShape + deltaShape.t(); } /* for (int i = 0; i < m.getNumLandmarks(); ++i) { cv::circle(landmarksImage, Point2f(modelShape.at<float>(i, 0), modelShape.at<float>(i + m.getNumLandmarks(), 0)), 6 - hogScale, Scalar(51.0f*(float)hogScale, 51.0f*(float)hogScale, 0.0f)); }*/ } return modelShape; };
void Checkbox::RenderCheck(Rect& rectArea) { Rect rectBox = rectArea; int iBoxMargin = int(rectArea.Height() * 0.2); int iBoxMarginRight = int(rectArea.Height() * 0.8 * 0.75); rectBox.Left(rectBox.Left() + iBoxMargin); rectBox.Right(rectBox.Left() + iBoxMarginRight); rectBox.Top(rectBox.Top() + iBoxMargin); rectBox.Bottom(rectBox.Bottom() - iBoxMargin); OpenGL::PushedAttributes attr(GL_ENABLE_BIT | GL_LINE_BIT | GL_POINT_BIT); glDisable(GL_TEXTURE_2D); glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); Color cBox = GetAttrAsColor(CheckboxAttr::BoxColor); glColor4ubv(cBox.m_color); glLineWidth(2.0); glBegin(GL_LINE_LOOP); glVertex2i(rectBox.Left(), rectBox.Bottom()); glVertex2i(rectBox.Right(), rectBox.Bottom()); glVertex2i(rectBox.Right(), rectBox.Top()); glVertex2i(rectBox.Left(), rectBox.Top()); glEnd(); if (IsChecked()) { double iCheckUnit = rectBox.Height() * 0.1; Point point1(int(rectBox.Left() + 3 * iCheckUnit), int(rectBox.Bottom() - 6 * iCheckUnit)); Point point2(int(rectBox.Left() + 6 * iCheckUnit), int(rectBox.Bottom() - 3 * iCheckUnit)); Point point3(int(rectBox.Left() + 11* iCheckUnit), int(rectBox.Bottom() - 11* iCheckUnit)); Color cCheck = GetAttrAsColor(CheckboxAttr::CheckColor); glColor4ubv(cCheck.m_color); glLineWidth(4.0); glBegin(GL_LINES); glVertex2i(point1.X(), point1.Y()); glVertex2i(point2.X(), point2.Y()); glVertex2i(point2.X(), point2.Y()); glVertex2i(point3.X(), point3.Y()); glEnd(); glPointSize(3.0); glBegin(GL_POINTS); glVertex2i(point1.X(), point1.Y()); glVertex2i(point2.X(), point2.Y()); glVertex2i(point3.X(), point3.Y()); glEnd(); } // adjust rect for size of checkbox int iOffset = int(rectArea.Height() * 1.1); rectArea.Left(rectArea.Left() + iOffset); }
void testOperatorDouble() { FTPoint point1(1.0f, 2.0f, 3.0f); const double* pointer = static_cast<const double*>(point1); CPPUNIT_ASSERT(pointer[0] == 1.0f); CPPUNIT_ASSERT(pointer[1] == 2.0f); CPPUNIT_ASSERT(pointer[2] == 3.0f); }
void TestSameChastePoints() { ChastePoint<3> point1(4,5,6); ChastePoint<3> point2(4,5,6); ChastePoint<3> point3(12,5,6); TS_ASSERT(point1.IsSamePoint(point2)); TS_ASSERT(!point1.IsSamePoint(point3)); }
/** @SYMTestCaseID GRAPHICS-WSERV-0021 @SYMDEF DEF081259 @SYMTestCaseDesc General PointerCursor Tests @SYMTestPriority High @SYMTestStatus Implemented @SYMTestActions Exercise the different pointercursor methods of a Window Server Session @SYMTestExpectedResults The methods are called without error */ void CTTSprite::GeneralPointerCursor() { if (!TestBase()->ConfigurationSupportsPointerEventTesting()) { INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing")); return; } TInt currentSMode=TheClient->iScreen->CurrentScreenMode(); TInt altSMode=-1; if (TheClient->iScreen->NumScreenModes()>1) altSMode=(currentSMode==1?0:1); RWsSession &ws=TheClient->iWs; TRect rect=ws.PointerCursorArea(); TRect testRect1(TPoint(rect.iBr.iX/4,rect.iBr.iY/4),TSize(rect.Width()/2,rect.Height()/2)); TRect testRect2(TPoint(rect.iBr.iX/3,rect.iBr.iY/3),TSize(2*rect.Width()/3,2*rect.Height()/3)); ws.SetPointerCursorArea(testRect1); TEST(ws.PointerCursorArea()==testRect1); TEST(ws.PointerCursorArea(currentSMode)==testRect1); ws.SetPointerCursorArea(currentSMode,testRect2); TEST(ws.PointerCursorArea()==testRect2); TEST(ws.PointerCursorArea(currentSMode)==testRect2); ws.SetPointerCursorArea(rect); TEST(ws.PointerCursorArea()==rect); if (altSMode>=0) { rect=ws.PointerCursorArea(altSMode); testRect1.iTl.iX=rect.iBr.iX/4; testRect1.iTl.iY=rect.iBr.iY/4; testRect1.SetWidth(rect.Width()/2); testRect1.SetHeight(rect.Height()/2); ws.SetPointerCursorArea(altSMode,testRect1); TEST(ws.PointerCursorArea(altSMode)==testRect1); ws.SetPointerCursorArea(altSMode,rect); TEST(ws.PointerCursorArea(altSMode)==rect); } TPointerCursorMode currentMode=ws.PointerCursorMode(); TInt ii; TInt err1; for(ii=EPointerCursorFirstMode;ii<=EPointerCursorLastMode;ii++) { ws.SetPointerCursorMode(STATIC_CAST(TPointerCursorMode,ii)); err1 = ws.PointerCursorMode(); TEST(ii==err1); if (ii!=err1) INFO_PRINTF3(_L("ws.PointerCursorMode() return value - Expected: %d, Actual: %d"), ii, err1); } ws.SetPointerCursorMode(currentMode); TEST(currentMode==ws.PointerCursorMode()); TPoint point1(10,12); TPoint point2(24,20); ws.PointerCursorPosition(); ws.SetPointerCursorPosition(point1); TEST(ws.PointerCursorPosition()==point1); ws.SetPointerCursorPosition(point2); TEST(ws.PointerCursorPosition()==point2); }
void SegmentsTests<dimension>::run() { VecD origin1 = random_vec<VecD>(); VecD direction1 = random_vec<VecD>(); geom::Point<dimension> point1( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) ); geom::Point<dimension> point2( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) ); // Test based on line geom::Line<dimension> line1( new typename geom::Line<dimension>::EuclideanDriver( origin1, direction1)); double firstIndex = random_float(); double lastIndex = random_float(); SegmentD seg1( new typename SegmentD::LineDriver( &line1, firstIndex, lastIndex ) ); test_segment_validity( seg1 ); GEOM_CHECK_VEC_EQUAL( seg1.firstPoint(), line1.pointAt(firstIndex) ); GEOM_CHECK_VEC_EQUAL( seg1.lastPoint(), line1.pointAt(lastIndex) ); GEOM_CHECK_NULL( geom::angle(seg1, line1 ) ); test_segment( seg1 ); JFR_CHECK( !seg1.isTransformable() ); // Test constructor based on two points SegmentD seg2( new typename SegmentD::TwoPointsPointerDriver( &point1, &point2 ) ); test_segment_validity( seg2 ); GEOM_CHECK_VEC_EQUAL( seg2.firstPoint(), point1.homogenousCoordinates() ); GEOM_CHECK_VEC_EQUAL( seg2.lastPoint(), point2.homogenousCoordinates() ); test_segment( seg2 ); JFR_CHECK( !seg2.isTransformable() ); // Test constructor based on two points SegmentD seg3( new typename SegmentD::TwoPointsDriver( point1.homogenousCoordinates(), point2.homogenousCoordinates() ) ); test_segment_validity( seg3 ); GEOM_CHECK_VEC_EQUAL( seg3.firstPoint(), point1.homogenousCoordinates() ); GEOM_CHECK_VEC_EQUAL( seg3.lastPoint(), point2.homogenousCoordinates() ); test_segment( seg3 ); JFR_CHECK( seg3.isTransformable() ); // Test transformability HomogenousMatrixD m = random_inversible_mat<dimension>(); HomogenousMatrixD mInv; jmath::ublasExtra::inv( m, mInv ); SegmentD seg3bis = seg3; seg3bis.applyTransformation( m ); GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), ublas::prod(m, seg3.firstPoint() ) ); GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), ublas::prod(m, seg3.lastPoint() ) ); seg3bis.applyTransformation( mInv ); GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), seg3.firstPoint() ); GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), seg3.lastPoint() ); // Test distance test_distance(seg1, seg2); test_distance(seg2, seg3); test_distance(seg1, seg3); test_distance(seg1, seg2.support()); test_distance(seg1, seg3.support()); test_distance(seg2, seg1.support()); test_distance(seg2, seg3.support()); test_distance(seg3, seg2.support()); test_distance(seg3, seg1.support()); }
void testOperatorPlus() { FTPoint point1(1.0f, 2.0f, 3.0f); FTPoint point2(1.0f, 2.0f, 3.0f); FTPoint point3(2.0f, 4.0f, 6.0f); FTPoint point4 = point1 + point2; CPPUNIT_ASSERT(point4 == point3); }
void testOperatorNotEqual() { FTPoint point1(1.0f, 2.0f, 3.0f); FTPoint point2(1.0f, 2.0f, 3.0f); FTPoint point3(-1.0f, 2.3f, 23.0f); CPPUNIT_ASSERT(!(point1 != point1)); CPPUNIT_ASSERT(!(point1 != point2)); CPPUNIT_ASSERT(point1 != point3); }
void testOperatorPlusEquals() { FTPoint point1(1.0f, 2.0f, 3.0f); FTPoint point2(-2.0f, 21.0f, 0.0f); FTPoint point3(-1.0f, 23.0f, 3.0f); point1 += point2; CPPUNIT_ASSERT(point1 == point3); }
void CapsuleTest::collisionPoint() { Shapes::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); Shapes::Point3D point({2.0f, 0.0f, 0.0f}); Shapes::Point3D point1({2.9f, 1.0f, 0.0f}); Shapes::Point3D point2({1.0f, 3.1f, 0.0f}); VERIFY_COLLIDES(capsule, point); VERIFY_COLLIDES(capsule, point1); VERIFY_NOT_COLLIDES(capsule, point2); }
FX_BOOL CPWL_EditCtrl::IsWndHorV() { CFX_Matrix mt = GetWindowMatrix(); CFX_FloatPoint point1(0, 1); CFX_FloatPoint point2(1, 1); mt.Transform(point1.x, point1.y); mt.Transform(point2.x, point2.y); return point2.y == point1.y; }
void CylinderTest::collisionPoint() { Shapes::Cylinder3D cylinder({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); Shapes::Point3D point({2.0f, 0.0f, 0.0f}); Shapes::Point3D point1({1.0f, 3.1f, 0.0f}); Shapes::Point3D point2({2.9f, -1.0f, 0.0f}); VERIFY_COLLIDES(cylinder, point); VERIFY_COLLIDES(cylinder, point1); VERIFY_NOT_COLLIDES(cylinder, point2); }
int main(){ int N = 3; CGAL::Timer cost; std::vector<Point_d> points; std::vector<double> point; point.push_back(6); point.push_back(6); point.push_back(6); Point_d point1(3, point.begin(), point.end()); std::cout << point1[1] << std::endl; // Point_d point1(1,3,5); Point_d point2(4,8,10); Point_d point3(2,7,9); // Point_d point(1,2,3); points.push_back(point1); points.push_back(point2); points.push_back(point3); // D Dt(d); // // CGAL_assertion(Dt.empty()); // // // insert the points in the triangulation // cost.reset();cost.start(); // std::cout << " Delaunay triangulation of "<<N<<" points in dim "<<d<< std::flush; // std::vector<Point_d>::iterator it; // for(it = points.begin(); it!= points.end(); ++it){ // Dt.insert(*it); // } // std::list<Simplex_handle> NL = Dt.all_simplices(D::NEAREST); // std::cout << " done in "<<cost.time()<<" seconds." << std::endl; // CGAL_assertion(Dt.is_valid() ); // CGAL_assertion(!Dt.empty()); // // // Vertex_handle v = Dt.nearest_neighbor(point); // Simplex_handle s = Dt.simplex(v); // // std::vector<Point_d> Simplex_vertices; // for(int j=0; j<=d; ++j){ // Vertex_handle vertex = Dt.vertex_of_simplex(s,j); // Simplex_vertices.push_back(Dt.associated_point(vertex)); // } // // std::vector<K::FT> coords; // K::Barycentric_coordinates_d BaryCoords; // BaryCoords(Simplex_vertices.begin(), Simplex_vertices.end(),point,std::inserter(coords, coords.begin())); // std::cout << coords[0] << std::endl; // return 0; }
// track object void ObjectTrackingClass::track(cv::Mat& image, // output image cv::Mat& image1, // previous frame cv::Mat& image2, // next frame std::vector<cv::Point2f>& points1, // previous points std::vector<cv::Point2f>& points2, // next points std::vector<uchar>& status, // status array std::vector<float>& err) // error array { // tracking code cv::calcOpticalFlowPyrLK(image1, image2, points1, points2, status, err, winSize, maxLevel, termcrit, flags, minEigThreshold); // work out maximum X,Y keypoint values in the next_points keypoint vector cv::Point2f min(FLT_MAX, FLT_MAX); cv::Point2f max(FLT_MIN, FLT_MIN); // refactor the points array to remove points lost due to tracking error size_t i, k; for( i = k = 0; i < points2.size(); i++ ) { if( !status[i] ) continue; points2[k++] = points2[i]; // find keypoints at the extremes min.x = Min(min.x, points2[i].x); min.y = Min(min.y, points2[i].y); max.x = Max(max.x, points2[i].x); max.y = Max(max.y, points2[i].y); // draw points cv::circle( image, points2[i], 3, cv::Scalar(0,255,0), -1, 8); } points2.resize(k); // Draw lines between the extreme points (square) cv::Point2f point0(min.x, min.y); cv::Point2f point1(max.x, min.y); cv::Point2f point2(max.x, max.y); cv::Point2f point3(min.x, max.y); cv::line( image, point0, point1, cv::Scalar( 0, 255, 0 ), 4 ); cv::line( image, point1, point2, cv::Scalar( 0, 255, 0 ), 4 ); cv::line( image, point2, point3, cv::Scalar( 0, 255, 0 ), 4 ); cv::line( image, point3, point0, cv::Scalar( 0, 255, 0 ), 4 ); }
static bool ClipToRect( long & x1, long & y1, long & x2, long & y2, const WRect & clip ) //----------------------------------------------------------------- // Cohen-Sutherland Clipping Algorithm from _Fundamentals of Interactive // Computer Graphics_, page 148. { PointCode point1( x1, y1, CL_Inside ); PointCode point2( x2, y2, CL_Inside ); PointCode * p1; PointCode * p2; PointCode * tmp; long top = clip.y(); long left = clip.x(); long bottom = clip.y() + clip.h(); long right = clip.x() + clip.w(); p1 = & point1; p2 = & point2; while( 1 ) { CalcOut( *p1, top, left, bottom, right ); CalcOut( *p2, top, left, bottom, right ); if( p1->code == CL_Inside && p2->code == CL_Inside ) { return TRUE; // trivial acceptance } if( (p1->code & p2->code) != 0 ) { return FALSE; // trivial rejection } if( p1->code == 0 ) { // p1 inside -- swap so p1 outside tmp = p1; p1 = p2; p2 = tmp; } // perform a subdivision; move p1 to the intersection point. // use the formula y = y1 + slope * (x - x1), // x = x1 + (y - y1) / slope. if( p1->code & CL_Above ) { // divide at top p1->x += ((p2->x - p1->x) * (top - p1->y)) / (p2->y - p1->y); p1->y = top; } else if( p1->code & CL_Below ) { // divide at bottom of p1->x += ((p2->x - p1->x) * (bottom - p1->y)) / (p2->y - p1->y); p1->y = bottom; } else if( p1->code & CL_Right ) { // divide at right p1->y += ((p2->y - p1->y) * (right - p1->x)) / (p2->x - p1->x); p1->x = right; } else if( p1->code & CL_Left ) { // divide at left p1->y += ((p2->y - p1->y) * (left - p1->x)) / (p2->x - p1->x); p1->x = left; } } }
void testSetters() { FTPoint point; FTPoint point1(1, 2, 3); point.X(1); point.Y(2); point.Z(3); CPPUNIT_ASSERT(point == point1); }