Example #1
0
    /**
     *  Set up the data object with empty UltrasoundPoint%s representing the points
     *  that need to be scanned.
     *
     *  This is analagous to setting up the view frustum in traditional 3D graphics.
     */
    private void EstablishScanningPlane(ref UltrasoundScanData data)
    {
        OnionLogger.globalLog.PushInfoLayer("Pre-populating data");

        UltrasoundProbeConfiguration config = data.GetProbeConfig();

        // nearZ and farZ represent near and far clipping "planes" (they're really arcs)
        float nearZ = config.GetMinScanDistance();
        float farZ  = config.GetMaxScanDistance();

        float arcSizeDegrees    = config.GetArcSizeInDegrees();
        int   scanlines         = config.GetNumberOfScanlines();
        int   pointsPerScanline = config.GetPointsPerScanline();

        for (int i = 0; i < scanlines; ++i)
        {
            UltrasoundScanline scanline = new UltrasoundScanline(config.GetPosition());
            float   angleInDegrees      = -(arcSizeDegrees / 2) + i * arcSizeDegrees / (scanlines - 1);
            float   angleInRadians      = Mathf.Deg2Rad * angleInDegrees;
            Vector2 trajectory          = new Vector2(Mathf.Sin(angleInRadians), Mathf.Cos(angleInRadians));

            for (int j = 0; j < pointsPerScanline; ++j)
            {
                float           d = nearZ + j * (farZ - nearZ) / (pointsPerScanline - 1);
                Vector2         positionOnPlane      = d * trajectory;
                Vector3         positionInWorldSpace = WorldSpaceFromProjectedPosition(positionOnPlane, config);
                UltrasoundPoint point = new UltrasoundPoint(positionInWorldSpace, positionOnPlane);
                scanline.AddUltrasoundPoint(point);
            }

            data.AddScanline(scanline);
        }

        OnionLogger.globalLog.PopInfoLayer();
    }
    /**
     *  Maps a point in the probe's scanning plane to a pixel index in the image.
     *  @param imageHeight The height of the image being rendered.
     *  @param imageWidth The width of the image being rendered.
     *  @param vector2 The point in the scanning plane to be mapped.
     *  @param probeConfig The UltrasoundProbeConfiguration of the probe object.
     *  @return The corresponding index in the image at which to render the point.
     */
    protected int MapScanningPlaneToPixelCoordinate(int imageHeight,
                                                    int imageWidth,
                                                    Vector2 vector2,
                                                    UltrasoundProbeConfiguration probeConfig)
    {
        float pixelsPerWorldUnit = Mathf.Min(imageWidth, imageHeight) / probeConfig.GetMaxScanDistance();
        int   xCenter            = imageWidth / 2;

        int newX = (int)(xCenter - pixelsPerWorldUnit * vector2.x);
        int newY = imageHeight - (int)(pixelsPerWorldUnit * vector2.y);

        int pixelMapping = newY * imageWidth + newX;

        return(pixelMapping);
    }
    /**
     *  Copy constructor to instantiate a new UltrasoundProbeConfiguration from another.
     *
     *  @param config The other UltrasoundProbeConfiguration object.
     *  @throw ArgumentNullException
     */
    public UltrasoundProbeConfiguration(UltrasoundProbeConfiguration config)
    {
        UltrasoundDebug.Assert(null != config,
                               "Null UltrasoundProbeConfiguration used for copy constructor.",
                               this);
        this.SetPosition(config.GetPosition());
        this.SetRotation(config.GetRotation());

        this.maxDistance       = config.GetMaxScanDistance();
        this.minDistance       = config.GetMinScanDistance();
        this.arcSizeInDegrees  = config.GetArcSizeInDegrees();
        this.pointsPerScanline = config.GetPointsPerScanline();
        this.numberOfScanlines = config.GetNumberOfScanlines();
        this.gain = config.GetGain();
    }