1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkParallelCoordinatesHistogramRepresentation.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16   Copyright 2009 Sandia Corporation.
17   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18   the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20 // .NAME vtkParallelCoordinatesHistogramRepresentation - Data representation
21 //  that takes generic multivariate data and produces a parallel coordinates plot.
22 //  This plot optionally can draw a histogram-based plot summary.
23 //
24 // .SECTION Description
25 //  A parallel coordinates plot represents each variable in a multivariate
26 //  data set as a separate axis.  Individual samples of that data set are
27 //  represented as a polyline that pass through each variable axis at
28 //  positions that correspond to data values.  This class can generate
29 //  parallel coordinates plots identical to its superclass
30 //  (vtkParallelCoordinatesRepresentation) and has the same interaction
31 //  styles.
32 //
33 //  In addition to the standard parallel coordinates plot, this class also
34 //  can draw a histogram summary of the parallel coordinates plot.
35 //  Rather than draw every row in an input data set, first it computes
36 //  a 2D histogram for all neighboring variable axes, then it draws
37 //  bar (thickness corresponds to bin size) for each bin the histogram
38 //  with opacity weighted by the number of rows contained in the bin.
39 //  The result is essentially a density map.
40 //
41 //  Because this emphasizes dense regions over sparse outliers, this class
42 //  also uses a vtkComputeHistogram2DOutliers instance to identify outlier
43 //  table rows and draws those as standard parallel coordinates lines.
44 //
45 // .SECTION See Also
46 //  vtkParallelCoordinatesView vtkParallelCoordinatesRepresentation
47 //  vtkExtractHistogram2D vtkComputeHistogram2DOutliers
48 //
49 // .SECTION Thanks
50 //  Developed by David Feng at Sandia National Laboratories
51 
52 #ifndef vtkParallelCoordinatesHistogramRepresentation_h
53 #define vtkParallelCoordinatesHistogramRepresentation_h
54 
55 #include "vtkViewsInfovisModule.h" // For export macro
56 #include "vtkParallelCoordinatesRepresentation.h"
57 
58 class vtkComputeHistogram2DOutliers;
59 class vtkPairwiseExtractHistogram2D;
60 class vtkExtractHistogram2D;
61 class vtkInformationVector;
62 class vtkLookupTable;
63 
64 class VTKVIEWSINFOVIS_EXPORT vtkParallelCoordinatesHistogramRepresentation : public vtkParallelCoordinatesRepresentation
65 {
66 public:
67   static vtkParallelCoordinatesHistogramRepresentation* New();
68   vtkTypeMacro(vtkParallelCoordinatesHistogramRepresentation, vtkParallelCoordinatesRepresentation);
69   void PrintSelf(ostream& os, vtkIndent indent);
70 
71   // Description:
72   // Apply the theme to this view.
73   virtual void ApplyViewTheme(vtkViewTheme* theme);
74 
75   // Description:
76   // Whether to use the histogram rendering mode or the superclass's line rendering mode
77   virtual void SetUseHistograms(int);
78   vtkGetMacro(UseHistograms,int);
79   vtkBooleanMacro(UseHistograms,int);
80 
81   // Description:
82   // Whether to compute and show outlier lines
83   virtual void SetShowOutliers(int);
84   vtkGetMacro(ShowOutliers,int);
85   vtkBooleanMacro(ShowOutliers,int);
86 
87   // Description:
88   // Control over the range of the lookup table used to draw the histogram quads.
89   vtkSetVector2Macro(HistogramLookupTableRange,double);
90   vtkGetVector2Macro(HistogramLookupTableRange,double);
91 
92   //BTX
93   // Description:
94   // The number of histogram bins on either side of each pair of axes.
95   void SetNumberOfHistogramBins(int,int);
96   void SetNumberOfHistogramBins(int*);
97   vtkGetVector2Macro(NumberOfHistogramBins,int);
98   //ETX
99 
100   // Description:
101   // Target maximum number of outliers to be drawn, although not guaranteed.
102   void SetPreferredNumberOfOutliers(int);
103   vtkGetMacro(PreferredNumberOfOutliers,int);
104 
105   // Description:
106   // Calls superclass swap, and assures that only histograms affected by the
107   // swap get recomputed.
108   virtual int SwapAxisPositions(int position1, int position2);
109 
110   // Description:
111   // Calls the superclass method, and assures that only the two histograms
112   // affect by this call get recomputed.
113   virtual int SetRangeAtPosition(int position, double range[2]);
114 
115 protected:
116   vtkParallelCoordinatesHistogramRepresentation();
117   virtual ~vtkParallelCoordinatesHistogramRepresentation();
118 
119   virtual int RequestData(
120     vtkInformation*,
121     vtkInformationVector**,
122     vtkInformationVector*);
123 
124   virtual bool AddToView(vtkView* view);
125 
126   virtual bool RemoveFromView(vtkView* view);
127 
128   // Description:
129   // Flag deciding if histograms will be drawn.
130   int UseHistograms;
131 
132   // Description:
133   // The range applied to the lookup table used to draw histogram quads
134   double HistogramLookupTableRange[2];
135 
136   // Description:
137   // How many bins are used during the 2D histogram computation
138   int NumberOfHistogramBins[2];
139 
140   //BTX
141   vtkSmartPointer<vtkPairwiseExtractHistogram2D> HistogramFilter;
142   vtkSmartPointer<vtkLookupTable> HistogramLookupTable;
143   //ETX
144 
145   // Description:
146   // Whether or not to draw outlier lines
147   int ShowOutliers;
148 
149   // Description:
150   // How many outlier lines to draw, approximately.
151   int PreferredNumberOfOutliers;
152 
153   //BTX
154   vtkSmartPointer<vtkComputeHistogram2DOutliers> OutlierFilter;
155   vtkSmartPointer<vtkPolyData> OutlierData;
156   vtkSmartPointer<vtkPolyDataMapper2D> OutlierMapper;
157   vtkSmartPointer<vtkActor2D> OutlierActor;
158   //ETX
159 
160   // Description:
161   // Correctly forwards the superclass call to draw lines to the internal
162   // PlaceHistogramLineQuads call.
163   virtual int PlaceLines(vtkPolyData* polyData, vtkTable* data, vtkIdTypeArray* idsToPlot);
164 
165   // Description:
166   // Correctly forwards the superclass call to draw curves to the internal
167   // PlaceHistogramLineCurves call.
168   virtual int PlaceCurves(vtkPolyData* polyData, vtkTable* data, vtkIdTypeArray* idsToPlot);
169 
170   // Description:
171   // Draw a selection node referencing the row ids of a table into a poly data object.
172   virtual int PlaceSelection(vtkPolyData* polyData, vtkTable* data, vtkSelectionNode* selectionNode);
173 
174   // Description:
175   // Take the input 2D histogram images and draw one quad for each bin
176   virtual int PlaceHistogramLineQuads(vtkPolyData* polyData);
177 
178   // Description:
179   // Take the input 2D histogram images and draw one triangle strip that
180   // is the curved version of the regular quad drawn via PlaceHistogramLineQuads
181   virtual int PlaceHistogramCurveQuads(vtkPolyData* polyData);
182 
183   // Description:
184   // Compute the number of axes and their individual ranges, as well
185   // as histograms if requested.
186   virtual int ComputeDataProperties();
187   virtual int UpdatePlotProperties(vtkStringArray*);
188 
189   // Description:
190   // Access the input data object containing the histograms and
191   // pull out the image data for the idx'th histogram.
192   virtual vtkImageData* GetHistogramImage(int idx);
193 
194   // Description:
195   // get the table containing just the outlier rows from the input table.
196   virtual vtkTable* GetOutlierData();
197 private:
198   vtkParallelCoordinatesHistogramRepresentation(const vtkParallelCoordinatesHistogramRepresentation&); // Not implemented
199   void operator=(const vtkParallelCoordinatesHistogramRepresentation&);   // Not implemented
200 };
201 
202 #endif
203