X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVTKViewer%2FVTKViewer_ArcBuilder.cxx;h=7af67d1fc5ee2635e451c85bfcffa0093ad56335;hb=76527b0c8b1208770b6f707644829b691a87d081;hp=26df8dbdc29e9e3b8494bb48d9ea5a60967156f8;hpb=3593b4d1585d69f34034e5c678dc97b6e92a85cf;p=modules%2Fgui.git diff --git a/src/VTKViewer/VTKViewer_ArcBuilder.cxx b/src/VTKViewer/VTKViewer_ArcBuilder.cxx index 26df8dbdc..7af67d1fc 100644 --- a/src/VTKViewer/VTKViewer_ArcBuilder.cxx +++ b/src/VTKViewer/VTKViewer_ArcBuilder.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,7 +23,7 @@ // #include "VTKViewer_ArcBuilder.h" -#include +#include #include //VTK includes @@ -42,11 +42,11 @@ #define ANGLE_PRECISION 0.5 //#define _MY_DEBUG_ +#include #ifdef _MY_DEBUG_ #include #endif - bool CheckAngle(const double compare, const double angle){ if((angle <= compare - ANGLE_PRECISION) || (angle >= compare + ANGLE_PRECISION)) return true; @@ -115,11 +115,16 @@ Vec::Vec (const double Xv, const double Zv) { double D = sqrt (Xv * Xv + Yv * Yv + Zv * Zv); - if(D != 0) { + if(D > std::numeric_limits::min() ) { coord.SetX(Xv / D); coord.SetY(Yv / D); coord.SetZ(Zv / D); } + else { + coord.SetX(0); + coord.SetY(0); + coord.SetZ(0); + } } /*! @@ -159,8 +164,7 @@ Vec Vec::VectMultiplication(const Vec & Other) const{ double x = GetXYZ().Y()*Other.GetXYZ().Z() - GetXYZ().Z()*Other.GetXYZ().Y(); double y = GetXYZ().Z()*Other.GetXYZ().X() - GetXYZ().X()*Other.GetXYZ().Z(); double z = GetXYZ().X()*Other.GetXYZ().Y() - GetXYZ().Y()*Other.GetXYZ().X(); - Vec *aRes = new Vec(x,y,z); - return *aRes; + return Vec(x,y,z); } /*---------------------Class Plane --------------------------------*/ @@ -282,47 +286,42 @@ VTKViewer_ArcBuilder::VTKViewer_ArcBuilder(const Pnt& thePnt1, aInputPnts.push_back(thePnt2); aInputPnts.push_back(thePnt3); - vtkUnstructuredGrid* aGrid = BuildGrid(aInputPnts); + vtkSmartPointer aGrid = BuildGrid(aInputPnts); + aGrid->Delete(); bool needRotation = true; if(anAngle == 0 || anAngle == 180) needRotation = false; if(aGrid) { - vtkUnstructuredGrid* aTransformedGrid; if(needRotation) { - aTransformedGrid = TransformGrid(aGrid,aAxis,anAngle); - aTransformedGrid->Update(); + aGrid = TransformGrid(aGrid,aAxis,anAngle); + aGrid->Delete(); #ifdef _MY_DEBUG_ cout<<"Need Rotation!!!"<GetPoint(0,coords); + aGrid->GetPoint(0,coords); myPnt1 = Pnt(coords[0],coords[1],coords[2], thePnt1.GetScalarValue()); - aTransformedGrid->GetPoint(1,coords); + aGrid->GetPoint(1,coords); myPnt2 = Pnt(coords[0],coords[1],coords[2], thePnt2.GetScalarValue()); - aTransformedGrid->GetPoint(2,coords); + aGrid->GetPoint(2,coords); myPnt3 = Pnt(coords[0],coords[1],coords[2], thePnt3.GetScalarValue()); - std::vector aScalarValues; - vtkUnstructuredGrid* anArc = BuildArc(aScalarValues); - vtkUnstructuredGrid* anTransArc; + + vtkSmartPointer anArc = BuildArc(myScalarValues); + anArc->Delete(); if(needRotation) { - anTransArc = TransformGrid(anArc,aAxis,-anAngle); - anTransArc->Update(); + anArc = TransformGrid(anArc,aAxis,-anAngle); + anArc->Delete(); } - else - anTransArc = anArc; - - myPoints = anTransArc->GetPoints(); - myScalarValues = aScalarValues; + myPoints = anArc->GetPoints(); myStatus = Arc_Done; } } @@ -335,8 +334,8 @@ VTKViewer_ArcBuilder::VTKViewer_ArcBuilder(const Pnt& thePnt1, aList.push_back(thePnt2); aList.push_back(thePnt3); vtkUnstructuredGrid* aGrid = BuildGrid(aList); - aGrid->Update(); myPoints = aGrid->GetPoints(); + aGrid->Delete(); myScalarValues.clear(); myScalarValues.push_back(thePnt1.GetScalarValue()); @@ -397,9 +396,13 @@ VTKViewer_ArcBuilder::TransformGrid(vtkUnstructuredGrid* theGrid, 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(); + aTransformFilter->SetInputData(theGrid); + aTransformFilter->Update(); + vtkUnstructuredGrid * aGrid = aTransformFilter->GetUnstructuredGridOutput(); + aGrid->Register(0); + aTransformFilter->Delete(); + return aGrid; } @@ -418,7 +421,8 @@ double InterpolateScalarValue(int index, int count, double firstValue, double mi return value; } -vtkUnstructuredGrid* VTKViewer_ArcBuilder::BuildArc(std::vector& theScalarValues){ +vtkUnstructuredGrid* VTKViewer_ArcBuilder::BuildArc(std::vector& theScalarValues) +{ 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 @@ -472,8 +476,8 @@ vtkUnstructuredGrid* VTKViewer_ArcBuilder::BuildArc(std::vector& theScal /* double aTotalAngle = fabs(angle3 - angle1); - if (aTotalAngle > vtkMath::DoublePi()) - aTotalAngle = 2*vtkMath::DoublePi()-aTotalAngle; + if (aTotalAngle > vtkMath::Pi()) + aTotalAngle = 2*vtkMath::Pi()-aTotalAngle; */ double aTotalAngle = 0; @@ -541,8 +545,8 @@ GetPointAngleOnCircle(const double theXCenter, const double theYCenter, const double theXPoint, const double theYPoint){ double result = atan2(theYCenter - theYPoint, theXPoint - theXCenter); if(result < 0 ) - result = result+vtkMath::DoublePi()*2; - return vtkMath::DoublePi()*2-result; + result = result+vtkMath::Pi()*2; + return vtkMath::Pi()*2-result; return result; } @@ -562,11 +566,11 @@ VTKViewer_ArcBuilder::IncOrder VTKViewer_ArcBuilder::GetArcAngle( const double& aResult = VTKViewer_ArcBuilder::PLUS; } else if((P1 < P3 && P3 < P2) || (P2 < P1 && P1 < P3)){ - *Ang = 2*vtkMath::DoublePi() - P3 + P1; + *Ang = 2*vtkMath::Pi() - P3 + P1; aResult = VTKViewer_ArcBuilder::MINUS; } else if((P2 < P3 && P3 < P1) || (P3 < P1 && P1 < P2)){ - *Ang = 2*vtkMath::DoublePi() - P1 + P3; + *Ang = 2*vtkMath::Pi() - P1 + P3; aResult = VTKViewer_ArcBuilder::PLUS; } else if(P3 < P2 && P2 < P1){ @@ -579,7 +583,7 @@ VTKViewer_ArcBuilder::IncOrder VTKViewer_ArcBuilder::GetArcAngle( const double& //------------------------------------------------------------------------ Pnt CreatePnt(vtkCell* cell, vtkDataArray* scalars, vtkIdType index) { - vtkFloatingPointType coord[3]; + double coord[3]; cell->GetPoints()->GetPoint(index, coord); vtkIdType pointId = cell->GetPointId(index); double scalarValue = scalars ? scalars->GetTuple1(pointId) : 0; @@ -590,7 +594,7 @@ Pnt CreatePnt(vtkCell* cell, vtkDataArray* scalars, vtkIdType index) //------------------------------------------------------------------------ vtkIdType Build1DArc(vtkIdType cellId, vtkUnstructuredGrid* input, vtkPolyData *output,vtkIdType *pts, - vtkFloatingPointType myMaxArcAngle){ + double myMaxArcAngle){ vtkIdType aResult = -1; vtkIdType *aNewPoints; @@ -612,10 +616,10 @@ vtkIdType Build1DArc(vtkIdType cellId, vtkUnstructuredGrid* input, vtkPoints* aPoints = aBuilder.GetPoints(); std::vector aScalarValues = aBuilder.GetScalarValues(); vtkIdType aNbPts = aPoints->GetNumberOfPoints(); - aNewPoints = new vtkIdType[aNbPts]; + std::vector< vtkIdType > aNewPoints( 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)); @@ -624,17 +628,17 @@ vtkIdType Build1DArc(vtkIdType cellId, vtkUnstructuredGrid* input, aNewPoints[idx] = curID; } aNewPoints[aNbPts-1] = pts[1]; - - aResult = output->InsertNextCell(aCellType,aNbPts,aNewPoints); + + aResult = output->InsertNextCell(aCellType,aNbPts,&aNewPoints[0]); return aResult; - } + } } /*! * Add all points from the input vector theCollection into thePoints. * Array theIds - it is array with ids of added points. */ -vtkIdType MergevtkPoints(const std::vector& theCollection, +vtkIdType MergevtkPoints(const std::vector< vtkSmartPointer< vtkPoints > >& theCollection, const std::vector< std::vector >& theScalarCollection, vtkPoints* thePoints, std::map& thePntId2ScalarValue, @@ -642,9 +646,9 @@ vtkIdType MergevtkPoints(const std::vector& theCollection, vtkIdType aNbPoints = 0; vtkIdType anIdCounter = 0; vtkIdType aNewPntId = 0; - + //Compute number of points - std::vector::const_iterator it = theCollection.begin(); + std::vector< vtkSmartPointer< vtkPoints > >::const_iterator it = theCollection.begin(); for(;it != theCollection.end();it++){ vtkPoints* aPoints = *it; if(aPoints) {