1 /*
2  * This file is part of ELKI:
3  * Environment for Developing KDD-Applications Supported by Index-Structures
4  *
5  * Copyright (C) 2018
6  * ELKI Development Team
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 package de.lmu.ifi.dbs.elki.visualization.projector;
22 
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 
27 import de.lmu.ifi.dbs.elki.algorithm.clustering.optics.ClusterOrder;
28 import de.lmu.ifi.dbs.elki.visualization.VisualizationTask;
29 import de.lmu.ifi.dbs.elki.visualization.VisualizerContext;
30 import de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem;
31 import de.lmu.ifi.dbs.elki.visualization.opticsplot.OPTICSPlot;
32 import de.lmu.ifi.dbs.elki.visualization.projections.OPTICSProjection;
33 
34 /**
35  * Projection for OPTICS plots.
36  *
37  * @author Erich Schubert
38  * @since 0.4.0
39  */
40 public class OPTICSProjector implements Projector {
41   /**
42    * Cluster order result
43    */
44   private ClusterOrder clusterOrder;
45 
46   /**
47    * OPTICS plot image
48    */
49   private OPTICSPlot plot = null;
50 
51   /**
52    * Constructor.
53    *
54    * @param co Cluster order
55    */
OPTICSProjector(ClusterOrder co)56   public OPTICSProjector(ClusterOrder co) {
57     super();
58     this.clusterOrder = co;
59   }
60 
61   @Override
getMenuName()62   public String getMenuName() {
63     return "OPTICS Plot Projection";
64   }
65 
66   @Override
arrange(VisualizerContext context)67   public Collection<PlotItem> arrange(VisualizerContext context) {
68     List<PlotItem> col = new ArrayList<>(1);
69     List<VisualizationTask> tasks = context.getVisTasks(this);
70     if(!tasks.isEmpty()) {
71       final PlotItem it = new PlotItem(4., 1., new OPTICSProjection(this));
72       it.tasks = tasks;
73       col.add(it);
74     }
75     return col;
76   }
77 
78   /**
79    * Get the cluster order
80    *
81    * @return the cluster order
82    */
getResult()83   public ClusterOrder getResult() {
84     return clusterOrder;
85   }
86 
87   /**
88    * Get or produce the actual OPTICS plot.
89    *
90    * @param context Context to use
91    * @return Plot
92    */
getOPTICSPlot(VisualizerContext context)93   public OPTICSPlot getOPTICSPlot(VisualizerContext context) {
94     if(plot == null) {
95       plot = OPTICSPlot.plotForClusterOrder(clusterOrder, context);
96     }
97     return plot;
98   }
99 }