diff --git a/VtkVis/VtkMeshSource.cpp b/VtkVis/VtkMeshSource.cpp index 9f6a3756da25514b4de5afa1b208916e4b94f855..0c1237ef5fc5392ca24b31a7a974ef0f302bf4d9 100644 --- a/VtkVis/VtkMeshSource.cpp +++ b/VtkVis/VtkMeshSource.cpp @@ -32,7 +32,7 @@ vtkStandardNewMacro(VtkMeshSource); vtkCxxRevisionMacro(VtkMeshSource, "$Revision$"); -VtkMeshSource::VtkMeshSource() : _matName("MatIDs") +VtkMeshSource::VtkMeshSource() : _matName("MaterialIDs") { this->SetNumberOfInputPorts(0); diff --git a/VtkVis/VtkSurfacesSource.cpp b/VtkVis/VtkSurfacesSource.cpp index 3342032963da07c5ee7ae1fc19bce6853a86d9a9..4b749112ecc8b1b510fe91c8e4c6e41dad371310 100644 --- a/VtkVis/VtkSurfacesSource.cpp +++ b/VtkVis/VtkSurfacesSource.cpp @@ -65,9 +65,9 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto vtkSmartPointer<vtkCellArray> newPolygons = vtkSmartPointer<vtkCellArray>::New(); //newPolygons->Allocate(nSurfaces); - vtkSmartPointer<vtkUnsignedCharArray> sfcColors = vtkSmartPointer<vtkUnsignedCharArray>::New(); - sfcColors->SetNumberOfComponents(3); - sfcColors->SetName("Colors"); + vtkSmartPointer<vtkIntArray> sfcIDs = vtkSmartPointer<vtkIntArray>::New(); + sfcIDs->SetNumberOfComponents(1); + sfcIDs->SetName("SurfaceIDs"); for (size_t i=0; i<nPoints; i++) { @@ -75,13 +75,10 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto newPoints->InsertNextPoint(coords); } + vtkIdType count(0); for (std::vector<GEOLIB::Surface*>::const_iterator it = _surfaces->begin(); 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(); for (size_t i = 0; i < nTriangles; i++) @@ -95,19 +92,17 @@ int VtkSurfacesSource::RequestData( vtkInformation* request, vtkInformationVecto aPolygon->GetPointIds()->SetId(j, ((*triangle)[j])); } newPolygons->InsertNextCell(aPolygon); - sfcColors->InsertNextTupleValue(sColor); + sfcIDs->InsertNextValue(count); aPolygon->Delete(); } + count++; } output->SetPoints(newPoints); output->SetPolys(newPolygons); - output->GetCellData()->AddArray(sfcColors); - output->GetCellData()->SetActiveAttribute("Colors", vtkDataSetAttributes::SCALARS); - - //const GEOLIB::Color* c = GEOLIB::getRandomColor(); - //this->GetProperties()->SetColor((*c)[0]/255.0,(*c)[1]/255.0,(*c)[2]/255.0); + output->GetCellData()->AddArray(sfcIDs); + output->GetCellData()->SetActiveAttribute("SurfaceIDs", vtkDataSetAttributes::SCALARS); return 1; } @@ -134,7 +129,6 @@ void VtkSurfacesSource::SetUserProperty( QString name, QVariant value ) this->SetScalarVisibility(value.toBool()); } - (*_algorithmUserProperties)[name] = value; } diff --git a/VtkVis/VtkVisPipeline.cpp b/VtkVis/VtkVisPipeline.cpp index de4ea5da78641b87241c7931520eb731cb05f3fb..909b89884c990c6975683bce65185f8692fdb3a6 100644 --- a/VtkVis/VtkVisPipeline.cpp +++ b/VtkVis/VtkVisPipeline.cpp @@ -197,6 +197,8 @@ void VtkVisPipeline::loadFromFile(QString filename) for (int i = 0; i < cellData->GetNumberOfArrays(); i++) std::cout << " Name: " << cellData->GetArrayName(i) << std::endl; + //dataSet->GetPointData()->SetActiveScalars(dataSet->GetPointData()->GetArrayName(2)); + addPipelineItem(oldStyleReader); } else diff --git a/VtkVis/VtkVisPipelineItem.cpp b/VtkVis/VtkVisPipelineItem.cpp index b8d6328a4efaa6cea39cb4786b6f33b03315d988..7c17c7cb6f50c87465c01ccb7b367ff18534be81 100644 --- a/VtkVis/VtkVisPipelineItem.cpp +++ b/VtkVis/VtkVisPipelineItem.cpp @@ -43,12 +43,9 @@ #include "VtkCompositeFilter.h" -#include "VtkMeshSource.h" - #include <vtkPointData.h> #include <vtkCellData.h> - #ifdef OGS_USE_OPENSG OSG::NodePtr VtkVisPipelineItem::rootNode = NullFC; @@ -269,7 +266,7 @@ void VtkVisPipelineItem::setVtkProperties(VtkAlgorithmProperties* vtkProps) QObject::connect(vtkProps, SIGNAL(ScalarVisibilityChanged(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); if (mapper) @@ -375,31 +372,47 @@ void VtkVisPipelineItem::SetScalarVisibility( bool 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)); - 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(); - pointData->SetActiveAttribute(charName, attributeType); - //pointData->SetActiveScalars(charName); - _mapper->SetScalarModeToUsePointData(); - _mapper->SetScalarRange(dataSet->GetScalarRange()); - } - else + onPointData = false; + arrayIndex-=nPointArrays; + } + + if (dataSet) { - vtkCellData* cellData = dataSet->GetCellData(); - cellData->SetActiveAttribute(charName, attributeType); - //cellData->SetActiveScalars(charName); - _mapper->SetScalarModeToUseCellData(); - _mapper->SetScalarRange(dataSet->GetScalarRange()); + if (onPointData) + { + vtkPointData* pointData = dataSet->GetPointData(); + const char* charName = pointData->GetArrayName(arrayIndex); + 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(); } - } diff --git a/VtkVis/VtkVisPipelineItem.h b/VtkVis/VtkVisPipelineItem.h index b0a44e0f32659c019646e3a2655a6bbd26d9a608..2973f6bd619e785e428b26f52aaacc024b318a6d 100644 --- a/VtkVis/VtkVisPipelineItem.h +++ b/VtkVis/VtkVisPipelineItem.h @@ -85,9 +85,8 @@ public: vtkTransformFilter* transformFilter() const { return _transformFilter; } - void SetActiveAttribute(const QString& name, - int attributeType = 0, // vtkDataSetAttributes::SCALARS, - bool onPointData = true); + /// @brief Sets the selected attribute array for the visualisation of the data set. + void SetActiveAttribute(int arrayIndex, int attributeType = 0 /*vtkDataSetAttributes::SCALARS*/); #ifdef OGS_USE_OPENSG // HACK static rootNode is set by VtkVisPipeline constructor diff --git a/VtkVis/VtkVisTabWidget.cpp b/VtkVis/VtkVisTabWidget.cpp index acca81af615c8277e59b72b2538ca04b43492703..8c25be827f8211a3cb490c6b46571842b171f59e 100644 --- a/VtkVis/VtkVisTabWidget.cpp +++ b/VtkVis/VtkVisTabWidget.cpp @@ -36,8 +36,8 @@ VtkVisTabWidget::VtkVisTabWidget( QWidget* parent /*= 0*/ ) connect(this->vtkVisPipelineView, SIGNAL(itemSelected(VtkVisPipelineItem*)), this, SLOT(setActiveItem(VtkVisPipelineItem*))); - connect(this->activeScalarComboBox, SIGNAL(currentIndexChanged(const QString&)), - this, SLOT(SetActiveAttributeOnItem(const QString&))); + connect(this->activeScalarComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(SetActiveAttributeOnItem(int))); } @@ -71,7 +71,7 @@ void VtkVisTabWidget::setActiveItem( VtkVisPipelineItem* item ) for (int i = 0; i < pointData->GetNumberOfArrays(); i++) { std::cout << " Name: " << pointData->GetArrayName(i) << std::endl; - //dataSetAttributesList.push_back(pointData->GetArrayName(i)); + dataSetAttributesList.push_back(pointData->GetArrayName(i)); } vtkCellData* cellData = dataSet->GetCellData(); @@ -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(); } diff --git a/VtkVis/VtkVisTabWidget.h b/VtkVis/VtkVisTabWidget.h index 8bc8b9b3163f3bc9ddd7f1564a6508d628dce8ed..4d08d4ec40da34cef9bf523135800244fcef0623 100644 --- a/VtkVis/VtkVisTabWidget.h +++ b/VtkVis/VtkVisTabWidget.h @@ -33,7 +33,7 @@ protected slots: void on_opacitySlider_sliderMoved(int value); void on_scaleZ_textChanged(const QString &text); - void SetActiveAttributeOnItem(const QString& attributeName); + void SetActiveAttributeOnItem(int idx); private: void addColorTable();