Back to index

salome-gui  6.5.0
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
VTKViewer_ArcBuilder Class Reference

#include <VTKViewer_ArcBuilder.h>

Collaboration diagram for VTKViewer_ArcBuilder:
Collaboration graph
[legend]

List of all members.

Public Types

enum  ArcStatus { Arc_Done = 0, Arc_Error }

Public Member Functions

 VTKViewer_ArcBuilder (const Pnt &thePnt1, const Pnt &thePnt2, const Pnt &thePnt3, double theAngle)
 Constructor.
 ~VTKViewer_ArcBuilder ()
 Destructor.
Vec GetNormale ()
ArcStatus GetStatus ()
void GetAngle (const double theAngle)
vtkPoints * GetPoints ()
const std::vector< double > & GetScalarValues ()

Static Public Member Functions

static double GetPointAngleOnCircle (const double theXCenter, const double theYCenter, const double theXPoint, const double theYPoint)

Private Types

enum  IncOrder { MINUS = 0, PLUS }

Private Member Functions

vtkUnstructuredGrid * BuildGrid (const PntList &theList) const
vtkUnstructuredGrid * TransformGrid (vtkUnstructuredGrid *theGrid, const Vec &theAxis, const double angle) const
vtkUnstructuredGrid * BuildArc (std::vector< double > &theScalarValues)
IncOrder GetArcAngle (const double &P1, const double &P2, const double &P3, double *Ang)

Private Attributes

Pnt myPnt1
Pnt myPnt2
Pnt myPnt3
double myAngle
ArcStatus myStatus
vtkPoints * myPoints
std::vector< double > myScalarValues

Detailed Description

Definition at line 145 of file VTKViewer_ArcBuilder.h.


Member Enumeration Documentation

Enumerator:
Arc_Done 
Arc_Error 

Definition at line 147 of file VTKViewer_ArcBuilder.h.

Enumerator:
MINUS 
PLUS 

Definition at line 169 of file VTKViewer_ArcBuilder.h.

{MINUS=0,PLUS};

Constructor & Destructor Documentation

VTKViewer_ArcBuilder::VTKViewer_ArcBuilder ( const Pnt thePnt1,
const Pnt thePnt2,
const Pnt thePnt3,
double  theAngle 
)

Constructor.

