1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkTreeDifferenceFilter.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 // .NAME vtkTreeDifferenceFilter - compare two trees
17 //
18 // .SECTION Description
19 // vtkTreeDifferenceFilter compares two trees by analyzing a vtkDoubleArray.
20 // Each tree must have a copy of this array.  A user of this filter should
21 // call SetComparisonArrayName to specify the array that should be used as
22 // the basis of coparison.  This array can either be part of the trees'
23 // EdgeData or VertexData.
24 //
25 
26 #ifndef vtkTreeDifferenceFilter_h
27 #define vtkTreeDifferenceFilter_h
28 
29 #include "vtkInfovisCoreModule.h" // For export macro
30 #include "vtkGraphAlgorithm.h"
31 
32 #include "vtkSmartPointer.h"      // For ivars
33 #include <vector>                 // For ivars
34 
35 class vtkDoubleArray;
36 class vtkTree;
37 
38 class VTKINFOVISCORE_EXPORT vtkTreeDifferenceFilter : public vtkGraphAlgorithm
39 {
40 public:
41   static vtkTreeDifferenceFilter* New();
42   vtkTypeMacro(vtkTreeDifferenceFilter,vtkGraphAlgorithm);
43   void PrintSelf(ostream& os, vtkIndent indent);
44 
45   // Description:
46   // Set/Get the name of the identifier array in the trees' VertexData.
47   // This array is used to find corresponding vertices in the two trees.
48   // If this array name is not set, then we assume that the vertices in
49   // the two trees to compare have corresponding vtkIdTypes.
50   // Otherwise, the named array must be a vtkStringArray.
51   // The identifier array does not necessarily have to specify a name for
52   // each vertex in the tree.  If some vertices are unnamed, then this
53   // filter will assign correspondence between ancestors of named vertices.
54   vtkSetStringMacro(IdArrayName);
55   vtkGetStringMacro(IdArrayName);
56 
57   // Description:
58   // Set/Get the name of the array that we're comparing between the two trees.
59   // The named array must be a vtkDoubleArray.
60   vtkSetStringMacro(ComparisonArrayName);
61   vtkGetStringMacro(ComparisonArrayName);
62 
63   // Description:
64   // Set/Get the name of a new vtkDoubleArray that will contain the results of
65   // the comparison between the two trees.  This new array will be added to
66   // the input tree's VertexData or EdgeData, based on the value of
67   // ComparisonArrayIsVertexData.  If this method is not called, the new
68   // vtkDoubleArray will be named "difference" by default.
69   vtkSetStringMacro(OutputArrayName);
70   vtkGetStringMacro(OutputArrayName);
71 
72   // Description:
73   // Specify whether the comparison array is within the trees' vertex data or
74   // not.  By default, we assume that the array to compare is within the trees'
75   // EdgeData().
76   vtkSetMacro(ComparisonArrayIsVertexData, bool);
77   vtkGetMacro(ComparisonArrayIsVertexData, bool);
78 
79 protected:
80   vtkTreeDifferenceFilter();
81   ~vtkTreeDifferenceFilter();
82 
83   virtual int RequestData(
84     vtkInformation*,
85     vtkInformationVector**,
86     vtkInformationVector*);
87 
88   virtual int FillInputPortInformation(int port, vtkInformation *info);
89 
90   // Description:
91   // Populate VertexMap and EdgeMap with meaningful values.  These maps
92   // allow us to look up the vtkIdType of a vertex or edge in tree #2,
93   // given its vtkIdType in tree #1.
94   bool GenerateMapping(vtkTree *tree1, vtkTree *tree2);
95 
96   // Description:
97   // Compute the differences between tree #1 and tree #2's copies of the
98   // comparison array.
99   vtkSmartPointer<vtkDoubleArray> ComputeDifference(vtkTree *tree1,
100                                                     vtkTree *tree2);
101 
102   char* IdArrayName;
103   char* ComparisonArrayName;
104   char* OutputArrayName;
105   bool ComparisonArrayIsVertexData;
106 
107   std::vector< vtkIdType > VertexMap;
108   std::vector< vtkIdType > EdgeMap;
109 
110 private:
111   vtkTreeDifferenceFilter(const vtkTreeDifferenceFilter&); // Not implemented
112   void operator=(const vtkTreeDifferenceFilter&);   // Not implemented
113 };
114 
115 #endif
116