Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxDisplayTextRep.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxDisplayTextRep.h"
14 
15 #include <vtkRenderer.h>
16 #include <vtkActor2D.h>
17 #include <vtkTextProperty.h>
18 #include <vtkTextMapper.h>
19 
20 #include "cxView.h"
21 #include "cxVtkHelperClasses.h"
22 #include "cxTypeConversions.h"
23 
24 namespace cx
25 {
26 
28  RepImpl("")
29 {
30 }
31 
33 {
34 
35 }
37 {
38  return wrap_new(new DisplayTextRep(), uid);
39 }
41 {
42  for(unsigned i =0; i<mDisplayText.size(); ++i)
43  mDisplayText[i]->setRenderer(view->getRenderer());
44 }
45 
47 {
48  for(unsigned i =0; i<mDisplayText.size(); ++i)
49  mDisplayText[i]->setRenderer(NULL);
50 }
51 
55 TextDisplayPtr DisplayTextRep::addText(const QColor& color, const QString& text, const Vector3D& pos, int maxWidth, vtkViewport *vp)
56 {
57 // Vector3D c = color;
58  TextDisplayPtr textRep;
59  textRep.reset( new TextDisplay( text, color, 20) );
60  textRep->getActor()->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
61  textRep->setPosition(pos);
62  textRep->textProperty()->SetJustificationToLeft();
63  if( pos[0]>0.5 )
64  {
65  textRep->textProperty()->SetJustificationToRight();
66  }
67  textRep->textProperty()->SetVerticalJustificationToBottom();
68  if (pos[1] > 0.5)
69  {
70  textRep->textProperty()->SetVerticalJustificationToTop();
71  }
72 
73  textRep->setRenderer(this->getRenderer());
74 
75  //textRep->setCentered();
76  mDisplayText.push_back( textRep );
77 
78  if (maxWidth != 0 && vp)
79  {
80  textRep->setMaxWidth(maxWidth, vp);
81  }
82  return textRep;
83 }
84 
88 void DisplayTextRep::setText(unsigned i, const QString& text)
89 {
90  if (i<mDisplayText.size())
91  mDisplayText[i]->updateText(text);
92 }
93 
97 void DisplayTextRep::setColor(const QColor& color )
98 {
99  for(unsigned i =0; i<mDisplayText.size(); ++i)
100  {
101  mDisplayText.at(i)->textProperty()->SetColor(getColorAsVector3D(color).begin()) ;
102  }
103 
104 }
105 
107 {
108  for(unsigned i =0; i<mDisplayText.size(); ++i)
109  {
110  mDisplayText.at(i)->textProperty()->SetFontSize(size) ;
111  if (size != mDisplayText[i]->textProperty()->GetFontSize())
112  mDisplayText.at(i)->textProperty()->SetFontSize(size) ;
113  }
114 }
115 
116 //-----------------------------------------------------------------------
117 }//end namespace
118 //-----------------------------------------------------------------------
virtual void addRepActorsToViewRenderer(ViewPtr view)
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
Vector3D getColorAsVector3D(QColor color)
Scalar * begin()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
boost::shared_ptr< class View > ViewPtr
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Helper for drawing text in 2D.
void setFontSize(int size)
boost::shared_ptr< class TextDisplay > TextDisplayPtr
void setColor(const QColor &color)
Default implementation of Rep.
Definition: cxRepImpl.h:42
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
static DisplayTextRepPtr New(const QString &uid="")
TextDisplayPtr addText(const QColor &color, const QString &text, const Vector3D &pos, int maxWidth=0, vtkViewport *vp=NULL)
boost::shared_ptr< class DisplayTextRep > DisplayTextRepPtr
void setText(unsigned i, const QString &text)
std::vector< TextDisplayPtr > mDisplayText
Namespace for all CustusX production code.