VTK
dox/Views/Infovis/vtkDendrogramItem.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkDendrogramItem.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00038 #ifndef __vtkDendrogramItem_h
00039 #define __vtkDendrogramItem_h
00040 
00041 #include "vtkViewsInfovisModule.h" // For export macro
00042 #include "vtkContextItem.h"
00043 
00044 #include "vtkNew.h"               // For vtkNew ivars
00045 #include "vtkStdString.h"         // For SetGet ivars
00046 #include "vtkSmartPointer.h"      // For vtkSmartPointer ivars
00047 #include "vtkVector.h"            // For vtkVector2f ivar
00048 
00049 class vtkColorLegend;
00050 class vtkDoubleArray;
00051 class vtkGraphLayout;
00052 class vtkLookupTable;
00053 class vtkPruneTreeFilter;
00054 class vtkTree;
00055 
00056 class VTKVIEWSINFOVIS_EXPORT vtkDendrogramItem : public vtkContextItem
00057 {
00058 public:
00059   static vtkDendrogramItem *New();
00060   vtkTypeMacro(vtkDendrogramItem, vtkContextItem);
00061   virtual void PrintSelf(ostream &os, vtkIndent indent);
00062 
00067   virtual void SetTree(vtkTree *tree);
00068 
00070   vtkTree * GetTree();
00071 
00076   void CollapseToNumberOfLeafNodes(unsigned int n);
00077 
00079   vtkTree * GetPrunedTree();
00080 
00084   void SetColorArray(const char *arrayName);
00085 
00087 
00091   vtkSetMacro(ExtendLeafNodes, bool);
00092   vtkGetMacro(ExtendLeafNodes, bool);
00093   vtkBooleanMacro(ExtendLeafNodes, bool);
00095 
00098   void SetOrientation(int orientation);
00099 
00101   int GetOrientation();
00102 
00106   double GetAngleForOrientation(int orientation);
00107 
00111   double GetTextAngleForOrientation(int orientation);
00112 
00114 
00116   vtkSetMacro(DrawLabels, bool);
00117   vtkGetMacro(DrawLabels, bool);
00118   vtkBooleanMacro(DrawLabels, bool);
00120 
00122 
00123   vtkSetVector2Macro(Position, float);
00124   void SetPosition(const vtkVector2f &pos);
00126 
00128 
00129   vtkGetVector2Macro(Position, float);
00130   vtkVector2f GetPositionVector();
00132 
00134 
00136   vtkGetMacro(LeafSpacing, double);
00137   vtkSetMacro(LeafSpacing, double);
00139 
00143   void PrepareToPaint(vtkContext2D *painter);
00144 
00148   virtual void GetBounds(double bounds[4]);
00149 
00151   void ComputeLabelWidth(vtkContext2D *painter);
00152 
00154   float GetLabelWidth();
00155 
00159   bool GetPositionOfVertex(std::string vertexName, double position[2]);
00160 
00162   virtual bool Paint(vtkContext2D *painter);
00163 
00165 
00167   vtkGetMacro(LineWidth, float);
00168   vtkSetMacro(LineWidth, float);
00170 
00172 
00175   vtkSetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
00176   vtkGetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
00177   vtkBooleanMacro(DisplayNumberOfCollapsedLeafNodes, bool);
00179 
00181 
00186   vtkGetMacro(DistanceArrayName, vtkStdString);
00187   vtkSetMacro(DistanceArrayName, vtkStdString);
00189 
00191 
00195   vtkGetMacro(VertexNameArrayName, vtkStdString);
00196   vtkSetMacro(VertexNameArrayName, vtkStdString);
00198 
00199   // this struct & class allow us to generate a priority queue of vertices.
00200   struct WeightedVertex
00201   {
00202     vtkIdType ID;
00203     double weight;
00204   };
00205   class CompareWeightedVertices
00206   {
00207     public:
00208     // Returns true if v2 is higher priority than v1
00209     bool operator()(WeightedVertex& v1, WeightedVertex& v2)
00210     {
00211     if (v1.weight < v2.weight)
00212       {
00213       return false;
00214       }
00215      return true;
00216     }
00217   };
00218 
00219   //BTX
00221 
00222   enum
00223     {
00224     LEFT_TO_RIGHT,
00225     UP_TO_DOWN,
00226     RIGHT_TO_LEFT,
00227     DOWN_TO_UP
00228     };
00230 
00232   virtual bool Hit(const vtkContextMouseEvent &mouse);
00233 
00235 
00237   virtual bool MouseDoubleClickEvent( const vtkContextMouseEvent &event);
00238   //ETX
00240 
00241 protected:
00242   vtkDendrogramItem();
00243   ~vtkDendrogramItem();
00244 
00245   vtkVector2f PositionVector;
00246   float* Position;
00247 
00250   virtual void RebuildBuffers();
00251 
00254   virtual void PaintBuffers(vtkContext2D *painter);
00255 
00258   virtual bool IsDirty();
00259 
00262   void ComputeMultipliers();
00263 
00265   void ComputeBounds();
00266 
00268   void CountLeafNodes();
00269 
00271   int CountLeafNodes(vtkIdType vertex);
00272 
00274   vtkIdType GetClosestVertex(double x, double y);
00275 
00277   void CollapseSubTree(vtkIdType vertex);
00278 
00280   void ExpandSubTree(vtkIdType vertex);
00281 
00283   vtkIdType GetOriginalId(vtkIdType vertex);
00284 
00287   vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId);
00288 
00292   vtkIdType GetClickedCollapsedSubTree(double x, double y);
00293 
00298   void UpdateVisibleSceneExtent(vtkContext2D *painter);
00299 
00303   bool LineIsVisible(double x0, double y0, double x1, double y1);
00304 
00306   void SetOrientation(vtkTree *tree, int orientation);
00307 
00308   // Setup the position, size, and orientation of this dendrogram's color
00309   // legend based on the dendrogram's current orientation.
00310   void PositionColorLegend();
00311 
00312   vtkSmartPointer<vtkTree> Tree;
00313   vtkSmartPointer<vtkTree> LayoutTree;
00314 
00315 private:
00316   vtkDendrogramItem(const vtkDendrogramItem&); // Not implemented
00317   void operator=(const vtkDendrogramItem&); // Not implemented
00318 
00319   vtkSmartPointer<vtkTree> PrunedTree;
00320   unsigned long DendrogramBuildTime;
00321   vtkNew<vtkGraphLayout> Layout;
00322   vtkNew<vtkPruneTreeFilter> PruneFilter;
00323   vtkNew<vtkLookupTable> TriangleLookupTable;
00324   vtkNew<vtkLookupTable> TreeLookupTable;
00325   vtkNew<vtkColorLegend> ColorLegend;
00326   vtkDoubleArray* ColorArray;
00327   double MultiplierX;
00328   double MultiplierY;
00329   int NumberOfLeafNodes;
00330   double LeafSpacing;
00331 
00332   double MinX;
00333   double MinY;
00334   double MaxX;
00335   double MaxY;
00336   double SceneBottomLeft[3];
00337   double SceneTopRight[3];
00338   float LabelWidth;
00339   float LineWidth;
00340   bool ColorTree;
00341   bool ExtendLeafNodes;
00342   bool DrawLabels;
00343   bool DisplayNumberOfCollapsedLeafNodes;
00344   bool LegendPositionSet;
00345   vtkStdString DistanceArrayName;
00346   vtkStdString VertexNameArrayName;
00347 };
00348 
00349 #endif