OGS
VtkSurfacesSource Class Reference

Detailed Description

VTK source object for the visualisation of surfaces. Technically, surfaces are displayed as triangulated polydata objects.

Definition at line 27 of file VtkSurfacesSource.h.

#include <VtkSurfacesSource.h>

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

Public Member Functions

 vtkTypeMacro (VtkSurfacesSource, vtkPolyDataAlgorithm)
 
void setSurfaces (const std::vector< GeoLib::Surface * > *surfaces)
 Sets the surfaces vector. More...
 
void PrintSelf (ostream &os, vtkIndent indent) override
 Prints its data on a stream. More...
 
void SetUserProperty (QString name, QVariant value) override
 Generates random colors for each surface. More...
 
- Public Member Functions inherited from VtkAlgorithmProperties
 VtkAlgorithmProperties (QObject *parent=nullptr)
 Constructor (sets default values) More...
 
 ~VtkAlgorithmProperties () override
 
vtkProperty * GetProperties () const
 Returns the vtk properties. More...
 
vtkTexture * GetTexture ()
 Returns a texture (if one has been assigned). More...
 
void SetTexture (vtkTexture *t)
 Sets a texture for the VtkVisPipelineItem. More...
 
vtkLookupTable * GetLookupTable (const QString &array_name)
 Returns the colour lookup table (if one has been assigned). More...
 
void RemoveLookupTable (const QString &array_name)
 Removes the lookup table for the given scalar. More...
 
void SetLookUpTable (const QString &array_name, vtkLookupTable *lut)
 Sets a colour lookup table for the given scalar array of the VtkVisPipelineItem. More...
 
void SetLookUpTable (const QString &array_name, const QString &filename)
 Loads a predefined color lookup table from a file for the specified scalar array. More...
 
bool GetScalarVisibility () const
 Returns the scalar visibility. More...
 
void SetScalarVisibility (bool on)
 Sets the scalar visibility. More...
 
QString GetName () const
 Returns the name. This is set to the file path if it is a source algorithm. More...
 
void SetName (QString name)
 Sets the name. More...
 
bool IsRemovable () const
 Is this algorithm removable from the pipeline (view). More...
 
QMap< QString, QVariant > * GetAlgorithmUserProperties () const
 Returns a map of user properties. More...
 
QMap< QString, QList< QVariant > > * GetAlgorithmUserVectorProperties () const
 Returns a map of vector user properties. More...
 
QVariant GetUserProperty (QString name) const
 Returns the value of a user property. More...
 
virtual void SetUserVectorProperty (QString name, QList< QVariant > values)
 Sets a vector user property. This should be implemented by subclasses. More...
 
QList< QVariant > GetUserVectorProperty (QString name) const
 Returns a list of values of a vector user property. More...
 
void SetActiveAttribute (QString name)
 Set the active attribute. More...
 
QString GetActiveAttribute () const
 Returns the desired active attribute. More...
 

Static Public Member Functions

static VtkSurfacesSourceNew ()
 Create new objects with New() because of VTKs object reference counting. More...
 

Protected Member Functions

 VtkSurfacesSource ()
 
 ~VtkSurfacesSource () override=default
 
