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
184class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
185{
186public:
188 void PrintSelf(ostream& os, vtkIndent indent) override;
189
193 static vtkWordCloud* New();
194
195 // Typedefs
196 using ColorDistributionContainer = std::array<double, 2>;
197 using OffsetDistributionContainer = std::array<int, 2>;
198 using OrientationDistributionContainer = std::array<double, 2>;
199 using OrientationsContainer = std::vector<double>;
200 using PairType = std::tuple<std::string, std::string>;
201 using ReplacementPairsContainer = std::vector<PairType>;
202 using SizesContainer = std::array<int, 2>;
203 using StopWordsContainer = std::set<std::string>;
204 using StringContainer = std::vector<std::string>;
205
207
211 virtual SizesContainer GetAdjustedSizes() { return AdjustedSizes; }
212
213#define SetStdContainerMacro(name, container) \
214 virtual void Set##name(container arg) \
215 { \
216 bool changed = false; \
217 if (arg.size() != name.size()) \
218 { \
219 changed = true; \
220 } \
221 else \
222 { \
223 auto a = arg.begin(); \
224 for (auto r : name) \
225 { \
226 if (*a != r) \
227 { \
228 changed = true; \
229 } \
230 a++; \
231 } \
232 } \
233 if (changed) \
234 { \
235 name = arg; \
236 this->Modified(); \
237 } \
238 }
239
241
245 virtual void SetBackgroundColorName(std::string arg)
246 {
247 if (arg != BackgroundColorName)
248 {
249 this->Modified();
250 BackgroundColorName = arg;
251 }
252 }
253 virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
254
256
261 virtual void SetBWMask(bool arg)
262 {
263 if (BWMask != arg)
264 {
265 this->Modified();
266 BWMask = arg;
267 }
268 }
269 virtual bool GetBWMask() { return BWMask; }
270
272
279 virtual void SetColorSchemeName(std::string arg)
280 {
281 if (ColorSchemeName != arg)
282 {
283 this->Modified();
284 ColorSchemeName = arg;
285 }
286 }
287 virtual std::string GetColorSchemeName() { return ColorSchemeName; }
288
290
297 vtkSetMacro(DPI, int);
298 vtkGetMacro(DPI, int);
299
301
306 virtual void SetFileName(VTK_FILEPATH std::string arg)
307 {
308 if (FileName != arg)
309 {
310 this->Modified();
311 FileName = arg;
312 }
313 }
314 virtual std::string GetFileName() VTK_FUTURE_CONST { return FileName; }
315
317
323 virtual void SetFontFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
324 {
325 if (FontFileName != arg)
326 {
327 this->Modified();
328 FontFileName = arg;
329 }
330 }
331 virtual std::string GetFontFileName() VTK_FUTURE_CONST { return FontFileName; }
332
334
339 vtkSetMacro(Gap, int);
340 vtkGetMacro(Gap, int);
341
343
349 virtual void SetMaskColorName(std::string arg)
350 {
351 if (MaskColorName != arg)
352 {
353 this->Modified();
354 MaskColorName = arg;
355 }
356 }
357 virtual std::string GetMaskColorName() { return MaskColorName; }
358
360
370 virtual void SetMaskFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
371 {
372 if (MaskFileName != arg)
373 {
374 this->Modified();
375 MaskFileName = arg;
376 }
377 }
378 virtual std::string GetMaskFileName() VTK_FUTURE_CONST { return MaskFileName; }
379
381
385 vtkSetMacro(MaxFontSize, int);
386 vtkGetMacro(MaxFontSize, int);
387
389
393 vtkSetMacro(MinFontSize, int);
394 vtkGetMacro(MinFontSize, int);
395
397
403 vtkSetMacro(MinFrequency, int);
404 vtkGetMacro(MinFrequency, int);
405
407
412 vtkSetMacro(FontMultiplier, int);
413 vtkGetMacro(FontMultiplier, int);
414
416
422 virtual ColorDistributionContainer GetColorDistribution() { return ColorDistribution; }
423
425
432 virtual OffsetDistributionContainer GetOffsetDistribution() { return OffsetDistribution; }
433
435
443 {
444 return OrientationDistribution;
445 }
446
448
455 void AddOrientation(double arg)
456 {
457 Orientations.push_back(arg);
458 this->Modified();
459 }
460 virtual OrientationsContainer GetOrientations() { return Orientations; }
461
463
471 {
472 ReplacementPairs.push_back(arg);
473 this->Modified();
474 }
475
476 virtual ReplacementPairsContainer GetReplacementPairs() { return ReplacementPairs; }
477
479
484 virtual SizesContainer GetSizes() { return Sizes; }
485
487
494 void AddStopWord(std::string word)
495 {
496 StopWords.insert(word);
497 this->Modified();
498 }
500 {
501 StopWords.clear();
502 this->Modified();
503 }
504 virtual StopWordsContainer GetStopWords() { return StopWords; }
505
507
512 virtual void SetStopListFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
513 {
514 if (StopListFileName != arg)
515 {
516 this->Modified();
517 StopListFileName = arg;
518 }
519 }
520 virtual std::string GetStopListFileName() VTK_FUTURE_CONST { return StopListFileName; }
521
523
528 virtual void SetTitle(std::string arg)
529 {
530 if (Title != arg)
531 {
532 this->Modified();
533 Title = arg;
534 }
535 }
536 virtual std::string GetTitle() { return Title; }
537
539
545 virtual void SetWordColorName(std::string arg)
546 {
547 if (WordColorName != arg)
548 {
549 this->Modified();
550 WordColorName = arg;
551 }
552 }
553 virtual std::string GetWordColorName() { return WordColorName; }
555
559 virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
560
562
567 virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
568
570
574 virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
575
576protected:
578 ~vtkWordCloud() override = default;
579
581
583
585 int WholeExtent[6];
586
589 bool BWMask;
591 std::string ColorSchemeName;
592 int DPI;
593 std::string FileName;
594 std::string FontFileName;
596 int Gap;
597 std::string MaskColorName;
598 std::string MaskFileName;
608 std::string StopListFileName;
609 std::string Title;
610 std::string WordColorName;
611
612 std::vector<std::string> KeptWords;
613 std::vector<std::string> SkippedWords;
614 std::vector<std::string> StoppedWords;
615
616private:
617 vtkWordCloud(const vtkWordCloud&) = delete;
618 void operator=(const vtkWordCloud&) = delete;
619
620 // Declaring the type of Predicate that accepts 2 pairs and returns a bool
621 typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
622
623 std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
624 std::string&, vtkWordCloud*);
625 struct ExtentOffset
626 {
627 ExtentOffset(int _x = 0.0, int _y = 0.0)
628 : x(_x)
629 , y(_y)
630 {
631 }
632 int x, y;
633 };
634};
635#endif
636
637// LocalWords: vtkNamedColors SetMaskColorName
Generic algorithm superclass for image algs.
a simple class to control print indentation
Definition vtkIndent.h:40
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.
generate a word cloud visualization of a text document
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
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