private void CreateImageTargets()
    {
        int    trackableDataArrayLength = QCARWrapper.Instance.DataSetGetNumTrackableType(TypeMapping.GetTypeID(typeof(ImageTarget)), this.mDataSetPtr);
        IntPtr trackableDataArray       = Marshal.AllocHGlobal((int)(Marshal.SizeOf(typeof(ImageTargetData)) * trackableDataArrayLength));

        if (QCARWrapper.Instance.DataSetGetTrackablesOfType(TypeMapping.GetTypeID(typeof(ImageTarget)), trackableDataArray, trackableDataArrayLength, this.mDataSetPtr) == 0)
        {
            Debug.LogError("Could not create Image Targets");
        }
        else
        {
            for (int i = 0; i < trackableDataArrayLength; i++)
            {
                IntPtr          ptr  = new IntPtr(trackableDataArray.ToInt32() + (i * Marshal.SizeOf(typeof(ImageTargetData))));
                ImageTargetData data = (ImageTargetData)Marshal.PtrToStructure(ptr, typeof(ImageTargetData));
                if (!this.mTrackablesDict.ContainsKey(data.id))
                {
                    int           capacity      = 0x80;
                    StringBuilder trackableName = new StringBuilder(capacity);
                    QCARWrapper.Instance.DataSetGetTrackableName(this.mDataSetPtr, data.id, trackableName, capacity);
                    ImageTarget target = new ImageTargetImpl(trackableName.ToString(), data.id, ImageTargetType.PREDEFINED, this);
                    this.mTrackablesDict[data.id] = target;
                }
            }
            Marshal.FreeHGlobal(trackableDataArray);
        }
    }
예제 #2
0
    private void CreateImageTargets()
    {
        // Allocate array for all Image Targets.
        int numImageTargets = QCARWrapper.Instance.DataSetGetNumTrackableType(
            (int)TrackableType.IMAGE_TARGET,
            mDataSetPtr);
        IntPtr imageTargetDataPtr =
            Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ImageTargetData)) * numImageTargets);

        // Copy Image Target properties from native.
        if (QCARWrapper.Instance.DataSetGetTrackablesOfType((int)TrackableType.IMAGE_TARGET,
                                                            imageTargetDataPtr, numImageTargets,
                                                            mDataSetPtr) == 0)
        {
            Debug.LogError("Could not create Image Targets");
            return;
        }

        // Create Image Target Behaviours.
        for (int i = 0; i < numImageTargets; ++i)
        {
            IntPtr trackablePtr = new IntPtr(imageTargetDataPtr.ToInt32() + i *
                                             Marshal.SizeOf(typeof(ImageTargetData)));
            ImageTargetData trackableData = (ImageTargetData)
                                            Marshal.PtrToStructure(trackablePtr, typeof(ImageTargetData));

            // Do not overwrite existing Trackables.
            if (mTrackablesDict.ContainsKey(trackableData.id))
            {
                continue;
            }

            // QCAR support names up to 64 characters in length, but here we allocate
            // a slightly larger buffer:
            int nameLength = 128;
            System.Text.StringBuilder trackableName = new System.Text.StringBuilder(nameLength);
            QCARWrapper.Instance.DataSetGetTrackableName(mDataSetPtr, trackableData.id, trackableName, nameLength);

            ImageTarget imageTarget = new ImageTargetImpl(trackableName.ToString(), trackableData.id, ImageTargetType.PREDEFINED, this);

            // Add newly created Image Target to dictionary.
            mTrackablesDict[trackableData.id] = imageTarget;
        }

        Marshal.FreeHGlobal(imageTargetDataPtr);
    }
예제 #3
0
        public Task <Status> New(Action <StatusCharacteristics> characteristics, Action <LevelTarget> level,
                                 Action <ImageTarget> image, CancellationToken cancellationToken = default(CancellationToken))
        {
            var statusCharacteristics = new StatusCharacteristicsImpl();

            characteristics(statusCharacteristics);

            var levelTargetImpl = new LevelTargetImpl();

            level(levelTargetImpl);

            var imageTargetImpl = new ImageTargetImpl();

            image(imageTargetImpl);

            string url = string.Format("/api/v1/statuses", statusCharacteristics, levelTargetImpl.Target, imageTargetImpl.Target);

            return(base.Post(url, cancellationToken).As <Status>(cancellationToken));
        }
    public override DataSetTrackableBehaviour CreateTrackable(TrackableSource trackableSource, GameObject gameObject)
    {
        TrackableSourceImpl impl       = (TrackableSourceImpl)trackableSource;
        int              capacity      = 0x80;
        StringBuilder    trackableName = new StringBuilder(capacity);
        IntPtr           trackableData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SimpleTargetData)));
        int              num2          = QCARWrapper.Instance.DataSetCreateTrackable(this.mDataSetPtr, impl.TrackableSourcePtr, trackableName, capacity, trackableData);
        SimpleTargetData data          = (SimpleTargetData)Marshal.PtrToStructure(trackableData, typeof(SimpleTargetData));

        Marshal.FreeHGlobal(trackableData);
        if (num2 == TypeMapping.GetTypeID(typeof(ImageTarget)))
        {
            ImageTarget trackable = new ImageTargetImpl(trackableName.ToString(), data.id, ImageTargetType.USER_DEFINED, this);
            this.mTrackablesDict[data.id] = trackable;
            Debug.Log(string.Format("Trackable created: {0}, {1}", num2, trackableName));
            StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();
            return(stateManager.FindOrCreateImageTargetBehaviourForTrackable(trackable, gameObject, this));
        }
        Debug.LogError("DataSet.CreateTrackable returned unknown or incompatible trackable type!");
        return(null);
    }