int RequestData (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
 Computes the polygonal data object. More...
 
int RequestInformation (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
 

Protected Attributes

const std::vector< GeoLib::Surface * > * _surfaces {nullptr}
 The surfaces to visualize. More...
 
- Protected Attributes inherited from VtkAlgorithmProperties
vtkProperty * _property
 
vtkTexture * _texture
 
bool _scalarVisibility
 
std::map< QString, vtkLookupTable * > _lut
 
QString _name
 
QString _activeAttributeName
 
bool _removable
 
QMap< QString, QVariant > * _algorithmUserProperties
 
QMap< QString, QList< QVariant > > * _algorithmUserVectorProperties
 

Additional Inherited Members

- Signals inherited from VtkAlgorithmProperties
void ScalarVisibilityChanged (bool on)
 

Constructor & Destructor Documentation

◆ VtkSurfacesSource()

VtkSurfacesSource::VtkSurfacesSource ( )
protected

Definition at line 36 of file VtkSurfacesSource.cpp.

37 {
38  _removable = false; // From VtkAlgorithmProperties
39  this->SetNumberOfInputPorts(0);
40  // this->SetColorBySurface(true);
41 
43  vtkProperty* vtkProps = GetProperties();
44  vtkProps->SetColor(c[0] / 255.0, c[1] / 255.0, c[2] / 255.0);
45  vtkProps->SetEdgeVisibility(0);
46 }
vtkProperty * GetProperties() const
Returns the vtk properties.
std::array< unsigned char, 4 > Color
Definition: Color.h:24
Color getRandomColor()
Returns a random RGB colour.
Definition: Color.cpp:29

References VtkAlgorithmProperties::_removable, MaterialPropertyLib::c, VtkAlgorithmProperties::GetProperties(), and DataHolderLib::getRandomColor().

◆ ~VtkSurfacesSource()

VtkSurfacesSource::~VtkSurfacesSource ( )
overrideprotecteddefault

Member Function Documentation

◆ New()

static VtkSurfacesSource* VtkSurfacesSource::New ( )
static

Create new objects with New() because of VTKs object reference counting.

◆ PrintSelf()

void VtkSurfacesSource::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
override

Prints its data on a stream.

Definition at line 48 of file VtkSurfacesSource.cpp.

49 {
50  this->Superclass::PrintSelf(os, indent);
51 
52  if (_surfaces->empty())
53  {
54  return;
55  }
56 
57  os << indent << "== VtkSurfacesSource =="
58  << "\n";
59 }
const std::vector< GeoLib::Surface * > * _surfaces
The surfaces to visualize.

References _surfaces.

◆ RequestData()

int VtkSurfacesSource::RequestData ( vtkInformation *  request,
vtkInformationVector **  inputVector,
vtkInformationVector *  outputVector 
)
overrideprotected

Computes the polygonal data object.

Definition at line 61 of file VtkSurfacesSource.cpp.

64 {
65  (void)request;
66  (void)inputVector;
67 
68  const int nSurfaces = _surfaces->size();
69  if (nSurfaces == 0)
70  {
71  return 0;
72  }
73 
74  const std::vector<GeoLib::Point*>* surfacePoints =
75  (*_surfaces)[0]->getPointVec();
76  std::size_t nPoints = surfacePoints->size();
77 
78  vtkSmartPointer<vtkInformation> outInfo =
79  outputVector->GetInformationObject(0);
80  vtkSmartPointer<vtkPolyData> output =
81  vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
82  if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) >
83  0)
84  {
85  return 1;
86  }
87 
88  vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
89  newPoints->SetNumberOfPoints(nPoints);
90 
91  vtkSmartPointer<vtkCellArray> newPolygons =
92  vtkSmartPointer<vtkCellArray>::New();
93  // newPolygons->Allocate(nSurfaces);
94 
95  vtkSmartPointer<vtkIntArray> sfcIDs = vtkSmartPointer<vtkIntArray>::New();
96  sfcIDs->SetNumberOfComponents(1);
97  sfcIDs->SetName("SurfaceIDs");
98 
99  for (std::size_t i = 0; i < nPoints; ++i)
100  {
101  const double* coords =
102  const_cast<double*>((*surfacePoints)[i]->getCoords());
103  newPoints->SetPoint(i, coords);
104  }
105 
106  int count(0);
107  for (auto surface : *_surfaces)
108  {
109  const std::size_t nTriangles = surface->getNumberOfTriangles();
110 
111  for (std::size_t i = 0; i < nTriangles; ++i)
112  {
113  vtkTriangle* new_tri = vtkTriangle::New();
114  new_tri->GetPointIds()->SetNumberOfIds(3);
115 
116  const GeoLib::Triangle* triangle = (*surface)[i];
117  for (std::size_t j = 0; j < 3; ++j)
118  {
119  new_tri->GetPointIds()->SetId(j, ((*triangle)[j]));
120  }
121  newPolygons->InsertNextCell(new_tri);
122  sfcIDs->InsertNextValue(count);
123  new_tri->Delete();
124  }
125  count++;
126  }
127 
128  output->SetPoints(newPoints);
129  output->SetPolys(newPolygons);
130  output->GetCellData()->AddArray(sfcIDs);
131  output->GetCellData()->SetActiveAttribute("SurfaceIDs",
132  vtkDataSetAttributes::SCALARS);
133  output->Squeeze();
134 
135  return 1;
136 }
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition: Triangle.h:26

References _surfaces.

◆ RequestInformation()

int VtkSurfacesSource::RequestInformation ( vtkInformation *  request,
vtkInformationVector **  inputVector,
vtkInformationVector *  outputVector 
)
overrideprotected

Definition at line 138 of file VtkSurfacesSource.cpp.

142 {
143  return 1;
144 }

◆ setSurfaces()

void VtkSurfacesSource::setSurfaces ( const std::vector< GeoLib::Surface * > *  surfaces)
inline

Sets the surfaces vector.

Definition at line 36 of file VtkSurfacesSource.h.

36 { _surfaces = surfaces; }

References _surfaces.

◆ SetUserProperty()

void VtkSurfacesSource::SetUserProperty ( QString  name,
QVariant  value 
)
overridevirtual

Generates random colors for each surface.

Reimplemented from VtkAlgorithmProperties.

Definition at line 146 of file VtkSurfacesSource.cpp.

147 {
149  (*_algorithmUserProperties)[name] = value;
150 }
virtual void SetUserProperty(QString name, QVariant value)
Sets a user property. This should be implemented by subclasses.

References MaterialPropertyLib::name, and VtkAlgorithmProperties::SetUserProperty().

◆ vtkTypeMacro()

VtkSurfacesSource::vtkTypeMacro ( VtkSurfacesSource  ,
vtkPolyDataAlgorithm   
)

Member Data Documentation

◆ _surfaces

const std::vector<GeoLib::Surface*>* VtkSurfacesSource::_surfaces {nullptr}
protected

The surfaces to visualize.

Definition at line 62 of file VtkSurfacesSource.h.

Referenced by PrintSelf(), RequestData(), and setSurfaces().


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