VMTK
Loading...
Searching...
No Matches
vtkvmtkTetGenWriter Class Reference

Writes TetGen .msh files. More...

#include <vtkvmtkTetGenWriter.h>

Inheritance diagram for vtkvmtkTetGenWriter:
[legend]
Collaboration diagram for vtkvmtkTetGenWriter:
[legend]

Public Types

typedef vtkUnstructuredGridWriter Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkTetGenWriter * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetBoundaryDataArrayName (const char *)
virtual char * GetBoundaryDataArrayName ()

Static Public Member Functions

static vtkvmtkTetGenWriter * New ()
static int IsTypeOf (const char *type)
static vtkvmtkTetGenWriter * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkTetGenWriter ()
 ~vtkvmtkTetGenWriter ()
void ConvertFaceToLeftHanded (vtkUnstructuredGrid *input, vtkIdType tetraCellId, vtkIdType &id0, vtkIdType &id1, vtkIdType &id2)
void WriteData () override

Protected Attributes

char * BoundaryDataArrayName

Detailed Description

Writes TetGen .msh files.

vtkvmtkTetGenWriter writes TetGen .msh files. Many thanks to M. Xenos, Y. Alemu and D. Bluestein, BioFluids Laboratory, Stony Brook University, Stony Brook, NY, for the inputs on the file format.

Definition at line 37 of file vtkvmtkTetGenWriter.h.

Member Typedef Documentation

◆ Superclass

typedef vtkUnstructuredGridWriter vtkvmtkTetGenWriter::Superclass

Definition at line 41 of file vtkvmtkTetGenWriter.h.

Constructor & Destructor Documentation

◆ vtkvmtkTetGenWriter()

vtkvmtkTetGenWriter::vtkvmtkTetGenWriter ( )
protected

Definition at line 37 of file vtkvmtkTetGenWriter.cxx.

38{
39 this->BoundaryDataArrayName = NULL;
40}

◆ ~vtkvmtkTetGenWriter()

vtkvmtkTetGenWriter::~vtkvmtkTetGenWriter ( )
protected

Definition at line 42 of file vtkvmtkTetGenWriter.cxx.

43{
44 if (this->BoundaryDataArrayName)
45 {
46 delete[] this->BoundaryDataArrayName;
47 this->BoundaryDataArrayName = NULL;
48 }
49}

Member Function Documentation

◆ New()

vtkvmtkTetGenWriter * vtkvmtkTetGenWriter::New ( )
static

◆ IsTypeOf()

int vtkvmtkTetGenWriter::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkTetGenWriter::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkTetGenWriter * vtkvmtkTetGenWriter::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkTetGenWriter::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkTetGenWriter * vtkvmtkTetGenWriter::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkTetGenWriter::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 201 of file vtkvmtkTetGenWriter.cxx.

202{
203 vtkUnstructuredGridWriter::PrintSelf(os,indent);
204}

◆ SetBoundaryDataArrayName()

virtual void vtkvmtkTetGenWriter::SetBoundaryDataArrayName ( const char * )
virtual

Set/get the name of the cell data array intended to hold boundary marker values to be written out alongside node/element data (mirroring vtkvmtkTetGenReader::BoundaryDataArrayName). Not currently used by WriteData: the .node/.ele files this writer produces have no attribute/boundary-marker columns. Commonly named "CellEntityIds".

◆ GetBoundaryDataArrayName()

virtual char * vtkvmtkTetGenWriter::GetBoundaryDataArrayName ( )
virtual

Set/get the name of the cell data array intended to hold boundary marker values to be written out alongside node/element data (mirroring vtkvmtkTetGenReader::BoundaryDataArrayName). Not currently used by WriteData: the .node/.ele files this writer produces have no attribute/boundary-marker columns. Commonly named "CellEntityIds".

◆ ConvertFaceToLeftHanded()

void vtkvmtkTetGenWriter::ConvertFaceToLeftHanded ( vtkUnstructuredGrid * input,
vtkIdType tetraCellId,
vtkIdType & id0,
vtkIdType & id1,
vtkIdType & id2 )
protected

◆ WriteData()

void vtkvmtkTetGenWriter::WriteData ( )
overrideprotected

Definition at line 51 of file vtkvmtkTetGenWriter.cxx.

