OGS
VtkStationSource Class Reference

Detailed Description

VTK source object for the visualisation of station data (including boreholes)

Definition at line 27 of file VtkStationSource.h.

#include <VtkStationSource.h>

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

Public Member Functions

 vtkTypeMacro (VtkStationSource, vtkPolyDataAlgorithm)
 
const std::map< std::string, DataHolderLib::Color > & getColorLookupTable () const
 
void setStations (const std::vector< GeoLib::Point * > *stations)
 Sets a predefined color lookup table for the colouring of borehole stratigraphies. More...
 
void PrintSelf (ostream &os, vtkIndent indent) override
 Prints its data on a stream. More...
 
void SetUserProperty (QString name, QVariant value) override
 Sets a user property. This should be implemented by subclasses. 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 VtkStationSourceNew ()
 Create new objects with New() because of VTKs object reference counting. More...
 

Protected Member Functions

 VtkStationSource ()
 
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::Point * > * _stations {nullptr}
 The stations to visualize. More...
 
std::map< std::string, DataHolderLib::Color_colorLookupTable
 
- 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
 

Private Member Functions

std::size_t GetIndexByName (std::string const &name)
 

Private Attributes

std::map< std::string, vtkIdType > _id_map
 

Additional Inherited Members

- Signals inherited from VtkAlgorithmProperties
void ScalarVisibilityChanged (bool on)
 

Constructor & Destructor Documentation

◆ VtkStationSource()

VtkStationSource::VtkStationSource ( )
protected

Definition at line 37 of file VtkStationSource.cpp.

38 {
39  _removable = false; // From VtkAlgorithmProperties
40  this->SetNumberOfInputPorts(0);
41 
43  GetProperties()->SetColor(c[0] / 255.0, c[1] / 255.0, c[2] / 255.0);
44 }
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().

Member Function Documentation

◆ getColorLookupTable()

const std::map<std::string, DataHolderLib::Color>& VtkStationSource::getColorLookupTable ( ) const
inline

Returns the colour lookup table generated for boreholes. This method should only be called after the colour lookup table has actually been build (via RequestData() or setColorLookupTable()).

Definition at line 37 of file VtkStationSource.h.

38  { return _colorLookupTable; }
std::map< std::string, DataHolderLib::Color > _colorLookupTable

References _colorLookupTable.

Referenced by StationTreeView::displayStratigraphy(), and StationTreeView::writeStratigraphiesAsImages().

◆ GetIndexByName()

std::size_t VtkStationSource::GetIndexByName ( std::string const &  name)
private

Definition at line 229 of file VtkStationSource.cpp.

