Fraxinus  16.5.0-fx-rc4
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #include "cxDisplayTextRep.h"
35 
36 #include <vtkRenderer.h>
37 #include <vtkActor2D.h>
38 #include <vtkTextProperty.h>
39 #include <vtkTextMapper.h>
40 
41 #include "cxView.h"
42 #include "cxVtkHelperClasses.h"
43 #include "cxTypeConversions.h"
44 
45 namespace cx
46 {
47 
49  RepImpl("")
50 {
51 }
52 
54 {
55 
56 }
58 {
59  return wrap_new(new DisplayTextRep(), uid);
60 }
62 {
63  for(unsigned i =0; i<mDisplayText.size(); ++i)
64  mDisplayText[i]->setRenderer(view->getRenderer());
65 }
66 
68 {
69  for(unsigned i =0; i<mDisplayText.size(); ++i)
70  mDisplayText[i]->setRenderer(NULL);
71 }
72 
76 TextDisplayPtr DisplayTextRep::addText(const QColor& color, const QString& text, const Vector3D& pos, int maxWidth, vtkViewport *vp)
77 {
78 // Vector3D c = color;
79  TextDisplayPtr textRep;
80  textRep.reset( new TextDisplay( text, color, 20) );
81  textRep->getActor()->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
82  textRep->setPosition(pos);
83  textRep->textProperty()->SetJustificationToLeft();
84  if( pos[0]>0.5 )
85  {
86  textRep->textProperty()->SetJustificationToRight();
87  }
88  textRep->textProperty()->SetVerticalJustificationToBottom();
89  if (pos[1] > 0.5)
90  {
91  textRep->textProperty()->SetVerticalJustificationToTop();
92  }
93 
94  textRep->setRenderer(this->getRenderer());
95 
96  //textRep->setCentered();
97  mDisplayText.push_back( textRep );
98 
99  if (maxWidth != 0 && vp)
100  {
101  textRep->setMaxWidth(maxWidth, vp);
102  }
103  return textRep;
104 }
105 
109 void DisplayTextRep::setText(unsigned i, const QString& text)
110 {
111  if (i<mDisplayText.size())
112  mDisplayText[i]->updateText(text);
113 }
114 
118 void DisplayTextRep::setColor(const QColor& color )
119 {
120  for(unsigned i =0; i<mDisplayText.size(); ++i)
121  {
122  mDisplayText.at(i)->textProperty()->SetColor(getColorAsVector3D(color).begin()) ;
123  }
124 
125 }
126 
128 {
129  for(unsigned i =0; i<mDisplayText.size(); ++i)
130  {
131  mDisplayText.at(i)->textProperty()->SetFontSize(size) ;
132  }
133 }
134 
135 
136 
137 
138 //-----------------------------------------------------------------------
139 }//end namespace
140 //-----------------------------------------------------------------------
virtual void addRepActorsToViewRenderer(ViewPtr view)
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:109
Vector3D getColorAsVector3D(QColor color)
Scalar * begin()
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
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:63
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
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