52{
53 vtkUnstructuredGrid *input= vtkUnstructuredGrid::SafeDownCast(this->GetInput());
54
55 if (!this->GetFileName())
56 {
57 vtkErrorMacro(<<"FileName not set.");
58 return;
59 }
60
61 std::string nodeFileName = this->GetFileName();
62 nodeFileName += ".node";
63
64 std::string eleFileName = this->GetFileName();
65 eleFileName += ".ele";
66
67 std::ofstream nodeStream(nodeFileName.c_str());
68 std::ofstream eleStream(eleFileName.c_str());
69
70 if (!nodeStream.good())
71 {
72 vtkErrorMacro(<<"Could not open node file for writing.");
73 return;
74 }
75
76 if (!eleStream.good())
77 {
78 vtkErrorMacro(<<"Could not open ele file for writing.");
79 return;
80 }
81
82 input->BuildLinks();
83
84 int numberOfPoints = input->GetNumberOfPoints();
85
86 int i, j;
87
88 //TODO: add attributes and boundary markers
89
90 nodeStream << numberOfPoints << " 3 0 0" << std::endl;
91
92 double point[3];
93 for (i=0; i<numberOfPoints; i++)
94 {
95 input->GetPoint(i,point);
96 nodeStream << i+1 << " " << point[0] << " " << point[1] << " " << point[2] << std::endl;
97 }
98
99#if 0
100 vtkIntArray* boundaryDataArray = vtkIntArray::New();
101 if (this->BoundaryDataArrayName)
102 {
103 if (input->GetCellData()->GetArray(this->BoundaryDataArrayName))
104 {
105 boundaryDataArray->DeepCopy(input->GetCellData()->GetArray(this->BoundaryDataArrayName));
106 }
107 else
108 {
109 vtkErrorMacro(<<"BoundaryDataArray with name specified does not exist");
110 boundaryDataArray->Delete();
111 return;
112 }
113 }
114 else
115 {
116 boundaryDataArray->SetNumberOfValues(numberOfCells);
117 boundaryDataArray->FillComponent(0,0.0);
118 }
119#endif
120
121 vtkIdTypeArray* tetraCellIdArray = vtkIdTypeArray::New();
122 input->GetIdsOfCellsOfType(VTK_TETRA,tetraCellIdArray);
123 int numberOfTetras = tetraCellIdArray->GetNumberOfTuples();
124
125 vtkIdTypeArray* quadraticTetraCellIdArray = vtkIdTypeArray::New();
126 input->GetIdsOfCellsOfType(VTK_QUADRATIC_TETRA,quadraticTetraCellIdArray);
127 int numberOfQuadraticTetras = quadraticTetraCellIdArray->GetNumberOfTuples();
128
129 int pointsInTet = 4;
130 vtkIdTypeArray* tetIdsArray = tetraCellIdArray;
131 int numberOfOutputTetras = tetraCellIdArray->GetNumberOfTuples();
132
133 if (numberOfQuadraticTetras > numberOfTetras)
134 {
135 pointsInTet = 10;
136 tetIdsArray = quadraticTetraCellIdArray;
137 numberOfOutputTetras = quadraticTetraCellIdArray->GetNumberOfTuples();
138 }
139
140 //TODO: add attributes
141
142 eleStream << numberOfOutputTetras << " " << pointsInTet << " 0" << std::endl;
143
144 double point0[3], point1[3], point2[3], point3[3];
145 double cross[3], vector01[3], vector21[3], vector31[3];
146 double dot;
147 int tmp;
148
149 int cellPointIds[10];
150 for (i=0; i<numberOfOutputTetras; i++)
151 {
152 vtkIdType cellId = tetraCellIdArray->GetValue(i);
153 vtkCell* cell = input->GetCell(cellId);
154 for (j=0; j<pointsInTet; j++)
155 {
156 cellPointIds[j] = cell->GetPointId(j);
157 }
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);
173 if (dot < 0.0)
174 {
175 tmp = cellPointIds[2];
176 cellPointIds[2] = cellPointIds[3];
177 cellPointIds[3] = tmp;
178 if (pointsInTet == 10)
179 {
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;
186 }
187 }
188
189 eleStream << i+1 << " ";
190 for (j=0; j<pointsInTet; j++)
191 {
192 eleStream << cellPointIds[j]+1 << " ";
193 }
194 eleStream << std::endl;
195 }
196
197 tetraCellIdArray->Delete();
198 quadraticTetraCellIdArray->Delete();
199}

Member Data Documentation

◆ BoundaryDataArrayName

char* vtkvmtkTetGenWriter::BoundaryDataArrayName
protected

Definition at line 64 of file vtkvmtkTetGenWriter.h.


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