VTK  9.2.6
vtkWordCloud.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkWordCloud.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15#ifndef vtkWordCloud_h
16#define vtkWordCloud_h
17
18#include "vtkImageAlgorithm.h"
19#include "vtkImageData.h" // For ImageData
20#include "vtkInfovisCoreModule.h" // For export macro
21#include "vtkSmartPointer.h" // For SmartPointer
22
23#include <array> // For stl array
24#include <functional> // for function
25#include <set> // for stl multiset
26#include <string> // For stl string
27#include <vector> // For stl vector
28
180
181class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
182{
183public:
185 void PrintSelf(ostream& os, vtkIndent indent) override;
186
190 static vtkWordCloud* New();
191
192 // Typedefs
193 using ColorDistributionContainer = std::array<double, 2>;
194 using OffsetDistributionContainer = std::array<int, 2>;
195 using OrientationDistributionContainer = std::array<double, 2>;
196 using OrientationsContainer = std::vector<double>;
197 using PairType = std::tuple<std::string, std::string>;
198 using ReplacementPairsContainer = std::vector<PairType>;
199 using SizesContainer = std::array<int, 2>;
200 using StopWordsContainer = std::set<std::string>;
201 using StringContainer = std::vector<std::string>;
202
204
209
210#define SetStdContainerMacro(name, container) \
211 virtual void Set##name(container arg) \
212 { \
213 bool changed = false; \
214 if (arg.size() != name.size()) \
215 { \
216 changed = true; \
217 } \
218 else \
219 { \
220 auto a = arg.begin(); \
221 for (auto r : name) \
222 { \
223 if (*a != r) \
224 { \
225 changed = true; \
226 } \
227 a++; \
228 } \
229 } \
230 if (changed) \
231 { \
232 name = arg; \
233 this->Modified(); \
234 } \
235 }
236
238
242 virtual void SetBackgroundColorName(std::string arg)
243 {
244 if (arg != BackgroundColorName)
245 {
246 this->Modified();
248 }
249 }
250 virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
251
253
258 virtual void SetBWMask(bool arg)
259 {
260 if (BWMask != arg)
261 {
262 this->Modified();
263 BWMask = arg;
264 }
265 }
266 virtual bool GetBWMask() { return BWMask; }
267
269
276 virtual void SetColorSchemeName(std::string arg)
277 {
278 if (ColorSchemeName != arg)
279 {
280 this->Modified();
281 ColorSchemeName = arg;
282 }
283 }
284 virtual std::string GetColorSchemeName() { return ColorSchemeName; }
285
287
294 vtkSetMacro(DPI, int);
295 vtkGetMacro(DPI, int);
296
298
303 virtual void SetFileName(VTK_FILEPATH std::string arg)
304 {
305 if (FileName != arg)
306 {
307 this->Modified();
308 FileName = arg;
309 }
310 }
311 virtual std::string GetFileName() VTK_FUTURE_CONST { return FileName; }
312
314
320 virtual void SetFontFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
321 {
322 if (FontFileName != arg)
323 {
324 this->Modified();
325 FontFileName = arg;
326 }
327 }
328 virtual std::string GetFontFileName() VTK_FUTURE_CONST { return FontFileName; }
329
331
336 vtkSetMacro(Gap, int);
337 vtkGetMacro(Gap, int);
338
340
346 virtual void SetMaskColorName(std::string arg)
347 {
348 if (MaskColorName != arg)
349 {
350 this->Modified();
351 MaskColorName = arg;
352 }
353 }
354 virtual std::string GetMaskColorName() { return MaskColorName; }
355
357
367 virtual void SetMaskFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
368 {
369 if (MaskFileName != arg)
370 {
371 this->Modified();
372 MaskFileName = arg;
373 }
374 }
375 virtual std::string GetMaskFileName() VTK_FUTURE_CONST { return MaskFileName; }
376
378
382 vtkSetMacro(MaxFontSize, int);
383 vtkGetMacro(MaxFontSize, int);
384
386
390 vtkSetMacro(MinFontSize, int);
391 vtkGetMacro(MinFontSize, int);
392
394
400 vtkSetMacro(MinFrequency, int);
401 vtkGetMacro(MinFrequency, int);
402
404
409 vtkSetMacro(FontMultiplier, int);
410 vtkGetMacro(FontMultiplier, int);
411
413
420
422
430
432
443
445
452 void AddOrientation(double arg)
453 {
454 Orientations.push_back(arg);
455 this->Modified();
456 }
458
460
468 {
469 ReplacementPairs.push_back(arg);
470 this->Modified();
471 }
472
474
476
481 virtual SizesContainer GetSizes() { return Sizes; }
482
484
491 void AddStopWord(std::string word)
492 {
493 StopWords.insert(word);
494 this->Modified();
495 }
497 {
498 StopWords.clear();
499 this->Modified();
500 }
502
504
509 virtual void SetStopListFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
510 {
511 if (StopListFileName != arg)
512 {
513 this->Modified();
514 StopListFileName = arg;
515 }
516 }
517 virtual std::string GetStopListFileName() VTK_FUTURE_CONST { return StopListFileName; }
518
520
525 virtual void SetTitle(std::string arg)
526 {
527 if (Title != arg)
528 {
529 this->Modified();
530 Title = arg;
531 }
532 }
533 virtual std::string GetTitle() { return Title; }
534
536
542 virtual void SetWordColorName(std::string arg)
543 {
544 if (WordColorName != arg)
545 {
546 this->Modified();
547 WordColorName = arg;
548 }
549 }
550 virtual std::string GetWordColorName() { return WordColorName; }
552
556 virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
557
559
564 virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
565
567
571 virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
572
573protected:
575 ~vtkWordCloud() override = default;
576
578
580
583
586 bool BWMask;
588 std::string ColorSchemeName;
589 int DPI;
590 std::string FileName;
591 std::string FontFileName;
593 int Gap;
594 std::string MaskColorName;
595 std::string MaskFileName;
605 std::string StopListFileName;
606 std::string Title;
607 std::string WordColorName;
608
609 std::vector<std::string> KeptWords;
610 std::vector<std::string> SkippedWords;
611 std::vector<std::string> StoppedWords;
612
613private:
614 vtkWordCloud(const vtkWordCloud&) = delete;
615 void operator=(const vtkWordCloud&) = delete;
616
617 // Declaring the type of Predicate that accepts 2 pairs and returns a bool
618 typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
619
620 std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
621 std::string&, vtkWordCloud*);
622 struct ExtentOffset
623 {
624 ExtentOffset(int _x = 0.0, int _y = 0.0)
625 : x(_x)
626 , y(_y)
627 {
628 }
629 int x, y;
630 };
631};
632#endif
633
634// LocalWords: vtkNamedColors SetMaskColorName
a simple class to control print indentation
Definition vtkIndent.h:34
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
virtual void Modified()
Update the modification time for this object.
Hold a reference to a vtkObjectBase instance.
virtual OrientationsContainer GetOrientations()
virtual OffsetDistributionContainer GetOffsetDistribution()
virtual void SetWordColorName(std::string arg)
Set/Get WordColorName, the name of the color for the words().
virtual std::string GetMaskFileName() VTK_FUTURE_CONST
virtual void SetBackgroundColorName(std::string arg)
Set/Get the vtkNamedColors name for the background(MidNightBlue).
virtual SizesContainer GetAdjustedSizes()
Return the AdjustedSizes of the resized mask file.
static vtkWordCloud * New()
Construct object with vertex cell generation turned off.
virtual void SetFileName(VTK_FILEPATH std::string arg)
Set/Get FileName, the name of the file that contains the text to be processed.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called in response to a REQUEST_DATA request from the executive.
std::vector< PairType > ReplacementPairsContainer
virtual void SetTitle(std::string arg)
Set/Get Title, add this word to the document's words and set a high frequency, so that is will be ren...
virtual std::string GetFontFileName() VTK_FUTURE_CONST
std::string StopListFileName
vtkSmartPointer< vtkImageData > ImageData
std::array< int, 2 > OffsetDistributionContainer
std::string ColorSchemeName
SetStdContainerMacro(Orientations, OrientationsContainer)
Set/Add/Get Orientations, a vector of discrete orientations ().
virtual std::vector< std::string > & GetKeptWords()
Get a vector of words that are kept in the final image.
virtual void SetColorSchemeName(std::string arg)
Set/Get ColorSchemeName, the name of a color scheme from vtkColorScheme to be used to select colors f...
virtual std::string GetWordColorName()
virtual void SetMaskColorName(std::string arg)
Set/Get MaskColorName, the name of the color for the mask (black).
std::tuple< std::string, std::string > PairType
SetStdContainerMacro(StopWords, StopWordsContainer)
Set/Add/Get StopWords, a set of user provided stop words().
std::string MaskFileName
std::string WordColorName
std::string BackgroundColorName
SetStdContainerMacro(ColorDistribution, ColorDistributionContainer)
Set/Get ColorDistribution, the distribution of random colors(.6 1.0), if WordColorName is empty.
std::array< double, 2 > ColorDistributionContainer
virtual std::vector< std::string > & GetStoppedWords()
Get a vector of words that were stopped in the final image.
std::set< std::string > StopWordsContainer
ReplacementPairsContainer ReplacementPairs
int WholeExtent[6]
virtual std::string GetStopListFileName() VTK_FUTURE_CONST
std::string FileName
virtual void SetStopListFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
Set/Get StopListFileName, the name of the file that contains the stop words, one per line.
std::array< double, 2 > OrientationDistributionContainer
std::vector< std::string > StringContainer
SizesContainer AdjustedSizes
std::string FontFileName
virtual std::vector< std::string > & GetSkippedWords()
Get a vector of words that are skipped.
virtual std::string GetFileName() VTK_FUTURE_CONST
virtual void SetMaskFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
Set/Get MaskFileName, the mask file name().
SetStdContainerMacro(Sizes, SizesContainer)
Set/Get Sizes, the size of the output image(640 480).
OrientationsContainer Orientations
virtual std::string GetTitle()
virtual SizesContainer GetSizes()
OrientationDistributionContainer OrientationDistribution
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Subclasses can reimplement this method to collect information from their inputs and set information f...
SizesContainer Sizes
std::string Title
virtual StopWordsContainer GetStopWords()
SetStdContainerMacro(OffsetDistribution, OffsetDistributionContainer)
Set/Get OffsetDistribution, the range of uniform random offsets(-size[0]/100.0 -size{1]/100....
virtual std::string GetMaskColorName()
std::vector< std::string > SkippedWords
std::vector< std::string > KeptWords
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
ColorDistributionContainer ColorDistribution
void ClearStopWords()
SetStdContainerMacro(OrientationDistribution, OrientationDistributionContainer)
Set/Get OrientationDistribution, ranges of random orientations(-20 20).
virtual ColorDistributionContainer GetColorDistribution()
virtual std::string GetBackgroundColorName()
virtual ReplacementPairsContainer GetReplacementPairs()
virtual std::string GetColorSchemeName()
StopWordsContainer StopWords
~vtkWordCloud() override=default
virtual OrientationDistributionContainer GetOrientationDistribution()
std::vector< double > OrientationsContainer
void AddReplacementPair(PairType arg)
std::vector< std::string > StoppedWords
void AddStopWord(std::string word)
OffsetDistributionContainer OffsetDistribution
virtual bool GetBWMask()
virtual void SetBWMask(bool arg)
Set/Get boolean that indicates the mask image is a single channel(false).
virtual void SetFontFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
Set/Get FontFileName, If empty, the built-in Arial font is used().
SetStdContainerMacro(ReplacementPairs, ReplacementPairsContainer)
Set/Add/Get ReplacementPairs, a vector of words that replace the first word with another second word ...
std::string MaskColorName
std::array< int, 2 > SizesContainer
void AddOrientation(double arg)
#define VTK_FILEPATH