37 #include <vtkSphereSource.h>
38 #include <vtkLineSource.h>
39 #include <vtkPolyDataMapper2D.h>
40 #include <vtkProperty2D.h>
41 #include <vtkTextMapper.h>
42 #include <vtkTextProperty.h>
43 #include <vtkAxesActor.h>
44 #include <vtkCaptionActor2D.h>
45 #include <vtkMatrix4x4.h>
46 #include <vtkRenderer.h>
47 #include <vtkCursor2D.h>
48 #include <vtkLeaderActor2D.h>
50 #include <vtkProperty.h>
54 #include "vtkOverrideInformationCollection.h"
55 #include "vtkObjectFactory.h"
63 property->SetColor(color.redF(), color.greenF(), color.blueF());
64 property->SetOpacity(color.alphaF());
69 Vector3D retval(color.redF(), color.greenF(), color.blueF());
78 for (
unsigned i=0; i<size(); ++i)
79 elems[i] = t.elems[i];
86 for (
unsigned i=0; i<size(); ++i)
87 elems[i] = t.elems[i];
95 elems[1] = t.greenF();
103 elems[1] = c.greenF();
104 elems[2] = c.blueF();
129 mRenderer = renderer;
130 source = vtkSphereSourcePtr::New() ;
131 source->SetRadius( 4);
133 mapper = vtkPolyDataMapper2DPtr::New() ;
134 mapper->SetInputConnection(source->GetOutputPort() );
136 actor = vtkActor2DPtr::New();
137 actor->SetMapper(mapper);
138 mRenderer->AddActor(actor);
143 mRenderer->RemoveActor(actor);
148 source->SetRadius(radius);
153 actor->GetProperty()->SetColor(color.begin());
154 actor->SetPosition(point.begin());
159 actor->GetProperty()->SetColor(color.begin());
160 actor->SetPosition(point.begin());
166 actor->SetPosition ( p.begin() );
182 mRenderer = renderer;
183 source = vtkLineSourcePtr::New();
184 mapper2d = vtkPolyDataMapper2DPtr::New();
185 actor2d = vtkActor2DPtr::New();
190 mRenderer->RemoveActor(actor2d);
195 source->SetPoint1(point1.begin());
196 source->SetPoint2(point2.begin());
197 mapper2d->SetInputConnection(source->GetOutputPort());
198 actor2d->SetMapper(mapper2d);
199 actor2d->GetProperty()->SetColor(color.begin());
200 actor2d->GetProperty()->SetLineStipplePattern(stipplePattern);
201 mRenderer->AddActor(actor2d);
206 source->SetResolution(res);
211 actor2d->GetProperty()->SetLineWidth(width);
216 source->SetPoint1(point1.begin());
217 source->SetPoint2(point2.begin());
222 actor2d->GetProperty()->SetColor(color.begin());
227 actor2d->GetProperty()->SetLineStipplePattern(stipplePattern);
241 mRenderer = renderer;
242 mCursor2D = vtkCursor2DPtr::New();
243 mapper = vtkPolyDataMapper2DPtr::New();
244 mapper->SetInputConnection ( mCursor2D->GetOutputPort() );
246 actor = vtkActor2DPtr::New();
247 actor->SetMapper ( mapper );
248 mRenderer->AddActor ( actor );
253 mRenderer->RemoveActor(actor);
261 mCursor2D->SetModelBounds ( bordarOffset, width - bordarOffset, bordarOffset, height - bordarOffset, 0.0, 0.0 );
262 mCursor2D->SetFocalPoint ( p[0]/2, p[1]/2, 0.0 );
263 mCursor2D->SetRadius ( 5 );
266 mCursor2D->PointOn();
267 mCursor2D->OutlineOff();
268 actor->GetProperty()-> SetColor ( c.begin() );
278 mCursor2D->SetModelBounds( cp[0]-50, cp[0]+50, cp[1]-50, cp[1]+50, 0.0, 0.0 );
279 mCursor2D->SetFocalPoint ( cp.begin() );
297 mCursor2D->PointOn();
298 mCursor2D->OutlineOff();
303 mCursor2D->SetFocalPoint ( cp.begin() );
325 mapper = vtkTextMapperPtr::New();
328 mapper->GetTextProperty()->SetFontSize( fontsize );
330 actor= vtkActor2DPtr::New();
331 actor->SetMapper( mapper );
342 vtkNew<vtkOverrideInformationCollection> overrides;
343 vtkObjectFactory::GetOverrideInformation(
"vtkTextMapper",
344 overrides.GetPointer());
345 overrides->InitTraversal();
346 while (vtkOverrideInformation *
override = overrides->GetNextItem())
348 if (vtkObjectFactory *factory = override->GetObjectFactory())
350 vtkObjectFactory::UnRegisterFactory(factory);
353 verifyVtkTextMapper();
356 void TextDisplay::verifyVtkTextMapper()
358 vtkNew<vtkTextMapper> nameChecker;
359 if (vtkStdString(nameChecker->GetClassName()) !=
"vtkTextMapper")
361 reportError(
"Needed a vtkTextMapper instance, got " + QString(nameChecker->GetClassName()));
373 mRenderer->RemoveActor(actor);
374 mRenderer = renderer;
376 mRenderer->AddActor(actor);
387 QStringList components = text.split(
"\n");
388 for (QStringList::iterator it = components.begin(); it != components.end(); ++it)
390 this->verifyVtkTextMapper();
392 bool changed =
false;
393 line->SetInput( it->toLatin1().constData() );
394 line->SetTextProperty(mapper->GetTextProperty());
395 while((*it).length() > 0 && line->GetWidth(vp) > maxWidth)
398 line->SetInput( QString(
"%1...").arg(*it).toLatin1().constData() );
406 QString newString = components.join(
"\n");
407 mapper->SetInput( newString.toLatin1().constData() );
417 return mapper->GetWidth( vp );
422 actor->SetPosition( pos[0], pos[1] );
427 actor->SetPosition( x, y );
436 mapper->SetInput(
" " );
445 return mapper->GetTextProperty();
455 mapper->GetTextProperty()->SetJustificationToCentered() ;
456 mapper->GetTextProperty()->SetVerticalJustificationToCentered() ;
465 mAxes = vtkSmartPointer<vtkAxesActor>::New();
467 setCaption(mAxes->GetXAxisCaptionActor2D(),
"x",
RGBColor(1,0,0));
468 setCaption(mAxes->GetYAxisCaptionActor2D(),
"y",
RGBColor(0,1,0));
469 setCaption(mAxes->GetZAxisCaptionActor2D(),
"z",
RGBColor(0,0,1));
476 Vector3D len(mAxes->GetNormalizedShaftLength());
479 mAxes->SetNormalizedShaftLength(len.begin());
482 mRenderer->AddActor(mAxes);
499 mRenderer->RemoveActor(mAxes);
507 void Axes3D::setCaption(vtkCaptionActor2D* captionActor,
const QString& caption,
RGBColor color)
510 captionActor->GetCaptionTextProperty()->SetColor(color.begin());
512 double fontsize = 0.02;
513 captionActor->SetWidth(fontsize);
514 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 vtkProperty > vtkPropertyPtr
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)
void setColorAndOpacity(vtkPropertyPtr property, QColor color)
bool contains(const Vector3D &p) const
void setRenderer(vtkRendererPtr renderer)