Definition at line 222 of file VTKViewer_ArcBuilder.cxx.

                                                           :
  myStatus(Arc_Error),
  myAngle(theAngle)
{
  Vec V1(thePnt2.GetXYZ().X()-thePnt1.GetXYZ().X(),
         thePnt2.GetXYZ().Y()-thePnt1.GetXYZ().Y(),
         thePnt2.GetXYZ().Z()-thePnt1.GetXYZ().Z());
  
  Vec V2(thePnt2.GetXYZ().X()-thePnt3.GetXYZ().X(),
         thePnt2.GetXYZ().Y()-thePnt3.GetXYZ().Y(),
         thePnt2.GetXYZ().Z()-thePnt3.GetXYZ().Z());

  double angle = V1.AngleBetweenInGrad(V2);
  
  //Check that points are not belong one line
#ifdef _MY_DEBUG_
  cout<<"Angle for check: "<<angle<<endl;
#endif
  if(CheckAngle(180,angle)) {
    
    // Build plane by three points
    Plane aPlane(thePnt1,thePnt2,thePnt3);
    
    //Plane normales
    Vec aPlaneNormale = aPlane.GetNormale();
#ifdef _MY_DEBUG_
    std::cout<<"X Normale: "<<aPlaneNormale.GetXYZ().X()<<std::endl;
    std::cout<<"Y Normale: "<<aPlaneNormale.GetXYZ().Y()<<std::endl;
    std::cout<<"Z Normale: "<<aPlaneNormale.GetXYZ().Z()<<std::endl;
#endif
    //OZ vector
    Vec OZ(0,0,1);
    
    //Projection plane normale on XOY
    Vec aNormaleProjection (aPlaneNormale.GetXYZ().X(),
                            aPlaneNormale.GetXYZ().Y(),
                            0);
#ifdef _MY_DEBUG_
    std::cout<<"X Normale Projection: "<<aNormaleProjection.GetXYZ().X()<<std::endl;
    std::cout<<"Y Normale Projection: "<<aNormaleProjection.GetXYZ().Y()<<std::endl;
    std::cout<<"Z Normale Projection: "<<aNormaleProjection.GetXYZ().Z()<<std::endl;
#endif
    
    //Rotation axis
    Vec aAxis = aNormaleProjection.VectMultiplication(OZ);
#ifdef _MY_DEBUG_
    std::cout<<"X Axis: "<<aAxis.GetXYZ().X()<<std::endl;
    std::cout<<"Y Axis: "<<aAxis.GetXYZ().Y()<<std::endl;
    std::cout<<"Z Axis: "<<aAxis.GetXYZ().Z()<<std::endl;
#endif   
    //Rotation angle
    double anAngle = OZ.AngleBetweenInGrad(aPlaneNormale);
#ifdef _MY_DEBUG_
    std::cout<<"Rotation Angle :"<<anAngle<<endl;
#endif
    PntList aInputPnts;
    aInputPnts.push_back(thePnt1);
    aInputPnts.push_back(thePnt2);
    aInputPnts.push_back(thePnt3);
    
    vtkUnstructuredGrid* aGrid = BuildGrid(aInputPnts);
    
    bool needRotation = true;
    if(anAngle  == 0 || anAngle == 180)
      needRotation = false;
    
    if(aGrid) {
      vtkUnstructuredGrid* aTransformedGrid;
      if(needRotation) {
        aTransformedGrid = TransformGrid(aGrid,aAxis,anAngle);    
        aTransformedGrid->Update();
#ifdef _MY_DEBUG_
        cout<<"Need Rotation!!!"<<endl;
#endif
      }
      else {
        aTransformedGrid = aGrid;
#ifdef _MY_DEBUG_
        cout<<"Rotation does not need!!!"<<endl;
#endif
      }
      
      double coords[3];
      aTransformedGrid->GetPoint(0,coords);
      myPnt1 = Pnt(coords[0],coords[1],coords[2], thePnt1.GetScalarValue());
      aTransformedGrid->GetPoint(1,coords);
      myPnt2 = Pnt(coords[0],coords[1],coords[2], thePnt2.GetScalarValue());
      aTransformedGrid->GetPoint(2,coords);
      myPnt3 = Pnt(coords[0],coords[1],coords[2], thePnt3.GetScalarValue());
      std::vector<double> aScalarValues;
      vtkUnstructuredGrid* anArc = BuildArc(aScalarValues);
      vtkUnstructuredGrid* anTransArc;
      if(needRotation) {
        anTransArc = TransformGrid(anArc,aAxis,-anAngle);
        anTransArc->Update();
      }
      else
        anTransArc = anArc;
      
      myPoints = anTransArc->GetPoints();
      myScalarValues = aScalarValues;
      myStatus = Arc_Done;
    }
  }
  else{
#ifdef _MY_DEBUG_
    std::cout<<"Points lay on the one line !"<<endl;
#endif           
    PntList aList;
    aList.push_back(thePnt1);
    aList.push_back(thePnt2);
    aList.push_back(thePnt3);
    vtkUnstructuredGrid* aGrid = BuildGrid(aList);
    aGrid->Update();
    myPoints = aGrid->GetPoints();

    myScalarValues.clear();
    myScalarValues.push_back(thePnt1.GetScalarValue());
    myScalarValues.push_back(thePnt2.GetScalarValue());
    myScalarValues.push_back(thePnt3.GetScalarValue());
    myStatus = Arc_Done;
  }
}

Here is the call graph for this function:

Destructor.

Definition at line 352 of file VTKViewer_ArcBuilder.cxx.

{}

Member Function Documentation

vtkUnstructuredGrid * VTKViewer_ArcBuilder::BuildArc ( std::vector< double > &  theScalarValues) [private]