230 {
231  vtkIdType max_key(0);
232  for (auto& it : _id_map)
233  {
234  if (name == it.first)
235  {
236  return it.second;
237  }
238  if (it.second > max_key)
239  {
240  max_key = it.second;
241  }
242  }
243 
244  vtkIdType new_index = (_id_map.empty()) ? 0 : (max_key + 1);
245  INFO("Key '{:s}' has been assigned index {:d}.", name, new_index);
246  _id_map.insert(std::pair<std::string, vtkIdType>(name, new_index));
247  return new_index;
248 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
std::map< std::string, vtkIdType > _id_map

References _id_map, INFO(), and MaterialPropertyLib::name.

Referenced by RequestData().

◆ New()

static VtkStationSource* VtkStationSource::New ( )
static

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

◆ PrintSelf()

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

Prints its data on a stream.

Definition at line 46 of file VtkStationSource.cpp.

47 {
48  this->Superclass::PrintSelf(os, indent);
49 
50  if (_stations->empty())
51  {
52  return;
53  }
54 
55  os << indent << "== VtkStationSource =="
56  << "\n";
57 
58  int i = 0;
59  for (auto station : *_stations)
60  {
61  os << indent << "Station " << i << " (" << (*station)[0] << ", "
62  << (*station)[1] << ", " << (*station)[2] << ")\n";
63  i++;
64  }
65 }
const std::vector< GeoLib::Point * > * _stations
The stations to visualize.

References _stations.

◆ RequestData()

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

Computes the polygonal data object.

Create 3d Station objects.

Definition at line 68 of file VtkStationSource.cpp.

71 {
72  (void)request;
73  (void)inputVector;
74 
75  if (!_stations)
76  {
77  return 0;
78  }
79  std::size_t nStations = _stations->size();
80  if (nStations == 0)
81  {
82  return 0;
83  }
84 
85  bool useStationValues(false);
86  double sValue =
87  static_cast<GeoLib::Station*>((*_stations)[0])->getStationValue();
88  for (std::size_t i = 1; i < nStations; i++)
89  {
90  if (static_cast<GeoLib::Station*>((*_stations)[i])->getStationValue() !=
91  sValue)
92  {
93  useStationValues = true;
94  break;
95  }
96  }
97 
98  bool isBorehole = dynamic_cast<GeoLib::StationBorehole*>((*_stations)[0]);
99 
100  vtkSmartPointer<vtkInformation> outInfo =
101  outputVector->GetInformationObject(0);
102  vtkSmartPointer<vtkPolyData> output =
103  vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
104 
105  vtkSmartPointer<vtkPoints> newStations = vtkSmartPointer<vtkPoints>::New();
106  vtkSmartPointer<vtkCellArray> newVerts =
107  vtkSmartPointer<vtkCellArray>::New();
108  newVerts->Allocate(nStations);
109 
110  vtkSmartPointer<vtkCellArray> newLines;
111 
112  if (isBorehole)
113  {
114  newLines = vtkSmartPointer<vtkCellArray>::New();
115  }
116 
117  if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) >
118  0)
119  {
120  return 1;
121  }
122 
123  vtkSmartPointer<vtkIntArray> station_ids =
124  vtkSmartPointer<vtkIntArray>::New();
125  station_ids->SetNumberOfComponents(1);
126  station_ids->SetName("SiteIDs");
127 
128  vtkSmartPointer<vtkDoubleArray> station_values =
129  vtkSmartPointer<vtkDoubleArray>::New();
130  station_values->SetNumberOfComponents(1);
131  station_values->SetName("StationValue");
132 
133  vtkSmartPointer<vtkIntArray> strat_ids =
134  vtkSmartPointer<vtkIntArray>::New();
135  strat_ids->SetNumberOfComponents(1);
136  strat_ids->SetName("Stratigraphies");
137 
138  std::size_t lastMaxIndex(0);
139  std::size_t site_count(0);
140 
141  // Generate graphic objects
142  for (auto station : *_stations)
143  {
144  double coords[3] = {(*station)[0], (*station)[1], (*station)[2]};
145  vtkIdType sid = newStations->InsertNextPoint(coords);
146  station_ids->InsertNextValue(site_count);
147  if (useStationValues)
148  {
149  station_values->InsertNextValue(
150  static_cast<GeoLib::Station*>(station)->getStationValue());
151  }
152 
153  if (!isBorehole)
154  {
155  newVerts->InsertNextCell(1, &sid);
156  }
157  else
158  {
159  std::vector<GeoLib::Point*> profile =
160  static_cast<GeoLib::StationBorehole*>(station)->getProfile();
161  std::vector<std::string> soilNames =
162  static_cast<GeoLib::StationBorehole*>(station)->getSoilNames();
163  const std::size_t nLayers = profile.size();
164 
165  for (std::size_t i = 1; i < nLayers; i++)
166  {
167  auto* pCoords = const_cast<double*>(profile[i]->getCoords());
168  double loc[3] = {pCoords[0], pCoords[1], pCoords[2]};
169  newStations->InsertNextPoint(loc);
170  station_ids->InsertNextValue(site_count);
171  newLines->InsertNextCell(2);
172  newLines->InsertCellPoint(
173  lastMaxIndex); // start of borehole-layer
174  newLines->InsertCellPoint(
175  ++lastMaxIndex); // end of boreholelayer
176  strat_ids->InsertNextValue(this->GetIndexByName(soilNames[i]));
177  if (useStationValues)
178  {
179  station_values->InsertNextValue(
180  static_cast<GeoLib::Station*>(station)
181  ->getStationValue());
182  }
183  }
184  lastMaxIndex++;
185  }
186  site_count++;
187  }
188 
189  output->SetPoints(newStations);
190 
191  if (!isBorehole)
192  {
193  output->SetVerts(newVerts);
194  output->GetCellData()->AddArray(station_ids);
195  output->GetCellData()->SetActiveAttribute(
196  "SiteIDs", vtkDataSetAttributes::SCALARS);
197  }
198  else
199  {
200  output->SetLines(newLines);
201  // output->GetCellData()->AddArray(station_ids);
202  output->GetCellData()->AddArray(strat_ids);
203  output->GetCellData()->SetActiveAttribute(
204  "Stratigraphies", vtkDataSetAttributes::SCALARS);
205  }
206  if (useStationValues)
207  {
208  output->GetPointData()->AddArray(station_values);
209  }
210 
211  output->Squeeze();
212 
213  return 1;
214 }
A borehole as a geometric object.
A Station (observation site) is basically a Point with some additional information.
Definition: Station.h:37
double getStationValue() const
Returns the specific value for this station.
Definition: Station.h:71
std::size_t GetIndexByName(std::string const &name)
bool isBorehole(GeoLib::Point const *pnt)

References _stations, GetIndexByName(), GeoLib::Station::getStationValue(), and GeoLib::isBorehole().

◆ RequestInformation()

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

Definition at line 216 of file VtkStationSource.cpp.

219 {
220  return 1;
221 }

◆ setStations()

void VtkStationSource::setStations ( const std::vector< GeoLib::Point * > *  stations)
inline

Sets a predefined color lookup table for the colouring of borehole stratigraphies.

Sets the stations as a vector

Definition at line 45 of file VtkStationSource.h.

45 { _stations = stations; }

References _stations.

◆ SetUserProperty()

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

Sets a user property. This should be implemented by subclasses.

Reimplemented from VtkAlgorithmProperties.

Definition at line 223 of file VtkStationSource.cpp.

224 {
225  Q_UNUSED(name);
226  Q_UNUSED(value);
227 }

References MaterialPropertyLib::name.

◆ vtkTypeMacro()

VtkStationSource::vtkTypeMacro ( VtkStationSource  ,
vtkPolyDataAlgorithm   
)

Member Data Documentation

◆ _colorLookupTable

std::map<std::string, DataHolderLib::Color> VtkStationSource::_colorLookupTable
protected

The colour table for stratigraphic data. This table is either set using the setColorLookupTable() method or is generated automatically with random colours while creating the VtkStationSource-object.

Definition at line 69 of file VtkStationSource.h.

Referenced by getColorLookupTable().

◆ _id_map

std::map<std::string, vtkIdType> VtkStationSource::_id_map
private

Definition at line 74 of file VtkStationSource.h.

Referenced by GetIndexByName().

◆ _stations

const std::vector<GeoLib::Point*>* VtkStationSource::_stations {nullptr}
protected

The stations to visualize.

Definition at line 65 of file VtkStationSource.h.

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


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