#include <vtkCellArray.h>
#include <vtkTriangle.h>
#include <vtkPolyData.h>
+#include <vtkPointData.h>
#define PRECISION 10e-4
#define ANGLE_PRECISION 0.5
*/
Pnt::Pnt(double X,
double Y,
- double Z):
- coord(X,Y,Z) {}
+ double Z,
+ double ScalarValue):
+ coord(X,Y,Z),
+ scalarValue(ScalarValue)
+{
+}
+Pnt::Pnt()
+{
+}
-Pnt::Pnt(){}
/*!
* Destructor
*/
Pnt::~Pnt()
-{}
+{
+}
//------------------------------------------------------------------------
/*!
double res;
double numerator = GetXYZ().X()*Other.GetXYZ().X()+GetXYZ().Y()*Other.GetXYZ().Y()+GetXYZ().Z()*Other.GetXYZ().Z();
double denumerator = GetXYZ().Modulus()*Other.GetXYZ().Modulus();
- res = acos(numerator/denumerator);
+ double d = numerator/denumerator;
+ if( d < -1 && d > -1 - PRECISION )
+ d = -1;
+ else if( d > 1 && d < 1 + PRECISION )
+ d = 1;
+ res = acos( d );
return res;
}
double coords[3];
aTransformedGrid->GetPoint(0,coords);
- myPnt1 = Pnt(coords[0],coords[1],coords[2]);
+ myPnt1 = Pnt(coords[0],coords[1],coords[2], thePnt1.GetScalarValue());
aTransformedGrid->GetPoint(1,coords);
- myPnt2 = Pnt(coords[0],coords[1],coords[2]);
+ myPnt2 = Pnt(coords[0],coords[1],coords[2], thePnt2.GetScalarValue());
aTransformedGrid->GetPoint(2,coords);
- myPnt3 = Pnt(coords[0],coords[1],coords[2]);
- vtkUnstructuredGrid* anArc = BuildArc();
+ 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 = anArc;
myPoints = anTransArc->GetPoints();
+ myScalarValues = aScalarValues;
myStatus = Arc_Done;
}
}
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;
}
}
myAngle = theAngle;
}
-vtkUnstructuredGrid* VTKViewer_ArcBuilder::BuildArc(){
+double InterpolateScalarValue(int index, int count, double firstValue, double middleValue, double lastValue)
+{
+ 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;
+}
+
+vtkUnstructuredGrid* VTKViewer_ArcBuilder::BuildArc(std::vector<double>& 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
-
+
+ theScalarValues.clear();
+
double K1;
double K2;
K1 = (y2 - y1)/(x2 - x1);
PntList aList;
aList.push_back(myPnt1);
- for(int i=0;i<nbSteps-1;i++){
+ 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);
- Pnt aPnt(x,y,z);
+ 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_
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;
}
return myPoints;
}
+const std::vector<double>& VTKViewer_ArcBuilder::GetScalarValues()
+{
+ return myScalarValues;
+}
+
VTKViewer_ArcBuilder::IncOrder VTKViewer_ArcBuilder::GetArcAngle( const double& P1, const double& P2, const double& P3,double* Ang){
IncOrder aResult;
if(P1 < P2 && P2 < P3){
return aResult;
}
+//------------------------------------------------------------------------
+Pnt CreatePnt(vtkCell* cell, vtkDataArray* scalars, vtkIdType index)
+{
+ 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;
+}
+
//------------------------------------------------------------------------
vtkIdType Build1DArc(vtkIdType cellId, vtkUnstructuredGrid* input,
vtkPolyData *output,vtkIdType *pts,
vtkFloatingPointType myMaxArcAngle){
- vtkFloatingPointType coord[3];
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
- aCell->GetPoints()->GetPoint(0,coord);
- Pnt P0(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(1,coord);
- Pnt P1(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(2,coord);
- Pnt P2(coord[0],coord[1],coord[2]);
+ 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) {
}
else{
vtkPoints* aPoints = aBuilder.GetPoints();
+ std::vector<double> aScalarValues = aBuilder.GetScalarValues();
vtkIdType aNbPts = aPoints->GetNumberOfPoints();
aNewPoints = new vtkIdType[aNbPts];
vtkIdType curID;
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];
* 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<vtkPoints*>& theCollection, vtkPoints* thePoints, vtkIdType* &theIds){
+vtkIdType MergevtkPoints(const std::vector<vtkPoints*>& theCollection,
+ const std::vector< std::vector<double> >& theScalarCollection,
+ vtkPoints* thePoints,
+ std::map<int, double>& thePntId2ScalarValue,
+ vtkIdType* &theIds){
vtkIdType aNbPoints = 0;
vtkIdType anIdCounter = 0;
vtkIdType aNewPntId = 0;
}
}
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();it++){
+ 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++;
}
}
cellVis = new char[numCells];
}
- // Just pass points through, never merge
- output->SetPoints(input->GetPoints());
+ // Issue 0020115: [CEA 308] Quadratic elements visualization
+ // Fix of remark described in note 0005222 - SIGSEGV
+ vtkPoints* outputPoints = vtkPoints::New();
+ outputPoints->DeepCopy(input->GetPoints());
+ output->SetPoints(outputPoints);
+ outputPoints->Delete();
+
outputPD->PassData(pd);
outputCD->CopyAllocate(cd,numCells,numCells/2);
aNewPts[3] = pts[4];
aNewPts[4] = pts[2];
aNewPts[5] = pts[5];
-
+
newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ if(myStoreMapping)
+ myVTK2ObjIds.push_back(cellId);
+
+ outputCD->CopyData(cd,cellId,newCellId);
}
else
BuildArcedPolygon(cellId,input,output);
aNewPts[5] = pts[6];
aNewPts[6] = pts[3];
aNewPts[7] = pts[7];
+
newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ if(myStoreMapping)
+ myVTK2ObjIds.push_back(cellId);
+
+ outputCD->CopyData(cd,cellId,newCellId);
}
else
BuildArcedPolygon(cellId,input,output);
void VTKViewer_GeometryFilter::BuildArcedPolygon(vtkIdType cellId, vtkUnstructuredGrid* input, vtkPolyData *output, bool triangulate){
- vtkFloatingPointType coord[3];
vtkIdType aCellType = VTK_POLYGON;
- vtkIdType *aNewPoints;
+ vtkIdType *aNewPoints = NULL;
vtkIdType aNbPoints = 0;
vtkIdType newCellId;
//Input and output cell data
vtkCellData *cd = input->GetCellData();
vtkCellData *outputCD = output->GetCellData();
-
+
+ //Input and output scalars on point data
+ vtkDataArray* inputScalars = input->GetPointData()->GetScalars();
+ vtkDataArray* outputScalars = output->GetPointData()->GetScalars();
+
+ std::vector<vtkPoints*> aCollection;
+ std::vector< std::vector<double> > aScalarCollection;
+
vtkCell* aCell = input->GetCell(cellId);
switch(aCell->GetCellType()) {
- case VTK_QUADRATIC_TRIANGLE:
+ case VTK_QUADRATIC_TRIANGLE:
{
//Get All points from input cell
- aCell->GetPoints()->GetPoint(0,coord);
- Pnt P0(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(1,coord);
- Pnt P1(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(2,coord);
- Pnt P2(coord[0],coord[1],coord[2]);
-
- aCell->GetPoints()->GetPoint(3,coord);
- Pnt P3(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(4,coord);
- Pnt P4(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(5,coord);
- Pnt P5(coord[0],coord[1],coord[2]);
-
- //Build arc usinf 0, 3 and 1 points
- VTKViewer_ArcBuilder aBuilder1(P0,P3,P1,myMaxArcAngle);
+ Pnt P0 = CreatePnt( aCell, inputScalars, 0 );
+ Pnt P1 = CreatePnt( aCell, inputScalars, 1 );
+ Pnt P2 = CreatePnt( aCell, inputScalars, 2 );
+ Pnt P3 = CreatePnt( aCell, inputScalars, 3 );
+ Pnt P4 = CreatePnt( aCell, inputScalars, 4 );
+ Pnt P5 = CreatePnt( aCell, inputScalars, 5 );
+
+ VTKViewer_ArcBuilder aBuilder1(P0,P3,P1,myMaxArcAngle); //Build arc using 0, 3 and 1 points
#ifdef __MYDEBUG__
- if(aBuilder1.GetStatus() == VTKViewer_ArcBuilder::Arc_Done) {
- cout<<"Triangle arc 1 done !!!"<<endl;
- }
- else{
- cout<<"Triangle arc 1 NOT done !!!"<<endl;
- }
+ cout << "Quadrangle arc 1 " << ( aBuilder1.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
#endif
-
- //Build arc usinf 1, 4 and 2 points
- VTKViewer_ArcBuilder aBuilder2(P1,P4,P2,myMaxArcAngle);
+
+ VTKViewer_ArcBuilder aBuilder2(P1,P4,P2,myMaxArcAngle); //Build arc using 1, 4 and 2 points
#ifdef __MYDEBUG__
- if(aBuilder2.GetStatus() == VTKViewer_ArcBuilder::Arc_Done) {
- cout<<"Triangle arc 2 done !!!"<<endl;
- }
- else{
- cout<<"Triangle arc 2 NOT done !!!"<<endl;
- }
+ cout << "Quadrangle arc 2 " << ( aBuilder2.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
#endif
- //Build arc usinf 2, 5 and 0 points
- VTKViewer_ArcBuilder aBuilder3(P2,P5,P0,myMaxArcAngle);
+
+ VTKViewer_ArcBuilder aBuilder3(P2,P5,P0,myMaxArcAngle); //Build arc using 2, 5 and 0 points
#ifdef __MYDEBUG__
- if(aBuilder3.GetStatus() == VTKViewer_ArcBuilder::Arc_Done) {
- cout<<"Triangle arc 3 done !!!"<<endl;
- }
- else{
- cout<<"Triangle arc 3 NOT done !!!"<<endl;
- }
+ cout << "Quadrangle arc 3 " << ( aBuilder3.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
#endif
- std::vector<vtkPoints*> aCollection;
+
aCollection.push_back(aBuilder1.GetPoints());
aCollection.push_back(aBuilder2.GetPoints());
aCollection.push_back(aBuilder3.GetPoints());
-
-
- //-----------------------------------------------------------------------------------------
- if(triangulate){
- const vtkIdType numFacePts = 3;
- vtkIdList *pts = vtkIdList::New();
- vtkPoints *coords = vtkPoints::New();
- aCellType = VTK_TRIANGLE;
- vtkIdType aNewPts[numFacePts];
- vtkIdType aTriangleId;
-
- vtkPolygon *aPlg = vtkPolygon::New();
- aNbPoints = MergevtkPoints(aCollection, aPlg->GetPoints(), aNewPoints);
- aPlg->GetPointIds()->SetNumberOfIds(aNbPoints);
-
- for(vtkIdType i = 0; i < aNbPoints;i++) {
- aPlg->GetPointIds()->SetId(i, aNewPoints[i]);
- }
-
- aPlg->Triangulate(0,pts,coords);
-
- for (vtkIdType i=0; i < pts->GetNumberOfIds(); i+=3) {
- aNewPts[0] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i));
- aNewPts[1] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+1));
- aNewPts[2] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+2));
-
- aTriangleId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
-
- if(myStoreMapping)
- myVTK2ObjIds.push_back(cellId);
- outputCD->CopyData(cd,cellId,aTriangleId);
- }
- pts->Delete();
- coords->Delete();
- aPlg->Delete();
- }
- //---------------------------------------------------------------------------------------------------
- else {
- aNbPoints = MergevtkPoints(aCollection, output->GetPoints(), aNewPoints);
- newCellId = output->InsertNextCell(aCellType,aNbPoints,aNewPoints);
- outputCD->CopyData(cd,cellId,newCellId);
-
- if(myStoreMapping)
- myVTK2ObjIds.push_back(cellId);
- }
+
+ aScalarCollection.push_back(aBuilder1.GetScalarValues());
+ aScalarCollection.push_back(aBuilder2.GetScalarValues());
+ aScalarCollection.push_back(aBuilder3.GetScalarValues());
break;
- } //VTK_QUADRATIC_TRIANGLE
-
+ }
case VTK_QUADRATIC_QUAD:
- {
- //Get All points from input cell
- aCell->GetPoints()->GetPoint(0,coord);
- Pnt P0(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(1,coord);
- Pnt P1(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(2,coord);
- Pnt P2(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(3,coord);
- Pnt P3(coord[0],coord[1],coord[2]);
-
- aCell->GetPoints()->GetPoint(4,coord);
- Pnt P4(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(5,coord);
- Pnt P5(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(6,coord);
- Pnt P6(coord[0],coord[1],coord[2]);
- aCell->GetPoints()->GetPoint(7,coord);
- Pnt P7(coord[0],coord[1],coord[2]);
-
- //Build arc usinf 0, 4 and 1 points
- VTKViewer_ArcBuilder aBuilder1(P0,P4,P1,myMaxArcAngle);
+ {
+ //Get All points from input cell
+ Pnt P0 = CreatePnt( aCell, inputScalars, 0 );
+ Pnt P1 = CreatePnt( aCell, inputScalars, 1 );
+ Pnt P2 = CreatePnt( aCell, inputScalars, 2 );
+ Pnt P3 = CreatePnt( aCell, inputScalars, 3 );
+ Pnt P4 = CreatePnt( aCell, inputScalars, 4 );
+ Pnt P5 = CreatePnt( aCell, inputScalars, 5 );
+ Pnt P6 = CreatePnt( aCell, inputScalars, 6 );
+ Pnt P7 = CreatePnt( aCell, inputScalars, 7 );
+
+ VTKViewer_ArcBuilder aBuilder1(P0,P4,P1,myMaxArcAngle); //Build arc using 0, 4 and 1 points
#ifdef __MYDEBUG__
- if(aBuilder1.GetStatus() == VTKViewer_ArcBuilder::Arc_Done) {
- cout<<"Quadrangle arc 1 done !!!"<<endl;
- }
- else{
- cout<<"Quadrangle arc 1 NOT done !!!"<<endl;
- }
+ cout << "Quadrangle arc 1 " << ( aBuilder1.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
#endif
- //Build arc usinf 1, 5 and 2 points
- VTKViewer_ArcBuilder aBuilder2(P1,P5,P2,myMaxArcAngle);
+
+ VTKViewer_ArcBuilder aBuilder2(P1,P5,P2,myMaxArcAngle); //Build arc using 1, 5 and 2 points
#ifdef __MYDEBUG__
- if(aBuilder2.GetStatus() == VTKViewer_ArcBuilder::Arc_Done) {
- cout<<"Quadrangle arc 2 done !!!"<<endl;
- }
- else{
- cout<<"Quadrangle arc 2 NOT done !!!"<<endl;
- }
+ cout << "Quadrangle arc 2 " << ( aBuilder2.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
#endif
- //Build arc usinf 2, 6 and 3 points
- VTKViewer_ArcBuilder aBuilder3(P2,P6,P3,myMaxArcAngle);
+
+ VTKViewer_ArcBuilder aBuilder3(P2,P6,P3,myMaxArcAngle); //Build arc using 2, 6 and 3 points
#ifdef __MYDEBUG__
- if(aBuilder3.GetStatus() == VTKViewer_ArcBuilder::Arc_Done) {
- cout<<"Quadrangle arc 3 done !!!"<<endl;
- }
- else{
- cout<<"Quadrangle arc 3 NOT done !!!"<<endl;
- }
+ cout << "Quadrangle arc 3 " << ( aBuilder3.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
#endif
- //Build arc usinf 3, 7 and 0 points
- VTKViewer_ArcBuilder aBuilder4(P3,P7,P0,myMaxArcAngle);
+
+ VTKViewer_ArcBuilder aBuilder4(P3,P7,P0,myMaxArcAngle); //Build arc using 3, 7 and 0 points
#ifdef __MYDEBUG__
- if(aBuilder3.GetStatus() == VTKViewer_ArcBuilder::Arc_Done) {
- cout<<"Quadrangle arc 4 done !!!"<<endl;
- }
- else{
- cout<<"Quadrangle arc 4 NOT done !!!"<<endl;
- }
+ cout << "Quadrangle arc 4 " << ( aBuilder4.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
#endif
- std::vector<vtkPoints*> aCollection;
- aCollection.push_back(aBuilder1.GetPoints());
- aCollection.push_back(aBuilder2.GetPoints());
- aCollection.push_back(aBuilder3.GetPoints());
- aCollection.push_back(aBuilder4.GetPoints());
-
- //-----------------------------------------------------------------------------------------
- if(triangulate){
- const vtkIdType numFacePts = 3;
- vtkIdList *pts = vtkIdList::New();
- vtkPoints *coords = vtkPoints::New();
- aCellType = VTK_TRIANGLE;
- vtkIdType aNewPts[numFacePts];
- vtkIdType aTriangleId;
-
- vtkPolygon *aPlg = vtkPolygon::New();
- aNbPoints = MergevtkPoints(aCollection, aPlg->GetPoints(), aNewPoints);
- aPlg->GetPointIds()->SetNumberOfIds(aNbPoints);
-
- for(vtkIdType i = 0; i < aNbPoints;i++) {
- aPlg->GetPointIds()->SetId(i, aNewPoints[i]);
- }
-
- aPlg->Triangulate(0,pts,coords);
-
- for (vtkIdType i=0; i < pts->GetNumberOfIds(); i+=3) {
- aNewPts[0] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i));
- aNewPts[1] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+1));
- aNewPts[2] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+2));
-
- aTriangleId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
-
- if(myStoreMapping)
- myVTK2ObjIds.push_back(cellId);
- outputCD->CopyData(cd,cellId,aTriangleId);
- }
- pts->Delete();
- coords->Delete();
- aPlg->Delete();
- }
- else {
- aNbPoints = MergevtkPoints(aCollection, output->GetPoints(), aNewPoints);
- newCellId = output->InsertNextCell(aCellType,aNbPoints,aNewPoints);
- outputCD->CopyData(cd,cellId,newCellId);
- if(myStoreMapping)
- myVTK2ObjIds.push_back(cellId);
- }
- break;
- } //VTK_QUADRATIC_QUAD
-
- //Unsupported cell type
- default:
- break;
- } //switch
+ aCollection.push_back(aBuilder1.GetPoints());
+ aCollection.push_back(aBuilder2.GetPoints());
+ aCollection.push_back(aBuilder3.GetPoints());
+ aCollection.push_back(aBuilder4.GetPoints());
+
+ aScalarCollection.push_back(aBuilder1.GetScalarValues());
+ aScalarCollection.push_back(aBuilder2.GetScalarValues());
+ aScalarCollection.push_back(aBuilder3.GetScalarValues());
+ aScalarCollection.push_back(aBuilder4.GetScalarValues());
+ break;
+ }
+ default: //Unsupported cell type
+ return;
+ }
+
+ if(triangulate){
+ const vtkIdType numFacePts = 3;
+ vtkIdList *pts = vtkIdList::New();
+ vtkPoints *coords = vtkPoints::New();
+ aCellType = VTK_TRIANGLE;
+ vtkIdType aNewPts[numFacePts];
+ vtkIdType aTriangleId;
+
+ vtkPolygon *aPlg = vtkPolygon::New();
+ std::map<int, double> aPntId2ScalarValue;
+ aNbPoints = MergevtkPoints(aCollection, aScalarCollection, aPlg->GetPoints(), aPntId2ScalarValue, aNewPoints);
+ aPlg->GetPointIds()->SetNumberOfIds(aNbPoints);
+
+ for(vtkIdType i = 0; i < aNbPoints;i++) {
+ aPlg->GetPointIds()->SetId(i, aNewPoints[i]);
+ }
+
+ aPlg->Triangulate(0,pts,coords);
+
+ for (vtkIdType i=0; i < pts->GetNumberOfIds(); i+=3) {
+ aNewPts[0] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i));
+ aNewPts[1] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+1));
+ aNewPts[2] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+2));
+
+ if(outputScalars) {
+ outputScalars->InsertNextTuple1(aPntId2ScalarValue[pts->GetId(i)]);
+ outputScalars->InsertNextTuple1(aPntId2ScalarValue[pts->GetId(i+1)]);
+ outputScalars->InsertNextTuple1(aPntId2ScalarValue[pts->GetId(i+2)]);
+ }
+
+ aTriangleId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+
+ if(myStoreMapping)
+ myVTK2ObjIds.push_back(cellId);
+ outputCD->CopyData(cd,cellId,aTriangleId);
+ }
+ pts->Delete();
+ coords->Delete();
+ aPlg->Delete();
+ }
+ else {
+ std::map<int, double> aPntId2ScalarValue;
+ aNbPoints = MergevtkPoints(aCollection, aScalarCollection, output->GetPoints(), aPntId2ScalarValue, aNewPoints);
+ if(outputScalars)
+ for(vtkIdType i = 0; i < aNbPoints; i++)
+ outputScalars->InsertNextTuple1(aPntId2ScalarValue[aNewPoints[i]]);
+ newCellId = output->InsertNextCell(aCellType,aNbPoints,aNewPoints);
+ outputCD->CopyData(cd,cellId,newCellId);
+
+ if(myStoreMapping)
+ myVTK2ObjIds.push_back(cellId);
+ }
if (aNewPoints)
delete [] aNewPoints;