bool ImgPatch::selfTest() { //Test 1 intersection: cv::Mat intersection_test = (cv::Mat_<uchar>(9,9) << 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0); setPatch(intersection_test); if (intersectionValue() < 1) return false; //Test 2 Single line test (horizontal) cv::Mat line_test_1 = (cv::Mat_<uchar>(9,9) << 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0); setPatch(line_test_1); if (intersectionValue() + cornerValue() > 1.0) return false; //Test 3 Single line test (diagnol): cv::Mat line_test_2 = (cv::Mat_<uchar>(9,9) << 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1); setPatch(line_test_2); if (intersectionValue() + cornerValue() > 1.0) return false; //Test 4 Single corner test (90 degree): cv::Mat corner = (cv::Mat_<uchar>(9,9) << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0); setPatch(corner); if (intersectionValue() > 1) return false; if (cornerValue() < 1) return false; }
float ImgPatch::onlyCornerValue() { float v = intersectionValue(); if (v > 1) { return 0.0f; } else cornerValue(); }
float ImgPatch::cornerOrIntersectionValue() { float v = intersectionValue(); if (v > 1) { return v; } else cornerValue(); }
void WaterPhysicsSystem::addEdge(const Vec2f& _a, const Vec2f& _b, b2FixtureBodyPart* _destructionListener) { Edge* edge = new Edge; Edge* intersections[2] = {0, 0}; unsigned int numIntersections = 0; for (unsigned int i = 0; i != edges.size(); i++) { try { Vec2f position = intersectionPosition(_a, _b, edges[i]->aPosition(), edges[i]->bPosition()); assert(numIntersections < 2); intersections[numIntersections] = edges[i]; numIntersections++; } catch (int ii) { } } switch (numIntersections) { case 0: { edge->setA(new Vertex(_a), _b); edge->setB(new Vertex(_b)); addFinalisedEdge(edge); break; } case 1: { float scalar = intersectionValue(_a, _b, intersections[0]->aPosition(), intersections[0]->bPosition()); if (scalar < 0.2f) { Vec2f position = intersectionPosition(_a, _b, intersections[0]->aPosition(), intersections[0]->bPosition()); edge->setB(position, new Vertex(_b)); createVertex(position, intersections[0], edge); } else if (scalar > 0.8f) { Vec2f position = intersectionPosition(_a, _b, intersections[0]->aPosition(), intersections[0]->bPosition()); edge->setA(new Vertex(_a), position); createVertex(position, edge, intersections[0]); } else { std::cout << "Error: scalar is " << scalar << std::endl; assert(false); } addFinalisedEdge(edge); break; } case 2: { float scalar0 = intersectionValue( _a, _b, intersections[0]->aPosition(), intersections[0]->bPosition()); float scalar1 = intersectionValue( _a, _b, intersections[1]->aPosition(), intersections[1]->bPosition()); if (scalar0 > scalar1) { { Edge* temp = intersections[0]; intersections[0] = intersections[1]; intersections[1] = temp; } { float temp = scalar0; scalar0 = scalar1; scalar1 = temp; } } Vec2f position0 = positionFromScalarValue(_a, _b, scalar0); /// FIXME might be the wrong line Vec2f position1 = positionFromScalarValue(_a, _b, scalar1); createVertex(position0, intersections[0], edge, &position1); createVertex(position1, edge, intersections[1]); addFinalisedEdge(edge); break; } default: { assert(false); } } //edges.push_back({_a, _b}); }