public void Test_RayRectangleIntersect_FromTop_Hit() { Rectangle rect = new Rectangle(0, 0, 21, 21); Point2Df rayPos; Point2Df rayStep; Geometry.RayIntersection res; // Vertical cases rayStep = new Point2Df(0, 1); ////////////////////////////// rayPos = new Point2Df(0, -10); ////////////////////////////// // Horizontal step, intersect along top edge res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); /////////////////////////////// rayPos = new Point2Df(20, -10); /////////////////////////////// // Horizontal step, intersect along bottom edge res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); /////////////////////////////// rayPos = new Point2Df(10, -10); /////////////////////////////// // Horizontal step, intersect through middle res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q1: In left, out top rayStep = new Point2Df(0.5, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(20, res.StepsToExit, "Incorrect steps to exit"); // Q1: In left, out right rayStep = new Point2Df(0.25, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q4: In left, out right rayStep = new Point2Df(-0.25, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q4: in left, out bottom rayStep = new Point2Df(-0.5, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(20, res.StepsToExit, "Incorrect steps to exit"); // Q1: Hit top left corner rayStep = new Point2Df(1, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(10, res.StepsToExit, "Incorrect steps to exit"); // Q4: Hit bottom left corner rayStep = new Point2Df(-1, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(10, res.StepsToExit, "Incorrect steps to exit"); /////////////////////////////// rayPos = new Point2Df(10, -5); /////////////////////////////// // Q1: In left, out top right rayStep = new Point2Df(1, 2.5); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(2, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(10, res.StepsToExit, "Incorrect steps to exit"); // Q4: In left, out bottom right rayStep = new Point2Df(-1, 2.5); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(2, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(10, res.StepsToExit, "Incorrect steps to exit"); }
public void Test_RayRectangleIntersect_FromTopRight_Miss() { Rectangle rect = new Rectangle(0, 0, 21, 21); Point2Df rayPos = new Point2Df(30, -10); Point2Df rayStep; Geometry.RayIntersection res; // Q2: Up, left rayStep = new Point2Df(-1, -1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Up rayStep = new Point2Df(0, -1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Q1: Up, Right rayStep = new Point2Df(1, -1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Right rayStep = new Point2Df(1, 0); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Q1: Down, Right rayStep = new Point2Df(1, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Down rayStep = new Point2Df(0, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Q3: Miss below rayStep = new Point2Df(-1, 4); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Q3: Miss above rayStep = new Point2Df(-4, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); // Left rayStep = new Point2Df(-1, 0); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNull(res, "Ray should not have intersected the rectangle"); }
public void Test_RayRectangleIntersect_FromTopRight_Hit() { Rectangle rect = new Rectangle(0, 0, 21, 21); Point2Df rayPos; Point2Df rayStep; Geometry.RayIntersection res; /////////////////////////////// rayPos = new Point2Df(25, -10); /////////////////////////////// // Q4: In top, out left rayStep = new Point2Df(-1, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(25, res.StepsToExit, "Incorrect steps to exit"); // Q4: In top, out bottom rayStep = new Point2Df(-0.75, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q4: In top, out bottom left rayStep = new Point2Df(-2.5 / 3, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q4: In top right, out bottom rayStep = new Point2Df(-0.5, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); /////////////////////////////// rayPos = new Point2Df(30, -5); /////////////////////////////// // Q4: In right, out bottom rayStep = new Point2Df(-1, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(25, res.StepsToExit, "Incorrect steps to exit"); // Q4: In right, out left rayStep = new Point2Df(-1, 0.75); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q4: In right, out bottom left rayStep = new Point2Df(-1, 2.5 / 3); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q4: In top right, out left rayStep = new Point2Df(-1, 0.5); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); //////////////////////////////// rayPos = new Point2Df(30, -10); //////////////////////////////// // Q4: In top right, out bottom left rayStep = new Point2Df(-1, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(30, res.StepsToExit, "Incorrect steps to exit"); // Q4: Hit top left corner rayStep = new Point2Df(-3, 1); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(10, res.StepsToExit, "Incorrect steps to exit"); // Q4: Hit bottom right corner rayStep = new Point2Df(-1, 3); res = Geometry.RayRectangleIntersect(rayPos, rayStep, rect); Assert.IsNotNull(res, "Ray should have intersected rectangle"); Assert.AreEqual(10, res.StepsToEntry, "Incorrect steps to entry"); Assert.AreEqual(10, res.StepsToExit, "Incorrect steps to exit"); }
public NaturalPipeline(IComponentManager xpcfComponentManager) : base(xpcfComponentManager) { imageViewerKeypoints = Create <IImageViewer>("SolARImageViewerOpencv", "keypoints"); imageViewerResult = Create <IImageViewer>("SolARImageViewerOpencv"); marker = Create <IMarker2DNaturalImage>("SolARMarker2DNaturalImageOpencv"); kpDetector = Create <IKeypointDetector>("SolARKeypointDetectorOpencv"); kpDetectorRegion = Create <IKeypointDetectorRegion>("SolARKeypointDetectorRegionOpencv"); descriptorExtractor = Create <IDescriptorsExtractor>("SolARDescriptorsExtractorAKAZE2Opencv"); matcher = Create <IDescriptorMatcher>("SolARDescriptorMatcherKNNOpencv"); geomMatchesFilter = Create <IMatchesFilter>("SolARGeometricMatchesFilterOpencv"); poseEstimationPlanar = Create <I3DTransformSACFinderFrom2D3D>("SolARPoseEstimationPlanarPointsOpencv"); opticalFlow = Create <IOpticalFlowEstimator>("SolAROpticalFlowPyrLKOpencv"); projection = Create <IProject>("SolARProjectOpencv"); unprojection = Create <IUnproject>("SolARUnprojectPlanarPointsOpencv"); img_mapper = Create <IImage2WorldMapper>("SolARImage2WorldMapper4Marker2D"); basicMatchesFilter = Create <IMatchesFilter>("SolARBasicMatchesFilter"); keypointsReindexer = Create <IKeypointsReIndexer>("SolARKeypointsReIndexer"); overlay3DComponent = Create <I3DOverlay>("SolAR3DOverlayOpencv"); /* in dynamic mode, we need to check that components are well created*/ /* this is needed in dynamic mode */ if (new object[] { imageViewerKeypoints, imageViewerResult, marker, kpDetector, kpDetectorRegion, descriptorExtractor, matcher, geomMatchesFilter, poseEstimationPlanar, opticalFlow, projection, unprojection, img_mapper, basicMatchesFilter, keypointsReindexer, overlay3DComponent }.Contains(null)) { LOG_ERROR("One or more component creations have failed"); return; } LOG_INFO("All components have been created"); // Declare data structures used to exchange information between components refImage = SharedPtr.Alloc <Image>().AddTo(subscriptions); previousCamImage = SharedPtr.Alloc <Image>().AddTo(subscriptions); //kpImageCam = SharedPtr.Alloc<Image>().AddTo(subscriptions); refDescriptors = SharedPtr.Alloc <DescriptorBuffer>().AddTo(subscriptions); camDescriptors = SharedPtr.Alloc <DescriptorBuffer>().AddTo(subscriptions); matches = new DescriptorMatchVector().AddTo(subscriptions); // where to store detected keypoints in ref image and camera image refKeypoints = new KeypointArray().AddTo(subscriptions); camKeypoints = new KeypointArray().AddTo(subscriptions); markerWorldCorners = new Point3DfArray().AddTo(subscriptions); // load marker marker.loadMarker().Check(); marker.getWorldCorners(markerWorldCorners).Check(); marker.getImage(refImage).Check(); // detect keypoints in reference image kpDetector.detect(refImage, refKeypoints); // extract descriptors in reference image descriptorExtractor.extract(refImage, refKeypoints, refDescriptors); // initialize image mapper with the reference image size and marker size var img_mapper_config = img_mapper.BindTo <IConfigurable>().AddTo(subscriptions); var refSize = refImage.getSize(); var mkSize = marker.getSize(); img_mapper_config.getProperty("digitalWidth").setIntegerValue((int)refSize.width); img_mapper_config.getProperty("digitalHeight").setIntegerValue((int)refSize.height); img_mapper_config.getProperty("worldWidth").setFloatingValue(mkSize.width); img_mapper_config.getProperty("worldHeight").setFloatingValue(mkSize.height); // vector of 4 corners in the marker refImgCorners = new Point2DfArray(); float w = refImage.getWidth(), h = refImage.getHeight(); Point2Df corner0 = new Point2Df(0, 0); Point2Df corner1 = new Point2Df(w, 0); Point2Df corner2 = new Point2Df(w, h); Point2Df corner3 = new Point2Df(0, h); refImgCorners.Add(corner0); refImgCorners.Add(corner1); refImgCorners.Add(corner2); refImgCorners.Add(corner3); }