Log in or register to post comments

Destroying a user defined target and removing recognition

January 30, 2013 - 5:10pm #1

I am trying to remove a created user defined trackable from the system.  At the moment I have modified the sample DefaultTargetEventHandler script that is on the user-def prefab to include a function I can call to remove the trackable.  Digging through the code a bit I found a destroy trackable call I could make from the StateManager which I could get from the trackable.

 

StateManagerImpl sm = TrackerManager.Instance.GetStateManager() as StateManagerImpl;

sm.DestroyTrackableBehavioursForTrackable(mTrackableBehaviour.Trackable, true);

 

This seems to neatly remove the behaviour from the event handler lists and also destroy the game object for me but when I hold up the target I used to create it with I still get log messages from the system like:

Num trackables detected: 1

Num trackables detected: 0

So clearly the tracker recognition is still in the system.  It looks to me like something also has to be removed from the dataset but I can't figure out how to hook my way into it to call the DataSetImpl.Destroy() function that looks like it does everything that I need (including the StateManager destroy call I have done already).

Any pointers would be appreciated.

Destroying a user defined target and removing recognition

December 6, 2016 - 1:26am #9

DavidBeard wrote:

These are the instructions you're using ?

 

Request an ImageTracker instance as explained above.
 
Make sure that the dataset to destroy is not active (otherwise destruction will fail): ImageTracker.Deactivate(DataSet dataset);
    
Destroy the dataset: ImageTracker.DestroyDataSet(DataSet dataset, bool destroyTrackableGameObjects);


	
// Destroy a dataset.
private bool DestroyDataSet(DataSet dataSet)
{
    // Request an ImageTracker instance from the TrackerManager.
    ImageTracker imageTracker =
 (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
  
  // Make sure the data set is not active.
    imageTracker.DeactivateDataSet(dataSet);
  
    // Destroy the data set
    // (choose true to also destroy the Target objects that belong to the data set).
    bool success = imageTracker.DestroyDataSet(dataSet, true);
 
    return success;
}

 

Is this for an ImageTarget or FrameMarker?

Hello!

I want to use this for ObjectTarget, it seems invalid!

Destroying a user defined target and removing recognition

December 6, 2016 - 1:23am #8

a_1 wrote:

Hello.  I'm trying to destroy a target as per the instructions but constantly get:

Could not destroy trackable with id 1 

 

I've Deactivated the dataset prior to attempting to destroy it via dataset.Destroy(trackable,true);
 
Any pointers?
 
Alejandro.

Hello!

DId you get it?

I want to destroy ObjectTarget created by "DataSet.Load" too, it seems that we cannot destroy it using "ataset.Destroy(trackable,true);"

Destroying a user defined target and removing recognition

December 6, 2016 - 1:18am #7

AlessandroB wrote:

Hi, 

you should simply need this method:

DataSet.Destroy(Trackable trackable,bool destroyGameObject 

and passing true for the destroyGameObject parameter.

 

if you look at the UserDefinedTargets sample, you can find some code to destroy trackables using the function above (wiith the effect of both removing the trackable from the scene and from the tracker detection system);

the relevant code is in UserDefinedTargetEventHandler.cs:

public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        // deactivates the dataset first
        mImageTracker.DeactivateDataSet(mBuiltDataSet);
        
        // Destroy the oldest target if the dataset is full or the dataset 
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= 5)
        {
            IEnumerable<Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
                if (oldest == null || trackable.ID < oldest.ID)
                    oldest = trackable;

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

 

Hello!

Is UserDefinedTargets only used in imagettarget?

Destroying a user defined target and removing recognition

February 10, 2013 - 9:51am #6

These are the instructions you're using ?

 

Request an ImageTracker instance as explained above.
 
Make sure that the dataset to destroy is not active (otherwise destruction will fail): ImageTracker.Deactivate(DataSet dataset);
    
Destroy the dataset: ImageTracker.DestroyDataSet(DataSet dataset, bool destroyTrackableGameObjects);


	
// Destroy a dataset.
private bool DestroyDataSet(DataSet dataSet)
{
    // Request an ImageTracker instance from the TrackerManager.
    ImageTracker imageTracker =
 (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
  
  // Make sure the data set is not active.
    imageTracker.DeactivateDataSet(dataSet);
  
    // Destroy the data set
    // (choose true to also destroy the Target objects that belong to the data set).
    bool success = imageTracker.DestroyDataSet(dataSet, true);
 
    return success;
}

 

Is this for an ImageTarget or FrameMarker?

Destroying a user defined target and removing recognition

February 9, 2013 - 5:34pm #5

Hello.  I'm trying to destroy a target as per the instructions but constantly get:

Could not destroy trackable with id 1 

 

I've Deactivated the dataset prior to attempting to destroy it via dataset.Destroy(trackable,true);
 
Any pointers?
 
Alejandro.

Destroying a user defined target and removing recognition

January 31, 2013 - 11:40am #4

You're welcome.

Destroying a user defined target and removing recognition

January 31, 2013 - 11:34am #3

Thanks again Alessandro!  I knew that call would do what I needed, just couldn't find the reference to get at it.

I should have found that code section in the handler but I think I got too many results in my greps for Destroy and DataSet and just looked past it.

Destroying a user defined target and removing recognition

January 31, 2013 - 1:02am #2

Hi, 

you should simply need this method:

DataSet.Destroy(Trackable trackable,bool destroyGameObject 

and passing true for the destroyGameObject parameter.

 

if you look at the UserDefinedTargets sample, you can find some code to destroy trackables using the function above (wiith the effect of both removing the trackable from the scene and from the tracker detection system);

the relevant code is in UserDefinedTargetEventHandler.cs:

public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        // deactivates the dataset first
        mImageTracker.DeactivateDataSet(mBuiltDataSet);
        
        // Destroy the oldest target if the dataset is full or the dataset 
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= 5)
        {
            IEnumerable<Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
                if (oldest == null || trackable.ID < oldest.ID)
                    oldest = trackable;

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

 

Log in or register to post comments