VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/DataModel/vtkGraph.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkGraph.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 =========================================================================*/
00015 /*-------------------------------------------------------------------------
00016   Copyright 2008 Sandia Corporation.
00017   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00018   the U.S. Government retains certain rights in this software.
00019 -------------------------------------------------------------------------*/
00215 #ifndef vtkGraph_h
00216 #define vtkGraph_h
00217 
00218 #include "vtkCommonDataModelModule.h" // For export macro
00219 #include "vtkDataObject.h"
00220 
00221 class vtkAdjacentVertexIterator;
00222 class vtkCellArray;
00223 class vtkEdgeListIterator;
00224 class vtkDataSetAttributes;
00225 class vtkDirectedGraph;
00226 class vtkGraphEdge;
00227 class vtkGraphEdgePoints;
00228 class vtkDistributedGraphHelper;
00229 class vtkGraphInternals;
00230 class vtkIdTypeArray;
00231 class vtkInEdgeIterator;
00232 class vtkOutEdgeIterator;
00233 class vtkPoints;
00234 class vtkUndirectedGraph;
00235 class vtkVertexListIterator;
00236 class vtkVariant;
00237 class vtkVariantArray;
00238 
00239 //BTX
00240 // Forward declare some boost stuff even if boost wrappers
00241 // are turned off.
00242 namespace boost
00243 {
00244   class vtk_edge_iterator;
00245   class vtk_out_edge_pointer_iterator;
00246   class vtk_in_edge_pointer_iterator;
00247 }
00248 
00249 // Edge structures.
00250 struct vtkEdgeBase
00251 {
00252   vtkEdgeBase() { }
00253   vtkEdgeBase(vtkIdType id) :
00254     Id(id) { }
00255   vtkIdType Id;
00256 };
00257 
00258 struct vtkOutEdgeType : vtkEdgeBase
00259 {
00260   vtkOutEdgeType() { }
00261   vtkOutEdgeType(vtkIdType t, vtkIdType id) :
00262     vtkEdgeBase(id),
00263     Target(t) { }
00264   vtkIdType Target;
00265 };
00266 
00267 struct vtkInEdgeType : vtkEdgeBase
00268 {
00269   vtkInEdgeType() { }
00270   vtkInEdgeType(vtkIdType s, vtkIdType id) :
00271     vtkEdgeBase(id),
00272     Source(s) { }
00273   vtkIdType Source;
00274 };
00275 
00276 struct vtkEdgeType : vtkEdgeBase
00277 {
00278   vtkEdgeType() { }
00279   vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id) :
00280     vtkEdgeBase(id),
00281     Source(s),
00282     Target(t) { }
00283   vtkIdType Source;
00284   vtkIdType Target;
00285 };
00286 //ETX
00287 
00288 class VTKCOMMONDATAMODEL_EXPORT vtkGraph : public vtkDataObject
00289 {
00290 public:
00291   vtkTypeMacro(vtkGraph, vtkDataObject);
00292   void PrintSelf(ostream& os, vtkIndent indent);
00293 
00295 
00296   vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
00297   vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
00299 
00301   virtual int GetDataObjectType() {return VTK_GRAPH;}
00302 
00304   virtual void Initialize();
00305 
00307 
00310   double *GetPoint(vtkIdType ptId);
00311   void GetPoint(vtkIdType ptId, double x[3]);
00313 
00315 
00319   vtkPoints* GetPoints();
00320   virtual void SetPoints(vtkPoints *points);
00322 
00325   void ComputeBounds();
00326 
00328 
00331   double *GetBounds();
00332   void GetBounds(double bounds[6]);
00334 
00336   unsigned long int GetMTime();
00337 
00341   virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it);
00342 
00346   virtual vtkIdType GetDegree(vtkIdType v);
00347 
00351   virtual vtkIdType GetOutDegree(vtkIdType v);
00352 
00353   //BTX
00355 
00356   virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index);
00357   //ETX
00359 
00364   virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
00365 
00369   virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator *it);
00370 
00374   virtual vtkIdType GetInDegree(vtkIdType v);
00375 
00376   //BTX
00378 
00379   virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index);
00380   //ETX
00382 
00387   virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
00388 
00393   virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator *it);
00394 
00398   virtual void GetEdges(vtkEdgeListIterator *it);
00399 
00402   virtual vtkIdType GetNumberOfEdges();
00403 
00407   virtual void GetVertices(vtkVertexListIterator *it);
00408 
00411   virtual vtkIdType GetNumberOfVertices();
00412 
00413   // BTX
00417   void SetDistributedGraphHelper(vtkDistributedGraphHelper *helper);
00418 
00420 
00421   vtkDistributedGraphHelper *GetDistributedGraphHelper();
00422   //ETX
00424 
00431   vtkIdType FindVertex(const vtkVariant& pedigreeID);
00432 
00435   virtual void ShallowCopy(vtkDataObject *obj);
00436 
00439   virtual void DeepCopy(vtkDataObject *obj);
00440 
00443   virtual void CopyStructure(vtkGraph *g);
00444 
00447   virtual bool CheckedShallowCopy(vtkGraph *g);
00448 
00451   virtual bool CheckedDeepCopy(vtkGraph *g);
00452 
00454   virtual void Squeeze();
00455 
00456   //BTX
00458 
00459   static vtkGraph *GetData(vtkInformation *info);
00460   static vtkGraph *GetData(vtkInformationVector *v, int i=0);
00461   //ETX
00463 
00468   void ReorderOutVertices(vtkIdType v, vtkIdTypeArray *vertices);
00469 
00472   bool IsSameStructure(vtkGraph *other);
00473 
00475 
00481   vtkIdType GetSourceVertex(vtkIdType e);
00482   vtkIdType GetTargetVertex(vtkIdType e);
00484 
00485   //BTX
00487 
00490   void SetEdgePoints(vtkIdType e, vtkIdType npts, double* pts);
00491   void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts);
00492   //ETX
00494 
00496   vtkIdType GetNumberOfEdgePoints(vtkIdType e);
00497 
00499   double* GetEdgePoint(vtkIdType e, vtkIdType i);
00500 
00502   void ClearEdgePoints(vtkIdType e);
00503 
00505 
00507   void SetEdgePoint(vtkIdType e, vtkIdType i, double x[3]);
00508   void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
00509     { double p[3] = {x, y, z}; this->SetEdgePoint(e, i, p); }
00511 
00513 
00515   void AddEdgePoint(vtkIdType e, double x[3]);
00516   void AddEdgePoint(vtkIdType e, double x, double y, double z)
00517     { double p[3] = {x, y, z}; this->AddEdgePoint(e, p); }
00519 
00521 
00523   void ShallowCopyEdgePoints(vtkGraph* g);
00524   void DeepCopyEdgePoints(vtkGraph* g);
00526 
00530   vtkGraphInternals *GetGraphInternals(bool modifying);
00531 
00534   void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
00535 
00540   virtual vtkFieldData* GetAttributesAsFieldData(int type);
00541 
00544   virtual vtkIdType GetNumberOfElements(int type);
00545 
00547   void Dump();
00548 
00555   vtkIdType GetEdgeId(vtkIdType a, vtkIdType b);
00556 
00558   bool ToDirectedGraph(vtkDirectedGraph* g);
00559 
00561   bool ToUndirectedGraph(vtkUndirectedGraph* g);
00562 
00563 protected:
00564   //BTX
00565   vtkGraph();
00566   ~vtkGraph();
00567 
00569 
00574   void AddVertexInternal(vtkVariantArray *propertyArr = 0,
00575                          vtkIdType *vertex = 0);
00577 
00582   void AddVertexInternal(const vtkVariant& pedigree, vtkIdType *vertex);
00583 
00585 
00589   void AddEdgeInternal(vtkIdType u, vtkIdType v, bool directed,
00590                        vtkVariantArray *propertyArr, vtkEdgeType *edge);
00591   void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
00592                        vtkVariantArray *propertyArr, vtkEdgeType *edge);
00593   void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
00594                        vtkVariantArray *propertyArr, vtkEdgeType *edge);
00595   void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree,
00596                        bool directed, vtkVariantArray *propertyArr,
00597                        vtkEdgeType *edge);
00599 
00602   void RemoveVertexInternal(vtkIdType v, bool directed);
00603 
00606   void RemoveEdgeInternal(vtkIdType e, bool directed);
00607 
00610   void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
00611 
00613 
00614   void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
00615   //ETX
00617 
00620   virtual bool IsStructureValid(vtkGraph *g) = 0;
00621 
00623   virtual void CopyInternal(vtkGraph *g, bool deep);
00624 
00626   vtkGraphInternals *Internals;
00627 
00629   vtkDistributedGraphHelper *DistributedHelper;
00630 
00632   void SetInternals(vtkGraphInternals* internals);
00633 
00635   vtkGraphEdgePoints *EdgePoints;
00636 
00638   void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
00639 
00642   void ForceOwnership();
00643 
00645 
00646   virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType *& edges, vtkIdType & nedges);
00647   virtual void GetInEdges(vtkIdType v, const vtkInEdgeType *& edges, vtkIdType & nedges);
00649 
00651   void BuildEdgeList();
00652 
00653   //BTX
00655 
00656   friend class vtkAdjacentVertexIterator;
00657   friend class vtkEdgeListIterator;
00658   friend class vtkInEdgeIterator;
00659   friend class vtkOutEdgeIterator;
00660   friend class boost::vtk_edge_iterator;
00661   friend class boost::vtk_in_edge_pointer_iterator;
00662   friend class boost::vtk_out_edge_pointer_iterator;
00663   //ETX
00665 
00667 
00668   vtkDataSetAttributes *VertexData;
00669   vtkDataSetAttributes *EdgeData;
00671 
00673   double Bounds[6];
00674 
00676   vtkTimeStamp ComputeTime;
00677 
00679 
00680   vtkPoints *Points;
00681   static double DefaultPoint[3];
00683 
00685 
00686   vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
00687   virtual void SetEdgeList(vtkIdTypeArray* list);
00688   vtkIdTypeArray *EdgeList;
00689   //ETX
00690 private:
00691   vtkGraph(const vtkGraph&);  // Not implemented.
00692   void operator=(const vtkGraph&);  // Not implemented.
00693 };
00695 
00696 //BTX
00697 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
00698 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
00699 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
00700 //ETX
00701 
00702 #endif