예제 #5
0
    // Adds a single trackable from a source and a given gameobject to this dataset
    public override DataSetTrackableBehaviour CreateTrackable(TrackableSource trackableSource, GameObject gameObject)
    {
        // create a trackable in native from the trackable source handle:
        TrackableSourceImpl trackableSourceImpl = (TrackableSourceImpl)trackableSource;

        // QCAR support names up to 64 characters in length, but here we allocate
        // a slightly larger buffer:
        int nameLength = 128;

        System.Text.StringBuilder trackableName = new System.Text.StringBuilder(nameLength);

        IntPtr targetDataPtr =
            Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SimpleTargetData)));
        TrackableType trackableType = (TrackableType)QCARWrapper.Instance.DataSetCreateTrackable(mDataSetPtr, trackableSourceImpl.TrackableSourcePtr, trackableName, nameLength, targetDataPtr);

        SimpleTargetData targetData = (SimpleTargetData)
                                      Marshal.PtrToStructure(targetDataPtr, typeof(SimpleTargetData));

        Marshal.FreeHGlobal(targetDataPtr);

        // currently only supported for ImageTargets:
        if (trackableType == TrackableType.IMAGE_TARGET)
        {
            ImageTarget newImageTarget = new ImageTargetImpl(trackableName.ToString(), targetData.id, ImageTargetType.USER_DEFINED, this);

            // Add newly created Image Target to dictionary.
            mTrackablesDict[targetData.id] = newImageTarget;

            Debug.Log(string.Format("Trackable created: {0}, {1}", trackableType, trackableName));

            // Find or create ImageTargetBehaviour for this ImageTarget:
            StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();
            return(stateManager.FindOrCreateImageTargetBehaviourForTrackable(newImageTarget, gameObject, this));
        }
        else
        {
            Debug.LogError("DataSet.CreateTrackable returned unknown or incompatible trackable type!");
            return(null);
        }
    }
    private void CreateImageTargets()
    {
        // Allocate array for all Image Targets.
        int numImageTargets = QCARWrapper.Instance.DataSetGetNumTrackableType(
            (int)TrackableType.IMAGE_TARGET,
            mDataSetPtr);
        IntPtr imageTargetDataPtr =
            Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ImageTargetData)) * numImageTargets);

        // Copy Image Target properties from native.
        if (QCARWrapper.Instance.DataSetGetTrackablesOfType((int)TrackableType.IMAGE_TARGET,
                                       imageTargetDataPtr, numImageTargets,
                                       mDataSetPtr) == 0)
        {
            Debug.LogError("Could not create Image Targets");
            return;
        }

        // Create Image Target Behaviours.
        for (int i = 0; i < numImageTargets; ++i)
        {
            IntPtr trackablePtr = new IntPtr(imageTargetDataPtr.ToInt32() + i *
                    Marshal.SizeOf(typeof(ImageTargetData)));
            ImageTargetData trackableData = (ImageTargetData)
                    Marshal.PtrToStructure(trackablePtr, typeof(ImageTargetData));

            // Do not overwrite existing Trackables.
            if (mTrackablesDict.ContainsKey(trackableData.id))
            {
                continue;
            }

            // QCAR support names up to 64 characters in length, but here we allocate
            // a slightly larger buffer:
            int nameLength = 128;
            System.Text.StringBuilder trackableName = new System.Text.StringBuilder(nameLength);
            QCARWrapper.Instance.DataSetGetTrackableName(mDataSetPtr, trackableData.id, trackableName, nameLength);

            ImageTarget imageTarget = new ImageTargetImpl(trackableName.ToString(), trackableData.id, ImageTargetType.PREDEFINED, this);

            // Add newly created Image Target to dictionary.
            mTrackablesDict[trackableData.id] = imageTarget;
        }

        Marshal.FreeHGlobal(imageTargetDataPtr);
    }
    // Adds a single trackable from a source and a given gameobject to this dataset
    public override DataSetTrackableBehaviour CreateTrackable(TrackableSource trackableSource, GameObject gameObject)
    {
        // create a trackable in native from the trackable source handle:
        TrackableSourceImpl trackableSourceImpl = (TrackableSourceImpl)trackableSource;

        // QCAR support names up to 64 characters in length, but here we allocate
        // a slightly larger buffer:
        int nameLength = 128;
        System.Text.StringBuilder trackableName = new System.Text.StringBuilder(nameLength);

        IntPtr targetDataPtr =
            Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SimpleTargetData)));
        TrackableType trackableType = (TrackableType)QCARWrapper.Instance.DataSetCreateTrackable(mDataSetPtr, trackableSourceImpl.TrackableSourcePtr, trackableName, nameLength, targetDataPtr);

        SimpleTargetData targetData = (SimpleTargetData)
                Marshal.PtrToStructure(targetDataPtr, typeof(SimpleTargetData));

        Marshal.FreeHGlobal(targetDataPtr);

        // currently only supported for ImageTargets:
        if (trackableType == TrackableType.IMAGE_TARGET)
        {
            ImageTarget newImageTarget = new ImageTargetImpl(trackableName.ToString(), targetData.id, ImageTargetType.USER_DEFINED, this);

            // Add newly created Image Target to dictionary.
            mTrackablesDict[targetData.id] = newImageTarget;

            Debug.Log(string.Format("Trackable created: {0}, {1}", trackableType, trackableName));

            // Find or create ImageTargetBehaviour for this ImageTarget:
            StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();
            return stateManager.FindOrCreateImageTargetBehaviourForTrackable(newImageTarget, gameObject, this);
        }
        else
        {
            Debug.LogError("DataSet.CreateTrackable returned unknown or incompatible trackable type!");
            return null;
        }
    }