Definition at line 421 of file VTKViewer_ArcBuilder.cxx.

                                                                                     {
  double x1 = myPnt1.GetXYZ().X(); double x2 = myPnt2.GetXYZ().X(); double x3 = myPnt3.GetXYZ().X();
  double y1 = myPnt1.GetXYZ().Y(); double y2 = myPnt2.GetXYZ().Y(); double y3 = myPnt3.GetXYZ().Y();
  double z =  myPnt1.GetXYZ().Z();  //Points on plane || XOY
  

  theScalarValues.clear();

  double K1 = 0;
  double K2 = 0;
  bool okK1 = false, okK2 = false;
  if ( fabs(x2 - x1) > DBL_MIN )
    K1 = (y2 - y1)/(x2 - x1), okK1 = true;
  if ( fabs(x3 - x2) > DBL_MIN )
    K2 = (y3 - y2)/(x3 - x2), okK2 = true;
  
#ifdef _MY_DEBUG_   
  std::cout<<"K1 : "<< K1 <<endl; 
  std::cout<<"K2 : "<< K2 <<endl; 
#endif
  double xCenter;
  if( !okK2 ) //K2 --> infinity
    xCenter = (K1*(y1-y3) + (x1+x2))/2.0;
  
  else if( !okK1 ) //K1 --> infinity
    xCenter = (K2*(y1-y3) - (x2+x3))/(-2.0);
  
  else 
    xCenter = (K1*K2*(y1-y3) + K2*(x1+x2) - K1*(x2+x3))/ (2.0*(K2-K1));
  
  double yCenter;
  
  if ( K1 == 0 )
    yCenter =  (-1/K2)*(xCenter - (x2+x3)/2.0) + (y2 + y3)/2.0;
  else 
    yCenter =  (-1/K1)*(xCenter - (x1+x2)/2.0) + (y1 + y2)/2.0;
  
#ifdef _MY_DEBUG_   
  double zCenter = z;
  std::cout<<"xCenter : "<<xCenter<<endl;
  std::cout<<"yCenter : "<<yCenter<<endl;
  std::cout<<"zCenter : "<<zCenter<<endl;
#endif
  double aRadius = sqrt((x1 - xCenter)*(x1 - xCenter) + (y1 - yCenter)*(y1 - yCenter));
  
  double angle1 = GetPointAngleOnCircle(xCenter,yCenter,x1,y1);
  double angle2 = GetPointAngleOnCircle(xCenter,yCenter,x2,y2);
  double angle3 = GetPointAngleOnCircle(xCenter,yCenter,x3,y3);
  
  
  double aMaxAngle = vtkMath::RadiansFromDegrees(1.)*myAngle*2;
  
  /*  double aTotalAngle =  fabs(angle3 - angle1);
  
  if (aTotalAngle > vtkMath::DoublePi())
    aTotalAngle = 2*vtkMath::DoublePi()-aTotalAngle;
  */
  
  double aTotalAngle = 0;
  IncOrder aOrder = GetArcAngle(angle1,angle2,angle3,&aTotalAngle);
  
  vtkUnstructuredGrid *aC = NULL;

  if(aTotalAngle > aMaxAngle) {
    int nbSteps = int(aTotalAngle/aMaxAngle)+1;
    double anIncrementAngle = aTotalAngle/nbSteps;
    double aCurrentAngle = angle1;
    if(aOrder == VTKViewer_ArcBuilder::MINUS)
      aCurrentAngle-=anIncrementAngle;
    else
      aCurrentAngle+=anIncrementAngle;
#ifdef _MY_DEBUG_
    cout<<"Total angle :"<<aTotalAngle<<endl;
    cout<<"Max Increment Angle :"<<aMaxAngle<<endl;
    cout<<"Real Increment angle :"<<anIncrementAngle<<endl;
    cout<<"Nb Steps : "<<nbSteps<<endl;
#endif
  
    PntList aList;
    aList.push_back(myPnt1);
    theScalarValues.push_back(myPnt1.GetScalarValue());
    for(int i=1;i<=nbSteps-1;i++){
      double x = xCenter + aRadius*cos(aCurrentAngle);
      double y = yCenter + aRadius*sin(aCurrentAngle);
      double value = InterpolateScalarValue(i, nbSteps, myPnt1.GetScalarValue(), myPnt2.GetScalarValue(), myPnt3.GetScalarValue());
      Pnt aPnt(x,y,z,value);

      aList.push_back(aPnt);
      theScalarValues.push_back(aPnt.GetScalarValue());
      if(aOrder == VTKViewer_ArcBuilder::MINUS)
        aCurrentAngle-=anIncrementAngle;
      else
        aCurrentAngle+=anIncrementAngle;
    }
    aList.push_back(myPnt3);
    theScalarValues.push_back(myPnt3.GetScalarValue());
    
    aC = BuildGrid(aList);
#ifdef _MY_DEBUG_
  cout<<"angle1 : "<<angle1*vtkMath::DoubleRadiansToDegrees()<<endl;
  cout<<"angle2 : "<<angle2*vtkMath::DoubleRadiansToDegrees()<<endl;
  cout<<"angle3 : "<<angle3*vtkMath::DoubleRadiansToDegrees()<<endl;
#endif
  }
  else{
    PntList aList;
    aList.push_back(myPnt1);
    aList.push_back(myPnt2);
    aList.push_back(myPnt3);
    aC = BuildGrid(aList);

    theScalarValues.push_back(myPnt1.GetScalarValue());
    theScalarValues.push_back(myPnt2.GetScalarValue());
    theScalarValues.push_back(myPnt3.GetScalarValue());
  }
  return aC;
}

Here is the call graph for this function:

Here is the caller graph for this function:

vtkUnstructuredGrid * VTKViewer_ArcBuilder::BuildGrid ( const PntList theList) const [private]

Definition at line 359 of file VTKViewer_ArcBuilder.cxx.

