19#include <vtkCellData.h>
20#include <vtkDataSetMapper.h>
21#include <vtkImageAlgorithm.h>
22#include <vtkLookupTable.h>
23#include <vtkPointData.h>
24#include <vtkProperty.h>
25#include <vtkRenderer.h>
26#include <vtkSmartPointer.h>
27#include <vtkTransform.h>
28#include <vtkTransformFilter.h>
46#include <vtkDataSetAttributes.h>
47#include <vtkPolyDataAlgorithm.h>
48#include <vtkTriangleFilter.h>
49#include <vtkTubeFilter.h>
50#include <vtkUnstructuredGridAlgorithm.h>
51#include <vtkXMLPolyDataWriter.h>
52#include <vtkXMLUnstructuredGridWriter.h>
56 const QList<QVariant>
data )
68 if (dynamic_cast<vtkImageAlgorithm*>(visParentItem->algorithm()))
70 _algorithm->SetInputConnection(
71 visParentItem->algorithm()->GetOutputPort());
75 auto* pointSetItem = dynamic_cast<VtkVisPointSetItem*>(parentItem);
78 _algorithm->SetInputConnection(
79 pointSetItem->transformFilter()->GetOutputPort());
87 const QList<QVariant>
data )
111 vtkSmartPointer<vtkTransform> transform =
112 vtkSmartPointer<vtkTransform>::New();
113 transform->Identity();
121 _mapper->InterpolateScalarsBeforeMappingOff();
122 _mapper->SetColorModeToMapScalars();
154 vtkProps->SetScalarVisibility(
156 vtkProps->SetTexture(parentProps->
GetTexture());
157 vtkProps->SetActiveAttribute(
177 if (vtkProps->GetActiveAttribute().length() == 0)
181 if (arrayNames.length() > 0)
183 vtkProps->SetActiveAttribute(arrayNames[0]);
187 vtkProps->SetActiveAttribute(
"Solid Color");
195 bool backfaceCulling = settings.value(
"globalCullBackfaces", 0).toBool();
203 QList<QVariant> thresholdRangeList;
204 thresholdRangeList.push_back(range[0]);
205 thresholdRangeList.push_back(range[1]);
207 ->SetUserVectorProperty(
"Range", thresholdRangeList);
213 _vtkProps->GetProperties()->SetEdgeVisibility(1);
219 _mapper->SetScalarVisibility(on);
224 QObject::connect(vtkProps, SIGNAL(ScalarVisibilityChanged(
bool)),
_mapper,
233 actor->GetProperty()->SetColor(1, 1, 1);
238 vtkSmartPointer<vtkProperty> itemProperty =
240 actor->SetProperty(itemProperty);
251 const std::string& filename)
const
253 std::string file_name_cpy(filename);
254 auto* algPD =
dynamic_cast<vtkPolyDataAlgorithm*
>(
algorithm);
257 vtkSmartPointer<vtkXMLPolyDataWriter> pdWriter =
258 vtkSmartPointer<vtkXMLPolyDataWriter>::New();
259 pdWriter->SetInputData(algPD->GetOutputDataObject(0));
262 file_name_cpy.append(
".vtp");
264 pdWriter->SetFileName(file_name_cpy.c_str());
265 return pdWriter->Write();
268 auto* algUG =
dynamic_cast<vtkUnstructuredGridAlgorithm*
>(
algorithm);
271 vtkSmartPointer<vtkXMLUnstructuredGridWriter> ugWriter =
272 vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
273 ugWriter->SetInputData(algUG->GetOutputDataObject(0));
276 file_name_cpy.append(
".vtu");
278 ugWriter->SetFileName(file_name_cpy.c_str());
279 return ugWriter->Write();
282 WARN(
"VtkVisPipelineItem::writeToFile(): Unknown data type.");
289 if (name.contains(QRegExp(
"^P-")))
293 else if (name.contains(QRegExp(
"^C-")))
297 else if (name.contains(
"Solid Color"))
299 _vtkProps->SetActiveAttribute(
"Solid Color");
300 _mapper->ScalarVisibilityOff();
311 vtkDataSet* dataSet =
312 vtkDataSet::SafeDownCast(this->
_algorithm->GetOutputDataObject(0));
322 vtkPointData* pointData = dataSet->GetPointData();
326 0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS,
328 _mapper->SetScalarModeToUsePointFieldData();
333 vtkCellData* cellData = dataSet->GetCellData();
337 0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS,
339 _mapper->SetScalarModeToUseCellFieldData();
346 _mapper->UseLookupTableScalarRangeOn();
353 vtkLookupTable* lut =
_vtkProps->GetLookupTable(name);
358 lut = vtkLookupTable::New();
360 lut->SetTableRange(range);
371 bool arrayFound =
false;
372 for (
int i = 0; i <
data->GetNumberOfArrays() && !arrayFound; i++)
374 std::string arrayName =
data->GetArrayName(i);
375 if (arrayName == name)
383 data->SetActiveAttribute(name.c_str(), vtkDataSetAttributes::SCALARS);
396 double* trans = transform->GetPosition();
397 transform->Identity();
398 transform->Scale(x, y, z);
399 transform->Translate(trans[0] / x, trans[1] / y, trans[2] / z);
410 double* scale = transform->GetScale();
411 transform->Identity();
412 transform->Scale(scale);
413 transform->Translate(x, y, z);
425 static_cast<vtkActor*
>(this->
_actor)
427 ->SetBackfaceCulling(
static_cast<int>(enable));
432 vtkDataSet* dataSet =
433 vtkDataSet::SafeDownCast(this->
_algorithm->GetOutputDataObject(0));
438 vtkPointData* pointData = dataSet->GetPointData();
446 vtkCellData* cellData = dataSet->GetCellData();
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the QVtkDataSetMapper class.
Definition of the VtkAlgorithmProperties class.
Definition of the VtkCompositeContourFilter class.
Definition of the VtkCompositeFilter class.
Definition of the VtkCompositeThresholdFilter class.
VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids....
Definition of the VtkVisPointSetItem class.
Simply wraps vtkDataSetMapper as a Qt object to enable slot connections.
static QVtkDataSetMapper * New()
Create new objects with New() because of VTKs reference counting.
TreeItem * parentItem() const
TreeItem(QList< QVariant > data, TreeItem *parent)
Contains properties for the visualization of objects as VtkVisPipelineItems.
bool GetScalarVisibility() const
Returns the scalar visibility.
void SetScalarVisibility(bool on)
Sets the scalar visibility.
vtkTexture * GetTexture()
Returns a texture (if one has been assigned).
QString GetActiveAttribute() const
Returns the desired active attribute.
vtkProperty * GetProperties() const
Returns the vtk properties.
Is used to combine several filter in one VtkVisPipelineItem. You can use vtk filter and custom filter...
Visualises only parts of meshes that are above/below/within given thresholds. In init() the threshold...
vtkProp3D * actor() const
Returns the actor as vtkProp3D.
QStringList getScalarArrayNames() const
Returns a list of array names prefixed with P- or C- for point and cell data.
vtkAlgorithm * algorithm() const
Returns the algorithm object.
VtkAlgorithmProperties * _vtkProps
The active VtkAlgorithmProperties. From algorithm, compositeFilter, or copied from parent.
VtkVisPipelineItem(vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
Constructor for a source/filter object.
vtkAlgorithm * _algorithm
VtkCompositeFilter * _compositeFilter
VtkAlgorithmProperties * getVtkProperties() const
Returns the VtkAlgorithmProperties.
QVariant data(int column) const override
VtkCompositeFilter * compositeFilter() const
Returns the composite filter.
void setTranslation(double x, double y, double z) const override
Translates the item in visualisation-space.
void GetRangeForActiveAttribute(double range[2]) const
Get the scalar range for the active attribute.
VtkVisPointSetItem(vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
Constructor for a source/filter object.
void SetActiveAttribute(const QString &name) override
Sets the selected attribute array for the visualisation of the data set.
bool activeAttributeExists(vtkDataSetAttributes *data, std::string &name)
Checks if the selected attribute actually exists for the data set.
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.
void SetScalarVisibility(bool on)
std::string _activeArrayName
void setVtkProperties(VtkAlgorithmProperties *vtkProps)
Sets pre-set properties on vtkActor and on vtkMapper.
~VtkVisPointSetItem() override
void setBackfaceCulling(bool enable) const override
Enables / disables backface culling.
QVtkDataSetMapper * _mapper
void setScale(double x, double y, double z) const override
Scales the data in visualisation-space.
QString GetActiveAttribute() const override
Gets the last selected attribute.
vtkTransformFilter * _transformFilter
vtkAlgorithm * transformFilter() const override
void Initialize(vtkRenderer *renderer) override
Initializes vtkMapper and vtkActor necessary for visualization of the item and sets the item's proper...
std::string getFileExtension(const std::string &path)