Back to index

salome-gui  6.5.0
Defines | Functions
VTKViewer_ArcBuilder.cxx File Reference
#include "VTKViewer_ArcBuilder.h"
#include <math.h>
#include <float.h>
#include <vtkMath.h>
#include <vtkUnstructuredGrid.h>
#include <vtkTransformFilter.h>
#include <vtkTransform.h>
#include <vtkPoints.h>
#include <vtkVertex.h>
#include <vtkCellArray.h>
#include <vtkTriangle.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>

Go to the source code of this file.

Defines

#define PRECISION   10e-4
#define ANGLE_PRECISION   0.5

Functions

bool CheckAngle (const double compare, const double angle)
double InterpolateScalarValue (int index, int count, double firstValue, double middleValue, double lastValue)
Pnt CreatePnt (vtkCell *cell, vtkDataArray *scalars, vtkIdType index)
vtkIdType Build1DArc (vtkIdType cellId, vtkUnstructuredGrid *input, vtkPolyData *output, vtkIdType *pts, vtkFloatingPointType myMaxArcAngle)
vtkIdType MergevtkPoints (const std::vector< vtkPoints * > &theCollection, const std::vector< std::vector< double > > &theScalarCollection, vtkPoints *thePoints, std::map< int, double > &thePntId2ScalarValue, vtkIdType *&theIds)
 Add all points from the input vector theCollection into thePoints.

Define Documentation

#define ANGLE_PRECISION   0.5

Definition at line 42 of file VTKViewer_ArcBuilder.cxx.

#define PRECISION   10e-4

Definition at line 41 of file VTKViewer_ArcBuilder.cxx.


Function Documentation

vtkIdType Build1DArc ( vtkIdType  cellId,
vtkUnstructuredGrid *  input,
vtkPolyData *  output,
vtkIdType *  pts,
vtkFloatingPointType  myMaxArcAngle 
)

Definition at line 591 of file VTKViewer_ArcBuilder.cxx.

                                                        {
  
  vtkIdType aResult = -1;
  vtkIdType *aNewPoints;

  vtkDataArray* inputScalars = input->GetPointData()->GetScalars();
  vtkDataArray* outputScalars = output->GetPointData()->GetScalars();

  vtkCell* aCell = input->GetCell(cellId);
  //Get All points from input cell
  Pnt P0 = CreatePnt( aCell, inputScalars, 0 );
  Pnt P1 = CreatePnt( aCell, inputScalars, 1 );
  Pnt P2 = CreatePnt( aCell, inputScalars, 2 );

  VTKViewer_ArcBuilder aBuilder(P0,P2,P1,myMaxArcAngle);
  if (aBuilder.GetStatus() != VTKViewer_ArcBuilder::Arc_Done) {
    return aResult;
  }
  else{
    vtkPoints* aPoints = aBuilder.GetPoints();
    std::vector<double> aScalarValues = aBuilder.GetScalarValues();
    vtkIdType aNbPts = aPoints->GetNumberOfPoints();
    aNewPoints = new vtkIdType[aNbPts];
    vtkIdType curID;
    vtkIdType aCellType = VTK_POLY_LINE;
    
    aNewPoints[0] = pts[0];
    for(vtkIdType idx = 1; idx < aNbPts-1;idx++) {
      curID = output->GetPoints()->InsertNextPoint(aPoints->GetPoint(idx));
      if( outputScalars )
        outputScalars->InsertNextTuple1(aScalarValues[idx]);
      aNewPoints[idx] = curID;
    }
    aNewPoints[aNbPts-1] = pts[1];
    
    aResult = output->InsertNextCell(aCellType,aNbPts,aNewPoints);
    return aResult;
  } 
}

Here is the call graph for this function:

bool CheckAngle ( const double  compare,
const double  angle 
)

Definition at line 50 of file VTKViewer_ArcBuilder.cxx.

                                                         {
  if((angle <= compare - ANGLE_PRECISION) || (angle >= compare + ANGLE_PRECISION))
    return true;
  else
    return false;
}

Here is the caller graph for this function:

Pnt CreatePnt ( vtkCell *  cell,
vtkDataArray *  scalars,
vtkIdType  index 
)

Definition at line 580 of file VTKViewer_ArcBuilder.cxx.

{
  vtkFloatingPointType coord[3];
  cell->GetPoints()->GetPoint(index, coord);
  vtkIdType pointId = cell->GetPointId(index);
  double scalarValue = scalars ? scalars->GetTuple1(pointId) : 0;
  Pnt point(coord[0], coord[1], coord[2], scalarValue);
  return point;
}

Here is the caller graph for this function:

double InterpolateScalarValue ( int  index,
int  count,
double  firstValue,
double  middleValue,
double  lastValue 
)

Definition at line 410 of file VTKViewer_ArcBuilder.cxx.

{
  bool isFirstHalf = index <= count / 2;
  double first = isFirstHalf ? firstValue : lastValue;
  double last = isFirstHalf ? middleValue : middleValue;
  double ratio = (double)index / (double)count;
  double position = isFirstHalf ? ratio * 2 : ( 1 - ratio ) * 2;
  double value = first + (last - first) * position;
  return value;
}

Here is the caller graph for this function:

vtkIdType MergevtkPoints ( const std::vector< vtkPoints * > &  theCollection,
const std::vector< std::vector< double > > &  theScalarCollection,
vtkPoints *  thePoints,
std::map< int, double > &  thePntId2ScalarValue,
vtkIdType *&  theIds 
)

Add all points from the input vector theCollection into thePoints.

Array theIds - it is array with ids of added points.

Definition at line 637 of file VTKViewer_ArcBuilder.cxx.

                                            {
  vtkIdType aNbPoints = 0;
  vtkIdType anIdCounter = 0;
  vtkIdType aNewPntId = 0;
  
  //Compute number of points
  std::vector<vtkPoints*>::const_iterator it = theCollection.begin();
  for(;it != theCollection.end();it++){
    vtkPoints* aPoints = *it;
    if(aPoints) { 
      aNbPoints += aPoints->GetNumberOfPoints()-1; //Because we add all points except last
    }
  }
  it = theCollection.begin();
  std::vector< std::vector<double> >::const_iterator itScalar = theScalarCollection.begin();
  theIds = new vtkIdType[aNbPoints];
  // ..and add all points
  for(;it != theCollection.end() && itScalar != theScalarCollection.end(); it++, itScalar++){
    vtkPoints* aPoints = *it;
    std::vector<double> aScalarValues = *itScalar;
    
    if(aPoints){
      for(vtkIdType idx = 0;idx < aPoints->GetNumberOfPoints()-1;idx++){
        aNewPntId = thePoints->InsertNextPoint(aPoints->GetPoint(idx));
        theIds[anIdCounter] = aNewPntId;
        thePntId2ScalarValue[ aNewPntId ] = aScalarValues[idx];
        anIdCounter++;
      }
    }
  }
  return aNbPoints;
}