From: vsr Date: Thu, 3 Nov 2011 09:56:46 +0000 (+0000) Subject: Fix compilation warnings (migrate to VTK 5.8) X-Git-Tag: V6_4_0b1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aaf61a41197d5305d8becf3c32e4764eafae41a8;p=modules%2Fvisu.git Fix compilation warnings (migrate to VTK 5.8) --- diff --git a/src/PIPELINE/VISU_XYPlotActor.cxx b/src/PIPELINE/VISU_XYPlotActor.cxx index 9c66379b..738780ab 100644 --- a/src/PIPELINE/VISU_XYPlotActor.cxx +++ b/src/PIPELINE/VISU_XYPlotActor.cxx @@ -600,12 +600,12 @@ int VISU_XYPlotActor::RenderOpaqueGeometry(vtkViewport *viewport) if (this->AxisLabelTextProperty && this->AxisLabelTextProperty->GetMTime() > this->BuildTime) { - if (this->XAxis->GetTitleTextProperty()) + if (this->XAxis->GetLabelTextProperty()) { this->XAxis->GetLabelTextProperty()->ShallowCopy( this->AxisLabelTextProperty); } - if (this->YAxis->GetTitleTextProperty()) + if (this->YAxis->GetLabelTextProperty()) { this->YAxis->GetLabelTextProperty()->ShallowCopy( this->AxisLabelTextProperty); @@ -1011,6 +1011,11 @@ void VISU_XYPlotActor::ComputeXRange(double range[2], double *lengths) (ds = this->InputList->GetNextDataSet(dsit)); dsNum++) { numPts = ds->GetNumberOfPoints(); + if (numPts == 0) + { + vtkErrorMacro(<<"No scalar data to plot!"); + continue; + } if ( this->XValues != VTK_XYPLOT_INDEX ) { @@ -1144,6 +1149,26 @@ void VISU_XYPlotActor::ComputeYRange(double range[2]) }//over all datasets } +//---------------------------------------------------------------------------- +static inline int VISU_XYPlotActorGetComponent(vtkFieldData* field, + vtkIdType tuple, int component, double* val) +{ + int array_comp; + int array_index = field->GetArrayContainingComponent(component, array_comp); + if (array_index < 0) + { + return 0; + } + vtkDataArray* da = field->GetArray(array_index); + if (!da) + { + // non-numeric array. + return 0; + } + *val = da->GetComponent(tuple, array_comp); + return 1; +} + //---------------------------------------------------------------------------- void VISU_XYPlotActor::ComputeDORange(double xrange[2], double yrange[2], double *lengths) @@ -1153,21 +1178,34 @@ void VISU_XYPlotActor::ComputeDORange(double xrange[2], double yrange[2], vtkFieldData *field; int doNum, numColumns; vtkIdType numTuples, numRows, num, ptId, maxNum; - double maxLength=0.0, x, y, xPrev = 0.0; + double maxLength=0.0; + double x = 0.0; + double y = 0.0; + double xPrev = 0.0; vtkDataArray *array; - + + // NOTE: FieldData can have non-numeric arrays. However, XY plot can only + // work on numeric arrays (or vtkDataArray subclasses). + xrange[0] = yrange[0] = VTK_DOUBLE_MAX; xrange[1] = yrange[1] = -VTK_DOUBLE_MAX; vtkCollectionSimpleIterator doit; for ( doNum=0, maxNum=0, this->DataObjectInputList->InitTraversal(doit); (dobj = this->DataObjectInputList->GetNextDataObject(doit)); doNum++) { + lengths[doNum] = 0.0; field = dobj->GetFieldData(); - numColumns = field->GetNumberOfComponents(); //number of "columns" + numColumns = field->GetNumberOfComponents(); //number of "columns" + // numColumns includes the components for non-numeric arrays as well. for (numRows = VTK_LARGE_ID, i=0; iGetNumberOfArrays(); i++) { array = field->GetArray(i); + if (!array) + { + // non-numeric array, skip. + continue; + } numTuples = array->GetNumberOfTuples(); if ( numTuples < numRows ) { @@ -1183,13 +1221,24 @@ void VISU_XYPlotActor::ComputeDORange(double xrange[2], double yrange[2], // gather the information to form a plot for ( ptId=0; ptId < num; ptId++ ) { + int status = 0; + if ( this->DataObjectPlotMode == VTK_XYPLOT_ROW ) { - x = field->GetComponent(this->XComponent->GetValue(doNum), ptId); + // x = field->GetComponent(this->XComponent->GetValue(doNum), ptId); + status = ::VISU_XYPlotActorGetComponent(field, + this->XComponent->GetValue(doNum), ptId, &x); } else //if ( this->DataObjectPlotMode == VTK_XYPLOT_COLUMN ) { - x = field->GetComponent(ptId, this->XComponent->GetValue(doNum)); + // x = field->GetComponent(ptId, this->XComponent->GetValue(doNum)); + status = ::VISU_XYPlotActorGetComponent(field, + ptId, this->XComponent->GetValue(doNum), &x); + } + if (!status) + { + // requested component falls in a non-numeric array, skip it. + continue; } if ( ptId == 0 ) { @@ -1244,13 +1293,24 @@ void VISU_XYPlotActor::ComputeDORange(double xrange[2], double yrange[2], // Get the y-values for ( ptId=0; ptId < num; ptId++ ) { + int status = 0; if ( this->DataObjectPlotMode == VTK_XYPLOT_ROW ) { - y = field->GetComponent(this->YComponent->GetValue(doNum), ptId); + //y = field->GetComponent(this->YComponent->GetValue(doNum), ptId); + status = ::VISU_XYPlotActorGetComponent(field, + this->YComponent->GetValue(doNum), ptId, &y); } else //if ( this->DataObjectPlotMode == VTK_XYPLOT_COLUMN ) { - y = field->GetComponent(ptId, this->YComponent->GetValue(doNum)); + //y = field->GetComponent(ptId, this->YComponent->GetValue(doNum)); + status = ::VISU_XYPlotActorGetComponent(field, + ptId, this->YComponent->GetValue(doNum), &y); + } + if (!status) + { + // requested component falls in non-numeric array. + // skip. + continue; } if ( y < yrange[0] ) { @@ -1526,9 +1586,15 @@ void VISU_XYPlotActor::CreatePlotData(int *pos, int *pos2Extern, double xRange[2 // determine the shape of the field field = dobj->GetFieldData(); numColumns = field->GetNumberOfComponents(); //number of "columns" + // numColumns also includes non-numeric array components. for (numRows = VTK_LARGE_ID, i=0; iGetNumberOfArrays(); i++) { array = field->GetArray(i); + if (!array) + { + // skip non-numeric arrays. + continue; + } numTuples = array->GetNumberOfTuples(); if ( numTuples < numRows ) { @@ -1546,15 +1612,42 @@ void VISU_XYPlotActor::CreatePlotData(int *pos, int *pos2Extern, double xRange[2 // gather the information to form a plot for ( numLinePts=0, length=0.0, ptId=0; ptId < numPts; ptId++ ) { + int status1, status2; if ( this->DataObjectPlotMode == VTK_XYPLOT_ROW ) { - x[0] = field->GetComponent(this->XComponent->GetValue(doNum),ptId); - xyz[1] = field->GetComponent(this->YComponent->GetValue(doNum),ptId); + //x[0] = field->GetComponent(this->XComponent->GetValue(doNum),ptId); + //xyz[1] = field->GetComponent(this->YComponent->GetValue(doNum),ptId); + status1 = ::VISU_XYPlotActorGetComponent(field, + this->XComponent->GetValue(doNum), ptId, &x[0]); + status2 = ::VISU_XYPlotActorGetComponent(field, + this->YComponent->GetValue(doNum), ptId, &xyz[1]); } else //if ( this->DataObjectPlotMode == VTK_XYPLOT_COLUMN ) { - x[0] = field->GetComponent(ptId, this->XComponent->GetValue(doNum)); - xyz[1] = field->GetComponent(ptId, this->YComponent->GetValue(doNum)); + //x[0] = field->GetComponent(ptId, this->XComponent->GetValue(doNum)); + //xyz[1] = field->GetComponent(ptId, this->YComponent->GetValue(doNum)); + + status1 = ::VISU_XYPlotActorGetComponent(field, + ptId, this->XComponent->GetValue(doNum), &x[0]); + + if (!status1) + { + vtkWarningMacro(<< this->XComponent->GetValue(doNum) << " is a non-numeric component."); + } + + status2 = ::VISU_XYPlotActorGetComponent(field, + ptId, this->YComponent->GetValue(doNum), &xyz[1]); + + if (!status2) + { + vtkWarningMacro(<< this->YComponent->GetValue(doNum) << " is a non-numeric component."); + } + } + if (!status1 || !status2) + { + // component is non-numeric. + // Skip it. + continue; } switch (this->XValues) @@ -2079,25 +2172,31 @@ void VISU_XYPlotActor::ClipPlotData(int *pos, int *pos2, vtkPolyData *pd) } else { + newPts[0] = -1; if (x1[0] >= p1[0] && x1[0] <= p2[0] && x1[1] >= p1[1] && x1[1] <= p2[1] ) {//first point in newPts[0] = pointMap[pts[i]]; } - else + else if (x2[0] >= p1[0] && x2[0] <= p2[0] && x2[1] >= p1[1] && x2[1] <= p2[1] ) {//second point in newPts[0] = pointMap[pts[i+1]]; } - for (j=0; j<4; j++) + + //only create cell if either x1 or x2 is inside the range + if (newPts[0] >= 0) { - this->ClipPlanes->GetPoints()->GetPoint(j, px); - this->ClipPlanes->GetNormals()->GetTuple(j, n); - if ( vtkPlane::IntersectWithLine(x1,x2,n,px,t,xint) && t >= 0 && t <= 1.0 ) + for (j=0; j<4; j++) { - newPts[1] = newPoints->InsertNextPoint(xint); - break; + this->ClipPlanes->GetPoints()->GetPoint(j, px); + this->ClipPlanes->GetNormals()->GetTuple(j, n); + if ( vtkPlane::IntersectWithLine(x1,x2,n,px,t,xint) && t >= 0 && t <= 1.0 ) + { + newPts[1] = newPoints->InsertNextPoint(xint); + break; + } } + newLines->InsertNextCell(2,newPts); } - newLines->InsertNextCell(2,newPts); } } }