Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/LayoutProperty.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 #ifndef TULIP_LAYOUT_H
00021 #define TULIP_LAYOUT_H
00022 
00023 #include <tulip/tuliphash.h>
00024 #include <tulip/PropertyTypes.h>
00025 #include <tulip/Observable.h>
00026 #include <tulip/AbstractProperty.h>
00027 #include <tulip/PropertyAlgorithm.h>
00028 #include <tulip/minmaxproperty.h>
00029 
00030 namespace tlp {
00031 
00032 template <>
00033 void tlp::MinMaxProperty<tlp::PointType, tlp::LineType>::updateEdgeValue(tlp::edge e, tlp::LineType::RealType newValue);
00034 
00035 template <>
00036 MINMAX_PAIR(tlp::PointType) tlp::MinMaxProperty<tlp::PointType, tlp::LineType>::computeMinMaxNode(Graph *sg);
00037 
00038 class PropertyContext;
00039 class Graph;
00040 
00041 typedef AbstractProperty<tlp::PointType, tlp::LineType> AbstractLayoutProperty;
00042 typedef MinMaxProperty<tlp::PointType, tlp::LineType> LayoutMinMaxProperty;
00043 
00044 /**
00045  * @ingroup Graph
00046  * @brief A graph property that maps a tlp::Coord value to graph nodes and std::vector<tlp::Coord> for edges.
00047  */
00048 class TLP_SCOPE LayoutProperty : public LayoutMinMaxProperty {
00049 public:
00050   LayoutProperty(Graph *graph, const std::string& name=""/*, bool updateOnEdgeReversal=true*/);
00051 
00052   // override some PropertyInterface methods
00053   PropertyInterface* clonePrototype(Graph *, const std::string& );
00054   static const std::string propertyTypename;
00055   const std::string& getTypename() const {
00056     return propertyTypename;
00057   }
00058 
00059   //=======================================
00060   //Methods for extra layout information
00061   //=======================================
00062 
00063   /**
00064   * Returns the maximum coordinate of the layout, i.e. the top-right corner of the induced bounding box
00065   *
00066   * @param subgraph If not null, returns the maximum coordinate for a sub-graph layout
00067   **/
00068   Coord getMax(Graph *subgraph=NULL);
00069 
00070   /**
00071   * Returns the minimum coordinate of the layout, i.e. the bottom-left corner of the induced bounding box
00072   *
00073   * @param subgraph If not null, returns the minimum coordinate for a sub-graph layout
00074   **/
00075   Coord getMin(Graph *subgraph=NULL);
00076 
00077   //============================================
00078   //Functions for layout modification
00079   //============================================
00080 
00081   /**
00082   * Translates the current layout according to a movement vector
00083   *
00084   * @param move a movement vector
00085   * @param subgraph If not null, only translates the layout of that sub-graph
00086   **/
00087   void translate(const Vec3f &move, Graph *subgraph=NULL);
00088 
00089   /**
00090   * Translates the layout of a set of nodes and edges provided through iterators
00091   * according to a movement vector
00092   *
00093   * @param move a movement vector
00094   * @param itNodes an iterator on graph nodes
00095   * @param itEdges an iterator on graph edges
00096   *
00097   * @warning The iterators are not deleted
00098   **/
00099   void translate(const Vec3f &move, Iterator<node> *itNodes, Iterator<edge> *itEdges);
00100 
00101   /**
00102   * Scales the current layout according to a vector of scale factors (sx, sy, sz).
00103   *
00104   * @param scaleFactors a vector of scale factors
00105   * @param subgraph If not null, only scales the layout of that sub-graph
00106   **/
00107   void scale(const Vec3f &scaleFactors, Graph *subgraph=NULL);
00108 
00109   /**
00110   * Scales the layout of a set of nodes and edges provided through iterators
00111   * according to a vector of scale factors (sx, sy, sz).
00112   *
00113   * @param scaleFactors a vector of scale factors
00114   * @param itNodes an iterator on graph nodes
00115   * @param itEdges an iterator on graph edges
00116   *
00117   * @warning The iterators are not deleted
00118   **/
00119   void scale(const Vec3f &scaleFactors, Iterator<node> *itNodes, Iterator<edge> *itEdges);
00120 
00121   /**
00122   * Rotates the layout around the X-axis according to an angle in degrees.
00123   *
00124   * @param alpha an angle in degrees
00125   * @param subgraph If not null, only rotates the layout of that sub-graph
00126   **/
00127   void rotateX(const double &alpha, Graph *subgraph=NULL);
00128 
00129   /**
00130   * Rotates the layout around the Y-axis according to an angle in degrees.
00131   *
00132   * @param alpha an angle in degrees
00133   * @param subgraph If not null, only rotates the layout of that sub-graph
00134   **/
00135   void rotateY(const double &alpha, Graph *subgraph=NULL);
00136 
00137   /**
00138   * Rotates the layout around the Z-axis according to an angle in degrees.
00139   *
00140   * @param alpha an angle in degrees
00141   * @param subgraph If not null, only rotates the layout of that sub-graph
00142   **/
00143   void rotateZ(const double &alpha, Graph *subgraph=NULL);
00144 
00145   /**
00146   * Rotates the layout around the X-axis of the nodes and edges provided
00147   * through iterators according to an angle in degrees.
00148   *
00149   * @param alpha an angle in degrees
00150   * @param itNodes an iterator on graph nodes
00151   * @param itEdges an iterator on graph edges
00152   *
00153   * @warning The iterators are not deleted
00154   **/
00155   void rotateX(const double &alpha, Iterator<node> *itNodes, Iterator<edge> *itEdges);
00156 
00157   /**
00158   * Rotates the layout around the Y-axis of the nodes and edges provided
00159   * through iterators according to an angle in degrees.
00160   *
00161   * @param alpha an angle in degrees
00162   * @param itNodes an iterator on graph nodes
00163   * @param itEdges an iterator on graph edges
00164   *
00165   * @warning The iterators are not deleted
00166   **/
00167   void rotateY(const double &alpha, Iterator<node> *itNodes, Iterator<edge> *itEdges);
00168 
00169   /**
00170   * Rotates the layout around the Z-axis of the nodes and edges provided through
00171   * iterators according to an angle in degrees.
00172   *
00173   * @param alpha an angle in degrees
00174   * @param itNodes an iterator on graph nodes
00175   * @param itEdges an iterator on graph edges
00176   *
00177   * @warning The iterators are not deleted
00178   **/
00179   void rotateZ(const double &alpha, Iterator<node> *itNodes, Iterator<edge> *itEdges);
00180 
00181   /**
00182   * Centers the layout, meaning translating it in order that
00183   * the center of its bounding box is (0,0,0)
00184   *
00185   * @param subgraph If not null, only centers the layout of that sub-graph
00186   **/
00187   void center(Graph *subgraph=NULL);
00188 
00189   /**
00190   * Centers the layout to newCenter, meaning translating it in order that
00191   * the center of its bounding box is equal to newCenter
00192   *
00193   * @param newCenter the coordinate of the new layout center
00194   * @param subgraph If not null, only centers the layout of that sub-graph
00195   **/
00196   void center(const Vec3f &newCenter, Graph *subgraph=NULL);
00197 
00198   /**
00199   * Normalizes the layout, meaning dividing each nodes and edges coordinate by the maximum magnitude of the whole coordinates set
00200   *
00201   * @param subgraph If not null, only normalizes the layout of that sub-graph
00202   **/
00203   void normalize(Graph *subgraph=NULL);
00204 
00205   /**
00206   * Scales the layout in order to approach an aspect ratio (width / height) of 1.0 .
00207   **/
00208   void perfectAspectRatio();
00209 
00210   //=======================================================================
00211   // Set of function in order to measure the quality of the LayoutAlgorithm
00212   //=======================================================================
00213 
00214   /**
00215   * Returns the length of an edge, the bends are taken into account.
00216   * Thus, it measure the length of a polyline.
00217   *
00218   * @param e the graph edge on which to compute its length
00219   *
00220   * @warning this function only measure the length of the polyline between bends,
00221   * when using curves like Bézier etc... the result will not be the length of the curve.
00222   **/
00223   double edgeLength(const edge e) const;
00224 
00225   /**
00226   * Returns the average edge length of the layout, the bends are taken into account
00227   *
00228   * @param subgraph If not null, only compute the average edge length for that sub-graph
00229   **/
00230   double averageEdgeLength(const Graph *subgraph=NULL) const;
00231 
00232   /**
00233   * Returns the average angular resolution of the layout.
00234   * It is only defined for 2D drawing, meaning the third coordinate
00235   * is omitted
00236   *
00237   * @param subgraph It not null, only computes the average angular resolution for that sub-graph
00238   **/
00239   double averageAngularResolution(const Graph *subgraph=NULL) const;
00240 
00241   /**
00242   * Returns the average angular resolution of a node.
00243   * It is only defined for 2D drawing, meaning the third coordinate
00244   * is omitted
00245   *
00246   * @param n the graph node on which to compute the angular resolution
00247   * @param subgraph If not null, only computes the average angular resolution for the node in that sub-graph
00248   **/
00249   double averageAngularResolution(const node n, const Graph *subgraph=NULL) const;
00250 
00251   /**
00252   * Returns a vector of all angular resolution of a node.
00253   * It is only defined for 2D drawing, meaning the third coordinate
00254   * is omitted
00255   *
00256   * @param n the graph node on which to compute the angular resolution
00257   * @param subgraph If not null, only computes the average angular resolution for the node in that sub-graph
00258   **/
00259   std::vector<double> angularResolutions(const node n, const Graph *subgraph=NULL) const;
00260 
00261   /**
00262   * Fixes embedding of the graph according to the layout
00263   * ie. sort edges around nodes according to their neighbors/bends position in the layout/
00264   * Only works in 2D, the third coordinate is not taken into account.
00265   *
00266   * @param subgraph It not null, only fixes embedding in that sub-graph
00267   **/
00268   void computeEmbedding(Graph *subgraph=NULL);
00269 
00270   /**
00271   * Fixes embedding of the node according to the layout
00272   * ie. sort edges around the node according to its neighbors/bends position in the layout/
00273   * Only work in 2D, the third coordinate is not taken into account.
00274   *
00275   * @param n the graph node on which to fix embedding
00276   * @param subgraph If not null, only fixes the embedding of the node in that sub-graph
00277   **/
00278   void computeEmbedding(const node n, Graph *subgraph=NULL);
00279 
00280   /**
00281   * Returns the number of crossings in the layout
00282   **/
00283   //methods removed until we have a working implementation
00284   //unsigned int crossingNumber() const;
00285 
00286   // redefinition of some AbstractProperty methods
00287   virtual void setNodeValue(const node, const Coord &v);
00288   virtual void setEdgeValue(const edge, const std::vector<Coord> &v);
00289   virtual void setAllNodeValue(const Coord &v);
00290   virtual void setAllEdgeValue(const std::vector<Coord> &v);
00291 
00292 protected:
00293   virtual void clone_handler(AbstractProperty<tlp::PointType, tlp::LineType> &);
00294 
00295 private:
00296   void resetBoundingBox();
00297   void rotate(const double& alpha, int rot, Iterator<node> *, Iterator<edge> *);
00298   // override Observable::treatEvent
00299   void treatEvent(const Event&);
00300 
00301 public:
00302   // the number of edges with bends
00303   unsigned int nbBendedEdges;
00304 };
00305 
00306 /**
00307  * @ingroup Graph
00308  * @brief A graph property that maps a std::vector<tlp::Coord> value to graph elements.
00309  */
00310 class TLP_SCOPE CoordVectorProperty:public AbstractVectorProperty<tlp::CoordVectorType, tlp::PointType> {
00311 public :
00312   CoordVectorProperty(Graph *g, const std::string& n=""):AbstractVectorProperty<CoordVectorType, tlp::PointType>(g, n) {}
00313   // redefinition of some PropertyInterface methods
00314   PropertyInterface* clonePrototype(Graph *, const std::string& );
00315   static const std::string propertyTypename;
00316   const std::string& getTypename() const {
00317     return propertyTypename;
00318   }
00319 
00320 };
00321 
00322 typedef CoordVectorProperty LayoutVectorProperty;
00323 
00324 
00325 
00326 }
00327 #endif
 All Classes Files Functions Variables Enumerations Enumerator Properties