COPASI API  4.16.103
CLLayoutRenderer.h
Go to the documentation of this file.
1 // Copyright (C) 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #ifndef CLLAYOUTRENDERER_H__
7 #define CLLAYOUTRENDERER_H__
8 
9 #include <stack>
10 #include <string>
11 #include <map>
12 #include <vector>
13 #include <set>
14 #include <utility>
15 
19 
20 class CLBoundingBox;
21 class CLCurve;
22 class CLEllipse;
23 class CLFontRendererBase;
25 class CLGradientBase;
26 class CLGraphicalObject;
29 class CLGroup;
30 class CLayout;
31 class CLImage;
32 class CLImageTexturizer;
33 class CLLinearGradient;
34 class CLLineEnding;
35 class CLLineSegment;
37 class CLMetabGlyph;
39 class CLPoint;
40 class CLPolygon;
41 class CLRadialGradient;
42 class CLReactionGlyph;
43 class CLRectangle;
44 class CLRenderCurve;
45 class CLRenderPoint;
46 class CLRenderResolver;
47 class CLStyle;
48 class CLText;
49 class CLTextGlyph;
50 class CLTransform;
51 class CModel;
52 struct CLTextureSpec;
53 struct CLTextTextureSpec;
54 
55 #ifdef _WIN32
56 #define STD_CALL _stdcall
57 #else
58 #define STD_CALL
59 #endif
60 
62 {
63 protected:
64  std::stack<CLGroupAttributes> mStateList;
66  const CModel* mpModel;
69  // base directory to resolve relative references to image files
70  // in Image objects.
71  std::string mBaseDir;
72  double mZoomFactor;
73  // normally the aspect ratio of a draing will be the same as the
74  // widget in which it is displayed, but for rendering into a
75  // pixmap with Qt, we might need an aspect that is not 1.0
76  // e.g. if the part of the layout the user has chosen
77  // does not have the same aspect as the image the user wants to
78  // create
79  // Setting the aspect to a number other than 1.0 means
80  // that the x axis is scaled by this aspect
81  double mAspect;
82  double mX;
83  double mY;
84  double mW;
85  double mH;
87 
88  // callable that can create a texture for some given font settings and
89  // a piece of text
91 
92  // stores all resolved colors
93  std::map<std::string, CLRGBAColor> mColorMap;
94 
95  // stores the gradients
96  std::map<std::string, std::pair<const CLGradientBase*, CLTextureSpec*> > mGradientMap;
97 
98  // stores the textures for the different text objects
99  std::map<CLFontSpec, std::map<std::string, CLTextTextureSpec*> > mFontTextureMap;
100 
101  // stores the 1D line stipple textures for all line stipples
102  std::map<const std::vector<unsigned int>, const CLLineStippleTexture*> mLinestippleMap;
103 
104  // stores the style for each layout object so that we only have to
105  // resolve styles once
106  // we assume the layout and the render information does not change
107  std::map<const CLGraphicalObject*, const CLStyle*> mStyleMap;
108 
109  // list of objects that are within the current viewport
110  // we only have to draw objects in this list and the list has to be
111  // updated each time the viewport changes
112  std::vector<const CLGraphicalObject*> mDrawables;
113 
114  // stores all line endings
115  std::map<std::string, const CLLineEnding*> mLineEndingMap;
116 
117  // stores all image textures associated with the filename
118  // this way if an image is used mre then once, we only need one texture
119  std::map<std::string, const CLTextureSpec*> mImageMap;
120 
121  // stores the texture for each TextGlyph
122  // this way we have to resolve texts only once and
123  // lookup of the textures is easier as well
124  std::map<const CLTextGlyph*, const CLTextTextureSpec*> mTextGlyphMap;
125 
126  // stores the texture for each text object
127  // this way we have to resolve texts only once and
128  // lookup of the textures is easier as well
129  std::map<const CLText*, const CLTextTextureSpec*> mTextMap;
130 
131  // some constants that influence rendering
132 
133  // specifies how many segments are used to approximate the rounded
134  // corners of a rectangle
135  static const unsigned int NUM_CORNER_SEGMENTS;
136 
137  // specifies how many segments are used to draw circles and ellipses
138  static const unsigned int NUM_CIRCLE_SEGMENTS;
139 
140  // specifies how many points to calculate for a cubic bezier curve
141  static const unsigned int NUM_BEZIER_POINTS;
142 
143  // a constant that is considered to be zero
144  static const double ALMOST_ZERO;
145 
146  // a constant that limits the size of gradient textures
147  static const unsigned int GRADIENT_TEXTURE_SIZE_LIMIT;
148 
149  // the disatance between the selection frame and the object
150  // this should be independent of the current zoom factor.
151  static const double SELECTION_FRAME_WIDTH;
152 
153  // a set of available texture names.
154  std::set<GLuint> mTextureNames;
155 
156  // flag that determines whether the render extension tries to guess
157  // species reference roles from associated model objects
159 
160  // this is a set of species reference glyphs where we have deduced and set a role.
161  // We need to remember this so that we can delete this information again if the flag is unset
162  std::map<const CLMetabReferenceGlyph*, std::string> mSpeciesReferencesWithDeducedRole;
163 
164  // this is a set of selected objects
165  std::set<CLGraphicalObject*> mSelection;
166 
167  // bounding box for the current selection frame
169 
170  // maps that stores the associations for text glyphs
171  std::map<CLTextGlyph*, CLGraphicalObject*> mTextGlyphToGraphicalObjectMap;
172  std::map<CLGraphicalObject*, std::set<CLTextGlyph*> > mGraphicalObjectToTextGlyphMap;
173 
174  // maps that store the associations for species reference glyphs
175  std::map<CLMetabReferenceGlyph*, std::pair<CLMetabGlyph*, bool> > mSpeciesReferenceToSpeciesMap;
176  std::map<CLMetabGlyph*, std::set<std::pair<CLMetabReferenceGlyph*, bool> > > mSpeciesToSpeciesReferenceMap;
177  std::map<CLMetabReferenceGlyph*, std::pair<CLReactionGlyph*, bool> > mSpeciesReferenceToReactionMap;
178  std::map<CLReactionGlyph*, std::set<std::pair<CLMetabReferenceGlyph*, bool> > > mReactionToSpeciesReferenceMap;
179 
180  // a class that can create a texture from a jpeg or png image file
182 
183  std::set<const CLGraphicalObject*> mHighlightedObjects;
184 
185  // flag that determines whether non-highlighted objects
186  // are placed in a fog or if highlighted objects are highlighted
187  // with a special color.
189 
190  // color value for highlighting
191  GLfloat mHighlightColor[4];
192 
193  // color value for the fog
194  GLfloat mFogColor[4];
195 
196  GLfloat mFogDensity;
197 
198  // stores whether the OpenGL functions we need
199  // to allocate dynamically have been initialized
201 
202  // have a function pointer to the glFogCoordf function
203  // in the renderer
204  // Maybe all this dynamic function initialization should
205  // be moved to some global place
207 
208 public:
209  /**
210  * constructor for global render information
211  */
212  CLLayoutRenderer(CLayout* pLayout, const CLGlobalRenderInformation* pRenderInformation, const CCopasiVector<CLGlobalRenderInformation>* pGlobalRenderInformationList, const CModel* pModel, const std::string& baseDir);
213 
214  /**
215  * constructor for local render information
216  */
217  CLLayoutRenderer(CLayout* pLayout, const CLLocalRenderInformation* pRenderInformation, const CCopasiVector<CLGlobalRenderInformation>* pGlobalRenderInformationList, const CModel* pModel, const std::string& baseDir);
218 
219  /**
220  * destructor.
221  */
223 
224  /**
225  * Analyses the render information and creates some of the textures.
226  * First it determines which object are drawn based on the viewport
227  * coordinates that are passed in.
228  * Next it resolves the styles for all the objects that are to be drawn
229  * and it determines the size of the textures.
230  * Last it creates all textures.
231  */
232  void analyse_render_information(double lx, double ly, double rx, double ry);
233 
234  /**
235  * Method to draw a given layout with a given render resolver.
236  */
237  void draw_layout();
238 
239  /**
240  * Resize method that is called whenever the GL window is resized.
241  */
242  void resize(GLsizei w, GLsizei h);
243 
244  /**
245  * This method sets the left edge of the viewport.
246  */
247  void setX(double x);
248 
249  /**
250  * This method sets the upper edge of the viewport.
251  */
252  void setY(double y);
253 
254  /**
255  * Sets the zoom factor.
256  */
257  void setZoomFactor(double zoomFactor);
258 
259  /**
260  * Returns the current zoom factor.
261  */
262  double getZoomFactor() const;
263 
264  /**
265  * Sets a function that is able to generate a texture spec from
266  * some given font settings and a piece of text.
267  */
268  void set_font_renderer(CLFontRendererBase* pFontRenderer);
269 
270  /**
271  * This method replaces the current style with the given global render information.
272  */
273  void change_style(const CLGlobalRenderInformation* pRenderInformation, bool defaultStyle = false);
274 
275  /**
276  * This method replaces the current style with the given glocal render information.
277  */
278  void change_style(const CLLocalRenderInformation* pRenderInformation);
279 
280  /**
281  * Sets whether the render extension is to deduce specie reference roles from associated
282  * model objects if there are any.
283  */
284  void setDeduceSpeciesReferenceRoles(bool deduce);
285 
286  /**
287  * Returns true or false depending on whether the render extension
288  * deduces specie reference roles from associated
289  * model objects if there are any.
290  */
292 
293  /**
294  * This method adds a graphical object to the set of selected objects.
295  */
296  void addToSelection(CLGraphicalObject* pObject);
297 
298  /**
299  * This method removes the given object from the selection if
300  * it is selected.
301  */
302  void removeFromSelection(CLGraphicalObject* pObject);
303 
304  /**
305  * This method returns a reference to the set of selected objects.
306  */
307  std::set<CLGraphicalObject*>& getSelection();
308 
309  /**
310  * This method returns a const reference to the set of selected objects.
311  */
312  const std::set<CLGraphicalObject*>& getSelection() const;
313 
314  /**
315  * This method returns true if the given object is part of the selection and false otherwise.
316  */
317  bool isSelected(const CLGraphicalObject*) const;
318 
319  /**
320  * This method clears the selection.
321  */
322  void clearSelection();
323 
324  /**
325  * This method returns all objects at the given 2D model coordinates.
326  * The depth value is ignored.
327  */
328  std::multiset<CLGraphicalObject*, compareGraphicalObjectsBySize> getObjectsAt(double x, double y);
329 
330  /**
331  * This method returns all objects at the given 2D screen coordinates.
332  * The depth value is ignored.
333  */
334  std::multiset<CLGraphicalObject*, compareGraphicalObjectsBySize> getObjectsAtViewportPosition(unsigned int x, unsigned int y);
335 
336  /**
337  * Calculates the bounding box of the curve by looking at all the basepoints.
338  * The returned boundingbox object has to be deleted by the caller.
339  */
340  static CLBoundingBox* getCurveBoundingBox(const CLCurve* pCurve);
341 
342  /**
343  * Returns all objects that are within a given bounding box.
344  * The bounding box is determined by lx and ly which are the lower x and lower y values of the box and
345  * rx, ry which are the higher x and y values of the box.
346  * If partial is true, objects that are only parially included in the
347  * box are returned.
348  * If it is set to false, an object has to be completely within the
349  * bounding box to be returned.
350  */
351  std::vector<CLGraphicalObject*> getObjectsInBoundingBox(double lx, double ly, double rx, double ry, bool partial = true);
352 
353  /**
354  * Sets the current selection box.
355  * Setting the Box to NULL means that no selection box is drawn.
356  */
357  void setSelectionBox(const CLBoundingBox* pBox);
358 
359  /**
360  * returns a point to the current selection box.
361  */
363 
364  /**
365  * returns a const point to the current selection box.
366  */
367  const CLBoundingBox* getSelectionBox() const;
368 
369  /**
370  * Moves a given graphical object by a given vector.
371  */
372  void move_graphical_object(CLGraphicalObject* pObject, double dx, double dy);
373 
374  /**
375  * converts the given coordinates from viewport space into model space.
376  */
377  std::pair<double, double> convert_to_model_space(double x, double y) const;
378 
379  /**
380  * Moves a given curve object by a given vector.
381  * Optionally the method can leave the start and/or the
382  * endpoint of the curve where it is.
383  */
384  void move_curve_object(CLCurve* pCurve, double dx, double dy, bool leaveStartPoint = false, bool leaveEndpoint = false);
385 
386  /**
387  * Moves the species reference glyph.
388  * If the glpyh is represented by a curve,
389  * the curves start and endpoint are left as they are.
390  */
391  void move_species_reference_glyph(CLMetabReferenceGlyph* pSRG, double dx, double dy);
392 
393  /**
394  * Moves the given text glyph by the given vector.
395  * For now, we do not move any associated object becuase it is difficult to
396  * create a behaviour that makes sense. E.g. if the associated object is a species
397  * glyph, all species reference glyphs might have to be moved.
398  * So for now, it is easier to only move the text and if the user wants to move the text
399  * with the associated object, he/she needs to move the object instead.
400  */
401  void move_text_glyph(CLTextGlyph* pTG, double dx, double dy);
402 
403  /**
404  * Moves the given reaction glyph by the given vector.
405  * The startpoints of all associated species reference glyphs are moved as well
406  * if they are represented by curves otherwise the comple species reference glyph
407  * is moved.
408  * Also all associated text glyphs are moved.
409  * The moveSelectedAssociations determines whether associated objects that
410  * are selected are moved with this object or not.
411  * The reason for this is that selected object might be part of the moving
412  * process and the objects would in this case be changed twice.
413  */
414  void move_reaction_glyph(CLReactionGlyph* pRG, double dx, double dy, bool moveSelectedAssociation = false);
415 
416  /**
417  * Moves the given Species glyph by the given vector.
418  * The endpoints of all associated species reference glyphs are moved as well
419  * if they are represented by curves.
420  * Also all associated text glyphs are moved.
421  * The moveSelectedAssociations determines whether associated objects that
422  * are selected are moved with this object or not.
423  * The reason for this is that selected object might be part of the moving
424  * process and the objects would in this case be changed twice.
425  */
426  void move_species_glyph(CLMetabGlyph* pSG, double dx, double dy, bool moveSelectedAssociations = false);
427 
428  /**
429  * Moves the current selection.
430  * If the moveAssociations falg is set to true,
431  * associated objects that are not selected are
432  * moved as well.
433  * In the case of associated species reference glyphs
434  * this means that the start and/or endpoint is moved.
435  */
436  void move_selection(double dx, double dy, bool moveAssociated = true);
437 
438  /**
439  * calculates the distance between two layout points.
440  */
441  static double distance(const CLPoint& p1, const CLPoint& p2);
442 
443  /**
444  * Checks if the given curve would be visible in the box determined by lx,ly,rx,ry.
445  * If the curve in any way intersects the box, true is returned.
446  */
447  static bool is_curve_visible(const CLCurve& curve, double lx, double ly, double rx, double ry, bool partial);
448 
449  /**
450  * Checks if the given curve segment would be visible in the box determined by lx,ly,rx,ry.
451  * If the curve in any way intersects the box, true is returned.
452  */
453  static bool is_curve_segment_visible(const CLLineSegment& segment, double lx, double ly, double rx, double ry, bool partial);
454 
455  /**
456  * reverts the direction of the given curve.
457  * The result is returned as a new curve object and
458  * the caller has to make sure that the memory for the
459  * new curve is freed.
460  */
461  static CLCurve* revert_curve(const CLCurve* pCurve);
462 
463  /**
464  * Returns the current aspect.
465  */
466  double getAspect() const;
467 
468  /**
469  * Sets the aspect.
470  */
471  void setAspect(double aspect);
472 
473  /**
474  * Sets the class that can create textures from a given image file.
475  */
476  void setImageTexturizer(CLImageTexturizer* pTexturizer);
477 
478  // the following methods are used to highlight elements in the diagram
479  // based on their association to model elements
480 
481  /**
482  * Sets the list of model objects that are to be highlighted in the diagram.
483  */
484  void setHighlightedObjects(const std::set<const CLGraphicalObject*>& highlightedObjects);
485 
486  /**
487  * Returns a const reference to the set of highlighted model objects.
488  */
489  const std::set<const CLGraphicalObject*>& getHighlightedObjects() const;
490 
491  /**
492  * Returns a reference to the set of highlighted model objects.
493  */
494  std::set<const CLGraphicalObject*>& getHighlightedObjects();
495 
496  /**
497  * Sets the highlight color.
498  */
499  void setHighlightColor(const GLfloat c[4]);
500 
501  /**
502  * Returns a const pointer to the highlight color.
503  * The array has a size of 4 elements.
504  */
505  const GLfloat* getHighlightColor() const;
506 
507  /**
508  * Sets the fog color.
509  */
510  void setFogColor(const GLfloat c[4]);
511 
512  /**
513  * Returns a const pointer to the fog color.
514  * The array has a size of 4 elements.
515  */
516  const GLfloat* getFogColor() const;
517 
518  /**
519  * Sets the fog density.
520  */
521  void setFogDensity(GLfloat dens);
522 
523  /**
524  * Returns the current fog density.
525  */
526  GLfloat getFogDensity() const;
527 
528  /**
529  * Toggles the flag that determines if highlighted objects
530  * are actually highlighted or if the rest is fogged out.
531  */
532  void toggleHighlightFlag();
533 
534  /**
535  * Toggles the flag that determines if highlighted objects
536  * are actually highlighted or if the rest is fogged out.
537  */
538  void setHighlightFlag(bool flag);
539 
540  /**
541  * Returns the highlight flag.
542  */
543  bool getHighlightFlag() const;
544 
545 protected:
546  /**
547  * Extracts the group attributes from the outermost group of a style.
548  */
549  static void extract_group_attributes(const CLStyle* pStyle, CLGroupAttributes* attributes);
550 
551  /**
552  * Extracts the group attributes from the given group.
553  */
554  static void extract_group_attributes(const CLGroup* pGroup, CLGroupAttributes* attributes);
555 
556  /**
557  * Method that draws a line with the given start and end points.
558  * All the other parameter like color, linewidth etc. have to be set
559  * before.
560  */
561  void draw_line_segment(double x1, double y1, double z1, double x2, double y2, double z2, double line_width, bool texture = false, double s1 = 0.0, double s2 = 0.0);
562 
563  /**
564  * Method that draws a curve from the layout extension.
565  * All the other parameter like color, linewidth etc. have to be set
566  * before.
567  */
568  void draw_curve(const CLCurve* pCurve, bool drawBasepoints = false);
569 
570  /**
571  * Method that draws a curve from the render extension.
572  * All the other parameter like color, linewidth etc. have to be set
573  * before.
574  */
575  void draw_curve(const CLRenderCurve* pCurve, const CLBoundingBox* pBB);
576 
577  /**
578  * Converts a given RenderPoint which can have relative values into a
579  * layout Point with only absolute values.
580  */
581  static const CLPoint convert_to_absolute(const CLRenderPoint* pRenderPoint, const CLBoundingBox* pBB);
582 
583  /**
584  * Method to draw an arbitrary object specified by it's bounding box
585  * and the style with which it should be drawn.
586  */
587  void draw_object(const CLStyle* pStyle, const CLBoundingBox* pBB);
588 
589  /**
590  * Method to draw a text object specified by it's bounding box
591  * and the style with which it should be drawn as well as the actual
592  * string.
593  */
594  void draw_text(const CLStyle* pStyle, const CLBoundingBox* pBB, const CLTextTextureSpec* pTexture);
595 
596  /**
597  * Method to resolve the text that belongs to a text glyph.
598  */
599  static const std::string resolve_text(const CLTextGlyph* pTextGlyph);
600 
601  /**
602  * Method that converts a color value or a color id into a color array for
603  * OpenGL.
604  */
605  void resolve_color(const std::string& color, GLubyte array[4]);
606 
607  /**
608  * Method to draw a render text object.
609  */
610  void draw_text(const CLText* pText, const CLBoundingBox* pBB);
611 
612  /**
613  * Method to draw a render ellipse object.
614  */
615  void draw_ellipse(const CLEllipse* pEllipse, const CLBoundingBox* pBB);
616 
617  /**
618  * Method to draw a render image object.
619  */
620  void draw_image(const CLImage* pImage, const CLBoundingBox* pBB);
621 
622  /**
623  * Method to draw a render polygon object.
624  */
625  void draw_polygon(const CLPolygon* pPolygon, const CLBoundingBox* pBB);
626 
627  /**
628  * Method to draw a render rectangle object.
629  */
630  void draw_rectangle(const CLRectangle* pRectangle, const CLBoundingBox* pBB);
631 
632  /**
633  * Extracts the attributes from the given one dimensional object.
634  */
635  static void extract_1d_attributes(const CLGraphicalPrimitive1D* pObject, CLGroupAttributes* attributes);
636 
637  /**
638  * Extracts the attributes from the given two dimensional object.
639  */
640  static void extract_2d_attributes(const CLGraphicalPrimitive2D* pObject, CLGroupAttributes* attributes);
641 
642  /**
643  * Extracts the attributes from the given object with text attribute
644  * information.
645  * This template function can be used for group and text elements.
646  */
647  template <typename T>
648  static void extract_text_attributes(const T* pObject, CLGroupAttributes* attributes)
649  {
650  assert(pObject != NULL);
651 
652  if (pObject == NULL) return;
653 
654  if (pObject->isSetFontFamily())
655  {
656  attributes->mFontFamily = pObject->getFontFamily();
657  }
658 
659  if (pObject->isSetFontSize())
660  {
661  attributes->mFontSize = pObject->getFontSize();
662  }
663 
664  if (pObject->isSetFontWeight())
665  {
666  attributes->mFontWeight = pObject->getFontWeight();
667  }
668 
669  if (pObject->isSetFontStyle())
670  {
671  attributes->mFontStyle = pObject->getFontStyle();
672  }
673 
674  if (pObject->isSetTextAnchor())
675  {
676  attributes->mTextAnchor = pObject->getTextAnchor();
677  }
678 
679  if (pObject->isSetVTextAnchor())
680  {
681  attributes->mVTextAnchor = pObject->getVTextAnchor();
682  }
683  }
684 
685  /**
686  * Extracts the attributes from the given transformation object.
687  */
688  static void extract_transformation_attributes(const CLTransformation* pObject, CLGroupAttributes* attributes);
689 
690  /**
691  * Extracts the attributes from the given object with arrow head
692  * information.
693  * This template function can be used for group and curve elements.
694  */
695  template <typename T>
696  static void extract_arrowhead_information(const T* pObject, CLGroupAttributes* attributes)
697  {
698  if (pObject->isSetStartHead())
699  {
700  attributes->mStartHead = pObject->getStartHead();
701  }
702 
703  if (pObject->isSetEndHead())
704  {
705  attributes->mEndHead = pObject->getEndHead();
706  }
707  }
708 
709  /**
710  * Method to draw an arbitrary object specified by it's bounding box
711  * and the style with which it should be drawn.
712  */
713  void draw_group(const CLGroup* pGroup, const CLBoundingBox* pBB);
714 
715  /**
716  * Method to draw a string at the given position within the given bounding box.
717  */
718  void draw_text(const CLTextTextureSpec* pTexture, double x, double y, double z, const CLBoundingBox* pBB);
719 
720  /**
721  * This method calculates a texture for a given gradient definition and a
722  * given size.
723  * The data object has to be a vector that can store RGBA values for a rectangle
724  * of the given size. The memory has to be allocated before calling the method.
725  * The scale specifies by how much the original box has been scaled.
726  */
727  void create_gradient_texture(unsigned int size, GLubyte* pData, const CLGradientBase* pGradient, double z_value = 0.0);
728 
729  /**
730  * This method calculates a texture for a given linear gradient definition
731  * and a given size.
732  * The data object has to be a vector that can store RGBA values for a rectangle
733  * of the given size. The memory has to be allocated before calling the method.
734  * The scale specifies by how much the original box has been scaled.
735  */
736  void create_linear_gradient_texture(unsigned int size, GLubyte* pData, const CLLinearGradient* pGradient, double z_value);
737 
738  /**
739  * This method calculates a texture for a given radial gradient
740  * definition and a given size.
741  * The data object has to be a vector that can store RGBA values for a rectangle
742  * of the given size. The memory has to be allocated before calling the method.
743  * The scale specifies by how much the original box has been scaled.
744  */
745  void create_radial_gradient_texture(unsigned int size, GLubyte* pData, const CLRadialGradient* pGradient, double z_value);
746 
747  /**
748  * Maps the relative distance to a color and set the color as an rgb value in
749  * pData. pData has to be the pointer where 4 GLfloat values are going to be
750  * stored.
751  */
752  void map_gradient_color(double rel_distance, const CLGradientBase* pGradient, GLubyte* pData);
753 
754  /**
755  * Draw a set of datapoints with the current attributes using the given bounding box.
756  */
757  void draw_datapoints(GLdouble* pData, size_t numPoints, const CLBoundingBox* pBB, bool doTesselation = false, float xOffset = 0.0, float yOffset = 0.0, float zOffset = 0.0);
758 
759  /**
760  * Maps the given arrow head to the given line segment.
761  */
762  void map_arrow_head(const CLPoint& p, const CLPoint& v, const std::string& headId);
763 
764  /**
765  * This method is used as a callback for the GLU tesselator to report
766  * errors during the tesselation process.
767  */
768  static void TESS_ERROR(GLenum error);
769 
770  /**
771  * This static method is used as a callback for the GLU tesselator.
772  * It is needed for polygons that intersect which itself and the
773  * tesselator has to create a new vertex at the intersection.
774  */
775 #ifdef _WIN32
776  static void __stdcall COMBINE_CALLBACK(GLdouble coords[3], GLdouble** /*vertex_data[4]*/, GLfloat* /*weight[4]*/, GLdouble** dataOut);
777 #else
778  static void COMBINE_CALLBACK(GLdouble coords[3], GLdouble** /*vertex_data[4]*/, GLfloat* /*weight[4]*/, GLdouble** dataOut);
779 #endif // _WIN32
780  /**
781  * This method is used as a callback for the GLU tesselator.
782  * It is called for every vertex that is processed by the tesselator.
783  * We need it to calculate the gradient colors at each vertex.
784  */
785 #ifdef _WIN32
786  static void _stdcall VERTEX_CALLBACK_GRADIENT(GLvoid* vertex);
787 #else
788  static void VERTEX_CALLBACK_GRADIENT(GLvoid* vertex);
789 #endif // _WIN32
790 
791  /**
792  * This static method is used as a callback for the GLU tesselator.
793  * It is needed for polygons that intersect which itself and the
794  * tesselator has to create a new vertex at the intersection.
795  */
796 #ifdef _WIN32
797  static void __stdcall COMBINE_CALLBACK_GRADIENT(GLdouble coords[3], GLdouble* vertex_data[4], GLfloat weight[4], GLdouble** dataOut);
798 #else
799  static void COMBINE_CALLBACK_GRADIENT(GLdouble coords[3], GLdouble* vertex_data[4], GLfloat weight[4], GLdouble** dataOut);
800 #endif //_WIN32
801 
802  /**
803  * Calculates the points for a cubic bezier curve.
804  * The algorithm calculates numPoints and stores them in pData. pData
805  * has to be an array with enough space for numPoints*3 GLfloat items.
806  */
807  static void calculate_cubicbezier(double sx, double sy, double sz, double p1x, double p1y, double p1z, double p2x, double p2y, double p2z, double ex, double ey, double ez, unsigned int numPoints, GLdouble* pData);
808 
809  /**
810  * Method to draw a line made up of a set of points.
811  */
812  void draw_line(size_t numPoints, GLdouble* pData);
813 
814  static void createGLMatrix(const double* const matrix, GLdouble* glMatrix);
815 
816  /**
817  * Creates a 1D texture for the line stippling.
818  * The caller is responsible for deleting the returned object.
819  * If the dasharray does not contain a valid stipple pattern NULL is
820  * returned.
821  */
822  static CLLineStippleTexture* createLineStippleTexture(const std::vector<unsigned int>& dasharray);
823 
824  /**
825  * This method takes a number of datapoints for a curve and segments
826  * the curve into pieces that have a datapoint at every multiple of length.
827  * This is needed if we need to apply line stippling for OpenGL < 2.0
828  * where texture sizes have to be a power of 2.
829  */
830  void segment_data(double length, double ratio, size_t numPoints, GLdouble* pData, std::vector<simple_point>& v);
831 
832  /**
833  * This method goes through all layout objects and checks them if they
834  * are within the current viewport. If they are, they are added to the list of objects that are drawn.
835  * An object is within the viewport if it's bounding box or parts of it
836  * are within the viewport.
837  * For curves, each start, end and base point is checked and if any
838  * of those is within the viewport, the curve is added to the list.
839  * The viewport is specified by its lower left (lx,ly) and upper right
840  * point (rx,ry).
841  */
842  void update_drawables(double lx, double ly, double rx, double ry);
843 
844  /**
845  * This method goes through all styles that are used by the current drawables
846  * and figures out which gradients, colors and line stipples are used and
847  * creates them.
848  */
850 
851  /**
852  * Goes through all render objects in the given group and updates the color
853  * map and gradients.
854  * The maxDimension parameter is the maximum of the width and the height of the
855  * corresponding layout object. This value is needed to determine the size of gradient textures.
856  */
857  void update_textures_and_colors(const CLGroup* pGroup, double maxDimension, double height, const std::string& parentFill = "", CLFontSpec parentFontSpec = CLFontSpec());
858 
859  /**
860  * This method creates a FontSpec object from the font attributes in the given
861  * group.
862  * The height that is passed to the method is the height for the bounding box
863  * and it used to calculate the font size if it has a relative component.
864  */
865  static CLFontSpec getFontSpec(const CLGroup* pGroup, double boxHeight, const CLFontSpec& parentFontSpec = CLFontSpec());
866 
867  /**
868  * This method creates a FontSpec object from the font attributes in the given
869  * text element.
870  * The height that is passed to the method is the height for the bounding box
871  * and it used to calculate the font size if it has a relative component.
872  */
873  static CLFontSpec getFontSpec(const CLText* pText, double boxHeight, const CLFontSpec& parentFontSpec = CLFontSpec());
874 
875  /**
876  * This method goes throught the list of all drawables and tries to resolve the
877  * style for each object.
878  */
880 
881  /**
882  * This methods extracts all colors from the given gradient and adds them to the
883  * color map.
884  */
885  void update_colors(const CLGradientBase* pGradient);
886 
887  /**
888  * Stores the current attributes on a stack.
889  */
891 
892  /**
893  * Restores the current attributes from the stack.
894  * Any transformation object that might have been created after the
895  * last call to save_current_attributes will be deleted.
896  */
898 
899  /**
900  * Routine to draw the caps between two line segments.
901  * The method takes the three points that make the two line segments
902  * and the width of the line.
903  */
904  void draw_cap(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double stroke_width);
905 
906  /**
907  * Removes all entries from all cache maps and frees the memory for the textures.
908  */
909  void clear_cached_data();
910 
911  /**
912  * calculates the intersection point of two lines.
913  * The caller has to delete the returned point object.
914  */
915  static CLPoint* calculate_intersection(double p1x, double p1y, double p1z, double sx, double sy, double sz,
916  double p2x, double p2y, double p2z, double tx, double ty, double tz);
917 
918  /**
919  * Calculates the intersection point between two lines in 2D.
920  * The intersection point is returned.
921  * If the lines are parallel, a point with two NaN values is returned.
922  * All numbers <= ALMOST_ZERO are considered to be 0.
923  */
924  static std::pair<double, double> calculate_intersection_point_2d(double p1x, double p1y, double sx, double sy, double p2x, double p2y, double tx, double ty);
925 
926  /**
927  * Calculates wether 2d segments intersect within the length of the segments.
928  * Calls calculate_intersection_point_2d.
929  */
930  static bool segments_intersect_2d(double p1x1, double p1y1, double p1x2, double p1y2, double p2x1, double p2y1, double p2x2, double p2y2);
931 
932  /**
933  * Calculates if the point given as x,y is close enough to the given line segment
934  * to count as a hit.
935  */
936  static bool isSegmentHit(const CLLineSegment* pLS, double x, double y, double toleranceRadius);
937 
938  /**
939  * Calculates the distance between a point and a line segment.
940  * It tries to calculate the intersection point of the line
941  * and another line perpendicular to the first line through the given point.
942  * If this intersection point is on the line segment, the result is the same
943  * as the distance between the two lines, otherwise the distance is the distance of the given
944  * point to the closest endpoint of the segment.
945  */
946  static double distancePointLineSegment(double x, double y, double lx1, double ly1, double lx2, double ly2);
947 
948  /**
949  * Draw the selection frame around an graphical objects bounding object box.
950  * If drawHandles is true, resize handles are drawn as well,
951  * else only the box is drawn.
952  * If the curve is given, the basepoints of the curve are also drawn
953  * as small circles.
954  */
955  static void drawSelectionBox(double x, double y, double width, double height, bool drawHandles = false);
956 
957  /**
958  * Updates the associations of species reference glyphs
959  * and text glyphs.
960  */
961  void update_associations();
962 
963  /**
964  * draws the selection box if there is one
965  */
966  void draw_selection_box() const;
967 
968  /**
969  * The glFogCoordf function is part of OpenGL 1.4 and may not be available on
970  * all implementations, so we need to query for this dynamically.
971  */
973 
974 #ifdef __APPLE__
975  void * MyNSGLGetProcAddress(const char *name);
976 #endif // __APPLE__
977 };
978 
979 #endif // CLLAYOUTRENDERER_H__
static void createGLMatrix(const double *const matrix, GLdouble *glMatrix)
void move_selection(double dx, double dy, bool moveAssociated=true)
static void calculate_cubicbezier(double sx, double sy, double sz, double p1x, double p1y, double p1z, double p2x, double p2y, double p2z, double ex, double ey, double ez, unsigned int numPoints, GLdouble *pData)
void draw_line_segment(double x1, double y1, double z1, double x2, double y2, double z2, double line_width, bool texture=false, double s1=0.0, double s2=0.0)
CLBoundingBox * mpSelectionBox
void draw_object(const CLStyle *pStyle, const CLBoundingBox *pBB)
GLfloat mHighlightColor[4]
Definition: CLText.h:27
void move_text_glyph(CLTextGlyph *pTG, double dx, double dy)
std::map< const CLText *, const CLTextTextureSpec * > mTextMap
static bool is_curve_segment_visible(const CLLineSegment &segment, double lx, double ly, double rx, double ry, bool partial)
const GLfloat * getFogColor() const
std::vector< const CLGraphicalObject * > mDrawables
std::set< GLuint > mTextureNames
static const double ALMOST_ZERO
std::set< CLGraphicalObject * > mSelection
std::multiset< CLGraphicalObject *, compareGraphicalObjectsBySize > getObjectsAtViewportPosition(unsigned int x, unsigned int y)
static const unsigned int NUM_CIRCLE_SEGMENTS
static const unsigned int GRADIENT_TEXTURE_SIZE_LIMIT
std::stack< CLGroupAttributes > mStateList
void update_colors(const CLGradientBase *pGradient)
CLText::TEXT_ANCHOR mTextAnchor
void draw_ellipse(const CLEllipse *pEllipse, const CLBoundingBox *pBB)
void resolve_color(const std::string &color, GLubyte array[4])
static CLLineStippleTexture * createLineStippleTexture(const std::vector< unsigned int > &dasharray)
void move_species_glyph(CLMetabGlyph *pSG, double dx, double dy, bool moveSelectedAssociations=false)
static double distance(const CLPoint &p1, const CLPoint &p2)
void setHighlightFlag(bool flag)
std::string mEndHead
CLImageTexturizer * mpImageTexturizer
void update_drawables(double lx, double ly, double rx, double ry)
std::map< CLMetabReferenceGlyph *, std::pair< CLMetabGlyph *, bool > > mSpeciesReferenceToSpeciesMap
static void extract_group_attributes(const CLStyle *pStyle, CLGroupAttributes *attributes)
std::map< CLMetabGlyph *, std::set< std::pair< CLMetabReferenceGlyph *, bool > > > mSpeciesToSpeciesReferenceMap
void draw_datapoints(GLdouble *pData, size_t numPoints, const CLBoundingBox *pBB, bool doTesselation=false, float xOffset=0.0, float yOffset=0.0, float zOffset=0.0)
void map_arrow_head(const CLPoint &p, const CLPoint &v, const std::string &headId)
std::map< CLTextGlyph *, CLGraphicalObject * > mTextGlyphToGraphicalObjectMap
#define STD_CALL
static bool segments_intersect_2d(double p1x1, double p1y1, double p1x2, double p1y2, double p2x1, double p2y1, double p2x2, double p2y2)
static const CLPoint convert_to_absolute(const CLRenderPoint *pRenderPoint, const CLBoundingBox *pBB)
void setAspect(double aspect)
CLLayoutRenderer(CLayout *pLayout, const CLGlobalRenderInformation *pRenderInformation, const CCopasiVector< CLGlobalRenderInformation > *pGlobalRenderInformationList, const CModel *pModel, const std::string &baseDir)
const std::set< const CLGraphicalObject * > & getHighlightedObjects() const
CLText::FONT_STYLE mFontStyle
static void extract_2d_attributes(const CLGraphicalPrimitive2D *pObject, CLGroupAttributes *attributes)
void create_radial_gradient_texture(unsigned int size, GLubyte *pData, const CLRadialGradient *pGradient, double z_value)
void create_linear_gradient_texture(unsigned int size, GLubyte *pData, const CLLinearGradient *pGradient, double z_value)
static void extract_arrowhead_information(const T *pObject, CLGroupAttributes *attributes)
std::map< const CLTextGlyph *, const CLTextTextureSpec * > mTextGlyphMap
void draw_polygon(const CLPolygon *pPolygon, const CLBoundingBox *pBB)
std::string mFontFamily
std::map< std::string, std::pair< const CLGradientBase *, CLTextureSpec * > > mGradientMap
void draw_text(const CLStyle *pStyle, const CLBoundingBox *pBB, const CLTextTextureSpec *pTexture)
void resize(GLsizei w, GLsizei h)
void setSelectionBox(const CLBoundingBox *pBox)
CLGroupAttributes mCurrentAttributes
static CLPoint * calculate_intersection(double p1x, double p1y, double p1z, double sx, double sy, double sz, double p2x, double p2y, double p2z, double tx, double ty, double tz)
static void drawSelectionBox(double x, double y, double width, double height, bool drawHandles=false)
std::set< const CLGraphicalObject * > mHighlightedObjects
static const unsigned int NUM_CORNER_SEGMENTS
static const std::string resolve_text(const CLTextGlyph *pTextGlyph)
std::map< CLGraphicalObject *, std::set< CLTextGlyph * > > mGraphicalObjectToTextGlyphMap
std::multiset< CLGraphicalObject *, compareGraphicalObjectsBySize > getObjectsAt(double x, double y)
double getZoomFactor() const
const CCopasiVector< CLGlobalRenderInformation > * mpGlobalRenderInfoList
static std::pair< double, double > calculate_intersection_point_2d(double p1x, double p1y, double sx, double sy, double p2x, double p2y, double tx, double ty)
static void extract_transformation_attributes(const CLTransformation *pObject, CLGroupAttributes *attributes)
void setZoomFactor(double zoomFactor)
std::map< CLReactionGlyph *, std::set< std::pair< CLMetabReferenceGlyph *, bool > > > mReactionToSpeciesReferenceMap
std::map< CLMetabReferenceGlyph *, std::pair< CLReactionGlyph *, bool > > mSpeciesReferenceToReactionMap
const GLfloat * getHighlightColor() const
CLRelAbsVector mFontSize
void setHighlightColor(const GLfloat c[4])
static void TESS_ERROR(GLenum error)
void addToSelection(CLGraphicalObject *pObject)
void setImageTexturizer(CLImageTexturizer *pTexturizer)
void move_reaction_glyph(CLReactionGlyph *pRG, double dx, double dy, bool moveSelectedAssociation=false)
Definition: CLBase.h:54
static const double SELECTION_FRAME_WIDTH
void draw_cap(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double stroke_width)
std::map< std::string, const CLTextureSpec * > mImageMap
std::map< const std::vector< unsigned int >, const CLLineStippleTexture * > mLinestippleMap
std::map< std::string, CLRGBAColor > mColorMap
std::string mBaseDir
static void COMBINE_CALLBACK(GLdouble coords[3], GLdouble **, GLfloat *, GLdouble **dataOut)
void draw_group(const CLGroup *pGroup, const CLBoundingBox *pBB)
double getAspect() const
bool getHighlightFlag() const
static const unsigned int NUM_BEZIER_POINTS
static void extract_1d_attributes(const CLGraphicalPrimitive1D *pObject, CLGroupAttributes *attributes)
static CLCurve * revert_curve(const CLCurve *pCurve)
void setFogColor(const GLfloat c[4])
static CLBoundingBox * getCurveBoundingBox(const CLCurve *pCurve)
std::map< const CLMetabReferenceGlyph *, std::string > mSpeciesReferencesWithDeducedRole
CLBoundingBox * getSelectionBox()
void removeFromSelection(CLGraphicalObject *pObject)
void move_species_reference_glyph(CLMetabReferenceGlyph *pSRG, double dx, double dy)
long int flag
Definition: f2c.h:52
std::pair< double, double > convert_to_model_space(double x, double y) const
void move_curve_object(CLCurve *pCurve, double dx, double dy, bool leaveStartPoint=false, bool leaveEndpoint=false)
void change_style(const CLGlobalRenderInformation *pRenderInformation, bool defaultStyle=false)
void setFogDensity(GLfloat dens)
static bool isSegmentHit(const CLLineSegment *pLS, double x, double y, double toleranceRadius)
CLFontRendererBase * mpFontRenderer
std::vector< CLGraphicalObject * > getObjectsInBoundingBox(double lx, double ly, double rx, double ry, bool partial=true)
static double distancePointLineSegment(double x, double y, double lx1, double ly1, double lx2, double ly2)
std::map< std::string, const CLLineEnding * > mLineEndingMap
bool isSelected(const CLGraphicalObject *) const
static void COMBINE_CALLBACK_GRADIENT(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut)
void draw_rectangle(const CLRectangle *pRectangle, const CLBoundingBox *pBB)
static void extract_text_attributes(const T *pObject, CLGroupAttributes *attributes)
std::map< CLFontSpec, std::map< std::string, CLTextTextureSpec * > > mFontTextureMap
void(* mpGlFogCoordfEXT)(GLfloat)
void initialize_gl_extension_functions()
GLfloat getFogDensity() const
CLText::TEXT_ANCHOR mVTextAnchor
std::set< CLGraphicalObject * > & getSelection()
void create_gradient_texture(unsigned int size, GLubyte *pData, const CLGradientBase *pGradient, double z_value=0.0)
CLText::FONT_WEIGHT mFontWeight
() void(yyvaluep))
void set_font_renderer(CLFontRendererBase *pFontRenderer)
CLRenderResolver * mpResolver
Definition: CModel.h:50
std::string mStartHead
bool isSetDeduceSpeciesReferenceRoles() const
const CModel * mpModel
void segment_data(double length, double ratio, size_t numPoints, GLdouble *pData, std::vector< simple_point > &v)
static bool is_curve_visible(const CLCurve &curve, double lx, double ly, double rx, double ry, bool partial)
void draw_selection_box() const
void setDeduceSpeciesReferenceRoles(bool deduce)
void analyse_render_information(double lx, double ly, double rx, double ry)
void move_graphical_object(CLGraphicalObject *pObject, double dx, double dy)
static CLFontSpec getFontSpec(const CLGroup *pGroup, double boxHeight, const CLFontSpec &parentFontSpec=CLFontSpec())
void draw_curve(const CLCurve *pCurve, bool drawBasepoints=false)
void draw_line(size_t numPoints, GLdouble *pData)
void map_gradient_color(double rel_distance, const CLGradientBase *pGradient, GLubyte *pData)
void setHighlightedObjects(const std::set< const CLGraphicalObject * > &highlightedObjects)
static void VERTEX_CALLBACK_GRADIENT(GLvoid *vertex)
std::map< const CLGraphicalObject *, const CLStyle * > mStyleMap
void draw_image(const CLImage *pImage, const CLBoundingBox *pBB)