VTK
|
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 "vtkDataObject.h" 00219 00220 class vtkAdjacentVertexIterator; 00221 class vtkCellArray; 00222 class vtkEdgeListIterator; 00223 class vtkDataSetAttributes; 00224 class vtkDirectedGraph; 00225 class vtkGraphEdge; 00226 class vtkGraphEdgePoints; 00227 class vtkDistributedGraphHelper; 00228 class vtkGraphInternals; 00229 class vtkIdTypeArray; 00230 class vtkInEdgeIterator; 00231 class vtkOutEdgeIterator; 00232 class vtkPoints; 00233 class vtkUndirectedGraph; 00234 class vtkVertexListIterator; 00235 class vtkVariant; 00236 class vtkVariantArray; 00237 00238 //BTX 00239 // Forward declare some boost stuff even if boost wrappers 00240 // are turned off. 00241 namespace boost 00242 { 00243 class vtk_edge_iterator; 00244 class vtk_out_edge_pointer_iterator; 00245 class vtk_in_edge_pointer_iterator; 00246 } 00247 00248 // Edge structures. 00249 struct vtkEdgeBase 00250 { 00251 vtkEdgeBase() { } 00252 vtkEdgeBase(vtkIdType id) : 00253 Id(id) { } 00254 vtkIdType Id; 00255 }; 00256 00257 struct vtkOutEdgeType : vtkEdgeBase 00258 { 00259 vtkOutEdgeType() { } 00260 vtkOutEdgeType(vtkIdType t, vtkIdType id) : 00261 vtkEdgeBase(id), 00262 Target(t) { } 00263 vtkIdType Target; 00264 }; 00265 00266 struct vtkInEdgeType : vtkEdgeBase 00267 { 00268 vtkInEdgeType() { } 00269 vtkInEdgeType(vtkIdType s, vtkIdType id) : 00270 vtkEdgeBase(id), 00271 Source(s) { } 00272 vtkIdType Source; 00273 }; 00274 00275 struct vtkEdgeType : vtkEdgeBase 00276 { 00277 vtkEdgeType() { } 00278 vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id) : 00279 vtkEdgeBase(id), 00280 Source(s), 00281 Target(t) { } 00282 vtkIdType Source; 00283 vtkIdType Target; 00284 }; 00285 //ETX 00286 00287 class VTK_FILTERING_EXPORT vtkGraph : public vtkDataObject 00288 { 00289 public: 00290 vtkTypeMacro(vtkGraph, vtkDataObject); 00291 void PrintSelf(ostream& os, vtkIndent indent); 00292 00294 00295 vtkGetObjectMacro(VertexData, vtkDataSetAttributes); 00296 vtkGetObjectMacro(EdgeData, vtkDataSetAttributes); 00298 00300 virtual int GetDataObjectType() {return VTK_GRAPH;} 00301 00303 virtual void Initialize(); 00304 00306 00309 double *GetPoint(vtkIdType ptId); 00310 void GetPoint(vtkIdType ptId, double x[3]); 00312 00314 00318 vtkPoints* GetPoints(); 00319 virtual void SetPoints(vtkPoints *points); 00321 00324 void ComputeBounds(); 00325 00327 00330 double *GetBounds(); 00331 void GetBounds(double bounds[6]); 00333 00335 unsigned long int GetMTime(); 00336 00340 virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it); 00341 00345 virtual vtkIdType GetDegree(vtkIdType v); 00346 00350 virtual vtkIdType GetOutDegree(vtkIdType v); 00351 00352 //BTX 00354 00355 virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index); 00356 //ETX 00358 00363 virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e); 00364 00368 virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator *it); 00369 00373 virtual vtkIdType GetInDegree(vtkIdType v); 00374 00375 //BTX 00377 00378 virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index); 00379 //ETX 00381 00386 virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e); 00387 00392 virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator *it); 00393 00397 virtual void GetEdges(vtkEdgeListIterator *it); 00398 00401 virtual vtkIdType GetNumberOfEdges(); 00402 00406 virtual void GetVertices(vtkVertexListIterator *it); 00407 00410 virtual vtkIdType GetNumberOfVertices(); 00411 00412 // BTX 00416 void SetDistributedGraphHelper(vtkDistributedGraphHelper *helper); 00417 00419 00420 vtkDistributedGraphHelper *GetDistributedGraphHelper(); 00421 //ETX 00423 00430 vtkIdType FindVertex(const vtkVariant& pedigreeID); 00431 00434 virtual void ShallowCopy(vtkDataObject *obj); 00435 00438 virtual void DeepCopy(vtkDataObject *obj); 00439 00442 virtual void CopyStructure(vtkGraph *g); 00443 00446 virtual bool CheckedShallowCopy(vtkGraph *g); 00447 00450 virtual bool CheckedDeepCopy(vtkGraph *g); 00451 00453 virtual void Squeeze(); 00454 00455 //BTX 00457 00458 static vtkGraph *GetData(vtkInformation *info); 00459 static vtkGraph *GetData(vtkInformationVector *v, int i=0); 00460 //ETX 00462 00467 void ReorderOutVertices(vtkIdType v, vtkIdTypeArray *vertices); 00468 00471 bool IsSameStructure(vtkGraph *other); 00472 00474 00480 vtkIdType GetSourceVertex(vtkIdType e); 00481 vtkIdType GetTargetVertex(vtkIdType e); 00483 00484 //BTX 00486 00489 void SetEdgePoints(vtkIdType e, vtkIdType npts, double* pts); 00490 void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts); 00491 //ETX 00493 00495 vtkIdType GetNumberOfEdgePoints(vtkIdType e); 00496 00498 double* GetEdgePoint(vtkIdType e, vtkIdType i); 00499 00501 void ClearEdgePoints(vtkIdType e); 00502 00504 00506 void SetEdgePoint(vtkIdType e, vtkIdType i, double x[3]); 00507 void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z) 00508 { double p[3] = {x, y, z}; this->SetEdgePoint(e, i, p); } 00510 00512 00514 void AddEdgePoint(vtkIdType e, double x[3]); 00515 void AddEdgePoint(vtkIdType e, double x, double y, double z) 00516 { double p[3] = {x, y, z}; this->AddEdgePoint(e, p); } 00518 00520 00522 void ShallowCopyEdgePoints(vtkGraph* g); 00523 void DeepCopyEdgePoints(vtkGraph* g); 00525 00529 vtkGraphInternals *GetGraphInternals(bool modifying); 00530 00533 void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges); 00534 00539 virtual vtkFieldData* GetAttributesAsFieldData(int type); 00540 00543 virtual vtkIdType GetNumberOfElements(int type); 00544 00546 void Dump(); 00547 00554 vtkIdType GetEdgeId(vtkIdType a, vtkIdType b); 00555 00557 bool ToDirectedGraph(vtkDirectedGraph* g); 00558 00560 bool ToUndirectedGraph(vtkUndirectedGraph* g); 00561 00562 protected: 00563 //BTX 00564 vtkGraph(); 00565 ~vtkGraph(); 00566 00568 00573 void AddVertexInternal(vtkVariantArray *propertyArr = 0, 00574 vtkIdType *vertex = 0); 00576 00581 void AddVertexInternal(const vtkVariant& pedigree, vtkIdType *vertex); 00582 00584 00588 void AddEdgeInternal(vtkIdType u, vtkIdType v, bool directed, 00589 vtkVariantArray *propertyArr, vtkEdgeType *edge); 00590 void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed, 00591 vtkVariantArray *propertyArr, vtkEdgeType *edge); 00592 void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed, 00593 vtkVariantArray *propertyArr, vtkEdgeType *edge); 00594 void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree, 00595 bool directed, vtkVariantArray *propertyArr, 00596 vtkEdgeType *edge); 00598 00601 void RemoveVertexInternal(vtkIdType v, bool directed); 00602 00605 void RemoveEdgeInternal(vtkIdType e, bool directed); 00606 00609 void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed); 00610 00612 00613 void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed); 00614 //ETX 00616 00619 virtual bool IsStructureValid(vtkGraph *g) = 0; 00620 00622 virtual void CopyInternal(vtkGraph *g, bool deep); 00623 00625 vtkGraphInternals *Internals; 00626 00628 vtkDistributedGraphHelper *DistributedHelper; 00629 00631 void SetInternals(vtkGraphInternals* internals); 00632 00634 vtkGraphEdgePoints *EdgePoints; 00635 00637 void SetEdgePoints(vtkGraphEdgePoints* edgePoints); 00638 00641 void ForceOwnership(); 00642 00644 00645 virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType *& edges, vtkIdType & nedges); 00646 virtual void GetInEdges(vtkIdType v, const vtkInEdgeType *& edges, vtkIdType & nedges); 00648 00650 void BuildEdgeList(); 00651 00652 //BTX 00654 00655 friend class vtkAdjacentVertexIterator; 00656 friend class vtkEdgeListIterator; 00657 friend class vtkInEdgeIterator; 00658 friend class vtkOutEdgeIterator; 00659 friend class boost::vtk_edge_iterator; 00660 friend class boost::vtk_in_edge_pointer_iterator; 00661 friend class boost::vtk_out_edge_pointer_iterator; 00662 //ETX 00664 00666 00667 vtkDataSetAttributes *VertexData; 00668 vtkDataSetAttributes *EdgeData; 00670 00672 double Bounds[6]; 00673 00675 vtkTimeStamp ComputeTime; 00676 00678 00679 vtkPoints *Points; 00680 static double DefaultPoint[3]; 00682 00684 00685 vtkGetObjectMacro(EdgeList, vtkIdTypeArray); 00686 virtual void SetEdgeList(vtkIdTypeArray* list); 00687 vtkIdTypeArray *EdgeList; 00688 //ETX 00689 private: 00690 vtkGraph(const vtkGraph&); // Not implemented. 00691 void operator=(const vtkGraph&); // Not implemented. 00692 }; 00694 00695 //BTX 00696 bool VTK_FILTERING_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2); 00697 bool VTK_FILTERING_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2); 00698 VTK_FILTERING_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e); 00699 //ETX 00700 00701 #endif