OGS
VtkVisImageItem Class Reference

Detailed Description

An item in the VtkVisPipeline containing an image to be visualized.

Any vtkImageAlgorithm object is represented by a VtkVisImageItem to be assigned a mapper, an actor and its visualization properties.

See also
VtkVisPipelineItem

Definition at line 36 of file VtkVisImageItem.h.

#include <VtkVisImageItem.h>

Inheritance diagram for VtkVisImageItem:
[legend]
Collaboration diagram for VtkVisImageItem:
[legend]

Public Member Functions

 VtkVisImageItem (vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for a source/filter object. More...
 
 VtkVisImageItem (VtkCompositeFilter *compositeFilter, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for composite filter. More...
 
 ~VtkVisImageItem () override
 
void Initialize (vtkRenderer *renderer) override
 Initializes vtkMapper and vtkActor necessary for visualization of the item and sets the item's properties. More...
 
void setTranslation (double x, double y, double z) const override
 Translates the item in visualisation-space. This function is empty and needs to be implemented by derived classes. More...
 
vtkAlgorithm * transformFilter () const override
 
- Public Member Functions inherited from VtkVisPipelineItem
 VtkVisPipelineItem (vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for a source/filter object. More...
 
 VtkVisPipelineItem (VtkCompositeFilter *compositeFilter, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for composite filter. More...
 
 ~VtkVisPipelineItem () override
 
VtkVisPipelineItemchild (int row) const
 Returns a VtkVisPipelineItem. More...
 
QVariant data (int column) const override
 
bool setData (int column, const QVariant &value) override
 
vtkAlgorithm * algorithm () const
 Returns the algorithm object. More...
 
vtkProp3D * actor () const
 Returns the actor as vtkProp3D. More...
 
virtual QString GetActiveAttribute () const
 
virtual void SetActiveAttribute (const QString &str)
 
VtkCompositeFiltercompositeFilter () const
 Returns the composite filter. More...
 
bool isVisible () const
 Returns if the VTK object is visible in the visualization. More...
 
void setVisible (bool visible)
 Sets the visibility of the VTK object in the visualization. More...
 
int writeToFile (const std::string &filename) const
 Writes this algorithm's vtkDataSet (i.e. vtkPolyData or vtkUnstructuredGrid) to a vtk-file. More...
 
virtual void setScale (double x, double y, double z) const
 Scales the data in visualisation-space. This function is empty and needs to be implemented by derived classes. More...
 
void setScaleOnChildren (double x, double y, double z) const
 Sets the geometry and date scaling recursively on all children of this item. More...
 
virtual void setBackfaceCulling (bool enable) const
 Enables / disables backface culling. More...
 
void setBackfaceCullingOnChildren (bool enable) const
 Enables / disables backface culling on all children. More...
 
QStringList getScalarArrayNames () const
 Returns a list of array names prefixed with P- or C- for point and cell data. More...
 
VtkAlgorithmPropertiesgetVtkProperties () const
 Returns the VtkAlgorithmProperties. More...
 
- Public Member Functions inherited from TreeItem
 TreeItem (QList< QVariant > data, TreeItem *parent)
 
virtual ~TreeItem ()
 
void appendChild (TreeItem *item)
 
TreeItemchild (int row) const
 
virtual int childCount () const
 
virtual int columnCount () const
 
int row () const
 
TreeItemparentItem () const
 
bool removeChildren (int position, int count)
 

Protected Member Functions

int callVTKWriter (vtkAlgorithm *algorithm, const std::string &filename) const override
 Selects the appropriate VTK-Writer object and writes the object to a file with the given name. More...
 
void setVtkProperties (VtkAlgorithmProperties *vtkProps)
 

Private Attributes

vtkImageChangeInformation * _transformFilter
 

Additional Inherited Members

- Protected Attributes inherited from VtkVisPipelineItem
vtkProp3D * _actor
 
vtkAlgorithm * _algorithm
 
vtkRenderer * _renderer
 
VtkCompositeFilter_compositeFilter
 
VtkAlgorithmProperties_vtkProps
 The active VtkAlgorithmProperties. From algorithm, compositeFilter, or copied from parent. More...
 

Constructor & Destructor Documentation

◆ VtkVisImageItem() [1/2]

VtkVisImageItem::VtkVisImageItem ( vtkAlgorithm *  algorithm,
TreeItem parentItem,
const QList< QVariant >  data = QList<QVariant>() 
)

Constructor for a source/filter object.

Definition at line 38 of file VtkVisImageItem.cpp.

42 {
43 }
TreeItem * parentItem() const
Definition: TreeItem.cpp:115
vtkImageChangeInformation * _transformFilter
vtkAlgorithm * algorithm() const
Returns the algorithm object.
VtkVisPipelineItem(vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
Constructor for a source/filter object.
QVariant data(int column) const override

◆ VtkVisImageItem() [2/2]

VtkVisImageItem::VtkVisImageItem ( VtkCompositeFilter compositeFilter,
TreeItem parentItem,
const QList< QVariant >  data = QList<QVariant>() 
)

Constructor for composite filter.

Definition at line 45 of file VtkVisImageItem.cpp.

49  _transformFilter(nullptr)
50 {
51 }
VtkCompositeFilter * compositeFilter() const
Returns the composite filter.

◆ ~VtkVisImageItem()

VtkVisImageItem::~VtkVisImageItem ( )
override

Definition at line 53 of file VtkVisImageItem.cpp.

54 {
55  _transformFilter->Delete();
56 }

References _transformFilter.

Member Function Documentation

◆ callVTKWriter()

int VtkVisImageItem::callVTKWriter ( vtkAlgorithm *  algorithm,
const std::string &  filename 
) const
overrideprotectedvirtual

Selects the appropriate VTK-Writer object and writes the object to a file with the given name.

Reimplemented from VtkVisPipelineItem.

Definition at line 152 of file VtkVisImageItem.cpp.

154 {
155  std::string file_name_cpy(filename);
156  auto* algID = dynamic_cast<vtkImageAlgorithm*>(algorithm);
157  if (algID)
158  {
159  vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
160  vtkSmartPointer<vtkXMLImageDataWriter>::New();
161  iWriter->SetInputData(algID->GetOutputDataObject(0));
162  if (BaseLib::getFileExtension(filename) != ".vti")
163  {
164  file_name_cpy.append(".vti");
165  }
166  iWriter->SetFileName(file_name_cpy.c_str());
167  return iWriter->Write();
168  }
169  ERR("VtkVisPipelineItem::writeToFile() - Unknown data type.");
170  return 0;
171 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
std::string getFileExtension(const std::string &path)
Definition: FileTools.cpp:186

References VtkVisPipelineItem::algorithm(), ERR(), and BaseLib::getFileExtension().

◆ Initialize()

void VtkVisImageItem::Initialize ( vtkRenderer *  renderer)
overridevirtual

Initializes vtkMapper and vtkActor necessary for visualization of the item and sets the item's properties.

Implements VtkVisPipelineItem.

Definition at line 58 of file VtkVisImageItem.cpp.

59 {
60  auto* img = dynamic_cast<vtkImageAlgorithm*>(_algorithm);
61  img->Update();
62  // VtkGeoImageSource* img = dynamic_cast<VtkGeoImageSource*>(_algorithm);
63 
64  double origin[3];
65  double spacing[3];
66  double range[2];
67  img->GetOutput()->GetOrigin(origin);
68  img->GetOutput()->GetSpacing(spacing);
69  // img->getRange(range);
70  img->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
71  vtkImageShiftScale* scale = vtkImageShiftScale::New();
72  scale->SetOutputScalarTypeToUnsignedChar();
73  scale->SetInputConnection(img->GetOutputPort());
74  scale->SetShift(-range[0]);
75  scale->SetScale(255.0 / (range[1] - range[0]));
76 
77  _transformFilter = vtkImageChangeInformation::New();
78  _transformFilter->SetInputConnection(scale->GetOutputPort());
79  // double origin[3];
80  // img->getOrigin(origin);
81  // double spacing = img->getSpacing();
82  //_transformFilter->SetOutputOrigin(origin2);
83  //_transformFilter->SetOutputSpacing(spacing2);
84  _transformFilter->Update();
85 
86  _renderer = renderer;
87 
88  // Use a special vtkImageActor instead of vtkActor
89  vtkImageActor* imageActor = vtkImageActor::New();
90  imageActor->SetInputData(_transformFilter->GetOutput());
91  _actor = imageActor;
92  _renderer->AddActor(_actor);
93 
94  // Set pre-set properties
95  auto* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm);
96  if (vtkProps)
97  {
98  setVtkProperties(vtkProps);
99  }
100 
101  auto* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem());
102  while (parentItem)
103  {
104  auto* parentProps =
105  dynamic_cast<VtkAlgorithmProperties*>(parentItem->algorithm());
106  if (parentProps)
107  {
108  auto* newProps = new VtkAlgorithmProperties();
109  newProps->SetScalarVisibility(parentProps->GetScalarVisibility());
110  newProps->SetTexture(parentProps->GetTexture());
111  setVtkProperties(newProps);
112  vtkProps = newProps;
113  parentItem = nullptr;
114  }
115  else
116  {
117  parentItem =
118  dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem());
119  }
120  }
121 
122  // Set active scalar to the desired one from VtkAlgorithmProperties
123  // or to match those of the parent.
124  if (vtkProps)
125  {
126  if (vtkProps->GetActiveAttribute().length() > 0)
127  {
128  this->SetActiveAttribute(vtkProps->GetActiveAttribute());
129  }
130  else
131  {
132  auto* visParentItem =
133  dynamic_cast<VtkVisPipelineItem*>(this->parentItem());
134  if (visParentItem)
135  {
136  this->SetActiveAttribute(visParentItem->GetActiveAttribute());
137  }
138  if (vtkProps->GetTexture() != nullptr)
139  {
140  this->SetActiveAttribute("Solid Color");
141  }
142  }
143  }
144 }
Contains properties for the visualization of objects as VtkVisPipelineItems.
void setVtkProperties(VtkAlgorithmProperties *vtkProps)
An item in the VtkVisPipeline containing a graphic object to be visualized.
vtkAlgorithm * _algorithm
virtual void SetActiveAttribute(const QString &str)
void scale(PETScVector &x, double const a)
Definition: LinAlg.cpp:44

References VtkVisPipelineItem::_actor, VtkVisPipelineItem::_algorithm, VtkVisPipelineItem::_renderer, _transformFilter, TreeItem::parentItem(), MathLib::LinAlg::scale(), VtkVisPipelineItem::SetActiveAttribute(), and setVtkProperties().

◆ setTranslation()

void VtkVisImageItem::setTranslation ( double  x,
double  y,
double  z 
) const
overridevirtual

Translates the item in visualisation-space. This function is empty and needs to be implemented by derived classes.

Reimplemented from VtkVisPipelineItem.

Definition at line 173 of file VtkVisImageItem.cpp.

174 {
175  _transformFilter->SetOriginTranslation(x, y, z);
176 }

References _transformFilter.

◆ setVtkProperties()

void VtkVisImageItem::setVtkProperties ( VtkAlgorithmProperties vtkProps)
protected

Definition at line 146 of file VtkVisImageItem.cpp.

147 {
148  // todo implementation
149  (void)vtkProps;
150 }

Referenced by Initialize().

◆ transformFilter()

vtkAlgorithm * VtkVisImageItem::transformFilter ( ) const
overridevirtual

Returns the transform filter for the object. This function needs to be implemented by derived classes.

Implements VtkVisPipelineItem.

Definition at line 178 of file VtkVisImageItem.cpp.

179 {
180  return _transformFilter;
181 }

References _transformFilter.

Referenced by VtkVisTabWidget::setActiveItem().

Member Data Documentation

◆ _transformFilter

vtkImageChangeInformation* VtkVisImageItem::_transformFilter
private

Definition at line 65 of file VtkVisImageItem.h.

Referenced by ~VtkVisImageItem(), Initialize(), setTranslation(), and transformFilter().


The documentation for this class was generated from the following files: