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();
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);