{
  int aListsize = theList.size();  
  vtkUnstructuredGrid* aGrid = NULL;
  
  if(aListsize != 0) {
    aGrid = vtkUnstructuredGrid::New();
    vtkPoints* aPoints = vtkPoints::New();
    aPoints->SetNumberOfPoints(aListsize);
    
    aGrid->Allocate(aListsize);
    
    PntList::const_iterator it = theList.begin();
    int aCounter = 0;
    for(;it != theList.end();it++) {
      Pnt aPnt =  *it;
      aPoints->InsertPoint(aCounter, 
                           aPnt.GetXYZ().X(), 
                           aPnt.GetXYZ().Y(),
                           aPnt.GetXYZ().Z());
      vtkVertex* aVertex = vtkVertex::New();
      aVertex->GetPointIds()->SetId(0, aCounter);
      aGrid->InsertNextCell(aVertex->GetCellType(), aVertex->GetPointIds());
      aCounter++;
      aVertex->Delete();
    }
    aGrid->SetPoints(aPoints);
    aPoints->Delete();
  }
  return aGrid;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void VTKViewer_ArcBuilder::GetAngle ( const double  theAngle)

Definition at line 406 of file VTKViewer_ArcBuilder.cxx.

                                                        {
  myAngle = theAngle;
}
VTKViewer_ArcBuilder::IncOrder VTKViewer_ArcBuilder::GetArcAngle ( const double &  P1,
const double &  P2,
const double &  P3,
double *  Ang 
) [private]

Definition at line 558 of file VTKViewer_ArcBuilder.cxx.

                                                                                                                               {
  IncOrder aResult;
  if(P1 < P2 && P2 < P3){
    *Ang = P3 - P1;
    aResult = VTKViewer_ArcBuilder::PLUS;
  }
  else if((P1 < P3 && P3 < P2) || (P2 < P1 && P1 < P3)){
    *Ang = 2*vtkMath::DoublePi() - P3 + P1;
    aResult = VTKViewer_ArcBuilder::MINUS;
  }
  else if((P2 < P3 && P3 < P1) || (P3 < P1 && P1 < P2)){
    *Ang = 2*vtkMath::DoublePi() - P1 + P3;
    aResult = VTKViewer_ArcBuilder::PLUS;
  }
  else if(P3 < P2 && P2 < P1){
    *Ang = P1 - P3;
    aResult = VTKViewer_ArcBuilder::MINUS;
  }
  return aResult;
}

Here is the caller graph for this function:

double VTKViewer_ArcBuilder::GetPointAngleOnCircle ( const double  theXCenter,
const double  theYCenter,
const double  theXPoint,
const double  theYPoint 
) [static]

Definition at line 540 of file VTKViewer_ArcBuilder.cxx.

                                                                     {
  double result = atan2(theYCenter - theYPoint, theXPoint - theXCenter);
  if(result < 0 )
    result = result+vtkMath::DoublePi()*2;
  return vtkMath::DoublePi()*2-result;
  return result;
}

Here is the caller graph for this function:

Definition at line 549 of file VTKViewer_ArcBuilder.cxx.

                                          {
  return myPoints;
}

Here is the caller graph for this function:

const std::vector< double > & VTKViewer_ArcBuilder::GetScalarValues ( )

Definition at line 553 of file VTKViewer_ArcBuilder.cxx.

{
  return myScalarValues;
}

Here is the caller graph for this function:

Definition at line 157 of file VTKViewer_ArcBuilder.h.

{return myStatus;}

Here is the caller graph for this function:

vtkUnstructuredGrid * VTKViewer_ArcBuilder::TransformGrid ( vtkUnstructuredGrid *  theGrid,
const Vec theAxis,
const double  angle 
) const [private]

Definition at line 393 of file VTKViewer_ArcBuilder.cxx.

{
  vtkTransform *aTransform = vtkTransform::New();
  aTransform->RotateWXYZ(angle, theAxis.GetXYZ().X(), theAxis.GetXYZ().Y(), theAxis.GetXYZ().Z());
  vtkTransformFilter* aTransformFilter  = vtkTransformFilter::New();
  aTransformFilter->SetTransform(aTransform);
  aTransformFilter->SetInput(theGrid);
  aTransform->Delete();
  return aTransformFilter->GetUnstructuredGridOutput();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 183 of file VTKViewer_ArcBuilder.h.

Definition at line 179 of file VTKViewer_ArcBuilder.h.

Definition at line 180 of file VTKViewer_ArcBuilder.h.

Definition at line 181 of file VTKViewer_ArcBuilder.h.

vtkPoints* VTKViewer_ArcBuilder::myPoints [private]

Definition at line 185 of file VTKViewer_ArcBuilder.h.

std::vector<double> VTKViewer_ArcBuilder::myScalarValues [private]

Definition at line 186 of file VTKViewer_ArcBuilder.h.

Definition at line 184 of file VTKViewer_ArcBuilder.h.


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