53 vtkUnstructuredGrid *input= vtkUnstructuredGrid::SafeDownCast(this->GetInput());
55 if (!this->GetFileName())
57 vtkErrorMacro(<<
"FileName not set.");
61 std::string nodeFileName = this->GetFileName();
62 nodeFileName +=
".node";
64 std::string eleFileName = this->GetFileName();
65 eleFileName +=
".ele";
67 std::ofstream nodeStream(nodeFileName.c_str());
68 std::ofstream eleStream(eleFileName.c_str());
70 if (!nodeStream.good())
72 vtkErrorMacro(<<
"Could not open node file for writing.");
76 if (!eleStream.good())
78 vtkErrorMacro(<<
"Could not open ele file for writing.");
84 int numberOfPoints = input->GetNumberOfPoints();
90 nodeStream << numberOfPoints <<
" 3 0 0" << std::endl;
93 for (i=0; i<numberOfPoints; i++)
95 input->GetPoint(i,point);
96 nodeStream << i+1 <<
" " << point[0] <<
" " << point[1] <<
" " << point[2] << std::endl;
100 vtkIntArray* boundaryDataArray = vtkIntArray::New();
103 if (input->GetCellData()->GetArray(this->BoundaryDataArrayName))
105 boundaryDataArray->DeepCopy(input->GetCellData()->GetArray(this->BoundaryDataArrayName));
109 vtkErrorMacro(<<
"BoundaryDataArray with name specified does not exist");
110 boundaryDataArray->Delete();
116 boundaryDataArray->SetNumberOfValues(numberOfCells);
117 boundaryDataArray->FillComponent(0,0.0);
121 vtkIdTypeArray* tetraCellIdArray = vtkIdTypeArray::New();
122 input->GetIdsOfCellsOfType(VTK_TETRA,tetraCellIdArray);
123 int numberOfTetras = tetraCellIdArray->GetNumberOfTuples();
125 vtkIdTypeArray* quadraticTetraCellIdArray = vtkIdTypeArray::New();
126 input->GetIdsOfCellsOfType(VTK_QUADRATIC_TETRA,quadraticTetraCellIdArray);
127 int numberOfQuadraticTetras = quadraticTetraCellIdArray->GetNumberOfTuples();
130 vtkIdTypeArray* tetIdsArray = tetraCellIdArray;
131 int numberOfOutputTetras = tetraCellIdArray->GetNumberOfTuples();
133 if (numberOfQuadraticTetras > numberOfTetras)
136 tetIdsArray = quadraticTetraCellIdArray;
137 numberOfOutputTetras = quadraticTetraCellIdArray->GetNumberOfTuples();
142 eleStream << numberOfOutputTetras <<
" " << pointsInTet <<
" 0" << std::endl;
144 double point0[3], point1[3], point2[3], point3[3];
145 double cross[3], vector01[3], vector21[3], vector31[3];
149 int cellPointIds[10];
150 for (i=0; i<numberOfOutputTetras; i++)
152 vtkIdType cellId = tetraCellIdArray->GetValue(i);
153 vtkCell* cell = input->GetCell(cellId);
154 for (j=0; j<pointsInTet; j++)
156 cellPointIds[j] = cell->GetPointId(j);
158 input->GetPoint(cellPointIds[0],point0);
159 input->GetPoint(cellPointIds[1],point1);
160 input->GetPoint(cellPointIds[2],point2);
161 input->GetPoint(cellPointIds[3],point3);
162 vector01[0] = point0[0] - point1[0];
163 vector01[1] = point0[1] - point1[1];
164 vector01[2] = point0[2] - point1[2];
165 vector21[0] = point2[0] - point1[0];
166 vector21[1] = point2[1] - point1[1];
167 vector21[2] = point2[2] - point1[2];
168 vector31[0] = point3[0] - point1[0];
169 vector31[1] = point3[1] - point1[1];
170 vector31[2] = point3[2] - point1[2];
171 vtkMath::Cross(vector21,vector31,cross);
172 dot = vtkMath::Dot(cross,vector01);
175 tmp = cellPointIds[2];
176 cellPointIds[2] = cellPointIds[3];
177 cellPointIds[3] = tmp;
178 if (pointsInTet == 10)
180 tmp = cellPointIds[6];
181 cellPointIds[6] = cellPointIds[7];
182 cellPointIds[7] = tmp;
183 tmp = cellPointIds[5];
184 cellPointIds[5] = cellPointIds[8];
185 cellPointIds[8] = tmp;
189 eleStream << i+1 <<
" ";
190 for (j=0; j<pointsInTet; j++)
192 eleStream << cellPointIds[j]+1 <<
" ";
194 eleStream << std::endl;
197 tetraCellIdArray->Delete();
198 quadraticTetraCellIdArray->Delete();