package myagent.featuredetectors;

import edu.memphis.ccrg.lida.framework.shared.ElementFactory;
import edu.memphis.ccrg.lida.globalworkspace.GlobalWorkspace;
import edu.memphis.ccrg.lida.pam.PamNodeImpl;
import java.util.HashMap;
import java.util.Map;

import edu.memphis.ccrg.lida.pam.tasks.BasicDetectionAlgorithm;
import edu.memphis.ccrg.lida.workspace.Workspace;
import java.util.HashSet;


public class GenericColorFeatureDetector extends BasicDetectionAlgorithm{

    private Map<String, Object> smParams = new HashMap<String, Object>();
    protected Workspace workspace;
    protected GlobalWorkspace globalWorkspace;
    
    @Override
    public void init() {
       super.init();
       
       smParams.put("mode","all");
    }

    @Override
    public double detect() {
        int[] layer = (int[]) sensoryMemory.getSensoryContent("visual",smParams);
        
        HashSet<Integer> handledColors = new HashSet<Integer>();
        
        for(int i=0;i<layer.length;i++){
            int color = layer[i];
            
            if(!handledColors.contains(color)){
                String label = Integer.toHexString(color).toUpperCase();
                PamNodeImpl node = (PamNodeImpl) pam.getNode(label);

                if(node == null){
                    node = (PamNodeImpl) ElementFactory.getInstance().getNode(
                            "PamNodeImpl", 
                            ElementFactory.getInstance().getDefaultDecayType(),
                            ElementFactory.getInstance().getDefaultExciteType(),
                            label,
                            1.0, 
                            0.01);
                    
                    pam.addNodeToPercept(node);
                }
                else{
                    pam.receiveExcitation(node, 0.1);
                }
                
                handledColors.add(color);
            }
                 
        }
       return 0.0;
    }
}
