Skip to content
Snippets Groups Projects
Commit f827ad7e authored by Lars Bilke's avatar Lars Bilke
Browse files

any scalar fields of vtk files are now displayed correctly.

git-svn-id: https://svn.ufz.de/svn/ogs/trunk/sources@7913 3895a583-e809-0410-9bb6-aa9463026377
parent 34a9b49a
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
vtkStandardNewMacro(VtkMeshSource); vtkStandardNewMacro(VtkMeshSource);
vtkCxxRevisionMacro(VtkMeshSource, "$Revision$"); vtkCxxRevisionMacro(VtkMeshSource, "$Revision$");
VtkMeshSource::VtkMeshSource() : _matName("MatIDs") VtkMeshSource::VtkMeshSource() : _matName("MaterialIDs")
{ {
this->SetNumberOfInputPorts(0); this->SetNumberOfInputPorts(0);
......
...@@ -65,9 +65,9 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto ...@@ -65,9 +65,9 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto
vtkSmartPointer<vtkCellArray> newPolygons = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkCellArray> newPolygons = vtkSmartPointer<vtkCellArray>::New();
//newPolygons->Allocate(nSurfaces); //newPolygons->Allocate(nSurfaces);
vtkSmartPointer<vtkUnsignedCharArray> sfcColors = vtkSmartPointer<vtkUnsignedCharArray>::New(); vtkSmartPointer<vtkIntArray> sfcIDs = vtkSmartPointer<vtkIntArray>::New();
sfcColors->SetNumberOfComponents(3); sfcIDs->SetNumberOfComponents(1);
sfcColors->SetName("Colors"); sfcIDs->SetName("SurfaceIDs");
for (size_t i=0; i<nPoints; i++) for (size_t i=0; i<nPoints; i++)
{ {
...@@ -75,13 +75,10 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto ...@@ -75,13 +75,10 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto
newPoints->InsertNextPoint(coords); newPoints->InsertNextPoint(coords);
} }
vtkIdType count(0);
for (std::vector<GEOLIB::Surface*>::const_iterator it = _surfaces->begin(); for (std::vector<GEOLIB::Surface*>::const_iterator it = _surfaces->begin();
it != _surfaces->end(); ++it) it != _surfaces->end(); ++it)
{ {
//const GEOLIB::Color *c (GEOLIB::getColor(/*getNameOfSurface*/, _colorLookupTable));
const GEOLIB::Color *c = GEOLIB::getRandomColor();
unsigned char sColor[3] = { (*c)[0], (*c)[1], (*c)[2] };
const size_t nTriangles = (*it)->getNTriangles(); const size_t nTriangles = (*it)->getNTriangles();
for (size_t i = 0; i < nTriangles; i++) for (size_t i = 0; i < nTriangles; i++)
...@@ -95,19 +92,17 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto ...@@ -95,19 +92,17 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto
aPolygon->GetPointIds()->SetId(j, ((*triangle)[j])); aPolygon->GetPointIds()->SetId(j, ((*triangle)[j]));
} }
newPolygons->InsertNextCell(aPolygon); newPolygons->InsertNextCell(aPolygon);
sfcColors->InsertNextTupleValue(sColor); sfcIDs->InsertNextValue(count);
aPolygon->Delete(); aPolygon->Delete();
} }
count++;
} }
output->SetPoints(newPoints); output->SetPoints(newPoints);
output->SetPolys(newPolygons); output->SetPolys(newPolygons);
output->GetCellData()->AddArray(sfcColors); output->GetCellData()->AddArray(sfcIDs);
output->GetCellData()->SetActiveAttribute("Colors", vtkDataSetAttributes::SCALARS); output->GetCellData()->SetActiveAttribute("SurfaceIDs", vtkDataSetAttributes::SCALARS);
//const GEOLIB::Color* c = GEOLIB::getRandomColor();
//this->GetProperties()->SetColor((*c)[0]/255.0,(*c)[1]/255.0,(*c)[2]/255.0);
return 1; return 1;
} }
...@@ -134,7 +129,6 @@ void VtkSurfacesSource::SetUserProperty( QString name, QVariant value ) ...@@ -134,7 +129,6 @@ void VtkSurfacesSource::SetUserProperty( QString name, QVariant value )
this->SetScalarVisibility(value.toBool()); this->SetScalarVisibility(value.toBool());
} }
(*_algorithmUserProperties)[name] = value; (*_algorithmUserProperties)[name] = value;
} }
...@@ -197,6 +197,8 @@ void VtkVisPipeline::loadFromFile(QString filename) ...@@ -197,6 +197,8 @@ void VtkVisPipeline::loadFromFile(QString filename)
for (int i = 0; i < cellData->GetNumberOfArrays(); i++) for (int i = 0; i < cellData->GetNumberOfArrays(); i++)
std::cout << " Name: " << cellData->GetArrayName(i) << std::endl; std::cout << " Name: " << cellData->GetArrayName(i) << std::endl;
//dataSet->GetPointData()->SetActiveScalars(dataSet->GetPointData()->GetArrayName(2));
addPipelineItem(oldStyleReader); addPipelineItem(oldStyleReader);
} }
else else
......
...@@ -43,12 +43,9 @@ ...@@ -43,12 +43,9 @@
#include "VtkCompositeFilter.h" #include "VtkCompositeFilter.h"
#include "VtkMeshSource.h"
#include <vtkPointData.h> #include <vtkPointData.h>
#include <vtkCellData.h> #include <vtkCellData.h>
#ifdef OGS_USE_OPENSG #ifdef OGS_USE_OPENSG
OSG::NodePtr VtkVisPipelineItem::rootNode = NullFC; OSG::NodePtr VtkVisPipelineItem::rootNode = NullFC;
...@@ -269,7 +266,7 @@ void VtkVisPipelineItem::setVtkProperties(VtkAlgorithmProperties* vtkProps) ...@@ -269,7 +266,7 @@ void VtkVisPipelineItem::setVtkProperties(VtkAlgorithmProperties* vtkProps)
QObject::connect(vtkProps, SIGNAL(ScalarVisibilityChanged(bool)), QObject::connect(vtkProps, SIGNAL(ScalarVisibilityChanged(bool)),
_mapper, SLOT(SetScalarVisibility(bool))); _mapper, SLOT(SetScalarVisibility(bool)));
//vtkProps->SetLookUpTable("c:/Project/BoreholeColourReferenceMesh.txt"); //HACK ... needs to be put in GUI vtkProps->SetLookUpTable("c:/Project/BoreholeColourReferenceMesh.txt"); //HACK ... needs to be put in GUI
QVtkDataSetMapper* mapper = dynamic_cast<QVtkDataSetMapper*>(_mapper); QVtkDataSetMapper* mapper = dynamic_cast<QVtkDataSetMapper*>(_mapper);
if (mapper) if (mapper)
...@@ -375,31 +372,47 @@ void VtkVisPipelineItem::SetScalarVisibility( bool on ) ...@@ -375,31 +372,47 @@ void VtkVisPipelineItem::SetScalarVisibility( bool on )
_mapper->SetScalarVisibility(on); _mapper->SetScalarVisibility(on);
} }
void VtkVisPipelineItem::SetActiveAttribute( const QString& name, int attributeType, bool onPointData ) void VtkVisPipelineItem::SetActiveAttribute( int arrayIndex, int attributeType )
{ {
std::string stdString = name.toStdString();
const char* charName = stdString.c_str();
vtkDataSet* dataSet = vtkDataSet::SafeDownCast(this->_algorithm->GetOutputDataObject(0)); vtkDataSet* dataSet = vtkDataSet::SafeDownCast(this->_algorithm->GetOutputDataObject(0));
if (dataSet) bool onPointData(true);
double* range(NULL);
int nPointArrays = dataSet->GetPointData()->GetNumberOfArrays();
int nCellArrays = dataSet->GetCellData()->GetNumberOfArrays();
if (nPointArrays+nCellArrays > 0)
{ {
if (onPointData) if ( arrayIndex > nPointArrays-1 )
{ {
vtkPointData* pointData = dataSet->GetPointData(); onPointData = false;
pointData->SetActiveAttribute(charName, attributeType); arrayIndex-=nPointArrays;
//pointData->SetActiveScalars(charName); }
_mapper->SetScalarModeToUsePointData();
_mapper->SetScalarRange(dataSet->GetScalarRange()); if (dataSet)
}
else
{ {
vtkCellData* cellData = dataSet->GetCellData(); if (onPointData)
cellData->SetActiveAttribute(charName, attributeType); {
//cellData->SetActiveScalars(charName); vtkPointData* pointData = dataSet->GetPointData();
_mapper->SetScalarModeToUseCellData(); const char* charName = pointData->GetArrayName(arrayIndex);
_mapper->SetScalarRange(dataSet->GetScalarRange()); pointData->SetActiveAttribute(charName, attributeType);
range = pointData->GetArray(charName)->GetRange();
_mapper->SetScalarModeToUsePointData();
_mapper->SetScalarRange(dataSet->GetScalarRange());
}
else
{
vtkCellData* cellData = dataSet->GetCellData();
const char* charName = cellData->GetArrayName(arrayIndex);
cellData->SetActiveAttribute(charName, attributeType);
range = cellData->GetArray(charName)->GetRange();
_mapper->SetScalarModeToUseCellData();
_mapper->SetScalarRange(dataSet->GetScalarRange());
}
_mapper->SetScalarRange(range);
_mapper->ScalarVisibilityOn();
_mapper->Update();
} }
_mapper->ScalarVisibilityOn();
_mapper->Update();
} }
} }
...@@ -85,9 +85,8 @@ public: ...@@ -85,9 +85,8 @@ public:
vtkTransformFilter* transformFilter() const { return _transformFilter; } vtkTransformFilter* transformFilter() const { return _transformFilter; }
void SetActiveAttribute(const QString& name, /// @brief Sets the selected attribute array for the visualisation of the data set.
int attributeType = 0, // vtkDataSetAttributes::SCALARS, void SetActiveAttribute(int arrayIndex, int attributeType = 0 /*vtkDataSetAttributes::SCALARS*/);
bool onPointData = true);
#ifdef OGS_USE_OPENSG #ifdef OGS_USE_OPENSG
// HACK static rootNode is set by VtkVisPipeline constructor // HACK static rootNode is set by VtkVisPipeline constructor
......
...@@ -36,8 +36,8 @@ VtkVisTabWidget::VtkVisTabWidget( QWidget* parent /*= 0*/ ) ...@@ -36,8 +36,8 @@ VtkVisTabWidget::VtkVisTabWidget( QWidget* parent /*= 0*/ )
connect(this->vtkVisPipelineView, SIGNAL(itemSelected(VtkVisPipelineItem*)), connect(this->vtkVisPipelineView, SIGNAL(itemSelected(VtkVisPipelineItem*)),
this, SLOT(setActiveItem(VtkVisPipelineItem*))); this, SLOT(setActiveItem(VtkVisPipelineItem*)));
connect(this->activeScalarComboBox, SIGNAL(currentIndexChanged(const QString&)), connect(this->activeScalarComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(SetActiveAttributeOnItem(const QString&))); this, SLOT(SetActiveAttributeOnItem(int)));
} }
...@@ -71,7 +71,7 @@ void VtkVisTabWidget::setActiveItem( VtkVisPipelineItem* item ) ...@@ -71,7 +71,7 @@ void VtkVisTabWidget::setActiveItem( VtkVisPipelineItem* item )
for (int i = 0; i < pointData->GetNumberOfArrays(); i++) for (int i = 0; i < pointData->GetNumberOfArrays(); i++)
{ {
std::cout << " Name: " << pointData->GetArrayName(i) << std::endl; std::cout << " Name: " << pointData->GetArrayName(i) << std::endl;
//dataSetAttributesList.push_back(pointData->GetArrayName(i)); dataSetAttributesList.push_back(pointData->GetArrayName(i));
} }
vtkCellData* cellData = dataSet->GetCellData(); vtkCellData* cellData = dataSet->GetCellData();
...@@ -272,8 +272,8 @@ void VtkVisTabWidget::addColorTable() ...@@ -272,8 +272,8 @@ void VtkVisTabWidget::addColorTable()
} }
void VtkVisTabWidget::SetActiveAttributeOnItem( const QString& attributeName ) void VtkVisTabWidget::SetActiveAttributeOnItem( int idx )
{ {
_item->SetActiveAttribute(attributeName, 0, false); _item->SetActiveAttribute(idx, 0);
emit requestViewUpdate(); emit requestViewUpdate();
} }
...@@ -33,7 +33,7 @@ protected slots: ...@@ -33,7 +33,7 @@ protected slots:
void on_opacitySlider_sliderMoved(int value); void on_opacitySlider_sliderMoved(int value);
void on_scaleZ_textChanged(const QString &text); void on_scaleZ_textChanged(const QString &text);
void SetActiveAttributeOnItem(const QString& attributeName); void SetActiveAttributeOnItem(int idx);
private: private:
void addColorTable(); void addColorTable();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment