16 #include <vtkSphereSource.h> 17 #include <vtkLineSource.h> 18 #include <vtkPolyDataMapper2D.h> 19 #include <vtkProperty2D.h> 20 #include <vtkTextMapper.h> 21 #include <vtkTextProperty.h> 22 #include <vtkAxesActor.h> 23 #include <vtkCaptionActor2D.h> 24 #include <vtkMatrix4x4.h> 25 #include <vtkRenderer.h> 26 #include <vtkCursor2D.h> 27 #include <vtkLeaderActor2D.h> 29 #include <vtkProperty.h> 33 #include "vtkOverrideInformationCollection.h" 34 #include "vtkObjectFactory.h" 42 Vector3D retval(color.redF(), color.greenF(), color.blueF());
51 for (
unsigned i=0; i<size(); ++i)
52 elems[i] = t.elems[i];
59 for (
unsigned i=0; i<size(); ++i)
60 elems[i] = t.elems[i];
68 elems[1] = t.greenF();
76 elems[1] = c.greenF();
102 mRenderer = renderer;
103 source = vtkSphereSourcePtr::New() ;
104 source->SetRadius( 4);
106 mapper = vtkPolyDataMapper2DPtr::New() ;
107 mapper->SetInputConnection(source->GetOutputPort() );
109 actor = vtkActor2DPtr::New();
110 actor->SetMapper(mapper);
111 mRenderer->AddActor(actor);
116 mRenderer->RemoveActor(actor);
121 source->SetRadius(radius);
126 actor->GetProperty()->SetColor(color.begin());
127 actor->SetPosition(point.begin());
132 actor->GetProperty()->SetColor(color.begin());
133 actor->SetPosition(point.begin());
139 actor->SetPosition ( p.begin() );
155 mRenderer = renderer;
156 source = vtkLineSourcePtr::New();
157 mapper2d = vtkPolyDataMapper2DPtr::New();
158 actor2d = vtkActor2DPtr::New();
163 mRenderer->RemoveActor(actor2d);
168 source->SetPoint1(point1.begin());
169 source->SetPoint2(point2.begin());
170 mapper2d->SetInputConnection(source->GetOutputPort());
171 actor2d->SetMapper(mapper2d);
172 actor2d->GetProperty()->SetColor(color.begin());
173 actor2d->GetProperty()->SetLineStipplePattern(stipplePattern);
174 mRenderer->AddActor(actor2d);
179 source->SetResolution(res);
184 actor2d->GetProperty()->SetLineWidth(width);
189 source->SetPoint1(point1.begin());
190 source->SetPoint2(point2.begin());
195 actor2d->GetProperty()->SetColor(color.begin());
200 actor2d->GetProperty()->SetLineStipplePattern(stipplePattern);
214 mRenderer = renderer;
215 mCursor2D = vtkCursor2DPtr::New();
216 mapper = vtkPolyDataMapper2DPtr::New();
217 mapper->SetInputConnection ( mCursor2D->GetOutputPort() );
219 actor = vtkActor2DPtr::New();
220 actor->SetMapper ( mapper );
221 mRenderer->AddActor ( actor );
226 mRenderer->RemoveActor(actor);
234 mCursor2D->SetModelBounds ( bordarOffset, width - bordarOffset, bordarOffset, height - bordarOffset, 0.0, 0.0 );
235 mCursor2D->SetFocalPoint ( p[0]/2, p[1]/2, 0.0 );
236 mCursor2D->SetRadius ( 5 );
239 mCursor2D->PointOn();
240 mCursor2D->OutlineOff();
241 actor->GetProperty()-> SetColor ( c.begin() );
251 mCursor2D->SetModelBounds( cp[0]-50, cp[0]+50, cp[1]-50, cp[1]+50, 0.0, 0.0 );
252 mCursor2D->SetFocalPoint ( cp.begin() );
270 mCursor2D->PointOn();
271 mCursor2D->OutlineOff();
276 mCursor2D->SetFocalPoint ( cp.begin() );
298 mapper = vtkTextMapperPtr::New();
300 this->setColor(color);
301 mapper->GetTextProperty()->SetFontSize( fontsize );
303 actor= vtkActor2DPtr::New();
304 actor->SetMapper( mapper );
315 vtkNew<vtkOverrideInformationCollection> overrides;
316 vtkObjectFactory::GetOverrideInformation(
"vtkTextMapper",
317 overrides.GetPointer());
318 overrides->InitTraversal();
319 while (vtkOverrideInformation *
override = overrides->GetNextItem())
321 if (vtkObjectFactory *factory = override->GetObjectFactory())
323 vtkObjectFactory::UnRegisterFactory(factory);
326 verifyVtkTextMapper();
329 void TextDisplay::verifyVtkTextMapper()
331 vtkNew<vtkTextMapper> nameChecker;
332 if (vtkStdString(nameChecker->GetClassName()) !=
"vtkTextMapper")
334 reportError(
"Needed a vtkTextMapper instance, got " + QString(nameChecker->GetClassName()));
346 mRenderer->RemoveActor(actor);
347 mRenderer = renderer;
349 mRenderer->AddActor(actor);
360 QStringList components = text.split(
"\n");
361 for (QStringList::iterator it = components.begin(); it != components.end(); ++it)
363 this->verifyVtkTextMapper();
365 bool changed =
false;
366 line->SetInput( it->toLatin1().constData() );
367 line->SetTextProperty(mapper->GetTextProperty());
368 while((*it).length() > 0 && line->GetWidth(vp) > maxWidth)
371 line->SetInput( QString(
"%1...").arg(*it).toLatin1().constData() );
379 QString newString = components.join(
"\n");
380 mapper->SetInput( newString.toLatin1().constData() );
390 return mapper->GetWidth( vp );
395 actor->SetPosition( pos[0], pos[1] );
400 actor->SetPosition( x, y );
405 QString input = text;
411 if (input == QString(mapper->GetInput()))
420 return mapper->GetTextProperty();
430 mapper->GetTextProperty()->SetJustificationToCentered() ;
431 mapper->GetTextProperty()->SetVerticalJustificationToCentered() ;
440 mAxes = vtkSmartPointer<vtkAxesActor>::New();
442 setCaption(mAxes->GetXAxisCaptionActor2D(),
"x",
RGBColor(1,0,0));
443 setCaption(mAxes->GetYAxisCaptionActor2D(),
"y",
RGBColor(0,1,0));
444 setCaption(mAxes->GetZAxisCaptionActor2D(),
"z",
RGBColor(0,0,1));
451 Vector3D len(mAxes->GetNormalizedShaftLength());
454 mAxes->SetNormalizedShaftLength(len.begin());
457 mRenderer->AddActor(mAxes);
474 mRenderer->RemoveActor(mAxes);
482 void Axes3D::setCaption(vtkCaptionActor2D* captionActor,
const QString& caption,
RGBColor color)
485 captionActor->GetCaptionTextProperty()->SetColor(color.begin());
487 double fontsize = 0.02;
488 captionActor->SetWidth(fontsize);
489 captionActor->SetHeight(fontsize);
vtkTextProperty * textProperty()
void reportError(QString msg)
void updateRegCross(const Vector3D &crossPos)
Vector3D getColorAsVector3D(QColor color)
RGBColor & operator=(const RGBColor &t)
void setResolution(int res)
Transform3D createTransformScale(const Vector3D &scale_)
vtkSmartPointer< class vtkActor2D > vtkActor2DPtr
vtkSmartPointer< class vtkTextMapper > vtkTextMapperPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void setPoints(Vector3D point1, Vector3D point2, RGBColor color, int stipplePattern=0xFFFF)
cstring_cast_Placeholder cstring_cast(const T &val)
void setRadius(int radius)
void update(const Vector3D &crossPos, const DoubleBoundingBox3D &vp)
void setColor(RGBColor color)
void setWidth(float width)
LineSegment(vtkRendererPtr renderer)
void updatePosition(Vector3D point1, Vector3D point2)
void setMaxWidth(int width, vtkViewport *vp)
void setColor(QColor color)
void setValue(Vector3D point, RGBColor color)
void setPosition(float x, float y)
void setPosition(const Transform3D &pos)
CrossHair2D(vtkRendererPtr renderer)
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
int getWidth(vtkViewport *vp)
void setValue(const Vector3D &focalPoint, int width, int height, double bordarOffset, const RGBColor &color)
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
TextDisplay(const QString &text, const QColor &color, int fontsize)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
vtkSmartPointer< class vtkProp3D > vtkProp3DPtr
void updateText(const QString &text)
Axes3D(vtkRendererPtr renderer=vtkRendererPtr())
static void forceUseVtkTextMapper()
OffsetPoint(vtkRendererPtr renderer)
void setPattern(int stipplePattern)
void update(const Vector3D &point)
bool contains(const Vector3D &p) const
void setRenderer(vtkRendererPtr renderer)
Namespace for all CustusX production code.